patchright-core 1.56.1 → 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 (180) hide show
  1. package/ThirdPartyNotices.txt +3134 -560
  2. package/bin/install_webkit_wsl.ps1 +1 -3
  3. package/browsers.json +21 -22
  4. package/lib/cli/program.js +16 -60
  5. package/lib/client/api.js +3 -3
  6. package/lib/client/browser.js +3 -5
  7. package/lib/client/browserContext.js +62 -8
  8. package/lib/client/browserType.js +4 -3
  9. package/lib/client/connection.js +4 -0
  10. package/lib/client/consoleMessage.js +5 -1
  11. package/lib/client/electron.js +1 -1
  12. package/lib/client/elementHandle.js +3 -0
  13. package/lib/client/events.js +5 -1
  14. package/lib/client/fetch.js +3 -4
  15. package/lib/client/frame.js +10 -1
  16. package/lib/client/locator.js +12 -1
  17. package/lib/client/network.js +5 -1
  18. package/lib/client/page.js +31 -6
  19. package/lib/client/pageAgent.js +64 -0
  20. package/lib/client/platform.js +3 -0
  21. package/lib/client/playwright.js +1 -5
  22. package/lib/client/tracing.js +7 -5
  23. package/lib/client/worker.js +22 -0
  24. package/lib/generated/clockSource.js +1 -1
  25. package/lib/generated/injectedScriptSource.js +1 -1
  26. package/lib/generated/pollingRecorderSource.js +1 -1
  27. package/lib/inProcessFactory.js +0 -2
  28. package/lib/mcpBundle.js +84 -0
  29. package/lib/mcpBundleImpl/index.js +147 -0
  30. package/lib/protocol/serializers.js +5 -0
  31. package/lib/protocol/validator.js +112 -50
  32. package/lib/remote/playwrightServer.js +1 -2
  33. package/lib/server/agent/actionRunner.js +335 -0
  34. package/lib/server/agent/actions.js +128 -0
  35. package/lib/server/agent/codegen.js +111 -0
  36. package/lib/server/agent/context.js +150 -0
  37. package/lib/server/agent/expectTools.js +156 -0
  38. package/lib/server/agent/pageAgent.js +204 -0
  39. package/lib/server/agent/performTools.js +262 -0
  40. package/lib/server/agent/tool.js +109 -0
  41. package/lib/server/android/android.js +1 -1
  42. package/lib/server/artifact.js +1 -1
  43. package/lib/server/bidi/bidiBrowser.js +81 -22
  44. package/lib/server/bidi/bidiChromium.js +9 -13
  45. package/lib/server/bidi/bidiConnection.js +1 -0
  46. package/lib/server/bidi/bidiDeserializer.js +116 -0
  47. package/lib/server/bidi/bidiExecutionContext.js +75 -29
  48. package/lib/server/bidi/bidiFirefox.js +7 -9
  49. package/lib/server/bidi/bidiNetworkManager.js +1 -1
  50. package/lib/server/bidi/bidiPage.js +61 -30
  51. package/lib/server/bidi/third_party/bidiProtocolCore.js +1 -0
  52. package/lib/server/browserContext.js +43 -36
  53. package/lib/server/browserType.js +12 -4
  54. package/lib/server/chromium/chromium.js +26 -21
  55. package/lib/server/chromium/chromiumSwitches.js +12 -3
  56. package/lib/server/chromium/crBrowser.js +30 -12
  57. package/lib/server/chromium/crConnection.js +0 -5
  58. package/lib/server/chromium/crCoverage.js +13 -1
  59. package/lib/server/chromium/crDevTools.js +0 -2
  60. package/lib/server/chromium/crNetworkManager.js +107 -18
  61. package/lib/server/chromium/crPage.js +68 -124
  62. package/lib/server/chromium/crServiceWorker.js +14 -1
  63. package/lib/server/codegen/javascript.js +6 -29
  64. package/lib/server/console.js +5 -1
  65. package/lib/server/deviceDescriptorsSource.json +56 -56
  66. package/lib/server/dispatchers/browserContextDispatcher.js +26 -8
  67. package/lib/server/dispatchers/dispatcher.js +6 -13
  68. package/lib/server/dispatchers/frameDispatcher.js +1 -1
  69. package/lib/server/dispatchers/jsHandleDispatcher.js +2 -2
  70. package/lib/server/dispatchers/pageAgentDispatcher.js +96 -0
  71. package/lib/server/dispatchers/pageDispatcher.js +14 -22
  72. package/lib/server/dispatchers/playwrightDispatcher.js +0 -4
  73. package/lib/server/dom.js +12 -3
  74. package/lib/server/electron/electron.js +6 -3
  75. package/lib/server/firefox/ffBrowser.js +10 -20
  76. package/lib/server/firefox/ffConnection.js +0 -5
  77. package/lib/server/firefox/ffNetworkManager.js +2 -2
  78. package/lib/server/firefox/ffPage.js +18 -24
  79. package/lib/server/firefox/firefox.js +18 -9
  80. package/lib/server/frameSelectors.js +18 -8
  81. package/lib/server/frames.js +257 -87
  82. package/lib/server/input.js +7 -3
  83. package/lib/server/instrumentation.js +3 -0
  84. package/lib/server/javascript.js +8 -4
  85. package/lib/server/launchApp.js +2 -1
  86. package/lib/server/localUtils.js +4 -8
  87. package/lib/server/network.js +50 -12
  88. package/lib/server/page.js +112 -126
  89. package/lib/server/playwright.js +2 -4
  90. package/lib/server/progress.js +26 -6
  91. package/lib/server/recorder/recorderApp.js +80 -101
  92. package/lib/server/recorder.js +3 -2
  93. package/lib/server/registry/browserFetcher.js +6 -4
  94. package/lib/server/registry/index.js +278 -189
  95. package/lib/server/registry/oopDownloadBrowserMain.js +9 -2
  96. package/lib/server/screencast.js +190 -0
  97. package/lib/server/screenshotter.js +6 -0
  98. package/lib/server/socksClientCertificatesInterceptor.js +1 -1
  99. package/lib/server/trace/recorder/snapshotter.js +17 -8
  100. package/lib/server/trace/recorder/snapshotterInjected.js +30 -72
  101. package/lib/server/trace/recorder/tracing.js +31 -21
  102. package/lib/server/trace/viewer/traceParser.js +72 -0
  103. package/lib/server/trace/viewer/traceViewer.js +45 -40
  104. package/lib/server/utils/comparators.js +3 -25
  105. package/lib/server/utils/expectUtils.js +87 -2
  106. package/lib/server/utils/hostPlatform.js +30 -3
  107. package/lib/server/utils/httpServer.js +5 -20
  108. package/lib/server/utils/imageUtils.js +141 -0
  109. package/lib/server/utils/network.js +55 -40
  110. package/lib/server/utils/nodePlatform.js +6 -0
  111. package/lib/server/{chromium/videoRecorder.js → videoRecorder.js} +35 -24
  112. package/lib/server/webkit/webkit.js +5 -16
  113. package/lib/server/webkit/wkBrowser.js +2 -6
  114. package/lib/server/webkit/wkConnection.js +1 -6
  115. package/lib/server/webkit/wkInterceptableRequest.js +29 -1
  116. package/lib/server/webkit/wkPage.js +76 -51
  117. package/lib/server/webkit/wkWorkers.js +2 -1
  118. package/lib/utils/isomorphic/ariaSnapshot.js +63 -0
  119. package/lib/utils/isomorphic/locatorGenerators.js +24 -8
  120. package/lib/utils/isomorphic/lruCache.js +51 -0
  121. package/lib/utils/isomorphic/mimeType.js +1 -1
  122. package/lib/utils/isomorphic/protocolFormatter.js +3 -0
  123. package/lib/utils/isomorphic/protocolMetainfo.js +11 -2
  124. package/lib/utils/isomorphic/stringUtils.js +49 -0
  125. package/lib/utils/isomorphic/trace/entries.js +16 -0
  126. package/lib/utils/isomorphic/trace/snapshotRenderer.js +499 -0
  127. package/lib/utils/isomorphic/trace/snapshotServer.js +120 -0
  128. package/lib/utils/isomorphic/trace/snapshotStorage.js +89 -0
  129. package/lib/utils/isomorphic/trace/traceLoader.js +131 -0
  130. package/lib/utils/isomorphic/trace/traceModel.js +365 -0
  131. package/lib/utils/isomorphic/trace/traceModernizer.js +400 -0
  132. package/lib/utils/isomorphic/trace/versions/traceV3.js +16 -0
  133. package/lib/utils/isomorphic/trace/versions/traceV4.js +16 -0
  134. package/lib/utils/isomorphic/trace/versions/traceV5.js +16 -0
  135. package/lib/utils/isomorphic/trace/versions/traceV6.js +16 -0
  136. package/lib/utils/isomorphic/trace/versions/traceV7.js +16 -0
  137. package/lib/utils/isomorphic/trace/versions/traceV8.js +16 -0
  138. package/lib/utils/isomorphic/urlMatch.js +19 -5
  139. package/lib/utils/isomorphic/yaml.js +84 -0
  140. package/lib/utils.js +4 -0
  141. package/lib/utilsBundle.js +1 -1
  142. package/lib/utilsBundleImpl/index.js +124 -124
  143. package/lib/vite/htmlReport/index.html +21 -21
  144. package/lib/vite/recorder/assets/codeMirrorModule-CFUTFUO7.js +32 -0
  145. package/lib/vite/recorder/assets/{codeMirrorModule-C3UTv-Ge.css → codeMirrorModule-DYBRYzYX.css} +1 -1
  146. package/lib/vite/recorder/assets/{index-Ri0uHF7I.css → index-BSjZa4pk.css} +1 -1
  147. package/lib/vite/recorder/assets/index-CVkBxsGf.js +193 -0
  148. package/lib/vite/recorder/index.html +2 -2
  149. package/lib/vite/traceViewer/assets/codeMirrorModule-BVA4h_ZY.js +32 -0
  150. package/lib/vite/traceViewer/assets/defaultSettingsView-CjfmcdOz.js +266 -0
  151. package/lib/vite/traceViewer/{codeMirrorModule.C3UTv-Ge.css → codeMirrorModule.DYBRYzYX.css} +1 -1
  152. package/lib/vite/traceViewer/defaultSettingsView.7ch9cixO.css +1 -0
  153. package/lib/vite/traceViewer/index.BVu7tZDe.css +1 -0
  154. package/lib/vite/traceViewer/index.BtyWtaE-.js +2 -0
  155. package/lib/vite/traceViewer/index.html +6 -6
  156. package/lib/vite/traceViewer/manifest.webmanifest +16 -0
  157. package/lib/vite/traceViewer/snapshot.html +3 -3
  158. package/lib/vite/traceViewer/sw.bundle.js +5 -3
  159. package/lib/vite/traceViewer/uiMode.fyrXARf2.js +5 -0
  160. package/lib/vite/traceViewer/uiMode.html +3 -3
  161. package/package.json +2 -1
  162. package/types/protocol.d.ts +939 -245
  163. package/types/types.d.ts +143 -153
  164. package/lib/client/accessibility.js +0 -49
  165. package/lib/server/accessibility.js +0 -69
  166. package/lib/server/bidi/third_party/bidiDeserializer.js +0 -98
  167. package/lib/server/chromium/crAccessibility.js +0 -263
  168. package/lib/server/firefox/ffAccessibility.js +0 -238
  169. package/lib/server/trace/test/inMemorySnapshotter.js +0 -87
  170. package/lib/server/webkit/wkAccessibility.js +0 -237
  171. package/lib/server/webkit/wsl/webkit-wsl-transport-client.js +0 -74
  172. package/lib/server/webkit/wsl/webkit-wsl-transport-server.js +0 -113
  173. package/lib/vite/recorder/assets/codeMirrorModule-RJCXzfmE.js +0 -24
  174. package/lib/vite/recorder/assets/index-Y-X2TGJv.js +0 -193
  175. package/lib/vite/traceViewer/assets/codeMirrorModule-rbQPefq7.js +0 -24
  176. package/lib/vite/traceViewer/assets/defaultSettingsView-CLbol9XR.js +0 -265
  177. package/lib/vite/traceViewer/defaultSettingsView.TQ8_7ybu.css +0 -1
  178. package/lib/vite/traceViewer/index.I8N9v4jT.css +0 -1
  179. package/lib/vite/traceViewer/index.zIVi6mN9.js +0 -2
  180. package/lib/vite/traceViewer/uiMode.B_CpmIpF.js +0 -5
