happy-dom 11.1.2 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of happy-dom might be problematic. Click here for more details.
- package/cjs/console/VirtualConsole.cjs.map +1 -1
- package/cjs/console/VirtualConsole.d.ts +2 -1
- package/cjs/console/VirtualConsole.d.ts.map +1 -1
- package/cjs/navigator/Navigator.cjs +15 -3
- package/cjs/navigator/Navigator.cjs.map +1 -1
- package/cjs/navigator/Navigator.d.ts +7 -0
- package/cjs/navigator/Navigator.d.ts.map +1 -1
- package/cjs/navigator/NavigatorUtility.cjs +34 -0
- package/cjs/navigator/NavigatorUtility.cjs.map +1 -0
- package/cjs/navigator/NavigatorUtility.d.ts +18 -0
- package/cjs/navigator/NavigatorUtility.d.ts.map +1 -0
- package/cjs/window/GlobalWindow.d.ts +1 -1
- package/cjs/window/GlobalWindow.d.ts.map +1 -1
- package/cjs/window/IHappyDOMOptions.d.ts +3 -0
- package/cjs/window/IHappyDOMOptions.d.ts.map +1 -1
- package/cjs/window/IHappyDOMSettings.d.ts +3 -0
- package/cjs/window/IHappyDOMSettings.d.ts.map +1 -1
- package/cjs/window/INodeJSGlobal.d.ts +1 -0
- package/cjs/window/INodeJSGlobal.d.ts.map +1 -1
- package/cjs/window/IWindow.d.ts +3 -0
- package/cjs/window/IWindow.d.ts.map +1 -1
- package/cjs/window/Window.cjs +11 -1
- package/cjs/window/Window.cjs.map +1 -1
- package/cjs/window/Window.d.ts +5 -1
- package/cjs/window/Window.d.ts.map +1 -1
- package/lib/console/VirtualConsole.d.ts +2 -1
- package/lib/console/VirtualConsole.d.ts.map +1 -1
- package/lib/console/VirtualConsole.js.map +1 -1
- package/lib/navigator/Navigator.d.ts +7 -0
- package/lib/navigator/Navigator.d.ts.map +1 -1
- package/lib/navigator/Navigator.js +15 -3
- package/lib/navigator/Navigator.js.map +1 -1
- package/lib/navigator/NavigatorUtility.d.ts +18 -0
- package/lib/navigator/NavigatorUtility.d.ts.map +1 -0
- package/lib/navigator/NavigatorUtility.js +28 -0
- package/lib/navigator/NavigatorUtility.js.map +1 -0
- package/lib/window/GlobalWindow.d.ts +1 -1
- package/lib/window/GlobalWindow.d.ts.map +1 -1
- package/lib/window/IHappyDOMOptions.d.ts +3 -0
- package/lib/window/IHappyDOMOptions.d.ts.map +1 -1
- package/lib/window/IHappyDOMSettings.d.ts +3 -0
- package/lib/window/IHappyDOMSettings.d.ts.map +1 -1
- package/lib/window/INodeJSGlobal.d.ts +1 -0
- package/lib/window/INodeJSGlobal.d.ts.map +1 -1
- package/lib/window/IWindow.d.ts +3 -0
- package/lib/window/IWindow.d.ts.map +1 -1
- package/lib/window/Window.d.ts +5 -1
- package/lib/window/Window.d.ts.map +1 -1
- package/lib/window/Window.js +11 -1
- package/lib/window/Window.js.map +1 -1
- package/package.json +2 -2
- package/src/console/VirtualConsole.ts +2 -1
- package/src/navigator/Navigator.ts +19 -3
- package/src/navigator/NavigatorUtility.ts +29 -0
- package/src/window/IHappyDOMOptions.ts +3 -0
- package/src/window/IHappyDOMSettings.ts +3 -0
- package/src/window/IWindow.ts +2 -0
- package/src/window/Window.ts +11 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "happy-dom",
|
3
|
-
"version": "
|
3
|
+
"version": "12.0.0",
|
4
4
|
"license": "MIT",
|
5
5
|
"homepage": "https://github.com/capricorn86/happy-dom",
|
6
6
|
"repository": "https://github.com/capricorn86/happy-dom",
|
@@ -85,7 +85,7 @@
|
|
85
85
|
},
|
86
86
|
"devDependencies": {
|
87
87
|
"@types/css.escape": "^1.5.0",
|
88
|
-
"@types/node": "^
|
88
|
+
"@types/node": "^16.11.7",
|
89
89
|
"@types/node-fetch": "^2.6.1",
|
90
90
|
"@typescript-eslint/eslint-plugin": "^5.16.0",
|
91
91
|
"@typescript-eslint/parser": "^5.16.0",
|
@@ -3,6 +3,7 @@ import VirtualConsoleLogLevelEnum from './enums/VirtualConsoleLogLevelEnum.js';
|
|
3
3
|
import VirtualConsoleLogTypeEnum from './enums/VirtualConsoleLogTypeEnum.js';
|
4
4
|
import IVirtualConsoleLogGroup from './types/IVirtualConsoleLogGroup.js';
|
5
5
|
import * as PerfHooks from 'perf_hooks';
|
6
|
+
import { ConsoleConstructor } from 'console';
|
6
7
|
|
7
8
|
/**
|
8
9
|
* Virtual Console.
|
@@ -12,7 +13,7 @@ import * as PerfHooks from 'perf_hooks';
|
|
12
13
|
export default class VirtualConsole implements Console {
|
13
14
|
// This is needed as the interface for the NodeJS Console also have a reference to the ConsoleConstructor class as a property for some reason.
|
14
15
|
// This is not part of the browser specs.
|
15
|
-
public Console:
|
16
|
+
public Console: ConsoleConstructor;
|
16
17
|
|
17
18
|
private _printer: IVirtualConsolePrinter;
|
18
19
|
private _count: { [label: string]: number } = {};
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import MimeTypeArray from './MimeTypeArray.js';
|
2
2
|
import PluginArray from './PluginArray.js';
|
3
|
+
import IWindow from '../window/IWindow.js';
|
3
4
|
|
4
5
|
/**
|
5
6
|
* Browser Navigator API.
|
@@ -10,6 +11,16 @@ import PluginArray from './PluginArray.js';
|
|
10
11
|
* https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator.
|
11
12
|
*/
|
12
13
|
export default class Navigator {
|
14
|
+
private _ownerWindow: IWindow;
|
15
|
+
|
16
|
+
/**
|
17
|
+
*
|
18
|
+
* @param ownerWindow
|
19
|
+
*/
|
20
|
+
constructor(ownerWindow: IWindow) {
|
21
|
+
this._ownerWindow = ownerWindow;
|
22
|
+
}
|
23
|
+
|
13
24
|
/**
|
14
25
|
* False if setting a cookie will be ignored and true otherwise.
|
15
26
|
*/
|
@@ -84,14 +95,19 @@ export default class Navigator {
|
|
84
95
|
* Browser app version.
|
85
96
|
*/
|
86
97
|
public get appVersion(): string {
|
87
|
-
|
98
|
+
const userAgent = this.userAgent;
|
99
|
+
const index = userAgent.indexOf('/');
|
100
|
+
return index > -1 ? userAgent.substring(index + 1) : '';
|
88
101
|
}
|
89
102
|
|
90
103
|
/**
|
91
104
|
* Browser platform.
|
92
105
|
*/
|
93
106
|
public get platform(): string {
|
94
|
-
|
107
|
+
const userAgent = this.userAgent;
|
108
|
+
const indexStart = userAgent.indexOf('(');
|
109
|
+
const indexEnd = userAgent.indexOf(')');
|
110
|
+
return indexStart > -1 && indexEnd > -1 ? userAgent.substring(indexStart + 1, indexEnd) : '';
|
95
111
|
}
|
96
112
|
|
97
113
|
/**
|
@@ -128,7 +144,7 @@ export default class Navigator {
|
|
128
144
|
* "appCodeName/appVersion number (Platform; Security; OS-or-CPU; Localization; rv: revision-version-number) product/productSub Application-Name Application-Name-version".
|
129
145
|
*/
|
130
146
|
public get userAgent(): string {
|
131
|
-
return
|
147
|
+
return this._ownerWindow.happyDOM.settings.navigator.userAgent;
|
132
148
|
}
|
133
149
|
|
134
150
|
/**
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import FS from 'fs';
|
2
|
+
import Path from 'path';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Utility for navigator.
|
6
|
+
*/
|
7
|
+
export default class NavigatorUtility {
|
8
|
+
/**
|
9
|
+
* Returns the package version.
|
10
|
+
*
|
11
|
+
* @returns Package version.
|
12
|
+
*/
|
13
|
+
public static getHappyDOMVersion(): string {
|
14
|
+
const content = FS.readFileSync(Path.join(__dirname, '..', '..', 'package.json')).toString();
|
15
|
+
const json = JSON.parse(content);
|
16
|
+
return json.version;
|
17
|
+
}
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Returns platform.
|
21
|
+
*
|
22
|
+
* @returns Platform.
|
23
|
+
*/
|
24
|
+
public static getPlatform(): string {
|
25
|
+
const platform = process.platform;
|
26
|
+
const platformCapitalized = platform.charAt(0).toUpperCase() + platform.slice(1);
|
27
|
+
return 'X11; ' + platformCapitalized + ' ' + process.arch;
|
28
|
+
}
|
29
|
+
}
|
@@ -13,6 +13,9 @@ export default interface IHappyDOMOptions {
|
|
13
13
|
disableIframePageLoading?: boolean;
|
14
14
|
disableComputedStyleRendering?: boolean;
|
15
15
|
enableFileSystemHttpRequests?: boolean;
|
16
|
+
navigator?: {
|
17
|
+
userAgent?: string;
|
18
|
+
};
|
16
19
|
device?: {
|
17
20
|
prefersColorScheme?: string;
|
18
21
|
mediaType?: string;
|
@@ -8,6 +8,9 @@ export default interface IHappyDOMSettings {
|
|
8
8
|
disableIframePageLoading: boolean;
|
9
9
|
disableComputedStyleRendering: boolean;
|
10
10
|
enableFileSystemHttpRequests: boolean;
|
11
|
+
navigator: {
|
12
|
+
userAgent: string;
|
13
|
+
};
|
11
14
|
device: {
|
12
15
|
prefersColorScheme: string;
|
13
16
|
mediaType: string;
|
package/src/window/IWindow.ts
CHANGED
@@ -114,6 +114,7 @@ import IHappyDOMSettings from './IHappyDOMSettings.js';
|
|
114
114
|
import RequestInfo from '../fetch/types/IRequestInfo.js';
|
115
115
|
import FileList from '../nodes/html-input-element/FileList.js';
|
116
116
|
import Stream from 'stream';
|
117
|
+
import { webcrypto } from 'crypto';
|
117
118
|
import FormData from '../form-data/FormData.js';
|
118
119
|
import AbortController from '../fetch/AbortController.js';
|
119
120
|
import AbortSignal from '../fetch/AbortSignal.js';
|
@@ -295,6 +296,7 @@ export default interface IWindow extends IEventTarget, INodeJSGlobal {
|
|
295
296
|
readonly pageYOffset: number;
|
296
297
|
readonly scrollX: number;
|
297
298
|
readonly scrollY: number;
|
299
|
+
readonly crypto: typeof webcrypto;
|
298
300
|
|
299
301
|
/**
|
300
302
|
* Returns an object containing the values of all CSS properties of an element.
|
package/src/window/Window.ts
CHANGED
@@ -114,6 +114,7 @@ import VMGlobalPropertyScript from './VMGlobalPropertyScript.js';
|
|
114
114
|
import * as PerfHooks from 'perf_hooks';
|
115
115
|
import VM from 'vm';
|
116
116
|
import { Buffer } from 'buffer';
|
117
|
+
import { webcrypto } from 'crypto';
|
117
118
|
import XMLHttpRequestImplementation from '../xml-http-request/XMLHttpRequest.js';
|
118
119
|
import XMLHttpRequestUpload from '../xml-http-request/XMLHttpRequestUpload.js';
|
119
120
|
import XMLHttpRequestEventTarget from '../xml-http-request/XMLHttpRequestEventTarget.js';
|
@@ -139,6 +140,7 @@ import WindowErrorUtility from './WindowErrorUtility.js';
|
|
139
140
|
import VirtualConsole from '../console/VirtualConsole.js';
|
140
141
|
import VirtualConsolePrinter from '../console/VirtualConsolePrinter.js';
|
141
142
|
import IHappyDOMSettings from './IHappyDOMSettings.js';
|
143
|
+
import NavigatorUtility from '../navigator/NavigatorUtility.js';
|
142
144
|
|
143
145
|
const ORIGINAL_SET_TIMEOUT = setTimeout;
|
144
146
|
const ORIGINAL_CLEAR_TIMEOUT = clearTimeout;
|
@@ -209,6 +211,9 @@ export default class Window extends EventTarget implements IWindow {
|
|
209
211
|
disableIframePageLoading: false,
|
210
212
|
disableComputedStyleRendering: false,
|
211
213
|
enableFileSystemHttpRequests: false,
|
214
|
+
navigator: {
|
215
|
+
userAgent: `Mozilla/5.0 (${NavigatorUtility.getPlatform()}) AppleWebKit/537.36 (KHTML, like Gecko) HappyDOM/${NavigatorUtility.getHappyDOMVersion()}`
|
216
|
+
},
|
212
217
|
device: {
|
213
218
|
prefersColorScheme: 'light',
|
214
219
|
mediaType: 'screen'
|
@@ -364,6 +369,7 @@ export default class Window extends EventTarget implements IWindow {
|
|
364
369
|
public readonly innerHeight: number = 768;
|
365
370
|
public readonly outerWidth: number = 1024;
|
366
371
|
public readonly outerHeight: number = 768;
|
372
|
+
public readonly crypto = webcrypto;
|
367
373
|
|
368
374
|
// Node.js Globals
|
369
375
|
public Array: typeof Array;
|
@@ -455,7 +461,7 @@ export default class Window extends EventTarget implements IWindow {
|
|
455
461
|
|
456
462
|
this.customElements = new CustomElementRegistry();
|
457
463
|
this.location = new Location();
|
458
|
-
this.navigator = new Navigator();
|
464
|
+
this.navigator = new Navigator(this);
|
459
465
|
this.history = new History();
|
460
466
|
this.screen = new Screen();
|
461
467
|
this.sessionStorage = new Storage();
|
@@ -486,6 +492,10 @@ export default class Window extends EventTarget implements IWindow {
|
|
486
492
|
this.happyDOM.settings = {
|
487
493
|
...this.happyDOM.settings,
|
488
494
|
...options.settings,
|
495
|
+
navigator: {
|
496
|
+
...this.happyDOM.settings.navigator,
|
497
|
+
...options.settings.navigator
|
498
|
+
},
|
489
499
|
device: {
|
490
500
|
...this.happyDOM.settings.device,
|
491
501
|
...options.settings.device
|