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