@@ -1,7 +1,5 @@
1
1
  $ErrorActionPreference = 'Stop'
2
2
 
3
- # WebKit WSL Installation Script
4
- # See webkit-wsl-transport-server.ts for the complete architecture diagram.
5
3
  # This script sets up a WSL distribution that will be used to run WebKit.
6
4
 
7
5
  $Distribution = "playwright"
@@ -25,9 +23,9 @@ if [ ! -f "/home/$Username/node/bin/node" ]; then
25
23
  mkdir -p /home/$Username/node
26
24
  curl -fsSL https://nodejs.org/dist/v22.17.0/node-v22.17.0-linux-x64.tar.xz -o /home/$Username/node/node-v22.17.0-linux-x64.tar.xz
27
25
  tar -xJf /home/$Username/node/node-v22.17.0-linux-x64.tar.xz -C /home/$Username/node --strip-components=1
26
+ sudo -u $Username echo 'export PATH=/home/$Username/node/bin:\`$PATH' >> /home/$Username/.profile
28
27
  fi
29
28
  /home/$Username/node/bin/node cli.js install-deps webkit
30
- cp lib/server/webkit/wsl/webkit-wsl-transport-client.js /home/$Username/
31
29
  sudo -u $Username PLAYWRIGHT_SKIP_BROWSER_GC=1 /home/$Username/node/bin/node cli.js install webkit
