patchright-core 1.52.5 → 1.55.0

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 (218) hide show
  1. package/ThirdPartyNotices.txt +65 -123
  2. package/bin/reinstall_chrome_beta_mac.sh +1 -1
  3. package/bin/reinstall_chrome_stable_mac.sh +1 -1
  4. package/bin/reinstall_msedge_beta_mac.sh +1 -1
  5. package/bin/reinstall_msedge_dev_mac.sh +1 -1
  6. package/bin/reinstall_msedge_stable_mac.sh +1 -1
  7. package/browsers.json +14 -14
  8. package/index.js +1 -1
  9. package/lib/androidServerImpl.js +4 -2
  10. package/lib/browserServerImpl.js +47 -12
  11. package/lib/cli/program.js +116 -50
  12. package/lib/cli/programWithTestStub.js +1 -1
  13. package/lib/client/android.js +30 -34
  14. package/lib/client/browser.js +54 -17
  15. package/lib/client/browserContext.js +67 -71
  16. package/lib/client/browserType.js +25 -34
  17. package/lib/client/channelOwner.js +20 -24
  18. package/lib/client/connection.js +6 -10
  19. package/lib/client/electron.js +8 -3
  20. package/lib/client/elementHandle.js +18 -21
  21. package/lib/client/fetch.js +5 -3
  22. package/lib/client/frame.js +54 -32
  23. package/lib/client/input.js +3 -1
  24. package/lib/client/jsHandle.js +4 -0
  25. package/lib/client/localUtils.js +0 -1
  26. package/lib/client/locator.js +30 -26
  27. package/lib/client/network.js +5 -12
  28. package/lib/client/page.js +32 -32
  29. package/lib/client/playwright.js +6 -16
  30. package/lib/client/selectors.js +18 -38
  31. package/lib/client/timeoutSettings.js +12 -8
  32. package/lib/client/tracing.js +24 -20
  33. package/lib/client/waiter.js +2 -2
  34. package/lib/client/webSocket.js +4 -22
  35. package/lib/generated/bindingsControllerSource.js +28 -0
  36. package/lib/generated/clockSource.js +1 -1
  37. package/lib/generated/injectedScriptSource.js +1 -1
  38. package/lib/generated/pollingRecorderSource.js +1 -1
  39. package/lib/generated/storageScriptSource.js +28 -0
  40. package/lib/generated/utilityScriptSource.js +1 -1
  41. package/lib/generated/webSocketMockSource.js +12 -50
  42. package/lib/inProcessFactory.js +9 -6
  43. package/lib/outofprocess.js +0 -2
  44. package/lib/protocol/validator.js +421 -345
  45. package/lib/protocol/validatorPrimitives.js +18 -4
  46. package/lib/remote/playwrightConnection.js +29 -166
  47. package/lib/remote/playwrightServer.js +233 -35
  48. package/lib/server/android/android.js +97 -83
  49. package/lib/server/android/backendAdb.js +0 -2
  50. package/lib/server/bidi/bidiBrowser.js +139 -73
  51. package/lib/server/bidi/bidiChromium.js +23 -22
  52. package/lib/server/bidi/bidiExecutionContext.js +2 -1
  53. package/lib/server/bidi/bidiFirefox.js +17 -14
  54. package/lib/server/bidi/bidiInput.js +22 -22
  55. package/lib/server/bidi/bidiNetworkManager.js +8 -11
  56. package/lib/server/bidi/bidiPage.js +42 -86
  57. package/lib/server/bidi/third_party/bidiProtocol.js +5 -133
  58. package/lib/server/bidi/third_party/bidiProtocolCore.js +179 -0
  59. package/lib/server/{dispatchers/selectorsDispatcher.js → bidi/third_party/bidiProtocolPermissions.js} +20 -18
  60. package/lib/server/browser.js +30 -21
  61. package/lib/server/browserContext.js +203 -165
  62. package/lib/server/browserType.js +109 -107
  63. package/lib/server/chromium/chromium.js +84 -69
  64. package/lib/server/chromium/chromiumSwitches.js +13 -20
  65. package/lib/server/chromium/crBrowser.js +74 -40
  66. package/lib/server/chromium/crConnection.js +8 -9
  67. package/lib/server/chromium/crCoverage.js +11 -8
  68. package/lib/server/chromium/crDragDrop.js +25 -20
  69. package/lib/server/chromium/crExecutionContext.js +2 -1
  70. package/lib/server/chromium/crInput.js +32 -29
  71. package/lib/server/chromium/crNetworkManager.js +43 -31
  72. package/lib/server/chromium/crPage.js +98 -72
  73. package/lib/server/chromium/crServiceWorker.js +13 -18
  74. package/lib/server/chromium/videoRecorder.js +10 -18
  75. package/lib/server/clock.js +51 -39
  76. package/lib/server/codegen/csharp.js +10 -5
  77. package/lib/server/codegen/java.js +1 -1
  78. package/lib/server/codegen/javascript.js +1 -1
  79. package/lib/server/codegen/jsonl.js +2 -1
  80. package/lib/server/codegen/language.js +22 -1
  81. package/lib/server/codegen/languages.js +4 -4
  82. package/lib/server/codegen/python.js +1 -1
  83. package/lib/server/cookieStore.js +3 -1
  84. package/lib/server/debugController.js +105 -71
  85. package/lib/server/debugger.js +6 -23
  86. package/lib/server/deviceDescriptorsSource.json +237 -127
  87. package/lib/server/dialog.js +50 -6
  88. package/lib/server/dispatchers/androidDispatcher.js +77 -62
  89. package/lib/server/dispatchers/artifactDispatcher.js +18 -18
  90. package/lib/server/dispatchers/browserContextDispatcher.js +141 -91
  91. package/lib/server/dispatchers/browserDispatcher.js +55 -88
  92. package/lib/server/dispatchers/browserTypeDispatcher.js +18 -9
  93. package/lib/server/dispatchers/cdpSessionDispatcher.js +4 -4
  94. package/lib/server/dispatchers/debugControllerDispatcher.js +12 -21
  95. package/lib/server/dispatchers/dialogDispatcher.js +4 -4
  96. package/lib/server/dispatchers/dispatcher.js +78 -53
  97. package/lib/server/dispatchers/electronDispatcher.js +19 -20
  98. package/lib/server/dispatchers/elementHandlerDispatcher.js +83 -93
  99. package/lib/server/dispatchers/frameDispatcher.js +98 -101
  100. package/lib/server/dispatchers/jsHandleDispatcher.js +21 -16
  101. package/lib/server/dispatchers/jsonPipeDispatcher.js +4 -4
  102. package/lib/server/dispatchers/localUtilsDispatcher.js +53 -59
  103. package/lib/server/dispatchers/networkDispatchers.js +41 -35
  104. package/lib/server/dispatchers/pageDispatcher.js +156 -107
  105. package/lib/server/dispatchers/playwrightDispatcher.js +37 -25
  106. package/lib/server/dispatchers/streamDispatcher.js +15 -8
  107. package/lib/server/dispatchers/tracingDispatcher.js +22 -13
  108. package/lib/server/dispatchers/webSocketRouteDispatcher.js +46 -35
  109. package/lib/server/dispatchers/writableStreamDispatcher.js +16 -10
  110. package/lib/server/dom.js +198 -266
  111. package/lib/server/download.js +3 -3
  112. package/lib/server/electron/electron.js +96 -103
  113. package/lib/server/electron/loader.js +1 -1
  114. package/lib/server/fetch.js +22 -41
  115. package/lib/server/fileUploadUtils.js +1 -1
  116. package/lib/server/firefox/ffBrowser.js +79 -55
  117. package/lib/server/firefox/ffExecutionContext.js +2 -1
  118. package/lib/server/firefox/ffInput.js +23 -23
  119. package/lib/server/firefox/ffNetworkManager.js +8 -6
  120. package/lib/server/firefox/ffPage.js +39 -36
  121. package/lib/server/firefox/firefox.js +9 -10
  122. package/lib/server/frameSelectors.js +63 -20
  123. package/lib/server/frames.js +495 -555
  124. package/lib/server/har/harRecorder.js +1 -1
  125. package/lib/server/har/harTracer.js +4 -2
  126. package/lib/server/helper.js +3 -7
  127. package/lib/server/index.js +0 -3
  128. package/lib/server/input.js +47 -54
  129. package/lib/server/instrumentation.js +8 -14
  130. package/lib/server/javascript.js +8 -16
  131. package/lib/server/launchApp.js +48 -30
  132. package/lib/server/localUtils.js +45 -38
  133. package/lib/server/network.js +44 -10
  134. package/lib/server/page.js +232 -177
  135. package/lib/server/pageBinding.js +6 -7
  136. package/lib/server/playwright.js +4 -14
  137. package/lib/server/progress.js +57 -49
  138. package/lib/server/recorder/recorderApp.js +298 -95
  139. package/lib/server/recorder/recorderRunner.js +23 -24
  140. package/lib/server/recorder/recorderSignalProcessor.js +83 -0
  141. package/lib/server/recorder/recorderUtils.js +67 -10
  142. package/lib/server/recorder.js +284 -146
  143. package/lib/server/registry/index.js +83 -48
  144. package/lib/server/registry/nativeDeps.js +175 -0
  145. package/lib/server/registry/oopDownloadBrowserMain.js +1 -1
  146. package/lib/server/screenshotter.js +84 -83
  147. package/lib/server/selectors.js +12 -12
  148. package/lib/server/socksClientCertificatesInterceptor.js +198 -136
  149. package/lib/server/trace/recorder/snapshotter.js +12 -19
  150. package/lib/server/trace/recorder/tracing.js +36 -27
  151. package/lib/server/trace/viewer/traceViewer.js +11 -20
  152. package/lib/server/transport.js +20 -22
  153. package/lib/server/utils/comparators.js +2 -2
  154. package/lib/server/utils/debug.js +3 -8
  155. package/lib/server/utils/debugLogger.js +8 -0
  156. package/lib/server/utils/hostPlatform.js +3 -1
  157. package/lib/server/utils/network.js +35 -25
  158. package/lib/server/utils/nodePlatform.js +1 -1
  159. package/lib/server/utils/processLauncher.js +4 -1
  160. package/lib/server/utils/wsServer.js +11 -17
  161. package/lib/server/webkit/webkit.js +5 -2
  162. package/lib/server/webkit/wkBrowser.js +51 -28
  163. package/lib/server/webkit/wkExecutionContext.js +2 -1
  164. package/lib/server/webkit/wkInput.js +25 -25
  165. package/lib/server/webkit/wkInterceptableRequest.js +1 -1
  166. package/lib/server/webkit/wkPage.js +80 -59
  167. package/lib/server/webkit/wkProvisionalPage.js +1 -1
  168. package/lib/server/webkit/wkWorkers.js +7 -7
  169. package/lib/utils/isomorphic/ariaSnapshot.js +13 -7
  170. package/lib/utils/isomorphic/cssParser.js +1 -2
  171. package/lib/utils/isomorphic/locatorGenerators.js +18 -0
  172. package/lib/utils/isomorphic/manualPromise.js +1 -2
  173. package/lib/utils/isomorphic/mimeType.js +1 -2
  174. package/lib/utils/isomorphic/multimap.js +1 -2
  175. package/lib/utils/isomorphic/oldUtilityScriptSerializers.js +248 -0
  176. package/lib/utils/isomorphic/protocolFormatter.js +78 -0
  177. package/lib/utils/isomorphic/protocolMetainfo.js +318 -0
  178. package/lib/utils/isomorphic/selectorParser.js +3 -4
  179. package/lib/utils/isomorphic/stringUtils.js +3 -24
  180. package/lib/utils/isomorphic/time.js +9 -4
  181. package/lib/utils/isomorphic/timeoutRunner.js +3 -4
  182. package/lib/utils/isomorphic/traceUtils.js +2 -3
  183. package/lib/utils/isomorphic/urlMatch.js +21 -7
  184. package/lib/utils/isomorphic/utilityScriptSerializers.js +208 -205
  185. package/lib/utils.js +8 -2
  186. package/lib/utilsBundleImpl/index.js +160 -150
  187. package/lib/vite/htmlReport/index.html +17 -17
  188. package/lib/vite/recorder/assets/{codeMirrorModule-CXVeovup.js → codeMirrorModule-DzQ0k89p.js} +1 -1
  189. package/lib/vite/recorder/assets/{index-eHBmevrY.css → index-CI4HQ-Zb.css} +1 -1
  190. package/lib/vite/recorder/assets/index-D7C7daHH.js +184 -0
  191. package/lib/vite/recorder/index.html +3 -3
  192. package/lib/vite/traceViewer/assets/{codeMirrorModule-_GLjJL-7.js → codeMirrorModule-Di48jgWx.js} +1 -1
  193. package/lib/vite/traceViewer/assets/defaultSettingsView-szBn8781.js +256 -0
  194. package/lib/vite/traceViewer/defaultSettingsView.DVJHpiGt.css +1 -0
  195. package/lib/vite/traceViewer/index.BFsek2M6.css +1 -0
  196. package/lib/vite/traceViewer/index.DQvXoPLL.js +2 -0
  197. package/lib/vite/traceViewer/index.html +6 -6
  198. package/lib/vite/traceViewer/sw.bundle.js +3 -3
  199. package/lib/vite/traceViewer/uiMode.dBV3oN9h.js +5 -0
  200. package/lib/vite/traceViewer/uiMode.html +4 -4
  201. package/lib/zipBundleImpl.js +4 -4
  202. package/package.json +1 -1
  203. package/types/protocol.d.ts +712 -107
  204. package/types/types.d.ts +128 -17
  205. package/lib/generated/consoleApiSource.js +0 -28
  206. package/lib/protocol/debug.js +0 -211
  207. package/lib/server/recorder/contextRecorder.js +0 -286
  208. package/lib/server/recorder/recorderCollection.js +0 -116
  209. package/lib/server/recorder/recorderFrontend.js +0 -16
  210. package/lib/server/storageScript.js +0 -154
  211. package/lib/server/timeoutSettings.js +0 -89
  212. package/lib/utils/isomorphic/builtins.js +0 -86
  213. package/lib/vite/recorder/assets/index-BsWQsSGl.js +0 -184
  214. package/lib/vite/traceViewer/assets/defaultSettingsView-DtCQiGHe.js +0 -265
  215. package/lib/vite/traceViewer/defaultSettingsView.QdHITyLI.css +0 -1
  216. package/lib/vite/traceViewer/index.CFOW-Ezb.css +0 -1
  217. package/lib/vite/traceViewer/index.cFZzK9RN.js +0 -2
  218. package/lib/vite/traceViewer/uiMode.XVPIqBeS.js +0 -5
