happy-dom 16.8.1 → 17.0.1
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.
- package/cjs/PropertySymbol.cjs +13 -1
- package/cjs/PropertySymbol.cjs.map +1 -1
- package/cjs/PropertySymbol.d.ts +12 -0
- package/cjs/PropertySymbol.d.ts.map +1 -1
- package/cjs/async-task-manager/AsyncTaskManager.cjs +67 -18
- package/cjs/async-task-manager/AsyncTaskManager.cjs.map +1 -1
- package/cjs/async-task-manager/AsyncTaskManager.d.ts +5 -0
- package/cjs/async-task-manager/AsyncTaskManager.d.ts.map +1 -1
- package/cjs/browser/BrowserSettingsFactory.cjs +4 -0
- package/cjs/browser/BrowserSettingsFactory.cjs.map +1 -1
- package/cjs/browser/BrowserSettingsFactory.d.ts.map +1 -1
- package/cjs/browser/DefaultBrowserSettings.cjs +3 -0
- package/cjs/browser/DefaultBrowserSettings.cjs.map +1 -1
- package/cjs/browser/DefaultBrowserSettings.d.ts.map +1 -1
- package/cjs/browser/types/IBrowserSettings.d.ts +6 -0
- package/cjs/browser/types/IBrowserSettings.d.ts.map +1 -1
- package/cjs/browser/types/IOptionalBrowserSettings.d.ts +6 -0
- package/cjs/browser/types/IOptionalBrowserSettings.d.ts.map +1 -1
- package/cjs/browser/utilities/BrowserFrameNavigator.cjs.map +1 -1
- package/cjs/browser/utilities/BrowserFrameNavigator.d.ts.map +1 -1
- package/cjs/dom/DOMTokenList.cjs +7 -4
- package/cjs/dom/DOMTokenList.cjs.map +1 -1
- package/cjs/dom/DOMTokenList.d.ts +5 -3
- package/cjs/dom/DOMTokenList.d.ts.map +1 -1
- package/cjs/event/EventTarget.cjs +31 -5
- package/cjs/event/EventTarget.cjs.map +1 -1
- package/cjs/event/EventTarget.d.ts.map +1 -1
- package/cjs/fetch/Fetch.cjs +67 -13
- package/cjs/fetch/Fetch.cjs.map +1 -1
- package/cjs/fetch/Fetch.d.ts +3 -0
- package/cjs/fetch/Fetch.d.ts.map +1 -1
- package/cjs/fetch/Request.cjs +119 -27
- package/cjs/fetch/Request.cjs.map +1 -1
- package/cjs/fetch/Request.d.ts +65 -9
- package/cjs/fetch/Request.d.ts.map +1 -1
- package/cjs/fetch/ResourceFetch.cjs +91 -13
- package/cjs/fetch/ResourceFetch.cjs.map +1 -1
- package/cjs/fetch/ResourceFetch.d.ts +21 -11
- package/cjs/fetch/ResourceFetch.d.ts.map +1 -1
- package/cjs/fetch/SyncFetch.cjs +36 -7
- package/cjs/fetch/SyncFetch.cjs.map +1 -1
- package/cjs/fetch/SyncFetch.d.ts.map +1 -1
- package/cjs/fetch/preload/PreloadEntry.cjs +44 -0
- package/cjs/fetch/preload/PreloadEntry.cjs.map +1 -0
- package/cjs/fetch/preload/PreloadEntry.d.ts +26 -0
- package/cjs/fetch/preload/PreloadEntry.d.ts.map +1 -0
- package/cjs/fetch/preload/PreloadUtility.cjs +29 -0
- package/cjs/fetch/preload/PreloadUtility.cjs.map +1 -0
- package/cjs/fetch/preload/PreloadUtility.d.ts +26 -0
- package/cjs/fetch/preload/PreloadUtility.d.ts.map +1 -0
- package/cjs/fetch/types/IRequestInit.d.ts +2 -0
- package/cjs/fetch/types/IRequestInit.d.ts.map +1 -1
- package/cjs/fetch/types/IRequestMode.cjs +3 -0
- package/cjs/fetch/types/IRequestMode.cjs.map +1 -0
- package/cjs/fetch/types/IRequestMode.d.ts +3 -0
- package/cjs/fetch/types/IRequestMode.d.ts.map +1 -0
- package/cjs/fetch/utilities/FetchRequestReferrerUtility.cjs +1 -1
- package/cjs/fetch/utilities/FetchRequestReferrerUtility.cjs.map +1 -1
- package/cjs/module/CSSModule.cjs +47 -0
- package/cjs/module/CSSModule.cjs.map +1 -0
- package/cjs/module/CSSModule.d.ts +34 -0
- package/cjs/module/CSSModule.d.ts.map +1 -0
- package/cjs/module/ECMAScriptModule.cjs +157 -0
- package/cjs/module/ECMAScriptModule.cjs.map +1 -0
- package/cjs/module/ECMAScriptModule.d.ts +36 -0
- package/cjs/module/ECMAScriptModule.d.ts.map +1 -0
- package/cjs/module/ECMAScriptModuleCompiler.cjs +550 -0
- package/cjs/module/ECMAScriptModuleCompiler.cjs.map +1 -0
- package/cjs/module/ECMAScriptModuleCompiler.d.ts +31 -0
- package/cjs/module/ECMAScriptModuleCompiler.d.ts.map +1 -0
- package/cjs/module/IECMAScriptModuleCompiledResult.cjs +3 -0
- package/cjs/module/IECMAScriptModuleCompiledResult.cjs.map +1 -0
- package/cjs/module/IECMAScriptModuleCompiledResult.d.ts +21 -0
- package/cjs/module/IECMAScriptModuleCompiledResult.d.ts.map +1 -0
- package/cjs/module/IECMAScriptModuleImport.cjs +3 -0
- package/cjs/module/IECMAScriptModuleImport.cjs.map +1 -0
- package/cjs/module/IECMAScriptModuleImport.d.ts +5 -0
- package/cjs/module/IECMAScriptModuleImport.d.ts.map +1 -0
- package/cjs/module/IModule.cjs +3 -0
- package/cjs/module/IModule.cjs.map +1 -0
- package/cjs/module/IModule.d.ts +21 -0
- package/cjs/module/IModule.d.ts.map +1 -0
- package/cjs/module/IModuleImportMap.cjs +3 -0
- package/cjs/module/IModuleImportMap.cjs.map +1 -0
- package/cjs/module/IModuleImportMap.d.ts +10 -0
- package/cjs/module/IModuleImportMap.d.ts.map +1 -0
- package/cjs/module/IModuleImportMapRule.cjs +3 -0
- package/cjs/module/IModuleImportMapRule.cjs.map +1 -0
- package/cjs/module/IModuleImportMapRule.d.ts +5 -0
- package/cjs/module/IModuleImportMapRule.d.ts.map +1 -0
- package/cjs/module/IModuleImportMapScope.cjs +3 -0
- package/cjs/module/IModuleImportMapScope.cjs.map +1 -0
- package/cjs/module/IModuleImportMapScope.d.ts +6 -0
- package/cjs/module/IModuleImportMapScope.d.ts.map +1 -0
- package/cjs/module/JSONModule.cjs +52 -0
- package/cjs/module/JSONModule.cjs.map +1 -0
- package/cjs/module/JSONModule.d.ts +33 -0
- package/cjs/module/JSONModule.d.ts.map +1 -0
- package/cjs/module/ModuleFactory.cjs +136 -0
- package/cjs/module/ModuleFactory.cjs.map +1 -0
- package/cjs/module/ModuleFactory.d.ts +33 -0
- package/cjs/module/ModuleFactory.d.ts.map +1 -0
- package/cjs/module/ModuleURLUtility.cjs +67 -0
- package/cjs/module/ModuleURLUtility.cjs.map +1 -0
- package/cjs/module/ModuleURLUtility.d.ts +17 -0
- package/cjs/module/ModuleURLUtility.d.ts.map +1 -0
- package/cjs/module/UnresolvedModule.cjs +70 -0
- package/cjs/module/UnresolvedModule.cjs.map +1 -0
- package/cjs/module/UnresolvedModule.d.ts +43 -0
- package/cjs/module/UnresolvedModule.d.ts.map +1 -0
- package/cjs/nodes/document/Document.cjs +1 -0
- package/cjs/nodes/document/Document.cjs.map +1 -1
- package/cjs/nodes/document/Document.d.ts +2 -0
- package/cjs/nodes/document/Document.d.ts.map +1 -1
- package/cjs/nodes/element/Element.cjs +21 -5
- package/cjs/nodes/element/Element.cjs.map +1 -1
- package/cjs/nodes/element/Element.d.ts +6 -0
- package/cjs/nodes/element/Element.d.ts.map +1 -1
- package/cjs/nodes/html-anchor-element/HTMLAnchorElement.cjs +8 -0
- package/cjs/nodes/html-anchor-element/HTMLAnchorElement.cjs.map +1 -1
- package/cjs/nodes/html-anchor-element/HTMLAnchorElement.d.ts +6 -0
- package/cjs/nodes/html-anchor-element/HTMLAnchorElement.d.ts.map +1 -1
- package/cjs/nodes/html-area-element/HTMLAreaElement.cjs +8 -0
- package/cjs/nodes/html-area-element/HTMLAreaElement.cjs.map +1 -1
- package/cjs/nodes/html-area-element/HTMLAreaElement.d.ts +6 -0
- package/cjs/nodes/html-area-element/HTMLAreaElement.d.ts.map +1 -1
- package/cjs/nodes/html-element/HTMLElement.cjs +3 -0
- package/cjs/nodes/html-element/HTMLElement.cjs.map +1 -1
- package/cjs/nodes/html-element/HTMLElement.d.ts.map +1 -1
- package/cjs/nodes/html-iframe-element/HTMLIFrameElement.cjs +7 -3
- package/cjs/nodes/html-iframe-element/HTMLIFrameElement.cjs.map +1 -1
- package/cjs/nodes/html-iframe-element/HTMLIFrameElement.d.ts.map +1 -1
- package/cjs/nodes/html-link-element/HTMLLinkElement.cjs +147 -19
- package/cjs/nodes/html-link-element/HTMLLinkElement.cjs.map +1 -1
- package/cjs/nodes/html-link-element/HTMLLinkElement.d.ts +8 -2
- package/cjs/nodes/html-link-element/HTMLLinkElement.d.ts.map +1 -1
- package/cjs/nodes/html-media-element/HTMLMediaElement.cjs +8 -0
- package/cjs/nodes/html-media-element/HTMLMediaElement.cjs.map +1 -1
- package/cjs/nodes/html-media-element/HTMLMediaElement.d.ts +6 -0
- package/cjs/nodes/html-media-element/HTMLMediaElement.d.ts.map +1 -1
- package/cjs/nodes/html-script-element/HTMLScriptElement.cjs +380 -46
- package/cjs/nodes/html-script-element/HTMLScriptElement.cjs.map +1 -1
- package/cjs/nodes/html-script-element/HTMLScriptElement.d.ts +80 -0
- package/cjs/nodes/html-script-element/HTMLScriptElement.d.ts.map +1 -1
- package/cjs/nodes/html-table-cell-element/HTMLTableCellElement.cjs +0 -1
- package/cjs/nodes/html-table-cell-element/HTMLTableCellElement.cjs.map +1 -1
- package/cjs/nodes/html-table-cell-element/HTMLTableCellElement.d.ts +0 -3
- package/cjs/nodes/html-table-cell-element/HTMLTableCellElement.d.ts.map +1 -1
- package/cjs/query-selector/QuerySelector.cjs +16 -7
- package/cjs/query-selector/QuerySelector.cjs.map +1 -1
- package/cjs/query-selector/QuerySelector.d.ts +2 -1
- package/cjs/query-selector/QuerySelector.d.ts.map +1 -1
- package/cjs/utilities/AttributeUtility.cjs +36 -0
- package/cjs/utilities/AttributeUtility.cjs.map +1 -0
- package/cjs/utilities/AttributeUtility.d.ts +18 -0
- package/cjs/utilities/AttributeUtility.d.ts.map +1 -0
- package/cjs/window/BrowserWindow.cjs +73 -6
- package/cjs/window/BrowserWindow.cjs.map +1 -1
- package/cjs/window/BrowserWindow.d.ts +14 -0
- package/cjs/window/BrowserWindow.d.ts.map +1 -1
- package/lib/PropertySymbol.d.ts +12 -0
- package/lib/PropertySymbol.d.ts.map +1 -1
- package/lib/PropertySymbol.js +12 -0
- package/lib/PropertySymbol.js.map +1 -1
- package/lib/async-task-manager/AsyncTaskManager.d.ts +5 -0
- package/lib/async-task-manager/AsyncTaskManager.d.ts.map +1 -1
- package/lib/async-task-manager/AsyncTaskManager.js +67 -18
- package/lib/async-task-manager/AsyncTaskManager.js.map +1 -1
- package/lib/browser/BrowserSettingsFactory.d.ts.map +1 -1
- package/lib/browser/BrowserSettingsFactory.js +4 -0
- package/lib/browser/BrowserSettingsFactory.js.map +1 -1
- package/lib/browser/DefaultBrowserSettings.d.ts.map +1 -1
- package/lib/browser/DefaultBrowserSettings.js +3 -0
- package/lib/browser/DefaultBrowserSettings.js.map +1 -1
- package/lib/browser/types/IBrowserSettings.d.ts +6 -0
- package/lib/browser/types/IBrowserSettings.d.ts.map +1 -1
- package/lib/browser/types/IOptionalBrowserSettings.d.ts +6 -0
- package/lib/browser/types/IOptionalBrowserSettings.d.ts.map +1 -1
- package/lib/browser/utilities/BrowserFrameNavigator.d.ts.map +1 -1
- package/lib/browser/utilities/BrowserFrameNavigator.js.map +1 -1
- package/lib/dom/DOMTokenList.d.ts +5 -3
- package/lib/dom/DOMTokenList.d.ts.map +1 -1
- package/lib/dom/DOMTokenList.js +7 -4
- package/lib/dom/DOMTokenList.js.map +1 -1
- package/lib/event/EventTarget.d.ts.map +1 -1
- package/lib/event/EventTarget.js +31 -5
- package/lib/event/EventTarget.js.map +1 -1
- package/lib/fetch/Fetch.d.ts +3 -0
- package/lib/fetch/Fetch.d.ts.map +1 -1
- package/lib/fetch/Fetch.js +64 -10
- package/lib/fetch/Fetch.js.map +1 -1
- package/lib/fetch/Request.d.ts +65 -9
- package/lib/fetch/Request.d.ts.map +1 -1
- package/lib/fetch/Request.js +116 -24
- package/lib/fetch/Request.js.map +1 -1
- package/lib/fetch/ResourceFetch.d.ts +21 -11
- package/lib/fetch/ResourceFetch.d.ts.map +1 -1
- package/lib/fetch/ResourceFetch.js +68 -13
- package/lib/fetch/ResourceFetch.js.map +1 -1
- package/lib/fetch/SyncFetch.d.ts.map +1 -1
- package/lib/fetch/SyncFetch.js +36 -7
- package/lib/fetch/SyncFetch.js.map +1 -1
- package/lib/fetch/preload/PreloadEntry.d.ts +26 -0
- package/lib/fetch/preload/PreloadEntry.d.ts.map +1 -0
- package/lib/fetch/preload/PreloadEntry.js +41 -0
- package/lib/fetch/preload/PreloadEntry.js.map +1 -0
- package/lib/fetch/preload/PreloadUtility.d.ts +26 -0
- package/lib/fetch/preload/PreloadUtility.d.ts.map +1 -0
- package/lib/fetch/preload/PreloadUtility.js +26 -0
- package/lib/fetch/preload/PreloadUtility.js.map +1 -0
- package/lib/fetch/types/IRequestInit.d.ts +2 -0
- package/lib/fetch/types/IRequestInit.d.ts.map +1 -1
- package/lib/fetch/types/IRequestMode.d.ts +3 -0
- package/lib/fetch/types/IRequestMode.d.ts.map +1 -0
- package/lib/fetch/types/IRequestMode.js +2 -0
- package/lib/fetch/types/IRequestMode.js.map +1 -0
- package/lib/fetch/utilities/FetchRequestReferrerUtility.js +1 -1
- package/lib/fetch/utilities/FetchRequestReferrerUtility.js.map +1 -1
- package/lib/module/CSSModule.d.ts +34 -0
- package/lib/module/CSSModule.d.ts.map +1 -0
- package/lib/module/CSSModule.js +44 -0
- package/lib/module/CSSModule.js.map +1 -0
- package/lib/module/ECMAScriptModule.d.ts +36 -0
- package/lib/module/ECMAScriptModule.d.ts.map +1 -0
- package/lib/module/ECMAScriptModule.js +128 -0
- package/lib/module/ECMAScriptModule.js.map +1 -0
- package/lib/module/ECMAScriptModuleCompiler.d.ts +31 -0
- package/lib/module/ECMAScriptModuleCompiler.d.ts.map +1 -0
- package/lib/module/ECMAScriptModuleCompiler.js +521 -0
- package/lib/module/ECMAScriptModuleCompiler.js.map +1 -0
- package/lib/module/IECMAScriptModuleCompiledResult.d.ts +21 -0
- package/lib/module/IECMAScriptModuleCompiledResult.d.ts.map +1 -0
- package/lib/module/IECMAScriptModuleCompiledResult.js +2 -0
- package/lib/module/IECMAScriptModuleCompiledResult.js.map +1 -0
- package/lib/module/IECMAScriptModuleImport.d.ts +5 -0
- package/lib/module/IECMAScriptModuleImport.d.ts.map +1 -0
- package/lib/module/IECMAScriptModuleImport.js +2 -0
- package/lib/module/IECMAScriptModuleImport.js.map +1 -0
- package/lib/module/IModule.d.ts +21 -0
- package/lib/module/IModule.d.ts.map +1 -0
- package/lib/module/IModule.js +2 -0
- package/lib/module/IModule.js.map +1 -0
- package/lib/module/IModuleImportMap.d.ts +10 -0
- package/lib/module/IModuleImportMap.d.ts.map +1 -0
- package/lib/module/IModuleImportMap.js +2 -0
- package/lib/module/IModuleImportMap.js.map +1 -0
- package/lib/module/IModuleImportMapRule.d.ts +5 -0
- package/lib/module/IModuleImportMapRule.d.ts.map +1 -0
- package/lib/module/IModuleImportMapRule.js +2 -0
- package/lib/module/IModuleImportMapRule.js.map +1 -0
- package/lib/module/IModuleImportMapScope.d.ts +6 -0
- package/lib/module/IModuleImportMapScope.d.ts.map +1 -0
- package/lib/module/IModuleImportMapScope.js +2 -0
- package/lib/module/IModuleImportMapScope.js.map +1 -0
- package/lib/module/JSONModule.d.ts +33 -0
- package/lib/module/JSONModule.d.ts.map +1 -0
- package/lib/module/JSONModule.js +49 -0
- package/lib/module/JSONModule.js.map +1 -0
- package/lib/module/ModuleFactory.d.ts +33 -0
- package/lib/module/ModuleFactory.d.ts.map +1 -0
- package/lib/module/ModuleFactory.js +107 -0
- package/lib/module/ModuleFactory.js.map +1 -0
- package/lib/module/ModuleURLUtility.d.ts +17 -0
- package/lib/module/ModuleURLUtility.d.ts.map +1 -0
- package/lib/module/ModuleURLUtility.js +41 -0
- package/lib/module/ModuleURLUtility.js.map +1 -0
- package/lib/module/UnresolvedModule.d.ts +43 -0
- package/lib/module/UnresolvedModule.d.ts.map +1 -0
- package/lib/module/UnresolvedModule.js +67 -0
- package/lib/module/UnresolvedModule.js.map +1 -0
- package/lib/nodes/document/Document.d.ts +2 -0
- package/lib/nodes/document/Document.d.ts.map +1 -1
- package/lib/nodes/document/Document.js +1 -0
- package/lib/nodes/document/Document.js.map +1 -1
- package/lib/nodes/element/Element.d.ts +6 -0
- package/lib/nodes/element/Element.d.ts.map +1 -1
- package/lib/nodes/element/Element.js +21 -5
- package/lib/nodes/element/Element.js.map +1 -1
- package/lib/nodes/html-anchor-element/HTMLAnchorElement.d.ts +6 -0
- package/lib/nodes/html-anchor-element/HTMLAnchorElement.d.ts.map +1 -1
- package/lib/nodes/html-anchor-element/HTMLAnchorElement.js +8 -0
- package/lib/nodes/html-anchor-element/HTMLAnchorElement.js.map +1 -1
- package/lib/nodes/html-area-element/HTMLAreaElement.d.ts +6 -0
- package/lib/nodes/html-area-element/HTMLAreaElement.d.ts.map +1 -1
- package/lib/nodes/html-area-element/HTMLAreaElement.js +8 -0
- package/lib/nodes/html-area-element/HTMLAreaElement.js.map +1 -1
- package/lib/nodes/html-element/HTMLElement.d.ts.map +1 -1
- package/lib/nodes/html-element/HTMLElement.js +3 -0
- package/lib/nodes/html-element/HTMLElement.js.map +1 -1
- package/lib/nodes/html-iframe-element/HTMLIFrameElement.d.ts.map +1 -1
- package/lib/nodes/html-iframe-element/HTMLIFrameElement.js +7 -3
- package/lib/nodes/html-iframe-element/HTMLIFrameElement.js.map +1 -1
- package/lib/nodes/html-link-element/HTMLLinkElement.d.ts +8 -2
- package/lib/nodes/html-link-element/HTMLLinkElement.d.ts.map +1 -1
- package/lib/nodes/html-link-element/HTMLLinkElement.js +147 -19
- package/lib/nodes/html-link-element/HTMLLinkElement.js.map +1 -1
- package/lib/nodes/html-media-element/HTMLMediaElement.d.ts +6 -0
- package/lib/nodes/html-media-element/HTMLMediaElement.d.ts.map +1 -1
- package/lib/nodes/html-media-element/HTMLMediaElement.js +8 -0
- package/lib/nodes/html-media-element/HTMLMediaElement.js.map +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.d.ts +80 -0
- package/lib/nodes/html-script-element/HTMLScriptElement.d.ts.map +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.js +380 -46
- package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
- package/lib/nodes/html-table-cell-element/HTMLTableCellElement.d.ts +0 -3
- package/lib/nodes/html-table-cell-element/HTMLTableCellElement.d.ts.map +1 -1
- package/lib/nodes/html-table-cell-element/HTMLTableCellElement.js +0 -1
- package/lib/nodes/html-table-cell-element/HTMLTableCellElement.js.map +1 -1
- package/lib/query-selector/QuerySelector.d.ts +2 -1
- package/lib/query-selector/QuerySelector.d.ts.map +1 -1
- package/lib/query-selector/QuerySelector.js +16 -7
- package/lib/query-selector/QuerySelector.js.map +1 -1
- package/lib/utilities/AttributeUtility.d.ts +18 -0
- package/lib/utilities/AttributeUtility.d.ts.map +1 -0
- package/lib/utilities/AttributeUtility.js +29 -0
- package/lib/utilities/AttributeUtility.js.map +1 -0
- package/lib/window/BrowserWindow.d.ts +14 -0
- package/lib/window/BrowserWindow.d.ts.map +1 -1
- package/lib/window/BrowserWindow.js +73 -6
- package/lib/window/BrowserWindow.js.map +1 -1
- package/package.json +1 -1
- package/src/PropertySymbol.ts +12 -0
- package/src/async-task-manager/AsyncTaskManager.ts +81 -19
- package/src/browser/BrowserSettingsFactory.ts +4 -0
- package/src/browser/DefaultBrowserSettings.ts +3 -0
- package/src/browser/types/IBrowserSettings.ts +7 -0
- package/src/browser/types/IOptionalBrowserSettings.ts +7 -0
- package/src/browser/utilities/BrowserFrameNavigator.ts +2 -7
- package/src/dom/DOMTokenList.ts +12 -4
- package/src/event/EventTarget.ts +31 -11
- package/src/fetch/Fetch.ts +82 -16
- package/src/fetch/Request.ts +132 -24
- package/src/fetch/ResourceFetch.ts +99 -14
- package/src/fetch/SyncFetch.ts +41 -9
- package/src/fetch/preload/PreloadEntry.ts +46 -0
- package/src/fetch/preload/PreloadUtility.ts +33 -0
- package/src/fetch/types/IRequestInit.ts +2 -0
- package/src/fetch/types/IRequestMode.ts +2 -0
- package/src/fetch/utilities/FetchRequestReferrerUtility.ts +1 -1
- package/src/module/CSSModule.ts +54 -0
- package/src/module/ECMAScriptModule.ts +171 -0
- package/src/module/ECMAScriptModuleCompiler.ts +567 -0
- package/src/module/IECMAScriptModuleCompiledResult.ts +14 -0
- package/src/module/IECMAScriptModuleImport.ts +4 -0
- package/src/module/IModule.ts +20 -0
- package/src/module/IModuleImportMap.ts +10 -0
- package/src/module/IModuleImportMapRule.ts +4 -0
- package/src/module/IModuleImportMapScope.ts +6 -0
- package/src/module/JSONModule.ts +59 -0
- package/src/module/ModuleFactory.ts +134 -0
- package/src/module/ModuleURLUtility.ts +51 -0
- package/src/module/UnresolvedModule.ts +77 -0
- package/src/nodes/document/Document.ts +2 -0
- package/src/nodes/element/Element.ts +25 -7
- package/src/nodes/html-anchor-element/HTMLAnchorElement.ts +9 -0
- package/src/nodes/html-area-element/HTMLAreaElement.ts +9 -0
- package/src/nodes/html-element/HTMLElement.ts +3 -0
- package/src/nodes/html-iframe-element/HTMLIFrameElement.ts +9 -8
- package/src/nodes/html-link-element/HTMLLinkElement.ts +181 -28
- package/src/nodes/html-media-element/HTMLMediaElement.ts +9 -0
- package/src/nodes/html-script-element/HTMLScriptElement.ts +441 -69
- package/src/nodes/html-table-cell-element/HTMLTableCellElement.ts +0 -3
- package/src/query-selector/QuerySelector.ts +19 -8
- package/src/utilities/AttributeUtility.ts +43 -0
- package/src/window/BrowserWindow.ts +77 -10
- package/cjs/window/WindowErrorUtility.cjs +0 -85
- package/cjs/window/WindowErrorUtility.cjs.map +0 -1
- package/cjs/window/WindowErrorUtility.d.ts +0 -27
- package/cjs/window/WindowErrorUtility.d.ts.map +0 -1
- package/lib/window/WindowErrorUtility.d.ts +0 -27
- package/lib/window/WindowErrorUtility.d.ts.map +0 -1
- package/lib/window/WindowErrorUtility.js +0 -56
- package/lib/window/WindowErrorUtility.js.map +0 -1
- package/src/window/WindowErrorUtility.ts +0 -68
package/src/fetch/Fetch.ts
CHANGED
@@ -7,7 +7,7 @@ import DOMExceptionNameEnum from '../exception/DOMExceptionNameEnum.js';
|
|
7
7
|
import HTTP, { IncomingMessage } from 'http';
|
8
8
|
import HTTPS from 'https';
|
9
9
|
import Zlib from 'zlib';
|
10
|
-
import URL from '
|
10
|
+
import { URL } from 'url';
|
11
11
|
import FS from 'fs';
|
12
12
|
import Path from 'path';
|
13
13
|
import { Socket } from 'net';
|
@@ -30,6 +30,7 @@ import { Buffer } from 'buffer';
|
|
30
30
|
import FetchBodyUtility from './utilities/FetchBodyUtility.js';
|
31
31
|
import IFetchInterceptor from './types/IFetchInterceptor.js';
|
32
32
|
import VirtualServerUtility from './utilities/VirtualServerUtility.js';
|
33
|
+
import PreloadUtility from './preload/PreloadUtility.js';
|
33
34
|
|
34
35
|
const LAST_CHUNK = Buffer.from('0\r\n\r\n');
|
35
36
|
|
@@ -59,6 +60,7 @@ export default class Fetch {
|
|
59
60
|
private redirectCount = 0;
|
60
61
|
private disableCache: boolean;
|
61
62
|
private disableSameOriginPolicy: boolean;
|
63
|
+
private disablePreload: boolean;
|
62
64
|
#browserFrame: IBrowserFrame;
|
63
65
|
#window: BrowserWindow;
|
64
66
|
#unfilteredHeaders: Headers | null = null;
|
@@ -76,6 +78,7 @@ export default class Fetch {
|
|
76
78
|
* @param [options.disableCache] Disables the use of cached responses. It will still store the response in the cache.
|
77
79
|
* @param [options.disableSameOriginPolicy] Disables the Same-Origin policy.
|
78
80
|
* @param [options.unfilteredHeaders] Unfiltered headers - necessary for preflight requests.
|
81
|
+
* @param [options.disablePreload] Disables the use of preloaded responses.
|
79
82
|
*/
|
80
83
|
constructor(options: {
|
81
84
|
browserFrame: IBrowserFrame;
|
@@ -87,6 +90,7 @@ export default class Fetch {
|
|
87
90
|
disableCache?: boolean;
|
88
91
|
disableSameOriginPolicy?: boolean;
|
89
92
|
unfilteredHeaders?: Headers;
|
93
|
+
disablePreload?: boolean;
|
90
94
|
}) {
|
91
95
|
this.#browserFrame = options.browserFrame;
|
92
96
|
this.#window = options.window;
|
@@ -105,6 +109,7 @@ export default class Fetch {
|
|
105
109
|
this.#browserFrame.page.context.browser.settings.fetch.disableSameOriginPolicy ??
|
106
110
|
false;
|
107
111
|
this.interceptor = this.#browserFrame.page.context.browser.settings.fetch.interceptor;
|
112
|
+
this.disablePreload = options.disablePreload ?? false;
|
108
113
|
}
|
109
114
|
|
110
115
|
/**
|
@@ -129,12 +134,6 @@ export default class Fetch {
|
|
129
134
|
|
130
135
|
FetchRequestValidationUtility.validateSchema(this.request);
|
131
136
|
|
132
|
-
const virtualServerResponse = await this.getVirtualServerResponse();
|
133
|
-
|
134
|
-
if (virtualServerResponse) {
|
135
|
-
return virtualServerResponse;
|
136
|
-
}
|
137
|
-
|
138
137
|
if (this.request.signal.aborted) {
|
139
138
|
throw new this.#window.DOMException(
|
140
139
|
'The operation was aborted.',
|
@@ -180,6 +179,38 @@ export default class Fetch {
|
|
180
179
|
}
|
181
180
|
}
|
182
181
|
|
182
|
+
if (!this.disablePreload) {
|
183
|
+
const preloadKey = PreloadUtility.getKey({
|
184
|
+
url: this.request.url,
|
185
|
+
destination: 'fetch',
|
186
|
+
mode: this.request.mode,
|
187
|
+
credentialsMode: this.request.credentials
|
188
|
+
});
|
189
|
+
|
190
|
+
const preloadEntry = this.#window.document[PropertySymbol.preloads].get(preloadKey);
|
191
|
+
|
192
|
+
if (preloadEntry) {
|
193
|
+
this.#window.document[PropertySymbol.preloads].delete(preloadKey);
|
194
|
+
|
195
|
+
if (preloadEntry.response) {
|
196
|
+
return preloadEntry.response;
|
197
|
+
}
|
198
|
+
|
199
|
+
const taskID = this.#browserFrame[PropertySymbol.asyncTaskManager].startTask();
|
200
|
+
const response = await preloadEntry.onResponseAvailable();
|
201
|
+
|
202
|
+
this.#browserFrame[PropertySymbol.asyncTaskManager].endTask(taskID);
|
203
|
+
|
204
|
+
return response;
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
const virtualServerResponse = await this.getVirtualServerResponse();
|
209
|
+
|
210
|
+
if (virtualServerResponse) {
|
211
|
+
return virtualServerResponse;
|
212
|
+
}
|
213
|
+
|
183
214
|
if (!this.disableSameOriginPolicy) {
|
184
215
|
const compliesWithCrossOriginPolicy = await this.compliesWithCrossOriginPolicy();
|
185
216
|
|
@@ -295,14 +326,23 @@ export default class Fetch {
|
|
295
326
|
return null;
|
296
327
|
}
|
297
328
|
|
329
|
+
const taskID = this.#browserFrame[PropertySymbol.asyncTaskManager].startTask();
|
330
|
+
|
298
331
|
if (this.request.method !== 'GET') {
|
299
332
|
this.#browserFrame?.page?.console.error(
|
300
333
|
`${this.request.method} ${this.request.url} 404 (Not Found)`
|
301
334
|
);
|
302
|
-
|
335
|
+
const response = VirtualServerUtility.getNotFoundResponse(this.#window);
|
336
|
+
const interceptedResponse = this.interceptor?.afterAsyncResponse
|
337
|
+
? await this.interceptor.afterAsyncResponse({
|
338
|
+
window: this.#window,
|
339
|
+
response: await response,
|
340
|
+
request: this.request
|
341
|
+
})
|
342
|
+
: undefined;
|
343
|
+
this.#browserFrame[PropertySymbol.asyncTaskManager].endTask(taskID);
|
344
|
+
return interceptedResponse instanceof Response ? interceptedResponse : response;
|
303
345
|
}
|
304
|
-
|
305
|
-
const taskID = this.#browserFrame[PropertySymbol.asyncTaskManager].startTask();
|
306
346
|
let buffer: Buffer;
|
307
347
|
|
308
348
|
try {
|
@@ -315,13 +355,18 @@ export default class Fetch {
|
|
315
355
|
`${this.request.method} ${this.request.url} 404 (Not Found)`
|
316
356
|
);
|
317
357
|
|
358
|
+
const response = VirtualServerUtility.getNotFoundResponse(this.#window);
|
359
|
+
const interceptedResponse = this.interceptor?.afterAsyncResponse
|
360
|
+
? await this.interceptor.afterAsyncResponse({
|
361
|
+
window: this.#window,
|
362
|
+
response: await response,
|
363
|
+
request: this.request
|
364
|
+
})
|
365
|
+
: undefined;
|
318
366
|
this.#browserFrame[PropertySymbol.asyncTaskManager].endTask(taskID);
|
319
|
-
|
320
|
-
return VirtualServerUtility.getNotFoundResponse(this.#window);
|
367
|
+
return interceptedResponse instanceof Response ? interceptedResponse : response;
|
321
368
|
}
|
322
369
|
|
323
|
-
this.#browserFrame[PropertySymbol.asyncTaskManager].endTask(taskID);
|
324
|
-
|
325
370
|
const body = new this.#window.ReadableStream({
|
326
371
|
start(controller) {
|
327
372
|
setTimeout(() => {
|
@@ -332,11 +377,32 @@ export default class Fetch {
|
|
332
377
|
});
|
333
378
|
|
334
379
|
const response = new this.#window.Response(body);
|
335
|
-
|
336
380
|
response[PropertySymbol.buffer] = buffer;
|
337
381
|
(<string>response.url) = this.request.url;
|
338
382
|
|
339
|
-
|
383
|
+
const interceptedResponse = this.interceptor?.afterAsyncResponse
|
384
|
+
? await this.interceptor.afterAsyncResponse({
|
385
|
+
window: this.#window,
|
386
|
+
response: await response,
|
387
|
+
request: this.request
|
388
|
+
})
|
389
|
+
: undefined;
|
390
|
+
|
391
|
+
this.#browserFrame[PropertySymbol.asyncTaskManager].endTask(taskID);
|
392
|
+
|
393
|
+
const returnResponse = interceptedResponse instanceof Response ? interceptedResponse : response;
|
394
|
+
const cachedResponse = {
|
395
|
+
...returnResponse,
|
396
|
+
body: buffer,
|
397
|
+
waitingForBody: false
|
398
|
+
};
|
399
|
+
|
400
|
+
response[PropertySymbol.cachedResponse] = this.#browserFrame.page?.context?.responseCache.add(
|
401
|
+
this.request,
|
402
|
+
cachedResponse
|
403
|
+
);
|
404
|
+
|
405
|
+
return returnResponse;
|
340
406
|
}
|
341
407
|
|
342
408
|
/**
|
package/src/fetch/Request.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import * as PropertySymbol from '../PropertySymbol.js';
|
2
2
|
import IRequestInit from './types/IRequestInit.js';
|
3
|
-
import URL from '
|
3
|
+
import { URL } from 'url';
|
4
4
|
import DOMExceptionNameEnum from '../exception/DOMExceptionNameEnum.js';
|
5
5
|
import IRequestInfo from './types/IRequestInfo.js';
|
6
6
|
import Headers from './Headers.js';
|
@@ -18,6 +18,7 @@ import FormData from '../form-data/FormData.js';
|
|
18
18
|
import MultipartFormDataParser from './multipart/MultipartFormDataParser.js';
|
19
19
|
import BrowserWindow from '../window/BrowserWindow.js';
|
20
20
|
import WindowBrowserContext from '../window/WindowBrowserContext.js';
|
21
|
+
import IRequestMode from './types/IRequestMode.js';
|
21
22
|
|
22
23
|
/**
|
23
24
|
* Fetch request.
|
@@ -32,14 +33,15 @@ export default class Request implements Request {
|
|
32
33
|
protected declare [PropertySymbol.window]: BrowserWindow;
|
33
34
|
|
34
35
|
// Public properties
|
35
|
-
public
|
36
|
-
public
|
37
|
-
public
|
38
|
-
public
|
39
|
-
public
|
40
|
-
public
|
41
|
-
public
|
42
|
-
public
|
36
|
+
public [PropertySymbol.method]: string;
|
37
|
+
public [PropertySymbol.body]: ReadableStream | null;
|
38
|
+
public [PropertySymbol.mode]: IRequestMode = 'cors';
|
39
|
+
public [PropertySymbol.headers]: Headers;
|
40
|
+
public [PropertySymbol.redirect]: IRequestRedirect;
|
41
|
+
public [PropertySymbol.referrerPolicy]: IRequestReferrerPolicy;
|
42
|
+
public [PropertySymbol.signal]: AbortSignal;
|
43
|
+
public [PropertySymbol.bodyUsed]: boolean = false;
|
44
|
+
public [PropertySymbol.credentials]: IRequestCredentials;
|
43
45
|
|
44
46
|
// Internal properties
|
45
47
|
public [PropertySymbol.aborted]: boolean = false;
|
@@ -70,7 +72,30 @@ export default class Request implements Request {
|
|
70
72
|
);
|
71
73
|
}
|
72
74
|
|
73
|
-
this.method = (init?.method || (<Request>input).method || 'GET').toUpperCase();
|
75
|
+
this[PropertySymbol.method] = (init?.method || (<Request>input).method || 'GET').toUpperCase();
|
76
|
+
|
77
|
+
if (init?.mode) {
|
78
|
+
switch (init.mode) {
|
79
|
+
case 'navigate':
|
80
|
+
case 'websocket':
|
81
|
+
throw new window.DOMException(
|
82
|
+
`Failed to construct 'Request': Cannot construct a Request with a RequestInit whose mode member is set as '${init.mode}'.`,
|
83
|
+
DOMExceptionNameEnum.securityError
|
84
|
+
);
|
85
|
+
case 'same-origin':
|
86
|
+
case 'no-cors':
|
87
|
+
case 'cors':
|
88
|
+
this[PropertySymbol.mode] = init.mode;
|
89
|
+
break;
|
90
|
+
default:
|
91
|
+
throw new window.DOMException(
|
92
|
+
`Failed to construct 'Request': The provided value '${init.mode}' is not a valid enum value of type RequestMode.`,
|
93
|
+
DOMExceptionNameEnum.syntaxError
|
94
|
+
);
|
95
|
+
}
|
96
|
+
} else if (input instanceof Request) {
|
97
|
+
this[PropertySymbol.mode] = input.mode;
|
98
|
+
}
|
74
99
|
|
75
100
|
const { stream, buffer, contentType, contentLength } = FetchBodyUtility.getBodyStream(
|
76
101
|
input instanceof Request && (input[PropertySymbol.bodyBuffer] || input.body)
|
@@ -79,9 +104,10 @@ export default class Request implements Request {
|
|
79
104
|
);
|
80
105
|
|
81
106
|
this[PropertySymbol.bodyBuffer] = buffer;
|
82
|
-
this.body = stream;
|
83
|
-
this.credentials =
|
84
|
-
|
107
|
+
this[PropertySymbol.body] = stream;
|
108
|
+
this[PropertySymbol.credentials] =
|
109
|
+
init?.credentials || (<Request>input).credentials || 'same-origin';
|
110
|
+
this[PropertySymbol.headers] = new Headers(init?.headers || (<Request>input).headers || {});
|
85
111
|
|
86
112
|
FetchRequestHeaderUtility.removeForbiddenHeaders(this.headers);
|
87
113
|
|
@@ -100,11 +126,12 @@ export default class Request implements Request {
|
|
100
126
|
this[PropertySymbol.contentType] = input[PropertySymbol.contentType];
|
101
127
|
}
|
102
128
|
|
103
|
-
this.redirect = init?.redirect || (<Request>input).redirect || 'follow';
|
104
|
-
this.referrerPolicy = <IRequestReferrerPolicy>(
|
129
|
+
this[PropertySymbol.redirect] = init?.redirect || (<Request>input).redirect || 'follow';
|
130
|
+
this[PropertySymbol.referrerPolicy] = <IRequestReferrerPolicy>(
|
105
131
|
(init?.referrerPolicy || (<Request>input).referrerPolicy || '').toLowerCase()
|
106
132
|
);
|
107
|
-
this.signal =
|
133
|
+
this[PropertySymbol.signal] =
|
134
|
+
init?.signal || (<Request>input).signal || new window.AbortSignal();
|
108
135
|
this[PropertySymbol.referrer] = FetchRequestReferrerUtility.getInitialReferrer(
|
109
136
|
window,
|
110
137
|
init?.referrer !== null && init?.referrer !== undefined
|
@@ -142,6 +169,87 @@ export default class Request implements Request {
|
|
142
169
|
FetchRequestValidationUtility.validateRedirect(this.redirect);
|
143
170
|
}
|
144
171
|
|
172
|
+
/**
|
173
|
+
* Returns method.
|
174
|
+
*
|
175
|
+
* @returns Method.
|
176
|
+
*/
|
177
|
+
public get method(): string {
|
178
|
+
return this[PropertySymbol.method];
|
179
|
+
}
|
180
|
+
|
181
|
+
/**
|
182
|
+
* Returns body.
|
183
|
+
*
|
184
|
+
* @returns Body.
|
185
|
+
*/
|
186
|
+
public get body(): ReadableStream | null {
|
187
|
+
return this[PropertySymbol.body];
|
188
|
+
}
|
189
|
+
|
190
|
+
/**
|
191
|
+
* Returns mode.
|
192
|
+
*
|
193
|
+
* @returns Mode.
|
194
|
+
*/
|
195
|
+
public get mode(): IRequestMode {
|
196
|
+
return this[PropertySymbol.mode];
|
197
|
+
}
|
198
|
+
|
199
|
+
/**
|
200
|
+
* Returns headers.
|
201
|
+
*
|
202
|
+
* @returns Headers.
|
203
|
+
*/
|
204
|
+
public get headers(): Headers {
|
205
|
+
return this[PropertySymbol.headers];
|
206
|
+
}
|
207
|
+
|
208
|
+
/**
|
209
|
+
* Returns redirect.
|
210
|
+
*
|
211
|
+
* @returns Redirect.
|
212
|
+
*/
|
213
|
+
public get redirect(): IRequestRedirect {
|
214
|
+
return this[PropertySymbol.redirect];
|
215
|
+
}
|
216
|
+
|
217
|
+
/**
|
218
|
+
* Returns referrer policy.
|
219
|
+
*
|
220
|
+
* @returns Referrer policy.
|
221
|
+
*/
|
222
|
+
public get referrerPolicy(): IRequestReferrerPolicy {
|
223
|
+
return this[PropertySymbol.referrerPolicy];
|
224
|
+
}
|
225
|
+
|
226
|
+
/**
|
227
|
+
* Returns signal.
|
228
|
+
*
|
229
|
+
* @returns Signal.
|
230
|
+
*/
|
231
|
+
public get signal(): AbortSignal {
|
232
|
+
return this[PropertySymbol.signal];
|
233
|
+
}
|
234
|
+
|
235
|
+
/**
|
236
|
+
* Returns body used.
|
237
|
+
*
|
238
|
+
* @returns Body used.
|
239
|
+
*/
|
240
|
+
public get bodyUsed(): boolean {
|
241
|
+
return this[PropertySymbol.bodyUsed];
|
242
|
+
}
|
243
|
+
|
244
|
+
/**
|
245
|
+
* Returns credentials.
|
246
|
+
*
|
247
|
+
* @returns Credentials.
|
248
|
+
*/
|
249
|
+
public get credentials(): IRequestCredentials {
|
250
|
+
return this[PropertySymbol.credentials];
|
251
|
+
}
|
252
|
+
|
145
253
|
/**
|
146
254
|
* Returns referrer.
|
147
255
|
*
|
@@ -185,7 +293,7 @@ export default class Request implements Request {
|
|
185
293
|
public async arrayBuffer(): Promise<ArrayBuffer> {
|
186
294
|
const window = this[PropertySymbol.window];
|
187
295
|
|
188
|
-
if (this.bodyUsed) {
|
296
|
+
if (this[PropertySymbol.bodyUsed]) {
|
189
297
|
throw new window.DOMException(
|
190
298
|
`Body has already been used for "${this.url}".`,
|
191
299
|
DOMExceptionNameEnum.invalidStateError
|
@@ -194,7 +302,7 @@ export default class Request implements Request {
|
|
194
302
|
|
195
303
|
const asyncTaskManager = new WindowBrowserContext(window).getAsyncTaskManager();
|
196
304
|
|
197
|
-
|
305
|
+
this[PropertySymbol.bodyUsed] = true;
|
198
306
|
|
199
307
|
const taskID = asyncTaskManager.startTask(() => {
|
200
308
|
if (this.body) {
|
@@ -236,7 +344,7 @@ export default class Request implements Request {
|
|
236
344
|
public async buffer(): Promise<Buffer> {
|
237
345
|
const window = this[PropertySymbol.window];
|
238
346
|
|
239
|
-
if (this.bodyUsed) {
|
347
|
+
if (this[PropertySymbol.bodyUsed]) {
|
240
348
|
throw new window.DOMException(
|
241
349
|
`Body has already been used for "${this.url}".`,
|
242
350
|
DOMExceptionNameEnum.invalidStateError
|
@@ -245,7 +353,7 @@ export default class Request implements Request {
|
|
245
353
|
|
246
354
|
const asyncTaskManager = new WindowBrowserContext(window).getAsyncTaskManager();
|
247
355
|
|
248
|
-
|
356
|
+
this[PropertySymbol.bodyUsed] = true;
|
249
357
|
|
250
358
|
const taskID = asyncTaskManager.startTask(() => {
|
251
359
|
if (this.body) {
|
@@ -275,7 +383,7 @@ export default class Request implements Request {
|
|
275
383
|
public async text(): Promise<string> {
|
276
384
|
const window = this[PropertySymbol.window];
|
277
385
|
|
278
|
-
if (this.bodyUsed) {
|
386
|
+
if (this[PropertySymbol.bodyUsed]) {
|
279
387
|
throw new window.DOMException(
|
280
388
|
`Body has already been used for "${this.url}".`,
|
281
389
|
DOMExceptionNameEnum.invalidStateError
|
@@ -284,7 +392,7 @@ export default class Request implements Request {
|
|
284
392
|
|
285
393
|
const asyncTaskManager = new WindowBrowserContext(window).getAsyncTaskManager();
|
286
394
|
|
287
|
-
|
395
|
+
this[PropertySymbol.bodyUsed] = true;
|
288
396
|
|
289
397
|
const taskID = asyncTaskManager.startTask(() => {
|
290
398
|
if (this.body) {
|
@@ -327,14 +435,14 @@ export default class Request implements Request {
|
|
327
435
|
const contentType = this[PropertySymbol.contentType];
|
328
436
|
|
329
437
|
if (/multipart/i.test(contentType)) {
|
330
|
-
if (this.bodyUsed) {
|
438
|
+
if (this[PropertySymbol.bodyUsed]) {
|
331
439
|
throw new window.DOMException(
|
332
440
|
`Body has already been used for "${this.url}".`,
|
333
441
|
DOMExceptionNameEnum.invalidStateError
|
334
442
|
);
|
335
443
|
}
|
336
444
|
|
337
|
-
|
445
|
+
this[PropertySymbol.bodyUsed] = true;
|
338
446
|
|
339
447
|
const taskID = asyncTaskManager.startTask(() => {
|
340
448
|
if (this.body) {
|
@@ -1,41 +1,84 @@
|
|
1
1
|
import BrowserWindow from '../window/BrowserWindow.js';
|
2
2
|
import URL from '../url/URL.js';
|
3
|
-
import IBrowserFrame from '../browser/types/IBrowserFrame.js';
|
4
3
|
import Fetch from './Fetch.js';
|
5
4
|
import SyncFetch from './SyncFetch.js';
|
5
|
+
import IRequestCredentials from './types/IRequestCredentials.js';
|
6
|
+
import WindowBrowserContext from '../window/WindowBrowserContext.js';
|
7
|
+
import PreloadUtility from './preload/PreloadUtility.js';
|
8
|
+
import * as PropertySymbol from '../PropertySymbol.js';
|
9
|
+
import IRequestReferrerPolicy from './types/IRequestReferrerPolicy.js';
|
6
10
|
|
7
11
|
/**
|
8
12
|
* Helper class for performing fetch of resources.
|
9
13
|
*/
|
10
14
|
export default class ResourceFetch {
|
11
15
|
private window: BrowserWindow;
|
12
|
-
#browserFrame: IBrowserFrame;
|
13
16
|
|
14
17
|
/**
|
15
18
|
* Constructor.
|
16
19
|
*
|
17
|
-
* @param
|
18
|
-
* @param options.browserFrame Browser frame.
|
19
|
-
* @param options.window Window.
|
20
|
+
* @param window Window.
|
20
21
|
*/
|
21
|
-
constructor(
|
22
|
-
this
|
23
|
-
this.window = options.window;
|
22
|
+
constructor(window: BrowserWindow) {
|
23
|
+
this.window = window;
|
24
24
|
}
|
25
25
|
|
26
26
|
/**
|
27
27
|
* Returns resource data asynchronously.
|
28
28
|
*
|
29
29
|
* @param url URL.
|
30
|
+
* @param destination Destination.
|
31
|
+
* @param [options]
|
32
|
+
* @param [options.credentials] Credentials.
|
33
|
+
* @param options.referrerPolicy
|
30
34
|
* @returns Response.
|
31
35
|
*/
|
32
|
-
public async fetch(
|
36
|
+
public async fetch(
|
37
|
+
url: string | URL,
|
38
|
+
destination: 'script' | 'style' | 'module',
|
39
|
+
options?: { credentials?: IRequestCredentials; referrerPolicy?: IRequestReferrerPolicy }
|
40
|
+
): Promise<string> {
|
41
|
+
const browserFrame = new WindowBrowserContext(this.window).getBrowserFrame();
|
42
|
+
|
43
|
+
// Preloaded resource
|
44
|
+
if (destination === 'script' || destination === 'style') {
|
45
|
+
const preloadKey = PreloadUtility.getKey({
|
46
|
+
url: String(url),
|
47
|
+
destination,
|
48
|
+
mode: 'cors',
|
49
|
+
credentialsMode: options.credentials || 'same-origin'
|
50
|
+
});
|
51
|
+
const preloadEntry = this.window.document[PropertySymbol.preloads].get(preloadKey);
|
52
|
+
|
53
|
+
if (preloadEntry) {
|
54
|
+
this.window.document[PropertySymbol.preloads].delete(preloadKey);
|
55
|
+
|
56
|
+
const response = preloadEntry.response || (await preloadEntry.onResponseAvailable());
|
57
|
+
|
58
|
+
if (!response.ok) {
|
59
|
+
throw new this.window.DOMException(
|
60
|
+
`Failed to perform request to "${
|
61
|
+
new URL(url, this.window.location.href).href
|
62
|
+
}". Status ${preloadEntry.response.status} ${preloadEntry.response.statusText}.`
|
63
|
+
);
|
64
|
+
}
|
65
|
+
|
66
|
+
return preloadEntry.response[PropertySymbol.buffer].toString();
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
33
70
|
const fetch = new Fetch({
|
34
|
-
browserFrame
|
71
|
+
browserFrame,
|
35
72
|
window: this.window,
|
36
73
|
url,
|
37
|
-
disableSameOriginPolicy:
|
74
|
+
disableSameOriginPolicy: destination === 'script' || destination === 'style',
|
75
|
+
disablePreload: true,
|
76
|
+
init: {
|
77
|
+
credentials: options?.credentials,
|
78
|
+
referrerPolicy: options?.referrerPolicy
|
79
|
+
}
|
38
80
|
});
|
81
|
+
|
39
82
|
const response = await fetch.send();
|
40
83
|
|
41
84
|
if (!response.ok) {
|
@@ -53,14 +96,56 @@ export default class ResourceFetch {
|
|
53
96
|
* Returns resource data synchronously.
|
54
97
|
*
|
55
98
|
* @param url URL.
|
99
|
+
* @param destination Destination.
|
100
|
+
* @param [options] Options.
|
101
|
+
* @param [options.credentials] Credentials.
|
102
|
+
* @param [options.referrerPolicy] Referrer policy.
|
56
103
|
* @returns Response.
|
57
104
|
*/
|
58
|
-
public fetchSync(
|
105
|
+
public fetchSync(
|
106
|
+
url: string,
|
107
|
+
destination: 'script' | 'style' | 'module',
|
108
|
+
options?: { credentials?: IRequestCredentials; referrerPolicy?: IRequestReferrerPolicy }
|
109
|
+
): string {
|
110
|
+
const browserFrame = new WindowBrowserContext(this.window).getBrowserFrame();
|
111
|
+
|
112
|
+
// Preloaded resource
|
113
|
+
if (destination === 'script' || destination === 'style') {
|
114
|
+
const preloadKey = PreloadUtility.getKey({
|
115
|
+
url: String(url),
|
116
|
+
destination,
|
117
|
+
mode: 'cors',
|
118
|
+
credentialsMode: options.credentials || 'same-origin'
|
119
|
+
});
|
120
|
+
const preloadEntry = this.window.document[PropertySymbol.preloads].get(preloadKey);
|
121
|
+
|
122
|
+
// We will only use this if the fetch for the resource is complete as it is async and this request is sync.
|
123
|
+
if (preloadEntry && preloadEntry.response) {
|
124
|
+
this.window.document[PropertySymbol.preloads].delete(preloadKey);
|
125
|
+
|
126
|
+
const response = preloadEntry.response;
|
127
|
+
|
128
|
+
if (!response.ok) {
|
129
|
+
throw new this.window.DOMException(
|
130
|
+
`Failed to perform request to "${
|
131
|
+
new URL(url, this.window.location.href).href
|
132
|
+
}". Status ${preloadEntry.response.status} ${preloadEntry.response.statusText}.`
|
133
|
+
);
|
134
|
+
}
|
135
|
+
|
136
|
+
return preloadEntry.response[PropertySymbol.buffer].toString();
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
59
140
|
const fetch = new SyncFetch({
|
60
|
-
browserFrame
|
141
|
+
browserFrame,
|
61
142
|
window: this.window,
|
62
143
|
url,
|
63
|
-
disableSameOriginPolicy: true
|
144
|
+
disableSameOriginPolicy: true,
|
145
|
+
init: {
|
146
|
+
credentials: options?.credentials,
|
147
|
+
referrerPolicy: options?.referrerPolicy
|
148
|
+
}
|
64
149
|
});
|
65
150
|
|
66
151
|
const response = fetch.send();
|
package/src/fetch/SyncFetch.ts
CHANGED
@@ -106,18 +106,13 @@ export default class SyncFetch {
|
|
106
106
|
window: this.#window
|
107
107
|
})
|
108
108
|
: undefined;
|
109
|
+
|
109
110
|
if (typeof beforeRequestResponse === 'object') {
|
110
111
|
return beforeRequestResponse;
|
111
112
|
}
|
112
113
|
|
113
114
|
FetchRequestValidationUtility.validateSchema(this.request);
|
114
115
|
|
115
|
-
const virtualServerResponse = this.getVirtualServerResponse();
|
116
|
-
|
117
|
-
if (virtualServerResponse) {
|
118
|
-
return virtualServerResponse;
|
119
|
-
}
|
120
|
-
|
121
116
|
if (this.request.signal.aborted) {
|
122
117
|
throw new this.#window.DOMException(
|
123
118
|
'The operation was aborted.',
|
@@ -167,6 +162,12 @@ export default class SyncFetch {
|
|
167
162
|
return cachedResponse;
|
168
163
|
}
|
169
164
|
|
165
|
+
const virtualServerResponse = this.getVirtualServerResponse();
|
166
|
+
|
167
|
+
if (virtualServerResponse) {
|
168
|
+
return virtualServerResponse;
|
169
|
+
}
|
170
|
+
|
170
171
|
if (!this.compliesWithCrossOriginPolicy()) {
|
171
172
|
this.#window.console.warn(
|
172
173
|
`Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at "${this.request.url}".`
|
@@ -283,7 +284,15 @@ export default class SyncFetch {
|
|
283
284
|
this.#browserFrame?.page?.console.error(
|
284
285
|
`${this.request.method} ${this.request.url} 404 (Not Found)`
|
285
286
|
);
|
286
|
-
|
287
|
+
const response = VirtualServerUtility.getNotFoundSyncResponse(this.#window);
|
288
|
+
const interceptedResponse = this.interceptor?.afterSyncResponse
|
289
|
+
? this.interceptor.afterSyncResponse({
|
290
|
+
window: this.#window,
|
291
|
+
response,
|
292
|
+
request: this.request
|
293
|
+
})
|
294
|
+
: undefined;
|
295
|
+
return typeof interceptedResponse === 'object' ? interceptedResponse : response;
|
287
296
|
}
|
288
297
|
|
289
298
|
let buffer: Buffer;
|
@@ -294,10 +303,18 @@ export default class SyncFetch {
|
|
294
303
|
this.#browserFrame?.page?.console.error(
|
295
304
|
`${this.request.method} ${this.request.url} 404 (Not Found)`
|
296
305
|
);
|
297
|
-
|
306
|
+
const response = VirtualServerUtility.getNotFoundSyncResponse(this.#window);
|
307
|
+
const interceptedResponse = this.interceptor?.afterSyncResponse
|
308
|
+
? this.interceptor.afterSyncResponse({
|
309
|
+
window: this.#window,
|
310
|
+
response,
|
311
|
+
request: this.request
|
312
|
+
})
|
313
|
+
: undefined;
|
314
|
+
return typeof interceptedResponse === 'object' ? interceptedResponse : response;
|
298
315
|
}
|
299
316
|
|
300
|
-
|
317
|
+
const response = {
|
301
318
|
status: 200,
|
302
319
|
statusText: '',
|
303
320
|
ok: true,
|
@@ -306,6 +323,21 @@ export default class SyncFetch {
|
|
306
323
|
headers: new this.#window.Headers(),
|
307
324
|
body: buffer
|
308
325
|
};
|
326
|
+
const interceptedResponse = this.interceptor?.afterSyncResponse
|
327
|
+
? this.interceptor.afterSyncResponse({
|
328
|
+
window: this.#window,
|
329
|
+
response,
|
330
|
+
request: this.request
|
331
|
+
})
|
332
|
+
: undefined;
|
333
|
+
const returnResponse = typeof interceptedResponse === 'object' ? interceptedResponse : response;
|
334
|
+
|
335
|
+
this.#browserFrame.page.context.responseCache.add(this.request, {
|
336
|
+
...returnResponse,
|
337
|
+
waitingForBody: false
|
338
|
+
});
|
339
|
+
|
340
|
+
return returnResponse;
|
309
341
|
}
|
310
342
|
|
311
343
|
/**
|