happy-dom 12.0.1 → 12.1.1

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.

Files changed (82) hide show
  1. package/cjs/css/declaration/element-style/CSSStyleDeclarationElementStyle.cjs +13 -0
  2. package/cjs/css/declaration/element-style/CSSStyleDeclarationElementStyle.cjs.map +1 -1
  3. package/cjs/css/declaration/element-style/CSSStyleDeclarationElementStyle.d.ts.map +1 -1
  4. package/cjs/css/declaration/element-style/config/CSSStyleDeclarationElementDefaultCSS.cjs +4 -1
  5. package/cjs/css/declaration/element-style/config/CSSStyleDeclarationElementDefaultCSS.cjs.map +1 -1
  6. package/cjs/css/declaration/element-style/config/CSSStyleDeclarationElementDefaultCSS.d.ts +4 -1
  7. package/cjs/css/declaration/element-style/config/CSSStyleDeclarationElementDefaultCSS.d.ts.map +1 -1
  8. package/cjs/event/EventTarget.cjs +9 -5
  9. package/cjs/event/EventTarget.cjs.map +1 -1
  10. package/cjs/event/EventTarget.d.ts.map +1 -1
  11. package/cjs/nodes/html-dialog-element/HTMLDialogElement.cjs +14 -1
  12. package/cjs/nodes/html-dialog-element/HTMLDialogElement.cjs.map +1 -1
  13. package/cjs/nodes/html-dialog-element/HTMLDialogElement.d.ts +6 -0
  14. package/cjs/nodes/html-dialog-element/HTMLDialogElement.d.ts.map +1 -1
  15. package/cjs/nodes/html-link-element/HTMLLinkElementUtility.cjs +21 -4
  16. package/cjs/nodes/html-link-element/HTMLLinkElementUtility.cjs.map +1 -1
  17. package/cjs/nodes/html-link-element/HTMLLinkElementUtility.d.ts.map +1 -1
  18. package/cjs/nodes/html-script-element/HTMLScriptElement.cjs +6 -1
  19. package/cjs/nodes/html-script-element/HTMLScriptElement.cjs.map +1 -1
  20. package/cjs/nodes/html-script-element/HTMLScriptElement.d.ts.map +1 -1
  21. package/cjs/nodes/html-script-element/HTMLScriptElementUtility.cjs +48 -8
  22. package/cjs/nodes/html-script-element/HTMLScriptElementUtility.cjs.map +1 -1
  23. package/cjs/nodes/html-script-element/HTMLScriptElementUtility.d.ts.map +1 -1
  24. package/cjs/version.cjs +1 -1
  25. package/cjs/window/IHappyDOMOptions.d.ts +1 -0
  26. package/cjs/window/IHappyDOMOptions.d.ts.map +1 -1
  27. package/cjs/window/IHappyDOMSettings.d.ts +1 -0
  28. package/cjs/window/IHappyDOMSettings.d.ts.map +1 -1
  29. package/cjs/window/Window.cjs +19 -3
  30. package/cjs/window/Window.cjs.map +1 -1
  31. package/cjs/window/Window.d.ts.map +1 -1
  32. package/cjs/window/WindowErrorUtility.cjs +1 -23
  33. package/cjs/window/WindowErrorUtility.cjs.map +1 -1
  34. package/cjs/window/WindowErrorUtility.d.ts +1 -12
  35. package/cjs/window/WindowErrorUtility.d.ts.map +1 -1
  36. package/lib/css/declaration/element-style/CSSStyleDeclarationElementStyle.d.ts.map +1 -1
  37. package/lib/css/declaration/element-style/CSSStyleDeclarationElementStyle.js +13 -0
  38. package/lib/css/declaration/element-style/CSSStyleDeclarationElementStyle.js.map +1 -1
  39. package/lib/css/declaration/element-style/config/CSSStyleDeclarationElementDefaultCSS.d.ts +4 -1
  40. package/lib/css/declaration/element-style/config/CSSStyleDeclarationElementDefaultCSS.d.ts.map +1 -1
  41. package/lib/css/declaration/element-style/config/CSSStyleDeclarationElementDefaultCSS.js +4 -1
  42. package/lib/css/declaration/element-style/config/CSSStyleDeclarationElementDefaultCSS.js.map +1 -1
  43. package/lib/event/EventTarget.d.ts.map +1 -1
  44. package/lib/event/EventTarget.js +9 -5
  45. package/lib/event/EventTarget.js.map +1 -1
  46. package/lib/nodes/html-dialog-element/HTMLDialogElement.d.ts +6 -0
  47. package/lib/nodes/html-dialog-element/HTMLDialogElement.d.ts.map +1 -1
  48. package/lib/nodes/html-dialog-element/HTMLDialogElement.js +14 -1
  49. package/lib/nodes/html-dialog-element/HTMLDialogElement.js.map +1 -1
  50. package/lib/nodes/html-link-element/HTMLLinkElementUtility.d.ts.map +1 -1
  51. package/lib/nodes/html-link-element/HTMLLinkElementUtility.js +21 -4
  52. package/lib/nodes/html-link-element/HTMLLinkElementUtility.js.map +1 -1
  53. package/lib/nodes/html-script-element/HTMLScriptElement.d.ts.map +1 -1
  54. package/lib/nodes/html-script-element/HTMLScriptElement.js +6 -1
  55. package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
  56. package/lib/nodes/html-script-element/HTMLScriptElementUtility.d.ts.map +1 -1
  57. package/lib/nodes/html-script-element/HTMLScriptElementUtility.js +48 -8
  58. package/lib/nodes/html-script-element/HTMLScriptElementUtility.js.map +1 -1
  59. package/lib/version.js +1 -1
  60. package/lib/window/IHappyDOMOptions.d.ts +1 -0
  61. package/lib/window/IHappyDOMOptions.d.ts.map +1 -1
  62. package/lib/window/IHappyDOMSettings.d.ts +1 -0
  63. package/lib/window/IHappyDOMSettings.d.ts.map +1 -1
  64. package/lib/window/Window.d.ts.map +1 -1
  65. package/lib/window/Window.js +19 -3
  66. package/lib/window/Window.js.map +1 -1
  67. package/lib/window/WindowErrorUtility.d.ts +1 -12
  68. package/lib/window/WindowErrorUtility.d.ts.map +1 -1
  69. package/lib/window/WindowErrorUtility.js +1 -23
  70. package/lib/window/WindowErrorUtility.js.map +1 -1
  71. package/package.json +4 -4
  72. package/src/css/declaration/element-style/CSSStyleDeclarationElementStyle.ts +18 -0
  73. package/src/css/declaration/element-style/config/CSSStyleDeclarationElementDefaultCSS.ts +4 -1
  74. package/src/event/EventTarget.ts +13 -5
  75. package/src/nodes/html-dialog-element/HTMLDialogElement.ts +14 -1
  76. package/src/nodes/html-link-element/HTMLLinkElementUtility.ts +23 -14
  77. package/src/nodes/html-script-element/HTMLScriptElement.ts +7 -3
  78. package/src/nodes/html-script-element/HTMLScriptElementUtility.ts +51 -22
  79. package/src/window/IHappyDOMOptions.ts +1 -0
  80. package/src/window/IHappyDOMSettings.ts +1 -0
  81. package/src/window/Window.ts +21 -7
  82. package/src/window/WindowErrorUtility.ts +1 -27