@@ -37,9 +37,9 @@ var import_browser = require("../browser");
37
37
  var import_browserContext = require("../browserContext");
38
38
  var import_errors = require("../errors");
39
39
  var network = __toESM(require("../network"));
40
- var import_page = require("../page");
41
40
  var import_ffConnection = require("./ffConnection");
42
41
  var import_ffPage = require("./ffPage");
42
+ var import_page = require("../page");
43
43
  class FFBrowser extends import_browser.Browser {
44
44
  constructor(parent, connection, options) {
45
45
  super(parent, options);
@@ -126,7 +126,7 @@ class FFBrowser extends import_browser.Browser {
126
126
  const ffPage = this._ffPages.get(payload.pageTargetId);
127
127
  if (!ffPage)
128
128
  return;
129
- ffPage._page._frameManager.frameAbortedNavigation(payload.frameId, "Download is starting");
129
+ ffPage._page.frameManager.frameAbortedNavigation(payload.frameId, "Download is starting");
130
130
  let originPage = ffPage._page.initializedOrUndefined();
131
131
  if (!originPage) {
132
132
  ffPage._markAsError(new Error("Starting new page download"));
@@ -163,7 +163,6 @@ class FFBrowserContext extends import_browserContext.BrowserContext {
163
163
  const browserContextId = this._browserContextId;
164
164
  const promises = [
165
165
  super._initialize(),
166
- this._browser.session.send("Browser.addBinding", { browserContextId: this._browserContextId, name: import_page.PageBinding.kPlaywrightBinding, script: "" }),
167
166
  this._updateInitScripts()
168
167
  ];
169
168
  if (this._options.acceptDownloads !== "internal-browser-default") {
@@ -175,13 +174,7 @@ class FFBrowserContext extends import_browserContext.BrowserContext {
175
174
  }
176
175
  }));
177
176
  }
178
- if (this._options.viewport) {
179
- const viewport = {
180
- viewportSize: { width: this._options.viewport.width, height: this._options.viewport.height },
181
- deviceScaleFactor: this._options.deviceScaleFactor || 1
182
- };
183
- promises.push(this._browser.session.send("Browser.setDefaultViewport", { browserContextId, viewport }));
184
- }
177
+ promises.push(this.doUpdateDefaultViewport());
185
178
  if (this._options.hasTouch)
186
179
  promises.push(this._browser.session.send("Browser.setTouchOverride", { browserContextId, hasTouch: true }));
187
180
  if (this._options.userAgent)
@@ -197,37 +190,14 @@ class FFBrowserContext extends import_browserContext.BrowserContext {
197
190
  if (this._options.timezoneId)
198
191
  promises.push(this._browser.session.send("Browser.setTimezoneOverride", { browserContextId, timezoneId: this._options.timezoneId }));
199
192
  if (this._options.extraHTTPHeaders || this._options.locale)
200
- promises.push(this.setExtraHTTPHeaders(this._options.extraHTTPHeaders || []));
193
+ promises.push(this.doUpdateExtraHTTPHeaders());
201
194
  if (this._options.httpCredentials)
202
195
  promises.push(this.setHTTPCredentials(this._options.httpCredentials));
203
196
  if (this._options.geolocation)
204
197
  promises.push(this.setGeolocation(this._options.geolocation));
205
198
  if (this._options.offline)
206
- promises.push(this.setOffline(this._options.offline));
207
- if (this._options.colorScheme !== "no-override") {
208
- promises.push(this._browser.session.send("Browser.setColorScheme", {
209
- browserContextId,
210
- colorScheme: this._options.colorScheme !== void 0 ? this._options.colorScheme : "light"
211
- }));
212
- }
213
- if (this._options.reducedMotion !== "no-override") {
214
- promises.push(this._browser.session.send("Browser.setReducedMotion", {
215
- browserContextId,
216
- reducedMotion: this._options.reducedMotion !== void 0 ? this._options.reducedMotion : "no-preference"
217
- }));
218
- }
219
- if (this._options.forcedColors !== "no-override") {
220
- promises.push(this._browser.session.send("Browser.setForcedColors", {
221
- browserContextId,
222
- forcedColors: this._options.forcedColors !== void 0 ? this._options.forcedColors : "none"
223
- }));
224
- }
225
- if (this._options.contrast !== "no-override") {
226
- promises.push(this._browser.session.send("Browser.setContrast", {
227
- browserContextId,
228
- contrast: this._options.contrast !== void 0 ? this._options.contrast : "no-preference"
229
- }));
230
- }
199
+ promises.push(this.doUpdateOffline());
200
+ promises.push(this.doUpdateDefaultEmulatedMedia());
231
201
  if (this._options.recordVideo) {
232
202
  promises.push(this._ensureVideosPath().then(() => {
233
203
  return this._browser.session.send("Browser.setVideoRecordingOptions", {
@@ -256,7 +226,6 @@ class FFBrowserContext extends import_browserContext.BrowserContext {
256
226
  return this._ffPages().map((ffPage) => ffPage._page);
257
227
  }
258
228
  async doCreateNewPage() {
259
- (0, import_browserContext.assertBrowserContextIsNotOwned)(this);
260
229
  const { targetId } = await this._browser.session.send("Browser.newPage", {
261
230
  browserContextId: this._browserContextId
262
231
  }).catch((e) => {
@@ -269,17 +238,34 @@ class FFBrowserContext extends import_browserContext.BrowserContext {
269
238
  async doGetCookies(urls) {
270
239
  const { cookies } = await this._browser.session.send("Browser.getCookies", { browserContextId: this._browserContextId });
271
240
  return network.filterCookies(cookies.map((c) => {
272
- const copy = { ...c };
273
- delete copy.size;
274
- delete copy.session;
275
- return copy;
241
+ const { name, value, domain, path, expires, httpOnly, secure, sameSite } = c;
242
+ return {
243
+ name,
244
+ value,
245
+ domain,
246
+ path,
247
+ expires,
248
+ httpOnly,
249
+ secure,
250
+ sameSite
251
+ };
276
252
  }), urls);
277
253
  }
278
254
  async addCookies(cookies) {
279
- const cc = network.rewriteCookies(cookies).map((c) => ({
280
- ...c,
281
- expires: c.expires === -1 ? void 0 : c.expires
282
- }));
255
+ const cc = network.rewriteCookies(cookies).map((c) => {
256
+ const { name, value, url, domain, path, expires, httpOnly, secure, sameSite } = c;
257
+ return {
258
+ name,
259
+ value,
260
+ url,
261
+ domain,
262
+ path,
263
+ expires: expires === -1 ? void 0 : expires,
264
+ httpOnly,
265
+ secure,
266
+ sameSite
267
+ };
268
+ });
283
269
  await this._browser.session.send("Browser.setCookies", { browserContextId: this._browserContextId, cookies: cc });
284
270
  }
285
271
  async doClearCookies() {
@@ -308,9 +294,8 @@ class FFBrowserContext extends import_browserContext.BrowserContext {
308
294
  this._options.geolocation = geolocation;
309
295
  await this._browser.session.send("Browser.setGeolocationOverride", { browserContextId: this._browserContextId, geolocation: geolocation || null });
310
296
  }
311
- async setExtraHTTPHeaders(headers) {
312
- this._options.extraHTTPHeaders = headers;
313
- let allHeaders = this._options.extraHTTPHeaders;
297
+ async doUpdateExtraHTTPHeaders() {
298
+ let allHeaders = this._options.extraHTTPHeaders || [];
314
299
  if (this._options.locale)
315
300
  allHeaders = network.mergeHeaders([allHeaders, network.singleHeader("Accept-Language", this._options.locale)]);
316
301
  await this._browser.session.send("Browser.setExtraHTTPHeaders", { browserContextId: this._browserContextId, headers: allHeaders });
@@ -318,9 +303,8 @@ class FFBrowserContext extends import_browserContext.BrowserContext {
318
303
  async setUserAgent(userAgent) {
319
304
  await this._browser.session.send("Browser.setUserAgentOverride", { browserContextId: this._browserContextId, userAgent: userAgent || null });
320
305
  }
321
- async setOffline(offline) {
322
- this._options.offline = offline;
323
- await this._browser.session.send("Browser.setOnlineOverride", { browserContextId: this._browserContextId, override: offline ? "offline" : "online" });
306
+ async doUpdateOffline() {
307
+ await this._browser.session.send("Browser.setOnlineOverride", { browserContextId: this._browserContextId, override: this._options.offline ? "offline" : "online" });
324
308
  }
325
309
  async doSetHTTPCredentials(httpCredentials) {
326
310
  this._options.httpCredentials = httpCredentials;
@@ -334,20 +318,60 @@ class FFBrowserContext extends import_browserContext.BrowserContext {
334
318
  async doAddInitScript(initScript) {
335
319
  await this._updateInitScripts();
336
320
  }
337
- async doRemoveNonInternalInitScripts() {
321
+ async doRemoveInitScripts(initScripts) {
338
322
  await this._updateInitScripts();
339
323
  }
340
324
  async _updateInitScripts() {
341
325
  const bindingScripts = [...this._pageBindings.values()].map((binding) => binding.initScript.source);
326
+ if (this.bindingsInitScript)
327
+ bindingScripts.unshift(this.bindingsInitScript.source);
342
328
  const initScripts = this.initScripts.map((script) => script.source);
343
- await this._browser.session.send("Browser.setInitScripts", { browserContextId: this._browserContextId, scripts: [import_page.kBuiltinsScript.source, ...bindingScripts, ...initScripts].map((script) => ({ script })) });
329
+ await this._browser.session.send("Browser.setInitScripts", { browserContextId: this._browserContextId, scripts: [...bindingScripts, ...initScripts].map((script) => ({ script })) });
344
330
  }
345
331
  async doUpdateRequestInterception() {
346
332
  await Promise.all([
347
- this._browser.session.send("Browser.setRequestInterception", { browserContextId: this._browserContextId, enabled: !!this._requestInterceptor }),
348
- this._browser.session.send("Browser.setCacheDisabled", { browserContextId: this._browserContextId, cacheDisabled: !!this._requestInterceptor })
333
+ this._browser.session.send("Browser.setRequestInterception", { browserContextId: this._browserContextId, enabled: this.requestInterceptors.length > 0 }),
334
+ this._browser.session.send("Browser.setCacheDisabled", { browserContextId: this._browserContextId, cacheDisabled: this.requestInterceptors.length > 0 })
349
335
  ]);
350
336
  }
337
+ async doUpdateDefaultViewport() {
338
+ if (!this._options.viewport)
339
+ return;
340
+ const viewport = {
341
+ viewportSize: { width: this._options.viewport.width, height: this._options.viewport.height },
342
+ deviceScaleFactor: this._options.deviceScaleFactor || 1
343
+ };
344
+ await this._browser.session.send("Browser.setDefaultViewport", { browserContextId: this._browserContextId, viewport });
345
+ }
346
+ async doUpdateDefaultEmulatedMedia() {
347
+ if (this._options.colorScheme !== "no-override") {
348
+ await this._browser.session.send("Browser.setColorScheme", {
349
+ browserContextId: this._browserContextId,
350
+ colorScheme: this._options.colorScheme !== void 0 ? this._options.colorScheme : "light"
351
+ });
352
+ }
353
+ if (this._options.reducedMotion !== "no-override") {
354
+ await this._browser.session.send("Browser.setReducedMotion", {
355
+ browserContextId: this._browserContextId,
356
+ reducedMotion: this._options.reducedMotion !== void 0 ? this._options.reducedMotion : "no-preference"
357
+ });
358
+ }
359
+ if (this._options.forcedColors !== "no-override") {
360
+ await this._browser.session.send("Browser.setForcedColors", {
361
+ browserContextId: this._browserContextId,
362
+ forcedColors: this._options.forcedColors !== void 0 ? this._options.forcedColors : "none"
363
+ });
364
+ }
365
+ if (this._options.contrast !== "no-override") {
366
+ await this._browser.session.send("Browser.setContrast", {
367
+ browserContextId: this._browserContextId,
368
+ contrast: this._options.contrast !== void 0 ? this._options.contrast : "no-preference"
369
+ });
370
+ }
371
+ }
372
+ async doExposePlaywrightBinding() {
373
+ this._browser.session.send("Browser.addBinding", { browserContextId: this._browserContextId, name: import_page.PageBinding.kBindingName, script: "" });
374
+ }
351
375
  onClosePersistent() {
352
376
  }
353
377
  async clearCache() {
@@ -34,6 +34,7 @@ __export(ffExecutionContext_exports, {
34
34
  module.exports = __toCommonJS(ffExecutionContext_exports);
35
35
  var import_assert = require("../../utils/isomorphic/assert");
36
36
  var import_stackTrace = require("../../utils/isomorphic/stackTrace");
37
+ var import_utilityScriptSerializers = require("../../utils/isomorphic/utilityScriptSerializers");
37
38
  var js = __toESM(require("../javascript"));
38
39
  var dom = __toESM(require("../dom"));
39
40
  var import_protocolError = require("../protocolError");
@@ -73,7 +74,7 @@ class FFExecutionContext {
73
74
  }).catch(rewriteError);
74
75
  checkException(payload.exceptionDetails);
75
76
  if (returnByValue)
76
- return js.parseEvaluationResultValue(payload.result.value);
77
+ return (0, import_utilityScriptSerializers.parseEvaluationResultValue)(payload.result.value);
77
78
  return createHandle(utilityScript._context, payload.result);
78
79
  }
79
80
  async getProperties(object) {
@@ -58,12 +58,12 @@ class RawKeyboardImpl {
58
58
  constructor(client) {
59
59
  this._client = client;
60
60
  }
61
- async keydown(modifiers, keyName, description, autoRepeat) {
61
+ async keydown(progress, modifiers, keyName, description, autoRepeat) {
62
62
  let text = description.text;
63
63
  if (text === "\r")
64
64
  text = "";
65
65
  const { code, key, location } = description;
66
- await this._client.send("Page.dispatchKeyEvent", {
66
+ await progress.race(this._client.send("Page.dispatchKeyEvent", {
67
67
  type: "keydown",
68
68
  keyCode: description.keyCodeWithoutLocation,
69
69
  code,
@@ -71,39 +71,39 @@ class RawKeyboardImpl {
71
71
  repeat: autoRepeat,
72
72
  location,
73
73
  text
74
- });
74
+ }));
75
75
  }
76
- async keyup(modifiers, keyName, description) {
76
+ async keyup(progress, modifiers, keyName, description) {
77
77
  const { code, key, location } = description;
78
- await this._client.send("Page.dispatchKeyEvent", {
78
+ await progress.race(this._client.send("Page.dispatchKeyEvent", {
79
79
  type: "keyup",
80
80
  key,
81
81
  keyCode: description.keyCodeWithoutLocation,
82
82
  code,
83
83
  location,
84
84
  repeat: false
85
- });
85
+ }));
86
86
  }
87
- async sendText(text) {
88
- await this._client.send("Page.insertText", { text });
87
+ async sendText(progress, text) {
88
+ await progress.race(this._client.send("Page.insertText", { text }));
89
89
  }
90
90
  }
91
91
  class RawMouseImpl {
92
92
  constructor(client) {
93
93
  this._client = client;
94
94
  }
95
- async move(x, y, button, buttons, modifiers, forClick) {
96
- await this._client.send("Page.dispatchMouseEvent", {
95
+ async move(progress, x, y, button, buttons, modifiers, forClick) {
96
+ await progress.race(this._client.send("Page.dispatchMouseEvent", {
97
97
  type: "mousemove",
98
98
  button: 0,
99
99
  buttons: toButtonsMask(buttons),
100
100
  x: Math.floor(x),
101
101
  y: Math.floor(y),
102
102
  modifiers: toModifiersMask(modifiers)
103
- });
103
+ }));
104
104
  }
105
- async down(x, y, button, buttons, modifiers, clickCount) {
106
- await this._client.send("Page.dispatchMouseEvent", {
105
+ async down(progress, x, y, button, buttons, modifiers, clickCount) {
106
+ await progress.race(this._client.send("Page.dispatchMouseEvent", {
107
107
  type: "mousedown",
108
108
  button: toButtonNumber(button),
109
109
  buttons: toButtonsMask(buttons),
@@ -111,10 +111,10 @@ class RawMouseImpl {
111
111
  y: Math.floor(y),
112
112
  modifiers: toModifiersMask(modifiers),
113
113
  clickCount
114
- });
114
+ }));
115
115
  }
116
- async up(x, y, button, buttons, modifiers, clickCount) {
117
- await this._client.send("Page.dispatchMouseEvent", {
116
+ async up(progress, x, y, button, buttons, modifiers, clickCount) {
117
+ await progress.race(this._client.send("Page.dispatchMouseEvent", {
118
118
  type: "mouseup",
119
119
  button: toButtonNumber(button),
120
120
  buttons: toButtonsMask(buttons),
@@ -122,18 +122,18 @@ class RawMouseImpl {
122
122
  y: Math.floor(y),
123
123
  modifiers: toModifiersMask(modifiers),
124
124
  clickCount
125
- });
125
+ }));
126
126
  }
127
- async wheel(x, y, buttons, modifiers, deltaX, deltaY) {
127
+ async wheel(progress, x, y, buttons, modifiers, deltaX, deltaY) {
128
128
  await this._page.mainFrame().evaluateExpression(`new Promise(requestAnimationFrame)`, { world: "utility" });
129
- await this._client.send("Page.dispatchWheelEvent", {
129
+ await progress.race(this._client.send("Page.dispatchWheelEvent", {
130
130
  deltaX,
131
131
  deltaY,
132
132
  x: Math.floor(x),
133
133
  y: Math.floor(y),
134
134
  deltaZ: 0,
135
135
  modifiers: toModifiersMask(modifiers)
136
- });
136
+ }));
137
137
  }
138
138
  setPage(page) {
139
139
  this._page = page;
@@ -143,12 +143,12 @@ class RawTouchscreenImpl {
143
143
  constructor(client) {
144
144
  this._client = client;
145
145
  }
146
- async tap(x, y, modifiers) {
147
- await this._client.send("Page.dispatchTapEvent", {
146
+ async tap(progress, x, y, modifiers) {
147
+ await progress.race(this._client.send("Page.dispatchTapEvent", {
148
148
  x,
149
149
  y,
150
150
  modifiers: toModifiersMask(modifiers)
151
- });
151
+ }));
152
152
  }
153
153
  }
154
154
  // Annotate the CommonJS export names for ESM import in node:
@@ -56,9 +56,11 @@ class FFNetworkManager {
56
56
  }
57
57
  _onRequestWillBeSent(event) {
58
58
  const redirectedFrom = event.redirectedFrom ? this._requests.get(event.redirectedFrom) || null : null;
59
- const frame = redirectedFrom ? redirectedFrom.request.frame() : event.frameId ? this._page._frameManager.frame(event.frameId) : null;
59
+ const frame = redirectedFrom ? redirectedFrom.request.frame() : event.frameId ? this._page.frameManager.frame(event.frameId) : null;
60
60
  if (!frame)
61
61
  return;
62
+ if (event.method === "OPTIONS" && !event.isIntercepted)
63
+ return;
62
64
  if (redirectedFrom)
63
65
  this._requests.delete(redirectedFrom._id);
64
66
  const request = new InterceptableRequest(frame, redirectedFrom, event);
@@ -66,7 +68,7 @@ class FFNetworkManager {
66
68
  if (event.isIntercepted)
67
69
  route = new FFRouteImpl(this._session, request);
68
70
  this._requests.set(request._id, request);
69
- this._page._frameManager.requestStarted(request.request, route);
71
+ this._page.frameManager.requestStarted(request.request, route);
70
72
  }
71
73
  _onResponseReceived(event) {
72
74
  const request = this._requests.get(event.requestId);
@@ -114,7 +116,7 @@ class FFNetworkManager {
114
116
  });
115
117
  response.setRawResponseHeaders(null);
116
118
  response.setResponseHeadersSize(null);
117
- this._page._frameManager.requestReceivedResponse(response);
119
+ this._page.frameManager.requestReceivedResponse(response);
118
120
  }
119
121
  _onRequestFinished(event) {
120
122
  const request = this._requests.get(event.requestId);
@@ -133,7 +135,7 @@ class FFNetworkManager {
133
135
  }
134
136
  if (event.protocolVersion)
135
137
  response._setHttpVersion(event.protocolVersion);
136
- this._page._frameManager.reportRequestFinished(request.request, response);
138
+ this._page.frameManager.reportRequestFinished(request.request, response);
137
139
  }
138
140
  _onRequestFailed(event) {
139
141
  const request = this._requests.get(event.requestId);
@@ -147,7 +149,7 @@ class FFNetworkManager {
147
149
  response._requestFinished(-1);
148
150
  }
149
151
  request.request._setFailureText(event.errorCode);
150
- this._page._frameManager.requestFailed(request.request, event.errorCode === "NS_BINDING_ABORTED");
152
+ this._page.frameManager.requestFailed(request.request, event.errorCode === "NS_BINDING_ABORTED");
151
153
  }
152
154
  }
153
155
  const causeToResourceType = {
@@ -187,7 +189,7 @@ class InterceptableRequest {
187
189
  if (payload.postData)
188
190
  postDataBuffer = Buffer.from(payload.postData, "base64");
189
191
  this.request = new network.Request(
190
- frame._page._browserContext,
192
+ frame._page.browserContext,
191
193
  frame,
192
194
  null,
193
195
  redirectedFrom ? redirectedFrom.request : null,
@@ -98,7 +98,7 @@ class FFPage {
98
98
  this._reportedAsNew = true;
99
99
  this._page.reportAsNew(this._opener?._page);
100
100
  });
101
- this.addInitScript(new import_page.InitScript("", true), UTILITY_WORLD_NAME).catch((e) => this._markAsError(e));
101
+ this.addInitScript(new import_page.InitScript(""), UTILITY_WORLD_NAME).catch((e) => this._markAsError(e));
102
102
  }
103
103
  async _markAsError(error) {
104
104
  if (this._reportedAsNew)
@@ -107,23 +107,23 @@ class FFPage {
107
107
  this._page.reportAsNew(this._opener?._page, error);
108
108
  }
109
109
  _onWebSocketCreated(event) {
110
- this._page._frameManager.onWebSocketCreated(webSocketId(event.frameId, event.wsid), event.requestURL);
111
- this._page._frameManager.onWebSocketRequest(webSocketId(event.frameId, event.wsid));
110
+ this._page.frameManager.onWebSocketCreated(webSocketId(event.frameId, event.wsid), event.requestURL);
111
+ this._page.frameManager.onWebSocketRequest(webSocketId(event.frameId, event.wsid));
112
112
  }
113
113
  _onWebSocketClosed(event) {
114
114
  if (event.error)
115
- this._page._frameManager.webSocketError(webSocketId(event.frameId, event.wsid), event.error);
116
- this._page._frameManager.webSocketClosed(webSocketId(event.frameId, event.wsid));
115
+ this._page.frameManager.webSocketError(webSocketId(event.frameId, event.wsid), event.error);
116
+ this._page.frameManager.webSocketClosed(webSocketId(event.frameId, event.wsid));
117
117
  }
118
118
  _onWebSocketFrameReceived(event) {
119
- this._page._frameManager.webSocketFrameReceived(webSocketId(event.frameId, event.wsid), event.opcode, event.data);
119
+ this._page.frameManager.webSocketFrameReceived(webSocketId(event.frameId, event.wsid), event.opcode, event.data);
120
120
  }
121
121
  _onWebSocketFrameSent(event) {
122
- this._page._frameManager.onWebSocketFrameSent(webSocketId(event.frameId, event.wsid), event.opcode, event.data);
122
+ this._page.frameManager.onWebSocketFrameSent(webSocketId(event.frameId, event.wsid), event.opcode, event.data);
123
123
  }
124
124
  _onExecutionContextCreated(payload) {
125
125
  const { executionContextId, auxData } = payload;
126
- const frame = this._page._frameManager.frame(auxData.frameId);
126
+ const frame = this._page.frameManager.frame(auxData.frameId);
127
127
  if (!frame)
128
128
  return;
129
129
  const delegate = new import_ffExecutionContext.FFExecutionContext(this._session, executionContextId);
@@ -157,38 +157,38 @@ class FFPage {
157
157
  }
158
158
  _onLinkClicked(phase) {
159
159
  if (phase === "before")
160
- this._page._frameManager.frameWillPotentiallyRequestNavigation();
160
+ this._page.frameManager.frameWillPotentiallyRequestNavigation();
161
161
  else
162
- this._page._frameManager.frameDidPotentiallyRequestNavigation();
162
+ this._page.frameManager.frameDidPotentiallyRequestNavigation();
163
163
  }
164
164
  _onNavigationStarted(params) {
165
- this._page._frameManager.frameRequestedNavigation(params.frameId, params.navigationId);
165
+ this._page.frameManager.frameRequestedNavigation(params.frameId, params.navigationId);
166
166
  }
167
167
  _onNavigationAborted(params) {
168
- this._page._frameManager.frameAbortedNavigation(params.frameId, params.errorText, params.navigationId);
168
+ this._page.frameManager.frameAbortedNavigation(params.frameId, params.errorText, params.navigationId);
169
169
  }
170
170
  _onNavigationCommitted(params) {
171
171
  for (const [workerId, worker] of this._workers) {
172
172
  if (worker.frameId === params.frameId)
173
173
  this._onWorkerDestroyed({ workerId });
174
174
  }
175
- this._page._frameManager.frameCommittedNewDocumentNavigation(params.frameId, params.url, params.name || "", params.navigationId || "", false);
175
+ this._page.frameManager.frameCommittedNewDocumentNavigation(params.frameId, params.url, params.name || "", params.navigationId || "", false);
176
176
  }
177
177
  _onSameDocumentNavigation(params) {
178
- this._page._frameManager.frameCommittedSameDocumentNavigation(params.frameId, params.url);
178
+ this._page.frameManager.frameCommittedSameDocumentNavigation(params.frameId, params.url);
179
179
  }
180
180
  _onFrameAttached(params) {
181
- this._page._frameManager.frameAttached(params.frameId, params.parentFrameId);
181
+ this._page.frameManager.frameAttached(params.frameId, params.parentFrameId);
182
182
  }
183
183
  _onFrameDetached(params) {
184
- this._page._frameManager.frameDetached(params.frameId);
184
+ this._page.frameManager.frameDetached(params.frameId);
185
185
  }
186
186
  _onEventFired(payload) {
187
187
  const { frameId, name } = payload;
188
188
  if (name === "load")
189
- this._page._frameManager.frameLifecycleEvent(frameId, "load");
189
+ this._page.frameManager.frameLifecycleEvent(frameId, "load");
190
190
  if (name === "DOMContentLoaded")
191
- this._page._frameManager.frameLifecycleEvent(frameId, "domcontentloaded");
191
+ this._page.frameManager.frameLifecycleEvent(frameId, "domcontentloaded");
192
192
  }
193
193
  _onUncaughtError(params) {
194
194
  const { name, message } = (0, import_stackTrace.splitErrorMessage)(params.message);
@@ -202,10 +202,10 @@ class FFPage {
202
202
  const context = this._contextIdToContext.get(executionContextId);
203
203
  if (!context)
204
204
  return;
205
- this._page._addConsoleMessage(type === "warn" ? "warning" : type, args.map((arg) => (0, import_ffExecutionContext.createHandle)(context, arg)), location);
205
+ this._page.addConsoleMessage(type === "warn" ? "warning" : type, args.map((arg) => (0, import_ffExecutionContext.createHandle)(context, arg)), location);
206
206
  }
207
207
  _onDialogOpened(params) {
208
- this._page.emitOnContext(import_browserContext.BrowserContext.Events.Dialog, new dialog.Dialog(
208
+ this._page.browserContext.dialogManager.dialogDidOpen(new dialog.Dialog(
209
209
  this._page,
210
210
  params.type,
211
211
  params.message,
@@ -220,7 +220,7 @@ class FFPage {
220
220
  if (!(pageOrError instanceof Error)) {
221
221
  const context = this._contextIdToContext.get(event.executionContextId);
222
222
  if (context)
223
- await this._page._onBindingCalled(event.payload, context);
223
+ await this._page.onBindingCalled(event.payload, context);
224
224
  }
225
225
  }
226
226
  async _onFileChooserOpened(payload) {
@@ -244,14 +244,14 @@ class FFPage {
244
244
  });
245
245
  });
246
246
  this._workers.set(workerId, { session: workerSession, frameId: event.frameId });
247
- this._page._addWorker(workerId, worker);
247
+ this._page.addWorker(workerId, worker);
248
248
  workerSession.once("Runtime.executionContextCreated", (event2) => {
249
- worker._createExecutionContext(new import_ffExecutionContext.FFExecutionContext(workerSession, event2.executionContextId));
249
+ worker.createExecutionContext(new import_ffExecutionContext.FFExecutionContext(workerSession, event2.executionContextId));
250
250
  });
251
251
  workerSession.on("Runtime.console", (event2) => {
252
252
  const { type, args, location } = event2;
253
- const context = worker._existingExecutionContext;
254
- this._page._addConsoleMessage(type, args.map((arg) => (0, import_ffExecutionContext.createHandle)(context, arg)), location);
253
+ const context = worker.existingExecutionContext;
254
+ this._page.addConsoleMessage(type, args.map((arg) => (0, import_ffExecutionContext.createHandle)(context, arg)), location);
255
255
  });
256
256
  }
257
257
  _onWorkerDestroyed(event) {
@@ -261,7 +261,7 @@ class FFPage {
261
261
  return;
262
262
  worker.session.dispose();
263
263
  this._workers.delete(workerId);
264
- this._page._removeWorker(workerId);
264
+ this._page.removeWorker(workerId);
265
265
  }
266
266
  async _onDispatchMessageFromWorker(event) {
267
267
  const worker = this._workers.get(event.workerId);
@@ -291,7 +291,7 @@ class FFPage {
291
291
  await this._session.send("Network.setExtraHTTPHeaders", { headers: this._page.extraHTTPHeaders() || [] });
292
292
  }
293
293
  async updateEmulatedViewportSize() {
294
- const viewportSize = this._page.viewportSize();
294
+ const viewportSize = this._page.emulatedSize()?.viewport ?? null;
295
295
  await this._session.send("Page.setViewportSize", { viewportSize });
296
296
  }
297
297
  async bringToFront() {
@@ -336,10 +336,14 @@ class FFPage {
336
336
  }
337
337
  async addInitScript(initScript, worldName) {
338
338
  this._initScripts.push({ initScript, worldName });
339
- await this._session.send("Page.setInitScripts", { scripts: this._initScripts.map((s) => ({ script: s.initScript.source, worldName: s.worldName })) });
339
+ await this._updateInitScripts();
340
+ }
341
+ async removeInitScripts(initScripts) {
342
+ const set = new Set(initScripts);
343
+ this._initScripts = this._initScripts.filter((s) => !set.has(s.initScript));
344
+ await this._updateInitScripts();
340
345
  }
341
- async removeInitScripts() {
342
- this._initScripts = this._initScripts.filter((s) => s.initScript.internal);
346
+ async _updateInitScripts() {
343
347
  await this._session.send("Page.setInitScripts", { scripts: this._initScripts.map((s) => ({ script: s.initScript.source, worldName: s.worldName })) });
344
348
  }
345
349
  async closePage(runBeforeUnload) {
@@ -359,13 +363,12 @@ class FFPage {
359
363
  height: viewportRect.height
360
364
  };
361
365
  }
362
- progress.throwIfAborted();
363
- const { data } = await this._session.send("Page.screenshot", {
366
+ const { data } = await progress.race(this._session.send("Page.screenshot", {
364
367
  mimeType: "image/" + format,
365
368
  clip: documentRect,
366
369
  quality,
367
370
  omitDeviceScaleFactor: scale === "css"
368
- });
371
+ }));
369
372
  return Buffer.from(data, "base64");
370
373
  }
371
374
  async getContentFrame(handle) {
@@ -375,7 +378,7 @@ class FFPage {
375
378
  });
376
379
  if (!contentFrameId)
377
380
  return null;
378
- return this._page._frameManager.frame(contentFrameId);
381
+ return this._page.frameManager.frame(contentFrameId);
379
382
  }
380
383
  async getOwnerFrame(handle) {
381
384
  const { ownerFrameId } = await this._session.send("Page.describeNode", {
@@ -471,8 +474,8 @@ class FFPage {
471
474
  }
472
475
  async inputActionEpilogue() {
473
476
  }
474
- async resetForReuse() {
475
- await this.rawMouse.move(-1, -1, "none", /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set(), false);
477
+ async resetForReuse(progress) {
478
+ await this.rawMouse.move(progress, -1, -1, "none", /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set(), false);
476
479
  }
477
480
  async getFrameElement(frame) {
478
481
  const parent = frame.parentFrame();
@@ -37,7 +37,7 @@ var import_ffBrowser = require("./ffBrowser");
37
37
  var import_ffConnection = require("./ffConnection");
38
38
  var import_ascii = require("../utils/ascii");
39
39
  var import_browserType = require("../browserType");
40
- var import_browserType2 = require("../browserType");
40
+ var import_manualPromise = require("../../utils/isomorphic/manualPromise");
41
41
  class Firefox extends import_browserType.BrowserType {
42
42
  constructor(parent) {
43
43
  super(parent, "firefox");
@@ -55,7 +55,7 @@ Workaround: Set the HOME=/root environment variable${process.env.GITHUB_ACTION ?
55
55
  error.logs = "\n" + (0, import_ascii.wrapInASCIIBox)(import_browserType.kNoXServerRunningError, 1);
56
56
  return error;
57
57
  }
58
- amendEnvironment(env, userDataDir, executable, browserArguments) {
58
+ amendEnvironment(env) {
59
59
  if (!import_path.default.isAbsolute(import_os.default.homedir()))
60
60
  throw new Error(`Cannot launch Firefox with relative home directory. Did you set ${import_os.default.platform() === "win32" ? "USERPROFILE" : "HOME"} to a relative path?`);
61
61
  if (import_os.default.platform() === "linux") {
@@ -90,14 +90,13 @@ Workaround: Set the HOME=/root environment variable${process.env.GITHUB_ACTION ?
90
90
  firefoxArguments.push("-silent");
91
91
  return firefoxArguments;
92
92
  }
93
- readyState(options) {
94
- return new JugglerReadyState();
95
- }
96
- }
97
- class JugglerReadyState extends import_browserType2.BrowserReadyState {
98
- onBrowserOutput(message) {
99
- if (message.includes("Juggler listening to the pipe"))
100
- this._wsEndpoint.resolve(void 0);
93
+ waitForReadyState(options, browserLogsCollector) {
94
+ const result = new import_manualPromise.ManualPromise();
95
+ browserLogsCollector.onMessage((message) => {
96
+ if (message.includes("Juggler listening to the pipe"))
97
+ result.resolve({});
98
+ });
99
+ return result;
101
100
  }
102
101
  }
103
102
  // Annotate the CommonJS export names for ESM import in node: