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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -71,6 +71,7 @@ class BrowserContext extends import_channelOwner.ChannelOwner {
71
71
  this._harRecorders = /* @__PURE__ */ new Map();
72
72
  this._closingStatus = "none";
73
73
  this._harRouters = [];
74
+ this.routeInjecting = false;
74
75
  this._options = initializer.options;
75
76
  this._timeoutSettings = new import_timeoutSettings.TimeoutSettings(this._platform);
76
77
  this.tracing = import_tracing.Tracing.from(initializer.tracing);
@@ -308,14 +309,17 @@ class BrowserContext extends import_channelOwner.ChannelOwner {
308
309
  await this._channel.setHTTPCredentials({ httpCredentials: httpCredentials || void 0 });
309
310
  }
310
311
  async addInitScript(script, arg) {
312
+ await this.installInjectRoute();
311
313
  const source = await (0, import_clientHelper.evaluationScript)(this._platform, script, arg);
312
314
  await this._channel.addInitScript({ source });
313
315
  }
314
316
  async exposeBinding(name, callback, options = {}) {
317
+ await this.installInjectRoute();
315
318
  await this._channel.exposeBinding({ name, needsHandle: options.handle });
316
319
  this._bindings.set(name, callback);
317
320
  }
318
321
  async exposeFunction(name, callback) {
322
+ await this.installInjectRoute();
319
323
  await this._channel.exposeBinding({ name });
320
324
  const binding = (source, ...args) => callback(...args);
321
325
  this._bindings.set(name, binding);
@@ -474,6 +478,21 @@ class BrowserContext extends import_channelOwner.ChannelOwner {
474
478
  this._onRecorderEventSink = void 0;
475
479
  await this._channel.disableRecorder();
476
480
  }
481
+ async installInjectRoute() {
482
+ if (this.routeInjecting) return;
483
+ await this.route("**/*", async (route) => {
484
+ try {
485
+ if (route.request().resourceType() === "document" && route.request().url().startsWith("http")) {
486
+ const protocol = route.request().url().split(":")[0];
487
+ await route.fallback({ url: protocol + "://patchright-init-script-inject.internal/" });
488
+ } else {
489
+ await route.fallback();
490
+ }
491
+ } catch (error) {
492
+ await route.fallback();
493
+ }
494
+ });
495
+ }
477
496
  }
478
497
  async function prepareStorageState(platform, storageState) {
479
498
  if (typeof storageState !== "string")
@@ -53,8 +53,7 @@ async function evaluationScript(platform, fun, arg, addSourceUrl = true) {
53
53
  throw new Error("Either path or content property must be present");
54
54
  }
55
55
  function addSourceUrlToScript(source, path) {
56
- return `${source}
57
- //# sourceURL=${path.replace(/\n/g, "")}`;
56
+ return source;
58
57
  }
59
58
  // Annotate the CommonJS export names for ESM import in node:
60
59
  0 && (module.exports = {
@@ -26,6 +26,7 @@ class Clock {
26
26
  this._browserContext = browserContext;
27
27
  }
28
28
  async install(options = {}) {
29
+ await this._browserContext.installInjectRoute();
29
30
  await this._browserContext._channel.clockInstall(options.time !== void 0 ? parseTime(options.time) : {});
30
31
  }
31
32
  async fastForward(ticks) {
@@ -166,14 +166,14 @@ class Frame extends import_channelOwner.ChannelOwner {
166
166
  async frameElement() {
167
167
  return import_elementHandle.ElementHandle.from((await this._channel.frameElement()).element);
168
168
  }
169
- async evaluateHandle(pageFunction, arg) {
170
- (0, import_jsHandle.assertMaxArguments)(arguments.length, 2);
171
- const result = await this._channel.evaluateExpressionHandle({ expression: String(pageFunction), isFunction: typeof pageFunction === "function", arg: (0, import_jsHandle.serializeArgument)(arg) });
169
+ async evaluateHandle(pageFunction, arg, isolatedContext = true) {
170
+ (0, import_jsHandle.assertMaxArguments)(arguments.length, 3);
171
+ const result = await this._channel.evaluateExpressionHandle({ expression: String(pageFunction), isFunction: typeof pageFunction === "function", arg: (0, import_jsHandle.serializeArgument)(arg), isolatedContext });
172
172
  return import_jsHandle.JSHandle.from(result.handle);
173
173
  }
174
- async evaluate(pageFunction, arg) {
175
- (0, import_jsHandle.assertMaxArguments)(arguments.length, 2);
176
- const result = await this._channel.evaluateExpression({ expression: String(pageFunction), isFunction: typeof pageFunction === "function", arg: (0, import_jsHandle.serializeArgument)(arg) });
174
+ async evaluate(pageFunction, arg, isolatedContext = true) {
175
+ (0, import_jsHandle.assertMaxArguments)(arguments.length, 3);
176
+ const result = await this._channel.evaluateExpression({ expression: String(pageFunction), isFunction: typeof pageFunction === "function", arg: (0, import_jsHandle.serializeArgument)(arg), isolatedContext });
177
177
  return (0, import_jsHandle.parseResult)(result.value);
178
178
  }
179
179
  async _evaluateFunction(functionDeclaration) {
@@ -205,9 +205,9 @@ class Frame extends import_channelOwner.ChannelOwner {
205
205
  const result = await this._channel.evalOnSelector({ selector, expression: String(pageFunction), isFunction: typeof pageFunction === "function", arg: (0, import_jsHandle.serializeArgument)(arg) });
206
206
  return (0, import_jsHandle.parseResult)(result.value);
207
207
  }
208
- async $$eval(selector, pageFunction, arg) {
209
- (0, import_jsHandle.assertMaxArguments)(arguments.length, 3);
210
- const result = await this._channel.evalOnSelectorAll({ selector, expression: String(pageFunction), isFunction: typeof pageFunction === "function", arg: (0, import_jsHandle.serializeArgument)(arg) });
208
+ async $$eval(selector, pageFunction, arg, isolatedContext = true) {
209
+ (0, import_jsHandle.assertMaxArguments)(arguments.length, 4);
210
+ const result = await this._channel.evalOnSelectorAll({ selector, expression: String(pageFunction), isFunction: typeof pageFunction === "function", arg: (0, import_jsHandle.serializeArgument)(arg), isolatedContext });
211
211
  return (0, import_jsHandle.parseResult)(result.value);
212
212
  }
213
213
  async $$(selector) {
@@ -36,16 +36,16 @@ class JSHandle extends import_channelOwner.ChannelOwner {
36
36
  this._preview = this._initializer.preview;
37
37
  this._channel.on("previewUpdated", ({ preview }) => this._preview = preview);
38
38
  }
39
- async evaluate(pageFunction, arg) {
40
- const result = await this._channel.evaluateExpression({ expression: String(pageFunction), isFunction: typeof pageFunction === "function", arg: serializeArgument(arg) });
39
+ async evaluate(pageFunction, arg, isolatedContext = true) {
40
+ const result = await this._channel.evaluateExpression({ expression: String(pageFunction), isFunction: typeof pageFunction === "function", arg: serializeArgument(arg), isolatedContext });
41
41
  return parseResult(result.value);
42
42
  }
43
43
  async _evaluateFunction(functionDeclaration) {
44
44
  const result = await this._channel.evaluateExpression({ expression: functionDeclaration, isFunction: true, arg: serializeArgument(void 0) });
45
45
  return parseResult(result.value);
46
46
  }
47
- async evaluateHandle(pageFunction, arg) {
48
- const result = await this._channel.evaluateExpressionHandle({ expression: String(pageFunction), isFunction: typeof pageFunction === "function", arg: serializeArgument(arg) });
47
+ async evaluateHandle(pageFunction, arg, isolatedContext = true) {
48
+ const result = await this._channel.evaluateExpressionHandle({ expression: String(pageFunction), isFunction: typeof pageFunction === "function", arg: serializeArgument(arg), isolatedContext });
49
49
  return JSHandle.from(result.handle);
50
50
  }
51
51
  async getProperty(propertyName) {
@@ -24,6 +24,7 @@ __export(locator_exports, {
24
24
  testIdAttributeName: () => testIdAttributeName
25
25
  });
26
26
  module.exports = __toCommonJS(locator_exports);
27
+ var import_jsHandle = require("./jsHandle");
27
28
  var import_elementHandle = require("./elementHandle");
28
29
  var import_locatorGenerators = require("../utils/isomorphic/locatorGenerators");
29
30
  var import_locatorUtils = require("../utils/isomorphic/locatorUtils");
@@ -97,17 +98,37 @@ class Locator {
97
98
  ...options
98
99
  });
99
100
  }
100
- async evaluate(pageFunction, arg, options) {
101
- return await this._withElement((h) => h.evaluate(pageFunction, arg), { title: "Evaluate", timeout: options?.timeout });
101
+ async evaluate(pageFunction, arg, options, isolatedContext = true) {
102
+ return await this._withElement(
103
+ async (h) => (0, import_jsHandle.parseResult)(
104
+ (await h._channel.evaluateExpression({
105
+ expression: String(pageFunction),
106
+ isFunction: typeof pageFunction === "function",
107
+ arg: (0, import_jsHandle.serializeArgument)(arg),
108
+ isolatedContext
109
+ })).value
110
+ ),
111
+ { title: "Evaluate", timeout: options?.timeout }
112
+ );
102
113
  }
103
114
  async _evaluateFunction(functionDeclaration, options) {
104
115
  return await this._withElement((h) => h._evaluateFunction(functionDeclaration), { title: "Evaluate", timeout: options?.timeout });
105
116
  }
106
- async evaluateAll(pageFunction, arg) {
107
- return await this._frame.$$eval(this._selector, pageFunction, arg);
108
- }
109
- async evaluateHandle(pageFunction, arg, options) {
110
- return await this._withElement((h) => h.evaluateHandle(pageFunction, arg), { title: "Evaluate", timeout: options?.timeout });
117
+ async evaluateAll(pageFunction, arg, isolatedContext = true) {
118
+ return await this._frame.$$eval(this._selector, pageFunction, arg, isolatedContext);
119
+ }
120
+ async evaluateHandle(pageFunction, arg, options, isolatedContext = true) {
121
+ return await this._withElement(
122
+ async (h) => import_jsHandle.JSHandle.from(
123
+ (await h._channel.evaluateExpressionHandle({
124
+ expression: String(pageFunction),
125
+ isFunction: typeof pageFunction === "function",
126
+ arg: (0, import_jsHandle.serializeArgument)(arg),
127
+ isolatedContext
128
+ })).handle
129
+ ),
130
+ { title: "Evaluate", timeout: options?.timeout }
131
+ );
111
132
  }
112
133
  async fill(value, options = {}) {
113
134
  return await this._frame.fill(this._selector, value, { strict: true, ...options });
@@ -62,6 +62,7 @@ class Page extends import_channelOwner.ChannelOwner {
62
62
  this._closeWasCalled = false;
63
63
  this._harRouters = [];
64
64
  this._locatorHandlers = /* @__PURE__ */ new Map();
65
+ this.routeInjecting = false;
65
66
  this._browserContext = parent;
66
67
  this._timeoutSettings = new import_timeoutSettings.TimeoutSettings(this._platform, this._browserContext._timeoutSettings);
67
68
  this.keyboard = new import_input.Keyboard(this);
@@ -228,9 +229,9 @@ class Page extends import_channelOwner.ChannelOwner {
228
229
  async dispatchEvent(selector, type, eventInit, options) {
229
230
  return await this._mainFrame.dispatchEvent(selector, type, eventInit, options);
230
231
  }
231
- async evaluateHandle(pageFunction, arg) {
232
- (0, import_jsHandle.assertMaxArguments)(arguments.length, 2);
233
- return await this._mainFrame.evaluateHandle(pageFunction, arg);
232
+ async evaluateHandle(pageFunction, arg, isolatedContext = true) {
233
+ (0, import_jsHandle.assertMaxArguments)(arguments.length, 3);
234
+ return await this._mainFrame.evaluateHandle(pageFunction, arg, isolatedContext);
234
235
  }
235
236
  async $eval(selector, pageFunction, arg) {
236
237
  (0, import_jsHandle.assertMaxArguments)(arguments.length, 3);
@@ -250,11 +251,13 @@ class Page extends import_channelOwner.ChannelOwner {
250
251
  return await this._mainFrame.addStyleTag(options);
251
252
  }
252
253
  async exposeFunction(name, callback) {
254
+ await this.installInjectRoute();
253
255
  await this._channel.exposeBinding({ name });
254
256
  const binding = (source, ...args) => callback(...args);
255
257
  this._bindings.set(name, binding);
256
258
  }
257
259
  async exposeBinding(name, callback, options = {}) {
260
+ await this.installInjectRoute();
258
261
  await this._channel.exposeBinding({ name, needsHandle: options.handle });
259
262
  this._bindings.set(name, callback);
260
263
  }
@@ -391,14 +394,15 @@ class Page extends import_channelOwner.ChannelOwner {
391
394
  viewportSize() {
392
395
  return this._viewportSize || null;
393
396
  }
394
- async evaluate(pageFunction, arg) {
395
- (0, import_jsHandle.assertMaxArguments)(arguments.length, 2);
396
- return await this._mainFrame.evaluate(pageFunction, arg);
397
+ async evaluate(pageFunction, arg, isolatedContext = true) {
398
+ (0, import_jsHandle.assertMaxArguments)(arguments.length, 3);
399
+ return await this._mainFrame.evaluate(pageFunction, arg, isolatedContext);
397
400
  }
398
401
  async _evaluateFunction(functionDeclaration) {
399
402
  return this._mainFrame._evaluateFunction(functionDeclaration);
400
403
  }
401
404
  async addInitScript(script, arg) {
405
+ await this.installInjectRoute();
402
406
  const source = await (0, import_clientHelper.evaluationScript)(this._platform, script, arg);
403
407
  await this._channel.addInitScript({ source });
404
408
  }
@@ -676,6 +680,21 @@ class Page extends import_channelOwner.ChannelOwner {
676
680
  async _snapshotForAI(options = {}) {
677
681
  return await this._channel.snapshotForAI({ timeout: this._timeoutSettings.timeout(options), track: options.track });
678
682
  }
683
+ async installInjectRoute() {
684
+ if (this.routeInjecting || this.context().routeInjecting) return;
685
+ await this.route("**/*", async (route) => {
686
+ try {
687
+ if (route.request().resourceType() === "document" && route.request().url().startsWith("http")) {
688
+ const protocol = route.request().url().split(":")[0];
689
+ await route.fallback({ url: protocol + "://patchright-init-script-inject.internal/" });
690
+ } else {
691
+ await route.fallback();
692
+ }
693
+ } catch (error) {
694
+ await route.fallback();
695
+ }
696
+ });
697
+ }
679
698
  }
680
699
  class BindingCall extends import_channelOwner.ChannelOwner {
681
700
  static from(channel) {
@@ -34,6 +34,7 @@ class Tracing extends import_channelOwner.ChannelOwner {
34
34
  return channel._object;
35
35
  }
36
36
  async start(options = {}) {
37
+ await this._parent.installInjectRoute();
37
38
  await this._wrapApiCall(async () => {
38
39
  this._includeSources = !!options.sources;
39
40
  this._isLive = !!options._live;
@@ -54,14 +54,14 @@ class Worker extends import_channelOwner.ChannelOwner {
54
54
  url() {
55
55
  return this._initializer.url;
56
56
  }
57
- async evaluate(pageFunction, arg) {
58
- (0, import_jsHandle.assertMaxArguments)(arguments.length, 2);
59
- const result = await this._channel.evaluateExpression({ expression: String(pageFunction), isFunction: typeof pageFunction === "function", arg: (0, import_jsHandle.serializeArgument)(arg) });
57
+ async evaluate(pageFunction, arg, isolatedContext = true) {
58
+ (0, import_jsHandle.assertMaxArguments)(arguments.length, 3);
59
+ const result = await this._channel.evaluateExpression({ expression: String(pageFunction), isFunction: typeof pageFunction === "function", arg: (0, import_jsHandle.serializeArgument)(arg), isolatedContext });
60
60
  return (0, import_jsHandle.parseResult)(result.value);
61
61
  }
62
- async evaluateHandle(pageFunction, arg) {
63
- (0, import_jsHandle.assertMaxArguments)(arguments.length, 2);
64
- const result = await this._channel.evaluateExpressionHandle({ expression: String(pageFunction), isFunction: typeof pageFunction === "function", arg: (0, import_jsHandle.serializeArgument)(arg) });
62
+ async evaluateHandle(pageFunction, arg, isolatedContext = true) {
63
+ (0, import_jsHandle.assertMaxArguments)(arguments.length, 3);
64
+ const result = await this._channel.evaluateExpressionHandle({ expression: String(pageFunction), isFunction: typeof pageFunction === "function", arg: (0, import_jsHandle.serializeArgument)(arg), isolatedContext });
65
65
  return import_jsHandle.JSHandle.from(result.handle);
66
66
  }
67
67
  async waitForEvent(event, optionsOrPredicate = {}) {