patchright-bun-core 1.58.0 → 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 (475) hide show
  1. package/README.md +2 -2
  2. package/ThirdPartyNotices.txt +3551 -4075
  3. package/bin/install_media_pack.ps1 +5 -5
  4. package/bin/install_webkit_wsl.ps1 +32 -32
  5. package/bin/reinstall_chrome_beta_linux.sh +42 -42
  6. package/bin/reinstall_chrome_beta_mac.sh +13 -13
  7. package/bin/reinstall_chrome_beta_win.ps1 +24 -24
  8. package/bin/reinstall_chrome_stable_linux.sh +42 -42
  9. package/bin/reinstall_chrome_stable_mac.sh +12 -12
  10. package/bin/reinstall_chrome_stable_win.ps1 +24 -24
  11. package/bin/reinstall_msedge_beta_linux.sh +48 -48
  12. package/bin/reinstall_msedge_beta_mac.sh +11 -11
  13. package/bin/reinstall_msedge_beta_win.ps1 +23 -23
  14. package/bin/reinstall_msedge_dev_linux.sh +48 -48
  15. package/bin/reinstall_msedge_dev_mac.sh +11 -11
  16. package/bin/reinstall_msedge_dev_win.ps1 +23 -23
  17. package/bin/reinstall_msedge_stable_linux.sh +48 -48
  18. package/bin/reinstall_msedge_stable_mac.sh +11 -11
  19. package/bin/reinstall_msedge_stable_win.ps1 +23 -23
  20. package/browsers.json +81 -79
  21. package/cli.js +18 -18
  22. package/index.d.ts +17 -17
  23. package/index.js +32 -32
  24. package/index.mjs +28 -28
  25. package/lib/androidServerImpl.js +65 -65
  26. package/lib/bootstrap.js +77 -0
  27. package/lib/browserServerImpl.js +120 -120
  28. package/lib/cli/browserActions.js +308 -0
  29. package/lib/cli/driver.js +98 -97
  30. package/lib/cli/installActions.js +171 -0
  31. package/lib/cli/program.js +225 -589
  32. package/lib/cli/programWithTestStub.js +74 -74
  33. package/lib/client/android.js +361 -361
  34. package/lib/client/api.js +137 -137
  35. package/lib/client/artifact.js +79 -79
  36. package/lib/client/browser.js +169 -161
  37. package/lib/client/browserContext.js +563 -582
  38. package/lib/client/browserType.js +153 -185
  39. package/lib/client/cdpSession.js +55 -51
  40. package/lib/client/channelOwner.js +194 -194
  41. package/lib/client/clientHelper.js +64 -64
  42. package/lib/client/clientInstrumentation.js +55 -55
  43. package/lib/client/clientStackTrace.js +69 -69
  44. package/lib/client/clock.js +68 -68
  45. package/lib/client/{webSocket.js → connect.js} +143 -93
  46. package/lib/client/connection.js +322 -318
  47. package/lib/client/consoleMessage.js +61 -58
  48. package/lib/client/coverage.js +44 -44
  49. package/lib/client/debugger.js +57 -0
  50. package/lib/client/dialog.js +63 -56
  51. package/lib/client/disposable.js +76 -0
  52. package/lib/client/download.js +62 -62
  53. package/lib/client/electron.js +139 -138
  54. package/lib/client/elementHandle.js +281 -284
  55. package/lib/client/errors.js +77 -77
  56. package/lib/client/eventEmitter.js +314 -314
  57. package/lib/client/events.js +103 -103
  58. package/lib/client/fetch.js +367 -368
  59. package/lib/client/fileChooser.js +46 -46
  60. package/lib/client/fileUtils.js +34 -34
  61. package/lib/client/frame.js +404 -409
  62. package/lib/client/harRouter.js +99 -87
  63. package/lib/client/input.js +84 -84
  64. package/lib/client/jsHandle.js +105 -109
  65. package/lib/client/jsonPipe.js +39 -39
  66. package/lib/client/localUtils.js +60 -60
  67. package/lib/client/locator.js +367 -369
  68. package/lib/client/network.js +750 -747
  69. package/lib/client/page.js +731 -745
  70. package/lib/client/platform.js +74 -77
  71. package/lib/client/playwright.js +71 -71
  72. package/lib/client/screencast.js +88 -0
  73. package/lib/client/selectors.js +57 -55
  74. package/lib/client/stream.js +39 -39
  75. package/lib/client/timeoutSettings.js +79 -79
  76. package/lib/client/tracing.js +126 -119
  77. package/lib/client/types.js +28 -28
  78. package/lib/client/video.js +52 -59
  79. package/lib/client/waiter.js +142 -142
  80. package/lib/client/webError.js +39 -39
  81. package/lib/client/worker.js +85 -85
  82. package/lib/client/writableStream.js +39 -39
  83. package/lib/generated/bindingsControllerSource.js +28 -28
  84. package/lib/generated/clockSource.js +28 -28
  85. package/lib/generated/injectedScriptSource.js +28 -28
  86. package/lib/generated/pollingRecorderSource.js +28 -28
  87. package/lib/generated/storageScriptSource.js +28 -28
  88. package/lib/generated/utilityScriptSource.js +28 -28
  89. package/lib/generated/webSocketMockSource.js +336 -336
  90. package/lib/inProcessFactory.js +60 -60
  91. package/lib/inprocess.js +3 -3
  92. package/lib/mcpBundle.js +78 -84
  93. package/lib/mcpBundleImpl.js +91 -0
  94. package/lib/outofprocess.js +76 -76
  95. package/lib/protocol/serializers.js +197 -197
  96. package/lib/protocol/validator.js +3067 -2969
  97. package/lib/protocol/validatorPrimitives.js +193 -193
  98. package/lib/remote/playwrightConnection.js +131 -129
  99. package/lib/remote/playwrightPipeServer.js +100 -0
  100. package/lib/remote/playwrightServer.js +339 -334
  101. package/lib/remote/playwrightWebSocketServer.js +73 -0
  102. package/lib/remote/serverTransport.js +96 -0
  103. package/lib/server/android/android.js +465 -465
  104. package/lib/server/android/backendAdb.js +177 -177
  105. package/lib/server/artifact.js +127 -127
  106. package/lib/server/bidi/bidiBrowser.js +571 -549
  107. package/lib/server/bidi/bidiChromium.js +162 -148
  108. package/lib/server/bidi/bidiConnection.js +213 -213
  109. package/lib/server/bidi/bidiDeserializer.js +116 -116
  110. package/lib/server/bidi/bidiExecutionContext.js +267 -267
  111. package/lib/server/bidi/bidiFirefox.js +128 -128
  112. package/lib/server/bidi/bidiInput.js +146 -146
  113. package/lib/server/bidi/bidiNetworkManager.js +411 -383
  114. package/lib/server/bidi/bidiOverCdp.js +102 -102
  115. package/lib/server/bidi/bidiPage.js +599 -583
  116. package/lib/server/bidi/bidiPdf.js +106 -106
  117. package/lib/server/bidi/third_party/bidiCommands.d.js +22 -22
  118. package/lib/server/bidi/third_party/bidiKeyboard.js +256 -256
  119. package/lib/server/bidi/third_party/bidiProtocol.js +24 -24
  120. package/lib/server/bidi/third_party/bidiProtocolCore.js +180 -180
  121. package/lib/server/bidi/third_party/bidiProtocolPermissions.js +42 -42
  122. package/lib/server/bidi/third_party/bidiSerializer.js +148 -148
  123. package/lib/server/bidi/third_party/firefoxPrefs.js +261 -259
  124. package/lib/server/browser.js +212 -149
  125. package/lib/server/browserContext.js +741 -702
  126. package/lib/server/browserType.js +338 -336
  127. package/lib/server/callLog.js +82 -82
  128. package/lib/server/chromium/chromium.js +399 -395
  129. package/lib/server/chromium/chromiumSwitches.js +104 -104
  130. package/lib/server/chromium/crBrowser.js +528 -511
  131. package/lib/server/chromium/crConnection.js +197 -197
  132. package/lib/server/chromium/crCoverage.js +235 -235
  133. package/lib/server/chromium/crDevTools.js +111 -111
  134. package/lib/server/chromium/crDragDrop.js +131 -131
  135. package/lib/server/chromium/crExecutionContext.js +146 -146
  136. package/lib/server/chromium/crInput.js +187 -187
  137. package/lib/server/chromium/crNetworkManager.js +707 -707
  138. package/lib/server/chromium/crPage.js +963 -1001
  139. package/lib/server/chromium/crPdf.js +121 -121
  140. package/lib/server/chromium/crProtocolHelper.js +145 -145
  141. package/lib/server/chromium/crServiceWorker.js +137 -136
  142. package/lib/server/chromium/defaultFontFamilies.js +162 -162
  143. package/lib/server/chromium/protocol.d.js +16 -16
  144. package/lib/server/clock.js +149 -149
  145. package/lib/server/codegen/csharp.js +327 -327
  146. package/lib/server/codegen/java.js +274 -274
  147. package/lib/server/codegen/javascript.js +247 -247
  148. package/lib/server/codegen/jsonl.js +52 -52
  149. package/lib/server/codegen/language.js +132 -132
  150. package/lib/server/codegen/languages.js +68 -68
  151. package/lib/server/codegen/python.js +279 -279
  152. package/lib/server/codegen/types.js +16 -16
  153. package/lib/server/console.js +61 -57
  154. package/lib/server/cookieStore.js +206 -206
  155. package/lib/server/debugController.js +197 -191
  156. package/lib/server/debugger.js +112 -119
  157. package/lib/server/deviceDescriptors.js +39 -39
  158. package/lib/server/deviceDescriptorsSource.json +1778 -1778
  159. package/lib/server/dialog.js +116 -116
  160. package/lib/server/dispatchers/androidDispatcher.js +325 -325
  161. package/lib/server/dispatchers/artifactDispatcher.js +118 -118
  162. package/lib/server/dispatchers/browserContextDispatcher.js +381 -384
  163. package/lib/server/dispatchers/browserDispatcher.js +124 -118
  164. package/lib/server/dispatchers/browserTypeDispatcher.js +71 -64
  165. package/lib/server/dispatchers/cdpSessionDispatcher.js +47 -44
  166. package/lib/server/dispatchers/debugControllerDispatcher.js +78 -78
  167. package/lib/server/dispatchers/debuggerDispatcher.js +84 -0
  168. package/lib/server/dispatchers/dialogDispatcher.js +47 -47
  169. package/lib/server/dispatchers/dispatcher.js +364 -364
  170. package/lib/server/dispatchers/disposableDispatcher.js +39 -0
  171. package/lib/server/dispatchers/electronDispatcher.js +90 -89
  172. package/lib/server/dispatchers/elementHandlerDispatcher.js +181 -181
  173. package/lib/server/dispatchers/frameDispatcher.js +227 -227
  174. package/lib/server/dispatchers/jsHandleDispatcher.js +85 -85
  175. package/lib/server/dispatchers/jsonPipeDispatcher.js +58 -58
  176. package/lib/server/dispatchers/localUtilsDispatcher.js +185 -149
  177. package/lib/server/dispatchers/networkDispatchers.js +214 -213
  178. package/lib/server/dispatchers/pageDispatcher.js +456 -393
  179. package/lib/server/dispatchers/playwrightDispatcher.js +108 -108
  180. package/lib/server/dispatchers/streamDispatcher.js +67 -67
  181. package/lib/server/dispatchers/tracingDispatcher.js +68 -68
  182. package/lib/server/dispatchers/webSocketRouteDispatcher.js +164 -165
  183. package/lib/server/dispatchers/writableStreamDispatcher.js +79 -79
  184. package/lib/server/disposable.js +41 -0
  185. package/lib/server/dom.js +833 -815
  186. package/lib/server/download.js +71 -70
  187. package/lib/server/electron/electron.js +278 -273
  188. package/lib/server/electron/loader.js +29 -29
  189. package/lib/server/errors.js +69 -69
  190. package/lib/server/fetch.js +621 -621
  191. package/lib/server/fileChooser.js +43 -43
  192. package/lib/server/fileUploadUtils.js +84 -84
  193. package/lib/server/firefox/ffBrowser.js +408 -418
  194. package/lib/server/firefox/ffConnection.js +142 -142
  195. package/lib/server/firefox/ffExecutionContext.js +150 -150
  196. package/lib/server/firefox/ffInput.js +175 -159
  197. package/lib/server/firefox/ffNetworkManager.js +256 -256
  198. package/lib/server/firefox/ffPage.js +494 -497
  199. package/lib/server/firefox/firefox.js +114 -114
  200. package/lib/server/firefox/protocol.d.js +16 -16
  201. package/lib/server/formData.js +147 -147
  202. package/lib/server/frameSelectors.js +160 -160
  203. package/lib/server/frames.js +1500 -1471
  204. package/lib/server/har/harRecorder.js +147 -147
  205. package/lib/server/har/harTracer.js +608 -607
  206. package/lib/server/harBackend.js +157 -157
  207. package/lib/server/helper.js +96 -96
  208. package/lib/server/index.js +58 -58
  209. package/lib/server/input.js +322 -277
  210. package/lib/server/instrumentation.js +77 -72
  211. package/lib/server/javascript.js +291 -291
  212. package/lib/server/launchApp.js +127 -128
  213. package/lib/server/localUtils.js +214 -214
  214. package/lib/server/macEditingCommands.js +143 -143
  215. package/lib/server/network.js +668 -667
  216. package/lib/server/overlay.js +138 -0
  217. package/lib/server/page.js +890 -830
  218. package/lib/server/pipeTransport.js +89 -89
  219. package/lib/server/playwright.js +69 -69
  220. package/lib/server/progress.js +138 -132
  221. package/lib/server/protocolError.js +52 -52
  222. package/lib/server/recorder/chat.js +161 -161
  223. package/lib/server/recorder/recorderApp.js +367 -366
  224. package/lib/server/recorder/recorderRunner.js +138 -138
  225. package/lib/server/recorder/recorderSignalProcessor.js +83 -83
  226. package/lib/server/recorder/recorderUtils.js +157 -157
  227. package/lib/server/recorder/throttledFile.js +57 -57
  228. package/lib/server/recorder.js +535 -499
  229. package/lib/server/registry/browserFetcher.js +177 -177
  230. package/lib/server/registry/dependencies.js +371 -371
  231. package/lib/server/registry/index.js +1395 -1422
  232. package/lib/server/registry/nativeDeps.js +1281 -1280
  233. package/lib/server/registry/oopDownloadBrowserMain.js +127 -127
  234. package/lib/server/screencast.js +137 -190
  235. package/lib/server/screenshotter.js +333 -333
  236. package/lib/server/selectors.js +112 -112
  237. package/lib/server/socksClientCertificatesInterceptor.js +383 -383
  238. package/lib/server/socksInterceptor.js +95 -95
  239. package/lib/server/trace/recorder/snapshotter.js +147 -147
  240. package/lib/server/trace/recorder/snapshotterInjected.js +561 -561
  241. package/lib/server/trace/recorder/tracing.js +655 -604
  242. package/lib/server/trace/viewer/traceViewer.js +244 -245
  243. package/lib/server/transport.js +254 -254
  244. package/lib/server/types.js +28 -28
  245. package/lib/server/usKeyboardLayout.js +152 -145
  246. package/lib/server/utils/ascii.js +44 -44
  247. package/lib/server/utils/comparators.js +139 -139
  248. package/lib/server/utils/crypto.js +216 -216
  249. package/lib/server/utils/debug.js +42 -42
  250. package/lib/server/utils/debugLogger.js +122 -122
  251. package/lib/server/utils/disposable.js +32 -0
  252. package/lib/server/utils/env.js +73 -73
  253. package/lib/server/utils/eventsHelper.js +41 -39
  254. package/lib/server/utils/expectUtils.js +123 -123
  255. package/lib/server/utils/fileUtils.js +205 -191
  256. package/lib/server/utils/happyEyeballs.js +210 -207
  257. package/lib/server/utils/hostPlatform.js +123 -123
  258. package/lib/server/utils/httpServer.js +205 -203
  259. package/lib/server/utils/image_tools/colorUtils.js +89 -89
  260. package/lib/server/utils/image_tools/compare.js +109 -109
  261. package/lib/server/utils/image_tools/imageChannel.js +78 -78
  262. package/lib/server/utils/image_tools/stats.js +102 -102
  263. package/lib/server/utils/linuxUtils.js +71 -71
  264. package/lib/server/utils/network.js +243 -242
  265. package/lib/server/utils/nodePlatform.js +148 -154
  266. package/lib/server/utils/pipeTransport.js +84 -84
  267. package/lib/server/utils/processLauncher.js +243 -241
  268. package/lib/server/utils/profiler.js +65 -65
  269. package/lib/server/utils/socksProxy.js +511 -511
  270. package/lib/server/utils/spawnAsync.js +41 -41
  271. package/lib/server/utils/task.js +51 -51
  272. package/lib/server/utils/userAgent.js +98 -98
  273. package/lib/server/utils/wsServer.js +121 -121
  274. package/lib/server/utils/zipFile.js +74 -74
  275. package/lib/server/utils/zones.js +57 -57
  276. package/lib/server/videoRecorder.js +194 -124
  277. package/lib/server/webkit/protocol.d.js +16 -16
  278. package/lib/server/webkit/webkit.js +108 -108
  279. package/lib/server/webkit/wkBrowser.js +330 -335
  280. package/lib/server/webkit/wkConnection.js +144 -144
  281. package/lib/server/webkit/wkExecutionContext.js +154 -154
  282. package/lib/server/webkit/wkInput.js +181 -181
  283. package/lib/server/webkit/wkInterceptableRequest.js +197 -197
  284. package/lib/server/webkit/wkPage.js +1161 -1158
  285. package/lib/server/webkit/wkProvisionalPage.js +83 -83
  286. package/lib/server/webkit/wkWorkers.js +106 -105
  287. package/lib/serverRegistry.js +156 -0
  288. package/lib/third_party/pixelmatch.js +255 -255
  289. package/lib/tools/backend/browserBackend.js +79 -0
  290. package/lib/tools/backend/common.js +63 -0
  291. package/lib/tools/backend/config.js +41 -0
  292. package/lib/tools/backend/console.js +66 -0
  293. package/lib/tools/backend/context.js +296 -0
  294. package/lib/tools/backend/cookies.js +152 -0
  295. package/lib/tools/backend/devtools.js +69 -0
  296. package/lib/tools/backend/dialogs.js +59 -0
  297. package/lib/tools/backend/evaluate.js +64 -0
  298. package/lib/tools/backend/files.js +60 -0
  299. package/lib/tools/backend/form.js +64 -0
  300. package/lib/tools/backend/keyboard.js +155 -0
  301. package/lib/tools/backend/logFile.js +95 -0
  302. package/lib/tools/backend/mouse.js +168 -0
  303. package/lib/tools/backend/navigate.js +106 -0
  304. package/lib/tools/backend/network.js +135 -0
  305. package/lib/tools/backend/pdf.js +48 -0
  306. package/lib/tools/backend/response.js +305 -0
  307. package/lib/tools/backend/route.js +140 -0
  308. package/lib/tools/backend/runCode.js +77 -0
  309. package/lib/tools/backend/screenshot.js +88 -0
  310. package/lib/tools/backend/sessionLog.js +74 -0
  311. package/lib/tools/backend/snapshot.js +208 -0
  312. package/lib/tools/backend/storage.js +68 -0
  313. package/lib/tools/backend/tab.js +445 -0
  314. package/lib/tools/backend/tabs.js +67 -0
  315. package/lib/tools/backend/tool.js +47 -0
  316. package/lib/tools/backend/tools.js +102 -0
  317. package/lib/tools/backend/tracing.js +78 -0
  318. package/lib/tools/backend/utils.js +83 -0
  319. package/lib/tools/backend/verify.js +151 -0
  320. package/lib/tools/backend/video.js +98 -0
  321. package/lib/tools/backend/wait.js +63 -0
  322. package/lib/tools/backend/webstorage.js +223 -0
  323. package/lib/tools/cli-client/cli.js +6 -0
  324. package/lib/tools/cli-client/help.json +399 -0
  325. package/lib/tools/cli-client/minimist.js +128 -0
  326. package/lib/tools/cli-client/program.js +350 -0
  327. package/lib/tools/cli-client/registry.js +176 -0
  328. package/lib/tools/cli-client/session.js +289 -0
  329. package/lib/tools/cli-client/skill/SKILL.md +328 -0
  330. package/lib/tools/cli-client/skill/references/element-attributes.md +23 -0
  331. package/lib/tools/cli-client/skill/references/playwright-tests.md +39 -0
  332. package/lib/tools/cli-client/skill/references/request-mocking.md +87 -0
  333. package/lib/tools/cli-client/skill/references/running-code.md +231 -0
  334. package/lib/tools/cli-client/skill/references/session-management.md +169 -0
  335. package/lib/tools/cli-client/skill/references/storage-state.md +275 -0
  336. package/lib/tools/cli-client/skill/references/test-generation.md +88 -0
  337. package/lib/tools/cli-client/skill/references/tracing.md +139 -0
  338. package/lib/tools/cli-client/skill/references/video-recording.md +143 -0
  339. package/lib/tools/cli-daemon/command.js +73 -0
  340. package/lib/tools/cli-daemon/commands.js +956 -0
  341. package/lib/tools/cli-daemon/daemon.js +157 -0
  342. package/lib/tools/cli-daemon/helpGenerator.js +177 -0
  343. package/lib/tools/cli-daemon/program.js +129 -0
  344. package/lib/tools/dashboard/appIcon.png +0 -0
  345. package/lib/tools/dashboard/dashboardApp.js +284 -0
  346. package/lib/tools/dashboard/dashboardController.js +296 -0
  347. package/lib/tools/exports.js +60 -0
  348. package/lib/tools/mcp/browserFactory.js +233 -0
  349. package/lib/tools/mcp/cdpRelay.js +352 -0
  350. package/lib/tools/mcp/cli-stub.js +7 -0
  351. package/lib/tools/mcp/config.d.js +16 -0
  352. package/lib/tools/mcp/config.js +446 -0
  353. package/lib/tools/mcp/configIni.js +189 -0
  354. package/lib/{server/trace/viewer/traceParser.js → tools/mcp/extensionContextFactory.js} +55 -72
  355. package/lib/tools/mcp/index.js +62 -0
  356. package/lib/tools/mcp/log.js +35 -0
  357. package/lib/tools/mcp/program.js +107 -0
  358. package/lib/tools/mcp/protocol.js +28 -0
  359. package/lib/tools/mcp/watchdog.js +44 -0
  360. package/lib/tools/trace/SKILL.md +171 -0
  361. package/lib/tools/trace/installSkill.js +48 -0
  362. package/lib/tools/trace/traceActions.js +142 -0
  363. package/lib/tools/trace/traceAttachments.js +69 -0
  364. package/lib/tools/trace/traceCli.js +87 -0
  365. package/lib/tools/trace/traceConsole.js +97 -0
  366. package/lib/tools/trace/traceErrors.js +55 -0
  367. package/lib/tools/trace/traceOpen.js +69 -0
  368. package/lib/tools/trace/traceParser.js +96 -0
  369. package/lib/tools/trace/traceRequests.js +182 -0
  370. package/lib/tools/trace/traceScreenshot.js +68 -0
  371. package/lib/tools/trace/traceSnapshot.js +149 -0
  372. package/lib/tools/trace/traceUtils.js +153 -0
  373. package/lib/tools/utils/connect.js +32 -0
  374. package/lib/tools/utils/mcp/http.js +152 -0
  375. package/lib/tools/utils/mcp/server.js +230 -0
  376. package/lib/tools/utils/mcp/tool.js +47 -0
  377. package/lib/tools/utils/socketConnection.js +108 -0
  378. package/lib/utils/isomorphic/ariaSnapshot.js +455 -455
  379. package/lib/utils/isomorphic/assert.js +31 -31
  380. package/lib/utils/isomorphic/colors.js +72 -72
  381. package/lib/utils/isomorphic/cssParser.js +245 -245
  382. package/lib/utils/isomorphic/cssTokenizer.js +1051 -1051
  383. package/lib/utils/isomorphic/formatUtils.js +64 -0
  384. package/lib/utils/isomorphic/headers.js +53 -53
  385. package/lib/{server/utils → utils/isomorphic}/imageUtils.js +141 -141
  386. package/lib/utils/isomorphic/jsonSchema.js +89 -0
  387. package/lib/utils/isomorphic/locatorGenerators.js +689 -689
  388. package/lib/utils/isomorphic/locatorParser.js +176 -176
  389. package/lib/utils/isomorphic/locatorUtils.js +81 -81
  390. package/lib/utils/isomorphic/lruCache.js +51 -51
  391. package/lib/utils/isomorphic/manualPromise.js +114 -114
  392. package/lib/utils/isomorphic/mimeType.js +464 -459
  393. package/lib/utils/isomorphic/multimap.js +80 -80
  394. package/lib/utils/isomorphic/protocolFormatter.js +81 -81
  395. package/lib/utils/isomorphic/protocolMetainfo.js +351 -330
  396. package/lib/utils/isomorphic/rtti.js +43 -43
  397. package/lib/utils/isomorphic/selectorParser.js +386 -386
  398. package/lib/utils/isomorphic/semaphore.js +54 -54
  399. package/lib/utils/isomorphic/stackTrace.js +158 -158
  400. package/lib/utils/isomorphic/stringUtils.js +204 -204
  401. package/lib/utils/isomorphic/time.js +49 -49
  402. package/lib/utils/isomorphic/timeoutRunner.js +66 -66
  403. package/lib/utils/isomorphic/trace/entries.js +16 -16
  404. package/lib/utils/isomorphic/trace/snapshotRenderer.js +492 -499
  405. package/lib/utils/isomorphic/trace/snapshotServer.js +120 -120
  406. package/lib/utils/isomorphic/trace/snapshotStorage.js +89 -89
  407. package/lib/utils/isomorphic/trace/traceLoader.js +132 -131
  408. package/lib/utils/isomorphic/trace/traceModel.js +366 -365
  409. package/lib/utils/isomorphic/trace/traceModernizer.js +401 -400
  410. package/lib/utils/isomorphic/{traceUtils.js → trace/traceUtils.js} +58 -58
  411. package/lib/utils/isomorphic/trace/versions/traceV3.js +16 -16
  412. package/lib/utils/isomorphic/trace/versions/traceV4.js +16 -16
  413. package/lib/utils/isomorphic/trace/versions/traceV5.js +16 -16
  414. package/lib/utils/isomorphic/trace/versions/traceV6.js +16 -16
  415. package/lib/utils/isomorphic/trace/versions/traceV7.js +16 -16
  416. package/lib/utils/isomorphic/trace/versions/traceV8.js +16 -16
  417. package/lib/utils/isomorphic/types.js +16 -16
  418. package/lib/utils/isomorphic/urlMatch.js +243 -190
  419. package/lib/utils/isomorphic/utilityScriptSerializers.js +262 -251
  420. package/lib/utils/isomorphic/yaml.js +84 -84
  421. package/lib/utils.js +115 -111
  422. package/lib/utilsBundle.js +91 -109
  423. package/lib/utilsBundleImpl/index.js +217 -218
  424. package/lib/utilsBundleImpl/xdg-open +1066 -1066
  425. package/lib/vite/dashboard/assets/index-BAOybkp8.js +50 -0
  426. package/lib/vite/dashboard/assets/index-CZAYOG76.css +1 -0
  427. package/lib/vite/dashboard/index.html +28 -0
  428. package/lib/vite/htmlReport/index.html +16 -84
  429. package/lib/vite/htmlReport/report.css +1 -0
  430. package/lib/vite/htmlReport/report.js +72 -0
  431. package/lib/vite/recorder/assets/{codeMirrorModule-DadYNm1I.js → codeMirrorModule-C8KMvO9L.js} +32 -32
  432. package/lib/vite/recorder/assets/codeMirrorModule-DYBRYzYX.css +1 -1
  433. package/lib/vite/recorder/assets/index-BSjZa4pk.css +1 -1
  434. package/lib/vite/recorder/assets/index-CqAYX1I3.js +193 -0
  435. package/lib/vite/recorder/index.html +29 -29
  436. package/lib/vite/recorder/playwright-logo.svg +9 -9
  437. package/lib/vite/traceViewer/assets/{codeMirrorModule-a5XoALAZ.js → codeMirrorModule-DS0FLvoc.js} +32 -32
  438. package/lib/vite/traceViewer/assets/defaultSettingsView-GTWI-W_B.js +262 -0
  439. package/lib/vite/traceViewer/assets/xtermModule-CsJ4vdCR.js +9 -9
  440. package/lib/vite/traceViewer/codeMirrorModule.DYBRYzYX.css +1 -1
  441. package/lib/vite/traceViewer/defaultSettingsView.B4dS75f0.css +1 -0
  442. package/lib/vite/traceViewer/{index.BVu7tZDe.css → index.CzXZzn5A.css} +1 -1
  443. package/lib/vite/traceViewer/{index.Bk2uYQRV.js → index.Dtstcb7U.js} +2 -2
  444. package/lib/vite/traceViewer/index.html +43 -43
  445. package/lib/vite/traceViewer/manifest.webmanifest +16 -16
  446. package/lib/vite/traceViewer/playwright-logo.svg +9 -9
  447. package/lib/vite/traceViewer/snapshot.html +21 -21
  448. package/lib/vite/traceViewer/sw.bundle.js +5 -5
  449. package/lib/vite/traceViewer/uiMode.Btcz36p_.css +1 -1
  450. package/lib/vite/traceViewer/uiMode.Vipi55dB.js +6 -0
  451. package/lib/vite/traceViewer/uiMode.html +17 -17
  452. package/lib/vite/traceViewer/xtermModule.DYP7pi_n.css +32 -32
  453. package/lib/zipBundle.js +34 -34
  454. package/lib/zipBundleImpl.js +5 -5
  455. package/lib/zodBundle.js +39 -0
  456. package/lib/zodBundleImpl.js +40 -0
  457. package/package.json +6 -1
  458. package/types/protocol.d.ts +24720 -23824
  459. package/types/structs.d.ts +45 -45
  460. package/types/types.d.ts +23623 -22843
  461. package/lib/client/pageAgent.js +0 -64
  462. package/lib/mcpBundleImpl/index.js +0 -147
  463. package/lib/server/agent/actionRunner.js +0 -335
  464. package/lib/server/agent/actions.js +0 -128
  465. package/lib/server/agent/codegen.js +0 -111
  466. package/lib/server/agent/context.js +0 -150
  467. package/lib/server/agent/expectTools.js +0 -156
  468. package/lib/server/agent/pageAgent.js +0 -204
  469. package/lib/server/agent/performTools.js +0 -262
  470. package/lib/server/agent/tool.js +0 -109
  471. package/lib/server/dispatchers/pageAgentDispatcher.js +0 -96
  472. package/lib/vite/recorder/assets/index-BhTWtUlo.js +0 -193
  473. package/lib/vite/traceViewer/assets/defaultSettingsView-CJSZINFr.js +0 -266
  474. package/lib/vite/traceViewer/defaultSettingsView.7ch9cixO.css +0 -1
  475. package/lib/vite/traceViewer/uiMode.CQJ9SCIQ.js +0 -5
