patchright-bun-core 1.58.2 → 1.59.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 (272) hide show
  1. package/ThirdPartyNotices.txt +126 -650
  2. package/browsers.json +16 -14
  3. package/lib/bootstrap.js +77 -0
  4. package/lib/cli/browserActions.js +308 -0
  5. package/lib/cli/driver.js +3 -2
  6. package/lib/cli/installActions.js +171 -0
  7. package/lib/cli/program.js +47 -411
  8. package/lib/client/android.js +4 -4
  9. package/lib/client/api.js +3 -3
  10. package/lib/client/browser.js +8 -0
  11. package/lib/client/browserContext.js +18 -37
  12. package/lib/client/browserType.js +19 -51
  13. package/lib/client/cdpSession.js +6 -2
  14. package/lib/client/channelOwner.js +1 -1
  15. package/lib/client/{webSocket.js → connect.js} +57 -7
  16. package/lib/client/connection.js +8 -4
  17. package/lib/client/consoleMessage.js +3 -0
  18. package/lib/client/debugger.js +57 -0
  19. package/lib/client/dialog.js +8 -1
  20. package/lib/client/disposable.js +76 -0
  21. package/lib/client/electron.js +1 -0
  22. package/lib/client/elementHandle.js +1 -4
  23. package/lib/client/events.js +3 -3
  24. package/lib/client/fetch.js +0 -1
  25. package/lib/client/frame.js +0 -5
  26. package/lib/client/harRouter.js +13 -1
  27. package/lib/client/jsHandle.js +0 -4
  28. package/lib/client/locator.js +5 -7
  29. package/lib/client/network.js +14 -11
  30. package/lib/client/page.js +34 -48
  31. package/lib/client/platform.js +0 -3
  32. package/lib/client/screencast.js +88 -0
  33. package/lib/client/selectors.js +3 -1
  34. package/lib/client/tracing.js +11 -4
  35. package/lib/client/video.js +13 -20
  36. package/lib/generated/bindingsControllerSource.js +1 -1
  37. package/lib/generated/clockSource.js +1 -1
  38. package/lib/generated/injectedScriptSource.js +1 -1
  39. package/lib/generated/pollingRecorderSource.js +1 -1
  40. package/lib/generated/storageScriptSource.js +1 -1
  41. package/lib/generated/utilityScriptSource.js +1 -1
  42. package/lib/mcpBundle.js +0 -6
  43. package/lib/mcpBundleImpl.js +91 -0
  44. package/lib/protocol/validator.js +216 -118
  45. package/lib/protocol/validatorPrimitives.js +1 -1
  46. package/lib/remote/playwrightConnection.js +10 -8
  47. package/lib/remote/playwrightPipeServer.js +100 -0
  48. package/lib/remote/playwrightServer.js +13 -8
  49. package/lib/remote/playwrightWebSocketServer.js +73 -0
  50. package/lib/remote/serverTransport.js +96 -0
  51. package/lib/server/android/android.js +2 -2
  52. package/lib/server/bidi/bidiBrowser.js +30 -8
  53. package/lib/server/bidi/bidiChromium.js +18 -5
  54. package/lib/server/bidi/bidiNetworkManager.js +39 -11
  55. package/lib/server/bidi/bidiPage.js +31 -15
  56. package/lib/server/bidi/third_party/firefoxPrefs.js +3 -1
  57. package/lib/server/browser.js +84 -21
  58. package/lib/server/browserContext.js +97 -58
  59. package/lib/server/browserType.js +14 -12
  60. package/lib/server/chromium/chromium.js +15 -13
  61. package/lib/server/chromium/crBrowser.js +18 -10
  62. package/lib/server/chromium/crNetworkManager.js +4 -4
  63. package/lib/server/chromium/crPage.js +26 -64
  64. package/lib/server/chromium/crServiceWorker.js +5 -4
  65. package/lib/server/clock.js +33 -33
  66. package/lib/server/console.js +5 -1
  67. package/lib/server/debugController.js +12 -6
  68. package/lib/server/debugger.js +40 -47
  69. package/lib/server/deviceDescriptorsSource.json +137 -137
  70. package/lib/server/dispatchers/browserContextDispatcher.js +27 -30
  71. package/lib/server/dispatchers/browserDispatcher.js +11 -5
  72. package/lib/server/dispatchers/browserTypeDispatcher.js +7 -0
  73. package/lib/server/dispatchers/cdpSessionDispatcher.js +4 -1
  74. package/lib/server/dispatchers/debuggerDispatcher.js +84 -0
  75. package/lib/server/dispatchers/dispatcher.js +1 -1
  76. package/lib/server/dispatchers/disposableDispatcher.js +39 -0
  77. package/lib/server/dispatchers/electronDispatcher.js +2 -1
  78. package/lib/server/dispatchers/frameDispatcher.js +3 -3
  79. package/lib/server/dispatchers/localUtilsDispatcher.js +37 -1
  80. package/lib/server/dispatchers/networkDispatchers.js +6 -5
  81. package/lib/server/dispatchers/pageDispatcher.js +101 -38
  82. package/lib/server/dispatchers/webSocketRouteDispatcher.js +4 -5
  83. package/lib/server/disposable.js +41 -0
  84. package/lib/server/dom.js +44 -26
  85. package/lib/server/download.js +3 -2
  86. package/lib/server/electron/electron.js +12 -7
  87. package/lib/server/firefox/ffBrowser.js +9 -19
  88. package/lib/server/firefox/ffInput.js +21 -5
  89. package/lib/server/firefox/ffNetworkManager.js +2 -2
  90. package/lib/server/firefox/ffPage.js +24 -27
  91. package/lib/server/frames.js +40 -11
  92. package/lib/server/har/harRecorder.js +2 -2
  93. package/lib/server/har/harTracer.js +5 -4
  94. package/lib/server/input.js +49 -4
  95. package/lib/server/instrumentation.js +5 -0
  96. package/lib/server/launchApp.js +0 -1
  97. package/lib/server/localUtils.js +6 -6
  98. package/lib/server/network.js +9 -8
  99. package/lib/server/overlay.js +138 -0
  100. package/lib/server/page.js +111 -51
  101. package/lib/server/progress.js +6 -0
  102. package/lib/server/recorder/recorderApp.js +9 -8
  103. package/lib/server/recorder.js +76 -40
  104. package/lib/server/registry/index.js +54 -81
  105. package/lib/server/registry/nativeDeps.js +1 -0
  106. package/lib/server/screencast.js +90 -143
  107. package/lib/server/trace/recorder/snapshotter.js +2 -2
  108. package/lib/server/trace/recorder/tracing.js +87 -36
  109. package/lib/server/trace/viewer/traceViewer.js +3 -4
  110. package/lib/server/usKeyboardLayout.js +7 -0
  111. package/lib/server/utils/comparators.js +1 -1
  112. package/lib/server/utils/disposable.js +32 -0
  113. package/lib/server/utils/eventsHelper.js +3 -1
  114. package/lib/server/utils/fileUtils.js +16 -2
  115. package/lib/server/utils/happyEyeballs.js +15 -12
  116. package/lib/server/utils/hostPlatform.js +0 -15
  117. package/lib/server/utils/httpServer.js +5 -3
  118. package/lib/server/utils/network.js +2 -1
  119. package/lib/server/utils/nodePlatform.js +0 -6
  120. package/lib/server/utils/processLauncher.js +8 -6
  121. package/lib/server/utils/zipFile.js +2 -2
  122. package/lib/server/videoRecorder.js +82 -12
  123. package/lib/server/webkit/wkBrowser.js +1 -6
  124. package/lib/server/webkit/wkPage.js +27 -25
  125. package/lib/server/webkit/wkWorkers.js +2 -1
  126. package/lib/serverRegistry.js +156 -0
  127. package/lib/tools/backend/browserBackend.js +79 -0
  128. package/lib/tools/backend/common.js +63 -0
  129. package/lib/tools/backend/config.js +41 -0
  130. package/lib/tools/backend/console.js +66 -0
  131. package/lib/tools/backend/context.js +296 -0
  132. package/lib/tools/backend/cookies.js +152 -0
  133. package/lib/tools/backend/devtools.js +69 -0
  134. package/lib/tools/backend/dialogs.js +59 -0
  135. package/lib/tools/backend/evaluate.js +64 -0
  136. package/lib/tools/backend/files.js +60 -0
  137. package/lib/tools/backend/form.js +64 -0
  138. package/lib/tools/backend/keyboard.js +155 -0
  139. package/lib/tools/backend/logFile.js +95 -0
  140. package/lib/tools/backend/mouse.js +168 -0
  141. package/lib/tools/backend/navigate.js +106 -0
  142. package/lib/tools/backend/network.js +135 -0
  143. package/lib/tools/backend/pdf.js +48 -0
  144. package/lib/tools/backend/response.js +305 -0
  145. package/lib/tools/backend/route.js +140 -0
  146. package/lib/tools/backend/runCode.js +77 -0
  147. package/lib/tools/backend/screenshot.js +88 -0
  148. package/lib/tools/backend/sessionLog.js +74 -0
  149. package/lib/tools/backend/snapshot.js +208 -0
  150. package/lib/tools/backend/storage.js +68 -0
  151. package/lib/tools/backend/tab.js +445 -0
  152. package/lib/tools/backend/tabs.js +67 -0
  153. package/lib/tools/backend/tool.js +47 -0
  154. package/lib/tools/backend/tools.js +102 -0
  155. package/lib/tools/backend/tracing.js +78 -0
  156. package/lib/tools/backend/utils.js +83 -0
  157. package/lib/tools/backend/verify.js +151 -0
  158. package/lib/tools/backend/video.js +98 -0
  159. package/lib/tools/backend/wait.js +63 -0
  160. package/lib/tools/backend/webstorage.js +223 -0
  161. package/lib/tools/cli-client/cli.js +6 -0
  162. package/lib/tools/cli-client/help.json +399 -0
  163. package/lib/tools/cli-client/minimist.js +128 -0
  164. package/lib/tools/cli-client/program.js +350 -0
  165. package/lib/tools/cli-client/registry.js +176 -0
  166. package/lib/tools/cli-client/session.js +289 -0
  167. package/lib/tools/cli-client/skill/SKILL.md +328 -0
  168. package/lib/tools/cli-client/skill/references/element-attributes.md +23 -0
  169. package/lib/tools/cli-client/skill/references/playwright-tests.md +39 -0
  170. package/lib/tools/cli-client/skill/references/request-mocking.md +87 -0
  171. package/lib/tools/cli-client/skill/references/running-code.md +231 -0
  172. package/lib/tools/cli-client/skill/references/session-management.md +169 -0
  173. package/lib/tools/cli-client/skill/references/storage-state.md +275 -0
  174. package/lib/tools/cli-client/skill/references/test-generation.md +88 -0
  175. package/lib/tools/cli-client/skill/references/tracing.md +139 -0
  176. package/lib/tools/cli-client/skill/references/video-recording.md +143 -0
  177. package/lib/tools/cli-daemon/command.js +73 -0
  178. package/lib/tools/cli-daemon/commands.js +956 -0
  179. package/lib/tools/cli-daemon/daemon.js +157 -0
  180. package/lib/tools/cli-daemon/helpGenerator.js +177 -0
  181. package/lib/tools/cli-daemon/program.js +129 -0
  182. package/lib/tools/dashboard/appIcon.png +0 -0
  183. package/lib/tools/dashboard/dashboardApp.js +284 -0
  184. package/lib/tools/dashboard/dashboardController.js +296 -0
  185. package/lib/tools/exports.js +60 -0
  186. package/lib/tools/mcp/browserFactory.js +233 -0
  187. package/lib/tools/mcp/cdpRelay.js +352 -0
  188. package/lib/tools/mcp/cli-stub.js +7 -0
  189. package/lib/tools/mcp/config.d.js +16 -0
  190. package/lib/tools/mcp/config.js +446 -0
  191. package/lib/tools/mcp/configIni.js +189 -0
  192. package/lib/tools/mcp/extensionContextFactory.js +55 -0
  193. package/lib/tools/mcp/index.js +62 -0
  194. package/lib/tools/mcp/log.js +35 -0
  195. package/lib/tools/mcp/program.js +107 -0
  196. package/lib/tools/mcp/protocol.js +28 -0
  197. package/lib/tools/mcp/watchdog.js +44 -0
  198. package/lib/tools/trace/SKILL.md +171 -0
  199. package/lib/{server/trace/viewer/traceParser.js → tools/trace/installSkill.js} +15 -39
  200. package/lib/tools/trace/traceActions.js +142 -0
  201. package/lib/tools/trace/traceAttachments.js +69 -0
  202. package/lib/tools/trace/traceCli.js +87 -0
  203. package/lib/tools/trace/traceConsole.js +97 -0
  204. package/lib/tools/trace/traceErrors.js +55 -0
  205. package/lib/tools/trace/traceOpen.js +69 -0
  206. package/lib/tools/trace/traceParser.js +96 -0
  207. package/lib/tools/trace/traceRequests.js +182 -0
  208. package/lib/tools/trace/traceScreenshot.js +68 -0
  209. package/lib/tools/trace/traceSnapshot.js +149 -0
  210. package/lib/tools/trace/traceUtils.js +153 -0
  211. package/lib/tools/utils/connect.js +32 -0
  212. package/lib/tools/utils/mcp/http.js +152 -0
  213. package/lib/tools/utils/mcp/server.js +230 -0
  214. package/lib/tools/utils/mcp/tool.js +47 -0
  215. package/lib/tools/utils/socketConnection.js +108 -0
  216. package/lib/utils/isomorphic/formatUtils.js +64 -0
  217. package/lib/utils/isomorphic/jsonSchema.js +89 -0
  218. package/lib/utils/isomorphic/mimeType.js +7 -2
  219. package/lib/utils/isomorphic/protocolFormatter.js +2 -2
  220. package/lib/utils/isomorphic/protocolMetainfo.js +127 -106
  221. package/lib/utils/isomorphic/stringUtils.js +3 -3
  222. package/lib/utils/isomorphic/timeoutRunner.js +3 -3
  223. package/lib/utils/isomorphic/trace/snapshotRenderer.js +35 -42
  224. package/lib/utils/isomorphic/trace/traceLoader.js +15 -14
  225. package/lib/utils/isomorphic/trace/traceModel.js +3 -2
  226. package/lib/utils/isomorphic/trace/traceModernizer.js +1 -0
  227. package/lib/utils/isomorphic/urlMatch.js +54 -1
  228. package/lib/utils/isomorphic/utilityScriptSerializers.js +11 -0
  229. package/lib/utils.js +6 -2
  230. package/lib/utilsBundle.js +3 -21
  231. package/lib/utilsBundleImpl/index.js +132 -133
  232. package/lib/vite/dashboard/assets/index-BAOybkp8.js +50 -0
  233. package/lib/vite/dashboard/assets/index-CZAYOG76.css +1 -0
  234. package/lib/vite/dashboard/index.html +28 -0
  235. package/lib/vite/htmlReport/index.html +2 -70
  236. package/lib/vite/htmlReport/report.css +1 -0
  237. package/lib/vite/htmlReport/report.js +72 -0
  238. package/lib/vite/recorder/assets/{codeMirrorModule-DadYNm1I.js → codeMirrorModule-C8KMvO9L.js} +20 -20
  239. package/lib/vite/recorder/assets/index-CqAYX1I3.js +193 -0
  240. package/lib/vite/recorder/index.html +1 -1
  241. package/lib/vite/traceViewer/assets/{codeMirrorModule-a5XoALAZ.js → codeMirrorModule-DS0FLvoc.js} +20 -20
  242. package/lib/vite/traceViewer/assets/defaultSettingsView-GTWI-W_B.js +262 -0
  243. package/lib/vite/traceViewer/defaultSettingsView.B4dS75f0.css +1 -0
  244. package/lib/vite/traceViewer/{index.BVu7tZDe.css → index.CzXZzn5A.css} +1 -1
  245. package/lib/vite/traceViewer/{index.BDwrLSGN.js → index.Dtstcb7U.js} +1 -1
  246. package/lib/vite/traceViewer/index.html +4 -4
  247. package/lib/vite/traceViewer/sw.bundle.js +4 -4
  248. package/lib/vite/traceViewer/uiMode.Vipi55dB.js +6 -0
  249. package/lib/vite/traceViewer/uiMode.html +3 -3
  250. package/lib/zipBundleImpl.js +2 -2
  251. package/lib/zodBundle.js +39 -0
  252. package/lib/zodBundleImpl.js +40 -0
  253. package/package.json +6 -1
  254. package/types/protocol.d.ts +947 -51
  255. package/types/types.d.ts +854 -74
  256. package/lib/client/pageAgent.js +0 -64
  257. package/lib/mcpBundleImpl/index.js +0 -147
  258. package/lib/server/agent/actionRunner.js +0 -335
  259. package/lib/server/agent/actions.js +0 -128
  260. package/lib/server/agent/codegen.js +0 -111
  261. package/lib/server/agent/context.js +0 -150
  262. package/lib/server/agent/expectTools.js +0 -156
  263. package/lib/server/agent/pageAgent.js +0 -204
  264. package/lib/server/agent/performTools.js +0 -262
  265. package/lib/server/agent/tool.js +0 -109
  266. package/lib/server/dispatchers/pageAgentDispatcher.js +0 -96
  267. package/lib/vite/recorder/assets/index-BhTWtUlo.js +0 -193
  268. package/lib/vite/traceViewer/assets/defaultSettingsView-CJSZINFr.js +0 -266
  269. package/lib/vite/traceViewer/defaultSettingsView.7ch9cixO.css +0 -1
  270. package/lib/vite/traceViewer/uiMode.CQJ9SCIQ.js +0 -5
  271. /package/lib/{server/utils → utils/isomorphic}/imageUtils.js +0 -0
  272. /package/lib/utils/isomorphic/{traceUtils.js → trace/traceUtils.js} +0 -0
