patchright-core 1.57.0 → 1.58.2

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 (148) hide show
  1. package/ThirdPartyNotices.txt +3223 -308
  2. package/browsers.json +21 -22
  3. package/lib/cli/program.js +4 -5
  4. package/lib/client/api.js +3 -0
  5. package/lib/client/browser.js +3 -5
  6. package/lib/client/browserContext.js +40 -4
  7. package/lib/client/browserType.js +4 -3
  8. package/lib/client/connection.js +4 -0
  9. package/lib/client/elementHandle.js +3 -0
  10. package/lib/client/events.js +3 -0
  11. package/lib/client/fetch.js +3 -4
  12. package/lib/client/frame.js +10 -1
  13. package/lib/client/locator.js +8 -0
  14. package/lib/client/network.js +5 -1
  15. package/lib/client/page.js +29 -1
  16. package/lib/client/pageAgent.js +64 -0
  17. package/lib/client/platform.js +3 -0
  18. package/lib/client/tracing.js +1 -1
  19. package/lib/generated/injectedScriptSource.js +1 -1
  20. package/lib/generated/pollingRecorderSource.js +1 -1
  21. package/lib/mcpBundle.js +84 -0
  22. package/lib/mcpBundleImpl/index.js +147 -0
  23. package/lib/protocol/serializers.js +5 -0
  24. package/lib/protocol/validator.js +88 -4
  25. package/lib/remote/playwrightServer.js +1 -2
  26. package/lib/server/agent/actionRunner.js +335 -0
  27. package/lib/server/agent/actions.js +128 -0
  28. package/lib/server/agent/codegen.js +111 -0
  29. package/lib/server/agent/context.js +150 -0
  30. package/lib/server/agent/expectTools.js +156 -0
  31. package/lib/server/agent/pageAgent.js +204 -0
  32. package/lib/server/agent/performTools.js +262 -0
  33. package/lib/server/agent/tool.js +109 -0
  34. package/lib/server/artifact.js +1 -1
  35. package/lib/server/bidi/bidiBrowser.js +56 -12
  36. package/lib/server/bidi/bidiChromium.js +8 -12
  37. package/lib/server/bidi/bidiConnection.js +1 -0
  38. package/lib/server/bidi/bidiDeserializer.js +116 -0
  39. package/lib/server/bidi/bidiExecutionContext.js +75 -29
  40. package/lib/server/bidi/bidiFirefox.js +6 -8
  41. package/lib/server/bidi/bidiNetworkManager.js +1 -1
  42. package/lib/server/bidi/bidiPage.js +39 -28
  43. package/lib/server/bidi/third_party/bidiProtocolCore.js +1 -0
  44. package/lib/server/browserContext.js +34 -26
  45. package/lib/server/browserType.js +12 -4
  46. package/lib/server/chromium/chromium.js +14 -20
  47. package/lib/server/chromium/chromiumSwitches.js +2 -2
  48. package/lib/server/chromium/crBrowser.js +22 -12
  49. package/lib/server/chromium/crConnection.js +0 -5
  50. package/lib/server/chromium/crCoverage.js +13 -1
  51. package/lib/server/chromium/crDevTools.js +0 -2
  52. package/lib/server/chromium/crNetworkManager.js +92 -12
  53. package/lib/server/chromium/crPage.js +62 -116
  54. package/lib/server/codegen/javascript.js +6 -29
  55. package/lib/server/deviceDescriptorsSource.json +56 -56
  56. package/lib/server/dispatchers/browserContextDispatcher.js +3 -2
  57. package/lib/server/dispatchers/dispatcher.js +6 -13
  58. package/lib/server/dispatchers/frameDispatcher.js +1 -1
  59. package/lib/server/dispatchers/jsHandleDispatcher.js +2 -2
  60. package/lib/server/dispatchers/pageAgentDispatcher.js +96 -0
  61. package/lib/server/dispatchers/pageDispatcher.js +4 -0
  62. package/lib/server/dom.js +12 -3
  63. package/lib/server/electron/electron.js +5 -2
  64. package/lib/server/firefox/ffBrowser.js +10 -20
  65. package/lib/server/firefox/ffConnection.js +0 -5
  66. package/lib/server/firefox/ffNetworkManager.js +2 -2
  67. package/lib/server/firefox/ffPage.js +15 -18
  68. package/lib/server/firefox/firefox.js +6 -8
  69. package/lib/server/frameSelectors.js +16 -4
  70. package/lib/server/frames.js +251 -86
  71. package/lib/server/instrumentation.js +3 -0
  72. package/lib/server/javascript.js +8 -4
  73. package/lib/server/launchApp.js +2 -1
  74. package/lib/server/network.js +50 -12
  75. package/lib/server/page.js +61 -91
  76. package/lib/server/progress.js +26 -6
  77. package/lib/server/recorder/recorderApp.js +79 -100
  78. package/lib/server/registry/browserFetcher.js +6 -4
  79. package/lib/server/registry/index.js +172 -149
  80. package/lib/server/registry/oopDownloadBrowserMain.js +3 -0
  81. package/lib/server/screencast.js +190 -0
  82. package/lib/server/screenshotter.js +6 -0
  83. package/lib/server/trace/recorder/snapshotter.js +17 -8
  84. package/lib/server/trace/recorder/snapshotterInjected.js +30 -72
  85. package/lib/server/trace/recorder/tracing.js +29 -21
  86. package/lib/server/trace/viewer/traceParser.js +72 -0
  87. package/lib/server/trace/viewer/traceViewer.js +21 -17
  88. package/lib/server/utils/expectUtils.js +87 -2
  89. package/lib/server/utils/hostPlatform.js +15 -0
  90. package/lib/server/utils/httpServer.js +5 -20
  91. package/lib/server/utils/network.js +37 -28
  92. package/lib/server/utils/nodePlatform.js +6 -0
  93. package/lib/server/{chromium/videoRecorder.js → videoRecorder.js} +22 -13
  94. package/lib/server/webkit/webkit.js +4 -6
  95. package/lib/server/webkit/wkBrowser.js +2 -6
  96. package/lib/server/webkit/wkConnection.js +1 -6
  97. package/lib/server/webkit/wkInterceptableRequest.js +29 -1
  98. package/lib/server/webkit/wkPage.js +75 -46
  99. package/lib/utils/isomorphic/ariaSnapshot.js +60 -2
  100. package/lib/utils/isomorphic/lruCache.js +51 -0
  101. package/lib/utils/isomorphic/protocolMetainfo.js +9 -1
  102. package/lib/utils/isomorphic/stringUtils.js +49 -0
  103. package/lib/utils/isomorphic/trace/entries.js +16 -0
  104. package/lib/utils/isomorphic/trace/snapshotRenderer.js +499 -0
  105. package/lib/utils/isomorphic/trace/snapshotServer.js +120 -0
  106. package/lib/utils/isomorphic/trace/snapshotStorage.js +89 -0
  107. package/lib/utils/isomorphic/trace/traceLoader.js +131 -0
  108. package/lib/utils/isomorphic/trace/traceModel.js +365 -0
  109. package/lib/utils/isomorphic/trace/traceModernizer.js +400 -0
  110. package/lib/utils/isomorphic/trace/versions/traceV3.js +16 -0
  111. package/lib/utils/isomorphic/trace/versions/traceV4.js +16 -0
  112. package/lib/utils/isomorphic/trace/versions/traceV5.js +16 -0
  113. package/lib/utils/isomorphic/trace/versions/traceV6.js +16 -0
  114. package/lib/utils/isomorphic/trace/versions/traceV7.js +16 -0
  115. package/lib/utils/isomorphic/trace/versions/traceV8.js +16 -0
  116. package/lib/utils/isomorphic/yaml.js +84 -0
  117. package/lib/utils.js +2 -0
  118. package/lib/utilsBundle.js +2 -5
  119. package/lib/utilsBundleImpl/index.js +165 -165
  120. package/lib/vite/htmlReport/index.html +21 -21
  121. package/lib/vite/recorder/assets/codeMirrorModule-CFUTFUO7.js +32 -0
  122. package/lib/vite/{traceViewer/codeMirrorModule.C3UTv-Ge.css → recorder/assets/codeMirrorModule-DYBRYzYX.css} +1 -1
  123. package/lib/vite/recorder/assets/{index-Ri0uHF7I.css → index-BSjZa4pk.css} +1 -1
  124. package/lib/vite/recorder/assets/index-CVkBxsGf.js +193 -0
  125. package/lib/vite/recorder/index.html +2 -2
  126. package/lib/vite/traceViewer/assets/codeMirrorModule-BVA4h_ZY.js +32 -0
  127. package/lib/vite/traceViewer/assets/defaultSettingsView-CjfmcdOz.js +266 -0
  128. package/lib/vite/{recorder/assets/codeMirrorModule-C3UTv-Ge.css → traceViewer/codeMirrorModule.DYBRYzYX.css} +1 -1
  129. package/lib/vite/traceViewer/defaultSettingsView.7ch9cixO.css +1 -0
  130. package/lib/vite/traceViewer/index.BVu7tZDe.css +1 -0
  131. package/lib/vite/traceViewer/index.BtyWtaE-.js +2 -0
  132. package/lib/vite/traceViewer/index.html +4 -4
  133. package/lib/vite/traceViewer/sw.bundle.js +5 -3
  134. package/lib/vite/traceViewer/uiMode.fyrXARf2.js +5 -0
  135. package/lib/vite/traceViewer/uiMode.html +3 -3
  136. package/package.json +2 -1
  137. package/types/protocol.d.ts +738 -159
  138. package/types/types.d.ts +25 -38
  139. package/lib/server/bidi/third_party/bidiDeserializer.js +0 -98
  140. package/lib/server/trace/test/inMemorySnapshotter.js +0 -87
  141. package/lib/vite/recorder/assets/codeMirrorModule-CBbSe-ZI.js +0 -25
  142. package/lib/vite/recorder/assets/index-CpZVd2nA.js +0 -193
  143. package/lib/vite/traceViewer/assets/codeMirrorModule-DHz0wP2C.js +0 -25
  144. package/lib/vite/traceViewer/assets/defaultSettingsView-WsZP88O6.js +0 -266
  145. package/lib/vite/traceViewer/defaultSettingsView.ConWv5KN.css +0 -1
  146. package/lib/vite/traceViewer/index.C4Y3Aw8n.css +0 -1
  147. package/lib/vite/traceViewer/index.C8xAeo93.js +0 -2
  148. package/lib/vite/traceViewer/uiMode.BltraIJB.js +0 -5
