happy-dom 12.0.0 → 12.1.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/event/EventTarget.cjs +9 -5
- package/cjs/event/EventTarget.cjs.map +1 -1
- package/cjs/event/EventTarget.d.ts.map +1 -1
- package/cjs/nodes/html-link-element/HTMLLinkElementUtility.cjs +21 -4
- package/cjs/nodes/html-link-element/HTMLLinkElementUtility.cjs.map +1 -1
- package/cjs/nodes/html-link-element/HTMLLinkElementUtility.d.ts.map +1 -1
- package/cjs/nodes/html-script-element/HTMLScriptElement.cjs +6 -1
- package/cjs/nodes/html-script-element/HTMLScriptElement.cjs.map +1 -1
- package/cjs/nodes/html-script-element/HTMLScriptElement.d.ts.map +1 -1
- package/cjs/nodes/html-script-element/HTMLScriptElementUtility.cjs +48 -8
- package/cjs/nodes/html-script-element/HTMLScriptElementUtility.cjs.map +1 -1
- package/cjs/nodes/html-script-element/HTMLScriptElementUtility.d.ts.map +1 -1
- package/cjs/nodes/html-unknown-element/HTMLUnknownElement.cjs +1 -1
- package/cjs/nodes/html-unknown-element/HTMLUnknownElement.cjs.map +1 -1
- package/cjs/version.cjs +1 -0
- package/cjs/version.cjs.map +1 -0
- package/cjs/version.d.ts +5 -0
- package/cjs/version.d.ts.map +1 -0
- package/cjs/window/IHappyDOMOptions.d.ts +1 -0
- package/cjs/window/IHappyDOMOptions.d.ts.map +1 -1
- package/cjs/window/IHappyDOMSettings.d.ts +1 -0
- package/cjs/window/IHappyDOMSettings.d.ts.map +1 -1
- package/cjs/window/Window.cjs +21 -5
- package/cjs/window/Window.cjs.map +1 -1
- package/cjs/window/Window.d.ts.map +1 -1
- package/cjs/window/WindowErrorUtility.cjs +1 -23
- package/cjs/window/WindowErrorUtility.cjs.map +1 -1
- package/cjs/window/WindowErrorUtility.d.ts +1 -12
- package/cjs/window/WindowErrorUtility.d.ts.map +1 -1
- package/lib/event/EventTarget.d.ts.map +1 -1
- package/lib/event/EventTarget.js +9 -5
- package/lib/event/EventTarget.js.map +1 -1
- package/lib/nodes/html-link-element/HTMLLinkElementUtility.d.ts.map +1 -1
- package/lib/nodes/html-link-element/HTMLLinkElementUtility.js +21 -4
- package/lib/nodes/html-link-element/HTMLLinkElementUtility.js.map +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.d.ts.map +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.js +6 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElementUtility.d.ts.map +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElementUtility.js +48 -8
- package/lib/nodes/html-script-element/HTMLScriptElementUtility.js.map +1 -1
- package/lib/nodes/html-unknown-element/HTMLUnknownElement.js +1 -1
- package/lib/nodes/html-unknown-element/HTMLUnknownElement.js.map +1 -1
- package/lib/version.d.ts +5 -0
- package/lib/version.d.ts.map +1 -0
- package/lib/version.js +1 -0
- package/lib/version.js.map +1 -0
- package/lib/window/IHappyDOMOptions.d.ts +1 -0
- package/lib/window/IHappyDOMOptions.d.ts.map +1 -1
- package/lib/window/IHappyDOMSettings.d.ts +1 -0
- package/lib/window/IHappyDOMSettings.d.ts.map +1 -1
- package/lib/window/Window.d.ts.map +1 -1
- package/lib/window/Window.js +21 -5
- package/lib/window/Window.js.map +1 -1
- package/lib/window/WindowErrorUtility.d.ts +1 -12
- package/lib/window/WindowErrorUtility.d.ts.map +1 -1
- package/lib/window/WindowErrorUtility.js +1 -23
- package/lib/window/WindowErrorUtility.js.map +1 -1
- package/package.json +3 -2
- package/src/event/EventTarget.ts +13 -5
- package/src/nodes/html-link-element/HTMLLinkElementUtility.ts +23 -14
- package/src/nodes/html-script-element/HTMLScriptElement.ts +7 -3
- package/src/nodes/html-script-element/HTMLScriptElementUtility.ts +51 -22
- package/src/nodes/html-unknown-element/HTMLUnknownElement.ts +1 -1
- package/src/version.ts +1 -0
- package/src/window/IHappyDOMOptions.ts +1 -0
- package/src/window/IHappyDOMSettings.ts +1 -0
- package/src/window/Window.ts +25 -9
- package/src/window/WindowErrorUtility.ts +1 -27
- package/cjs/navigator/NavigatorUtility.cjs +0 -34
- package/cjs/navigator/NavigatorUtility.cjs.map +0 -1
- package/cjs/navigator/NavigatorUtility.d.ts +0 -18
- package/cjs/navigator/NavigatorUtility.d.ts.map +0 -1
- package/lib/navigator/NavigatorUtility.d.ts +0 -18
- package/lib/navigator/NavigatorUtility.d.ts.map +0 -1
- package/lib/navigator/NavigatorUtility.js +0 -28
- package/lib/navigator/NavigatorUtility.js.map +0 -1
- package/src/navigator/NavigatorUtility.ts +0 -29
@@ -4,17 +4,6 @@ import { IElement } from '../index.js';
|
|
4
4
|
* Error utility.
|
5
5
|
*/
|
6
6
|
export default class WindowErrorUtility {
|
7
|
-
/**
|
8
|
-
* Calls a function asynchronously wrapped in a try/catch block to capture errors and dispatch error events.
|
9
|
-
*
|
10
|
-
* It will also output the errors to the console.
|
11
|
-
*
|
12
|
-
* @param elementOrWindow Element or Window.
|
13
|
-
* @param callback Callback.
|
14
|
-
* @param [cleanup] Cleanup callback on error.
|
15
|
-
* @returns Promise.
|
16
|
-
*/
|
17
|
-
static captureErrorAsync<T>(elementOrWindow: IWindow | IElement, callback: () => Promise<T>, cleanup?: () => void): Promise<T | null>;
|
18
7
|
/**
|
19
8
|
* Calls a function synchronously wrapped in a try/catch block to capture errors and dispatch error events.
|
20
9
|
* If the callback returns a Promise, it will catch errors from the promise.
|
@@ -26,7 +15,7 @@ export default class WindowErrorUtility {
|
|
26
15
|
* @param [cleanup] Cleanup callback on error.
|
27
16
|
* @returns Result.
|
28
17
|
*/
|
29
|
-
static
|
18
|
+
static captureError<T>(elementOrWindow: IWindow | IElement, callback: () => T, cleanup?: () => void): T | null;
|
30
19
|
/**
|
31
20
|
* Dispatches an error event and outputs it to the console.
|
32
21
|
*
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"WindowErrorUtility.d.ts","sourceRoot":"","sources":["../../src/window/WindowErrorUtility.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAkB;IACtC
|
1
|
+
{"version":3,"file":"WindowErrorUtility.d.ts","sourceRoot":"","sources":["../../src/window/WindowErrorUtility.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAkB;IACtC;;;;;;;;;;OAUG;WACW,YAAY,CAAC,CAAC,EAC3B,eAAe,EAAE,OAAO,GAAG,QAAQ,EACnC,QAAQ,EAAE,MAAM,CAAC,EACjB,OAAO,CAAC,EAAE,MAAM,IAAI,GAClB,CAAC,GAAG,IAAI;IAwBX;;;;;OAKG;WACW,aAAa,CAAC,eAAe,EAAE,OAAO,GAAG,QAAQ,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;CAcpF"}
|
@@ -3,28 +3,6 @@ import ErrorEvent from '../event/events/ErrorEvent.js';
|
|
3
3
|
* Error utility.
|
4
4
|
*/
|
5
5
|
export default class WindowErrorUtility {
|
6
|
-
/**
|
7
|
-
* Calls a function asynchronously wrapped in a try/catch block to capture errors and dispatch error events.
|
8
|
-
*
|
9
|
-
* It will also output the errors to the console.
|
10
|
-
*
|
11
|
-
* @param elementOrWindow Element or Window.
|
12
|
-
* @param callback Callback.
|
13
|
-
* @param [cleanup] Cleanup callback on error.
|
14
|
-
* @returns Promise.
|
15
|
-
*/
|
16
|
-
static async captureErrorAsync(elementOrWindow, callback, cleanup) {
|
17
|
-
try {
|
18
|
-
return await callback();
|
19
|
-
}
|
20
|
-
catch (error) {
|
21
|
-
this.dispatchError(elementOrWindow, error);
|
22
|
-
if (cleanup) {
|
23
|
-
cleanup();
|
24
|
-
}
|
25
|
-
}
|
26
|
-
return null;
|
27
|
-
}
|
28
6
|
/**
|
29
7
|
* Calls a function synchronously wrapped in a try/catch block to capture errors and dispatch error events.
|
30
8
|
* If the callback returns a Promise, it will catch errors from the promise.
|
@@ -36,7 +14,7 @@ export default class WindowErrorUtility {
|
|
36
14
|
* @param [cleanup] Cleanup callback on error.
|
37
15
|
* @returns Result.
|
38
16
|
*/
|
39
|
-
static
|
17
|
+
static captureError(elementOrWindow, callback, cleanup) {
|
40
18
|
let result = null;
|
41
19
|
try {
|
42
20
|
result = callback();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"WindowErrorUtility.js","sourceRoot":"","sources":["../../src/window/WindowErrorUtility.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,+BAA+B,CAAC;AAGvD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAkB;IACtC
|
1
|
+
{"version":3,"file":"WindowErrorUtility.js","sourceRoot":"","sources":["../../src/window/WindowErrorUtility.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,+BAA+B,CAAC;AAGvD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAkB;IACtC;;;;;;;;;;OAUG;IACI,MAAM,CAAC,YAAY,CACzB,eAAmC,EACnC,QAAiB,EACjB,OAAoB;QAEpB,IAAI,MAAM,GAAG,IAAI,CAAC;QAElB,IAAI;YACH,MAAM,GAAG,QAAQ,EAAE,CAAC;SACpB;QAAC,OAAO,KAAK,EAAE;YACf,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;YAC3C,IAAI,OAAO,EAAE;gBACZ,OAAO,EAAE,CAAC;aACV;SACD;QAED,IAAI,MAAM,IAAI,MAAM,YAAY,OAAO,EAAE;YACxC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBACtB,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;gBAC3C,IAAI,OAAO,EAAE;oBACZ,OAAO,EAAE,CAAC;iBACV;YACF,CAAC,CAAC,CAAC;SACH;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,aAAa,CAAC,eAAmC,EAAE,KAAY;QAC5E,IAAc,eAAgB,CAAC,OAAO,EAAE;YAC7B,eAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAChD,eAAe,CAAC,aAAa,CAAC,IAAI,UAAU,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;SAC1F;aAAM;YACK,eAAgB,CAAC,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAChE,eAAgB,CAAC,aAAa,CACxC,IAAI,UAAU,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAC1D,CAAC;YACS,eAAgB,CAAC,aAAa,CAAC,WAAW,CAAC,aAAa,CAClE,IAAI,UAAU,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAC1D,CAAC;SACF;IACF,CAAC;CACD"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "happy-dom",
|
3
|
-
"version": "12.
|
3
|
+
"version": "12.1.0",
|
4
4
|
"license": "MIT",
|
5
5
|
"homepage": "https://github.com/capricorn86/happy-dom",
|
6
6
|
"repository": "https://github.com/capricorn86/happy-dom",
|
@@ -65,8 +65,9 @@
|
|
65
65
|
"access": "public"
|
66
66
|
},
|
67
67
|
"scripts": {
|
68
|
-
"compile": "tsc && tsc --module CommonJS --outDir cjs && npm run change-cjs-file-extension",
|
68
|
+
"compile": "tsc && tsc --module CommonJS --outDir cjs && npm run change-cjs-file-extension && npm run build-version-file",
|
69
69
|
"change-cjs-file-extension": "node ./bin/change-file-extension.cjs --dir=./cjs --fromExt=.js --toExt=.cjs",
|
70
|
+
"build-version-file": "node ./bin/build-version-file.cjs",
|
70
71
|
"watch": "tsc -w --preserveWatchOutput",
|
71
72
|
"lint": "eslint --ignore-path .gitignore --max-warnings 0 .",
|
72
73
|
"lint:fix": "eslint --ignore-path .gitignore --max-warnings 0 --fix .",
|
package/src/event/EventTarget.ts
CHANGED
@@ -140,8 +140,12 @@ export default abstract class EventTarget implements IEventTarget {
|
|
140
140
|
|
141
141
|
if (typeof this[onEventName] === 'function') {
|
142
142
|
// We can end up in a never ending loop if the listener for the error event on Window also throws an error.
|
143
|
-
if (
|
144
|
-
|
143
|
+
if (
|
144
|
+
window &&
|
145
|
+
(this !== <IEventTarget>window || event.type !== 'error') &&
|
146
|
+
!window.happyDOM.settings.disableErrorCapturing
|
147
|
+
) {
|
148
|
+
WindowErrorUtility.captureError(window, this[onEventName].bind(this, event));
|
145
149
|
} else {
|
146
150
|
this[onEventName].call(this, event);
|
147
151
|
}
|
@@ -169,14 +173,18 @@ export default abstract class EventTarget implements IEventTarget {
|
|
169
173
|
}
|
170
174
|
|
171
175
|
// We can end up in a never ending loop if the listener for the error event on Window also throws an error.
|
172
|
-
if (
|
176
|
+
if (
|
177
|
+
window &&
|
178
|
+
(this !== <IEventTarget>window || event.type !== 'error') &&
|
179
|
+
!window.happyDOM.settings.disableErrorCapturing
|
180
|
+
) {
|
173
181
|
if ((<IEventListener>listener).handleEvent) {
|
174
|
-
WindowErrorUtility.
|
182
|
+
WindowErrorUtility.captureError(
|
175
183
|
window,
|
176
184
|
(<IEventListener>listener).handleEvent.bind(this, event)
|
177
185
|
);
|
178
186
|
} else {
|
179
|
-
WindowErrorUtility.
|
187
|
+
WindowErrorUtility.captureError(
|
180
188
|
window,
|
181
189
|
(<(event: Event) => void>listener).bind(this, event)
|
182
190
|
);
|
@@ -24,32 +24,41 @@ export default class HTMLLinkElementUtility {
|
|
24
24
|
|
25
25
|
if (href !== null && rel && rel.toLowerCase() === 'stylesheet' && element.isConnected) {
|
26
26
|
if (element.ownerDocument.defaultView.happyDOM.settings.disableCSSFileLoading) {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
`Failed to load external stylesheet "${href}". CSS file loading is disabled.`,
|
31
|
-
DOMExceptionNameEnum.notSupportedError
|
32
|
-
)
|
27
|
+
const error = new DOMException(
|
28
|
+
`Failed to load external stylesheet "${href}". CSS file loading is disabled.`,
|
29
|
+
DOMExceptionNameEnum.notSupportedError
|
33
30
|
);
|
34
|
-
|
31
|
+
WindowErrorUtility.dispatchError(element, error);
|
32
|
+
if (element.ownerDocument.defaultView.happyDOM.settings.disableErrorCapturing) {
|
33
|
+
throw error;
|
34
|
+
}
|
35
35
|
return;
|
36
36
|
}
|
37
37
|
|
38
38
|
(<Document>element.ownerDocument)._readyStateManager.startTask();
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
let code: string | null = null;
|
41
|
+
let error: Error | null = null;
|
42
|
+
|
43
|
+
try {
|
44
|
+
code = await ResourceFetch.fetch(element.ownerDocument, href);
|
45
|
+
} catch (e) {
|
46
|
+
error = e;
|
47
|
+
}
|
44
48
|
|
45
|
-
|
49
|
+
(<Document>element.ownerDocument)._readyStateManager.endTask();
|
50
|
+
|
51
|
+
if (error) {
|
52
|
+
WindowErrorUtility.dispatchError(element, error);
|
53
|
+
if (element.ownerDocument.defaultView.happyDOM.settings.disableErrorCapturing) {
|
54
|
+
throw error;
|
55
|
+
}
|
56
|
+
} else {
|
46
57
|
const styleSheet = new CSSStyleSheet();
|
47
58
|
styleSheet.replaceSync(code);
|
48
59
|
(<CSSStyleSheet>element.sheet) = styleSheet;
|
49
60
|
element.dispatchEvent(new Event('load'));
|
50
61
|
}
|
51
|
-
|
52
|
-
(<Document>element.ownerDocument)._readyStateManager.endTask();
|
53
62
|
}
|
54
63
|
}
|
55
64
|
}
|
@@ -189,9 +189,13 @@ export default class HTMLScriptElement extends HTMLElement implements IHTMLScrip
|
|
189
189
|
type === 'application/x-javascript' ||
|
190
190
|
type.startsWith('text/javascript'))
|
191
191
|
) {
|
192
|
-
|
193
|
-
this.ownerDocument.defaultView.eval(textContent)
|
194
|
-
|
192
|
+
if (this.ownerDocument.defaultView.happyDOM.settings.disableErrorCapturing) {
|
193
|
+
this.ownerDocument.defaultView.eval(textContent);
|
194
|
+
} else {
|
195
|
+
WindowErrorUtility.captureError(this.ownerDocument.defaultView, () =>
|
196
|
+
this.ownerDocument.defaultView.eval(textContent)
|
197
|
+
);
|
198
|
+
}
|
195
199
|
}
|
196
200
|
}
|
197
201
|
}
|
@@ -25,40 +25,69 @@ export default class HTMLScriptElementUtility {
|
|
25
25
|
element.ownerDocument.defaultView.happyDOM.settings.disableJavaScriptFileLoading ||
|
26
26
|
element.ownerDocument.defaultView.happyDOM.settings.disableJavaScriptEvaluation
|
27
27
|
) {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
`Failed to load external script "${src}". JavaScript file loading is disabled.`,
|
32
|
-
DOMExceptionNameEnum.notSupportedError
|
33
|
-
)
|
28
|
+
const error = new DOMException(
|
29
|
+
`Failed to load external script "${src}". JavaScript file loading is disabled.`,
|
30
|
+
DOMExceptionNameEnum.notSupportedError
|
34
31
|
);
|
32
|
+
WindowErrorUtility.dispatchError(element, error);
|
33
|
+
if (element.ownerDocument.defaultView.happyDOM.settings.disableErrorCapturing) {
|
34
|
+
throw error;
|
35
|
+
}
|
35
36
|
return;
|
36
37
|
}
|
37
38
|
|
38
39
|
if (async) {
|
39
40
|
(<Document>element.ownerDocument)._readyStateManager.startTask();
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
async () => await ResourceFetch.fetch(element.ownerDocument, src)
|
44
|
-
);
|
42
|
+
let code: string | null = null;
|
43
|
+
let error: Error | null = null;
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
element.dispatchEvent(new Event('load'));
|
45
|
+
try {
|
46
|
+
code = await ResourceFetch.fetch(element.ownerDocument, src);
|
47
|
+
} catch (e) {
|
48
|
+
error = e;
|
51
49
|
}
|
50
|
+
|
52
51
|
(<Document>element.ownerDocument)._readyStateManager.endTask();
|
52
|
+
|
53
|
+
if (error) {
|
54
|
+
WindowErrorUtility.dispatchError(element, error);
|
55
|
+
if (element.ownerDocument.defaultView.happyDOM.settings.disableErrorCapturing) {
|
56
|
+
throw error;
|
57
|
+
}
|
58
|
+
} else {
|
59
|
+
if (element.ownerDocument.defaultView.happyDOM.settings.disableErrorCapturing) {
|
60
|
+
element.ownerDocument.defaultView.eval(code);
|
61
|
+
} else {
|
62
|
+
WindowErrorUtility.captureError(element.ownerDocument.defaultView, () =>
|
63
|
+
element.ownerDocument.defaultView.eval(code)
|
64
|
+
);
|
65
|
+
}
|
66
|
+
element.dispatchEvent(new Event('load'));
|
67
|
+
}
|
53
68
|
} else {
|
54
|
-
|
55
|
-
|
56
|
-
|
69
|
+
let code: string | null = null;
|
70
|
+
let error: Error | null = null;
|
71
|
+
|
72
|
+
try {
|
73
|
+
code = ResourceFetch.fetchSync(element.ownerDocument, src);
|
74
|
+
} catch (e) {
|
75
|
+
error = e;
|
76
|
+
}
|
57
77
|
|
58
|
-
if (
|
59
|
-
WindowErrorUtility.
|
60
|
-
|
61
|
-
|
78
|
+
if (error) {
|
79
|
+
WindowErrorUtility.dispatchError(element, error);
|
80
|
+
if (element.ownerDocument.defaultView.happyDOM.settings.disableErrorCapturing) {
|
81
|
+
throw error;
|
82
|
+
}
|
83
|
+
} else {
|
84
|
+
if (element.ownerDocument.defaultView.happyDOM.settings.disableErrorCapturing) {
|
85
|
+
element.ownerDocument.defaultView.eval(code);
|
86
|
+
} else {
|
87
|
+
WindowErrorUtility.captureError(element.ownerDocument.defaultView, () =>
|
88
|
+
element.ownerDocument.defaultView.eval(code)
|
89
|
+
);
|
90
|
+
}
|
62
91
|
element.dispatchEvent(new Event('load'));
|
63
92
|
}
|
64
93
|
}
|
@@ -27,7 +27,7 @@ export default class HTMLUnknownElement extends HTMLElement implements IHTMLElem
|
|
27
27
|
|
28
28
|
// This element can potentially be a custom element that has not been defined yet
|
29
29
|
// Therefore we need to register a callback for when it is defined in CustomElementRegistry and replace it with the registered element (see #404)
|
30
|
-
if (tagName.includes('-')) {
|
30
|
+
if (tagName.includes('-') && this.ownerDocument.defaultView.customElements._callbacks) {
|
31
31
|
const callbacks = this.ownerDocument.defaultView.customElements._callbacks;
|
32
32
|
|
33
33
|
if (parentNode && !this._customElementDefineCallback) {
|
package/src/version.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export default { version: '0.0.0' };
|
@@ -12,6 +12,7 @@ export default interface IHappyDOMOptions {
|
|
12
12
|
disableCSSFileLoading?: boolean;
|
13
13
|
disableIframePageLoading?: boolean;
|
14
14
|
disableComputedStyleRendering?: boolean;
|
15
|
+
disableErrorCapturing?: boolean;
|
15
16
|
enableFileSystemHttpRequests?: boolean;
|
16
17
|
navigator?: {
|
17
18
|
userAgent?: string;
|
@@ -7,6 +7,7 @@ export default interface IHappyDOMSettings {
|
|
7
7
|
disableCSSFileLoading: boolean;
|
8
8
|
disableIframePageLoading: boolean;
|
9
9
|
disableComputedStyleRendering: boolean;
|
10
|
+
disableErrorCapturing: boolean;
|
10
11
|
enableFileSystemHttpRequests: boolean;
|
11
12
|
navigator: {
|
12
13
|
userAgent: string;
|
package/src/window/Window.ts
CHANGED
@@ -140,7 +140,7 @@ import WindowErrorUtility from './WindowErrorUtility.js';
|
|
140
140
|
import VirtualConsole from '../console/VirtualConsole.js';
|
141
141
|
import VirtualConsolePrinter from '../console/VirtualConsolePrinter.js';
|
142
142
|
import IHappyDOMSettings from './IHappyDOMSettings.js';
|
143
|
-
import
|
143
|
+
import PackageVersion from '../version.js';
|
144
144
|
|
145
145
|
const ORIGINAL_SET_TIMEOUT = setTimeout;
|
146
146
|
const ORIGINAL_CLEAR_TIMEOUT = clearTimeout;
|
@@ -210,9 +210,12 @@ export default class Window extends EventTarget implements IWindow {
|
|
210
210
|
disableCSSFileLoading: false,
|
211
211
|
disableIframePageLoading: false,
|
212
212
|
disableComputedStyleRendering: false,
|
213
|
+
disableErrorCapturing: false,
|
213
214
|
enableFileSystemHttpRequests: false,
|
214
215
|
navigator: {
|
215
|
-
userAgent: `Mozilla/5.0 (${
|
216
|
+
userAgent: `Mozilla/5.0 (X11; ${
|
217
|
+
process.platform.charAt(0).toUpperCase() + process.platform.slice(1) + ' ' + process.arch
|
218
|
+
}) AppleWebKit/537.36 (KHTML, like Gecko) HappyDOM/${PackageVersion.version}`
|
216
219
|
},
|
217
220
|
device: {
|
218
221
|
prefersColorScheme: 'light',
|
@@ -734,7 +737,11 @@ export default class Window extends EventTarget implements IWindow {
|
|
734
737
|
public setTimeout(callback: Function, delay = 0, ...args: unknown[]): NodeJS.Timeout {
|
735
738
|
const id = this._setTimeout(() => {
|
736
739
|
this.happyDOM.asyncTaskManager.endTimer(id);
|
737
|
-
|
740
|
+
if (this.happyDOM.settings.disableErrorCapturing) {
|
741
|
+
callback(...args);
|
742
|
+
} else {
|
743
|
+
WindowErrorUtility.captureError(this, () => callback(...args));
|
744
|
+
}
|
738
745
|
}, delay);
|
739
746
|
this.happyDOM.asyncTaskManager.startTimer(id);
|
740
747
|
return id;
|
@@ -760,11 +767,15 @@ export default class Window extends EventTarget implements IWindow {
|
|
760
767
|
*/
|
761
768
|
public setInterval(callback: Function, delay = 0, ...args: unknown[]): NodeJS.Timeout {
|
762
769
|
const id = this._setInterval(() => {
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
770
|
+
if (this.happyDOM.settings.disableErrorCapturing) {
|
771
|
+
callback(...args);
|
772
|
+
} else {
|
773
|
+
WindowErrorUtility.captureError(
|
774
|
+
this,
|
775
|
+
() => callback(...args),
|
776
|
+
() => this.clearInterval(id)
|
777
|
+
);
|
778
|
+
}
|
768
779
|
}, delay);
|
769
780
|
this.happyDOM.asyncTaskManager.startTimer(id);
|
770
781
|
return id;
|
@@ -809,8 +820,13 @@ export default class Window extends EventTarget implements IWindow {
|
|
809
820
|
const taskId = this.happyDOM.asyncTaskManager.startTask(() => (isAborted = true));
|
810
821
|
this._queueMicrotask(() => {
|
811
822
|
if (!isAborted) {
|
812
|
-
WindowErrorUtility.captureErrorSync(this, <() => unknown>callback);
|
813
823
|
this.happyDOM.asyncTaskManager.endTask(taskId);
|
824
|
+
|
825
|
+
if (this.happyDOM.settings.disableErrorCapturing) {
|
826
|
+
callback();
|
827
|
+
} else {
|
828
|
+
WindowErrorUtility.captureError(this, <() => unknown>callback);
|
829
|
+
}
|
814
830
|
}
|
815
831
|
});
|
816
832
|
}
|
@@ -6,32 +6,6 @@ import { IElement } from '../index.js';
|
|
6
6
|
* Error utility.
|
7
7
|
*/
|
8
8
|
export default class WindowErrorUtility {
|
9
|
-
/**
|
10
|
-
* Calls a function asynchronously wrapped in a try/catch block to capture errors and dispatch error events.
|
11
|
-
*
|
12
|
-
* It will also output the errors to the console.
|
13
|
-
*
|
14
|
-
* @param elementOrWindow Element or Window.
|
15
|
-
* @param callback Callback.
|
16
|
-
* @param [cleanup] Cleanup callback on error.
|
17
|
-
* @returns Promise.
|
18
|
-
*/
|
19
|
-
public static async captureErrorAsync<T>(
|
20
|
-
elementOrWindow: IWindow | IElement,
|
21
|
-
callback: () => Promise<T>,
|
22
|
-
cleanup?: () => void
|
23
|
-
): Promise<T | null> {
|
24
|
-
try {
|
25
|
-
return await callback();
|
26
|
-
} catch (error) {
|
27
|
-
this.dispatchError(elementOrWindow, error);
|
28
|
-
if (cleanup) {
|
29
|
-
cleanup();
|
30
|
-
}
|
31
|
-
}
|
32
|
-
return null;
|
33
|
-
}
|
34
|
-
|
35
9
|
/**
|
36
10
|
* Calls a function synchronously wrapped in a try/catch block to capture errors and dispatch error events.
|
37
11
|
* If the callback returns a Promise, it will catch errors from the promise.
|
@@ -43,7 +17,7 @@ export default class WindowErrorUtility {
|
|
43
17
|
* @param [cleanup] Cleanup callback on error.
|
44
18
|
* @returns Result.
|
45
19
|
*/
|
46
|
-
public static
|
20
|
+
public static captureError<T>(
|
47
21
|
elementOrWindow: IWindow | IElement,
|
48
22
|
callback: () => T,
|
49
23
|
cleanup?: () => void
|
@@ -1,34 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
7
|
-
const path_1 = __importDefault(require("path"));
|
8
|
-
/**
|
9
|
-
* Utility for navigator.
|
10
|
-
*/
|
11
|
-
class NavigatorUtility {
|
12
|
-
/**
|
13
|
-
* Returns the package version.
|
14
|
-
*
|
15
|
-
* @returns Package version.
|
16
|
-
*/
|
17
|
-
static getHappyDOMVersion() {
|
18
|
-
const content = fs_1.default.readFileSync(path_1.default.join(__dirname, '..', '..', 'package.json')).toString();
|
19
|
-
const json = JSON.parse(content);
|
20
|
-
return json.version;
|
21
|
-
}
|
22
|
-
/**
|
23
|
-
* Returns platform.
|
24
|
-
*
|
25
|
-
* @returns Platform.
|
26
|
-
*/
|
27
|
-
static getPlatform() {
|
28
|
-
const platform = process.platform;
|
29
|
-
const platformCapitalized = platform.charAt(0).toUpperCase() + platform.slice(1);
|
30
|
-
return 'X11; ' + platformCapitalized + ' ' + process.arch;
|
31
|
-
}
|
32
|
-
}
|
33
|
-
exports.default = NavigatorUtility;
|
34
|
-
//# sourceMappingURL=NavigatorUtility.cjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"NavigatorUtility.cjs","sourceRoot":"","sources":["../../src/navigator/NavigatorUtility.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAExB;;GAEG;AACH,MAAqB,gBAAgB;IACpC;;;;OAIG;IACI,MAAM,CAAC,kBAAkB;QAC/B,MAAM,OAAO,GAAG,YAAE,CAAC,YAAY,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC7F,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,WAAW;QACxB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAClC,MAAM,mBAAmB,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjF,OAAO,OAAO,GAAG,mBAAmB,GAAG,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3D,CAAC;CACD;AAtBD,mCAsBC"}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Utility for navigator.
|
3
|
-
*/
|
4
|
-
export default class NavigatorUtility {
|
5
|
-
/**
|
6
|
-
* Returns the package version.
|
7
|
-
*
|
8
|
-
* @returns Package version.
|
9
|
-
*/
|
10
|
-
static getHappyDOMVersion(): string;
|
11
|
-
/**
|
12
|
-
* Returns platform.
|
13
|
-
*
|
14
|
-
* @returns Platform.
|
15
|
-
*/
|
16
|
-
static getPlatform(): string;
|
17
|
-
}
|
18
|
-
//# sourceMappingURL=NavigatorUtility.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"NavigatorUtility.d.ts","sourceRoot":"","sources":["../../src/navigator/NavigatorUtility.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACpC;;;;OAIG;WACW,kBAAkB,IAAI,MAAM;IAM1C;;;;OAIG;WACW,WAAW,IAAI,MAAM;CAKnC"}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Utility for navigator.
|
3
|
-
*/
|
4
|
-
export default class NavigatorUtility {
|
5
|
-
/**
|
6
|
-
* Returns the package version.
|
7
|
-
*
|
8
|
-
* @returns Package version.
|
9
|
-
*/
|
10
|
-
static getHappyDOMVersion(): string;
|
11
|
-
/**
|
12
|
-
* Returns platform.
|
13
|
-
*
|
14
|
-
* @returns Platform.
|
15
|
-
*/
|
16
|
-
static getPlatform(): string;
|
17
|
-
}
|
18
|
-
//# sourceMappingURL=NavigatorUtility.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"NavigatorUtility.d.ts","sourceRoot":"","sources":["../../src/navigator/NavigatorUtility.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACpC;;;;OAIG;WACW,kBAAkB,IAAI,MAAM;IAM1C;;;;OAIG;WACW,WAAW,IAAI,MAAM;CAKnC"}
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import FS from 'fs';
|
2
|
-
import Path from 'path';
|
3
|
-
/**
|
4
|
-
* Utility for navigator.
|
5
|
-
*/
|
6
|
-
export default class NavigatorUtility {
|
7
|
-
/**
|
8
|
-
* Returns the package version.
|
9
|
-
*
|
10
|
-
* @returns Package version.
|
11
|
-
*/
|
12
|
-
static getHappyDOMVersion() {
|
13
|
-
const content = FS.readFileSync(Path.join(__dirname, '..', '..', 'package.json')).toString();
|
14
|
-
const json = JSON.parse(content);
|
15
|
-
return json.version;
|
16
|
-
}
|
17
|
-
/**
|
18
|
-
* Returns platform.
|
19
|
-
*
|
20
|
-
* @returns Platform.
|
21
|
-
*/
|
22
|
-
static getPlatform() {
|
23
|
-
const platform = process.platform;
|
24
|
-
const platformCapitalized = platform.charAt(0).toUpperCase() + platform.slice(1);
|
25
|
-
return 'X11; ' + platformCapitalized + ' ' + process.arch;
|
26
|
-
}
|
27
|
-
}
|
28
|
-
//# sourceMappingURL=NavigatorUtility.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"NavigatorUtility.js","sourceRoot":"","sources":["../../src/navigator/NavigatorUtility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACpC;;;;OAIG;IACI,MAAM,CAAC,kBAAkB;QAC/B,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC7F,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,WAAW;QACxB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAClC,MAAM,mBAAmB,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjF,OAAO,OAAO,GAAG,mBAAmB,GAAG,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3D,CAAC;CACD"}
|
@@ -1,29 +0,0 @@
|
|
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
|
-
}
|