@@ -40,6 +40,7 @@ var frames = __toESM(require("../frames"));
40
40
  var import_helper = require("../helper");
41
41
  var network = __toESM(require("../network"));
42
42
  var import_page = require("../page");
43
+ var import_browserContext = require("../browserContext");
43
44
  var import_crCoverage = require("./crCoverage");
44
45
  var import_crDragDrop = require("./crDragDrop");
45
46
  var import_crExecutionContext = require("./crExecutionContext");
@@ -50,6 +51,7 @@ var import_crProtocolHelper = require("./crProtocolHelper");
50
51
  var import_defaultFontFamilies = require("./defaultFontFamilies");
51
52
  var import_errors = require("../errors");
52
53
  var import_protocolError = require("../protocolError");
54
+ var import_videoRecorder = require("../videoRecorder");
53
55
  class CRPage {
54
56
  constructor(client, targetId, browserContext, opener, bits) {
55
57
  this._sessions = /* @__PURE__ */ new Map();
@@ -201,7 +203,7 @@ class CRPage {
201
203
  await this._mainFrameSession._client.send("Emulation.setDefaultBackgroundColorOverride", { color });
202
204
  }
203
205
  async takeScreenshot(progress, format, documentRect, viewportRect, quality, fitsViewport, scale) {
204
- const { visualViewport } = await progress.race(this._mainFrameSession._client.send("Page.getLayoutMetrics"));
206
+ const { visualViewport, contentSize, cssContentSize } = await progress.race(this._mainFrameSession._client.send("Page.getLayoutMetrics"));
205
207
  if (!documentRect) {
206
208
  documentRect = {
207
209
  x: visualViewport.pageX + viewportRect.x,
@@ -214,7 +216,7 @@ class CRPage {
214
216
  }
215
217
  const clip = { ...documentRect, scale: viewportRect ? visualViewport.scale : 1 };
216
218
  if (scale === "css") {
217
- const deviceScaleFactor = this._browserContext._options.deviceScaleFactor || 1;
219
+ const deviceScaleFactor = this._mainFrameSession._metricsOverride?.deviceScaleFactor || contentSize.width / cssContentSize.width || 1;
218
220
  clip.scale /= deviceScaleFactor;
219
221
  }
220
222
  const result = await progress.race(this._mainFrameSession._client.send("Page.captureScreenshot", { format, quality, clip, captureBeyondViewport: !fitsViewport }));
@@ -232,16 +234,18 @@ class CRPage {
232
234
  async scrollRectIntoViewIfNeeded(handle, rect) {
233
235
  return this._sessionForHandle(handle)._scrollRectIntoViewIfNeeded(handle, rect);
234
236
  }
235
- async startScreencast(options) {
236
- await this._mainFrameSession._client.send("Page.startScreencast", {
237
+ startScreencast(options) {
238
+ this._mainFrameSession._client.send("Page.startScreencast", {
237
239
  format: "jpeg",
238
240
  quality: options.quality,
239
241
  maxWidth: options.width,
240
242
  maxHeight: options.height
243
+ }).catch(() => {
241
244
  });
242
245
  }
243
- async stopScreencast() {
244
- await this._mainFrameSession._client._sendMayFail("Page.stopScreencast");
246
+ stopScreencast() {
247
+ this._mainFrameSession._client._sendMayFail("Page.stopScreencast").catch(() => {
248
+ });
245
249
  }
246
250
  rafCountForStablePosition() {
247
251
  return 1;
@@ -293,6 +297,9 @@ class CRPage {
293
297
  shouldToggleStyleSheetToSyncAnimations() {
294
298
  return false;
295
299
  }
300
+ async setDockTile(image) {
301
+ await this._mainFrameSession._client.send("Browser.setDockTile", { image: image.toString("base64") });
302
+ }
296
303
  }
297
304
  class FrameSession {
298
305
  constructor(crPage, client, targetId, parentSession) {
@@ -357,9 +364,8 @@ class FrameSession {
357
364
  const { windowId } = await this._client.send("Browser.getWindowForTarget");
358
365
  this._windowId = windowId;
359
366
  }
360
- let videoOptions;
361
- if (!this._page.isStorageStatePage && this._isMainFrame() && hasUIWindow)
362
- videoOptions = this._crPage._page.screencast.launchVideoRecorder();
367
+ if (this._isMainFrame() && hasUIWindow && !this._page.isStorageStatePage)
368
+ (0, import_videoRecorder.startAutomaticVideoRecording)(this._crPage._page);
363
369
  let lifecycleEventsEnabled;
364
370
  if (!this._isMainFrame())
365
371
  this._addRendererListeners();
@@ -439,8 +445,6 @@ class FrameSession {
439
445
  true
440
446
  /* runImmediately */
441
447
  ));
442
- if (videoOptions)
443
- promises.push(this._crPage._page.screencast.startVideoRecording(videoOptions));
444
448
  }
445
449
  promises.push(this._client.send("Runtime.runIfWaitingForDebugger"));
446
450
  promises.push(this._firstNonInitialNavigationCommittedPromise);
@@ -607,7 +611,7 @@ class FrameSession {
607
611
  session.on("Target.detachedFromTarget", (event2) => this._onDetachedFromTarget(event2));
608
612
  session.on("Runtime.consoleAPICalled", (event2) => {
609
613
  const args = event2.args.map((o) => (0, import_crExecutionContext.createHandle)(worker.existingExecutionContext, o));
610
- this._page.addConsoleMessage(worker, event2.type, args, (0, import_crProtocolHelper.toConsoleMessageLocation)(event2.stackTrace));
614
+ this._page.addConsoleMessage(worker, event2.type, args, (0, import_crProtocolHelper.toConsoleMessageLocation)(event2.stackTrace), void 0, event2.timestamp);
611
615
  });
612
616
  session.on("Runtime.exceptionThrown", (exception) => this._page.addPageError((0, import_crProtocolHelper.exceptionToError)(exception.exceptionDetails)));
613
617
  }
@@ -642,7 +646,7 @@ class FrameSession {
642
646
  if (!context)
643
647
  return;
644
648
  const values = event.args.map((arg) => (0, import_crExecutionContext.createHandle)(context, arg));
645
- this._page.addConsoleMessage(null, event.type, values, (0, import_crProtocolHelper.toConsoleMessageLocation)(event.stackTrace));
649
+ this._page.addConsoleMessage(null, event.type, values, (0, import_crProtocolHelper.toConsoleMessageLocation)(event.stackTrace), void 0, event.timestamp);
646
650
  }
647
651
  async _onBindingCalled(event) {
648
652
  const pageOrError = await this._crPage._page.waitForInitializedOrError();
@@ -684,7 +688,7 @@ class FrameSession {
684
688
  lineNumber: lineNumber || 0,
685
689
  columnNumber: 0
686
690
  };
687
- this._page.addConsoleMessage(null, level, [], location, text);
691
+ this._page.addConsoleMessage(null, level, [], location, text, event.entry.timestamp);
688
692
  }
689
693
  }
690
694
  async _onFileChooserOpened(event) {
@@ -708,15 +712,14 @@ class FrameSession {
708
712
  }
709
713
  }
710
714
  _onScreencastFrame(payload) {
711
- this._page.screencast.throttleFrameAck(() => {
712
- this._client._sendMayFail("Page.screencastFrameAck", { sessionId: payload.sessionId });
713
- });
714
715
  const buffer = Buffer.from(payload.data, "base64");
715
- this._page.emit(import_page.Page.Events.ScreencastFrame, {
716
+ this._page.screencast.onScreencastFrame({
716
717
  buffer,
717
718
  frameSwapWallTime: payload.metadata.timestamp ? payload.metadata.timestamp * 1e3 : Date.now(),
718
- width: payload.metadata.deviceWidth,
719
- height: payload.metadata.deviceHeight
719
+ viewportWidth: payload.metadata.deviceWidth,
720
+ viewportHeight: payload.metadata.deviceHeight
721
+ }, () => {
722
+ this._client._sendMayFail("Page.screencastFrameAck", { sessionId: payload.sessionId });
720
723
  });
721
724
  }
722
725
  async _updateGeolocation(initial) {
@@ -800,10 +803,12 @@ class FrameSession {
800
803
  }
801
804
  async _updateUserAgent() {
802
805
  const options = this._crPage._browserContext._options;
806
+ const { navigatorPlatform, userAgentMetadata } = (0, import_browserContext.calculateUserAgentEmulation)(options);
803
807
  await this._client.send("Emulation.setUserAgentOverride", {
804
808
  userAgent: options.userAgent || "",
805
809
  acceptLanguage: options.locale,
806
- userAgentMetadata: calculateUserAgentMetadata(options)
810
+ platform: navigatorPlatform,
811
+ userAgentMetadata
807
812
  });
808
813
  }
809
814
  async _setDefaultFontFamilies(session) {
@@ -952,49 +957,6 @@ async function emulateTimezone(session, timezoneId) {
952
957
  throw exception;
953
958
  }
954
959
  }
955
- function calculateUserAgentMetadata(options) {
956
- const ua = options.userAgent;
957
- if (!ua)
958
- return void 0;
959
- const metadata = {
960
- mobile: !!options.isMobile,
961
- model: "",
962
- architecture: "x86",
963
- platform: "Windows",
964
- platformVersion: ""
965
- };
966
- const androidMatch = ua.match(/Android (\d+(\.\d+)?(\.\d+)?)/);
967
- const iPhoneMatch = ua.match(/iPhone OS (\d+(_\d+)?)/);
968
- const iPadMatch = ua.match(/iPad; CPU OS (\d+(_\d+)?)/);
969
- const macOSMatch = ua.match(/Mac OS X (\d+(_\d+)?(_\d+)?)/);
970
- const windowsMatch = ua.match(/Windows\D+(\d+(\.\d+)?(\.\d+)?)/);
971
- if (androidMatch) {
972
- metadata.platform = "Android";
973
- metadata.platformVersion = androidMatch[1];
974
- metadata.architecture = "arm";
975
- } else if (iPhoneMatch) {
976
- metadata.platform = "iOS";
977
- metadata.platformVersion = iPhoneMatch[1];
978
- metadata.architecture = "arm";
979
- } else if (iPadMatch) {
980
- metadata.platform = "iOS";
981
- metadata.platformVersion = iPadMatch[1];
982
- metadata.architecture = "arm";
983
- } else if (macOSMatch) {
984
- metadata.platform = "macOS";
985
- metadata.platformVersion = macOSMatch[1];
986
- if (!ua.includes("Intel"))
987
- metadata.architecture = "arm";
988
- } else if (windowsMatch) {
989
- metadata.platform = "Windows";
990
- metadata.platformVersion = windowsMatch[1];
991
- } else if (ua.toLowerCase().includes("linux")) {
992
- metadata.platform = "Linux";
993
- }
994
- if (ua.includes("ARM"))
995
- metadata.architecture = "arm";
996
- return metadata;
997
- }
998
960
  // Annotate the CommonJS export names for ESM import in node:
999
961
  0 && (module.exports = {
1000
962
  CRPage
@@ -45,13 +45,14 @@ class CRServiceWorker extends import_page.Worker {
45
45
  this.browserContext = browserContext;
46
46
  if (!process.env.PLAYWRIGHT_DISABLE_SERVICE_WORKER_NETWORK)
47
47
  this._networkManager = new import_crNetworkManager.CRNetworkManager(null, this);
48
- session.once("Runtime.executionContextCreated", (event) => {
48
+ session.on("Inspector.targetCrashed", () => this._prepareContextForRestart());
49
+ session.on("Runtime.executionContextCreated", (event) => {
49
50
  this.createExecutionContext(new import_crExecutionContext.CRExecutionContext(session, event.context));
51
+ if (this.browserContext._browser.majorVersion() < 143)
52
+ this.workerScriptLoaded();
50
53
  });
51
54
  if (this.browserContext._browser.majorVersion() >= 143)
52
55
  session.on("Inspector.workerScriptLoaded", () => this.workerScriptLoaded());
53
- else
54
- this.workerScriptLoaded();
55
56
  if (this._networkManager && this._isNetworkInspectionEnabled()) {
56
57
  this.updateRequestInterception();
57
58
  this.updateExtraHTTPHeaders();
@@ -69,7 +70,7 @@ class CRServiceWorker extends import_page.Worker {
69
70
  if (!this.existingExecutionContext || process.env.PLAYWRIGHT_DISABLE_SERVICE_WORKER_CONSOLE)
70
71
  return;
71
72
  const args = event.args.map((o) => (0, import_crExecutionContext.createHandle)(this.existingExecutionContext, o));
72
- const message = new import_console.ConsoleMessage(null, this, event.type, void 0, args, (0, import_crProtocolHelper.toConsoleMessageLocation)(event.stackTrace));
73
+ const message = new import_console.ConsoleMessage(null, this, event.type, void 0, args, (0, import_crProtocolHelper.toConsoleMessageLocation)(event.stackTrace), event.timestamp);
73
74
  this.browserContext.emit(import_browserContext.BrowserContext.Events.Console, message);
74
75
  });
75
76
  session.send("Runtime.enable", {}).catch((e) => {
@@ -38,71 +38,71 @@ class Clock {
38
38
  this._browserContext = browserContext;
39
39
  }
40
40
  async uninstall(progress) {
41
- await progress.race(this._browserContext.removeInitScripts(this._initScripts));
41
+ await progress.race(Promise.all(this._initScripts.map((script) => script.dispose())));
42
42
  this._initScripts = [];
43
43
  }
44
- async fastForward(progress, ticks) {
45
- await this._installIfNeeded(progress);
44
+ async fastForward(ticks) {
45
+ await this._installIfNeeded();
46
46
  const ticksMillis = parseTicks(ticks);
47
- this._initScripts.push(await this._browserContext.addInitScript(progress, `globalThis.__pwClock.controller.log('fastForward', ${Date.now()}, ${ticksMillis})`));
48
- await progress.race(this._evaluateInFrames(`globalThis.__pwClock.controller.fastForward(${ticksMillis})`));
47
+ this._initScripts.push(await this._browserContext.addInitScript(`globalThis.__pwClock.controller.log('fastForward', ${Date.now()}, ${ticksMillis})`));
48
+ await this._evaluateInFrames(`globalThis.__pwClock.controller.fastForward(${ticksMillis})`);
49
49
  }
50
- async install(progress, time) {
51
- await this._installIfNeeded(progress);
50
+ async install(time) {
51
+ await this._installIfNeeded();
52
52
  const timeMillis = time !== void 0 ? parseTime(time) : Date.now();
53
- this._initScripts.push(await this._browserContext.addInitScript(progress, `globalThis.__pwClock.controller.log('install', ${Date.now()}, ${timeMillis})`));
54
- await progress.race(this._evaluateInFrames(`globalThis.__pwClock.controller.install(${timeMillis})`));
53
+ this._initScripts.push(await this._browserContext.addInitScript(`globalThis.__pwClock.controller.log('install', ${Date.now()}, ${timeMillis})`));
54
+ await this._evaluateInFrames(`globalThis.__pwClock.controller.install(${timeMillis})`);
55
55
  }
56
- async pauseAt(progress, ticks) {
57
- await this._installIfNeeded(progress);
56
+ async pauseAt(ticks) {
57
+ await this._installIfNeeded();
58
58
  const timeMillis = parseTime(ticks);
59
- this._initScripts.push(await this._browserContext.addInitScript(progress, `globalThis.__pwClock.controller.log('pauseAt', ${Date.now()}, ${timeMillis})`));
60
- await progress.race(this._evaluateInFrames(`globalThis.__pwClock.controller.pauseAt(${timeMillis})`));
59
+ this._initScripts.push(await this._browserContext.addInitScript(`globalThis.__pwClock.controller.log('pauseAt', ${Date.now()}, ${timeMillis})`));
60
+ await this._evaluateInFrames(`globalThis.__pwClock.controller.pauseAt(${timeMillis})`);
61
61
  }
62
62
  resumeNoReply() {
63
63
  if (!this._initScripts.length)
64
64
  return;
65
65
  const doResume = async () => {
66
- this._initScripts.push(await this._browserContext.addInitScript(void 0, `globalThis.__pwClock.controller.log('resume', ${Date.now()})`));
66
+ this._initScripts.push(await this._browserContext.addInitScript(`globalThis.__pwClock.controller.log('resume', ${Date.now()})`));
67
67
  await this._evaluateInFrames(`globalThis.__pwClock.controller.resume()`);
68
68
  };
69
69
  doResume().catch(() => {
70
70
  });
71
71
  }
72
72
  async resume(progress) {
73
- await this._installIfNeeded(progress);
74
- this._initScripts.push(await this._browserContext.addInitScript(progress, `globalThis.__pwClock.controller.log('resume', ${Date.now()})`));
75
- await progress.race(this._evaluateInFrames(`globalThis.__pwClock.controller.resume()`));
73
+ await this._installIfNeeded();
74
+ this._initScripts.push(await this._browserContext.addInitScript(`globalThis.__pwClock.controller.log('resume', ${Date.now()})`));
75
+ await this._evaluateInFrames(`globalThis.__pwClock.controller.resume()`);
76
76
  }
77
- async setFixedTime(progress, time) {
78
- await this._installIfNeeded(progress);
77
+ async setFixedTime(time) {
78
+ await this._installIfNeeded();
79
79
  const timeMillis = parseTime(time);
80
- this._initScripts.push(await this._browserContext.addInitScript(progress, `globalThis.__pwClock.controller.log('setFixedTime', ${Date.now()}, ${timeMillis})`));
81
- await progress.race(this._evaluateInFrames(`globalThis.__pwClock.controller.setFixedTime(${timeMillis})`));
80
+ this._initScripts.push(await this._browserContext.addInitScript(`globalThis.__pwClock.controller.log('setFixedTime', ${Date.now()}, ${timeMillis})`));
81
+ await this._evaluateInFrames(`globalThis.__pwClock.controller.setFixedTime(${timeMillis})`);
82
82
  }
83
- async setSystemTime(progress, time) {
84
- await this._installIfNeeded(progress);
83
+ async setSystemTime(time) {
84
+ await this._installIfNeeded();
85
85
  const timeMillis = parseTime(time);
86
- this._initScripts.push(await this._browserContext.addInitScript(progress, `globalThis.__pwClock.controller.log('setSystemTime', ${Date.now()}, ${timeMillis})`));
87
- await progress.race(this._evaluateInFrames(`globalThis.__pwClock.controller.setSystemTime(${timeMillis})`));
86
+ this._initScripts.push(await this._browserContext.addInitScript(`globalThis.__pwClock.controller.log('setSystemTime', ${Date.now()}, ${timeMillis})`));
87
+ await this._evaluateInFrames(`globalThis.__pwClock.controller.setSystemTime(${timeMillis})`);
88
88
  }
89
- async runFor(progress, ticks) {
90
- await this._installIfNeeded(progress);
89
+ async runFor(ticks) {
90
+ await this._installIfNeeded();
91
91
  const ticksMillis = parseTicks(ticks);
92
- this._initScripts.push(await this._browserContext.addInitScript(progress, `globalThis.__pwClock.controller.log('runFor', ${Date.now()}, ${ticksMillis})`));
93
- await progress.race(this._evaluateInFrames(`globalThis.__pwClock.controller.runFor(${ticksMillis})`));
92
+ this._initScripts.push(await this._browserContext.addInitScript(`globalThis.__pwClock.controller.log('runFor', ${Date.now()}, ${ticksMillis})`));
93
+ await this._evaluateInFrames(`globalThis.__pwClock.controller.runFor(${ticksMillis})`);
94
94
  }
95
- async _installIfNeeded(progress) {
95
+ async _installIfNeeded() {
96
96
  if (this._initScripts.length)
97
97
  return;
98
98
  const script = `(() => {
99
99
  const module = {};
100
100
  ${rawClockSource.source}
101
101
  if (!globalThis.__pwClock)
102
- globalThis.__pwClock = (module.exports.inject())(globalThis);
102
+ globalThis.__pwClock = (module.exports.inject())(globalThis, ${JSON.stringify(this._browserContext._browser.options.name)});
103
103
  })();`;
104
- const initScript = await this._browserContext.addInitScript(progress, script);
105
- await progress.race(this._evaluateInFrames(script));
104
+ const initScript = await this._browserContext.addInitScript(script);
105
+ await this._evaluateInFrames(script);
106
106
  this._initScripts.push(initScript);
107
107
  }
108
108
  async _evaluateInFrames(script) {
@@ -22,13 +22,14 @@ __export(console_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(console_exports);
24
24
  class ConsoleMessage {
25
- constructor(page, worker, type, text, args, location) {
25
+ constructor(page, worker, type, text, args, location, timestamp) {
26
26
  this._page = page;
27
27
  this._worker = worker;
28
28
  this._type = type;
29
29
  this._text = text;
30
30
  this._args = args;
31
31
  this._location = location || { url: "", lineNumber: 0, columnNumber: 0 };
32
+ this._timestamp = timestamp;
32
33
  }
33
34
  page() {
34
35
  return this._page;
@@ -50,6 +51,9 @@ class ConsoleMessage {
50
51
  location() {
51
52
  return this._location;
52
53
  }
54
+ timestamp() {
55
+ return this._timestamp;
56
+ }
53
57
  }
54
58
  // Annotate the CommonJS export names for ESM import in node:
55
59
  0 && (module.exports = {
@@ -70,10 +70,12 @@ class DebugController extends import_instrumentation.SdkObject {
70
70
  await progress.race(this._closeBrowsersWithoutPages());
71
71
  this._generateAutoExpect = !!params.generateAutoExpect;
72
72
  if (params.mode === "none") {
73
+ const promises = [];
73
74
  for (const recorder of await progress.race(this._allRecorders())) {
74
- recorder.hideHighlightedSelector();
75
- recorder.setMode("none");
75
+ promises.push(recorder.hideHighlightedSelector());
76
+ promises.push(recorder.setMode("none"));
76
77
  }
78
+ await Promise.all(promises);
77
79
  return;
78
80
  }
79
81
  if (!this._playwright.allBrowsers().length)
@@ -97,18 +99,22 @@ class DebugController extends import_instrumentation.SdkObject {
97
99
  if (params.selector)
98
100
  (0, import_locatorParser.unsafeLocatorOrSelectorAsSelector)(this._sdkLanguage, params.selector, "data-testid");
99
101
  const ariaTemplate = params.ariaTemplate ? (0, import_ariaSnapshot.parseAriaSnapshotUnsafe)(import_utilsBundle.yaml, params.ariaTemplate) : void 0;
102
+ const promises = [];
100
103
  for (const recorder of await progress.race(this._allRecorders())) {
101
104
  if (ariaTemplate)
102
- recorder.setHighlightedAriaTemplate(ariaTemplate);
105
+ promises.push(recorder.setHighlightedAriaTemplate(ariaTemplate));
103
106
  else if (params.selector)
104
- recorder.setHighlightedSelector(params.selector);
107
+ promises.push(recorder.setHighlightedSelector(params.selector));
105
108
  }
109
+ await Promise.all(promises);
106
110
  }
107
111
  async hideHighlight(progress) {
112
+ const promises = [];
108
113
  for (const recorder of await progress.race(this._allRecorders()))
109
- recorder.hideHighlightedSelector();
110
- await Promise.all(this._playwright.allPages().map((p) => p.hideHighlight().catch(() => {
114
+ promises.push(recorder.hideHighlightedSelector());
115
+ promises.push(...this._playwright.allPages().map((p) => p.hideHighlight().catch(() => {
111
116
  })));
117
+ await Promise.all(promises);
112
118
  }
113
119
  async resume(progress) {
114
120
  for (const recorder of await progress.race(this._allRecorders()))
@@ -21,22 +21,20 @@ __export(debugger_exports, {
21
21
  Debugger: () => Debugger
22
22
  });
23
23
  module.exports = __toCommonJS(debugger_exports);
24
- var import_events = require("events");
24
+ var import_instrumentation = require("./instrumentation");
25
25
  var import_utils = require("../utils");
26
26
  var import_browserContext = require("./browserContext");
27
27
  var import_protocolMetainfo = require("../utils/isomorphic/protocolMetainfo");
28
28
  const symbol = Symbol("Debugger");
29
- class Debugger extends import_events.EventEmitter {
29
+ class Debugger extends import_instrumentation.SdkObject {
30
30
  constructor(context) {
31
- super();
32
- this._pauseOnNextStatement = false;
33
- this._pausedCallsMetadata = /* @__PURE__ */ new Map();
31
+ super(context, "debugger");
32
+ this._pauseAt = {};
33
+ this._enabled = false;
34
+ this._pauseBeforeWaitingActions = false;
34
35
  this._muted = false;
35
36
  this._context = context;
36
37
  this._context[symbol] = this;
37
- this._enabled = (0, import_utils.debugMode)() === "inspector";
38
- if (this._enabled)
39
- this.pauseOnNextStatement();
40
38
  context.instrumentation.addListener(this, context);
41
39
  this._context.once(import_browserContext.BrowserContext.Events.Close, () => {
42
40
  this._context.instrumentation.removeListener(this);
@@ -51,67 +49,62 @@ class Debugger extends import_events.EventEmitter {
51
49
  this._muted = muted;
52
50
  }
53
51
  async onBeforeCall(sdkObject, metadata) {
54
- if (this._muted)
52
+ if (this._muted || metadata.internal)
55
53
  return;
56
- if (shouldPauseOnCall(sdkObject, metadata) || this._pauseOnNextStatement && shouldPauseBeforeStep(metadata))
57
- await this.pause(sdkObject, metadata);
54
+ const metainfo = (0, import_protocolMetainfo.getMetainfo)(metadata);
55
+ const pauseOnPauseCall = this._enabled && metadata.type === "BrowserContext" && metadata.method === "pause";
56
+ const pauseBeforeAction = !!this._pauseAt.next && !!metainfo?.pause && (this._pauseBeforeWaitingActions || !metainfo?.isAutoWaiting);
57
+ const pauseOnLocation = !!this._pauseAt.location && matchesLocation(metadata, this._pauseAt.location);
58
+ if (pauseOnPauseCall || pauseBeforeAction || pauseOnLocation)
59
+ await this._pause(sdkObject, metadata);
58
60
  }
59
61
  async onBeforeInputAction(sdkObject, metadata) {
60
- if (this._muted)
62
+ if (this._muted || metadata.internal)
61
63
  return;
62
- if (this._enabled && this._pauseOnNextStatement)
63
- await this.pause(sdkObject, metadata);
64
+ const metainfo = (0, import_protocolMetainfo.getMetainfo)(metadata);
65
+ const pauseBeforeInput = !!this._pauseAt.next && !!metainfo?.pause && !!metainfo?.isAutoWaiting && !this._pauseBeforeWaitingActions;
66
+ if (pauseBeforeInput)
67
+ await this._pause(sdkObject, metadata);
64
68
  }
65
- async pause(sdkObject, metadata) {
66
- if (this._muted)
69
+ async _pause(sdkObject, metadata) {
70
+ if (this._muted || metadata.internal)
67
71
  return;
68
- this._enabled = true;
72
+ if (this._pausedCall)
73
+ return;
74
+ this._pauseAt = {};
69
75
  metadata.pauseStartTime = (0, import_utils.monotonicTime)();
70
76
  const result = new Promise((resolve) => {
71
- this._pausedCallsMetadata.set(metadata, { resolve, sdkObject });
77
+ this._pausedCall = { metadata, sdkObject, resolve };
72
78
  });
73
79
  this.emit(Debugger.Events.PausedStateChanged);
74
80
  return result;
75
81
  }
76
- resume(step) {
77
- if (!this.isPaused())
82
+ resume() {
83
+ if (!this._pausedCall)
78
84
  return;
79
- this._pauseOnNextStatement = step;
80
- const endTime = (0, import_utils.monotonicTime)();
81
- for (const [metadata, { resolve }] of this._pausedCallsMetadata) {
82
- metadata.pauseEndTime = endTime;
83
- resolve();
84
- }
85
- this._pausedCallsMetadata.clear();
85
+ this._pausedCall.metadata.pauseEndTime = (0, import_utils.monotonicTime)();
86
+ this._pausedCall.resolve();
87
+ this._pausedCall = void 0;
86
88
  this.emit(Debugger.Events.PausedStateChanged);
87
89
  }
88
- pauseOnNextStatement() {
89
- this._pauseOnNextStatement = true;
90
+ setPauseBeforeWaitingActions() {
91
+ this._pauseBeforeWaitingActions = true;
92
+ }
93
+ setPauseAt(at = {}) {
94
+ this._enabled = true;
95
+ this._pauseAt = at;
90
96
  }
91
97
  isPaused(metadata) {
92
98
  if (metadata)
93
- return this._pausedCallsMetadata.has(metadata);
94
- return !!this._pausedCallsMetadata.size;
99
+ return this._pausedCall?.metadata === metadata;
100
+ return !!this._pausedCall;
95
101
  }
96
102
  pausedDetails() {
97
- const result = [];
98
- for (const [metadata, { sdkObject }] of this._pausedCallsMetadata)
99
- result.push({ metadata, sdkObject });
100
- return result;
103
+ return this._pausedCall;
101
104
  }
102
105
  }
103
- function shouldPauseOnCall(sdkObject, metadata) {
104
- if (sdkObject.attribution.playwright.options.isServer)
105
- return false;
106
- if (!sdkObject.attribution.browser?.options.headful && !(0, import_utils.isUnderTest)())
107
- return false;
108
- return metadata.method === "pause";
109
- }
110
- function shouldPauseBeforeStep(metadata) {
111
- if (metadata.internal)
112
- return false;
113
- const metainfo = import_protocolMetainfo.methodMetainfo.get(metadata.type + "." + metadata.method);
114
- return !!metainfo?.pausesBeforeAction;
106
+ function matchesLocation(metadata, location) {
107
+ return !!metadata.location?.file.includes(location.file) && (location.line === void 0 || metadata.location.line === location.line) && (location.column === void 0 || metadata.location.column === location.column);
115
108
  }
116
109
  // Annotate the CommonJS export names for ESM import in node:
117
110
  0 && (module.exports = {