package/browsers.json CHANGED
@@ -3,59 +3,58 @@
3
3
  "browsers": [
4
4
  {
5
5
  "name": "chromium",
6
- "revision": "1200",
6
+ "revision": "1208",
7
7
  "installByDefault": true,
8
- "browserVersion": "143.0.7499.4"
8
+ "browserVersion": "145.0.7632.6",
9
+ "title": "Chrome for Testing"
9
10
  },
10
11
  {
11
12
  "name": "chromium-headless-shell",
12
- "revision": "1200",
13
+ "revision": "1208",
13
14
  "installByDefault": true,
14
- "browserVersion": "143.0.7499.4"
15
+ "browserVersion": "145.0.7632.6",
16
+ "title": "Chrome Headless Shell"
15
17
  },
16
18
  {
17
19
  "name": "chromium-tip-of-tree",
18
- "revision": "1380",
20
+ "revision": "1401",
19
21
  "installByDefault": false,
20
- "browserVersion": "143.0.7488.0"
22
+ "browserVersion": "146.0.7644.0",
23
+ "title": "Chrome Canary for Testing"
21
24
  },
22
25
  {
23
26
  "name": "chromium-tip-of-tree-headless-shell",
24
- "revision": "1380",
27
+ "revision": "1401",
25
28
  "installByDefault": false,
26
- "browserVersion": "143.0.7488.0"
29
+ "browserVersion": "146.0.7644.0",
30
+ "title": "Chrome Canary Headless Shell"
27
31
  },
28
32
  {
29
33
  "name": "firefox",
30
- "revision": "1497",
34
+ "revision": "1509",
31
35
  "installByDefault": true,
32
- "browserVersion": "144.0.2"
36
+ "browserVersion": "146.0.1",
37
+ "title": "Firefox"
33
38
  },
34
39
  {
35
40
  "name": "firefox-beta",
36
- "revision": "1493",
41
+ "revision": "1504",
37
42
  "installByDefault": false,
38
- "browserVersion": "145.0b10"
43
+ "browserVersion": "146.0b8",
44
+ "title": "Firefox Beta"
39
45
  },
40
46
  {
41
47
  "name": "webkit",
42
- "revision": "2227",
48
+ "revision": "2248",
43
49
  "installByDefault": true,
44
50
  "revisionOverrides": {
45
51
  "debian11-x64": "2105",
46
52
  "debian11-arm64": "2105",
47
- "mac10.14": "1446",
48
- "mac10.15": "1616",
49
- "mac11": "1816",
50
- "mac11-arm64": "1816",
51
- "mac12": "2009",
52
- "mac12-arm64": "2009",
53
- "mac13": "2140",
54
- "mac13-arm64": "2140",
55
53
  "ubuntu20.04-x64": "2092",
56
54
  "ubuntu20.04-arm64": "2092"
57
55
  },
58
- "browserVersion": "26.0"
56
+ "browserVersion": "26.0",
57
+ "title": "WebKit"
59
58
  },
60
59
  {
61
60
  "name": "ffmpeg",
@@ -124,7 +124,7 @@ Playwright version: ${version}`);
124
124
  printInstalledBrowsers(groupedByPlaywrightMinorVersion.get(version));
125
125
  }
126
126
  }
127
- import_utilsBundle.program.command("install [browser...]").description("ensure browsers necessary for this version of Playwright are installed").option("--with-deps", "install system dependencies for browsers").option("--dry-run", "do not execute installation, only print information").option("--list", "prints list of browsers from all playwright installations").option("--force", "force reinstall of stable browser channels").option("--only-shell", "only install headless shell when installing chromium").option("--no-shell", "do not install chromium headless shell").action(async function(args, options) {
127
+ import_utilsBundle.program.command("install [browser...]").description("ensure browsers necessary for this version of Playwright are installed").option("--with-deps", "install system dependencies for browsers").option("--dry-run", "do not execute installation, only print information").option("--list", "prints list of browsers from all playwright installations").option("--force", "force reinstall of already installed browsers").option("--only-shell", "only install headless shell when installing chromium").option("--no-shell", "do not install chromium headless shell").action(async function(args, options) {
128
128
  if ((0, import_utils.isLikelyNpxGlobal)()) {
129
129
  console.error((0, import_ascii.wrapInASCIIBox)([
130
130
  `WARNING: It looks like you are running 'npx playwright install' without first`,
@@ -156,8 +156,7 @@ import_utilsBundle.program.command("install [browser...]").description("ensure b
156
156
  throw new Error(`Only one of --dry-run and --list can be specified`);
157
157
  if (options.dryRun) {
158
158
  for (const executable of executables) {
159
- const version = executable.browserVersion ? `version ` + executable.browserVersion : "";
160
- console.log(`browser: ${executable.name}${version ? " " + version : ""}`);
159
+ console.log(import_server.registry.calculateDownloadTitle(executable));
161
160
  console.log(` Install location: ${executable.directory ?? "<system>"}`);
162
161
  if (executable.downloadURLs?.length) {
163
162
  const [url, ...fallbacks] = executable.downloadURLs;
@@ -171,8 +170,7 @@ import_utilsBundle.program.command("install [browser...]").description("ensure b
171
170
  const browsers2 = await import_server.registry.listInstalledBrowsers();
172
171
  printGroupedByPlaywrightVersion(browsers2);
173
172
  } else {
174
- const force = args.length === 0 ? false : !!options.force;
175
- await import_server.registry.install(executables, { force });
173
+ await import_server.registry.install(executables, { force: options.force });
176
174
  await import_server.registry.validateHostRequirementsForExecutablesIfNeeded(executables, process.env.PW_LANG_NAME || "javascript").catch((e) => {
177
175
  e.name = "Playwright Host validation warning";
178
176
  console.error(e);
@@ -423,6 +421,7 @@ async function openPage(context, url) {
423
421
  }
424
422
  async function open(options, url) {
425
423
  const { context } = await launchContext(options, { headless: !!process.env.PWTEST_CLI_HEADLESS, executablePath: process.env.PWTEST_CLI_EXECUTABLE_PATH });
424
+ await context._exposeConsoleApi();
426
425
  await openPage(context, url);
427
426
  }
428
427
  async function codegen(options, url) {
package/lib/client/api.js CHANGED
@@ -46,6 +46,7 @@ __export(api_exports, {
46
46
  Locator: () => import_locator.Locator,
47
47
  Mouse: () => import_input.Mouse,
48
48
  Page: () => import_page.Page,
49
+ PageAgent: () => import_pageAgent.PageAgent,
49
50
  Playwright: () => import_playwright.Playwright,
50
51
  Request: () => import_network.Request,
51
52
  Response: () => import_network.Response,
@@ -81,6 +82,7 @@ var import_jsHandle = require("./jsHandle");
81
82
  var import_network = require("./network");
82
83
  var import_fetch = require("./fetch");
83
84
  var import_page = require("./page");
85
+ var import_pageAgent = require("./pageAgent");
84
86
  var import_selectors = require("./selectors");
85
87
  var import_tracing = require("./tracing");
86
88
  var import_video = require("./video");
@@ -118,6 +120,7 @@ var import_webError = require("./webError");
118
120
  Locator,
119
121
  Mouse,
120
122
  Page,
123
+ PageAgent,
121
124
  Playwright,
122
125
  Request,
123
126
  Response,
@@ -62,11 +62,9 @@ class Browser extends import_channelOwner.ChannelOwner {
62
62
  context._onClose();
63
63
  await this._channel.disconnectFromReusedContext({ reason });
64
64
  }
65
- async _innerNewContext(options = {}, forReuse) {
66
- options = this._browserType._playwright.selectors._withSelectorOptions({
67
- ...this._browserType._playwright._defaultContextOptions,
68
- ...options
69
- });
65
+ async _innerNewContext(userOptions = {}, forReuse) {
66
+ const options = this._browserType._playwright.selectors._withSelectorOptions(userOptions);
67
+ await this._instrumentation.runBeforeCreateBrowserContext(options);
70
68
  const contextOptions = await (0, import_browserContext.prepareBrowserContextParams)(this._platform, options);
71
69
  const response = forReuse ? await this._channel.newContextForReuse(contextOptions) : await this._channel.newContext(contextOptions);
72
70
  const context = import_browserContext.BrowserContext.from(response.context);
@@ -77,6 +77,7 @@ class BrowserContext extends import_channelOwner.ChannelOwner {
77
77
  this.tracing = import_tracing.Tracing.from(initializer.tracing);
78
78
  this.request = import_fetch.APIRequestContext.from(initializer.requestContext);
79
79
  this.request._timeoutSettings = this._timeoutSettings;
80
+ this.request._checkUrlAllowed = (url) => this._checkUrlAllowed(url);
80
81
  this.clock = new import_clock.Clock(this);
81
82
  this._channel.on("bindingCall", ({ binding }) => this._onBinding(import_page.BindingCall.from(binding)));
82
83
  this._channel.on("close", () => this._onClose());
@@ -119,11 +120,11 @@ class BrowserContext extends import_channelOwner.ChannelOwner {
119
120
  hasListeners = page.emit(import_events.Events.Page.Dialog, dialogObject) || hasListeners;
120
121
  if (!hasListeners) {
121
122
  if (dialogObject.type() === "beforeunload")
122
- dialog.accept({}).catch(() => {
123
- });
123
+ dialogObject._wrapApiCall(() => dialog.accept({}).catch(() => {
124
+ }), { internal: true });
124
125
  else
125
- dialog.dismiss().catch(() => {
126
- });
126
+ dialogObject._wrapApiCall(() => dialog.dismiss().catch(() => {
127
+ }), { internal: true });
127
128
  }
128
129
  });
129
130
  this._channel.on("request", ({ request, page }) => this._onRequest(network.Request.from(request), import_page.Page.fromNullable(page)));
@@ -478,6 +479,40 @@ class BrowserContext extends import_channelOwner.ChannelOwner {
478
479
  this._onRecorderEventSink = void 0;
479
480
  await this._channel.disableRecorder();
480
481
  }
482
+ async _exposeConsoleApi() {
483
+ await this._channel.exposeConsoleApi();
484
+ }
485
+ _setAllowedProtocols(protocols) {
486
+ this._allowedProtocols = protocols;
487
+ }
488
+ _checkUrlAllowed(url) {
489
+ if (!this._allowedProtocols)
490
+ return;
491
+ let parsedURL;
492
+ try {
493
+ parsedURL = new URL(url);
494
+ } catch (e) {
495
+ throw new Error(`Access to ${url} is blocked. Invalid URL: ${e.message}`);
496
+ }
497
+ if (!this._allowedProtocols.includes(parsedURL.protocol))
498
+ throw new Error(`Access to "${parsedURL.protocol}" URL is blocked. Allowed protocols: ${this._allowedProtocols.join(", ")}. Attempted URL: ${url}`);
499
+ }
500
+ _setAllowedDirectories(rootDirectories) {
501
+ this._allowedDirectories = rootDirectories;
502
+ }
503
+ _checkFileAccess(filePath) {
504
+ if (!this._allowedDirectories)
505
+ return;
506
+ const path = this._platform.path().resolve(filePath);
507
+ const isInsideDir = (container, child) => {
508
+ const path2 = this._platform.path();
509
+ const rel = path2.relative(container, child);
510
+ return !!rel && !rel.startsWith("..") && !path2.isAbsolute(rel);
511
+ };
512
+ if (this._allowedDirectories.some((root) => isInsideDir(root, path)))
513
+ return;
514
+ throw new Error(`File access denied: ${filePath} is outside allowed roots. Allowed roots: ${this._allowedDirectories.length ? this._allowedDirectories.join(", ") : "none"}`);
515
+ }
481
516
  async installInjectRoute() {
482
517
  if (this.routeInjecting) return;
483
518
  await this.route("**/*", async (route) => {
@@ -492,6 +527,7 @@ class BrowserContext extends import_channelOwner.ChannelOwner {
492
527
  await route.fallback();
493
528
  }
494
529
  });
530
+ this.routeInjecting = true;
495
531
  }
496
532
  }
497
533
  async function prepareStorageState(platform, storageState) {
@@ -73,13 +73,13 @@ class BrowserType extends import_channelOwner.ChannelOwner {
73
73
  return await this._serverLauncher.launchServer(options);
74
74
  }
75
75
  async launchPersistentContext(userDataDir, options = {}) {
76
- const logger = options.logger || this._playwright._defaultLaunchOptions?.logger;
77
76
  (0, import_assert.assert)(!options.port, "Cannot specify a port without launching as a server.");
78
77
  options = this._playwright.selectors._withSelectorOptions({
79
78
  ...this._playwright._defaultLaunchOptions,
80
- ...this._playwright._defaultContextOptions,
81
79
  ...options
82
80
  });
81
+ await this._instrumentation.runBeforeCreateBrowserContext(options);
82
+ const logger = options.logger || this._playwright._defaultLaunchOptions?.logger;
83
83
  const contextParams = await (0, import_browserContext.prepareBrowserContextParams)(this._platform, options);
84
84
  const persistentParams = {
85
85
  ...contextParams,
@@ -169,7 +169,8 @@ class BrowserType extends import_channelOwner.ChannelOwner {
169
169
  endpointURL,
170
170
  headers,
171
171
  slowMo: params.slowMo,
172
- timeout: new import_timeoutSettings.TimeoutSettings(this._platform).timeout(params)
172
+ timeout: new import_timeoutSettings.TimeoutSettings(this._platform).timeout(params),
173
+ isLocal: params.isLocal
173
174
  });
174
175
  const browser = import_browser.Browser.from(result.browser);
175
176
  browser._connectToBrowserType(this, {}, params.logger);
@@ -48,6 +48,7 @@ var import_worker = require("./worker");
48
48
  var import_writableStream = require("./writableStream");
49
49
  var import_validator = require("../protocol/validator");
50
50
  var import_stackTrace = require("../utils/isomorphic/stackTrace");
51
+ var import_pageAgent = require("./pageAgent");
51
52
  class Root extends import_channelOwner.ChannelOwner {
52
53
  constructor(connection) {
53
54
  super(connection, "Root", "", {});
@@ -261,6 +262,9 @@ class Connection extends import_eventEmitter.EventEmitter {
261
262
  case "Page":
262
263
  result = new import_page.Page(parent, type, guid, initializer);
263
264
  break;
265
+ case "PageAgent":
266
+ result = new import_pageAgent.PageAgent(parent, type, guid, initializer);
267
+ break;
264
268
  case "Playwright":
265
269
  result = new import_playwright.Playwright(parent, type, guid, initializer);
266
270
  break;
@@ -230,6 +230,9 @@ async function convertInputFiles(platform, files, context) {
230
230
  if (!items.every((item) => typeof item === "string"))
231
231
  throw new Error("File paths cannot be mixed with buffers");
232
232
  const [localPaths, localDirectory] = await resolvePathsAndDirectoryForInputFiles(platform, items);
233
+ localPaths?.forEach((path) => context._checkFileAccess(path));
234
+ if (localDirectory)
235
+ context._checkFileAccess(localDirectory);
233
236
  if (context._connection.isRemote()) {
234
237
  const files2 = localDirectory ? (await platform.fs().promises.readdir(localDirectory, { withFileTypes: true, recursive: true })).filter((f) => f.isFile()).map((f) => platform.path().join(f.path, f.name)) : localPaths;
235
238
  const { writableStreams, rootDir } = await context._wrapApiCall(async () => context._channel.createTempFiles({
@@ -78,6 +78,9 @@ const Events = {
78
78
  WebSocket: "websocket",
79
79
  Worker: "worker"
80
80
  },
81
+ PageAgent: {
82
+ Turn: "turn"
83
+ },
81
84
  WebSocket: {
82
85
  Close: "close",
83
86
  Error: "socketerror",
@@ -39,10 +39,8 @@ class APIRequest {
39
39
  this._playwright = playwright;
40
40
  }
41
41
  async newContext(options = {}) {
42
- options = {
43
- ...this._playwright._defaultContextOptions,
44
- ...options
45
- };
42
+ options = { ...options };
43
+ await this._playwright._instrumentation.runBeforeCreateRequestContext(options);
46
44
  const storageState = typeof options.storageState === "string" ? JSON.parse(await this._playwright._platform.fs().promises.readFile(options.storageState, "utf8")) : options.storageState;
47
45
  const context = APIRequestContext.from((await this._playwright._channel.newRequest({
48
46
  ...options,
@@ -135,6 +133,7 @@ class APIRequestContext extends import_channelOwner.ChannelOwner {
135
133
  (0, import_assert.assert)(options.maxRedirects === void 0 || options.maxRedirects >= 0, `'maxRedirects' must be greater than or equal to '0'`);
136
134
  (0, import_assert.assert)(options.maxRetries === void 0 || options.maxRetries >= 0, `'maxRetries' must be greater than or equal to '0'`);
137
135
  const url = options.url !== void 0 ? options.url : options.request.url();
136
+ this._checkUrlAllowed?.(url);
138
137
  const method = options.method || options.request?.method();
139
138
  let encodedParams = void 0;
140
139
  if (typeof options.params === "string")
@@ -101,6 +101,7 @@ class Frame extends import_channelOwner.ChannelOwner {
101
101
  }
102
102
  async goto(url, options = {}) {
103
103
  const waitUntil = verifyLoadState("waitUntil", options.waitUntil === void 0 ? "load" : options.waitUntil);
104
+ this.page().context()._checkUrlAllowed(url);
104
105
  return network.Response.fromNullable((await this._channel.goto({ url, ...options, waitUntil, timeout: this._navigationTimeout(options) })).response);
105
106
  }
106
107
  _setupNavigationWaiter(options) {
@@ -161,7 +162,15 @@ class Frame extends import_channelOwner.ChannelOwner {
161
162
  async waitForURL(url, options = {}) {
162
163
  if ((0, import_urlMatch.urlMatches)(this._page?.context()._options.baseURL, this.url(), url))
163
164
  return await this.waitForLoadState(options.waitUntil, options);
164
- await this.waitForNavigation({ url, ...options });
165
+ try {
166
+ await this.waitForNavigation({ url, ...options });
167
+ } catch (error) {
168
+ if ((0, import_urlMatch.urlMatches)(this._page?.context()._options.baseURL, this.url(), url)) {
169
+ await this.waitForLoadState(options.waitUntil, options);
170
+ return;
171
+ }
172
+ throw error;
173
+ }
165
174
  }
166
175
  async frameElement() {
167
176
  return import_elementHandle.ElementHandle.from((await this._channel.frameElement()).element);
@@ -99,6 +99,10 @@ class Locator {
99
99
  });
100
100
  }
101
101
  async evaluate(pageFunction, arg, options, isolatedContext = true) {
102
+ if (typeof options === "boolean") {
103
+ isolatedContext = options;
104
+ options = void 0;
105
+ }
102
106
  return await this._withElement(
103
107
  async (h) => (0, import_jsHandle.parseResult)(
104
108
  (await h._channel.evaluateExpression({
@@ -118,6 +122,10 @@ class Locator {
118
122
  return await this._frame.$$eval(this._selector, pageFunction, arg, isolatedContext);
119
123
  }
120
124
  async evaluateHandle(pageFunction, arg, options, isolatedContext = true) {
125
+ if (typeof options === "boolean") {
126
+ isolatedContext = options;
127
+ options = void 0;
128
+ }
121
129
  return await this._withElement(
122
130
  async (h) => import_jsHandle.JSHandle.from(
123
131
  (await h._channel.evaluateExpressionHandle({
@@ -128,7 +128,11 @@ class Request extends import_channelOwner.ChannelOwner {
128
128
  return await this._actualHeadersPromise;
129
129
  }
130
130
  async allHeaders() {
131
- return (await this._actualHeaders()).headers();
131
+ const headers = await this._actualHeaders();
132
+ const page = this._safePage();
133
+ if (page?._closeWasCalled)
134
+ throw new import_errors.TargetClosedError();
135
+ return headers.headers();
132
136
  }
133
137
  async headersArray() {
134
138
  return (await this._actualHeaders()).headersArray();
@@ -48,6 +48,7 @@ var import_urlMatch = require("../utils/isomorphic/urlMatch");
48
48
  var import_manualPromise = require("../utils/isomorphic/manualPromise");
49
49
  var import_rtti = require("../utils/isomorphic/rtti");
50
50
  var import_consoleMessage = require("./consoleMessage");
51
+ var import_pageAgent = require("./pageAgent");
51
52
  class Page extends import_channelOwner.ChannelOwner {
52
53
  constructor(parent, type, guid, initializer) {
53
54
  super(parent, type, guid, initializer);
@@ -63,6 +64,7 @@ class Page extends import_channelOwner.ChannelOwner {
63
64
  this._harRouters = [];
64
65
  this._locatorHandlers = /* @__PURE__ */ new Map();
65
66
  this.routeInjecting = false;
67
+ this._instrumentation.onPage(this);
66
68
  this._browserContext = parent;
67
69
  this._timeoutSettings = new import_timeoutSettings.TimeoutSettings(this._platform, this._browserContext._timeoutSettings);
68
70
  this.keyboard = new import_input.Keyboard(this);
@@ -506,7 +508,8 @@ class Page extends import_channelOwner.ChannelOwner {
506
508
  }
507
509
  async close(options = {}) {
508
510
  this._closeReason = options.reason;
509
- this._closeWasCalled = true;
511
+ if (!options.runBeforeUnload)
512
+ this._closeWasCalled = true;
510
513
  try {
511
514
  if (this._ownedContext)
512
515
  await this._ownedContext.close();
@@ -677,6 +680,30 @@ class Page extends import_channelOwner.ChannelOwner {
677
680
  }
678
681
  return result.pdf;
679
682
  }
683
+ // @ts-expect-error agents are hidden
684
+ async agent(options = {}) {
685
+ const params = {
686
+ api: options.provider?.api,
687
+ apiEndpoint: options.provider?.apiEndpoint,
688
+ apiKey: options.provider?.apiKey,
689
+ apiTimeout: options.provider?.apiTimeout,
690
+ apiCacheFile: options.provider?._apiCacheFile,
691
+ doNotRenderActive: options._doNotRenderActive,
692
+ model: options.provider?.model,
693
+ cacheFile: options.cache?.cacheFile,
694
+ cacheOutFile: options.cache?.cacheOutFile,
695
+ maxTokens: options.limits?.maxTokens,
696
+ maxActions: options.limits?.maxActions,
697
+ maxActionRetries: options.limits?.maxActionRetries,
698
+ // @ts-expect-error runAgents is hidden
699
+ secrets: options.secrets ? Object.entries(options.secrets).map(([name, value]) => ({ name, value })) : void 0,
700
+ systemPrompt: options.systemPrompt
701
+ };
702
+ const { agent } = await this._channel.agent(params);
703
+ const pageAgent = import_pageAgent.PageAgent.from(agent);
704
+ pageAgent._expectTimeout = options?.expect?.timeout;
705
+ return pageAgent;
706
+ }
680
707
  async _snapshotForAI(options = {}) {
681
708
  return await this._channel.snapshotForAI({ timeout: this._timeoutSettings.timeout(options), track: options.track });
682
709
  }
@@ -694,6 +721,7 @@ class Page extends import_channelOwner.ChannelOwner {
694
721
  await route.fallback();
695
722
  }
696
723
  });
724
+ this.routeInjecting = true;
697
725
  }
698
726
  }
699
727
  class BindingCall extends import_channelOwner.ChannelOwner {
@@ -0,0 +1,64 @@
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 pageAgent_exports = {};
20
+ __export(pageAgent_exports, {
21
+ PageAgent: () => PageAgent
22
+ });
23
+ module.exports = __toCommonJS(pageAgent_exports);
24
+ var import_channelOwner = require("./channelOwner");
25
+ var import_events = require("./events");
26
+ var import_page = require("./page");
27
+ class PageAgent extends import_channelOwner.ChannelOwner {
28
+ static from(channel) {
29
+ return channel._object;
30
+ }
31
+ constructor(parent, type, guid, initializer) {
32
+ super(parent, type, guid, initializer);
33
+ this._page = import_page.Page.from(initializer.page);
34
+ this._channel.on("turn", (params) => this.emit(import_events.Events.PageAgent.Turn, params));
35
+ }
36
+ async expect(expectation, options = {}) {
37
+ const timeout = options.timeout ?? this._expectTimeout ?? 5e3;
38
+ await this._channel.expect({ expectation, ...options, timeout });
39
+ }
40
+ async perform(task, options = {}) {
41
+ const timeout = this._page._timeoutSettings.timeout(options);
42
+ const { usage } = await this._channel.perform({ task, ...options, timeout });
43
+ return { usage };
44
+ }
45
+ async extract(query, schema, options = {}) {
46
+ const timeout = this._page._timeoutSettings.timeout(options);
47
+ const { result, usage } = await this._channel.extract({ query, schema: this._page._platform.zodToJsonSchema(schema), ...options, timeout });
48
+ return { result, usage };
49
+ }
50
+ async usage() {
51
+ const { usage } = await this._channel.usage({});
52
+ return usage;
53
+ }
54
+ async dispose() {
55
+ await this._channel.dispose();
56
+ }
57
+ async [Symbol.asyncDispose]() {
58
+ await this.dispose();
59
+ }
60
+ }
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ PageAgent
64
+ });
@@ -66,6 +66,9 @@ const emptyPlatform = {
66
66
  streamWritable: (channel) => {
67
67
  throw new Error("Streams are not available");
68
68
  },
69
+ zodToJsonSchema: (schema) => {
70
+ throw new Error("Zod is not available");
71
+ },
69
72
  zones: { empty: noopZone, current: () => noopZone }
70
73
  };
71
74
  // Annotate the CommonJS export names for ESM import in node:
@@ -34,7 +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
+ if (typeof this._parent.installInjectRoute === "function") await this._parent.installInjectRoute();
38
38
  await this._wrapApiCall(async () => {
39
39
  this._includeSources = !!options.sources;
40
40
  this._isLive = !!options._live;