1 |
|
2 |
|
3 | import { EventEmitter } from "events";
|
4 | import { ElementLocation } from "parse5";
|
5 | import { Context } from "vm";
|
6 | import * as tough from "tough-cookie";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | declare module "jsdom" {
|
12 | const toughCookie: typeof tough;
|
13 | class CookieJar extends tough.CookieJar {}
|
14 |
|
15 | interface AbortablePromise<T> extends Promise<T> {
|
16 | abort(): void;
|
17 | }
|
18 |
|
19 | class JSDOM {
|
20 | constructor(html?: string | Buffer | BinaryData, options?: ConstructorOptions);
|
21 |
|
22 | static fromURL(url: string, options?: BaseOptions): Promise<JSDOM>;
|
23 | static fromFile(url: string, options?: FileOptions): Promise<JSDOM>;
|
24 | static fragment(html: string): DocumentFragment;
|
25 |
|
26 | readonly window: DOMWindow;
|
27 | readonly virtualConsole: VirtualConsole;
|
28 | readonly cookieJar: CookieJar;
|
29 |
|
30 | /**
|
31 | * The serialize() method will return the HTML serialization of the document, including the doctype.
|
32 | */
|
33 | serialize(): string;
|
34 |
|
35 | /**
|
36 | * The nodeLocation() method will find where a DOM node is within the source document,
|
37 | * returning the parse5 location info for the node.
|
38 | *
|
39 | * @throws {Error} If the JSDOM was not created with `includeNodeLocations`
|
40 | */
|
41 | nodeLocation(node: Node): ElementLocation | null;
|
42 |
|
43 | |
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | getInternalVMContext(): Context;
|
53 |
|
54 | |
55 |
|
56 |
|
57 | reconfigure(settings: ReconfigureSettings): void;
|
58 | }
|
59 |
|
60 | class ResourceLoader {
|
61 | fetch(url: string, options: FetchOptions): AbortablePromise<Buffer> | null;
|
62 |
|
63 | constructor(obj?: ResourceLoaderConstructorOptions);
|
64 | }
|
65 |
|
66 | class VirtualConsole extends EventEmitter {
|
67 | on<K extends keyof Console>(method: K, callback: Console[K]): this;
|
68 | on(event: "jsdomError", callback: (e: Error) => void): this;
|
69 |
|
70 | sendTo(console: Console, options?: VirtualConsoleSendToOptions): this;
|
71 | }
|
72 |
|
73 | type BinaryData = ArrayBufferLike | NodeJS.ArrayBufferView;
|
74 | interface BaseOptions {
|
75 | |
76 |
|
77 |
|
78 |
|
79 | referrer?: string | undefined;
|
80 |
|
81 | |
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | userAgent?: string | undefined;
|
88 |
|
89 | |
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | includeNodeLocations?: boolean | undefined;
|
99 | runScripts?: "dangerously" | "outside-only" | undefined;
|
100 | resources?: "usable" | ResourceLoader | undefined;
|
101 | virtualConsole?: VirtualConsole | undefined;
|
102 | cookieJar?: CookieJar | undefined;
|
103 |
|
104 | |
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | pretendToBeVisual?: boolean | undefined;
|
114 | beforeParse?(window: DOMWindow): void;
|
115 | }
|
116 |
|
117 | interface FileOptions extends BaseOptions {
|
118 | |
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | url?: string | undefined;
|
125 |
|
126 | |
127 |
|
128 |
|
129 |
|
130 |
|
131 | contentType?: string | undefined;
|
132 | }
|
133 |
|
134 | interface ConstructorOptions extends BaseOptions {
|
135 | |
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | url?: string | undefined;
|
142 |
|
143 | |
144 |
|
145 |
|
146 |
|
147 | contentType?: string | undefined;
|
148 |
|
149 | |
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 | storageQuota?: number | undefined;
|
157 | }
|
158 |
|
159 | interface VirtualConsoleSendToOptions {
|
160 | omitJSDOMErrors: boolean;
|
161 | }
|
162 |
|
163 | interface ReconfigureSettings {
|
164 | windowTop?: DOMWindow | undefined;
|
165 | url?: string | undefined;
|
166 | }
|
167 |
|
168 | interface FetchOptions {
|
169 | cookieJar?: CookieJar | undefined;
|
170 | referrer?: string | undefined;
|
171 | accept?: string | undefined;
|
172 | element?: HTMLScriptElement | HTMLLinkElement | HTMLIFrameElement | HTMLImageElement | undefined;
|
173 | }
|
174 |
|
175 | interface ResourceLoaderConstructorOptions {
|
176 | strictSSL?: boolean | undefined;
|
177 | proxy?: string | undefined;
|
178 | userAgent?: string | undefined;
|
179 | }
|
180 |
|
181 | interface DOMWindow extends Omit<Window, "top" | "self" | "window"> {
|
182 | [key: string]: any;
|
183 |
|
184 |
|
185 | Window: typeof Window;
|
186 | readonly top: DOMWindow;
|
187 | readonly self: DOMWindow;
|
188 | readonly window: DOMWindow;
|
189 |
|
190 |
|
191 | globalThis: DOMWindow;
|
192 | readonly ["Infinity"]: number;
|
193 | readonly ["NaN"]: number;
|
194 | readonly undefined: undefined;
|
195 |
|
196 | eval(script: string): any;
|
197 | parseInt(s: string, radix?: number): number;
|
198 | parseFloat(string: string): number;
|
199 | isNaN(number: number): boolean;
|
200 | isFinite(number: number): boolean;
|
201 | decodeURI(encodedURI: string): string;
|
202 | decodeURIComponent(encodedURIComponent: string): string;
|
203 | encodeURI(uri: string): string;
|
204 | encodeURIComponent(uriComponent: string | number | boolean): string;
|
205 | escape(string: string): string;
|
206 | unescape(string: string): string;
|
207 |
|
208 | Array: typeof Array;
|
209 | ArrayBuffer: typeof ArrayBuffer;
|
210 | Atomics: typeof Atomics;
|
211 | BigInt: typeof BigInt;
|
212 | BigInt64Array: typeof BigInt64Array;
|
213 | BigUint64Array: typeof BigUint64Array;
|
214 | Boolean: typeof Boolean;
|
215 | DataView: typeof DataView;
|
216 | Date: typeof Date;
|
217 | Error: typeof Error;
|
218 | EvalError: typeof EvalError;
|
219 | Float32Array: typeof Float32Array;
|
220 | Float64Array: typeof Float64Array;
|
221 | Function: typeof Function;
|
222 | Int16Array: typeof Int16Array;
|
223 | Int32Array: typeof Int32Array;
|
224 | Int8Array: typeof Int8Array;
|
225 | Intl: typeof Intl;
|
226 | JSON: typeof JSON;
|
227 | Map: typeof Map;
|
228 | Math: typeof Math;
|
229 | Number: typeof Number;
|
230 | Object: typeof Object;
|
231 | Promise: typeof Promise;
|
232 | Proxy: typeof Proxy;
|
233 | RangeError: typeof RangeError;
|
234 | ReferenceError: typeof ReferenceError;
|
235 | Reflect: typeof Reflect;
|
236 | RegExp: typeof RegExp;
|
237 | Set: typeof Set;
|
238 | SharedArrayBuffer: typeof SharedArrayBuffer;
|
239 | String: typeof String;
|
240 | Symbol: typeof Symbol;
|
241 | SyntaxError: typeof SyntaxError;
|
242 | TypeError: typeof TypeError;
|
243 | URIError: typeof URIError;
|
244 | Uint16Array: typeof Uint16Array;
|
245 | Uint32Array: typeof Uint32Array;
|
246 | Uint8Array: typeof Uint8Array;
|
247 | Uint8ClampedArray: typeof Uint8ClampedArray;
|
248 | WeakMap: typeof WeakMap;
|
249 | WeakSet: typeof WeakSet;
|
250 | WebAssembly: typeof WebAssembly;
|
251 |
|
252 |
|
253 | DOMException: typeof DOMException;
|
254 |
|
255 | URL: typeof URL;
|
256 | URLSearchParams: typeof URLSearchParams;
|
257 |
|
258 | EventTarget: typeof EventTarget;
|
259 |
|
260 | NamedNodeMap: typeof NamedNodeMap;
|
261 | Node: typeof Node;
|
262 | Attr: typeof Attr;
|
263 | Element: typeof Element;
|
264 | DocumentFragment: typeof DocumentFragment;
|
265 | DOMImplementation: typeof DOMImplementation;
|
266 | Document: typeof Document;
|
267 | HTMLDocument: typeof HTMLDocument;
|
268 | XMLDocument: typeof XMLDocument;
|
269 | CharacterData: typeof CharacterData;
|
270 | Text: typeof Text;
|
271 | CDATASection: typeof CDATASection;
|
272 | ProcessingInstruction: typeof ProcessingInstruction;
|
273 | Comment: typeof Comment;
|
274 | DocumentType: typeof DocumentType;
|
275 | NodeList: typeof NodeList;
|
276 | HTMLCollection: typeof HTMLCollection;
|
277 | HTMLOptionsCollection: typeof HTMLOptionsCollection;
|
278 | DOMStringMap: typeof DOMStringMap;
|
279 | DOMTokenList: typeof DOMTokenList;
|
280 |
|
281 | StyleSheetList: typeof StyleSheetList;
|
282 |
|
283 | HTMLElement: typeof HTMLElement;
|
284 | HTMLHeadElement: typeof HTMLHeadElement;
|
285 | HTMLTitleElement: typeof HTMLTitleElement;
|
286 | HTMLBaseElement: typeof HTMLBaseElement;
|
287 | HTMLLinkElement: typeof HTMLLinkElement;
|
288 | HTMLMetaElement: typeof HTMLMetaElement;
|
289 | HTMLStyleElement: typeof HTMLStyleElement;
|
290 | HTMLBodyElement: typeof HTMLBodyElement;
|
291 | HTMLHeadingElement: typeof HTMLHeadingElement;
|
292 | HTMLParagraphElement: typeof HTMLParagraphElement;
|
293 | HTMLHRElement: typeof HTMLHRElement;
|
294 | HTMLPreElement: typeof HTMLPreElement;
|
295 | HTMLUListElement: typeof HTMLUListElement;
|
296 | HTMLOListElement: typeof HTMLOListElement;
|
297 | HTMLLIElement: typeof HTMLLIElement;
|
298 | HTMLMenuElement: typeof HTMLMenuElement;
|
299 | HTMLDListElement: typeof HTMLDListElement;
|
300 | HTMLDivElement: typeof HTMLDivElement;
|
301 | HTMLAnchorElement: typeof HTMLAnchorElement;
|
302 | HTMLAreaElement: typeof HTMLAreaElement;
|
303 | HTMLBRElement: typeof HTMLBRElement;
|
304 | HTMLButtonElement: typeof HTMLButtonElement;
|
305 | HTMLCanvasElement: typeof HTMLCanvasElement;
|
306 | HTMLDataElement: typeof HTMLDataElement;
|
307 | HTMLDataListElement: typeof HTMLDataListElement;
|
308 | HTMLDetailsElement: typeof HTMLDetailsElement;
|
309 | HTMLDialogElement: {
|
310 | new(): HTMLDialogElement;
|
311 | readonly prototype: HTMLDialogElement;
|
312 | };
|
313 | HTMLDirectoryElement: typeof HTMLDirectoryElement;
|
314 | HTMLFieldSetElement: typeof HTMLFieldSetElement;
|
315 | HTMLFontElement: typeof HTMLFontElement;
|
316 | HTMLFormElement: typeof HTMLFormElement;
|
317 | HTMLHtmlElement: typeof HTMLHtmlElement;
|
318 | HTMLImageElement: typeof HTMLImageElement;
|
319 | HTMLInputElement: typeof HTMLInputElement;
|
320 | HTMLLabelElement: typeof HTMLLabelElement;
|
321 | HTMLLegendElement: typeof HTMLLegendElement;
|
322 | HTMLMapElement: typeof HTMLMapElement;
|
323 | HTMLMarqueeElement: typeof HTMLMarqueeElement;
|
324 | HTMLMediaElement: typeof HTMLMediaElement;
|
325 | HTMLMeterElement: typeof HTMLMeterElement;
|
326 | HTMLModElement: typeof HTMLModElement;
|
327 | HTMLOptGroupElement: typeof HTMLOptGroupElement;
|
328 | HTMLOptionElement: typeof HTMLOptionElement;
|
329 | HTMLOutputElement: typeof HTMLOutputElement;
|
330 | HTMLPictureElement: typeof HTMLPictureElement;
|
331 | HTMLProgressElement: typeof HTMLProgressElement;
|
332 | HTMLQuoteElement: typeof HTMLQuoteElement;
|
333 | HTMLScriptElement: typeof HTMLScriptElement;
|
334 | HTMLSelectElement: typeof HTMLSelectElement;
|
335 | HTMLSlotElement: typeof HTMLSlotElement;
|
336 | HTMLSourceElement: typeof HTMLSourceElement;
|
337 | HTMLSpanElement: typeof HTMLSpanElement;
|
338 | HTMLTableCaptionElement: typeof HTMLTableCaptionElement;
|
339 | HTMLTableCellElement: typeof HTMLTableCellElement;
|
340 | HTMLTableColElement: typeof HTMLTableColElement;
|
341 | HTMLTableElement: typeof HTMLTableElement;
|
342 | HTMLTimeElement: typeof HTMLTimeElement;
|
343 | HTMLTableRowElement: typeof HTMLTableRowElement;
|
344 | HTMLTableSectionElement: typeof HTMLTableSectionElement;
|
345 | HTMLTemplateElement: typeof HTMLTemplateElement;
|
346 | HTMLTextAreaElement: typeof HTMLTextAreaElement;
|
347 | HTMLUnknownElement: typeof HTMLUnknownElement;
|
348 | HTMLFrameElement: typeof HTMLFrameElement;
|
349 | HTMLFrameSetElement: typeof HTMLFrameSetElement;
|
350 | HTMLIFrameElement: typeof HTMLIFrameElement;
|
351 | HTMLEmbedElement: typeof HTMLEmbedElement;
|
352 | HTMLObjectElement: typeof HTMLObjectElement;
|
353 | HTMLParamElement: typeof HTMLParamElement;
|
354 | HTMLVideoElement: typeof HTMLVideoElement;
|
355 | HTMLAudioElement: typeof HTMLAudioElement;
|
356 | HTMLTrackElement: typeof HTMLTrackElement;
|
357 |
|
358 | SVGElement: typeof SVGElement;
|
359 | SVGGraphicsElement: typeof SVGGraphicsElement;
|
360 | SVGSVGElement: typeof SVGSVGElement;
|
361 | SVGTitleElement: typeof SVGTitleElement;
|
362 | SVGAnimatedString: typeof SVGAnimatedString;
|
363 | SVGNumber: typeof SVGNumber;
|
364 | SVGStringList: typeof SVGStringList;
|
365 |
|
366 | Event: typeof Event;
|
367 | CloseEvent: typeof CloseEvent;
|
368 | CustomEvent: typeof CustomEvent;
|
369 | MessageEvent: typeof MessageEvent;
|
370 | ErrorEvent: typeof ErrorEvent;
|
371 | HashChangeEvent: typeof HashChangeEvent;
|
372 | PopStateEvent: typeof PopStateEvent;
|
373 | StorageEvent: typeof StorageEvent;
|
374 | ProgressEvent: typeof ProgressEvent;
|
375 | PageTransitionEvent: typeof PageTransitionEvent;
|
376 |
|
377 | UIEvent: typeof UIEvent;
|
378 | FocusEvent: typeof FocusEvent;
|
379 | MouseEvent: typeof MouseEvent;
|
380 | KeyboardEvent: typeof KeyboardEvent;
|
381 | TouchEvent: typeof TouchEvent;
|
382 | CompositionEvent: typeof CompositionEvent;
|
383 | WheelEvent: typeof WheelEvent;
|
384 |
|
385 | BarProp: typeof BarProp;
|
386 | Location: typeof Location;
|
387 | History: typeof History;
|
388 | Screen: typeof Screen;
|
389 | Performance: typeof Performance;
|
390 | Navigator: typeof Navigator;
|
391 |
|
392 | PluginArray: typeof PluginArray;
|
393 | MimeTypeArray: typeof MimeTypeArray;
|
394 | Plugin: typeof Plugin;
|
395 | MimeType: typeof MimeType;
|
396 |
|
397 | FileReader: typeof FileReader;
|
398 | Blob: typeof Blob;
|
399 | File: typeof File;
|
400 | FileList: typeof FileList;
|
401 | ValidityState: typeof ValidityState;
|
402 |
|
403 | DOMParser: typeof DOMParser;
|
404 | XMLSerializer: typeof XMLSerializer;
|
405 |
|
406 | FormData: typeof FormData;
|
407 | XMLHttpRequestEventTarget: typeof XMLHttpRequestEventTarget;
|
408 | XMLHttpRequestUpload: typeof XMLHttpRequestUpload;
|
409 | XMLHttpRequest: typeof XMLHttpRequest;
|
410 | WebSocket: typeof WebSocket;
|
411 |
|
412 | NodeFilter: typeof NodeFilter;
|
413 | NodeIterator: typeof NodeIterator;
|
414 | TreeWalker: typeof TreeWalker;
|
415 |
|
416 | AbstractRange: typeof AbstractRange;
|
417 | Range: typeof Range;
|
418 | StaticRange: typeof StaticRange;
|
419 | Selection: typeof Selection;
|
420 |
|
421 | Storage: typeof Storage;
|
422 |
|
423 | CustomElementRegistry: typeof CustomElementRegistry;
|
424 | ShadowRoot: typeof ShadowRoot;
|
425 |
|
426 | MutationObserver: typeof MutationObserver;
|
427 | MutationRecord: typeof MutationRecord;
|
428 |
|
429 | Headers: typeof Headers;
|
430 | AbortController: typeof AbortController;
|
431 | AbortSignal: typeof AbortSignal;
|
432 |
|
433 |
|
434 | StyleSheet: typeof StyleSheet;
|
435 | MediaList: typeof MediaList;
|
436 | CSSStyleSheet: typeof CSSStyleSheet;
|
437 | CSSRule: typeof CSSRule;
|
438 | CSSStyleRule: typeof CSSStyleRule;
|
439 | CSSMediaRule: typeof CSSMediaRule;
|
440 | CSSImportRule: typeof CSSImportRule;
|
441 | CSSStyleDeclaration: typeof CSSStyleDeclaration;
|
442 |
|
443 |
|
444 |
|
445 | XPathExpression: typeof XPathExpression;
|
446 | XPathResult: typeof XPathResult;
|
447 | XPathEvaluator: typeof XPathEvaluator;
|
448 | }
|
449 | }
|