32
30
  "@ -replace "\r\n", "`n"
33
31
 
package/browsers.json CHANGED
@@ -3,59 +3,58 @@
3
3
  "browsers": [
4
4
  {
5
5
  "name": "chromium",
6
- "revision": "1194",
6
+ "revision": "1208",
7
7
  "installByDefault": true,
8
- "browserVersion": "141.0.7390.37"
8
+ "browserVersion": "145.0.7632.6",
9
+ "title": "Chrome for Testing"
9
10
  },
10
11
  {
11
12
  "name": "chromium-headless-shell",
12
- "revision": "1194",
13
+ "revision": "1208",
13
14
  "installByDefault": true,
14
- "browserVersion": "141.0.7390.37"
15
+ "browserVersion": "145.0.7632.6",
16
+ "title": "Chrome Headless Shell"
15
17
  },
16
18
  {
17
19
  "name": "chromium-tip-of-tree",
18
- "revision": "1371",
20
+ "revision": "1401",
19
21
  "installByDefault": false,
20
- "browserVersion": "142.0.7430.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": "1371",
27
+ "revision": "1401",
25
28
  "installByDefault": false,
26
- "browserVersion": "142.0.7430.0"
29
+ "browserVersion": "146.0.7644.0",
30
+ "title": "Chrome Canary Headless Shell"
27
31
  },
28
32
  {
29
33
  "name": "firefox",
30
- "revision": "1495",
34
+ "revision": "1509",
31
35
  "installByDefault": true,
32
- "browserVersion": "142.0.1"
36
+ "browserVersion": "146.0.1",
37
+ "title": "Firefox"
33
38
  },
34
39
  {
35
40
  "name": "firefox-beta",
36
- "revision": "1490",
41
+ "revision": "1504",
37
42
  "installByDefault": false,
38
- "browserVersion": "143.0b10"
43
+ "browserVersion": "146.0b8",
44
+ "title": "Firefox Beta"
39
45
  },
40
46
  {
41
47
  "name": "webkit",
42
- "revision": "2215",
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",
@@ -72,47 +72,6 @@ Examples:
72
72
  $ codegen
73
73
  $ codegen --target=python
74
74
  $ codegen -b webkit https://example.com`);