@@ -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
- WindowErrorUtility.dispatchError(
29
- element,
30
- new DOMException(
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
- const code = await WindowErrorUtility.captureErrorAsync<string>(
42
- element,
43
- async () => await ResourceFetch.fetch(element.ownerDocument, src)
44
- );
42
+ let code: string | null = null;
43
+ let error: Error | null = null;
45
44
 
46
- if (code) {
47
- WindowErrorUtility.captureErrorSync(element.ownerDocument.defaultView, () =>
48
- element.ownerDocument.defaultView.eval(code)
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
- const code = WindowErrorUtility.captureErrorSync<string>(element, () =>
55
- ResourceFetch.fetchSync(element.ownerDocument, src)
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 (code) {
59
- WindowErrorUtility.captureErrorSync(element.ownerDocument.defaultView, () =>
60
- element.ownerDocument.defaultView.eval(code)
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
  }
@@ -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;
@@ -210,6 +210,7 @@ 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
216
  userAgent: `Mozilla/5.0 (X11; ${
@@ -736,7 +737,11 @@ export default class Window extends EventTarget implements IWindow {
736
737
  public setTimeout(callback: Function, delay = 0, ...args: unknown[]): NodeJS.Timeout {
737
738
  const id = this._setTimeout(() => {
738
739
  this.happyDOM.asyncTaskManager.endTimer(id);
739
- WindowErrorUtility.captureErrorSync(this, () => callback(...args));
740
+ if (this.happyDOM.settings.disableErrorCapturing) {
741
+ callback(...args);
742
+ } else {
743
+ WindowErrorUtility.captureError(this, () => callback(...args));
744
+ }
740
745
  }, delay);
741
746
  this.happyDOM.asyncTaskManager.startTimer(id);
742
747
  return id;
@@ -762,11 +767,15 @@ export default class Window extends EventTarget implements IWindow {
762
767
  */
763
768
  public setInterval(callback: Function, delay = 0, ...args: unknown[]): NodeJS.Timeout {
764
769
  const id = this._setInterval(() => {
765
- WindowErrorUtility.captureErrorSync(
766
- this,
767
- () => callback(...args),
768
- () => this.clearInterval(id)
769
- );
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
+ }
770
779
  }, delay);
771
780
  this.happyDOM.asyncTaskManager.startTimer(id);
772
781
  return id;
@@ -811,8 +820,13 @@ export default class Window extends EventTarget implements IWindow {
811
820
  const taskId = this.happyDOM.asyncTaskManager.startTask(() => (isAborted = true));
812
821
  this._queueMicrotask(() => {
813
822
  if (!isAborted) {
814
- WindowErrorUtility.captureErrorSync(this, <() => unknown>callback);
815
823
  this.happyDOM.asyncTaskManager.endTask(taskId);
824
+
825
+ if (this.happyDOM.settings.disableErrorCapturing) {
826
+ callback();
827
+ } else {
828
+ WindowErrorUtility.captureError(this, <() => unknown>callback);
829
+ }
816
830
  }
817
831
  });
818
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 captureErrorSync<T>(
20
+ public static captureError<T>(
47
21
  elementOrWindow: IWindow | IElement,
48
22
  callback: () => T,
49
23
  cleanup?: () => void