phantomwright-driver-core 1.57.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.
- package/README.md +3 -0
- package/ThirdPartyNotices.txt +1161 -0
- package/bin/install_media_pack.ps1 +5 -0
- package/bin/install_webkit_wsl.ps1 +33 -0
- package/bin/reinstall_chrome_beta_linux.sh +42 -0
- package/bin/reinstall_chrome_beta_mac.sh +13 -0
- package/bin/reinstall_chrome_beta_win.ps1 +24 -0
- package/bin/reinstall_chrome_stable_linux.sh +42 -0
- package/bin/reinstall_chrome_stable_mac.sh +12 -0
- package/bin/reinstall_chrome_stable_win.ps1 +24 -0
- package/bin/reinstall_msedge_beta_linux.sh +48 -0
- package/bin/reinstall_msedge_beta_mac.sh +11 -0
- package/bin/reinstall_msedge_beta_win.ps1 +23 -0
- package/bin/reinstall_msedge_dev_linux.sh +48 -0
- package/bin/reinstall_msedge_dev_mac.sh +11 -0
- package/bin/reinstall_msedge_dev_win.ps1 +23 -0
- package/bin/reinstall_msedge_stable_linux.sh +48 -0
- package/bin/reinstall_msedge_stable_mac.sh +11 -0
- package/bin/reinstall_msedge_stable_win.ps1 +24 -0
- package/browsers.json +80 -0
- package/cli.js +18 -0
- package/index.d.ts +17 -0
- package/index.js +32 -0
- package/index.mjs +28 -0
- package/lib/androidServerImpl.js +65 -0
- package/lib/browserServerImpl.js +120 -0
- package/lib/cli/driver.js +97 -0
- package/lib/cli/program.js +590 -0
- package/lib/cli/programWithTestStub.js +74 -0
- package/lib/client/android.js +361 -0
- package/lib/client/api.js +134 -0
- package/lib/client/artifact.js +79 -0
- package/lib/client/browser.js +163 -0
- package/lib/client/browserContext.js +547 -0
- package/lib/client/browserType.js +184 -0
- package/lib/client/cdpSession.js +51 -0
- package/lib/client/channelOwner.js +194 -0
- package/lib/client/clientHelper.js +64 -0
- package/lib/client/clientInstrumentation.js +55 -0
- package/lib/client/clientStackTrace.js +69 -0
- package/lib/client/clock.js +68 -0
- package/lib/client/connection.js +314 -0
- package/lib/client/consoleMessage.js +58 -0
- package/lib/client/coverage.js +44 -0
- package/lib/client/dialog.js +56 -0
- package/lib/client/download.js +62 -0
- package/lib/client/electron.js +138 -0
- package/lib/client/elementHandle.js +281 -0
- package/lib/client/errors.js +77 -0
- package/lib/client/eventEmitter.js +314 -0
- package/lib/client/events.js +100 -0
- package/lib/client/fetch.js +369 -0
- package/lib/client/fileChooser.js +46 -0
- package/lib/client/fileUtils.js +34 -0
- package/lib/client/frame.js +408 -0
- package/lib/client/harRouter.js +87 -0
- package/lib/client/input.js +84 -0
- package/lib/client/jsHandle.js +109 -0
- package/lib/client/jsonPipe.js +39 -0
- package/lib/client/localUtils.js +60 -0
- package/lib/client/locator.js +369 -0
- package/lib/client/network.js +747 -0
- package/lib/client/page.js +718 -0
- package/lib/client/platform.js +74 -0
- package/lib/client/playwright.js +71 -0
- package/lib/client/selectors.js +55 -0
- package/lib/client/stream.js +39 -0
- package/lib/client/timeoutSettings.js +79 -0
- package/lib/client/tracing.js +119 -0
- package/lib/client/types.js +28 -0
- package/lib/client/video.js +59 -0
- package/lib/client/waiter.js +142 -0
- package/lib/client/webError.js +39 -0
- package/lib/client/webSocket.js +93 -0
- package/lib/client/worker.js +85 -0
- package/lib/client/writableStream.js +39 -0
- package/lib/generated/bindingsControllerSource.js +28 -0
- package/lib/generated/clockSource.js +28 -0
- package/lib/generated/injectedScriptSource.js +28 -0
- package/lib/generated/pollingRecorderSource.js +28 -0
- package/lib/generated/storageScriptSource.js +28 -0
- package/lib/generated/utilityScriptSource.js +28 -0
- package/lib/generated/webSocketMockSource.js +336 -0
- package/lib/inProcessFactory.js +60 -0
- package/lib/inprocess.js +3 -0
- package/lib/outofprocess.js +76 -0
- package/lib/protocol/serializers.js +192 -0
- package/lib/protocol/validator.js +2890 -0
- package/lib/protocol/validatorPrimitives.js +193 -0
- package/lib/remote/playwrightConnection.js +129 -0
- package/lib/remote/playwrightServer.js +335 -0
- package/lib/server/android/android.js +465 -0
- package/lib/server/android/backendAdb.js +177 -0
- package/lib/server/artifact.js +127 -0
- package/lib/server/bidi/bidiBrowser.js +505 -0
- package/lib/server/bidi/bidiChromium.js +153 -0
- package/lib/server/bidi/bidiConnection.js +212 -0
- package/lib/server/bidi/bidiExecutionContext.js +221 -0
- package/lib/server/bidi/bidiFirefox.js +130 -0
- package/lib/server/bidi/bidiInput.js +146 -0
- package/lib/server/bidi/bidiNetworkManager.js +383 -0
- package/lib/server/bidi/bidiOverCdp.js +102 -0
- package/lib/server/bidi/bidiPage.js +572 -0
- package/lib/server/bidi/bidiPdf.js +106 -0
- package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
- package/lib/server/bidi/third_party/bidiDeserializer.js +98 -0
- package/lib/server/bidi/third_party/bidiKeyboard.js +256 -0
- package/lib/server/bidi/third_party/bidiProtocol.js +24 -0
- package/lib/server/bidi/third_party/bidiProtocolCore.js +179 -0
- package/lib/server/bidi/third_party/bidiProtocolPermissions.js +42 -0
- package/lib/server/bidi/third_party/bidiSerializer.js +148 -0
- package/lib/server/bidi/third_party/firefoxPrefs.js +259 -0
- package/lib/server/browser.js +149 -0
- package/lib/server/browserContext.js +695 -0
- package/lib/server/browserType.js +328 -0
- package/lib/server/callLog.js +82 -0
- package/lib/server/chromium/appIcon.png +0 -0
- package/lib/server/chromium/chromium.js +402 -0
- package/lib/server/chromium/chromiumSwitches.js +104 -0
- package/lib/server/chromium/crBrowser.js +510 -0
- package/lib/server/chromium/crConnection.js +202 -0
- package/lib/server/chromium/crCoverage.js +235 -0
- package/lib/server/chromium/crDevTools.js +113 -0
- package/lib/server/chromium/crDragDrop.js +131 -0
- package/lib/server/chromium/crExecutionContext.js +146 -0
- package/lib/server/chromium/crInput.js +187 -0
- package/lib/server/chromium/crNetworkManager.js +666 -0
- package/lib/server/chromium/crPage.js +1069 -0
- package/lib/server/chromium/crPdf.js +121 -0
- package/lib/server/chromium/crProtocolHelper.js +145 -0
- package/lib/server/chromium/crServiceWorker.js +136 -0
- package/lib/server/chromium/defaultFontFamilies.js +162 -0
- package/lib/server/chromium/protocol.d.js +16 -0
- package/lib/server/chromium/videoRecorder.js +115 -0
- package/lib/server/clock.js +149 -0
- package/lib/server/codegen/csharp.js +327 -0
- package/lib/server/codegen/java.js +274 -0
- package/lib/server/codegen/javascript.js +270 -0
- package/lib/server/codegen/jsonl.js +52 -0
- package/lib/server/codegen/language.js +132 -0
- package/lib/server/codegen/languages.js +68 -0
- package/lib/server/codegen/python.js +279 -0
- package/lib/server/codegen/types.js +16 -0
- package/lib/server/console.js +57 -0
- package/lib/server/cookieStore.js +206 -0
- package/lib/server/debugController.js +191 -0
- package/lib/server/debugger.js +119 -0
- package/lib/server/deviceDescriptors.js +39 -0
- package/lib/server/deviceDescriptorsSource.json +1779 -0
- package/lib/server/dialog.js +116 -0
- package/lib/server/dispatchers/androidDispatcher.js +325 -0
- package/lib/server/dispatchers/artifactDispatcher.js +118 -0
- package/lib/server/dispatchers/browserContextDispatcher.js +381 -0
- package/lib/server/dispatchers/browserDispatcher.js +118 -0
- package/lib/server/dispatchers/browserTypeDispatcher.js +64 -0
- package/lib/server/dispatchers/cdpSessionDispatcher.js +44 -0
- package/lib/server/dispatchers/debugControllerDispatcher.js +78 -0
- package/lib/server/dispatchers/dialogDispatcher.js +47 -0
- package/lib/server/dispatchers/dispatcher.js +371 -0
- package/lib/server/dispatchers/electronDispatcher.js +89 -0
- package/lib/server/dispatchers/elementHandlerDispatcher.js +181 -0
- package/lib/server/dispatchers/frameDispatcher.js +227 -0
- package/lib/server/dispatchers/jsHandleDispatcher.js +85 -0
- package/lib/server/dispatchers/jsonPipeDispatcher.js +58 -0
- package/lib/server/dispatchers/localUtilsDispatcher.js +149 -0
- package/lib/server/dispatchers/networkDispatchers.js +213 -0
- package/lib/server/dispatchers/pageDispatcher.js +389 -0
- package/lib/server/dispatchers/playwrightDispatcher.js +108 -0
- package/lib/server/dispatchers/streamDispatcher.js +67 -0
- package/lib/server/dispatchers/tracingDispatcher.js +68 -0
- package/lib/server/dispatchers/webSocketRouteDispatcher.js +165 -0
- package/lib/server/dispatchers/writableStreamDispatcher.js +79 -0
- package/lib/server/dom.js +806 -0
- package/lib/server/download.js +70 -0
- package/lib/server/electron/electron.js +270 -0
- package/lib/server/electron/loader.js +29 -0
- package/lib/server/errors.js +69 -0
- package/lib/server/fetch.js +621 -0
- package/lib/server/fileChooser.js +43 -0
- package/lib/server/fileUploadUtils.js +84 -0
- package/lib/server/firefox/ffBrowser.js +428 -0
- package/lib/server/firefox/ffConnection.js +147 -0
- package/lib/server/firefox/ffExecutionContext.js +150 -0
- package/lib/server/firefox/ffInput.js +159 -0
- package/lib/server/firefox/ffNetworkManager.js +256 -0
- package/lib/server/firefox/ffPage.js +500 -0
- package/lib/server/firefox/firefox.js +116 -0
- package/lib/server/firefox/protocol.d.js +16 -0
- package/lib/server/formData.js +147 -0
- package/lib/server/frameSelectors.js +154 -0
- package/lib/server/frames.js +1455 -0
- package/lib/server/har/harRecorder.js +147 -0
- package/lib/server/har/harTracer.js +607 -0
- package/lib/server/harBackend.js +157 -0
- package/lib/server/helper.js +96 -0
- package/lib/server/index.js +58 -0
- package/lib/server/input.js +277 -0
- package/lib/server/instrumentation.js +69 -0
- package/lib/server/javascript.js +291 -0
- package/lib/server/launchApp.js +128 -0
- package/lib/server/localUtils.js +214 -0
- package/lib/server/macEditingCommands.js +143 -0
- package/lib/server/network.js +629 -0
- package/lib/server/page.js +886 -0
- package/lib/server/pipeTransport.js +89 -0
- package/lib/server/playwright.js +69 -0
- package/lib/server/progress.js +112 -0
- package/lib/server/protocolError.js +52 -0
- package/lib/server/recorder/chat.js +161 -0
- package/lib/server/recorder/recorderApp.js +387 -0
- package/lib/server/recorder/recorderRunner.js +138 -0
- package/lib/server/recorder/recorderSignalProcessor.js +83 -0
- package/lib/server/recorder/recorderUtils.js +157 -0
- package/lib/server/recorder/throttledFile.js +57 -0
- package/lib/server/recorder.js +499 -0
- package/lib/server/registry/browserFetcher.js +175 -0
- package/lib/server/registry/dependencies.js +371 -0
- package/lib/server/registry/index.js +1399 -0
- package/lib/server/registry/nativeDeps.js +1280 -0
- package/lib/server/registry/oopDownloadBrowserMain.js +124 -0
- package/lib/server/screenshotter.js +333 -0
- package/lib/server/selectors.js +112 -0
- package/lib/server/socksClientCertificatesInterceptor.js +383 -0
- package/lib/server/socksInterceptor.js +95 -0
- package/lib/server/trace/recorder/snapshotter.js +147 -0
- package/lib/server/trace/recorder/snapshotterInjected.js +541 -0
- package/lib/server/trace/recorder/tracing.js +604 -0
- package/lib/server/trace/test/inMemorySnapshotter.js +87 -0
- package/lib/server/trace/viewer/traceViewer.js +241 -0
- package/lib/server/transport.js +181 -0
- package/lib/server/types.js +28 -0
- package/lib/server/usKeyboardLayout.js +145 -0
- package/lib/server/utils/ascii.js +44 -0
- package/lib/server/utils/comparators.js +139 -0
- package/lib/server/utils/crypto.js +216 -0
- package/lib/server/utils/debug.js +42 -0
- package/lib/server/utils/debugLogger.js +122 -0
- package/lib/server/utils/env.js +73 -0
- package/lib/server/utils/eventsHelper.js +39 -0
- package/lib/server/utils/expectUtils.js +38 -0
- package/lib/server/utils/fileUtils.js +191 -0
- package/lib/server/utils/happyEyeballs.js +207 -0
- package/lib/server/utils/hostPlatform.js +123 -0
- package/lib/server/utils/httpServer.js +218 -0
- package/lib/server/utils/imageUtils.js +141 -0
- package/lib/server/utils/image_tools/colorUtils.js +89 -0
- package/lib/server/utils/image_tools/compare.js +109 -0
- package/lib/server/utils/image_tools/imageChannel.js +78 -0
- package/lib/server/utils/image_tools/stats.js +102 -0
- package/lib/server/utils/linuxUtils.js +71 -0
- package/lib/server/utils/network.js +233 -0
- package/lib/server/utils/nodePlatform.js +148 -0
- package/lib/server/utils/pipeTransport.js +84 -0
- package/lib/server/utils/processLauncher.js +241 -0
- package/lib/server/utils/profiler.js +65 -0
- package/lib/server/utils/socksProxy.js +511 -0
- package/lib/server/utils/spawnAsync.js +41 -0
- package/lib/server/utils/task.js +51 -0
- package/lib/server/utils/userAgent.js +98 -0
- package/lib/server/utils/wsServer.js +121 -0
- package/lib/server/utils/zipFile.js +74 -0
- package/lib/server/utils/zones.js +57 -0
- package/lib/server/webkit/protocol.d.js +16 -0
- package/lib/server/webkit/webkit.js +110 -0
- package/lib/server/webkit/wkBrowser.js +339 -0
- package/lib/server/webkit/wkConnection.js +149 -0
- package/lib/server/webkit/wkExecutionContext.js +154 -0
- package/lib/server/webkit/wkInput.js +181 -0
- package/lib/server/webkit/wkInterceptableRequest.js +169 -0
- package/lib/server/webkit/wkPage.js +1130 -0
- package/lib/server/webkit/wkProvisionalPage.js +83 -0
- package/lib/server/webkit/wkWorkers.js +105 -0
- package/lib/third_party/pixelmatch.js +255 -0
- package/lib/utils/isomorphic/ariaSnapshot.js +397 -0
- package/lib/utils/isomorphic/assert.js +31 -0
- package/lib/utils/isomorphic/colors.js +72 -0
- package/lib/utils/isomorphic/cssParser.js +245 -0
- package/lib/utils/isomorphic/cssTokenizer.js +1051 -0
- package/lib/utils/isomorphic/headers.js +53 -0
- package/lib/utils/isomorphic/locatorGenerators.js +689 -0
- package/lib/utils/isomorphic/locatorParser.js +176 -0
- package/lib/utils/isomorphic/locatorUtils.js +81 -0
- package/lib/utils/isomorphic/manualPromise.js +114 -0
- package/lib/utils/isomorphic/mimeType.js +459 -0
- package/lib/utils/isomorphic/multimap.js +80 -0
- package/lib/utils/isomorphic/protocolFormatter.js +81 -0
- package/lib/utils/isomorphic/protocolMetainfo.js +322 -0
- package/lib/utils/isomorphic/rtti.js +43 -0
- package/lib/utils/isomorphic/selectorParser.js +386 -0
- package/lib/utils/isomorphic/semaphore.js +54 -0
- package/lib/utils/isomorphic/stackTrace.js +158 -0
- package/lib/utils/isomorphic/stringUtils.js +155 -0
- package/lib/utils/isomorphic/time.js +49 -0
- package/lib/utils/isomorphic/timeoutRunner.js +66 -0
- package/lib/utils/isomorphic/traceUtils.js +58 -0
- package/lib/utils/isomorphic/types.js +16 -0
- package/lib/utils/isomorphic/urlMatch.js +190 -0
- package/lib/utils/isomorphic/utilityScriptSerializers.js +251 -0
- package/lib/utils.js +109 -0
- package/lib/utilsBundle.js +112 -0
- package/lib/utilsBundleImpl/index.js +218 -0
- package/lib/utilsBundleImpl/xdg-open +1066 -0
- package/lib/vite/htmlReport/index.html +84 -0
- package/lib/vite/recorder/assets/codeMirrorModule-BoWUGj0J.js +25 -0
- package/lib/vite/recorder/assets/codeMirrorModule-C3UTv-Ge.css +1 -0
- package/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
- package/lib/vite/recorder/assets/index-DJqDAOZp.js +193 -0
- package/lib/vite/recorder/assets/index-Ri0uHF7I.css +1 -0
- package/lib/vite/recorder/index.html +29 -0
- package/lib/vite/recorder/playwright-logo.svg +9 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-Bucv2d7q.js +25 -0
- package/lib/vite/traceViewer/assets/defaultSettingsView-BEpdCv1S.js +266 -0
- package/lib/vite/traceViewer/assets/xtermModule-CsJ4vdCR.js +9 -0
- package/lib/vite/traceViewer/codeMirrorModule.C3UTv-Ge.css +1 -0
- package/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
- package/lib/vite/traceViewer/defaultSettingsView.ConWv5KN.css +1 -0
- package/lib/vite/traceViewer/index.BxQ34UMZ.js +2 -0
- package/lib/vite/traceViewer/index.C4Y3Aw8n.css +1 -0
- package/lib/vite/traceViewer/index.html +43 -0
- package/lib/vite/traceViewer/manifest.webmanifest +16 -0
- package/lib/vite/traceViewer/playwright-logo.svg +9 -0
- package/lib/vite/traceViewer/snapshot.html +21 -0
- package/lib/vite/traceViewer/sw.bundle.js +3 -0
- package/lib/vite/traceViewer/uiMode.BWTwXl41.js +5 -0
- package/lib/vite/traceViewer/uiMode.Btcz36p_.css +1 -0
- package/lib/vite/traceViewer/uiMode.html +17 -0
- package/lib/vite/traceViewer/xtermModule.DYP7pi_n.css +32 -0
- package/lib/zipBundle.js +34 -0
- package/lib/zipBundleImpl.js +5 -0
- package/package.json +42 -0
- package/types/protocol.d.ts +23245 -0
- package/types/structs.d.ts +45 -0
- package/types/types.d.ts +22856 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var webSocketMockSource_exports = {};
|
|
20
|
+
__export(webSocketMockSource_exports, {
|
|
21
|
+
source: () => source
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(webSocketMockSource_exports);
|
|
24
|
+
const source = `
|
|
25
|
+
var __commonJS = obj => {
|
|
26
|
+
let required = false;
|
|
27
|
+
let result;
|
|
28
|
+
return function __require() {
|
|
29
|
+
if (!required) {
|
|
30
|
+
required = true;
|
|
31
|
+
let fn;
|
|
32
|
+
for (const name in obj) { fn = obj[name]; break; }
|
|
33
|
+
const module = { exports: {} };
|
|
34
|
+
fn(module.exports, module);
|
|
35
|
+
result = module.exports;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var __export = (target, all) => {for (var name in all) target[name] = all[name];};
|
|
41
|
+
var __toESM = mod => ({ ...mod, 'default': mod });
|
|
42
|
+
var __toCommonJS = mod => ({ ...mod, __esModule: true });
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
// packages/injected/src/webSocketMock.ts
|
|
46
|
+
var webSocketMock_exports = {};
|
|
47
|
+
__export(webSocketMock_exports, {
|
|
48
|
+
inject: () => inject
|
|
49
|
+
});
|
|
50
|
+
module.exports = __toCommonJS(webSocketMock_exports);
|
|
51
|
+
function inject(globalThis) {
|
|
52
|
+
if (globalThis.__pwWebSocketDispatch)
|
|
53
|
+
return;
|
|
54
|
+
function generateId() {
|
|
55
|
+
const bytes = new Uint8Array(32);
|
|
56
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
57
|
+
const hex = "0123456789abcdef";
|
|
58
|
+
return [...bytes].map((value) => {
|
|
59
|
+
const high = Math.floor(value / 16);
|
|
60
|
+
const low = value % 16;
|
|
61
|
+
return hex[high] + hex[low];
|
|
62
|
+
}).join("");
|
|
63
|
+
}
|
|
64
|
+
function bufferToData(b) {
|
|
65
|
+
let s = "";
|
|
66
|
+
for (let i = 0; i < b.length; i++)
|
|
67
|
+
s += String.fromCharCode(b[i]);
|
|
68
|
+
return { data: globalThis.btoa(s), isBase64: true };
|
|
69
|
+
}
|
|
70
|
+
function stringToBuffer(s) {
|
|
71
|
+
s = globalThis.atob(s);
|
|
72
|
+
const b = new Uint8Array(s.length);
|
|
73
|
+
for (let i = 0; i < s.length; i++)
|
|
74
|
+
b[i] = s.charCodeAt(i);
|
|
75
|
+
return b.buffer;
|
|
76
|
+
}
|
|
77
|
+
function messageToData(message, cb) {
|
|
78
|
+
if (message instanceof globalThis.Blob)
|
|
79
|
+
return message.arrayBuffer().then((buffer) => cb(bufferToData(new Uint8Array(buffer))));
|
|
80
|
+
if (typeof message === "string")
|
|
81
|
+
return cb({ data: message, isBase64: false });
|
|
82
|
+
if (ArrayBuffer.isView(message))
|
|
83
|
+
return cb(bufferToData(new Uint8Array(message.buffer, message.byteOffset, message.byteLength)));
|
|
84
|
+
return cb(bufferToData(new Uint8Array(message)));
|
|
85
|
+
}
|
|
86
|
+
function dataToMessage(data, binaryType) {
|
|
87
|
+
if (!data.isBase64)
|
|
88
|
+
return data.data;
|
|
89
|
+
const buffer = stringToBuffer(data.data);
|
|
90
|
+
return binaryType === "arraybuffer" ? buffer : new Blob([buffer]);
|
|
91
|
+
}
|
|
92
|
+
const binding = globalThis.__pwWebSocketBinding;
|
|
93
|
+
const NativeWebSocket = globalThis.WebSocket;
|
|
94
|
+
const idToWebSocket = /* @__PURE__ */ new Map();
|
|
95
|
+
globalThis.__pwWebSocketDispatch = (request) => {
|
|
96
|
+
const ws = idToWebSocket.get(request.id);
|
|
97
|
+
if (!ws)
|
|
98
|
+
return;
|
|
99
|
+
if (request.type === "connect")
|
|
100
|
+
ws._apiConnect();
|
|
101
|
+
if (request.type === "passthrough")
|
|
102
|
+
ws._apiPassThrough();
|
|
103
|
+
if (request.type === "ensureOpened")
|
|
104
|
+
ws._apiEnsureOpened();
|
|
105
|
+
if (request.type === "sendToPage")
|
|
106
|
+
ws._apiSendToPage(dataToMessage(request.data, ws.binaryType));
|
|
107
|
+
if (request.type === "closePage")
|
|
108
|
+
ws._apiClosePage(request.code, request.reason, request.wasClean);
|
|
109
|
+
if (request.type === "sendToServer")
|
|
110
|
+
ws._apiSendToServer(dataToMessage(request.data, ws.binaryType));
|
|
111
|
+
if (request.type === "closeServer")
|
|
112
|
+
ws._apiCloseServer(request.code, request.reason, request.wasClean);
|
|
113
|
+
};
|
|
114
|
+
const _WebSocketMock = class _WebSocketMock extends EventTarget {
|
|
115
|
+
constructor(url, protocols) {
|
|
116
|
+
var _a, _b;
|
|
117
|
+
super();
|
|
118
|
+
// WebSocket.CLOSED
|
|
119
|
+
this.CONNECTING = 0;
|
|
120
|
+
// WebSocket.CONNECTING
|
|
121
|
+
this.OPEN = 1;
|
|
122
|
+
// WebSocket.OPEN
|
|
123
|
+
this.CLOSING = 2;
|
|
124
|
+
// WebSocket.CLOSING
|
|
125
|
+
this.CLOSED = 3;
|
|
126
|
+
// WebSocket.CLOSED
|
|
127
|
+
this._oncloseListener = null;
|
|
128
|
+
this._onerrorListener = null;
|
|
129
|
+
this._onmessageListener = null;
|
|
130
|
+
this._onopenListener = null;
|
|
131
|
+
this.bufferedAmount = 0;
|
|
132
|
+
this.extensions = "";
|
|
133
|
+
this.protocol = "";
|
|
134
|
+
this.readyState = 0;
|
|
135
|
+
this._origin = "";
|
|
136
|
+
this._passthrough = false;
|
|
137
|
+
this._wsBufferedMessages = [];
|
|
138
|
+
this._binaryType = "blob";
|
|
139
|
+
this.url = new URL(url, globalThis.window.document.baseURI).href.replace(/^http/, "ws");
|
|
140
|
+
this._origin = (_b = (_a = URL.parse(this.url)) == null ? void 0 : _a.origin) != null ? _b : "";
|
|
141
|
+
this._protocols = protocols;
|
|
142
|
+
this._id = generateId();
|
|
143
|
+
idToWebSocket.set(this._id, this);
|
|
144
|
+
binding({ type: "onCreate", id: this._id, url: this.url });
|
|
145
|
+
}
|
|
146
|
+
// --- native WebSocket implementation ---
|
|
147
|
+
get binaryType() {
|
|
148
|
+
return this._binaryType;
|
|
149
|
+
}
|
|
150
|
+
set binaryType(type) {
|
|
151
|
+
this._binaryType = type;
|
|
152
|
+
if (this._ws)
|
|
153
|
+
this._ws.binaryType = type;
|
|
154
|
+
}
|
|
155
|
+
get onclose() {
|
|
156
|
+
return this._oncloseListener;
|
|
157
|
+
}
|
|
158
|
+
set onclose(listener) {
|
|
159
|
+
if (this._oncloseListener)
|
|
160
|
+
this.removeEventListener("close", this._oncloseListener);
|
|
161
|
+
this._oncloseListener = listener;
|
|
162
|
+
if (this._oncloseListener)
|
|
163
|
+
this.addEventListener("close", this._oncloseListener);
|
|
164
|
+
}
|
|
165
|
+
get onerror() {
|
|
166
|
+
return this._onerrorListener;
|
|
167
|
+
}
|
|
168
|
+
set onerror(listener) {
|
|
169
|
+
if (this._onerrorListener)
|
|
170
|
+
this.removeEventListener("error", this._onerrorListener);
|
|
171
|
+
this._onerrorListener = listener;
|
|
172
|
+
if (this._onerrorListener)
|
|
173
|
+
this.addEventListener("error", this._onerrorListener);
|
|
174
|
+
}
|
|
175
|
+
get onopen() {
|
|
176
|
+
return this._onopenListener;
|
|
177
|
+
}
|
|
178
|
+
set onopen(listener) {
|
|
179
|
+
if (this._onopenListener)
|
|
180
|
+
this.removeEventListener("open", this._onopenListener);
|
|
181
|
+
this._onopenListener = listener;
|
|
182
|
+
if (this._onopenListener)
|
|
183
|
+
this.addEventListener("open", this._onopenListener);
|
|
184
|
+
}
|
|
185
|
+
get onmessage() {
|
|
186
|
+
return this._onmessageListener;
|
|
187
|
+
}
|
|
188
|
+
set onmessage(listener) {
|
|
189
|
+
if (this._onmessageListener)
|
|
190
|
+
this.removeEventListener("message", this._onmessageListener);
|
|
191
|
+
this._onmessageListener = listener;
|
|
192
|
+
if (this._onmessageListener)
|
|
193
|
+
this.addEventListener("message", this._onmessageListener);
|
|
194
|
+
}
|
|
195
|
+
send(message) {
|
|
196
|
+
if (this.readyState === _WebSocketMock.CONNECTING)
|
|
197
|
+
throw new DOMException(\`Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.\`);
|
|
198
|
+
if (this.readyState !== _WebSocketMock.OPEN)
|
|
199
|
+
throw new DOMException(\`WebSocket is already in CLOSING or CLOSED state.\`);
|
|
200
|
+
if (this._passthrough) {
|
|
201
|
+
if (this._ws)
|
|
202
|
+
this._apiSendToServer(message);
|
|
203
|
+
} else {
|
|
204
|
+
messageToData(message, (data) => binding({ type: "onMessageFromPage", id: this._id, data }));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
close(code, reason) {
|
|
208
|
+
if (code !== void 0 && code !== 1e3 && (code < 3e3 || code > 4999))
|
|
209
|
+
throw new DOMException(\`Failed to execute 'close' on 'WebSocket': The close code must be either 1000, or between 3000 and 4999. \${code} is neither.\`);
|
|
210
|
+
if (this.readyState === _WebSocketMock.OPEN || this.readyState === _WebSocketMock.CONNECTING)
|
|
211
|
+
this.readyState = _WebSocketMock.CLOSING;
|
|
212
|
+
if (this._passthrough)
|
|
213
|
+
this._apiCloseServer(code, reason, true);
|
|
214
|
+
else
|
|
215
|
+
binding({ type: "onClosePage", id: this._id, code, reason, wasClean: true });
|
|
216
|
+
}
|
|
217
|
+
// --- methods called from the routing API ---
|
|
218
|
+
_apiEnsureOpened() {
|
|
219
|
+
if (!this._ws)
|
|
220
|
+
this._ensureOpened();
|
|
221
|
+
}
|
|
222
|
+
_apiSendToPage(message) {
|
|
223
|
+
this._ensureOpened();
|
|
224
|
+
if (this.readyState !== _WebSocketMock.OPEN)
|
|
225
|
+
throw new DOMException(\`WebSocket is already in CLOSING or CLOSED state.\`);
|
|
226
|
+
this.dispatchEvent(new MessageEvent("message", { data: message, origin: this._origin, cancelable: true }));
|
|
227
|
+
}
|
|
228
|
+
_apiSendToServer(message) {
|
|
229
|
+
if (!this._ws)
|
|
230
|
+
throw new Error("Cannot send a message before connecting to the server");
|
|
231
|
+
if (this._ws.readyState === _WebSocketMock.CONNECTING)
|
|
232
|
+
this._wsBufferedMessages.push(message);
|
|
233
|
+
else
|
|
234
|
+
this._ws.send(message);
|
|
235
|
+
}
|
|
236
|
+
_apiConnect() {
|
|
237
|
+
if (this._ws)
|
|
238
|
+
throw new Error("Can only connect to the server once");
|
|
239
|
+
this._ws = new NativeWebSocket(this.url, this._protocols);
|
|
240
|
+
this._ws.binaryType = this._binaryType;
|
|
241
|
+
this._ws.onopen = () => {
|
|
242
|
+
for (const message of this._wsBufferedMessages)
|
|
243
|
+
this._ws.send(message);
|
|
244
|
+
this._wsBufferedMessages = [];
|
|
245
|
+
this._ensureOpened();
|
|
246
|
+
};
|
|
247
|
+
this._ws.onclose = (event) => {
|
|
248
|
+
this._onWSClose(event.code, event.reason, event.wasClean);
|
|
249
|
+
};
|
|
250
|
+
this._ws.onmessage = (event) => {
|
|
251
|
+
if (this._passthrough)
|
|
252
|
+
this._apiSendToPage(event.data);
|
|
253
|
+
else
|
|
254
|
+
messageToData(event.data, (data) => binding({ type: "onMessageFromServer", id: this._id, data }));
|
|
255
|
+
};
|
|
256
|
+
this._ws.onerror = () => {
|
|
257
|
+
const event = new Event("error", { cancelable: true });
|
|
258
|
+
this.dispatchEvent(event);
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
// This method connects to the server, and passes all messages through,
|
|
262
|
+
// as if WebSocketMock was not engaged.
|
|
263
|
+
_apiPassThrough() {
|
|
264
|
+
this._passthrough = true;
|
|
265
|
+
this._apiConnect();
|
|
266
|
+
}
|
|
267
|
+
_apiCloseServer(code, reason, wasClean) {
|
|
268
|
+
if (!this._ws) {
|
|
269
|
+
this._onWSClose(code, reason, wasClean);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (this._ws.readyState === _WebSocketMock.CONNECTING || this._ws.readyState === _WebSocketMock.OPEN)
|
|
273
|
+
this._ws.close(code, reason);
|
|
274
|
+
}
|
|
275
|
+
_apiClosePage(code, reason, wasClean) {
|
|
276
|
+
if (this.readyState === _WebSocketMock.CLOSED)
|
|
277
|
+
return;
|
|
278
|
+
this.readyState = _WebSocketMock.CLOSED;
|
|
279
|
+
this.dispatchEvent(new CloseEvent("close", { code, reason, wasClean, cancelable: true }));
|
|
280
|
+
this._maybeCleanup();
|
|
281
|
+
if (this._passthrough)
|
|
282
|
+
this._apiCloseServer(code, reason, wasClean);
|
|
283
|
+
else
|
|
284
|
+
binding({ type: "onClosePage", id: this._id, code, reason, wasClean });
|
|
285
|
+
}
|
|
286
|
+
// --- internals ---
|
|
287
|
+
_ensureOpened() {
|
|
288
|
+
var _a;
|
|
289
|
+
if (this.readyState !== _WebSocketMock.CONNECTING)
|
|
290
|
+
return;
|
|
291
|
+
this.extensions = ((_a = this._ws) == null ? void 0 : _a.extensions) || "";
|
|
292
|
+
if (this._ws)
|
|
293
|
+
this.protocol = this._ws.protocol;
|
|
294
|
+
else if (Array.isArray(this._protocols))
|
|
295
|
+
this.protocol = this._protocols[0] || "";
|
|
296
|
+
else
|
|
297
|
+
this.protocol = this._protocols || "";
|
|
298
|
+
this.readyState = _WebSocketMock.OPEN;
|
|
299
|
+
this.dispatchEvent(new Event("open", { cancelable: true }));
|
|
300
|
+
}
|
|
301
|
+
_onWSClose(code, reason, wasClean) {
|
|
302
|
+
if (this._passthrough)
|
|
303
|
+
this._apiClosePage(code, reason, wasClean);
|
|
304
|
+
else
|
|
305
|
+
binding({ type: "onCloseServer", id: this._id, code, reason, wasClean });
|
|
306
|
+
if (this._ws) {
|
|
307
|
+
this._ws.onopen = null;
|
|
308
|
+
this._ws.onclose = null;
|
|
309
|
+
this._ws.onmessage = null;
|
|
310
|
+
this._ws.onerror = null;
|
|
311
|
+
this._ws = void 0;
|
|
312
|
+
this._wsBufferedMessages = [];
|
|
313
|
+
}
|
|
314
|
+
this._maybeCleanup();
|
|
315
|
+
}
|
|
316
|
+
_maybeCleanup() {
|
|
317
|
+
if (this.readyState === _WebSocketMock.CLOSED && !this._ws)
|
|
318
|
+
idToWebSocket.delete(this._id);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
_WebSocketMock.CONNECTING = 0;
|
|
322
|
+
// WebSocket.CONNECTING
|
|
323
|
+
_WebSocketMock.OPEN = 1;
|
|
324
|
+
// WebSocket.OPEN
|
|
325
|
+
_WebSocketMock.CLOSING = 2;
|
|
326
|
+
// WebSocket.CLOSING
|
|
327
|
+
_WebSocketMock.CLOSED = 3;
|
|
328
|
+
let WebSocketMock = _WebSocketMock;
|
|
329
|
+
globalThis.WebSocket = class WebSocket extends WebSocketMock {
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
`;
|
|
333
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
334
|
+
0 && (module.exports = {
|
|
335
|
+
source
|
|
336
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var inProcessFactory_exports = {};
|
|
20
|
+
__export(inProcessFactory_exports, {
|
|
21
|
+
createInProcessPlaywright: () => createInProcessPlaywright
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(inProcessFactory_exports);
|
|
24
|
+
var import_androidServerImpl = require("./androidServerImpl");
|
|
25
|
+
var import_browserServerImpl = require("./browserServerImpl");
|
|
26
|
+
var import_server = require("./server");
|
|
27
|
+
var import_nodePlatform = require("./server/utils/nodePlatform");
|
|
28
|
+
var import_connection = require("./client/connection");
|
|
29
|
+
function createInProcessPlaywright() {
|
|
30
|
+
const playwright = (0, import_server.createPlaywright)({ sdkLanguage: process.env.PW_LANG_NAME || "javascript" });
|
|
31
|
+
const clientConnection = new import_connection.Connection(import_nodePlatform.nodePlatform);
|
|
32
|
+
clientConnection.useRawBuffers();
|
|
33
|
+
const dispatcherConnection = new import_server.DispatcherConnection(
|
|
34
|
+
true
|
|
35
|
+
/* local */
|
|
36
|
+
);
|
|
37
|
+
dispatcherConnection.onmessage = (message) => clientConnection.dispatch(message);
|
|
38
|
+
clientConnection.onmessage = (message) => dispatcherConnection.dispatch(message);
|
|
39
|
+
const rootScope = new import_server.RootDispatcher(dispatcherConnection);
|
|
40
|
+
new import_server.PlaywrightDispatcher(rootScope, playwright);
|
|
41
|
+
const playwrightAPI = clientConnection.getObjectWithKnownName("Playwright");
|
|
42
|
+
playwrightAPI.chromium._serverLauncher = new import_browserServerImpl.BrowserServerLauncherImpl("chromium");
|
|
43
|
+
playwrightAPI.firefox._serverLauncher = new import_browserServerImpl.BrowserServerLauncherImpl("firefox");
|
|
44
|
+
playwrightAPI.webkit._serverLauncher = new import_browserServerImpl.BrowserServerLauncherImpl("webkit");
|
|
45
|
+
playwrightAPI._android._serverLauncher = new import_androidServerImpl.AndroidServerLauncherImpl();
|
|
46
|
+
dispatcherConnection.onmessage = (message) => setImmediate(() => clientConnection.dispatch(message));
|
|
47
|
+
clientConnection.onmessage = (message) => setImmediate(() => dispatcherConnection.dispatch(message));
|
|
48
|
+
clientConnection.toImpl = (x) => {
|
|
49
|
+
if (x instanceof import_connection.Connection)
|
|
50
|
+
return x === clientConnection ? dispatcherConnection : void 0;
|
|
51
|
+
if (!x)
|
|
52
|
+
return dispatcherConnection._dispatcherByGuid.get("");
|
|
53
|
+
return dispatcherConnection._dispatcherByGuid.get(x._guid)._object;
|
|
54
|
+
};
|
|
55
|
+
return playwrightAPI;
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
createInProcessPlaywright
|
|
60
|
+
});
|
package/lib/inprocess.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var outofprocess_exports = {};
|
|
30
|
+
__export(outofprocess_exports, {
|
|
31
|
+
start: () => start
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(outofprocess_exports);
|
|
34
|
+
var childProcess = __toESM(require("child_process"));
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_connection = require("./client/connection");
|
|
37
|
+
var import_pipeTransport = require("./server/utils/pipeTransport");
|
|
38
|
+
var import_manualPromise = require("./utils/isomorphic/manualPromise");
|
|
39
|
+
var import_nodePlatform = require("./server/utils/nodePlatform");
|
|
40
|
+
async function start(env = {}) {
|
|
41
|
+
const client = new PlaywrightClient(env);
|
|
42
|
+
const playwright = await client._playwright;
|
|
43
|
+
playwright.driverProcess = client._driverProcess;
|
|
44
|
+
return { playwright, stop: () => client.stop() };
|
|
45
|
+
}
|
|
46
|
+
class PlaywrightClient {
|
|
47
|
+
constructor(env) {
|
|
48
|
+
this._closePromise = new import_manualPromise.ManualPromise();
|
|
49
|
+
this._driverProcess = childProcess.fork(import_path.default.join(__dirname, "..", "cli.js"), ["run-driver"], {
|
|
50
|
+
stdio: "pipe",
|
|
51
|
+
detached: true,
|
|
52
|
+
env: {
|
|
53
|
+
...process.env,
|
|
54
|
+
...env
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
this._driverProcess.unref();
|
|
58
|
+
this._driverProcess.stderr.on("data", (data) => process.stderr.write(data));
|
|
59
|
+
const connection = new import_connection.Connection(import_nodePlatform.nodePlatform);
|
|
60
|
+
const transport = new import_pipeTransport.PipeTransport(this._driverProcess.stdin, this._driverProcess.stdout);
|
|
61
|
+
connection.onmessage = (message) => transport.send(JSON.stringify(message));
|
|
62
|
+
transport.onmessage = (message) => connection.dispatch(JSON.parse(message));
|
|
63
|
+
transport.onclose = () => this._closePromise.resolve();
|
|
64
|
+
this._playwright = connection.initializePlaywright();
|
|
65
|
+
}
|
|
66
|
+
async stop() {
|
|
67
|
+
this._driverProcess.stdin.destroy();
|
|
68
|
+
this._driverProcess.stdout.destroy();
|
|
69
|
+
this._driverProcess.stderr.destroy();
|
|
70
|
+
await this._closePromise;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
start
|
|
76
|
+
});
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var serializers_exports = {};
|
|
20
|
+
__export(serializers_exports, {
|
|
21
|
+
parseSerializedValue: () => parseSerializedValue,
|
|
22
|
+
serializeValue: () => serializeValue
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(serializers_exports);
|
|
25
|
+
function parseSerializedValue(value, handles) {
|
|
26
|
+
return innerParseSerializedValue(value, handles, /* @__PURE__ */ new Map(), []);
|
|
27
|
+
}
|
|
28
|
+
function innerParseSerializedValue(value, handles, refs, accessChain) {
|
|
29
|
+
if (value.ref !== void 0)
|
|
30
|
+
return refs.get(value.ref);
|
|
31
|
+
if (value.n !== void 0)
|
|
32
|
+
return value.n;
|
|
33
|
+
if (value.s !== void 0)
|
|
34
|
+
return value.s;
|
|
35
|
+
if (value.b !== void 0)
|
|
36
|
+
return value.b;
|
|
37
|
+
if (value.v !== void 0) {
|
|
38
|
+
if (value.v === "undefined")
|
|
39
|
+
return void 0;
|
|
40
|
+
if (value.v === "null")
|
|
41
|
+
return null;
|
|
42
|
+
if (value.v === "NaN")
|
|
43
|
+
return NaN;
|
|
44
|
+
if (value.v === "Infinity")
|
|
45
|
+
return Infinity;
|
|
46
|
+
if (value.v === "-Infinity")
|
|
47
|
+
return -Infinity;
|
|
48
|
+
if (value.v === "-0")
|
|
49
|
+
return -0;
|
|
50
|
+
}
|
|
51
|
+
if (value.d !== void 0)
|
|
52
|
+
return new Date(value.d);
|
|
53
|
+
if (value.u !== void 0)
|
|
54
|
+
return new URL(value.u);
|
|
55
|
+
if (value.bi !== void 0)
|
|
56
|
+
return BigInt(value.bi);
|
|
57
|
+
if (value.e !== void 0) {
|
|
58
|
+
const error = new Error(value.e.m);
|
|
59
|
+
error.name = value.e.n;
|
|
60
|
+
error.stack = value.e.s;
|
|
61
|
+
return error;
|
|
62
|
+
}
|
|
63
|
+
if (value.r !== void 0)
|
|
64
|
+
return new RegExp(value.r.p, value.r.f);
|
|
65
|
+
if (value.ta !== void 0) {
|
|
66
|
+
const ctor = typedArrayKindToConstructor[value.ta.k];
|
|
67
|
+
return new ctor(value.ta.b.buffer, value.ta.b.byteOffset, value.ta.b.length / ctor.BYTES_PER_ELEMENT);
|
|
68
|
+
}
|
|
69
|
+
if (value.a !== void 0) {
|
|
70
|
+
const result = [];
|
|
71
|
+
refs.set(value.id, result);
|
|
72
|
+
for (let i = 0; i < value.a.length; i++)
|
|
73
|
+
result.push(innerParseSerializedValue(value.a[i], handles, refs, [...accessChain, i]));
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
if (value.o !== void 0) {
|
|
77
|
+
const result = {};
|
|
78
|
+
refs.set(value.id, result);
|
|
79
|
+
for (const { k, v } of value.o)
|
|
80
|
+
result[k] = innerParseSerializedValue(v, handles, refs, [...accessChain, k]);
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
if (value.h !== void 0) {
|
|
84
|
+
if (handles === void 0)
|
|
85
|
+
throw new Error("Unexpected handle");
|
|
86
|
+
return handles[value.h];
|
|
87
|
+
}
|
|
88
|
+
throw new Error(`Attempting to deserialize unexpected value${accessChainToDisplayString(accessChain)}: ${value}`);
|
|
89
|
+
}
|
|
90
|
+
function serializeValue(value, handleSerializer) {
|
|
91
|
+
return innerSerializeValue(value, handleSerializer, { lastId: 0, visited: /* @__PURE__ */ new Map() }, []);
|
|
92
|
+
}
|
|
93
|
+
function innerSerializeValue(value, handleSerializer, visitorInfo, accessChain) {
|
|
94
|
+
const handle = handleSerializer(value);
|
|
95
|
+
if ("fallThrough" in handle)
|
|
96
|
+
value = handle.fallThrough;
|
|
97
|
+
else
|
|
98
|
+
return handle;
|
|
99
|
+
if (typeof value === "symbol")
|
|
100
|
+
return { v: "undefined" };
|
|
101
|
+
if (Object.is(value, void 0))
|
|
102
|
+
return { v: "undefined" };
|
|
103
|
+
if (Object.is(value, null))
|
|
104
|
+
return { v: "null" };
|
|
105
|
+
if (Object.is(value, NaN))
|
|
106
|
+
return { v: "NaN" };
|
|
107
|
+
if (Object.is(value, Infinity))
|
|
108
|
+
return { v: "Infinity" };
|
|
109
|
+
if (Object.is(value, -Infinity))
|
|
110
|
+
return { v: "-Infinity" };
|
|
111
|
+
if (Object.is(value, -0))
|
|
112
|
+
return { v: "-0" };
|
|
113
|
+
if (typeof value === "boolean")
|
|
114
|
+
return { b: value };
|
|
115
|
+
if (typeof value === "number")
|
|
116
|
+
return { n: value };
|
|
117
|
+
if (typeof value === "string")
|
|
118
|
+
return { s: value };
|
|
119
|
+
if (typeof value === "bigint")
|
|
120
|
+
return { bi: value.toString() };
|
|
121
|
+
if (isError(value))
|
|
122
|
+
return { e: { n: value.name, m: value.message, s: value.stack || "" } };
|
|
123
|
+
if (isDate(value))
|
|
124
|
+
return { d: value.toJSON() };
|
|
125
|
+
if (isURL(value))
|
|
126
|
+
return { u: value.toJSON() };
|
|
127
|
+
if (isRegExp(value))
|
|
128
|
+
return { r: { p: value.source, f: value.flags } };
|
|
129
|
+
const typedArrayKind = constructorToTypedArrayKind.get(value.constructor);
|
|
130
|
+
if (typedArrayKind)
|
|
131
|
+
return { ta: { b: Buffer.from(value.buffer, value.byteOffset, value.byteLength), k: typedArrayKind } };
|
|
132
|
+
const id = visitorInfo.visited.get(value);
|
|
133
|
+
if (id)
|
|
134
|
+
return { ref: id };
|
|
135
|
+
if (Array.isArray(value)) {
|
|
136
|
+
const a = [];
|
|
137
|
+
const id2 = ++visitorInfo.lastId;
|
|
138
|
+
visitorInfo.visited.set(value, id2);
|
|
139
|
+
for (let i = 0; i < value.length; ++i)
|
|
140
|
+
a.push(innerSerializeValue(value[i], handleSerializer, visitorInfo, [...accessChain, i]));
|
|
141
|
+
return { a, id: id2 };
|
|
142
|
+
}
|
|
143
|
+
if (typeof value === "object") {
|
|
144
|
+
const o = [];
|
|
145
|
+
const id2 = ++visitorInfo.lastId;
|
|
146
|
+
visitorInfo.visited.set(value, id2);
|
|
147
|
+
for (const name of Object.keys(value))
|
|
148
|
+
o.push({ k: name, v: innerSerializeValue(value[name], handleSerializer, visitorInfo, [...accessChain, name]) });
|
|
149
|
+
return { o, id: id2 };
|
|
150
|
+
}
|
|
151
|
+
throw new Error(`Attempting to serialize unexpected value${accessChainToDisplayString(accessChain)}: ${value}`);
|
|
152
|
+
}
|
|
153
|
+
function accessChainToDisplayString(accessChain) {
|
|
154
|
+
const chainString = accessChain.map((accessor, i) => {
|
|
155
|
+
if (typeof accessor === "string")
|
|
156
|
+
return i ? `.${accessor}` : accessor;
|
|
157
|
+
return `[${accessor}]`;
|
|
158
|
+
}).join("");
|
|
159
|
+
return chainString.length > 0 ? ` at position "${chainString}"` : "";
|
|
160
|
+
}
|
|
161
|
+
function isRegExp(obj) {
|
|
162
|
+
return obj instanceof RegExp || Object.prototype.toString.call(obj) === "[object RegExp]";
|
|
163
|
+
}
|
|
164
|
+
function isDate(obj) {
|
|
165
|
+
return obj instanceof Date || Object.prototype.toString.call(obj) === "[object Date]";
|
|
166
|
+
}
|
|
167
|
+
function isURL(obj) {
|
|
168
|
+
return obj instanceof URL || Object.prototype.toString.call(obj) === "[object URL]";
|
|
169
|
+
}
|
|
170
|
+
function isError(obj) {
|
|
171
|
+
const proto = obj ? Object.getPrototypeOf(obj) : null;
|
|
172
|
+
return obj instanceof Error || proto?.name === "Error" || proto && isError(proto);
|
|
173
|
+
}
|
|
174
|
+
const typedArrayKindToConstructor = {
|
|
175
|
+
i8: Int8Array,
|
|
176
|
+
ui8: Uint8Array,
|
|
177
|
+
ui8c: Uint8ClampedArray,
|
|
178
|
+
i16: Int16Array,
|
|
179
|
+
ui16: Uint16Array,
|
|
180
|
+
i32: Int32Array,
|
|
181
|
+
ui32: Uint32Array,
|
|
182
|
+
f32: Float32Array,
|
|
183
|
+
f64: Float64Array,
|
|
184
|
+
bi64: BigInt64Array,
|
|
185
|
+
bui64: BigUint64Array
|
|
186
|
+
};
|
|
187
|
+
const constructorToTypedArrayKind = new Map(Object.entries(typedArrayKindToConstructor).map(([k, v]) => [v, k]));
|
|
188
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
189
|
+
0 && (module.exports = {
|
|
190
|
+
parseSerializedValue,
|
|
191
|
+
serializeValue
|
|
192
|
+
});
|