75
- function suggestedBrowsersToInstall() {
76
- return import_server.registry.executables().filter((e) => e.installType !== "none" && e.type !== "tool").map((e) => e.name).join(", ");
77
- }
78
- function defaultBrowsersToInstall(options) {
79
- let executables = import_server.registry.defaultExecutables();
80
- if (options.noShell)
81
- executables = executables.filter((e) => e.name !== "chromium-headless-shell");
82
- if (options.onlyShell)
83
- executables = executables.filter((e) => e.name !== "chromium");
84
- return executables;
85
- }
86
- function checkBrowsersToInstall(args, options) {
87
- if (options.noShell && options.onlyShell)
88
- throw new Error(`Only one of --no-shell and --only-shell can be specified`);
89
- const faultyArguments = [];
90
- const executables = [];
91
- const handleArgument = (arg) => {
92
- const executable = import_server.registry.findExecutable(arg);
93
- if (!executable || executable.installType === "none")
94
- faultyArguments.push(arg);
95
- else
96
- executables.push(executable);
97
- if (executable?.browserName === "chromium")
98
- executables.push(import_server.registry.findExecutable("ffmpeg"));
99
- };
100
- for (const arg of args) {
101
- if (arg === "chromium") {
102
- if (!options.onlyShell)
103
- handleArgument("chromium");
104
- if (!options.noShell)
105
- handleArgument("chromium-headless-shell");
106
- } else {
107
- handleArgument(arg);
108
- }
109
- }
110
- if (process.platform === "win32")
111
- executables.push(import_server.registry.findExecutable("winldd"));
112
- if (faultyArguments.length)
113
- throw new Error(`Invalid installation targets: ${faultyArguments.map((name) => `'${name}'`).join(", ")}. Expecting one of: ${suggestedBrowsersToInstall()}`);
114
- return executables;
115
- }
116
75
  function printInstalledBrowsers(browsers2) {
117
76
  const browserPaths = /* @__PURE__ */ new Set();
118
77
  for (const browser of browsers2)
@@ -165,9 +124,7 @@ Playwright version: ${version}`);
165
124
  printInstalledBrowsers(groupedByPlaywrightMinorVersion.get(version));
166
125
  }
167
126
  }
168
- 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) {
169
- if (options.shell === false)
170
- options.noShell = true;
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) {
171
128
  if ((0, import_utils.isLikelyNpxGlobal)()) {
172
129
  console.error((0, import_ascii.wrapInASCIIBox)([
173
130
  `WARNING: It looks like you are running 'npx playwright install' without first`,
@@ -189,16 +146,17 @@ import_utilsBundle.program.command("install [browser...]").description("ensure b
189
146
  ].join("\n"), 1));
190
147
  }
191
148
  try {
192
- const hasNoArguments = !args.length;
193
- const executables = hasNoArguments ? defaultBrowsersToInstall(options) : checkBrowsersToInstall(args, options);
149
+ if (options.shell === false && options.onlyShell)
150
+ throw new Error(`Only one of --no-shell and --only-shell can be specified`);
151
+ const shell = options.shell === false ? "no" : options.onlyShell ? "only" : void 0;
152
+ const executables = import_server.registry.resolveBrowsers(args, { shell });
194
153
  if (options.withDeps)
195
154
  await import_server.registry.installDeps(executables, !!options.dryRun);
196
155
  if (options.dryRun && options.list)
197
156
  throw new Error(`Only one of --dry-run and --list can be specified`);
198
157
  if (options.dryRun) {
199
158
  for (const executable of executables) {
200
- const version = executable.browserVersion ? `version ` + executable.browserVersion : "";
201
- console.log(`browser: ${executable.name}${version ? " " + version : ""}`);
159
+ console.log(import_server.registry.calculateDownloadTitle(executable));
202
160
  console.log(` Install location: ${executable.directory ?? "<system>"}`);
203
161
  if (executable.downloadURLs?.length) {
204
162
  const [url, ...fallbacks] = executable.downloadURLs;
@@ -212,8 +170,7 @@ import_utilsBundle.program.command("install [browser...]").description("ensure b
212
170
  const browsers2 = await import_server.registry.listInstalledBrowsers();
213
171
  printGroupedByPlaywrightVersion(browsers2);
214
172
  } else {
215
- const forceReinstall = hasNoArguments ? false : !!options.force;
216
- await import_server.registry.install(executables, forceReinstall);
173
+ await import_server.registry.install(executables, { force: options.force });
217
174
  await import_server.registry.validateHostRequirementsForExecutablesIfNeeded(executables, process.env.PW_LANG_NAME || "javascript").catch((e) => {
218
175
  e.name = "Playwright Host validation warning";
219
176
  console.error(e);
@@ -231,7 +188,7 @@ Examples:
231
188
  Install default browsers.
232
189
 
233
190
  - $ install chrome firefox
234
- Install custom browsers, supports ${suggestedBrowsersToInstall()}.`);
191
+ Install custom browsers, supports ${import_server.registry.suggestedBrowsersToInstall()}.`);
235
192
  import_utilsBundle.program.command("uninstall").description("Removes browsers used by this installation of Playwright from the system (chromium, firefox, webkit, ffmpeg). This does not include branded channels.").option("--all", "Removes all browsers used by any Playwright installation from the system.").action(async (options) => {
236
193
  delete process.env.PLAYWRIGHT_SKIP_BROWSER_GC;
237
194
  await import_server.registry.uninstall(!!options.all).then(({ numberOfBrowsersLeft }) => {
@@ -244,10 +201,7 @@ To uninstall Playwright browsers for all installations, re-run with --all flag.`
244
201
  });
