@smoothdeploy/playwright-core 1.57.1 → 1.58.1-beta-1770452953000

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.

Potentially problematic release.


This version of @smoothdeploy/playwright-core might be problematic. Click here for more details.

Files changed (155) 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 +35 -0
  7. package/lib/client/browserType.js +4 -3
  8. package/lib/client/channelOwner.js +4 -3
  9. package/lib/client/clientInstrumentation.js +10 -0
  10. package/lib/client/connection.js +4 -0
  11. package/lib/client/elementHandle.js +3 -0
  12. package/lib/client/events.js +3 -0
  13. package/lib/client/fetch.js +3 -4
  14. package/lib/client/frame.js +1 -0
  15. package/lib/client/page.js +28 -1
  16. package/lib/client/pageAgent.js +64 -0
  17. package/lib/client/platform.js +3 -0
  18. package/lib/generated/injectedScriptSource.js +1 -1
  19. package/lib/generated/pollingRecorderSource.js +1 -1
  20. package/lib/mcpBundle.js +84 -0
  21. package/lib/mcpBundleImpl/index.js +147 -0
  22. package/lib/protocol/serializers.js +5 -0
  23. package/lib/protocol/validator.js +92 -3
  24. package/lib/remote/playwrightServer.js +1 -2
  25. package/lib/server/agent/actionRunner.js +335 -0
  26. package/lib/server/agent/actions.js +128 -0
  27. package/lib/server/agent/codegen.js +111 -0
  28. package/lib/server/agent/context.js +150 -0
  29. package/lib/server/agent/expectTools.js +156 -0
  30. package/lib/server/agent/pageAgent.js +204 -0
  31. package/lib/server/agent/performTools.js +262 -0
  32. package/lib/server/agent/tool.js +109 -0
  33. package/lib/server/artifact.js +1 -1
  34. package/lib/server/bidi/bidiBrowser.js +56 -12
  35. package/lib/server/bidi/bidiChromium.js +6 -11
  36. package/lib/server/bidi/bidiConnection.js +1 -0
  37. package/lib/server/bidi/bidiDeserializer.js +116 -0
  38. package/lib/server/bidi/bidiExecutionContext.js +75 -29
  39. package/lib/server/bidi/bidiFirefox.js +6 -8
  40. package/lib/server/bidi/bidiNetworkManager.js +1 -1
  41. package/lib/server/bidi/bidiPage.js +39 -28
  42. package/lib/server/bidi/third_party/bidiProtocolCore.js +1 -0
  43. package/lib/server/browserContext.js +32 -25
  44. package/lib/server/browserType.js +12 -4
  45. package/lib/server/chromium/chromium.js +14 -21
  46. package/lib/server/chromium/chromiumSwitches.js +2 -2
  47. package/lib/server/chromium/crBrowser.js +22 -12
  48. package/lib/server/chromium/crConnection.js +0 -5
  49. package/lib/server/chromium/crDevTools.js +0 -2
  50. package/lib/server/chromium/crNetworkManager.js +43 -2
  51. package/lib/server/chromium/crPage.js +19 -87
  52. package/lib/server/codegen/javascript.js +6 -29
  53. package/lib/server/deviceDescriptorsSource.json +56 -56
  54. package/lib/server/dispatchers/browserContextDispatcher.js +3 -0
  55. package/lib/server/dispatchers/dispatcher.js +6 -13
  56. package/lib/server/dispatchers/frameDispatcher.js +1 -1
  57. package/lib/server/dispatchers/pageAgentDispatcher.js +96 -0
  58. package/lib/server/dispatchers/pageDispatcher.js +4 -0
  59. package/lib/server/dom.js +12 -3
  60. package/lib/server/electron/electron.js +5 -2
  61. package/lib/server/firefox/ffBrowser.js +10 -20
  62. package/lib/server/firefox/ffConnection.js +0 -5
  63. package/lib/server/firefox/ffNetworkManager.js +2 -2
  64. package/lib/server/firefox/ffPage.js +15 -18
  65. package/lib/server/firefox/firefox.js +6 -8
  66. package/lib/server/frameSelectors.js +9 -3
  67. package/lib/server/frames.js +49 -33
  68. package/lib/server/instrumentation.js +3 -0
  69. package/lib/server/network.js +50 -12
  70. package/lib/server/page.js +33 -89
  71. package/lib/server/progress.js +26 -6
  72. package/lib/server/recorder/recorderApp.js +79 -100
  73. package/lib/server/recorder.js +55 -0
  74. package/lib/server/registry/browserFetcher.js +6 -4
  75. package/lib/server/registry/index.js +172 -149
  76. package/lib/server/registry/oopDownloadBrowserMain.js +3 -0
  77. package/lib/server/screencast.js +190 -0
  78. package/lib/server/screenshotCompositor.js +153 -0
  79. package/lib/server/trace/recorder/snapshotterInjected.js +21 -1
  80. package/lib/server/trace/recorder/tracing.js +21 -21
  81. package/lib/server/trace/viewer/traceParser.js +72 -0
  82. package/lib/server/trace/viewer/traceViewer.js +17 -13
  83. package/lib/server/utils/expectUtils.js +87 -2
  84. package/lib/server/utils/httpServer.js +4 -19
  85. package/lib/server/utils/network.js +37 -28
  86. package/lib/server/utils/nodePlatform.js +6 -0
  87. package/lib/server/videoRecorder.js +124 -0
  88. package/lib/server/webkit/webkit.js +4 -6
  89. package/lib/server/webkit/wkBrowser.js +2 -6
  90. package/lib/server/webkit/wkConnection.js +1 -6
  91. package/lib/server/webkit/wkInterceptableRequest.js +29 -1
  92. package/lib/server/webkit/wkPage.js +75 -46
  93. package/lib/utils/isomorphic/ariaSnapshot.js +60 -2
  94. package/lib/utils/isomorphic/lruCache.js +51 -0
  95. package/lib/utils/isomorphic/protocolMetainfo.js +9 -1
  96. package/lib/utils/isomorphic/stringUtils.js +49 -0
  97. package/lib/utils/isomorphic/trace/entries.js +16 -0
  98. package/lib/utils/isomorphic/trace/snapshotRenderer.js +499 -0
  99. package/lib/utils/isomorphic/trace/snapshotServer.js +120 -0
  100. package/lib/utils/isomorphic/trace/snapshotStorage.js +89 -0
  101. package/lib/utils/isomorphic/trace/traceLoader.js +131 -0
  102. package/lib/utils/isomorphic/trace/traceModel.js +365 -0
  103. package/lib/utils/isomorphic/trace/traceModernizer.js +400 -0
  104. package/lib/utils/isomorphic/trace/versions/traceV3.js +16 -0
  105. package/lib/utils/isomorphic/trace/versions/traceV4.js +16 -0
  106. package/lib/utils/isomorphic/trace/versions/traceV5.js +16 -0
  107. package/lib/utils/isomorphic/trace/versions/traceV6.js +16 -0
  108. package/lib/utils/isomorphic/trace/versions/traceV7.js +16 -0
  109. package/lib/utils/isomorphic/trace/versions/traceV8.js +16 -0
  110. package/lib/utils/isomorphic/yaml.js +84 -0
  111. package/lib/utils.js +2 -0
  112. package/lib/utilsBundle.js +2 -5
  113. package/lib/utilsBundleImpl/index.js +165 -165
  114. package/lib/vite/htmlReport/index.html +21 -21
  115. package/lib/vite/recorder/assets/{codeMirrorModule-C3UTv-Ge.css → codeMirrorModule-DYBRYzYX.css} +1 -1
  116. package/lib/vite/recorder/assets/codeMirrorModule-DadYNm1I.js +32 -0
  117. package/lib/vite/recorder/assets/{index-Ri0uHF7I.css → index-BSjZa4pk.css} +1 -1
  118. package/lib/vite/recorder/assets/index-BhTWtUlo.js +193 -0
  119. package/lib/vite/recorder/index.html +2 -2
  120. package/lib/vite/traceViewer/assets/codeMirrorModule-8UJPCtp4.js +16884 -0
  121. package/lib/vite/{recorder/assets/codeMirrorModule-BoWUGj0J.js → traceViewer/assets/codeMirrorModule-BNr6yhVP.js} +1 -1
  122. package/lib/vite/traceViewer/assets/codeMirrorModule-Dimjuz94.js +32 -0
  123. package/lib/vite/traceViewer/assets/codeMirrorModule-DkmsYcws.js +32 -0
  124. package/lib/vite/traceViewer/assets/codeMirrorModule-DySgctgr.js +16884 -0
  125. package/lib/vite/traceViewer/assets/defaultSettingsView-B1vuWQsF.js +266 -0
  126. package/lib/vite/traceViewer/assets/defaultSettingsView-CtEsdeVH.js +266 -0
  127. package/lib/vite/traceViewer/assets/defaultSettingsView-D4fm31R-.js +34087 -0
  128. package/lib/vite/traceViewer/assets/defaultSettingsView-JtyB0yzL.js +34087 -0
  129. package/lib/vite/traceViewer/assets/defaultSettingsView-tEZf-LNj.js +266 -0
  130. package/lib/vite/traceViewer/assets/xtermModule-DDw6eROI.js +6168 -0
  131. package/lib/vite/traceViewer/codeMirrorModule.DYBRYzYX.css +1 -0
  132. package/lib/vite/traceViewer/codeMirrorModule.DuST8d_k.css +344 -0
  133. package/lib/vite/traceViewer/defaultSettingsView.5FCqBwKs.css +3986 -0
  134. package/lib/vite/traceViewer/defaultSettingsView.7ch9cixO.css +1 -0
  135. package/lib/vite/traceViewer/index.BQs8gGhY.js +249 -0
  136. package/lib/vite/traceViewer/index.BVu7tZDe.css +1 -0
  137. package/lib/vite/traceViewer/index.BoLn624r.js +2 -0
  138. package/lib/vite/traceViewer/index.Bq_EaK8x.js +249 -0
  139. package/lib/vite/traceViewer/index.C8YVh4B5.js +2 -0
  140. package/lib/vite/traceViewer/index.Cr7-GRf8.js +2 -0
  141. package/lib/vite/traceViewer/index.G-7UhDxt.css +164 -0
  142. package/lib/vite/traceViewer/index.html +4 -4
  143. package/lib/vite/traceViewer/sw.bundle.js +5 -3
  144. package/lib/vite/traceViewer/uiMode.-Kflt2XM.css +1440 -0
  145. package/lib/vite/traceViewer/uiMode.BTRKnokb.js +5 -0
  146. package/lib/vite/traceViewer/uiMode.CEZ5RVHh.js +5 -0
  147. package/lib/vite/traceViewer/uiMode.CIWF23si.js +1829 -0
  148. package/lib/vite/traceViewer/uiMode.Wi-DvIEY.js +1829 -0
  149. package/lib/vite/traceViewer/uiMode.html +3 -3
  150. package/lib/vite/traceViewer/uiMode.zEH1ejvz.js +5 -0
  151. package/lib/vite/traceViewer/xtermModule.BKlWQB97.css +218 -0
  152. package/package.json +3 -1
  153. package/types/protocol.d.ts +738 -159
  154. package/types/types.d.ts +25 -38
  155. package/lib/vite/recorder/assets/index-DJqDAOZp.js +0 -193
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);
@@ -76,6 +76,7 @@ class BrowserContext extends import_channelOwner.ChannelOwner {
76
76
  this.tracing = import_tracing.Tracing.from(initializer.tracing);
77
77
  this.request = import_fetch.APIRequestContext.from(initializer.requestContext);
78
78
  this.request._timeoutSettings = this._timeoutSettings;
79
+ this.request._checkUrlAllowed = (url) => this._checkUrlAllowed(url);
79
80
  this.clock = new import_clock.Clock(this);
80
81
  this._channel.on("bindingCall", ({ binding }) => this._onBinding(import_page.BindingCall.from(binding)));
81
82
  this._channel.on("close", () => this._onClose());
@@ -474,6 +475,40 @@ class BrowserContext extends import_channelOwner.ChannelOwner {
474
475
  this._onRecorderEventSink = void 0;
475
476
  await this._channel.disableRecorder();
476
477
  }
478
+ async _exposeConsoleApi() {
479
+ await this._channel.exposeConsoleApi();
480
+ }
481
+ _setAllowedProtocols(protocols) {
482
+ this._allowedProtocols = protocols;
483
+ }
484
+ _checkUrlAllowed(url) {
485
+ if (!this._allowedProtocols)
486
+ return;
487
+ let parsedURL;
488
+ try {
489
+ parsedURL = new URL(url);
490
+ } catch (e) {
491
+ throw new Error(`Access to ${url} is blocked. Invalid URL: ${e.message}`);
492
+ }
493
+ if (!this._allowedProtocols.includes(parsedURL.protocol))
494
+ throw new Error(`Access to "${parsedURL.protocol}" URL is blocked. Allowed protocols: ${this._allowedProtocols.join(", ")}. Attempted URL: ${url}`);
495
+ }
496
+ _setAllowedDirectories(rootDirectories) {
497
+ this._allowedDirectories = rootDirectories;
498
+ }
499
+ _checkFileAccess(filePath) {
500
+ if (!this._allowedDirectories)
501
+ return;
502
+ const path = this._platform.path().resolve(filePath);
503
+ const isInsideDir = (container, child) => {
504
+ const path2 = this._platform.path();
505
+ const rel = path2.relative(container, child);
506
+ return !!rel && !rel.startsWith("..") && !path2.isAbsolute(rel);
507
+ };
508
+ if (this._allowedDirectories.some((root) => isInsideDir(root, path)))
509
+ return;
510
+ throw new Error(`File access denied: ${filePath} is outside allowed roots. Allowed roots: ${this._allowedDirectories.length ? this._allowedDirectories.join(", ") : "none"}`);
511
+ }
477
512
  }
