phantomwright-driver-core 1.57.0 → 1.57.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.
Files changed (49) hide show
  1. package/bin/reinstall_chrome_beta_linux.sh +0 -0
  2. package/bin/reinstall_chrome_beta_mac.sh +0 -0
  3. package/bin/reinstall_chrome_stable_linux.sh +0 -0
  4. package/bin/reinstall_chrome_stable_mac.sh +0 -0
  5. package/bin/reinstall_msedge_beta_linux.sh +0 -0
  6. package/bin/reinstall_msedge_beta_mac.sh +0 -0
  7. package/bin/reinstall_msedge_dev_linux.sh +0 -0
  8. package/bin/reinstall_msedge_dev_mac.sh +0 -0
  9. package/bin/reinstall_msedge_stable_linux.sh +0 -0
  10. package/bin/reinstall_msedge_stable_mac.sh +0 -0
  11. package/lib/client/browserContext.js +19 -0
  12. package/lib/client/clientHelper.js +1 -2
  13. package/lib/client/clock.js +1 -0
  14. package/lib/client/frame.js +9 -9
  15. package/lib/client/jsHandle.js +4 -4
  16. package/lib/client/locator.js +28 -7
  17. package/lib/client/page.js +25 -6
  18. package/lib/client/tracing.js +1 -0
  19. package/lib/client/worker.js +6 -6
  20. package/lib/generated/injectedScriptSource.js +1 -1
  21. package/lib/protocol/validator.js +20 -8
  22. package/lib/server/browserContext.js +10 -23
  23. package/lib/server/chromium/chromiumSwitches.js +2 -14
  24. package/lib/server/chromium/crBrowser.js +7 -2
  25. package/lib/server/chromium/crDevTools.js +0 -1
  26. package/lib/server/chromium/crNetworkManager.js +246 -7
  27. package/lib/server/chromium/crPage.js +119 -41
  28. package/lib/server/chromium/crServiceWorker.js +10 -2
  29. package/lib/server/clock.js +8 -0
  30. package/lib/server/dispatchers/frameDispatcher.js +3 -3
  31. package/lib/server/dispatchers/jsHandleDispatcher.js +2 -2
  32. package/lib/server/frameSelectors.js +167 -5
  33. package/lib/server/frames.js +525 -181
  34. package/lib/server/javascript.js +22 -6
  35. package/lib/server/page.js +40 -58
  36. package/lib/server/pageBinding.js +87 -0
  37. package/lib/server/registry/index.js +1 -1
  38. package/lib/utils/isomorphic/oldUtilityScriptSerializers.js +248 -0
  39. package/lib/utilsBundleImpl/xdg-open +0 -0
  40. package/lib/vite/recorder/assets/{codeMirrorModule-BoWUGj0J.js → codeMirrorModule-CBbSe-ZI.js} +1 -1
  41. package/lib/vite/recorder/assets/{index-DJqDAOZp.js → index-CpZVd2nA.js} +3 -3
  42. package/lib/vite/recorder/index.html +1 -1
  43. package/lib/vite/traceViewer/assets/{codeMirrorModule-Bucv2d7q.js → codeMirrorModule-DHz0wP2C.js} +1 -1
  44. package/lib/vite/traceViewer/assets/{defaultSettingsView-BEpdCv1S.js → defaultSettingsView-WsZP88O6.js} +87 -87
  45. package/lib/vite/traceViewer/{index.BxQ34UMZ.js → index.C8xAeo93.js} +1 -1
  46. package/lib/vite/traceViewer/index.html +2 -2
  47. package/lib/vite/traceViewer/{uiMode.BWTwXl41.js → uiMode.BltraIJB.js} +1 -1
  48. package/lib/vite/traceViewer/uiMode.html +2 -2
  49. package/package.json +42 -42
