happy-dom 8.6.0 → 8.7.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/README.md +11 -1
- package/lib/config/ElementTag.d.ts +2 -1
- package/lib/config/ElementTag.js +2 -1
- package/lib/config/ElementTag.js.map +1 -1
- package/lib/config/NonImplemenetedElementClasses.js +0 -1
- package/lib/config/NonImplemenetedElementClasses.js.map +1 -1
- package/lib/event/IMessagePort.d.ts +23 -0
- package/lib/event/IMessagePort.js +3 -0
- package/lib/event/IMessagePort.js.map +1 -0
- package/lib/event/MessagePort.d.ts +24 -0
- package/lib/event/MessagePort.js +36 -0
- package/lib/event/MessagePort.js.map +1 -0
- package/lib/event/events/IMessageEventInit.d.ts +10 -0
- package/lib/event/events/IMessageEventInit.js +3 -0
- package/lib/event/events/IMessageEventInit.js.map +1 -0
- package/lib/event/events/MessageEvent.d.ts +23 -0
- package/lib/event/events/MessageEvent.js +34 -0
- package/lib/event/events/MessageEvent.js.map +1 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/nodes/html-iframe-element/HTMLIFrameElement.d.ts +126 -0
- package/lib/nodes/html-iframe-element/HTMLIFrameElement.js +246 -0
- package/lib/nodes/html-iframe-element/HTMLIFrameElement.js.map +1 -0
- package/lib/nodes/html-iframe-element/IFrameCrossOriginWindow.d.ts +29 -0
- package/lib/nodes/html-iframe-element/IFrameCrossOriginWindow.js +47 -0
- package/lib/nodes/html-iframe-element/IFrameCrossOriginWindow.js.map +1 -0
- package/lib/nodes/html-iframe-element/IHTMLIFrameElement.d.ts +24 -0
- package/lib/nodes/html-iframe-element/IHTMLIFrameElement.js +3 -0
- package/lib/nodes/html-iframe-element/IHTMLIFrameElement.js.map +1 -0
- package/lib/nodes/html-link-element/HTMLLinkElement.js +2 -1
- package/lib/nodes/html-link-element/HTMLLinkElement.js.map +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.js +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
- package/lib/window/IHappyDOMOptions.d.ts +15 -0
- package/lib/window/IHappyDOMOptions.js +3 -0
- package/lib/window/IHappyDOMOptions.js.map +1 -0
- package/lib/window/IHappyDOMSettings.d.ts +1 -0
- package/lib/window/IWindow.d.ts +13 -0
- package/lib/window/Window.d.ts +17 -7
- package/lib/window/Window.js +33 -0
- package/lib/window/Window.js.map +1 -1
- package/package.json +1 -1
- package/src/config/ElementTag.ts +2 -1
- package/src/config/NonImplemenetedElementClasses.ts +0 -1
- package/src/event/IMessagePort.ts +26 -0
- package/src/event/MessagePort.ts +33 -0
- package/src/event/events/IMessageEventInit.ts +11 -0
- package/src/event/events/MessageEvent.ts +32 -0
- package/src/index.ts +4 -0
- package/src/nodes/html-iframe-element/HTMLIFrameElement.ts +266 -0
- package/src/nodes/html-iframe-element/IFrameCrossOriginWindow.ts +60 -0
- package/src/nodes/html-iframe-element/IHTMLIFrameElement.ts +27 -0
- package/src/nodes/html-link-element/HTMLLinkElement.ts +2 -1
- package/src/nodes/html-script-element/HTMLScriptElement.ts +2 -2
- package/src/window/IHappyDOMOptions.ts +15 -0
- package/src/window/IHappyDOMSettings.ts +1 -0
- package/src/window/IWindow.ts +14 -0
- package/src/window/Window.ts +46 -7
@@ -182,13 +182,13 @@ export default class HTMLScriptElement extends HTMLElement implements IHTMLScrip
|
|
182
182
|
/**
|
183
183
|
* @override
|
184
184
|
*/
|
185
|
-
public _connectToNode(parentNode: INode = null): void {
|
185
|
+
public override _connectToNode(parentNode: INode = null): void {
|
186
186
|
const isConnected = this.isConnected;
|
187
187
|
const isParentConnected = parentNode ? parentNode.isConnected : false;
|
188
188
|
|
189
189
|
super._connectToNode(parentNode);
|
190
190
|
|
191
|
-
if (isConnected !== isParentConnected && this._evaluateScript) {
|
191
|
+
if (isParentConnected && isConnected !== isParentConnected && this._evaluateScript) {
|
192
192
|
const src = this.getAttributeNS(null, 'src');
|
193
193
|
|
194
194
|
if (src !== null) {
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/**
|
2
|
+
* Happy DOM options.
|
3
|
+
*/
|
4
|
+
export default interface IHappyDOMOptions {
|
5
|
+
innerWidth?: number;
|
6
|
+
innerHeight?: number;
|
7
|
+
url?: string;
|
8
|
+
settings?: {
|
9
|
+
disableJavaScriptEvaluation?: boolean;
|
10
|
+
disableJavaScriptFileLoading?: boolean;
|
11
|
+
disableCSSFileLoading?: boolean;
|
12
|
+
disableIframePageLoading?: boolean;
|
13
|
+
enableFileSystemHttpRequests?: boolean;
|
14
|
+
};
|
15
|
+
}
|
package/src/window/IWindow.ts
CHANGED
@@ -24,6 +24,7 @@ import HTMLMediaElement from '../nodes/html-media-element/HTMLMediaElement';
|
|
24
24
|
import HTMLAudioElement from '../nodes/html-audio-element/HTMLAudioElement';
|
25
25
|
import HTMLVideoElement from '../nodes/html-video-element/HTMLVideoElement';
|
26
26
|
import HTMLBaseElement from '../nodes/html-base-element/HTMLBaseElement';
|
27
|
+
import HTMLIFrameElement from '../nodes/html-iframe-element/HTMLIFrameElement';
|
27
28
|
import SVGSVGElement from '../nodes/svg-element/SVGSVGElement';
|
28
29
|
import SVGElement from '../nodes/svg-element/SVGElement';
|
29
30
|
import HTMLScriptElement from '../nodes/html-script-element/HTMLScriptElement';
|
@@ -73,6 +74,8 @@ import InputEvent from '../event/events/InputEvent';
|
|
73
74
|
import UIEvent from '../event/UIEvent';
|
74
75
|
import ErrorEvent from '../event/events/ErrorEvent';
|
75
76
|
import StorageEvent from '../event/events/StorageEvent';
|
77
|
+
import MessageEvent from '../event/events/MessageEvent';
|
78
|
+
import MessagePort from '../event/MessagePort';
|
76
79
|
import Screen from '../screen/Screen';
|
77
80
|
import AsyncTaskManager from '../async-task-manager/AsyncTaskManager';
|
78
81
|
import Storage from '../storage/Storage';
|
@@ -142,6 +145,7 @@ export default interface IWindow extends IEventTarget, NodeJS.Global {
|
|
142
145
|
readonly HTMLAudioElement: typeof HTMLAudioElement;
|
143
146
|
readonly HTMLVideoElement: typeof HTMLVideoElement;
|
144
147
|
readonly HTMLBaseElement: typeof HTMLBaseElement;
|
148
|
+
readonly HTMLIFrameElement: typeof HTMLIFrameElement;
|
145
149
|
readonly HTMLDialogElement: typeof HTMLDialogElement;
|
146
150
|
readonly Attr: typeof Attr;
|
147
151
|
readonly NamedNodeMap: typeof NamedNodeMap;
|
@@ -175,6 +179,8 @@ export default interface IWindow extends IEventTarget, NodeJS.Global {
|
|
175
179
|
readonly InputEvent: typeof InputEvent;
|
176
180
|
readonly ErrorEvent: typeof ErrorEvent;
|
177
181
|
readonly StorageEvent: typeof StorageEvent;
|
182
|
+
readonly MessageEvent: typeof MessageEvent;
|
183
|
+
readonly MessagePort: typeof MessagePort;
|
178
184
|
readonly ProgressEvent: typeof ProgressEvent;
|
179
185
|
readonly MediaQueryListEvent: typeof MediaQueryListEvent;
|
180
186
|
readonly EventTarget: typeof EventTarget;
|
@@ -374,4 +380,12 @@ export default interface IWindow extends IEventTarget, NodeJS.Global {
|
|
374
380
|
* @returns An ASCII string containing decoded data from encodedData.
|
375
381
|
*/
|
376
382
|
atob(data: unknown): string;
|
383
|
+
|
384
|
+
/**
|
385
|
+
* Safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.
|
386
|
+
*
|
387
|
+
* @param message Message.
|
388
|
+
* @param listener Listener.
|
389
|
+
*/
|
390
|
+
postMessage(message: unknown, targetOrigin?: string, transfer?: unknown[]): void;
|
377
391
|
}
|
package/src/window/Window.ts
CHANGED
@@ -25,6 +25,7 @@ import HTMLMediaElement from '../nodes/html-media-element/HTMLMediaElement';
|
|
25
25
|
import HTMLAudioElement from '../nodes/html-audio-element/HTMLAudioElement';
|
26
26
|
import HTMLVideoElement from '../nodes/html-video-element/HTMLVideoElement';
|
27
27
|
import HTMLBaseElement from '../nodes/html-base-element/HTMLBaseElement';
|
28
|
+
import HTMLIFrameElement from '../nodes/html-iframe-element/HTMLIFrameElement';
|
28
29
|
import HTMLDialogElement from '../nodes/html-dialog-element/HTMLDialogElement';
|
29
30
|
import SVGSVGElement from '../nodes/svg-element/SVGSVGElement';
|
30
31
|
import SVGElement from '../nodes/svg-element/SVGElement';
|
@@ -39,9 +40,11 @@ import Event from '../event/Event';
|
|
39
40
|
import CustomEvent from '../event/events/CustomEvent';
|
40
41
|
import AnimationEvent from '../event/events/AnimationEvent';
|
41
42
|
import KeyboardEvent from '../event/events/KeyboardEvent';
|
43
|
+
import MessageEvent from '../event/events/MessageEvent';
|
42
44
|
import ProgressEvent from '../event/events/ProgressEvent';
|
43
45
|
import MediaQueryListEvent from '../event/events/MediaQueryListEvent';
|
44
46
|
import EventTarget from '../event/EventTarget';
|
47
|
+
import MessagePort from '../event/MessagePort';
|
45
48
|
import { URL, URLSearchParams } from 'url';
|
46
49
|
import Location from '../location/Location';
|
47
50
|
import NonImplementedEventTypes from '../event/NonImplementedEventTypes';
|
@@ -115,9 +118,10 @@ import Attr from '../nodes/attr/Attr';
|
|
115
118
|
import NamedNodeMap from '../named-node-map/NamedNodeMap';
|
116
119
|
import IElement from '../nodes/element/IElement';
|
117
120
|
import ProcessingInstruction from '../nodes/processing-instruction/ProcessingInstruction';
|
118
|
-
import IHappyDOMSettings from './IHappyDOMSettings';
|
119
121
|
import RequestInfo from '../fetch/RequestInfo';
|
120
122
|
import FileList from '../nodes/html-input-element/FileList';
|
123
|
+
import DOMExceptionNameEnum from '../exception/DOMExceptionNameEnum';
|
124
|
+
import IHappyDOMOptions from './IHappyDOMOptions';
|
121
125
|
|
122
126
|
const ORIGINAL_SET_TIMEOUT = setTimeout;
|
123
127
|
const ORIGINAL_CLEAR_TIMEOUT = clearTimeout;
|
@@ -159,6 +163,7 @@ export default class Window extends EventTarget implements IWindow {
|
|
159
163
|
disableJavaScriptEvaluation: false,
|
160
164
|
disableJavaScriptFileLoading: false,
|
161
165
|
disableCSSFileLoading: false,
|
166
|
+
disableIframePageLoading: false,
|
162
167
|
enableFileSystemHttpRequests: false
|
163
168
|
}
|
164
169
|
};
|
@@ -183,6 +188,7 @@ export default class Window extends EventTarget implements IWindow {
|
|
183
188
|
public readonly HTMLAudioElement = HTMLAudioElement;
|
184
189
|
public readonly HTMLVideoElement = HTMLVideoElement;
|
185
190
|
public readonly HTMLBaseElement = HTMLBaseElement;
|
191
|
+
public readonly HTMLIFrameElement = HTMLIFrameElement;
|
186
192
|
public readonly HTMLDialogElement = HTMLDialogElement;
|
187
193
|
public readonly Attr = Attr;
|
188
194
|
public readonly NamedNodeMap = NamedNodeMap;
|
@@ -208,6 +214,7 @@ export default class Window extends EventTarget implements IWindow {
|
|
208
214
|
public readonly CustomEvent = CustomEvent;
|
209
215
|
public readonly AnimationEvent = AnimationEvent;
|
210
216
|
public readonly KeyboardEvent = KeyboardEvent;
|
217
|
+
public readonly MessageEvent = MessageEvent;
|
211
218
|
public readonly MouseEvent = MouseEvent;
|
212
219
|
public readonly PointerEvent = PointerEvent;
|
213
220
|
public readonly FocusEvent = FocusEvent;
|
@@ -218,6 +225,7 @@ export default class Window extends EventTarget implements IWindow {
|
|
218
225
|
public readonly ProgressEvent = ProgressEvent;
|
219
226
|
public readonly MediaQueryListEvent = MediaQueryListEvent;
|
220
227
|
public readonly EventTarget = EventTarget;
|
228
|
+
public readonly MessagePort = MessagePort;
|
221
229
|
public readonly DataTransfer = DataTransfer;
|
222
230
|
public readonly DataTransferItem = DataTransferItem;
|
223
231
|
public readonly DataTransferItemList = DataTransferItemList;
|
@@ -370,12 +378,7 @@ export default class Window extends EventTarget implements IWindow {
|
|
370
378
|
* @param [options.url] URL.
|
371
379
|
* @param [options.settings] Settings.
|
372
380
|
*/
|
373
|
-
constructor(options?: {
|
374
|
-
innerWidth?: number;
|
375
|
-
innerHeight?: number;
|
376
|
-
url?: string;
|
377
|
-
settings?: IHappyDOMSettings;
|
378
|
-
}) {
|
381
|
+
constructor(options?: IHappyDOMOptions) {
|
379
382
|
super();
|
380
383
|
|
381
384
|
this.customElements = new CustomElementRegistry();
|
@@ -732,6 +735,42 @@ export default class Window extends EventTarget implements IWindow {
|
|
732
735
|
return Base64.atob(data);
|
733
736
|
}
|
734
737
|
|
738
|
+
/**
|
739
|
+
* Safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.
|
740
|
+
*
|
741
|
+
* @param message Message.
|
742
|
+
* @param [targetOrigin=*] Target origin.
|
743
|
+
* @param _transfer Transfer. Not implemented.
|
744
|
+
*/
|
745
|
+
public postMessage(message: unknown, targetOrigin = '*', _transfer?: unknown[]): void {
|
746
|
+
// TODO: Implement transfer.
|
747
|
+
|
748
|
+
if (targetOrigin && targetOrigin !== '*' && this.location.origin !== targetOrigin) {
|
749
|
+
throw new DOMException(
|
750
|
+
`Failed to execute 'postMessage' on 'Window': The target origin provided ('${targetOrigin}') does not match the recipient window\'s origin ('${this.location.origin}').`,
|
751
|
+
DOMExceptionNameEnum.securityError
|
752
|
+
);
|
753
|
+
}
|
754
|
+
|
755
|
+
try {
|
756
|
+
JSON.stringify(message);
|
757
|
+
} catch (error) {
|
758
|
+
throw new DOMException(
|
759
|
+
`Failed to execute 'postMessage' on 'Window': The provided message cannot be serialized.`,
|
760
|
+
DOMExceptionNameEnum.invalidStateError
|
761
|
+
);
|
762
|
+
}
|
763
|
+
|
764
|
+
this.dispatchEvent(
|
765
|
+
new MessageEvent('message', {
|
766
|
+
data: message,
|
767
|
+
origin: this.parent.location.origin,
|
768
|
+
source: this.parent,
|
769
|
+
lastEventId: ''
|
770
|
+
})
|
771
|
+
);
|
772
|
+
}
|
773
|
+
|
735
774
|
/**
|
736
775
|
* Setup of VM context.
|
737
776
|
*/
|