happy-dom 10.0.5 → 10.0.6
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/nodes/element/Element.d.ts +1 -1
- package/cjs/nodes/element/Element.d.ts.map +1 -1
- package/cjs/nodes/html-anchor-element/HTMLAnchorElement.d.ts +1 -1
- package/cjs/nodes/html-anchor-element/HTMLAnchorElement.d.ts.map +1 -1
- package/cjs/nodes/html-button-element/HTMLButtonElement.d.ts +1 -1
- package/cjs/nodes/html-button-element/HTMLButtonElement.d.ts.map +1 -1
- package/cjs/nodes/html-element/HTMLElement.d.ts +1 -1
- package/cjs/nodes/html-element/HTMLElement.d.ts.map +1 -1
- package/cjs/nodes/html-iframe-element/HTMLIFrameElement.cjs +19 -79
- package/cjs/nodes/html-iframe-element/HTMLIFrameElement.cjs.map +1 -1
- package/cjs/nodes/html-iframe-element/HTMLIFrameElement.d.ts +6 -1
- package/cjs/nodes/html-iframe-element/HTMLIFrameElement.d.ts.map +1 -1
- package/cjs/nodes/html-iframe-element/HTMLIFrameUtility.cjs +74 -0
- package/cjs/nodes/html-iframe-element/HTMLIFrameUtility.cjs.map +1 -0
- package/cjs/nodes/html-iframe-element/HTMLIFrameUtility.d.ts +13 -0
- package/cjs/nodes/html-iframe-element/HTMLIFrameUtility.d.ts.map +1 -0
- package/cjs/nodes/html-input-element/HTMLInputElement.d.ts +1 -1
- package/cjs/nodes/html-input-element/HTMLInputElement.d.ts.map +1 -1
- package/cjs/nodes/html-link-element/HTMLLinkElement.d.ts +1 -1
- package/cjs/nodes/html-link-element/HTMLLinkElement.d.ts.map +1 -1
- package/cjs/nodes/html-link-element/HTMLLinkElementUtility.cjs +1 -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-option-element/HTMLOptionElement.d.ts +1 -1
- package/cjs/nodes/html-option-element/HTMLOptionElement.d.ts.map +1 -1
- package/cjs/nodes/html-script-element/HTMLScriptElement.d.ts +1 -1
- package/cjs/nodes/html-script-element/HTMLScriptElement.d.ts.map +1 -1
- package/cjs/nodes/html-script-element/HTMLScriptElementUtility.cjs +1 -4
- 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-select-element/HTMLSelectElement.d.ts +1 -1
- package/cjs/nodes/html-select-element/HTMLSelectElement.d.ts.map +1 -1
- package/cjs/nodes/html-text-area-element/HTMLTextAreaElement.d.ts +1 -1
- package/cjs/nodes/html-text-area-element/HTMLTextAreaElement.d.ts.map +1 -1
- package/cjs/nodes/svg-element/SVGElement.d.ts +1 -1
- package/cjs/nodes/svg-element/SVGElement.d.ts.map +1 -1
- package/cjs/window/Window.cjs +2 -2
- package/cjs/window/Window.cjs.map +1 -1
- package/cjs/window/Window.d.ts.map +1 -1
- package/lib/nodes/element/Element.d.ts +1 -1
- package/lib/nodes/element/Element.d.ts.map +1 -1
- package/lib/nodes/html-anchor-element/HTMLAnchorElement.d.ts +1 -1
- package/lib/nodes/html-anchor-element/HTMLAnchorElement.d.ts.map +1 -1
- package/lib/nodes/html-button-element/HTMLButtonElement.d.ts +1 -1
- package/lib/nodes/html-button-element/HTMLButtonElement.d.ts.map +1 -1
- package/lib/nodes/html-element/HTMLElement.d.ts +1 -1
- package/lib/nodes/html-element/HTMLElement.d.ts.map +1 -1
- package/lib/nodes/html-iframe-element/HTMLIFrameElement.d.ts +6 -1
- package/lib/nodes/html-iframe-element/HTMLIFrameElement.d.ts.map +1 -1
- package/lib/nodes/html-iframe-element/HTMLIFrameElement.js +19 -79
- package/lib/nodes/html-iframe-element/HTMLIFrameElement.js.map +1 -1
- package/lib/nodes/html-iframe-element/HTMLIFrameUtility.d.ts +13 -0
- package/lib/nodes/html-iframe-element/HTMLIFrameUtility.d.ts.map +1 -0
- package/lib/nodes/html-iframe-element/HTMLIFrameUtility.js +68 -0
- package/lib/nodes/html-iframe-element/HTMLIFrameUtility.js.map +1 -0
- package/lib/nodes/html-input-element/HTMLInputElement.d.ts +1 -1
- package/lib/nodes/html-input-element/HTMLInputElement.d.ts.map +1 -1
- package/lib/nodes/html-link-element/HTMLLinkElement.d.ts +1 -1
- package/lib/nodes/html-link-element/HTMLLinkElement.d.ts.map +1 -1
- package/lib/nodes/html-link-element/HTMLLinkElementUtility.d.ts.map +1 -1
- package/lib/nodes/html-link-element/HTMLLinkElementUtility.js +1 -4
- package/lib/nodes/html-link-element/HTMLLinkElementUtility.js.map +1 -1
- package/lib/nodes/html-option-element/HTMLOptionElement.d.ts +1 -1
- package/lib/nodes/html-option-element/HTMLOptionElement.d.ts.map +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.d.ts +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.d.ts.map +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElementUtility.d.ts.map +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElementUtility.js +1 -4
- package/lib/nodes/html-script-element/HTMLScriptElementUtility.js.map +1 -1
- package/lib/nodes/html-select-element/HTMLSelectElement.d.ts +1 -1
- package/lib/nodes/html-select-element/HTMLSelectElement.d.ts.map +1 -1
- package/lib/nodes/html-text-area-element/HTMLTextAreaElement.d.ts +1 -1
- package/lib/nodes/html-text-area-element/HTMLTextAreaElement.d.ts.map +1 -1
- package/lib/nodes/svg-element/SVGElement.d.ts +1 -1
- package/lib/nodes/svg-element/SVGElement.d.ts.map +1 -1
- package/lib/window/Window.d.ts.map +1 -1
- package/lib/window/Window.js +2 -2
- package/lib/window/Window.js.map +1 -1
- package/package.json +1 -1
- package/src/nodes/element/Element.ts +1 -1
- package/src/nodes/html-anchor-element/HTMLAnchorElement.ts +1 -1
- package/src/nodes/html-button-element/HTMLButtonElement.ts +1 -1
- package/src/nodes/html-element/HTMLElement.ts +1 -1
- package/src/nodes/html-iframe-element/HTMLIFrameElement.ts +23 -79
- package/src/nodes/html-iframe-element/HTMLIFrameUtility.ts +86 -0
- package/src/nodes/html-input-element/HTMLInputElement.ts +1 -1
- package/src/nodes/html-link-element/HTMLLinkElement.ts +1 -1
- package/src/nodes/html-link-element/HTMLLinkElementUtility.ts +1 -6
- package/src/nodes/html-option-element/HTMLOptionElement.ts +1 -1
- package/src/nodes/html-script-element/HTMLScriptElement.ts +1 -1
- package/src/nodes/html-script-element/HTMLScriptElementUtility.ts +1 -6
- package/src/nodes/html-select-element/HTMLSelectElement.ts +1 -1
- package/src/nodes/html-text-area-element/HTMLTextAreaElement.ts +1 -1
- package/src/nodes/svg-element/SVGElement.ts +1 -1
- package/src/window/Window.ts +9 -7
@@ -1,13 +1,12 @@
|
|
1
|
-
import { URL } from 'url';
|
2
1
|
import Event from '../../event/Event.js';
|
3
|
-
import ErrorEvent from '../../event/events/ErrorEvent.js';
|
4
2
|
import IWindow from '../../window/IWindow.js';
|
5
|
-
import Window from '../../window/Window.js';
|
6
3
|
import IDocument from '../document/IDocument.js';
|
7
4
|
import HTMLElement from '../html-element/HTMLElement.js';
|
8
5
|
import INode from '../node/INode.js';
|
9
6
|
import IFrameCrossOriginWindow from './IFrameCrossOriginWindow.js';
|
10
7
|
import IHTMLIFrameElement from './IHTMLIFrameElement.js';
|
8
|
+
import HTMLIFrameUtility from './HTMLIFrameUtility.js';
|
9
|
+
import IAttr from '../attr/IAttr.js';
|
11
10
|
|
12
11
|
/**
|
13
12
|
* HTML Iframe Element.
|
@@ -20,8 +19,8 @@ export default class HTMLIFrameElement extends HTMLElement implements IHTMLIFram
|
|
20
19
|
public onload: (event: Event) => void | null = null;
|
21
20
|
public onerror: (event: Event) => void | null = null;
|
22
21
|
|
23
|
-
//
|
24
|
-
|
22
|
+
// Internal properties
|
23
|
+
public _contentWindow: IWindow | IFrameCrossOriginWindow | null = null;
|
25
24
|
|
26
25
|
/**
|
27
26
|
* Returns source.
|
@@ -155,7 +154,7 @@ export default class HTMLIFrameElement extends HTMLElement implements IHTMLIFram
|
|
155
154
|
* @returns Content document.
|
156
155
|
*/
|
157
156
|
public get contentDocument(): IDocument | null {
|
158
|
-
return (<IWindow>this
|
157
|
+
return (<IWindow>this._contentWindow)?.document || null;
|
159
158
|
}
|
160
159
|
|
161
160
|
/**
|
@@ -164,7 +163,7 @@ export default class HTMLIFrameElement extends HTMLElement implements IHTMLIFram
|
|
164
163
|
* @returns Content window.
|
165
164
|
*/
|
166
165
|
public get contentWindow(): IWindow | IFrameCrossOriginWindow | null {
|
167
|
-
return this
|
166
|
+
return this._contentWindow;
|
168
167
|
}
|
169
168
|
|
170
169
|
/**
|
@@ -176,81 +175,26 @@ export default class HTMLIFrameElement extends HTMLElement implements IHTMLIFram
|
|
176
175
|
|
177
176
|
super._connectToNode(parentNode);
|
178
177
|
|
179
|
-
if (
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
) {
|
184
|
-
const src = this.src;
|
185
|
-
|
186
|
-
if (src !== null) {
|
187
|
-
const contentWindow = new (<typeof Window>this.ownerDocument.defaultView.constructor)({
|
188
|
-
url: src,
|
189
|
-
settings: {
|
190
|
-
...this.ownerDocument.defaultView.happyDOM.settings
|
191
|
-
}
|
192
|
-
});
|
193
|
-
|
194
|
-
(<IWindow>contentWindow.parent) = this.ownerDocument.defaultView;
|
195
|
-
(<IWindow>contentWindow.top) = this.ownerDocument.defaultView;
|
196
|
-
|
197
|
-
if (src === 'about:blank') {
|
198
|
-
this.#contentWindow = contentWindow;
|
199
|
-
return;
|
200
|
-
}
|
201
|
-
|
202
|
-
if (src.startsWith('javascript:')) {
|
203
|
-
this.#contentWindow = contentWindow;
|
204
|
-
this.#contentWindow.eval(src.replace('javascript:', ''));
|
205
|
-
return;
|
206
|
-
}
|
207
|
-
|
208
|
-
const originURL = this.ownerDocument.defaultView.location;
|
209
|
-
const targetURL = new URL(src, originURL);
|
210
|
-
const isCORS =
|
211
|
-
(originURL.hostname !== targetURL.hostname &&
|
212
|
-
!originURL.hostname.endsWith(targetURL.hostname)) ||
|
213
|
-
originURL.protocol !== targetURL.protocol;
|
178
|
+
if (isParentConnected && isConnected !== isParentConnected) {
|
179
|
+
HTMLIFrameUtility.loadPage(this);
|
180
|
+
}
|
181
|
+
}
|
214
182
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
})
|
221
|
-
);
|
222
|
-
this.ownerDocument.defaultView.dispatchEvent(
|
223
|
-
new ErrorEvent('error', {
|
224
|
-
message: error.message,
|
225
|
-
error
|
226
|
-
})
|
227
|
-
);
|
228
|
-
if (
|
229
|
-
!this['_listeners']['error'] &&
|
230
|
-
!this.ownerDocument.defaultView['_listeners']['error']
|
231
|
-
) {
|
232
|
-
this.ownerDocument.defaultView.console.error(error);
|
233
|
-
}
|
234
|
-
};
|
183
|
+
/**
|
184
|
+
* @override
|
185
|
+
*/
|
186
|
+
public override setAttributeNode(attribute: IAttr): IAttr | null {
|
187
|
+
const replacedAttribute = super.setAttributeNode(attribute);
|
235
188
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
.then((text) => {
|
243
|
-
this.#contentWindow = isCORS
|
244
|
-
? new IFrameCrossOriginWindow(this.ownerDocument.defaultView, contentWindow)
|
245
|
-
: contentWindow;
|
246
|
-
contentWindow.document.write(text);
|
247
|
-
this.dispatchEvent(new Event('load'));
|
248
|
-
})
|
249
|
-
.catch(onError);
|
250
|
-
})
|
251
|
-
.catch(onError);
|
252
|
-
}
|
189
|
+
if (
|
190
|
+
attribute.name === 'src' &&
|
191
|
+
attribute.value &&
|
192
|
+
attribute.value !== replacedAttribute?.value
|
193
|
+
) {
|
194
|
+
HTMLIFrameUtility.loadPage(this);
|
253
195
|
}
|
196
|
+
|
197
|
+
return replacedAttribute;
|
254
198
|
}
|
255
199
|
|
256
200
|
/**
|
@@ -0,0 +1,86 @@
|
|
1
|
+
import { URL } from 'url';
|
2
|
+
import Event from '../../event/Event.js';
|
3
|
+
import ErrorEvent from '../../event/events/ErrorEvent.js';
|
4
|
+
import IWindow from '../../window/IWindow.js';
|
5
|
+
import Window from '../../window/Window.js';
|
6
|
+
import IFrameCrossOriginWindow from './IFrameCrossOriginWindow.js';
|
7
|
+
import HTMLIFrameElement from './HTMLIFrameElement.js';
|
8
|
+
|
9
|
+
/**
|
10
|
+
* HTML Iframe Utility.
|
11
|
+
*/
|
12
|
+
export default class HTMLIFrameUtility {
|
13
|
+
/**
|
14
|
+
* Loads an iframe page.
|
15
|
+
*
|
16
|
+
* @param element
|
17
|
+
*/
|
18
|
+
public static async loadPage(element: HTMLIFrameElement): Promise<void> {
|
19
|
+
if (
|
20
|
+
element.isConnected &&
|
21
|
+
!element.ownerDocument.defaultView.happyDOM.settings.disableIframePageLoading
|
22
|
+
) {
|
23
|
+
const src = element.src;
|
24
|
+
|
25
|
+
if (src) {
|
26
|
+
const contentWindow = new (<typeof Window>element.ownerDocument.defaultView.constructor)({
|
27
|
+
url: src,
|
28
|
+
settings: {
|
29
|
+
...element.ownerDocument.defaultView.happyDOM.settings
|
30
|
+
}
|
31
|
+
});
|
32
|
+
|
33
|
+
(<IWindow>contentWindow.parent) = element.ownerDocument.defaultView;
|
34
|
+
(<IWindow>contentWindow.top) = element.ownerDocument.defaultView;
|
35
|
+
|
36
|
+
if (src === 'about:blank') {
|
37
|
+
element._contentWindow = contentWindow;
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
|
41
|
+
if (src.startsWith('javascript:')) {
|
42
|
+
element._contentWindow = contentWindow;
|
43
|
+
element._contentWindow.eval(src.replace('javascript:', ''));
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
|
47
|
+
const originURL = element.ownerDocument.defaultView.location;
|
48
|
+
const targetURL = new URL(src, originURL);
|
49
|
+
const isCORS =
|
50
|
+
(originURL.hostname !== targetURL.hostname &&
|
51
|
+
!originURL.hostname.endsWith(targetURL.hostname)) ||
|
52
|
+
originURL.protocol !== targetURL.protocol;
|
53
|
+
|
54
|
+
let responseText: string;
|
55
|
+
|
56
|
+
element._contentWindow = null;
|
57
|
+
|
58
|
+
try {
|
59
|
+
const response = await element.ownerDocument.defaultView.fetch(src);
|
60
|
+
responseText = await response.text();
|
61
|
+
} catch (error) {
|
62
|
+
element.dispatchEvent(
|
63
|
+
new ErrorEvent('error', {
|
64
|
+
message: error.message,
|
65
|
+
error
|
66
|
+
})
|
67
|
+
);
|
68
|
+
element.ownerDocument.defaultView.dispatchEvent(
|
69
|
+
new ErrorEvent('error', {
|
70
|
+
message: error.message,
|
71
|
+
error
|
72
|
+
})
|
73
|
+
);
|
74
|
+
element.ownerDocument.defaultView.console.error(error);
|
75
|
+
return;
|
76
|
+
}
|
77
|
+
|
78
|
+
element._contentWindow = isCORS
|
79
|
+
? new IFrameCrossOriginWindow(element.ownerDocument.defaultView, contentWindow)
|
80
|
+
: contentWindow;
|
81
|
+
contentWindow.document.write(responseText);
|
82
|
+
element.dispatchEvent(new Event('load'));
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
@@ -1074,7 +1074,7 @@ export default class HTMLInputElement extends HTMLElement implements IHTMLInputE
|
|
1074
1074
|
/**
|
1075
1075
|
* @override
|
1076
1076
|
*/
|
1077
|
-
public override setAttributeNode(attribute: IAttr): IAttr {
|
1077
|
+
public override setAttributeNode(attribute: IAttr): IAttr | null {
|
1078
1078
|
const replacedAttribute = super.setAttributeNode(attribute);
|
1079
1079
|
const oldValue = replacedAttribute ? replacedAttribute.value : null;
|
1080
1080
|
|
@@ -181,7 +181,7 @@ export default class HTMLLinkElement extends HTMLElement implements IHTMLLinkEle
|
|
181
181
|
/**
|
182
182
|
* @override
|
183
183
|
*/
|
184
|
-
public override setAttributeNode(attribute: IAttr): IAttr {
|
184
|
+
public override setAttributeNode(attribute: IAttr): IAttr | null {
|
185
185
|
const replacedAttribute = super.setAttributeNode(attribute);
|
186
186
|
|
187
187
|
if (attribute.name === 'rel' && this._relList) {
|
@@ -72,11 +72,6 @@ export default class HTMLLinkElementUtility {
|
|
72
72
|
})
|
73
73
|
);
|
74
74
|
(<Document>element.ownerDocument)._readyStateManager.endTask();
|
75
|
-
|
76
|
-
!element['_listeners']['error'] &&
|
77
|
-
!element.ownerDocument.defaultView['_listeners']['error']
|
78
|
-
) {
|
79
|
-
element.ownerDocument.defaultView.console.error(error);
|
80
|
-
}
|
75
|
+
element.ownerDocument.defaultView.console.error(error);
|
81
76
|
}
|
82
77
|
}
|
@@ -120,7 +120,7 @@ export default class HTMLOptionElement extends HTMLElement implements IHTMLOptio
|
|
120
120
|
/**
|
121
121
|
* @override
|
122
122
|
*/
|
123
|
-
public setAttributeNode(attribute: IAttr): IAttr {
|
123
|
+
public setAttributeNode(attribute: IAttr): IAttr | null {
|
124
124
|
const replacedAttribute = super.setAttributeNode(attribute);
|
125
125
|
|
126
126
|
if (
|
@@ -158,7 +158,7 @@ export default class HTMLScriptElement extends HTMLElement implements IHTMLScrip
|
|
158
158
|
* @param attribute Attribute.
|
159
159
|
* @returns Replaced attribute.
|
160
160
|
*/
|
161
|
-
public setAttributeNode(attribute: IAttr): IAttr {
|
161
|
+
public setAttributeNode(attribute: IAttr): IAttr | null {
|
162
162
|
const replacedAttribute = super.setAttributeNode(attribute);
|
163
163
|
|
164
164
|
if (attribute.name === 'src' && attribute.value !== null && this.isConnected) {
|
@@ -104,11 +104,6 @@ export default class HTMLScriptElementUtility {
|
|
104
104
|
error
|
105
105
|
})
|
106
106
|
);
|
107
|
-
|
108
|
-
!element['_listeners']['error'] &&
|
109
|
-
!element.ownerDocument.defaultView['_listeners']['error']
|
110
|
-
) {
|
111
|
-
element.ownerDocument.defaultView.console.error(error);
|
112
|
-
}
|
107
|
+
element.ownerDocument.defaultView.console.error(error);
|
113
108
|
}
|
114
109
|
}
|
@@ -405,7 +405,7 @@ export default class HTMLSelectElement extends HTMLElement implements IHTMLSelec
|
|
405
405
|
/**
|
406
406
|
* @override
|
407
407
|
*/
|
408
|
-
public override setAttributeNode(attribute: IAttr): IAttr {
|
408
|
+
public override setAttributeNode(attribute: IAttr): IAttr | null {
|
409
409
|
const replacedAttribute = super.setAttributeNode(attribute);
|
410
410
|
const oldValue = replacedAttribute ? replacedAttribute.value : null;
|
411
411
|
|
@@ -591,7 +591,7 @@ export default class HTMLTextAreaElement extends HTMLElement implements IHTMLTex
|
|
591
591
|
/**
|
592
592
|
* @override
|
593
593
|
*/
|
594
|
-
public override setAttributeNode(attribute: IAttr): IAttr {
|
594
|
+
public override setAttributeNode(attribute: IAttr): IAttr | null {
|
595
595
|
const replacedAttribute = super.setAttributeNode(attribute);
|
596
596
|
const oldValue = replacedAttribute ? replacedAttribute.value : null;
|
597
597
|
|
@@ -113,7 +113,7 @@ export default class SVGElement extends Element implements ISVGElement {
|
|
113
113
|
/**
|
114
114
|
* @override
|
115
115
|
*/
|
116
|
-
public setAttributeNode(attribute: IAttr): IAttr {
|
116
|
+
public setAttributeNode(attribute: IAttr): IAttr | null {
|
117
117
|
const replacedAttribute = super.setAttributeNode(attribute);
|
118
118
|
|
119
119
|
if (attribute.name === 'style' && this._style) {
|
package/src/window/Window.ts
CHANGED
@@ -845,13 +845,15 @@ export default class Window extends EventTarget implements IWindow {
|
|
845
845
|
);
|
846
846
|
}
|
847
847
|
|
848
|
-
this.
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
848
|
+
this.window.setTimeout(() =>
|
849
|
+
this.dispatchEvent(
|
850
|
+
new MessageEvent('message', {
|
851
|
+
data: message,
|
852
|
+
origin: this.parent.location.origin,
|
853
|
+
source: this.parent,
|
854
|
+
lastEventId: ''
|
855
|
+
})
|
856
|
+
)
|
855
857
|
);
|
856
858
|
}
|
857
859
|
|