@@ -113,14 +113,30 @@ class JSHandle extends import_instrumentation.SdkObject {
113
113
  async evaluateHandle(pageFunction, arg) {
114
114
  return evaluate(this._context, false, pageFunction, this, arg);
115
115
  }
116
- async evaluateExpression(expression, options, arg) {
117
- const value = await evaluateExpression(this._context, expression, { ...options, returnByValue: true }, this, arg);
118
- await this._context.doSlowMo();
116
+ async evaluateExpression(expression, options, arg, isolatedContext) {
117
+ let context = this._context;
118
+ if (context.constructor.name === "FrameExecutionContext") {
119
+ const frame = context.frame;
120
+ if (frame) {
121
+ if (isolatedContext === true) context = await frame._utilityContext();
122
+ else if (isolatedContext === false) context = await frame._mainContext();
123
+ }
124
+ }
125
+ const value = await evaluateExpression(context, expression, { ...options, returnByValue: true }, this, arg);
126
+ await context.doSlowMo();
119
127
  return value;
120
128
  }
121
- async evaluateExpressionHandle(expression, options, arg) {
122
- const value = await evaluateExpression(this._context, expression, { ...options, returnByValue: false }, this, arg);
123
- await this._context.doSlowMo();
129
+ async evaluateExpressionHandle(expression, options, arg, isolatedContext) {
130
+ let context = this._context;
131
+ if (context.constructor.name === "FrameExecutionContext") {
132
+ const frame = this._context.frame;
133
+ if (frame) {
134
+ if (isolatedContext === true) context = await frame._utilityContext();
135
+ else if (isolatedContext === false) context = await frame._mainContext();
136
+ }
137
+ }
138
+ const value = await evaluateExpression(context, expression, { ...options, returnByValue: false }, this, arg);
139
+ await context.doSlowMo();
124
140
  return value;
125
141
  }
126
142
  async getProperty(propertyName) {
@@ -34,6 +34,7 @@ __export(page_exports, {
34
34
  Worker: () => Worker
35
35
  });
36
36
  module.exports = __toCommonJS(page_exports);
37
+ var import_pageBinding = require("./pageBinding");
37
38
  var import_browserContext = require("./browserContext");
38
39
  var import_console = require("./console");
39
40
  var import_errors = require("./errors");
@@ -52,7 +53,6 @@ var import_selectorParser = require("../utils/isomorphic/selectorParser");
52
53
  var import_manualPromise = require("../utils/isomorphic/manualPromise");
53
54
  var import_utilityScriptSerializers = require("../utils/isomorphic/utilityScriptSerializers");
54
55
  var import_callLog = require("./callLog");
55
- var rawBindingsControllerSource = __toESM(require("../generated/bindingsControllerSource"));
56
56
  class Page extends import_instrumentation.SdkObject {
57
57
  constructor(delegate, browserContext) {
58
58
  super(browserContext, "page");
@@ -202,26 +202,16 @@ class Page extends import_instrumentation.SdkObject {
202
202
  throw new Error(`Function "${name}" has been already registered`);
203
203
  if (this.browserContext._pageBindings.has(name))
204
204
  throw new Error(`Function "${name}" has been already registered in the browser context`);
205
- await progress.race(this.browserContext.exposePlaywrightBindingIfNeeded());
206
205
  const binding = new PageBinding(name, playwrightBinding, needsHandle);
207
206
  this._pageBindings.set(name, binding);
208
- try {
209
- await progress.race(this.delegate.addInitScript(binding.initScript));
210
- await progress.race(this.safeNonStallingEvaluateInAllFrames(binding.initScript.source, "main"));
211
- return binding;
212
- } catch (error) {
213
- this._pageBindings.delete(name);
214
- throw error;
215
- }
207
+ await this.delegate.exposeBinding(binding);
216
208
  }
217
209
  async removeExposedBindings(bindings) {
218
- bindings = bindings.filter((binding) => this._pageBindings.get(binding.name) === binding);
219
- for (const binding of bindings)
220
- this._pageBindings.delete(binding.name);
221
- await this.delegate.removeInitScripts(bindings.map((binding) => binding.initScript));
222
- const cleanup = bindings.map((binding) => `{ ${binding.cleanupScript} };
223
- `).join("");
224
- await this.safeNonStallingEvaluateInAllFrames(cleanup, "main");
210
+ for (const key of this._pageBindings.keys()) {
211
+ if (!key.startsWith("__pw"))
212
+ this._pageBindings.delete(key);
213
+ }
214
+ await this.delegate.removeExposedBindings();
225
215
  }
226
216
  async setExtraHTTPHeaders(progress, headers) {
227
217
  const oldHeaders = this._extraHTTPHeaders;
@@ -462,9 +452,8 @@ class Page extends import_instrumentation.SdkObject {
462
452
  return initScript;
463
453
  }
464
454
  async removeInitScripts(initScripts) {
465
- const set = new Set(initScripts);
466
- this.initScripts = this.initScripts.filter((script) => !set.has(script));
467
- await this.delegate.removeInitScripts(initScripts);
455
+ this.initScripts.splice(0, this.initScripts.length);
456
+ await this.delegate.removeInitScripts();
468
457
  }
469
458
  needsRequestInterception() {
470
459
  return this.requestInterceptors.length > 0 || this.browserContext.requestInterceptors.length > 0;
@@ -632,12 +621,6 @@ class Page extends import_instrumentation.SdkObject {
632
621
  if (origin)
633
622
  this.browserContext.addVisitedOrigin(origin);
634
623
  }
635
- allInitScripts() {
636
- const bindings = [...this.browserContext._pageBindings.values(), ...this._pageBindings.values()].map((binding) => binding.initScript);
637
- if (this.browserContext.bindingsInitScript)
638
- bindings.unshift(this.browserContext.bindingsInitScript);
639
- return [...bindings, ...this.browserContext.initScripts, ...this.initScripts];
640
- }
641
624
  getBinding(name) {
642
625
  return this._pageBindings.get(name) || this.browserContext._pageBindings.get(name);
643
626
  }
@@ -669,6 +652,9 @@ class Page extends import_instrumentation.SdkObject {
669
652
  const snapshot = await snapshotFrameForAI(progress, this.mainFrame(), options);
670
653
  return { full: snapshot.full.join("\n"), incremental: snapshot.incremental?.join("\n") };
671
654
  }
655
+ allBindings() {
656
+ return [...this.browserContext._pageBindings.values(), ...this._pageBindings.values()];
657
+ }
672
658
  }
673
659
  class Worker extends import_instrumentation.SdkObject {
674
660
  constructor(parent, url) {
@@ -701,37 +687,35 @@ class Worker extends import_instrumentation.SdkObject {
701
687
  this.emit(Worker.Events.Close, this);
702
688
  this.openScope.close(new Error("Worker closed"));
703
689
  }
704
- async evaluateExpression(expression, isFunction, arg) {
705
- return js.evaluateExpression(await this._executionContextPromise, expression, { returnByValue: true, isFunction }, arg);
706
- }
707
- async evaluateExpressionHandle(expression, isFunction, arg) {
708
- return js.evaluateExpression(await this._executionContextPromise, expression, { returnByValue: false, isFunction }, arg);
690
+ async evaluateExpression(expression, isFunction, arg, isolatedContext) {
691
+ let context = await this._executionContextPromise;
692
+ if (context.constructor.name === "FrameExecutionContext") {
693
+ const frame = context.frame;
694
+ if (frame) {
695
+ if (isolatedContext) context = await frame._utilityContext();
696
+ else if (!isolatedContext) context = await frame._mainContext();
697
+ }
698
+ }
699
+ return js.evaluateExpression(context, expression, { returnByValue: true, isFunction }, arg);
700
+ }
701
+ async evaluateExpressionHandle(expression, isFunction, arg, isolatedContext) {
702
+ let context = await this._executionContextPromise;
703
+ if (context.constructor.name === "FrameExecutionContext") {
704
+ const frame = this._context.frame;
705
+ if (frame) {
706
+ if (isolatedContext) context = await frame._utilityContext();
707
+ else if (!isolatedContext) context = await frame._mainContext();
708
+ }
709
+ }
710
+ return js.evaluateExpression(context, expression, { returnByValue: false, isFunction }, arg);
709
711
  }
710
712
  }
711
713
  class PageBinding {
712
- static {
713
- this.kController = "__playwright__binding__controller__";
714
- }
715
- static {
716
- this.kBindingName = "__playwright__binding__";
717
- }
718
- static createInitScript() {
719
- return new InitScript(`
720
- (() => {
721
- const module = {};
722
- ${rawBindingsControllerSource.source}
723
- const property = '${PageBinding.kController}';
724
- if (!globalThis[property])
725
- globalThis[property] = new (module.exports.BindingsController())(globalThis, '${PageBinding.kBindingName}');
726
- })();
727
- `);
728
- }
729
714
  constructor(name, playwrightFunction, needsHandle) {
730
715
  this.name = name;
731
716
  this.playwrightFunction = playwrightFunction;
732
- this.initScript = new InitScript(`globalThis['${PageBinding.kController}'].addBinding(${JSON.stringify(name)}, ${needsHandle})`);
717
+ this.source = (0, import_pageBinding.createPageBindingScript)(name, needsHandle);
733
718
  this.needsHandle = needsHandle;
734
- this.cleanupScript = `globalThis['${PageBinding.kController}'].removeBinding(${JSON.stringify(name)})`;
735
719
  }
736
720
  static async dispatch(page, payload, context) {
737
721
  const { name, seq, serializedArgs } = JSON.parse(payload);
@@ -742,25 +726,23 @@ class PageBinding {
742
726
  throw new Error(`Function "${name}" is not exposed`);
743
727
  let result;
744
728
  if (binding.needsHandle) {
745
- const handle = await context.evaluateExpressionHandle(`arg => globalThis['${PageBinding.kController}'].takeBindingHandle(arg)`, { isFunction: true }, { name, seq }).catch((e) => null);
746
- result = await binding.playwrightFunction({ frame: context.frame, page, context: page.browserContext }, handle);
729
+ const handle = await context.evaluateHandle(import_pageBinding.takeBindingHandle, { name, seq }).catch((e) => null);
730
+ result = await binding.playwrightFunction({ frame: context.frame, page, context: page._browserContext }, handle);
747
731
  } else {
748
732
  if (!Array.isArray(serializedArgs))
749
733
  throw new Error(`serializedArgs is not an array. This can happen when Array.prototype.toJSON is defined incorrectly`);
750
734
  const args = serializedArgs.map((a) => (0, import_utilityScriptSerializers.parseEvaluationResultValue)(a));
751
- result = await binding.playwrightFunction({ frame: context.frame, page, context: page.browserContext }, ...args);
735
+ result = await binding.playwrightFunction({ frame: context.frame, page, context: page._browserContext }, ...args);
752
736
  }
753
- context.evaluateExpressionHandle(`arg => globalThis['${PageBinding.kController}'].deliverBindingResult(arg)`, { isFunction: true }, { name, seq, result }).catch((e) => import_debugLogger.debugLogger.log("error", e));
737
+ context.evaluate(import_pageBinding.deliverBindingResult, { name, seq, result }).catch((e) => import_debugLogger.debugLogger.log("error", e));
754
738
  } catch (error) {
755
- context.evaluateExpressionHandle(`arg => globalThis['${PageBinding.kController}'].deliverBindingResult(arg)`, { isFunction: true }, { name, seq, error }).catch((e) => import_debugLogger.debugLogger.log("error", e));
739
+ context.evaluate(import_pageBinding.deliverBindingResult, { name, seq, error }).catch((e) => import_debugLogger.debugLogger.log("error", e));
756
740
  }
757
741
  }
758
742
  }
759
743
  class InitScript {
760
744
  constructor(source) {
761
- this.source = `(() => {
762
- ${source}
763
- })();`;
745
+ this.source = `(() => { ${source} })();`;
764
746
  }
765
747
  }
766
748
  class FrameThrottler {
@@ -0,0 +1,87 @@
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 pageBinding_exports = {};
20
+ __export(pageBinding_exports, {
21
+ createPageBindingScript: () => createPageBindingScript,
22
+ deliverBindingResult: () => deliverBindingResult,
23
+ takeBindingHandle: () => takeBindingHandle
24
+ });
25
+ module.exports = __toCommonJS(pageBinding_exports);
26
+ var import_oldUtilityScriptSerializers = require("../utils/isomorphic/oldUtilityScriptSerializers");
27
+ function addPageBinding(bindingName, needsHandle, utilityScriptSerializersFactory) {
28
+ const { serializeAsCallArgument } = utilityScriptSerializersFactory;
29
+ const binding = globalThis[bindingName];
30
+ if (!binding || binding.toString().startsWith("(...args) => {")) return;
31
+ globalThis[bindingName] = (...args) => {
32
+ const me = globalThis[bindingName];
33
+ if (needsHandle && args.slice(1).some((arg) => arg !== void 0))
34
+ throw new Error(`exposeBindingHandle supports a single argument, ${args.length} received`);
35
+ let callbacks = me["callbacks"];
36
+ if (!callbacks) {
37
+ callbacks = /* @__PURE__ */ new Map();
38
+ me["callbacks"] = callbacks;
39
+ }
40
+ const seq = (me["lastSeq"] || 0) + 1;
41
+ me["lastSeq"] = seq;
42
+ let handles = me["handles"];
43
+ if (!handles) {
44
+ handles = /* @__PURE__ */ new Map();
45
+ me["handles"] = handles;
46
+ }
47
+ const promise = new Promise((resolve, reject) => callbacks.set(seq, { resolve, reject }));
48
+ let payload;
49
+ if (needsHandle) {
50
+ handles.set(seq, args[0]);
51
+ payload = { name: bindingName, seq };
52
+ } else {
53
+ const serializedArgs = [];
54
+ for (let i = 0; i < args.length; i++) {
55
+ serializedArgs[i] = serializeAsCallArgument(args[i], (v) => {
56
+ return { fallThrough: v };
57
+ });
58
+ }
59
+ payload = { name: bindingName, seq, serializedArgs };
60
+ }
61
+ binding(JSON.stringify(payload));
62
+ return promise;
63
+ };
64
+ }
65
+ function takeBindingHandle(arg) {
66
+ const handles = globalThis[arg.name]["handles"];
67
+ const handle = handles.get(arg.seq);
68
+ handles.delete(arg.seq);
69
+ return handle;
70
+ }
71
+ function deliverBindingResult(arg) {
72
+ const callbacks = globalThis[arg.name]["callbacks"];
73
+ if ("error" in arg)
74
+ callbacks.get(arg.seq).reject(arg.error);
75
+ else
76
+ callbacks.get(arg.seq).resolve(arg.result);
77
+ callbacks.delete(arg.seq);
78
+ }
79
+ function createPageBindingScript(name, needsHandle) {
80
+ return `(${addPageBinding.toString()})(${JSON.stringify(name)}, ${needsHandle}, (${import_oldUtilityScriptSerializers.source})())`;
81
+ }
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ createPageBindingScript,
85
+ deliverBindingResult,
86
+ takeBindingHandle
87
+ });
@@ -1331,7 +1331,7 @@ function buildPlaywrightCLICommand(sdkLanguage, parameters) {
1331
1331
  return `pwsh bin/Debug/netX/playwright.ps1 ${parameters}`;
1332
1332
  default: {
1333
1333
  const packageManagerCommand = (0, import_utils.getPackageManagerExecCommand)();
1334
- return `${packageManagerCommand} playwright ${parameters}`;
1334
+ return `${packageManagerCommand} patchright ${parameters}`;
1335
1335
  }
1336
1336
  }
1337
1337
  }
@@ -0,0 +1,248 @@
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 oldUtilityScriptSerializers_exports = {};
20
+ __export(oldUtilityScriptSerializers_exports, {
21
+ source: () => source
22
+ });
23
+ module.exports = __toCommonJS(oldUtilityScriptSerializers_exports);
24
+ function source() {
25
+ function isRegExp(obj) {
26
+ try {
27
+ return obj instanceof RegExp || Object.prototype.toString.call(obj) === "[object RegExp]";
28
+ } catch (error) {
29
+ return false;
30
+ }
31
+ }
32
+ function isDate(obj) {
33
+ try {
34
+ return obj instanceof Date || Object.prototype.toString.call(obj) === "[object Date]";
35
+ } catch (error) {
36
+ return false;
37
+ }
38
+ }
39
+ function isURL(obj) {
40
+ try {
41
+ return obj instanceof URL || Object.prototype.toString.call(obj) === "[object URL]";
42
+ } catch (error) {
43
+ return false;
44
+ }
45
+ }
46
+ function isError(obj) {
47
+ try {
48
+ return obj instanceof Error || obj && Object.getPrototypeOf(obj)?.name === "Error";
49
+ } catch (error) {
50
+ return false;
51
+ }
52
+ }
53
+ function isTypedArray(obj, constructor) {
54
+ try {
55
+ return obj instanceof constructor || Object.prototype.toString.call(obj) === `[object ${constructor.name}]`;
56
+ } catch (error) {
57
+ return false;
58
+ }
59
+ }
60
+ const typedArrayConstructors = {
61
+ i8: Int8Array,
62
+ ui8: Uint8Array,
63
+ ui8c: Uint8ClampedArray,
64
+ i16: Int16Array,
65
+ ui16: Uint16Array,
66
+ i32: Int32Array,
67
+ ui32: Uint32Array,
68
+ // TODO: add Float16Array once it's in baseline
69
+ f32: Float32Array,
70
+ f64: Float64Array,
71
+ bi64: BigInt64Array,
72
+ bui64: BigUint64Array
73
+ };
74
+ function typedArrayToBase64(array) {
75
+ if ("toBase64" in array)
76
+ return array.toBase64();
77
+ const binary = Array.from(new Uint8Array(array.buffer, array.byteOffset, array.byteLength)).map((b) => String.fromCharCode(b)).join("");
78
+ return btoa(binary);
79
+ }
80
+ function base64ToTypedArray(base64, TypedArrayConstructor) {
81
+ const binary = atob(base64);
82
+ const bytes = new Uint8Array(binary.length);
83
+ for (let i = 0; i < binary.length; i++)
84
+ bytes[i] = binary.charCodeAt(i);
85
+ return new TypedArrayConstructor(bytes.buffer);
86
+ }
87
+ function parseEvaluationResultValue(value, handles = [], refs = /* @__PURE__ */ new Map()) {
88
+ if (Object.is(value, void 0))
89
+ return void 0;
90
+ if (typeof value === "object" && value) {
91
+ if ("ref" in value)
92
+ return refs.get(value.ref);
93
+ if ("v" in value) {
94
+ if (value.v === "undefined")
95
+ return void 0;
96
+ if (value.v === "null")
97
+ return null;
98
+ if (value.v === "NaN")
99
+ return NaN;
100
+ if (value.v === "Infinity")
101
+ return Infinity;
102
+ if (value.v === "-Infinity")
103
+ return -Infinity;
104
+ if (value.v === "-0")
105
+ return -0;
106
+ return void 0;
107
+ }
108
+ if ("d" in value)
109
+ return new Date(value.d);
110
+ if ("u" in value)
111
+ return new URL(value.u);
112
+ if ("bi" in value)
113
+ return BigInt(value.bi);
114
+ if ("e" in value) {
115
+ const error = new Error(value.e.m);
116
+ error.name = value.e.n;
117
+ error.stack = value.e.s;
118
+ return error;
119
+ }
120
+ if ("r" in value)
121
+ return new RegExp(value.r.p, value.r.f);
122
+ if ("a" in value) {
123
+ const result = [];
124
+ refs.set(value.id, result);
125
+ for (const a of value.a)
126
+ result.push(parseEvaluationResultValue(a, handles, refs));
127
+ return result;
128
+ }
129
+ if ("o" in value) {
130
+ const result = {};
131
+ refs.set(value.id, result);
132
+ for (const { k, v } of value.o)
133
+ result[k] = parseEvaluationResultValue(v, handles, refs);
134
+ return result;
135
+ }
136
+ if ("h" in value)
137
+ return handles[value.h];
138
+ if ("ta" in value)
139
+ return base64ToTypedArray(value.ta.b, typedArrayConstructors[value.ta.k]);
140
+ }
141
+ return value;
142
+ }
143
+ function serializeAsCallArgument(value, handleSerializer) {
144
+ return serialize(value, handleSerializer, { visited: /* @__PURE__ */ new Map(), lastId: 0 });
145
+ }
146
+ function serialize(value, handleSerializer, visitorInfo) {
147
+ if (value && typeof value === "object") {
148
+ if (typeof globalThis.Window === "function" && value instanceof globalThis.Window)
149
+ return "ref: <Window>";
150
+ if (typeof globalThis.Document === "function" && value instanceof globalThis.Document)
151
+ return "ref: <Document>";
152
+ if (typeof globalThis.Node === "function" && value instanceof globalThis.Node)
153
+ return "ref: <Node>";
154
+ }
155
+ return innerSerialize(value, handleSerializer, visitorInfo);
156
+ }
157
+ function innerSerialize(value, handleSerializer, visitorInfo) {
158
+ const result = handleSerializer(value);
159
+ if ("fallThrough" in result)
160
+ value = result.fallThrough;
161
+ else
162
+ return result;
163
+ if (typeof value === "symbol")
164
+ return { v: "undefined" };
165
+ if (Object.is(value, void 0))
166
+ return { v: "undefined" };
167
+ if (Object.is(value, null))
168
+ return { v: "null" };
169
+ if (Object.is(value, NaN))
170
+ return { v: "NaN" };
171
+ if (Object.is(value, Infinity))
172
+ return { v: "Infinity" };
173
+ if (Object.is(value, -Infinity))
174
+ return { v: "-Infinity" };
175
+ if (Object.is(value, -0))
176
+ return { v: "-0" };
177
+ if (typeof value === "boolean")
178
+ return value;
179
+ if (typeof value === "number")
180
+ return value;
181
+ if (typeof value === "string")
182
+ return value;
183
+ if (typeof value === "bigint")
184
+ return { bi: value.toString() };
185
+ if (isError(value)) {
186
+ let stack;
187
+ if (value.stack?.startsWith(value.name + ": " + value.message)) {
188
+ stack = value.stack;
189
+ } else {
190
+ stack = `${value.name}: ${value.message}
191
+ ${value.stack}`;
192
+ }
193
+ return { e: { n: value.name, m: value.message, s: stack } };
194
+ }
195
+ if (isDate(value))
196
+ return { d: value.toJSON() };
197
+ if (isURL(value))
198
+ return { u: value.toJSON() };
199
+ if (isRegExp(value))
200
+ return { r: { p: value.source, f: value.flags } };
201
+ for (const [k, ctor] of Object.entries(typedArrayConstructors)) {
202
+ if (isTypedArray(value, ctor))
203
+ return { ta: { b: typedArrayToBase64(value), k } };
204
+ }
205
+ const id = visitorInfo.visited.get(value);
206
+ if (id)
207
+ return { ref: id };
208
+ if (Array.isArray(value)) {
209
+ const a = [];
210
+ const id2 = ++visitorInfo.lastId;
211
+ visitorInfo.visited.set(value, id2);
212
+ for (let i = 0; i < value.length; ++i)
213
+ a.push(serialize(value[i], handleSerializer, visitorInfo));
214
+ return { a, id: id2 };
215
+ }
216
+ if (typeof value === "object") {
217
+ const o = [];
218
+ const id2 = ++visitorInfo.lastId;
219
+ visitorInfo.visited.set(value, id2);
220
+ for (const name of Object.keys(value)) {
221
+ let item;
222
+ try {
223
+ item = value[name];
224
+ } catch (e) {
225
+ continue;
226
+ }
227
+ if (name === "toJSON" && typeof item === "function")
228
+ o.push({ k: name, v: { o: [], id: 0 } });
229
+ else
230
+ o.push({ k: name, v: serialize(item, handleSerializer, visitorInfo) });
231
+ }
232
+ let jsonWrapper;
233
+ try {
234
+ if (o.length === 0 && value.toJSON && typeof value.toJSON === "function")
235
+ jsonWrapper = { value: value.toJSON() };
236
+ } catch (e) {
237
+ }
238
+ if (jsonWrapper)
239
+ return innerSerialize(jsonWrapper.value, handleSerializer, visitorInfo);
240
+ return { o, id: id2 };
241
+ }
242
+ }
243
+ return { parseEvaluationResultValue, serializeAsCallArgument };
244
+ }
245
+ // Annotate the CommonJS export names for ESM import in node:
246
+ 0 && (module.exports = {
247
+ source
248
+ });
File without changes