@@ -1,604 +1,655 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var tracing_exports = {};
30
- __export(tracing_exports, {
31
- Tracing: () => Tracing
32
- });
33
- module.exports = __toCommonJS(tracing_exports);
34
- var import_fs = __toESM(require("fs"));
35
- var import_os = __toESM(require("os"));
36
- var import_path = __toESM(require("path"));
37
- var import_snapshotter = require("./snapshotter");
38
- var import_protocolMetainfo = require("../../../utils/isomorphic/protocolMetainfo");
39
- var import_assert = require("../../../utils/isomorphic/assert");
40
- var import_time = require("../../../utils/isomorphic/time");
41
- var import_eventsHelper = require("../../utils/eventsHelper");
42
- var import_crypto = require("../../utils/crypto");
43
- var import_userAgent = require("../../utils/userAgent");
44
- var import_artifact = require("../../artifact");
45
- var import_browserContext = require("../../browserContext");
46
- var import_dispatcher = require("../../dispatchers/dispatcher");
47
- var import_errors = require("../../errors");
48
- var import_fileUtils = require("../../utils/fileUtils");
49
- var import_harTracer = require("../../har/harTracer");
50
- var import_instrumentation = require("../../instrumentation");
51
- var import_page = require("../../page");
52
- var import_progress = require("../../progress");
53
- const version = 8;
54
- const kScreencastOptions = { width: 800, height: 600, quality: 90 };
55
- class Tracing extends import_instrumentation.SdkObject {
56
- constructor(context, tracesDir) {
57
- super(context, "tracing");
58
- this._fs = new import_fileUtils.SerializedFS();
59
- this._screencastListeners = [];
60
- this._eventListeners = [];
61
- this._isStopping = false;
62
- this._allResources = /* @__PURE__ */ new Set();
63
- this._pendingHarEntries = /* @__PURE__ */ new Set();
64
- this._context = context;
65
- this._precreatedTracesDir = tracesDir;
66
- this._harTracer = new import_harTracer.HarTracer(context, null, this, {
67
- content: "attach",
68
- includeTraceInfo: true,
69
- recordRequestOverrides: false,
70
- waitForContentOnStop: false
71
- });
72
- const testIdAttributeName = "selectors" in context ? context.selectors().testIdAttributeName() : void 0;
73
- this._contextCreatedEvent = {
74
- version,
75
- type: "context-options",
76
- origin: "library",
77
- browserName: "",
78
- playwrightVersion: (0, import_userAgent.getPlaywrightVersion)(),
79
- options: {},
80
- platform: process.platform,
81
- wallTime: 0,
82
- monotonicTime: 0,
83
- sdkLanguage: this._sdkLanguage(),
84
- testIdAttributeName,
85
- contextId: context.guid
86
- };
87
- if (context instanceof import_browserContext.BrowserContext) {
88
- this._snapshotter = new import_snapshotter.Snapshotter(context, this);
89
- (0, import_assert.assert)(tracesDir, "tracesDir must be specified for BrowserContext");
90
- this._contextCreatedEvent.browserName = context._browser.options.name;
91
- this._contextCreatedEvent.channel = context._browser.options.channel;
92
- this._contextCreatedEvent.options = context._options;
93
- }
94
- }
95
- _sdkLanguage() {
96
- return this._context instanceof import_browserContext.BrowserContext ? this._context._browser.sdkLanguage() : this._context.attribution.playwright.options.sdkLanguage;
97
- }
98
- async resetForReuse(progress) {
99
- await this.stopChunk(progress, { mode: "discard" }).catch(() => {
100
- });
101
- await this.stop(progress);
102
- if (this._snapshotter)
103
- await progress.race(this._snapshotter.resetForReuse());
104
- }
105
- start(options) {
106
- if (this._isStopping)
107
- throw new Error("Cannot start tracing while stopping");
108
- if (this._state)
109
- throw new Error("Tracing has been already started");
110
- this._contextCreatedEvent.sdkLanguage = this._sdkLanguage();
111
- const traceName = options.name || (0, import_crypto.createGuid)();
112
- const tracesDir = this._createTracesDirIfNeeded();
113
- this._state = {
114
- options,
115
- traceName,
116
- tracesDir,
117
- traceFile: import_path.default.join(tracesDir, traceName + ".trace"),
118
- networkFile: import_path.default.join(tracesDir, traceName + ".network"),
119
- resourcesDir: import_path.default.join(tracesDir, "resources"),
120
- chunkOrdinal: 0,
121
- traceSha1s: /* @__PURE__ */ new Set(),
122
- networkSha1s: /* @__PURE__ */ new Set(),
123
- recording: false,
124
- callIds: /* @__PURE__ */ new Set(),
125
- groupStack: []
126
- };
127
- this._fs.mkdir(this._state.resourcesDir);
128
- this._fs.writeFile(this._state.networkFile, "");
129
- if (options.snapshots)
130
- this._harTracer.start({ omitScripts: !options.live });
131
- }
132
- async startChunk(progress, options = {}) {
133
- if (this._state && this._state.recording)
134
- await this.stopChunk(progress, { mode: "discard" });
135
- if (!this._state)
136
- throw new Error("Must start tracing before starting a new chunk");
137
- if (this._isStopping)
138
- throw new Error("Cannot start a trace chunk while stopping");
139
- this._state.recording = true;
140
- this._state.callIds.clear();
141
- const preserveNetworkResources = this._context instanceof import_browserContext.BrowserContext;
142
- if (options.name && options.name !== this._state.traceName)
143
- this._changeTraceName(this._state, options.name, preserveNetworkResources);
144
- else
145
- this._allocateNewTraceFile(this._state);
146
- if (!preserveNetworkResources)
147
- this._fs.writeFile(this._state.networkFile, "");
148
- this._fs.mkdir(import_path.default.dirname(this._state.traceFile));
149
- const event = {
150
- ...this._contextCreatedEvent,
151
- title: options.title,
152
- wallTime: Date.now(),
153
- monotonicTime: (0, import_time.monotonicTime)()
154
- };
155
- this._appendTraceEvent(event);
156
- this._context.instrumentation.addListener(this, this._context);
157
- this._eventListeners.push(
158
- import_eventsHelper.eventsHelper.addEventListener(this._context, import_browserContext.BrowserContext.Events.Console, this._onConsoleMessage.bind(this)),
159
- import_eventsHelper.eventsHelper.addEventListener(this._context, import_browserContext.BrowserContext.Events.PageError, this._onPageError.bind(this))
160
- );
161
- if (this._state.options.screenshots)
162
- this._startScreencast();
163
- if (this._state.options.snapshots)
164
- await this._snapshotter?.start();
165
- return { traceName: this._state.traceName };
166
- }
167
- _currentGroupId() {
168
- return this._state?.groupStack.length ? this._state.groupStack[this._state.groupStack.length - 1] : void 0;
169
- }
170
- group(name, location, metadata) {
171
- if (!this._state)
172
- return;
173
- const stackFrames = [];
174
- const { file, line, column } = location ?? metadata.location ?? {};
175
- if (file) {
176
- stackFrames.push({
177
- file,
178
- line: line ?? 0,
179
- column: column ?? 0
180
- });
181
- }
182
- const event = {
183
- type: "before",
184
- callId: metadata.id,
185
- startTime: metadata.startTime,
186
- title: name,
187
- class: "Tracing",
188
- method: "tracingGroup",
189
- params: {},
190
- stepId: metadata.stepId,
191
- stack: stackFrames
192
- };
193
- if (this._currentGroupId())
194
- event.parentId = this._currentGroupId();
195
- this._state.groupStack.push(event.callId);
196
- this._appendTraceEvent(event);
197
- }
198
- groupEnd() {
199
- if (!this._state)
200
- return;
201
- const callId = this._state.groupStack.pop();
202
- if (!callId)
203
- return;
204
- const event = {
205
- type: "after",
206
- callId,
207
- endTime: (0, import_time.monotonicTime)()
208
- };
209
- this._appendTraceEvent(event);
210
- }
211
- _startScreencast() {
212
- if (!(this._context instanceof import_browserContext.BrowserContext))
213
- return;
214
- for (const page of this._context.pages())
215
- this._startScreencastInPage(page);
216
- this._screencastListeners.push(
217
- import_eventsHelper.eventsHelper.addEventListener(this._context, import_browserContext.BrowserContext.Events.Page, this._startScreencastInPage.bind(this))
218
- );
219
- }
220
- _stopScreencast() {
221
- import_eventsHelper.eventsHelper.removeEventListeners(this._screencastListeners);
222
- if (!(this._context instanceof import_browserContext.BrowserContext))
223
- return;
224
- for (const page of this._context.pages())
225
- page.screencast.setOptions(null);
226
- }
227
- _allocateNewTraceFile(state) {
228
- const suffix = state.chunkOrdinal ? `-chunk${state.chunkOrdinal}` : ``;
229
- state.chunkOrdinal++;
230
- state.traceFile = import_path.default.join(state.tracesDir, `${state.traceName}${suffix}.trace`);
231
- }
232
- _changeTraceName(state, name, preserveNetworkResources) {
233
- state.traceName = name;
234
- state.chunkOrdinal = 0;
235
- this._allocateNewTraceFile(state);
236
- const newNetworkFile = import_path.default.join(state.tracesDir, name + ".network");
237
- if (preserveNetworkResources)
238
- this._fs.copyFile(state.networkFile, newNetworkFile);
239
- state.networkFile = newNetworkFile;
240
- }
241
- async stop(progress) {
242
- if (!this._state)
243
- return;
244
- if (this._isStopping)
245
- throw new Error(`Tracing is already stopping`);
246
- if (this._state.recording)
247
- throw new Error(`Must stop trace file before stopping tracing`);
248
- this._closeAllGroups();
249
- this._harTracer.stop();
250
- this.flushHarEntries();
251
- const promise = progress ? progress.race(this._fs.syncAndGetError()) : this._fs.syncAndGetError();
252
- await promise.finally(() => {
253
- this._state = void 0;
254
- });
255
- }
256
- async deleteTmpTracesDir() {
257
- if (this._tracesTmpDir)
258
- await (0, import_fileUtils.removeFolders)([this._tracesTmpDir]);
259
- }
260
- _createTracesDirIfNeeded() {
261
- if (this._precreatedTracesDir)
262
- return this._precreatedTracesDir;
263
- this._tracesTmpDir = import_fs.default.mkdtempSync(import_path.default.join(import_os.default.tmpdir(), "playwright-tracing-"));
264
- return this._tracesTmpDir;
265
- }
266
- abort() {
267
- this._snapshotter?.dispose();
268
- this._harTracer.stop();
269
- }
270
- async flush() {
271
- this.abort();
272
- await this._fs.syncAndGetError();
273
- }
274
- _closeAllGroups() {
275
- while (this._currentGroupId())
276
- this.groupEnd();
277
- }
278
- async stopChunk(progress, params) {
279
- if (this._isStopping)
280
- throw new Error(`Tracing is already stopping`);
281
- this._isStopping = true;
282
- if (!this._state || !this._state.recording) {
283
- this._isStopping = false;
284
- if (params.mode !== "discard")
285
- throw new Error(`Must start tracing before stopping`);
286
- return {};
287
- }
288
- this._closeAllGroups();
289
- this._context.instrumentation.removeListener(this);
290
- import_eventsHelper.eventsHelper.removeEventListeners(this._eventListeners);
291
- if (this._state.options.screenshots)
292
- this._stopScreencast();
293
- if (this._state.options.snapshots)
294
- this._snapshotter?.stop();
295
- this.flushHarEntries();
296
- const newNetworkFile = import_path.default.join(this._state.tracesDir, this._state.traceName + `-pwnetcopy-${this._state.chunkOrdinal}.network`);
297
- const entries = [];
298
- entries.push({ name: "trace.trace", value: this._state.traceFile });
299
- entries.push({ name: "trace.network", value: newNetworkFile });
300
- for (const sha1 of /* @__PURE__ */ new Set([...this._state.traceSha1s, ...this._state.networkSha1s]))
301
- entries.push({ name: import_path.default.join("resources", sha1), value: import_path.default.join(this._state.resourcesDir, sha1) });
302
- this._state.traceSha1s = /* @__PURE__ */ new Set();
303
- if (params.mode === "discard") {
304
- this._isStopping = false;
305
- this._state.recording = false;
306
- return {};
307
- }
308
- this._fs.copyFile(this._state.networkFile, newNetworkFile);
309
- const zipFileName = this._state.traceFile + ".zip";
310
- if (params.mode === "archive")
311
- this._fs.zip(entries, zipFileName);
312
- const promise = progress ? progress.race(this._fs.syncAndGetError()) : this._fs.syncAndGetError();
313
- const error = await promise.catch((e) => e);
314
- this._isStopping = false;
315
- if (this._state)
316
- this._state.recording = false;
317
- if (error) {
318
- if (!(0, import_progress.isAbortError)(error) && this._context instanceof import_browserContext.BrowserContext && !this._context._browser.isConnected())
319
- return {};
320
- throw error;
321
- }
322
- if (params.mode === "entries")
323
- return { entries };
324
- const artifact = new import_artifact.Artifact(this._context, zipFileName);
325
- artifact.reportFinished();
326
- return { artifact };
327
- }
328
- async _captureSnapshot(snapshotName, sdkObject, metadata) {
329
- if (!snapshotName || !sdkObject.attribution.page)
330
- return;
331
- await this._snapshotter?.captureSnapshot(sdkObject.attribution.page, metadata.id, snapshotName).catch(() => {
332
- });
333
- }
334
- _shouldCaptureSnapshot(sdkObject, metadata) {
335
- return !!this._snapshotter?.started() && shouldCaptureSnapshot(metadata) && !!sdkObject.attribution.page;
336
- }
337
- onBeforeCall(sdkObject, metadata, parentId) {
338
- const event = createBeforeActionTraceEvent(metadata, parentId ?? this._currentGroupId());
339
- if (!event)
340
- return Promise.resolve();
341
- sdkObject.attribution.page?.screencast.temporarilyDisableThrottling();
342
- if (this._shouldCaptureSnapshot(sdkObject, metadata))
343
- event.beforeSnapshot = `before@${metadata.id}`;
344
- this._state?.callIds.add(metadata.id);
345
- this._appendTraceEvent(event);
346
- return this._captureSnapshot(event.beforeSnapshot, sdkObject, metadata);
347
- }
348
- onBeforeInputAction(sdkObject, metadata) {
349
- if (!this._state?.callIds.has(metadata.id))
350
- return Promise.resolve();
351
- const event = createInputActionTraceEvent(metadata);
352
- if (!event)
353
- return Promise.resolve();
354
- sdkObject.attribution.page?.screencast.temporarilyDisableThrottling();
355
- if (this._shouldCaptureSnapshot(sdkObject, metadata))
356
- event.inputSnapshot = `input@${metadata.id}`;
357
- this._appendTraceEvent(event);
358
- return this._captureSnapshot(event.inputSnapshot, sdkObject, metadata);
359
- }
360
- onCallLog(sdkObject, metadata, logName, message) {
361
- if (!this._state?.callIds.has(metadata.id))
362
- return;
363
- if (metadata.internal)
364
- return;
365
- if (logName !== "api")
366
- return;
367
- const event = createActionLogTraceEvent(metadata, message);
368
- if (event)
369
- this._appendTraceEvent(event);
370
- }
371
- onAfterCall(sdkObject, metadata) {
372
- if (!this._state?.callIds.has(metadata.id))
373
- return Promise.resolve();
374
- this._state?.callIds.delete(metadata.id);
375
- const event = createAfterActionTraceEvent(metadata);
376
- if (!event)
377
- return Promise.resolve();
378
- sdkObject.attribution.page?.screencast.temporarilyDisableThrottling();
379
- if (this._shouldCaptureSnapshot(sdkObject, metadata))
380
- event.afterSnapshot = `after@${metadata.id}`;
381
- this._appendTraceEvent(event);
382
- return this._captureSnapshot(event.afterSnapshot, sdkObject, metadata);
383
- }
384
- onEntryStarted(entry) {
385
- this._pendingHarEntries.add(entry);
386
- }
387
- onEntryFinished(entry) {
388
- this._pendingHarEntries.delete(entry);
389
- const event = { type: "resource-snapshot", snapshot: entry };
390
- const visited = visitTraceEvent(event, this._state.networkSha1s);
391
- this._fs.appendFile(
392
- this._state.networkFile,
393
- JSON.stringify(visited) + "\n",
394
- true
395
- /* flush */
396
- );
397
- }
398
- flushHarEntries() {
399
- const harLines = [];
400
- for (const entry of this._pendingHarEntries) {
401
- const event = { type: "resource-snapshot", snapshot: entry };
402
- const visited = visitTraceEvent(event, this._state.networkSha1s);
403
- harLines.push(JSON.stringify(visited));
404
- }
405
- this._pendingHarEntries.clear();
406
- if (harLines.length)
407
- this._fs.appendFile(
408
- this._state.networkFile,
409
- harLines.join("\n") + "\n",
410
- true
411
- /* flush */
412
- );
413
- }
414
- onContentBlob(sha1, buffer) {
415
- this._appendResource(sha1, buffer);
416
- }
417
- onSnapshotterBlob(blob) {
418
- this._appendResource(blob.sha1, blob.buffer);
419
- }
420
- onFrameSnapshot(snapshot) {
421
- this._appendTraceEvent({ type: "frame-snapshot", snapshot });
422
- }
423
- _onConsoleMessage(message) {
424
- const event = {
425
- type: "console",
426
- messageType: message.type(),
427
- text: message.text(),
428
- args: message.args().map((a) => ({ preview: a.toString(), value: a.rawValue() })),
429
- location: message.location(),
430
- time: (0, import_time.monotonicTime)(),
431
- pageId: message.page()?.guid
432
- };
433
- this._appendTraceEvent(event);
434
- }
435
- onDialog(dialog) {
436
- const event = {
437
- type: "event",
438
- time: (0, import_time.monotonicTime)(),
439
- class: "BrowserContext",
440
- method: "dialog",
441
- params: { pageId: dialog.page().guid, type: dialog.type(), message: dialog.message(), defaultValue: dialog.defaultValue() }
442
- };
443
- this._appendTraceEvent(event);
444
- }
445
- onDownload(page, download) {
446
- const event = {
447
- type: "event",
448
- time: (0, import_time.monotonicTime)(),
449
- class: "BrowserContext",
450
- method: "download",
451
- params: { pageId: page.guid, url: download.url, suggestedFilename: download.suggestedFilename() }
452
- };
453
- this._appendTraceEvent(event);
454
- }
455
- onPageOpen(page) {
456
- const event = {
457
- type: "event",
458
- time: (0, import_time.monotonicTime)(),
459
- class: "BrowserContext",
460
- method: "page",
461
- params: { pageId: page.guid, openerPageId: page.opener()?.guid }
462
- };
463
- this._appendTraceEvent(event);
464
- }
465
- onPageClose(page) {
466
- const event = {
467
- type: "event",
468
- time: (0, import_time.monotonicTime)(),
469
- class: "BrowserContext",
470
- method: "pageClosed",
471
- params: { pageId: page.guid }
472
- };
473
- this._appendTraceEvent(event);
474
- }
475
- _onPageError(error, page) {
476
- const event = {
477
- type: "event",
478
- time: (0, import_time.monotonicTime)(),
479
- class: "BrowserContext",
480
- method: "pageError",
481
- params: { error: (0, import_errors.serializeError)(error) },
482
- pageId: page.guid
483
- };
484
- this._appendTraceEvent(event);
485
- }
486
- _startScreencastInPage(page) {
487
- page.screencast.setOptions(kScreencastOptions);
488
- const prefix = page.guid;
489
- this._screencastListeners.push(
490
- import_eventsHelper.eventsHelper.addEventListener(page, import_page.Page.Events.ScreencastFrame, (params) => {
491
- const suffix = params.timestamp || Date.now();
492
- const sha1 = `${prefix}-${suffix}.jpeg`;
493
- const event = {
494
- type: "screencast-frame",
495
- pageId: page.guid,
496
- sha1,
497
- width: params.width,
498
- height: params.height,
499
- timestamp: (0, import_time.monotonicTime)(),
500
- frameSwapWallTime: params.frameSwapWallTime
501
- };
502
- this._appendResource(sha1, params.buffer);
503
- this._appendTraceEvent(event);
504
- })
505
- );
506
- }
507
- _appendTraceEvent(event) {
508
- const visited = visitTraceEvent(event, this._state.traceSha1s);
509
- const flush = this._state.options.live || event.type !== "event" && event.type !== "console" && event.type !== "log";
510
- this._fs.appendFile(this._state.traceFile, JSON.stringify(visited) + "\n", flush);
511
- }
512
- _appendResource(sha1, buffer) {
513
- if (this._allResources.has(sha1))
514
- return;
515
- this._allResources.add(sha1);
516
- const resourcePath = import_path.default.join(this._state.resourcesDir, sha1);
517
- this._fs.writeFile(
518
- resourcePath,
519
- buffer,
520
- true
521
- /* skipIfExists */
522
- );
523
- }
524
- }
525
- function visitTraceEvent(object, sha1s) {
526
- if (Array.isArray(object))
527
- return object.map((o) => visitTraceEvent(o, sha1s));
528
- if (object instanceof import_dispatcher.Dispatcher)
529
- return `<${object._type}>`;
530
- if (object instanceof Buffer)
531
- return `<Buffer>`;
532
- if (object instanceof Date)
533
- return object;
534
- if (typeof object === "object") {
535
- const result = {};
536
- for (const key in object) {
537
- if (key === "sha1" || key === "_sha1" || key.endsWith("Sha1")) {
538
- const sha1 = object[key];
539
- if (sha1)
540
- sha1s.add(sha1);
541
- }
542
- result[key] = visitTraceEvent(object[key], sha1s);
543
- }
544
- return result;
545
- }
546
- return object;
547
- }
548
- function shouldCaptureSnapshot(metadata) {
549
- const metainfo = import_protocolMetainfo.methodMetainfo.get(metadata.type + "." + metadata.method);
550
- return !!metainfo?.snapshot;
551
- }
552
- function createBeforeActionTraceEvent(metadata, parentId) {
553
- if (metadata.internal || metadata.method.startsWith("tracing"))
554
- return null;
555
- const event = {
556
- type: "before",
557
- callId: metadata.id,
558
- startTime: metadata.startTime,
559
- title: metadata.title,
560
- class: metadata.type,
561
- method: metadata.method,
562
- params: metadata.params,
563
- stepId: metadata.stepId,
564
- pageId: metadata.pageId
565
- };
566
- if (parentId)
567
- event.parentId = parentId;
568
- return event;
569
- }
570
- function createInputActionTraceEvent(metadata) {
571
- if (metadata.internal || metadata.method.startsWith("tracing"))
572
- return null;
573
- return {
574
- type: "input",
575
- callId: metadata.id,
576
- point: metadata.point
577
- };
578
- }
579
- function createActionLogTraceEvent(metadata, message) {
580
- if (metadata.internal || metadata.method.startsWith("tracing"))
581
- return null;
582
- return {
583
- type: "log",
584
- callId: metadata.id,
585
- time: (0, import_time.monotonicTime)(),
586
- message
587
- };
588
- }
589
- function createAfterActionTraceEvent(metadata) {
590
- if (metadata.internal || metadata.method.startsWith("tracing"))
591
- return null;
592
- return {
593
- type: "after",
594
- callId: metadata.id,
595
- endTime: metadata.endTime,
596
- error: metadata.error?.error,
597
- result: metadata.result,
598
- point: metadata.point
599
- };
600
- }
601
- // Annotate the CommonJS export names for ESM import in node:
602
- 0 && (module.exports = {
603
- Tracing
604
- });
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var tracing_exports = {};
30
+ __export(tracing_exports, {
31
+ Tracing: () => Tracing
32
+ });
33
+ module.exports = __toCommonJS(tracing_exports);
34
+ var import_fs = __toESM(require("fs"));
35
+ var import_os = __toESM(require("os"));
36
+ var import_path = __toESM(require("path"));
37
+ var import_snapshotter = require("./snapshotter");
38
+ var import_protocolMetainfo = require("../../../utils/isomorphic/protocolMetainfo");
39
+ var import_assert = require("../../../utils/isomorphic/assert");
40
+ var import_time = require("../../../utils/isomorphic/time");
41
+ var import_manualPromise = require("../../../utils/isomorphic/manualPromise");
42
+ var import_eventsHelper = require("../../utils/eventsHelper");
43
+ var import_crypto = require("../../utils/crypto");
44
+ var import_userAgent = require("../../utils/userAgent");
45
+ var import_artifact = require("../../artifact");
46
+ var import_browserContext = require("../../browserContext");
47
+ var import_dispatcher = require("../../dispatchers/dispatcher");
48
+ var import_errors = require("../../errors");
49
+ var import_fileUtils = require("../../utils/fileUtils");
50
+ var import_harTracer = require("../../har/harTracer");
51
+ var import_instrumentation = require("../../instrumentation");
52
+ var import_progress = require("../../progress");
53
+ const version = 8;
54
+ class Tracing extends import_instrumentation.SdkObject {
55
+ constructor(context, tracesDir) {
56
+ super(context, "tracing");
57
+ this._fs = new import_fileUtils.SerializedFS();
58
+ this._screencastListeners = [];
59
+ this._pageTracingRecorders = /* @__PURE__ */ new Map();
60
+ this._eventListeners = [];
61
+ this._isStopping = false;
62
+ this._allResources = /* @__PURE__ */ new Set();
63
+ this._pendingHarEntries = /* @__PURE__ */ new Set();
64
+ this._context = context;
65
+ this._precreatedTracesDir = tracesDir;
66
+ this._harTracer = new import_harTracer.HarTracer(context, null, this, {
67
+ content: "attach",
68
+ includeTraceInfo: true,
69
+ recordRequestOverrides: false,
70
+ waitForContentOnStop: false
71
+ });
72
+ const testIdAttributeName = "selectors" in context ? context.selectors().testIdAttributeName() : void 0;
73
+ this._contextCreatedEvent = {
74
+ version,
75
+ type: "context-options",
76
+ origin: "library",
77
+ browserName: "",
78
+ playwrightVersion: (0, import_userAgent.getPlaywrightVersion)(),
79
+ options: {},
80
+ platform: process.platform,
81
+ wallTime: 0,
82
+ monotonicTime: 0,
83
+ sdkLanguage: this._sdkLanguage(),
84
+ testIdAttributeName,
85
+ contextId: context.guid
86
+ };
87
+ if (context instanceof import_browserContext.BrowserContext) {
88
+ this._snapshotter = new import_snapshotter.Snapshotter(context, this);
89
+ (0, import_assert.assert)(tracesDir, "tracesDir must be specified for BrowserContext");
90
+ this._contextCreatedEvent.browserName = context._browser.options.name;
91
+ this._contextCreatedEvent.channel = context._browser.options.channel;
92
+ this._contextCreatedEvent.options = context._options;
93
+ }
94
+ }
95
+ _sdkLanguage() {
96
+ return this._context instanceof import_browserContext.BrowserContext ? this._context._browser.sdkLanguage() : this._context.attribution.playwright.options.sdkLanguage;
97
+ }
98
+ async resetForReuse(progress) {
99
+ await this.stopChunk(progress, { mode: "discard" }).catch(() => {
100
+ });
101
+ await this.stop(progress);
102
+ if (this._snapshotter)
103
+ await progress.race(this._snapshotter.resetForReuse());
104
+ }
105
+ start(options) {
106
+ if (this._isStopping)
107
+ throw new Error("Cannot start tracing while stopping");
108
+ if (this._state)
109
+ throw new Error("Tracing has been already started");
110
+ this._contextCreatedEvent.sdkLanguage = this._sdkLanguage();
111
+ const traceName = options.name || (0, import_crypto.createGuid)();
112
+ const tracesDir = this._createTracesDirIfNeeded();
113
+ this._state = {
114
+ options,
115
+ traceName,
116
+ tracesDir,
117
+ traceFile: import_path.default.join(tracesDir, traceName + ".trace"),
118
+ networkFile: import_path.default.join(tracesDir, traceName + ".network"),
119
+ resourcesDir: import_path.default.join(tracesDir, "resources"),
120
+ chunkOrdinal: 0,
121
+ traceSha1s: /* @__PURE__ */ new Set(),
122
+ networkSha1s: /* @__PURE__ */ new Set(),
123
+ recording: false,
124
+ callIds: /* @__PURE__ */ new Set(),
125
+ groupStack: []
126
+ };
127
+ this._fs.mkdir(this._state.resourcesDir);
128
+ this._fs.writeFile(this._state.networkFile, "");
129
+ if (options.snapshots)
130
+ this._harTracer.start({ omitScripts: !options.live });
131
+ }
132
+ async startChunk(progress, options = {}) {
133
+ if (this._state && this._state.recording)
134
+ await this.stopChunk(progress, { mode: "discard" });
135
+ if (!this._state)
136
+ throw new Error("Must start tracing before starting a new chunk");
137
+ if (this._isStopping)
138
+ throw new Error("Cannot start a trace chunk while stopping");
139
+ this._state.recording = true;
140
+ this._state.callIds.clear();
141
+ const preserveNetworkResources = this._context instanceof import_browserContext.BrowserContext;
142
+ if (options.name && options.name !== this._state.traceName)
143
+ this._changeTraceName(this._state, options.name, preserveNetworkResources);
144
+ else
145
+ this._allocateNewTraceFile(this._state);
146
+ if (!preserveNetworkResources)
147
+ this._fs.writeFile(this._state.networkFile, "");
148
+ this._fs.mkdir(import_path.default.dirname(this._state.traceFile));
149
+ const event = {
150
+ ...this._contextCreatedEvent,
151
+ title: options.title,
152
+ wallTime: Date.now(),
153
+ monotonicTime: (0, import_time.monotonicTime)()
154
+ };
155
+ this._appendTraceEvent(event);
156
+ this._context.instrumentation.addListener(this, this._context);
157
+ this._eventListeners.push(
158
+ import_eventsHelper.eventsHelper.addEventListener(this._context, import_browserContext.BrowserContext.Events.Console, this._onConsoleMessage.bind(this)),
159
+ import_eventsHelper.eventsHelper.addEventListener(this._context, import_browserContext.BrowserContext.Events.PageError, this._onPageError.bind(this))
160
+ );
161
+ if (this._state.options.screenshots)
162
+ this._startScreencast();
163
+ if (this._state.options.snapshots)
164
+ await this._snapshotter?.start();
165
+ return { traceName: this._state.traceName };
166
+ }
167
+ _currentGroupId() {
168
+ return this._state?.groupStack.length ? this._state.groupStack[this._state.groupStack.length - 1] : void 0;
169
+ }
170
+ group(name, location, metadata) {
171
+ if (!this._state)
172
+ return;
173
+ const stackFrames = [];
174
+ const { file, line, column } = location ?? metadata.location ?? {};
175
+ if (file) {
176
+ stackFrames.push({
177
+ file,
178
+ line: line ?? 0,
179
+ column: column ?? 0
180
+ });
181
+ }
182
+ const event = {
183
+ type: "before",
184
+ callId: metadata.id,
185
+ startTime: metadata.startTime,
186
+ title: name,
187
+ class: "Tracing",
188
+ method: "tracingGroup",
189
+ params: {},
190
+ stepId: metadata.stepId,
191
+ stack: stackFrames
192
+ };
193
+ if (this._currentGroupId())
194
+ event.parentId = this._currentGroupId();
195
+ this._state.groupStack.push(event.callId);
196
+ this._appendTraceEvent(event);
197
+ }
198
+ groupEnd() {
199
+ if (!this._state)
200
+ return;
201
+ const callId = this._state.groupStack.pop();
202
+ if (!callId)
203
+ return;
204
+ const event = {
205
+ type: "after",
206
+ callId,
207
+ endTime: (0, import_time.monotonicTime)()
208
+ };
209
+ this._appendTraceEvent(event);
210
+ }
211
+ _startScreencast() {
212
+ if (!(this._context instanceof import_browserContext.BrowserContext))
213
+ return;
214
+ for (const page of this._context.pages())
215
+ this._startScreencastInPage(page);
216
+ this._screencastListeners.push(
217
+ import_eventsHelper.eventsHelper.addEventListener(this._context, import_browserContext.BrowserContext.Events.Page, this._startScreencastInPage.bind(this))
218
+ );
219
+ }
220
+ _stopScreencast() {
221
+ import_eventsHelper.eventsHelper.removeEventListeners(this._screencastListeners);
222
+ for (const recorder of this._pageTracingRecorders.values())
223
+ recorder.dispose();
224
+ this._pageTracingRecorders.clear();
225
+ }
226
+ _allocateNewTraceFile(state) {
227
+ const suffix = state.chunkOrdinal ? `-chunk${state.chunkOrdinal}` : ``;
228
+ state.chunkOrdinal++;
229
+ state.traceFile = import_path.default.join(state.tracesDir, `${state.traceName}${suffix}.trace`);
230
+ }
231
+ _changeTraceName(state, name, preserveNetworkResources) {
232
+ state.traceName = name;
233
+ state.chunkOrdinal = 0;
234
+ this._allocateNewTraceFile(state);
235
+ const newNetworkFile = import_path.default.join(state.tracesDir, name + ".network");
236
+ if (preserveNetworkResources)
237
+ this._fs.copyFile(state.networkFile, newNetworkFile);
238
+ state.networkFile = newNetworkFile;
239
+ }
240
+ async stop(progress) {
241
+ if (!this._state)
242
+ return;
243
+ if (this._isStopping)
244
+ throw new Error(`Tracing is already stopping`);
245
+ if (this._state.recording)
246
+ throw new Error(`Must stop trace file before stopping tracing`);
247
+ this._closeAllGroups();
248
+ this._harTracer.stop();
249
+ this.flushHarEntries();
250
+ const promise = progress ? progress.race(this._fs.syncAndGetError()) : this._fs.syncAndGetError();
251
+ await promise.finally(() => {
252
+ this._state = void 0;
253
+ });
254
+ }
255
+ async deleteTmpTracesDir() {
256
+ if (this._tracesTmpDir)
257
+ await (0, import_fileUtils.removeFolders)([this._tracesTmpDir]);
258
+ }
259
+ _createTracesDirIfNeeded() {
260
+ if (this._precreatedTracesDir)
261
+ return this._precreatedTracesDir;
262
+ this._tracesTmpDir = import_fs.default.mkdtempSync(import_path.default.join(import_os.default.tmpdir(), "playwright-tracing-"));
263
+ return this._tracesTmpDir;
264
+ }
265
+ abort() {
266
+ this._snapshotter?.dispose();
267
+ this._harTracer.stop();
268
+ }
269
+ async flush() {
270
+ this.abort();
271
+ await this._fs.syncAndGetError();
272
+ }
273
+ _closeAllGroups() {
274
+ while (this._currentGroupId())
275
+ this.groupEnd();
276
+ }
277
+ async stopChunk(progress, params) {
278
+ if (this._isStopping)
279
+ throw new Error(`Tracing is already stopping`);
280
+ this._isStopping = true;
281
+ if (!this._state || !this._state.recording) {
282
+ this._isStopping = false;
283
+ if (params.mode !== "discard")
284
+ throw new Error(`Must start tracing before stopping`);
285
+ return {};
286
+ }
287
+ this._closeAllGroups();
288
+ this._context.instrumentation.removeListener(this);
289
+ import_eventsHelper.eventsHelper.removeEventListeners(this._eventListeners);
290
+ if (this._state.options.screenshots)
291
+ this._stopScreencast();
292
+ if (this._state.options.snapshots)
293
+ this._snapshotter?.stop();
294
+ this.flushHarEntries();
295
+ const newNetworkFile = import_path.default.join(this._state.tracesDir, this._state.traceName + `-pwnetcopy-${this._state.chunkOrdinal}.network`);
296
+ const entries = [];
297
+ entries.push({ name: "trace.trace", value: this._state.traceFile });
298
+ entries.push({ name: "trace.network", value: newNetworkFile });
299
+ for (const sha1 of /* @__PURE__ */ new Set([...this._state.traceSha1s, ...this._state.networkSha1s]))
300
+ entries.push({ name: import_path.default.join("resources", sha1), value: import_path.default.join(this._state.resourcesDir, sha1) });
301
+ this._state.traceSha1s = /* @__PURE__ */ new Set();
302
+ if (params.mode === "discard") {
303
+ this._isStopping = false;
304
+ this._state.recording = false;
305
+ return {};
306
+ }
307
+ this._fs.copyFile(this._state.networkFile, newNetworkFile);
308
+ const zipFileName = this._state.traceFile + ".zip";
309
+ if (params.mode === "archive")
310
+ this._fs.zip(entries, zipFileName);
311
+ const promise = progress ? progress.race(this._fs.syncAndGetError()) : this._fs.syncAndGetError();
312
+ const error = await promise.catch((e) => e);
313
+ this._isStopping = false;
314
+ if (this._state)
315
+ this._state.recording = false;
316
+ if (error) {
317
+ if (!(0, import_progress.isAbortError)(error) && this._context instanceof import_browserContext.BrowserContext && !this._context._browser.isConnected())
318
+ return {};
319
+ throw error;
320
+ }
321
+ if (params.mode === "entries")
322
+ return { entries };
323
+ const artifact = new import_artifact.Artifact(this._context, zipFileName);
324
+ artifact.reportFinished();
325
+ return { artifact };
326
+ }
327
+ async _captureSnapshot(snapshotName, sdkObject, metadata) {
328
+ if (!snapshotName || !sdkObject.attribution.page)
329
+ return;
330
+ await this._snapshotter?.captureSnapshot(sdkObject.attribution.page, metadata.id, snapshotName).catch(() => {
331
+ });
332
+ }
333
+ _shouldCaptureSnapshot(sdkObject, metadata, phase) {
334
+ if (!sdkObject.attribution.page || !this._snapshotter?.started())
335
+ return;
336
+ const metainfo = (0, import_protocolMetainfo.getMetainfo)(metadata);
337
+ if (!metainfo?.snapshot)
338
+ return false;
339
+ switch (phase) {
340
+ case "before":
341
+ return !metainfo.input || !!metainfo.isAutoWaiting;
342
+ case "input":
343
+ return !!metainfo.input;
344
+ case "after":
345
+ return true;
346
+ }
347
+ }
348
+ onBeforeCall(sdkObject, metadata, parentId) {
349
+ const event = createBeforeActionTraceEvent(metadata, parentId ?? this._currentGroupId());
350
+ if (!event)
351
+ return Promise.resolve();
352
+ this._temporarilyDisableThrottling(sdkObject.attribution.page);
353
+ if (this._shouldCaptureSnapshot(sdkObject, metadata, "before"))
354
+ event.beforeSnapshot = `before@${metadata.id}`;
355
+ this._state?.callIds.add(metadata.id);
356
+ this._appendTraceEvent(event);
357
+ return this._captureSnapshot(event.beforeSnapshot, sdkObject, metadata);
358
+ }
359
+ onBeforeInputAction(sdkObject, metadata) {
360
+ if (!this._state?.callIds.has(metadata.id))
361
+ return Promise.resolve();
362
+ const event = createInputActionTraceEvent(metadata);
363
+ if (!event)
364
+ return Promise.resolve();
365
+ this._temporarilyDisableThrottling(sdkObject.attribution.page);
366
+ if (this._shouldCaptureSnapshot(sdkObject, metadata, "input"))
367
+ event.inputSnapshot = `input@${metadata.id}`;
368
+ this._appendTraceEvent(event);
369
+ return this._captureSnapshot(event.inputSnapshot, sdkObject, metadata);
370
+ }
371
+ onCallLog(sdkObject, metadata, logName, message) {
372
+ if (!this._state?.callIds.has(metadata.id))
373
+ return;
374
+ if (metadata.internal)
375
+ return;
376
+ if (logName !== "api")
377
+ return;
378
+ const event = createActionLogTraceEvent(metadata, message);
379
+ if (event)
380
+ this._appendTraceEvent(event);
381
+ }
382
+ onAfterCall(sdkObject, metadata) {
383
+ if (!this._state?.callIds.has(metadata.id))
384
+ return Promise.resolve();
385
+ this._state?.callIds.delete(metadata.id);
386
+ const event = createAfterActionTraceEvent(metadata);
387
+ if (!event)
388
+ return Promise.resolve();
389
+ this._temporarilyDisableThrottling(sdkObject.attribution.page);
390
+ if (this._shouldCaptureSnapshot(sdkObject, metadata, "after"))
391
+ event.afterSnapshot = `after@${metadata.id}`;
392
+ this._appendTraceEvent(event);
393
+ return this._captureSnapshot(event.afterSnapshot, sdkObject, metadata);
394
+ }
395
+ onEntryStarted(entry) {
396
+ this._pendingHarEntries.add(entry);
397
+ }
398
+ onEntryFinished(entry) {
399
+ this._pendingHarEntries.delete(entry);
400
+ const event = { type: "resource-snapshot", snapshot: entry };
401
+ const visited = visitTraceEvent(event, this._state.networkSha1s);
402
+ this._fs.appendFile(
403
+ this._state.networkFile,
404
+ JSON.stringify(visited) + "\n",
405
+ true
406
+ /* flush */
407
+ );
408
+ }
409
+ flushHarEntries() {
410
+ const harLines = [];
411
+ for (const entry of this._pendingHarEntries) {
412
+ const event = { type: "resource-snapshot", snapshot: entry };
413
+ const visited = visitTraceEvent(event, this._state.networkSha1s);
414
+ harLines.push(JSON.stringify(visited));
415
+ }
416
+ this._pendingHarEntries.clear();
417
+ if (harLines.length)
418
+ this._fs.appendFile(
419
+ this._state.networkFile,
420
+ harLines.join("\n") + "\n",
421
+ true
422
+ /* flush */
423
+ );
424
+ }
425
+ onContentBlob(sha1, buffer) {
426
+ this._appendResource(sha1, buffer);
427
+ }
428
+ onSnapshotterBlob(blob) {
429
+ this._appendResource(blob.sha1, blob.buffer);
430
+ }
431
+ onFrameSnapshot(snapshot) {
432
+ this._appendTraceEvent({ type: "frame-snapshot", snapshot });
433
+ }
434
+ _onConsoleMessage(message) {
435
+ const event = {
436
+ type: "console",
437
+ messageType: message.type(),
438
+ text: message.text(),
439
+ args: message.args().map((a) => ({ preview: a.toString(), value: a.rawValue() })),
440
+ location: message.location(),
441
+ time: (0, import_time.monotonicTime)(),
442
+ pageId: message.page()?.guid
443
+ };
444
+ this._appendTraceEvent(event);
445
+ }
446
+ onDialog(dialog) {
447
+ const event = {
448
+ type: "event",
449
+ time: (0, import_time.monotonicTime)(),
450
+ class: "BrowserContext",
451
+ method: "dialog",
452
+ params: { pageId: dialog.page().guid, type: dialog.type(), message: dialog.message(), defaultValue: dialog.defaultValue() }
453
+ };
454
+ this._appendTraceEvent(event);
455
+ }
456
+ onDownload(page, download) {
457
+ const event = {
458
+ type: "event",
459
+ time: (0, import_time.monotonicTime)(),
460
+ class: "BrowserContext",
461
+ method: "download",
462
+ params: { pageId: page.guid, url: download.url, suggestedFilename: download.suggestedFilename() }
463
+ };
464
+ this._appendTraceEvent(event);
465
+ }
466
+ onPageOpen(page) {
467
+ const event = {
468
+ type: "event",
469
+ time: (0, import_time.monotonicTime)(),
470
+ class: "BrowserContext",
471
+ method: "page",
472
+ params: { pageId: page.guid, openerPageId: page.opener()?.guid }
473
+ };
474
+ this._appendTraceEvent(event);
475
+ }
476
+ onPageClose(page) {
477
+ const event = {
478
+ type: "event",
479
+ time: (0, import_time.monotonicTime)(),
480
+ class: "BrowserContext",
481
+ method: "pageClosed",
482
+ params: { pageId: page.guid }
483
+ };
484
+ this._appendTraceEvent(event);
485
+ }
486
+ _onPageError(error, page) {
487
+ const event = {
488
+ type: "event",
489
+ time: (0, import_time.monotonicTime)(),
490
+ class: "BrowserContext",
491
+ method: "pageError",
492
+ params: { error: (0, import_errors.serializeError)(error) },
493
+ pageId: page.guid
494
+ };
495
+ this._appendTraceEvent(event);
496
+ }
497
+ _temporarilyDisableThrottling(page) {
498
+ if (page)
499
+ this._pageTracingRecorders.get(page)?.temporarilyDisableThrottling();
500
+ }
501
+ _startScreencastInPage(page) {
502
+ const prefix = page.guid;
503
+ const onFrame = (params) => {
504
+ const suffix = Date.now();
505
+ const sha1 = `${prefix}-${suffix}.jpeg`;
506
+ const event = {
507
+ type: "screencast-frame",
508
+ pageId: page.guid,
509
+ sha1,
510
+ width: params.viewportWidth,
511
+ height: params.viewportHeight,
512
+ timestamp: (0, import_time.monotonicTime)(),
513
+ frameSwapWallTime: params.frameSwapWallTime
514
+ };
515
+ this._appendResource(sha1, params.buffer);
516
+ this._appendTraceEvent(event);
517
+ };
518
+ this._pageTracingRecorders.set(page, new ScreencastTracingRecorder(page.screencast, onFrame));
519
+ }
520
+ _appendTraceEvent(event) {
521
+ const visited = visitTraceEvent(event, this._state.traceSha1s);
522
+ const flush = this._state.options.live || event.type !== "event" && event.type !== "console" && event.type !== "log";
523
+ this._fs.appendFile(this._state.traceFile, JSON.stringify(visited) + "\n", flush);
524
+ }
525
+ _appendResource(sha1, buffer) {
526
+ if (this._allResources.has(sha1))
527
+ return;
528
+ this._allResources.add(sha1);
529
+ const resourcePath = import_path.default.join(this._state.resourcesDir, sha1);
530
+ this._fs.writeFile(
531
+ resourcePath,
532
+ buffer,
533
+ true
534
+ /* skipIfExists */
535
+ );
536
+ }
537
+ }
538
+ function visitTraceEvent(object, sha1s) {
539
+ if (Array.isArray(object))
540
+ return object.map((o) => visitTraceEvent(o, sha1s));
541
+ if (object instanceof import_dispatcher.Dispatcher)
542
+ return `<${object._type}>`;
543
+ if (object instanceof Buffer)
544
+ return `<Buffer>`;
545
+ if (object instanceof Date)
546
+ return object;
547
+ if (typeof object === "object") {
548
+ const result = {};
549
+ for (const key in object) {
550
+ if (key === "sha1" || key === "_sha1" || key.endsWith("Sha1")) {
551
+ const sha1 = object[key];
552
+ if (sha1)
553
+ sha1s.add(sha1);
554
+ }
555
+ result[key] = visitTraceEvent(object[key], sha1s);
556
+ }
557
+ return result;
558
+ }
559
+ return object;
560
+ }
561
+ function createBeforeActionTraceEvent(metadata, parentId) {
562
+ if (metadata.internal || metadata.method.startsWith("tracing"))
563
+ return null;
564
+ const event = {
565
+ type: "before",
566
+ callId: metadata.id,
567
+ startTime: metadata.startTime,
568
+ title: metadata.title,
569
+ class: metadata.type,
570
+ method: metadata.method,
571
+ params: metadata.params,
572
+ stepId: metadata.stepId,
573
+ pageId: metadata.pageId
574
+ };
575
+ if (parentId)
576
+ event.parentId = parentId;
577
+ return event;
578
+ }
579
+ function createInputActionTraceEvent(metadata) {
580
+ if (metadata.internal || metadata.method.startsWith("tracing"))
581
+ return null;
582
+ return {
583
+ type: "input",
584
+ callId: metadata.id,
585
+ point: metadata.point
586
+ };
587
+ }
588
+ function createActionLogTraceEvent(metadata, message) {
589
+ if (metadata.internal || metadata.method.startsWith("tracing"))
590
+ return null;
591
+ return {
592
+ type: "log",
593
+ callId: metadata.id,
594
+ time: (0, import_time.monotonicTime)(),
595
+ message
596
+ };
597
+ }
598
+ function createAfterActionTraceEvent(metadata) {
599
+ if (metadata.internal || metadata.method.startsWith("tracing"))
600
+ return null;
601
+ return {
602
+ type: "after",
603
+ callId: metadata.id,
604
+ endTime: metadata.endTime,
605
+ error: metadata.error?.error,
606
+ result: metadata.result,
607
+ point: metadata.point
608
+ };
609
+ }
610
+ const throttledRate = 200;
611
+ const unthrottleDuration = 500;
612
+ class ScreencastTracingRecorder {
613
+ constructor(screencast, onFrame) {
614
+ this._unthrottledUntil = 0;
615
+ this._screencast = screencast;
616
+ this._client = {
617
+ onFrame: (frame) => {
618
+ const time = (0, import_time.monotonicTime)();
619
+ if (time < this._unthrottledUntil) {
620
+ onFrame(frame);
621
+ return;
622
+ }
623
+ if (this._pendingAck)
624
+ return;
625
+ onFrame(frame);
626
+ this._pendingAck = new import_manualPromise.ManualPromise();
627
+ this._timer = setTimeout(() => this._clearPendingAck(), throttledRate);
628
+ return this._pendingAck;
629
+ },
630
+ gracefulClose: () => this.dispose(),
631
+ dispose: () => this.dispose()
632
+ };
633
+ this._screencast.addClient(this._client);
634
+ }
635
+ dispose() {
636
+ this._screencast.removeClient(this._client);
637
+ this._clearPendingAck();
638
+ }
639
+ temporarilyDisableThrottling() {
640
+ this._unthrottledUntil = (0, import_time.monotonicTime)() + unthrottleDuration;
641
+ this._clearPendingAck();
642
+ }
643
+ _clearPendingAck() {
644
+ this._pendingAck?.resolve();
645
+ this._pendingAck = void 0;
646
+ if (this._timer) {
647
+ clearTimeout(this._timer);
648
+ this._timer = void 0;
649
+ }
650
+ }
651
+ }
652
+ // Annotate the CommonJS export names for ESM import in node:
653
+ 0 && (module.exports = {
654
+ Tracing
655
+ });