happy-dom 7.7.1 → 7.8.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 +62 -27
- package/lib/async-task-manager/AsyncTaskManager.d.ts +3 -8
- package/lib/async-task-manager/AsyncTaskManager.js +21 -24
- package/lib/async-task-manager/AsyncTaskManager.js.map +1 -1
- package/lib/cookie/Cookie.d.ts +53 -0
- package/lib/cookie/Cookie.js +146 -0
- package/lib/cookie/Cookie.js.map +1 -0
- package/lib/cookie/CookieJar.d.ts +30 -0
- package/lib/cookie/CookieJar.js +84 -0
- package/lib/cookie/CookieJar.js.map +1 -0
- package/lib/event/IEventListener.d.ts +1 -1
- package/lib/exception/DOMExceptionNameEnum.d.ts +4 -1
- package/lib/exception/DOMExceptionNameEnum.js +3 -0
- package/lib/exception/DOMExceptionNameEnum.js.map +1 -1
- package/lib/fetch/FetchHandler.d.ts +3 -2
- package/lib/fetch/FetchHandler.js +31 -3
- package/lib/fetch/FetchHandler.js.map +1 -1
- package/lib/fetch/RequestInfo.d.ts +5 -0
- package/lib/fetch/RequestInfo.js +3 -0
- package/lib/fetch/RequestInfo.js.map +1 -0
- package/lib/fetch/ResourceFetchHandler.d.ts +2 -2
- package/lib/fetch/ResourceFetchHandler.js +9 -8
- package/lib/fetch/ResourceFetchHandler.js.map +1 -1
- package/lib/index.d.ts +1 -2
- package/lib/index.js +3 -4
- package/lib/index.js.map +1 -1
- package/lib/location/Location.d.ts +2 -1
- package/lib/location/Location.js +4 -7
- package/lib/location/Location.js.map +1 -1
- package/lib/location/RelativeURL.d.ts +3 -1
- package/lib/location/RelativeURL.js +2 -11
- package/lib/location/RelativeURL.js.map +1 -1
- package/lib/nodes/document/Document.d.ts +14 -3
- package/lib/nodes/document/Document.js +21 -6
- package/lib/nodes/document/Document.js.map +1 -1
- package/lib/nodes/document/IDocument.d.ts +2 -0
- package/lib/nodes/html-link-element/HTMLLinkElement.js +5 -2
- 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/nodes/html-script-element/ScriptUtility.js +4 -0
- package/lib/nodes/html-script-element/ScriptUtility.js.map +1 -1
- package/lib/window/IHappyDOMSettings.d.ts +9 -0
- package/lib/window/IHappyDOMSettings.js +3 -0
- package/lib/window/IHappyDOMSettings.js.map +1 -0
- package/lib/window/IWindow.d.ts +15 -6
- package/lib/window/Window.d.ts +18 -3
- package/lib/window/Window.js +26 -4
- package/lib/window/Window.js.map +1 -1
- package/lib/xml-http-request/XMLHttpRequest.d.ts +196 -0
- package/lib/xml-http-request/XMLHttpRequest.js +777 -0
- package/lib/xml-http-request/XMLHttpRequest.js.map +1 -0
- package/lib/xml-http-request/XMLHttpRequestCertificate.d.ts +5 -0
- package/lib/xml-http-request/XMLHttpRequestCertificate.js +55 -0
- package/lib/xml-http-request/XMLHttpRequestCertificate.js.map +1 -0
- package/lib/xml-http-request/XMLHttpRequestEventTarget.d.ts +15 -0
- package/lib/xml-http-request/XMLHttpRequestEventTarget.js +23 -0
- package/lib/xml-http-request/XMLHttpRequestEventTarget.js.map +1 -0
- package/lib/xml-http-request/XMLHttpRequestReadyStateEnum.d.ts +8 -0
- package/lib/xml-http-request/XMLHttpRequestReadyStateEnum.js +12 -0
- package/lib/xml-http-request/XMLHttpRequestReadyStateEnum.js.map +1 -0
- package/lib/xml-http-request/XMLHttpRequestUpload.d.ts +6 -0
- package/lib/xml-http-request/XMLHttpRequestUpload.js +13 -0
- package/lib/xml-http-request/XMLHttpRequestUpload.js.map +1 -0
- package/lib/xml-http-request/XMLHttpResponseTypeEnum.d.ts +8 -0
- package/lib/xml-http-request/XMLHttpResponseTypeEnum.js +12 -0
- package/lib/xml-http-request/XMLHttpResponseTypeEnum.js.map +1 -0
- package/lib/xml-http-request/utilities/XMLHttpRequestSyncRequestScriptBuilder.d.ts +15 -0
- package/lib/xml-http-request/utilities/XMLHttpRequestSyncRequestScriptBuilder.js +55 -0
- package/lib/xml-http-request/utilities/XMLHttpRequestSyncRequestScriptBuilder.js.map +1 -0
- package/lib/xml-http-request/utilities/XMLHttpRequestURLUtility.d.ts +35 -0
- package/lib/xml-http-request/utilities/XMLHttpRequestURLUtility.js +62 -0
- package/lib/xml-http-request/utilities/XMLHttpRequestURLUtility.js.map +1 -0
- package/package.json +2 -2
- package/src/async-task-manager/AsyncTaskManager.ts +24 -26
- package/src/cookie/Cookie.ts +158 -0
- package/src/cookie/CookieJar.ts +82 -0
- package/src/event/IEventListener.ts +1 -1
- package/src/exception/DOMExceptionNameEnum.ts +4 -1
- package/src/fetch/FetchHandler.ts +40 -4
- package/src/fetch/RequestInfo.ts +6 -0
- package/src/fetch/ResourceFetchHandler.ts +10 -8
- package/src/index.ts +1 -2
- package/src/location/Location.ts +3 -3
- package/src/location/RelativeURL.ts +3 -14
- package/src/nodes/document/Document.ts +24 -6
- package/src/nodes/document/IDocument.ts +2 -0
- package/src/nodes/html-link-element/HTMLLinkElement.ts +7 -2
- package/src/nodes/html-script-element/HTMLScriptElement.ts +1 -1
- package/src/nodes/html-script-element/ScriptUtility.ts +8 -0
- package/src/window/IHappyDOMSettings.ts +9 -0
- package/src/window/IWindow.ts +15 -6
- package/src/window/Window.ts +36 -5
- package/src/xml-http-request/XMLHttpRequest.ts +998 -0
- package/src/xml-http-request/XMLHttpRequestCertificate.ts +52 -0
- package/src/xml-http-request/XMLHttpRequestEventTarget.ts +17 -0
- package/src/xml-http-request/XMLHttpRequestReadyStateEnum.ts +9 -0
- package/src/xml-http-request/XMLHttpRequestUpload.ts +6 -0
- package/src/xml-http-request/XMLHttpResponseTypeEnum.ts +9 -0
- package/src/xml-http-request/utilities/XMLHttpRequestSyncRequestScriptBuilder.ts +53 -0
- package/src/xml-http-request/utilities/XMLHttpRequestURLUtility.ts +64 -0
- package/lib/cookie/CookieUtility.d.ts +0 -15
- package/lib/cookie/CookieUtility.js +0 -83
- package/lib/cookie/CookieUtility.js.map +0 -1
- package/lib/location/URL.d.ts +0 -53
- package/lib/location/URL.js +0 -96
- package/lib/location/URL.js.map +0 -1
- package/src/cookie/CookieUtility.ts +0 -87
- package/src/location/URL.ts +0 -102
package/src/window/IWindow.ts
CHANGED
@@ -39,7 +39,7 @@ import KeyboardEvent from '../event/events/KeyboardEvent';
|
|
39
39
|
import ProgressEvent from '../event/events/ProgressEvent';
|
40
40
|
import MediaQueryListEvent from '../event/events/MediaQueryListEvent';
|
41
41
|
import EventTarget from '../event/EventTarget';
|
42
|
-
import URL from '
|
42
|
+
import { URL, URLSearchParams } from 'url';
|
43
43
|
import Location from '../location/Location';
|
44
44
|
import MutationObserver from '../mutation-observer/MutationObserver';
|
45
45
|
import DOMParser from '../dom-parser/DOMParser';
|
@@ -92,14 +92,18 @@ import IRequestInit from '../fetch/IRequestInit';
|
|
92
92
|
import IResponse from '../fetch/IResponse';
|
93
93
|
import Range from '../range/Range';
|
94
94
|
import MediaQueryList from '../match-media/MediaQueryList';
|
95
|
+
import XMLHttpRequest from '../xml-http-request/XMLHttpRequest';
|
96
|
+
import XMLHttpRequestUpload from '../xml-http-request/XMLHttpRequestUpload';
|
97
|
+
import XMLHttpRequestEventTarget from '../xml-http-request/XMLHttpRequestEventTarget';
|
95
98
|
import DOMRect from '../nodes/element/DOMRect';
|
96
99
|
import Window from './Window';
|
97
100
|
import Attr from '../nodes/attr/Attr';
|
98
101
|
import NamedNodeMap from '../named-node-map/NamedNodeMap';
|
99
|
-
import { URLSearchParams } from 'url';
|
100
102
|
import { Performance } from 'perf_hooks';
|
101
103
|
import IElement from '../nodes/element/IElement';
|
102
104
|
import ProcessingInstruction from '../nodes/processing-instruction/ProcessingInstruction';
|
105
|
+
import IHappyDOMSettings from './IHappyDOMSettings';
|
106
|
+
import RequestInfo from '../fetch/RequestInfo';
|
103
107
|
|
104
108
|
/**
|
105
109
|
* Window without dependencies to server side specific packages.
|
@@ -112,6 +116,8 @@ export default interface IWindow extends IEventTarget, NodeJS.Global {
|
|
112
116
|
asyncTaskManager: AsyncTaskManager;
|
113
117
|
setInnerWidth: (width: number) => void;
|
114
118
|
setInnerHeight: (height: number) => void;
|
119
|
+
setURL: (url: string) => void;
|
120
|
+
settings: IHappyDOMSettings;
|
115
121
|
};
|
116
122
|
|
117
123
|
// Global classes
|
@@ -173,6 +179,7 @@ export default interface IWindow extends IEventTarget, NodeJS.Global {
|
|
173
179
|
readonly DataTransferItem: typeof DataTransferItem;
|
174
180
|
readonly DataTransferItemList: typeof DataTransferItemList;
|
175
181
|
readonly URL: typeof URL;
|
182
|
+
readonly URLSearchParams: typeof URLSearchParams;
|
176
183
|
readonly Location: typeof Location;
|
177
184
|
readonly CustomElementRegistry: typeof CustomElementRegistry;
|
178
185
|
readonly Window: typeof Window;
|
@@ -186,7 +193,6 @@ export default interface IWindow extends IEventTarget, NodeJS.Global {
|
|
186
193
|
readonly History: typeof History;
|
187
194
|
readonly Screen: typeof Screen;
|
188
195
|
readonly Storage: typeof Storage;
|
189
|
-
readonly URLSearchParams: typeof URLSearchParams;
|
190
196
|
readonly HTMLCollection: typeof HTMLCollection;
|
191
197
|
readonly NodeList: typeof NodeList;
|
192
198
|
readonly CSSUnitValue: typeof CSSUnitValue;
|
@@ -209,6 +215,9 @@ export default interface IWindow extends IEventTarget, NodeJS.Global {
|
|
209
215
|
readonly Response: { new (body?: unknown | null, init?: IResponseInit): IResponse };
|
210
216
|
readonly Range: typeof Range;
|
211
217
|
readonly DOMRect: typeof DOMRect;
|
218
|
+
readonly XMLHttpRequest: typeof XMLHttpRequest;
|
219
|
+
readonly XMLHttpRequestUpload: typeof XMLHttpRequestUpload;
|
220
|
+
readonly XMLHttpRequestEventTarget: typeof XMLHttpRequestEventTarget;
|
212
221
|
|
213
222
|
// Events
|
214
223
|
onload: (event: Event) => void;
|
@@ -334,13 +343,13 @@ export default interface IWindow extends IEventTarget, NodeJS.Global {
|
|
334
343
|
* @param [init] Init.
|
335
344
|
* @returns Promise.
|
336
345
|
*/
|
337
|
-
fetch(url:
|
346
|
+
fetch(url: RequestInfo, init?: IRequestInit): Promise<IResponse>;
|
338
347
|
|
339
348
|
/**
|
340
349
|
* Creates a Base64-encoded ASCII string from a binary string (i.e., a string in which each character in the string is treated as a byte of binary data).
|
341
350
|
*
|
342
351
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/btoa
|
343
|
-
* @param data
|
352
|
+
* @param data Binary data.
|
344
353
|
* @returns Base64-encoded string.
|
345
354
|
*/
|
346
355
|
btoa(data: unknown): string;
|
@@ -351,7 +360,7 @@ export default interface IWindow extends IEventTarget, NodeJS.Global {
|
|
351
360
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/atob
|
352
361
|
* @see https://infra.spec.whatwg.org/#forgiving-base64-encode.
|
353
362
|
* @see Https://html.spec.whatwg.org/multipage/webappapis.html#btoa.
|
354
|
-
* @param data
|
363
|
+
* @param data Binary string.
|
355
364
|
* @returns An ASCII string containing decoded data from encodedData.
|
356
365
|
*/
|
357
366
|
atob(data: unknown): string;
|
package/src/window/Window.ts
CHANGED
@@ -40,7 +40,7 @@ import KeyboardEvent from '../event/events/KeyboardEvent';
|
|
40
40
|
import ProgressEvent from '../event/events/ProgressEvent';
|
41
41
|
import MediaQueryListEvent from '../event/events/MediaQueryListEvent';
|
42
42
|
import EventTarget from '../event/EventTarget';
|
43
|
-
import URL from '
|
43
|
+
import { URL, URLSearchParams } from 'url';
|
44
44
|
import Location from '../location/Location';
|
45
45
|
import NonImplementedEventTypes from '../event/NonImplementedEventTypes';
|
46
46
|
import MutationObserver from '../mutation-observer/MutationObserver';
|
@@ -97,7 +97,6 @@ import MimeType from '../navigator/MimeType';
|
|
97
97
|
import MimeTypeArray from '../navigator/MimeTypeArray';
|
98
98
|
import Plugin from '../navigator/Plugin';
|
99
99
|
import PluginArray from '../navigator/PluginArray';
|
100
|
-
import { URLSearchParams } from 'url';
|
101
100
|
import FetchHandler from '../fetch/FetchHandler';
|
102
101
|
import { default as RangeImplementation } from '../range/Range';
|
103
102
|
import DOMRect from '../nodes/element/DOMRect';
|
@@ -105,12 +104,17 @@ import VMGlobalPropertyScript from './VMGlobalPropertyScript';
|
|
105
104
|
import * as PerfHooks from 'perf_hooks';
|
106
105
|
import VM from 'vm';
|
107
106
|
import { Buffer } from 'buffer';
|
107
|
+
import XMLHttpRequestImplementation from '../xml-http-request/XMLHttpRequest';
|
108
|
+
import XMLHttpRequestUpload from '../xml-http-request/XMLHttpRequestUpload';
|
109
|
+
import XMLHttpRequestEventTarget from '../xml-http-request/XMLHttpRequestEventTarget';
|
108
110
|
import Base64 from '../base64/Base64';
|
109
111
|
import IDocument from '../nodes/document/IDocument';
|
110
112
|
import Attr from '../nodes/attr/Attr';
|
111
113
|
import NamedNodeMap from '../named-node-map/NamedNodeMap';
|
112
114
|
import IElement from '../nodes/element/IElement';
|
113
115
|
import ProcessingInstruction from '../nodes/processing-instruction/ProcessingInstruction';
|
116
|
+
import IHappyDOMSettings from './IHappyDOMSettings';
|
117
|
+
import RequestInfo from '../fetch/RequestInfo';
|
114
118
|
|
115
119
|
const ORIGINAL_SET_TIMEOUT = setTimeout;
|
116
120
|
const ORIGINAL_CLEAR_TIMEOUT = clearTimeout;
|
@@ -144,6 +148,15 @@ export default class Window extends EventTarget implements IWindow {
|
|
144
148
|
(<number>this.innerHeight) = height;
|
145
149
|
this.dispatchEvent(new Event('resize'));
|
146
150
|
}
|
151
|
+
},
|
152
|
+
setURL: (url: string) => {
|
153
|
+
this.location.href = url;
|
154
|
+
},
|
155
|
+
settings: {
|
156
|
+
disableJavaScriptEvaluation: false,
|
157
|
+
disableJavaScriptFileLoading: false,
|
158
|
+
disableCSSFileLoading: false,
|
159
|
+
enableFileSystemHttpRequests: false
|
147
160
|
}
|
148
161
|
};
|
149
162
|
|
@@ -241,6 +254,9 @@ export default class Window extends EventTarget implements IWindow {
|
|
241
254
|
public readonly Response: {
|
242
255
|
new (body?: NodeJS.ReadableStream | null, init?: IResponseInit): IResponse;
|
243
256
|
};
|
257
|
+
public readonly XMLHttpRequestUpload = XMLHttpRequestUpload;
|
258
|
+
public readonly XMLHttpRequestEventTarget = XMLHttpRequestEventTarget;
|
259
|
+
public readonly XMLHttpRequest;
|
244
260
|
public readonly DOMParser;
|
245
261
|
public readonly Range;
|
246
262
|
public readonly FileReader;
|
@@ -346,8 +362,14 @@ export default class Window extends EventTarget implements IWindow {
|
|
346
362
|
* @param [options.innerWidth] Inner width.
|
347
363
|
* @param [options.innerHeight] Inner height.
|
348
364
|
* @param [options.url] URL.
|
365
|
+
* @param [options.settings] Settings.
|
349
366
|
*/
|
350
|
-
constructor(options?: {
|
367
|
+
constructor(options?: {
|
368
|
+
innerWidth?: number;
|
369
|
+
innerHeight?: number;
|
370
|
+
url?: string;
|
371
|
+
settings?: IHappyDOMSettings;
|
372
|
+
}) {
|
351
373
|
super();
|
352
374
|
|
353
375
|
this.customElements = new CustomElementRegistry();
|
@@ -365,6 +387,10 @@ export default class Window extends EventTarget implements IWindow {
|
|
365
387
|
this.location.href = options.url;
|
366
388
|
}
|
367
389
|
|
390
|
+
if (options?.settings) {
|
391
|
+
this.happyDOM.settings = Object.assign(this.happyDOM.settings, options.settings);
|
392
|
+
}
|
393
|
+
|
368
394
|
this._setTimeout = ORIGINAL_SET_TIMEOUT;
|
369
395
|
this._clearTimeout = ORIGINAL_CLEAR_TIMEOUT;
|
370
396
|
this._setInterval = ORIGINAL_SET_INTERVAL;
|
@@ -413,6 +439,7 @@ export default class Window extends EventTarget implements IWindow {
|
|
413
439
|
FileReaderImplementation._ownerDocument = document;
|
414
440
|
DOMParserImplementation._ownerDocument = document;
|
415
441
|
RangeImplementation._ownerDocument = document;
|
442
|
+
XMLHttpRequestImplementation._ownerDocument = document;
|
416
443
|
|
417
444
|
/* eslint-disable jsdoc/require-jsdoc */
|
418
445
|
class Response extends ResponseImplementation {
|
@@ -430,10 +457,13 @@ export default class Window extends EventTarget implements IWindow {
|
|
430
457
|
class DOMParser extends DOMParserImplementation {
|
431
458
|
public static _ownerDocument: IDocument = document;
|
432
459
|
}
|
433
|
-
class
|
460
|
+
class XMLHttpRequest extends XMLHttpRequestImplementation {
|
434
461
|
public static _ownerDocument: IDocument = document;
|
435
462
|
}
|
436
463
|
|
464
|
+
class Range extends RangeImplementation {
|
465
|
+
public static _ownerDocument: IDocument = document;
|
466
|
+
}
|
437
467
|
/* eslint-enable jsdoc/require-jsdoc */
|
438
468
|
|
439
469
|
this.Response = Response;
|
@@ -441,6 +471,7 @@ export default class Window extends EventTarget implements IWindow {
|
|
441
471
|
this.Image = Image;
|
442
472
|
this.FileReader = FileReader;
|
443
473
|
this.DOMParser = DOMParser;
|
474
|
+
this.XMLHttpRequest = XMLHttpRequest;
|
444
475
|
this.Range = Range;
|
445
476
|
|
446
477
|
this._setupVMContext();
|
@@ -629,7 +660,7 @@ export default class Window extends EventTarget implements IWindow {
|
|
629
660
|
* @param [init] Init.
|
630
661
|
* @returns Promise.
|
631
662
|
*/
|
632
|
-
public async fetch(url:
|
663
|
+
public async fetch(url: RequestInfo, init?: IRequestInit): Promise<IResponse> {
|
633
664
|
return await FetchHandler.fetch(this.document, url, init);
|
634
665
|
}
|
635
666
|
|