245
202
  import_utilsBundle.program.command("install-deps [browser...]").description("install dependencies necessary to run browsers (will ask for sudo permissions)").option("--dry-run", "Do not execute installation commands, only print them").action(async function(args, options) {
246
203
  try {
247
- if (!args.length)
248
- await import_server.registry.installDeps(defaultBrowsersToInstall({}), !!options.dryRun);
249
- else
250
- await import_server.registry.installDeps(checkBrowsersToInstall(args, {}), !!options.dryRun);
204
+ await import_server.registry.installDeps(import_server.registry.resolveBrowsers(args, {}), !!options.dryRun);
251
205
  } catch (e) {
252
206
  console.log(`Failed to install browser dependencies
253
207
  ${e}`);
@@ -259,7 +213,7 @@ Examples:
259
213
  Install dependencies for default browsers.
260
214
 
261
215
  - $ install-deps chrome firefox
262
- Install dependencies for specific browsers, supports ${suggestedBrowsersToInstall()}.`);
216
+ Install dependencies for specific browsers, supports ${import_server.registry.suggestedBrowsersToInstall()}.`);
263
217
  const browsers = [
264
218
  { alias: "cr", name: "Chromium", type: "chromium" },
265
219
  { alias: "ff", name: "Firefox", type: "firefox" },
@@ -304,7 +258,7 @@ Examples:
304
258
  import_utilsBundle.program.command("run-driver", { hidden: true }).action(function(options) {
305
259
  (0, import_driver.runDriver)();
306
260
  });
307
- import_utilsBundle.program.command("run-server").option("--port <port>", "Server port").option("--host <host>", "Server host").option("--path <path>", "Endpoint Path", "/").option("--max-clients <maxClients>", "Maximum clients").option("--mode <mode>", 'Server mode, either "default" or "extension"').action(function(options) {
261
+ import_utilsBundle.program.command("run-server", { hidden: true }).option("--port <port>", "Server port").option("--host <host>", "Server host").option("--path <path>", "Endpoint Path", "/").option("--max-clients <maxClients>", "Maximum clients").option("--mode <mode>", 'Server mode, either "default" or "extension"').action(function(options) {
308
262
  (0, import_driver.runServer)({
309
263
  port: options.port ? +options.port : void 0,
310
264
  host: options.host,
@@ -319,7 +273,7 @@ import_utilsBundle.program.command("print-api-json", { hidden: true }).action(fu
319
273
  import_utilsBundle.program.command("launch-server", { hidden: true }).requiredOption("--browser <browserName>", 'Browser name, one of "chromium", "firefox" or "webkit"').option("--config <path-to-config-file>", "JSON file with launchServer options").action(function(options) {
320
274
  (0, import_driver.launchBrowserServer)(options.browser, options.config);
321
275
  });
322
- import_utilsBundle.program.command("show-trace [trace...]").option("-b, --browser <browserType>", "browser to use, one of cr, chromium, ff, firefox, wk, webkit", "chromium").option("-h, --host <host>", "Host to serve trace on; specifying this option opens trace in a browser tab").option("-p, --port <port>", "Port to serve trace on, 0 for any free port; specifying this option opens trace in a browser tab").option("--stdin", "Accept trace URLs over stdin to update the viewer").description("show trace viewer").action(function(traces, options) {
276
+ import_utilsBundle.program.command("show-trace [trace]").option("-b, --browser <browserType>", "browser to use, one of cr, chromium, ff, firefox, wk, webkit", "chromium").option("-h, --host <host>", "Host to serve trace on; specifying this option opens trace in a browser tab").option("-p, --port <port>", "Port to serve trace on, 0 for any free port; specifying this option opens trace in a browser tab").option("--stdin", "Accept trace URLs over stdin to update the viewer").description("show trace viewer").action(function(trace, options) {
323
277
  if (options.browser === "cr")
324
278
  options.browser = "chromium";
325
279
  if (options.browser === "ff")
@@ -332,12 +286,13 @@ import_utilsBundle.program.command("show-trace [trace...]").option("-b, --browse
332
286
  isServer: !!options.stdin
333
287
  };
334
288
  if (options.port !== void 0 || options.host !== void 0)
335
- (0, import_traceViewer.runTraceInBrowser)(traces, openOptions).catch(logErrorAndExit);
289
+ (0, import_traceViewer.runTraceInBrowser)(trace, openOptions).catch(logErrorAndExit);
336
290
  else
337
- (0, import_traceViewer.runTraceViewerApp)(traces, options.browser, openOptions, true).catch(logErrorAndExit);
291
+ (0, import_traceViewer.runTraceViewerApp)(trace, options.browser, openOptions, true).catch(logErrorAndExit);
338
292
  }).addHelpText("afterAll", `
339
293
  Examples:
340
294
 
295
+ $ show-trace
341
296
  $ show-trace https://example.com/trace.zip`);
342
297
  async function launchContext(options, extraOptions) {
343
298
  validateOptions(options);
@@ -466,6 +421,7 @@ async function openPage(context, url) {
466
421
  }
467
422
  async function open(options, url) {
468
423
  const { context } = await launchContext(options, { headless: !!process.env.PWTEST_CLI_HEADLESS, executablePath: process.env.PWTEST_CLI_EXECUTABLE_PATH });
424
+ await context._exposeConsoleApi();
469
425
  await openPage(context, url);
470
426
  }
471
427
  async function codegen(options, url) {
package/lib/client/api.js CHANGED
@@ -21,7 +21,6 @@ __export(api_exports, {
21
21
  APIRequest: () => import_fetch.APIRequest,
22
22
  APIRequestContext: () => import_fetch.APIRequestContext,
23
23
  APIResponse: () => import_fetch.APIResponse,
24
- Accessibility: () => import_accessibility.Accessibility,
25
24
  Android: () => import_android.Android,
26
25
  AndroidDevice: () => import_android.AndroidDevice,
27
26
  AndroidInput: () => import_android.AndroidInput,
@@ -47,6 +46,7 @@ __export(api_exports, {
47
46
  Locator: () => import_locator.Locator,
48
47
  Mouse: () => import_input.Mouse,
49
48
  Page: () => import_page.Page,
49
+ PageAgent: () => import_pageAgent.PageAgent,
50
50
  Playwright: () => import_playwright.Playwright,
51
51
  Request: () => import_network.Request,
52
52
  Response: () => import_network.Response,
@@ -62,7 +62,6 @@ __export(api_exports, {
62
62
  Worker: () => import_worker.Worker
63
63
  });
64
64
  module.exports = __toCommonJS(api_exports);
65
- var import_accessibility = require("./accessibility");
66
65
  var import_android = require("./android");
67
66
  var import_browser = require("./browser");
68
67
  var import_browserContext = require("./browserContext");
@@ -83,6 +82,7 @@ var import_jsHandle = require("./jsHandle");
83
82
  var import_network = require("./network");
84
83
  var import_fetch = require("./fetch");
85
84
  var import_page = require("./page");
85
+ var import_pageAgent = require("./pageAgent");
86
86
  var import_selectors = require("./selectors");
87
87
  var import_tracing = require("./tracing");
88
88
  var import_video = require("./video");
@@ -95,7 +95,6 @@ var import_webError = require("./webError");
95
95
  APIRequest,
96
96
  APIRequestContext,
97
97
  APIResponse,
98
- Accessibility,
99
98
  Android,
100
99
  AndroidDevice,
101
100
  AndroidInput,
@@ -121,6 +120,7 @@ var import_webError = require("./webError");
121
120
  Locator,
122
121
  Mouse,
123
122
  Page,
123
+ PageAgent,
124
124
  Playwright,
125
125
  Request,
126
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());
@@ -90,11 +91,19 @@ class BrowserContext extends import_channelOwner.ChannelOwner {
90
91
  this.emit(import_events.Events.BrowserContext.ServiceWorker, serviceWorker);
91
92
  });
92
93
  this._channel.on("console", (event) => {
93
- const consoleMessage = new import_consoleMessage.ConsoleMessage(this._platform, event, import_page.Page.fromNullable(event.page));
94
+ const worker = import_worker.Worker.fromNullable(event.worker);
95
+ const page = import_page.Page.fromNullable(event.page);
96
+ const consoleMessage = new import_consoleMessage.ConsoleMessage(this._platform, event, page, worker);
97
+ worker?.emit(import_events.Events.Worker.Console, consoleMessage);
98
+ page?.emit(import_events.Events.Page.Console, consoleMessage);
99
+ if (worker && this._serviceWorkers.has(worker)) {
100
+ const scope = this._serviceWorkerScope(worker);
101
+ for (const page2 of this._pages) {
102
+ if (scope && page2.url().startsWith(scope))
103
+ page2.emit(import_events.Events.Page.Console, consoleMessage);
104
+ }
105
+ }
94
106
  this.emit(import_events.Events.BrowserContext.Console, consoleMessage);
95
- const page = consoleMessage.page();
96
- if (page)
97
- page.emit(import_events.Events.Page.Console, consoleMessage);
98
107
  });
99
108
  this._channel.on("pageError", ({ error, page }) => {
100
109
  const pageObject = import_page.Page.from(page);
@@ -111,11 +120,11 @@ class BrowserContext extends import_channelOwner.ChannelOwner {
111
120
  hasListeners = page.emit(import_events.Events.Page.Dialog, dialogObject) || hasListeners;
112
121
  if (!hasListeners) {
113
122
  if (dialogObject.type() === "beforeunload")
114
- dialog.accept({}).catch(() => {
115
- });
123
+ dialogObject._wrapApiCall(() => dialog.accept({}).catch(() => {
124
+ }), { internal: true });
116
125
  else
117
- dialog.dismiss().catch(() => {
118
- });
126
+ dialogObject._wrapApiCall(() => dialog.dismiss().catch(() => {
127
+ }), { internal: true });
119
128
  }
120
129
  });
121
130
  this._channel.on("request", ({ request, page }) => this._onRequest(network.Request.from(request), import_page.Page.fromNullable(page)));
@@ -231,6 +240,16 @@ class BrowserContext extends import_channelOwner.ChannelOwner {
231
240
  return;
232
241
  await bindingCall.call(func);
233
242
  }
243
+ _serviceWorkerScope(serviceWorker) {
244
+ try {
245
+ let url = new URL(".", serviceWorker.url()).href;
246
+ if (!url.endsWith("/"))
247
+ url += "/";
248
+ return url;
249
+ } catch {
250
+ return null;
251
+ }
252
+ }
234
253
  setDefaultNavigationTimeout(timeout) {
235
254
  this._timeoutSettings.setDefaultNavigationTimeout(timeout);
236
255
  }
@@ -460,6 +479,40 @@ class BrowserContext extends import_channelOwner.ChannelOwner {
460
479
  this._onRecorderEventSink = void 0;
461
480
  await this._channel.disableRecorder();
462
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
+ }
463
516
  async installInjectRoute() {
464
517
  if (this.routeInjecting) return;
465
518
  await this.route("**/*", async (route) => {
@@ -474,6 +527,7 @@ class BrowserContext extends import_channelOwner.ChannelOwner {
474
527
  await route.fallback();
475
528
  }
476
529
  });
530
+ this.routeInjecting = true;
477
531
  }
478
532
  }
479
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;
@@ -23,12 +23,16 @@ __export(consoleMessage_exports, {
23
23
  module.exports = __toCommonJS(consoleMessage_exports);
24
24
  var import_jsHandle = require("./jsHandle");
25
25
  class ConsoleMessage {
26
- constructor(platform, event, page) {
26
+ constructor(platform, event, page, worker) {
27
27
  this._page = page;
28
+ this._worker = worker;
28
29
  this._event = event;
29
30
  if (platform.inspectCustom)
30
31
  this[platform.inspectCustom] = () => this._inspect();
31
32
  }
33
+ worker() {
34
+ return this._worker;
35
+ }
32
36
  page() {
33
37
  return this._page;
34
38
  }
@@ -66,7 +66,7 @@ class ElectronApplication extends import_channelOwner.ChannelOwner {
66
66
  this._channel.on("close", () => {
67
67
  this.emit(import_events.Events.ElectronApplication.Close);
68
68
  });
69
- this._channel.on("console", (event) => this.emit(import_events.Events.ElectronApplication.Console, new import_consoleMessage.ConsoleMessage(this._platform, event, null)));
69
+ this._channel.on("console", (event) => this.emit(import_events.Events.ElectronApplication.Console, new import_consoleMessage.ConsoleMessage(this._platform, event, null, null)));
70
70
  this._setEventToSubscriptionMapping(/* @__PURE__ */ new Map([
71
71
  [import_events.Events.ElectronApplication.Console, "console"]
72
72
  ]));
@@ -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",
@@ -85,7 +88,8 @@ const Events = {
85
88
  FrameSent: "framesent"
86
89
  },
87
90
  Worker: {
88
- Close: "close"
91
+ Close: "close",
92
+ Console: "console"
89
93
  },
90
94
  ElectronApplication: {
91
95
  Close: "close",
@@ -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({
@@ -188,6 +196,9 @@ class Locator {
188
196
  describe(description) {
189
197
  return new Locator(this._frame, this._selector + " >> internal:describe=" + JSON.stringify(description));
190
198
  }
199
+ description() {
200
+ return (0, import_locatorGenerators.locatorCustomDescription)(this._selector) || null;
201
+ }
191
202
  first() {
192
203
  return new Locator(this._frame, this._selector + " >> nth=0");
193
204
  }
@@ -319,7 +330,7 @@ class Locator {
319
330
  return this.toString();
320
331
  }
321
332
  toString() {
322
- return (0, import_locatorGenerators.asLocator)("javascript", this._selector);
333
+ return (0, import_locatorGenerators.asLocatorDescription)("javascript", this._selector);
323
334
  }
324
335
  }
325
336
  class FrameLocator {
@@ -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();