478
513
  async function prepareStorageState(platform, storageState) {
479
514
  if (typeof storageState !== "string")
@@ -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);
@@ -125,7 +125,7 @@ class ChannelOwner extends import_eventEmitter.EventEmitter {
125
125
  const validatedParams = validator(params, "", this._validatorToWireContext());
126
126
  if (!apiZone.internal && !apiZone.reported) {
127
127
  apiZone.reported = true;
128
- this._instrumentation.onApiCallBegin(apiZone, { type: this._type, method: prop, params });
128
+ this._instrumentation.onApiCallBegin(apiZone, { type: this._type, method: prop, params, object: this });
129
129
  logApiCall(this._platform, this._logger, `=> ${apiZone.apiName} started`);
130
130
  return await this._connection.sendMessageToServer(this, prop, validatedParams, apiZone);
131
131
  }
@@ -151,7 +151,7 @@ class ChannelOwner extends import_eventEmitter.EventEmitter {
151
151
  const result = await this._platform.zones.current().push(apiZone).run(async () => await func(apiZone));
152
152
  if (!options?.internal) {
153
153
  logApiCall(this._platform, logger, `<= ${apiZone.apiName} succeeded`);
154
- this._instrumentation.onApiCallEnd(apiZone);
154
+ await this._instrumentation.onApiCallEnd(apiZone);
155
155
  }
156
156
  return result;
157
157
  } catch (e) {
@@ -166,7 +166,8 @@ class ChannelOwner extends import_eventEmitter.EventEmitter {
166
166
  if (!options?.internal) {
167
167
  apiZone.error = e;
168
168
  logApiCall(this._platform, logger, `<= ${apiZone.apiName} failed`);
169
- this._instrumentation.onApiCallEnd(apiZone);
169
+ await this._instrumentation.onApiCallEnd(apiZone).catch(() => {
170
+ });
170
171
  }
171
172
  throw e;
172
173
  }
@@ -39,6 +39,16 @@ function createInstrumentation() {
39
39
  await listener[prop]?.(...params);
40
40
  };
41
41
  }
42
+ if (prop === "onApiCallEnd") {
43
+ return async (...params) => {
44
+ for (const listener of listeners) {
45
+ try {
46
+ await listener[prop]?.(...params);
47
+ } catch {
48
+ }
49
+ }
50
+ };
51
+ }
42
52
  if (prop.startsWith("on")) {
43
53
  return (...params) => {
44
54
  for (const listener of listeners)
@@ -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) {
@@ -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);
@@ -62,6 +63,7 @@ class Page extends import_channelOwner.ChannelOwner {
62
63
  this._closeWasCalled = false;
63
64
  this._harRouters = [];
64
65
  this._locatorHandlers = /* @__PURE__ */ new Map();
66
+ this._instrumentation.onPage(this);
65
67
  this._browserContext = parent;
66
68
  this._timeoutSettings = new import_timeoutSettings.TimeoutSettings(this._platform, this._browserContext._timeoutSettings);
67
69
  this.keyboard = new import_input.Keyboard(this);
@@ -502,7 +504,8 @@ class Page extends import_channelOwner.ChannelOwner {
502
504
  }
503
505
  async close(options = {}) {
504
506
  this._closeReason = options.reason;
505
- this._closeWasCalled = true;
507
+ if (!options.runBeforeUnload)
508
+ this._closeWasCalled = true;
506
509
  try {
507
510
  if (this._ownedContext)
508
511
  await this._ownedContext.close();
@@ -673,6 +676,30 @@ class Page extends import_channelOwner.ChannelOwner {
673
676
  }
674
677
  return result.pdf;
675
678
  }
679
+ // @ts-expect-error agents are hidden
680
+ async agent(options = {}) {
681
+ const params = {
682
+ api: options.provider?.api,
683
+ apiEndpoint: options.provider?.apiEndpoint,
684
+ apiKey: options.provider?.apiKey,
685
+ apiTimeout: options.provider?.apiTimeout,
686
+ apiCacheFile: options.provider?._apiCacheFile,
687
+ doNotRenderActive: options._doNotRenderActive,
688
+ model: options.provider?.model,
689
+ cacheFile: options.cache?.cacheFile,
690
+ cacheOutFile: options.cache?.cacheOutFile,
691
+ maxTokens: options.limits?.maxTokens,
692
+ maxActions: options.limits?.maxActions,
693
+ maxActionRetries: options.limits?.maxActionRetries,
694
+ // @ts-expect-error runAgents is hidden
695
+ secrets: options.secrets ? Object.entries(options.secrets).map(([name, value]) => ({ name, value })) : void 0,
696
+ systemPrompt: options.systemPrompt
697
+ };
698
+ const { agent } = await this._channel.agent(params);
699
+ const pageAgent = import_pageAgent.PageAgent.from(agent);
700
+ pageAgent._expectTimeout = options?.expect?.timeout;
701
+ return pageAgent;
702
+ }
676
703
  async _snapshotForAI(options = {}) {
677
704
  return await this._channel.snapshotForAI({ timeout: this._timeoutSettings.timeout(options), track: options.track });
678
705
  }
@@ -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: