@checkly/playwright-core 1.51.17-beta.2 → 1.54.2-beta.1

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 (376) hide show
  1. package/ThirdPartyNotices.txt +65 -123
  2. package/browsers.json +16 -14
  3. package/index.js +1 -1
  4. package/lib/androidServerImpl.js +47 -50
  5. package/lib/browserServerImpl.js +89 -69
  6. package/lib/checkly/escapeRegExp.js +23 -27
  7. package/lib/checkly/fetch.js +64 -46
  8. package/lib/checkly/secretsFilter.js +49 -35
  9. package/lib/cli/driver.js +71 -69
  10. package/lib/cli/program.js +400 -359
  11. package/lib/cli/programWithTestStub.js +51 -45
  12. package/lib/client/accessibility.js +31 -32
  13. package/lib/client/android.js +151 -242
  14. package/lib/client/api.js +135 -283
  15. package/lib/client/artifact.js +39 -36
  16. package/lib/client/browser.js +96 -71
  17. package/lib/client/browserContext.js +314 -345
  18. package/lib/client/browserType.js +103 -127
  19. package/lib/client/cdpSession.js +29 -31
  20. package/lib/client/channelOwner.js +89 -112
  21. package/lib/client/clientHelper.js +48 -39
  22. package/lib/client/clientInstrumentation.js +40 -37
  23. package/lib/client/clientStackTrace.js +41 -37
  24. package/lib/client/clock.js +36 -36
  25. package/lib/client/connection.js +188 -214
  26. package/lib/client/consoleMessage.js +31 -28
  27. package/lib/client/coverage.js +25 -22
  28. package/lib/client/dialog.js +30 -31
  29. package/lib/client/download.js +25 -25
  30. package/lib/client/electron.js +80 -77
  31. package/lib/client/elementHandle.js +120 -159
  32. package/lib/client/errors.js +53 -53
  33. package/lib/client/eventEmitter.js +124 -121
  34. package/lib/client/events.js +72 -68
  35. package/lib/client/fetch.js +166 -190
  36. package/lib/client/fileChooser.js +25 -24
  37. package/lib/client/fileUtils.js +31 -28
  38. package/lib/client/frame.js +207 -306
  39. package/lib/client/harRouter.js +42 -52
  40. package/lib/client/input.js +42 -69
  41. package/lib/client/jsHandle.js +54 -69
  42. package/lib/client/jsonPipe.js +27 -23
  43. package/lib/client/localUtils.js +29 -29
  44. package/lib/client/locator.js +145 -237
  45. package/lib/client/network.js +282 -307
  46. package/lib/client/page.js +269 -318
  47. package/lib/client/platform.js +46 -43
  48. package/lib/client/playwright.js +51 -76
  49. package/lib/client/selectors.js +45 -63
  50. package/lib/client/stream.js +29 -25
  51. package/lib/client/timeoutSettings.js +55 -41
  52. package/lib/client/tracing.js +49 -96
  53. package/lib/client/types.js +26 -22
  54. package/lib/client/video.js +35 -27
  55. package/lib/client/waiter.js +69 -88
  56. package/lib/client/webError.js +25 -23
  57. package/lib/client/webSocket.js +43 -56
  58. package/lib/client/worker.js +48 -56
  59. package/lib/client/writableStream.js +27 -23
  60. package/lib/generated/bindingsControllerSource.js +28 -0
  61. package/lib/generated/clockSource.js +26 -6
  62. package/lib/generated/consoleApiSource.js +26 -6
  63. package/lib/generated/injectedScriptSource.js +26 -6
  64. package/lib/generated/pollingRecorderSource.js +26 -6
  65. package/lib/generated/storageScriptSource.js +28 -0
  66. package/lib/generated/utilityScriptSource.js +26 -6
  67. package/lib/generated/webSocketMockSource.js +333 -5
  68. package/lib/inProcessFactory.js +51 -53
  69. package/lib/inprocess.js +2 -19
  70. package/lib/outofprocess.js +51 -46
  71. package/lib/protocol/serializers.js +153 -134
  72. package/lib/protocol/validator.js +2807 -2739
  73. package/lib/protocol/validatorPrimitives.js +114 -73
  74. package/lib/remote/playwrightConnection.js +88 -242
  75. package/lib/remote/playwrightServer.js +305 -92
  76. package/lib/server/accessibility.js +44 -37
  77. package/lib/server/android/android.js +251 -241
  78. package/lib/server/android/backendAdb.js +87 -82
  79. package/lib/server/artifact.js +78 -55
  80. package/lib/server/bidi/bidiBrowser.js +297 -158
  81. package/lib/server/bidi/bidiChromium.js +119 -89
  82. package/lib/server/bidi/bidiConnection.js +66 -83
  83. package/lib/server/bidi/bidiExecutionContext.js +129 -113
  84. package/lib/server/bidi/bidiFirefox.js +86 -76
  85. package/lib/server/bidi/bidiInput.js +106 -117
  86. package/lib/server/bidi/bidiNetworkManager.js +142 -159
  87. package/lib/server/bidi/bidiOverCdp.js +57 -58
  88. package/lib/server/bidi/bidiPage.js +260 -260
  89. package/lib/server/bidi/bidiPdf.js +52 -86
  90. package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
  91. package/lib/server/bidi/third_party/bidiDeserializer.js +55 -50
  92. package/lib/server/bidi/third_party/bidiKeyboard.js +236 -220
  93. package/lib/server/bidi/third_party/bidiProtocol.js +22 -137
  94. package/lib/server/bidi/third_party/bidiProtocolCore.js +152 -0
  95. package/lib/server/bidi/third_party/bidiProtocolPermissions.js +42 -0
  96. package/lib/server/bidi/third_party/bidiSerializer.js +67 -63
  97. package/lib/server/bidi/third_party/firefoxPrefs.js +141 -119
  98. package/lib/server/browser.js +93 -95
  99. package/lib/server/browserContext.js +419 -429
  100. package/lib/server/browserType.js +186 -216
  101. package/lib/server/callLog.js +47 -44
  102. package/lib/server/chromium/chromium.js +235 -203
  103. package/lib/server/chromium/chromiumSwitches.js +100 -67
  104. package/lib/server/chromium/crAccessibility.js +157 -131
  105. package/lib/server/chromium/crBrowser.js +310 -292
  106. package/lib/server/chromium/crConnection.js +95 -121
  107. package/lib/server/chromium/crCoverage.js +121 -131
  108. package/lib/server/chromium/crDevTools.js +60 -51
  109. package/lib/server/chromium/crDragDrop.js +68 -84
  110. package/lib/server/chromium/crExecutionContext.js +89 -83
  111. package/lib/server/chromium/crInput.js +118 -113
  112. package/lib/server/chromium/crNetworkManager.js +274 -375
  113. package/lib/server/chromium/crPage.js +536 -593
  114. package/lib/server/chromium/crPdf.js +54 -86
  115. package/lib/server/chromium/crProtocolHelper.js +92 -80
  116. package/lib/server/chromium/crServiceWorker.js +84 -73
  117. package/lib/server/chromium/defaultFontFamilies.js +152 -135
  118. package/lib/server/chromium/protocol.d.js +16 -0
  119. package/lib/server/chromium/videoRecorder.js +66 -99
  120. package/lib/server/clock.js +107 -83
  121. package/lib/server/codegen/csharp.js +192 -162
  122. package/lib/server/codegen/java.js +156 -129
  123. package/lib/server/codegen/javascript.js +163 -148
  124. package/lib/server/codegen/jsonl.js +32 -28
  125. package/lib/server/codegen/language.js +75 -52
  126. package/lib/server/codegen/languages.js +65 -27
  127. package/lib/server/codegen/python.js +141 -126
  128. package/lib/server/codegen/types.js +15 -4
  129. package/lib/server/console.js +28 -32
  130. package/lib/server/cookieStore.js +108 -86
  131. package/lib/server/debugController.js +147 -151
  132. package/lib/server/debugger.js +86 -78
  133. package/lib/server/deviceDescriptors.js +37 -24
  134. package/lib/server/deviceDescriptorsSource.json +238 -128
  135. package/lib/server/dialog.js +84 -39
  136. package/lib/server/dispatchers/androidDispatcher.js +257 -148
  137. package/lib/server/dispatchers/artifactDispatcher.js +79 -79
  138. package/lib/server/dispatchers/browserContextDispatcher.js +289 -259
  139. package/lib/server/dispatchers/browserDispatcher.js +96 -148
  140. package/lib/server/dispatchers/browserTypeDispatcher.js +50 -41
  141. package/lib/server/dispatchers/cdpSessionDispatcher.js +35 -39
  142. package/lib/server/dispatchers/debugControllerDispatcher.js +65 -83
  143. package/lib/server/dispatchers/dialogDispatcher.js +34 -31
  144. package/lib/server/dispatchers/dispatcher.js +208 -248
  145. package/lib/server/dispatchers/electronDispatcher.js +66 -70
  146. package/lib/server/dispatchers/elementHandlerDispatcher.js +164 -216
  147. package/lib/server/dispatchers/frameDispatcher.js +211 -272
  148. package/lib/server/dispatchers/jsHandleDispatcher.js +63 -75
  149. package/lib/server/dispatchers/jsonPipeDispatcher.js +37 -38
  150. package/lib/server/dispatchers/localUtilsDispatcher.js +121 -119
  151. package/lib/server/dispatchers/networkDispatchers.js +117 -128
  152. package/lib/server/dispatchers/pageDispatcher.js +256 -248
  153. package/lib/server/dispatchers/playwrightDispatcher.js +92 -87
  154. package/lib/server/dispatchers/streamDispatcher.js +52 -48
  155. package/lib/server/dispatchers/tracingDispatcher.js +47 -52
  156. package/lib/server/dispatchers/webSocketRouteDispatcher.js +126 -150
  157. package/lib/server/dispatchers/writableStreamDispatcher.js +65 -43
  158. package/lib/server/dom.js +485 -582
  159. package/lib/server/download.js +47 -37
  160. package/lib/server/electron/electron.js +216 -243
  161. package/lib/server/electron/loader.js +9 -37
  162. package/lib/server/errors.js +47 -46
  163. package/lib/server/fetch.js +317 -360
  164. package/lib/server/fileChooser.js +25 -24
  165. package/lib/server/fileUploadUtils.js +66 -60
  166. package/lib/server/firefox/ffAccessibility.js +153 -131
  167. package/lib/server/firefox/ffBrowser.js +268 -305
  168. package/lib/server/firefox/ffConnection.js +63 -84
  169. package/lib/server/firefox/ffExecutionContext.js +92 -73
  170. package/lib/server/firefox/ffInput.js +82 -84
  171. package/lib/server/firefox/ffNetworkManager.js +137 -114
  172. package/lib/server/firefox/ffPage.js +261 -293
  173. package/lib/server/firefox/firefox.js +80 -72
  174. package/lib/server/firefox/protocol.d.js +16 -0
  175. package/lib/server/formData.js +107 -35
  176. package/lib/server/frameSelectors.js +98 -114
  177. package/lib/server/frames.js +845 -1055
  178. package/lib/server/har/harRecorder.js +85 -77
  179. package/lib/server/har/harTracer.js +290 -223
  180. package/lib/server/harBackend.js +80 -80
  181. package/lib/server/helper.js +55 -59
  182. package/lib/server/index.js +59 -99
  183. package/lib/server/input.js +151 -189
  184. package/lib/server/instrumentation.js +57 -44
  185. package/lib/server/javascript.js +133 -134
  186. package/lib/server/launchApp.js +113 -75
  187. package/lib/server/localUtils.js +150 -142
  188. package/lib/server/macEditingCommands.js +141 -137
  189. package/lib/server/network.js +299 -303
  190. package/lib/server/page.js +513 -544
  191. package/lib/server/pipeTransport.js +49 -45
  192. package/lib/server/playwright.js +58 -67
  193. package/lib/server/progress.js +137 -68
  194. package/lib/server/protocolError.js +34 -31
  195. package/lib/server/recorder/chat.js +70 -86
  196. package/lib/server/recorder/recorderApp.js +341 -176
  197. package/lib/server/recorder/recorderInTraceViewer.js +65 -94
  198. package/lib/server/recorder/recorderRunner.js +93 -116
  199. package/lib/server/recorder/recorderSignalProcessor.js +83 -0
  200. package/lib/server/recorder/recorderUtils.js +104 -47
  201. package/lib/server/recorder/throttledFile.js +42 -30
  202. package/lib/server/recorder.js +395 -275
  203. package/lib/server/registry/browserFetcher.js +106 -101
  204. package/lib/server/registry/dependencies.js +245 -196
  205. package/lib/server/registry/index.js +930 -803
  206. package/lib/server/registry/nativeDeps.js +1073 -464
  207. package/lib/server/registry/oopDownloadBrowserMain.js +57 -75
  208. package/lib/server/screenshotter.js +160 -191
  209. package/lib/server/selectors.js +90 -51
  210. package/lib/server/socksClientCertificatesInterceptor.js +171 -186
  211. package/lib/server/socksInterceptor.js +62 -70
  212. package/lib/server/trace/recorder/snapshotter.js +76 -102
  213. package/lib/server/trace/recorder/snapshotterInjected.js +238 -217
  214. package/lib/server/trace/recorder/tracing.js +354 -362
  215. package/lib/server/trace/test/inMemorySnapshotter.js +46 -52
  216. package/lib/server/trace/viewer/traceViewer.js +160 -147
  217. package/lib/server/transport.js +119 -134
  218. package/lib/server/types.js +26 -22
  219. package/lib/server/usKeyboardLayout.js +135 -545
  220. package/lib/server/utils/ascii.js +39 -26
  221. package/lib/server/utils/comparators.js +105 -103
  222. package/lib/server/utils/crypto.js +157 -112
  223. package/lib/server/utils/debug.js +36 -32
  224. package/lib/server/utils/debugLogger.js +77 -48
  225. package/lib/server/utils/env.js +52 -37
  226. package/lib/server/utils/eventsHelper.js +29 -28
  227. package/lib/server/utils/expectUtils.js +31 -26
  228. package/lib/server/utils/fileUtils.js +123 -136
  229. package/lib/server/utils/happyEyeballs.js +141 -126
  230. package/lib/server/utils/hostPlatform.js +84 -120
  231. package/lib/server/utils/httpServer.js +106 -121
  232. package/lib/server/utils/image_tools/colorUtils.js +42 -51
  233. package/lib/server/utils/image_tools/compare.js +44 -43
  234. package/lib/server/utils/image_tools/imageChannel.js +38 -30
  235. package/lib/server/utils/image_tools/stats.js +40 -40
  236. package/lib/server/utils/linuxUtils.js +50 -37
  237. package/lib/server/utils/network.js +152 -96
  238. package/lib/server/utils/nodePlatform.js +87 -79
  239. package/lib/server/utils/pipeTransport.js +44 -42
  240. package/lib/server/utils/processLauncher.js +111 -121
  241. package/lib/server/utils/profiler.js +52 -39
  242. package/lib/server/utils/socksProxy.js +280 -339
  243. package/lib/server/utils/spawnAsync.js +37 -41
  244. package/lib/server/utils/task.js +31 -38
  245. package/lib/server/utils/userAgent.js +73 -66
  246. package/lib/server/utils/wsServer.js +68 -75
  247. package/lib/server/utils/zipFile.js +36 -37
  248. package/lib/server/utils/zones.js +37 -34
  249. package/lib/server/webkit/protocol.d.js +16 -0
  250. package/lib/server/webkit/webkit.js +77 -61
  251. package/lib/server/webkit/wkAccessibility.js +161 -118
  252. package/lib/server/webkit/wkBrowser.js +193 -184
  253. package/lib/server/webkit/wkConnection.js +59 -83
  254. package/lib/server/webkit/wkExecutionContext.js +85 -70
  255. package/lib/server/webkit/wkInput.js +97 -95
  256. package/lib/server/webkit/wkInterceptableRequest.js +102 -95
  257. package/lib/server/webkit/wkPage.js +568 -667
  258. package/lib/server/webkit/wkProvisionalPage.js +45 -56
  259. package/lib/server/webkit/wkWorkers.js +79 -79
  260. package/lib/utils/expectUtils.js +31 -26
  261. package/lib/utils/isomorphic/ariaSnapshot.js +149 -152
  262. package/lib/utils/isomorphic/assert.js +28 -22
  263. package/lib/utils/isomorphic/colors.js +66 -59
  264. package/lib/utils/isomorphic/cssParser.js +120 -125
  265. package/lib/utils/isomorphic/cssTokenizer.js +436 -364
  266. package/lib/utils/isomorphic/headers.js +38 -37
  267. package/lib/utils/isomorphic/locatorGenerators.js +358 -357
  268. package/lib/utils/isomorphic/locatorParser.js +96 -105
  269. package/lib/utils/isomorphic/locatorUtils.js +63 -44
  270. package/lib/utils/isomorphic/manualPromise.js +46 -39
  271. package/lib/utils/isomorphic/mimeType.js +447 -25
  272. package/lib/utils/isomorphic/multimap.js +34 -27
  273. package/lib/utils/isomorphic/protocolFormatter.js +68 -0
  274. package/lib/utils/isomorphic/protocolMetainfo.js +321 -0
  275. package/lib/utils/isomorphic/recorderUtils.js +140 -181
  276. package/lib/utils/isomorphic/rtti.js +35 -33
  277. package/lib/utils/isomorphic/selectorParser.js +182 -193
  278. package/lib/utils/isomorphic/semaphore.js +27 -24
  279. package/lib/utils/isomorphic/stackTrace.js +87 -98
  280. package/lib/utils/isomorphic/stringUtils.js +98 -112
  281. package/lib/utils/isomorphic/time.js +46 -22
  282. package/lib/utils/isomorphic/timeoutRunner.js +53 -53
  283. package/lib/utils/isomorphic/traceUtils.js +37 -41
  284. package/lib/utils/isomorphic/types.js +15 -4
  285. package/lib/utils/isomorphic/urlMatch.js +113 -67
  286. package/lib/utils/isomorphic/utilityScriptSerializers.js +251 -0
  287. package/lib/utils.js +101 -443
  288. package/lib/utilsBundle.js +101 -52
  289. package/lib/utilsBundleImpl/index.js +160 -150
  290. package/lib/zipBundle.js +32 -23
  291. package/lib/zipBundleImpl.js +4 -4
  292. package/package.json +1 -1
  293. package/types/protocol.d.ts +1267 -1057
  294. package/types/types.d.ts +131 -29
  295. package/lib/common/socksProxy.js +0 -569
  296. package/lib/common/timeoutSettings.js +0 -73
  297. package/lib/common/types.js +0 -5
  298. package/lib/image_tools/colorUtils.js +0 -98
  299. package/lib/image_tools/compare.js +0 -108
  300. package/lib/image_tools/imageChannel.js +0 -70
  301. package/lib/image_tools/stats.js +0 -102
  302. package/lib/protocol/debug.js +0 -27
  303. package/lib/protocol/transport.js +0 -82
  304. package/lib/server/dispatchers/selectorsDispatcher.js +0 -36
  305. package/lib/server/isomorphic/utilityScriptSerializers.js +0 -229
  306. package/lib/server/recorder/contextRecorder.js +0 -290
  307. package/lib/server/recorder/recorderCollection.js +0 -104
  308. package/lib/server/recorder/recorderFrontend.js +0 -5
  309. package/lib/server/storageScript.js +0 -160
  310. package/lib/server/timeoutSettings.js +0 -74
  311. package/lib/third_party/diff_match_patch.js +0 -2222
  312. package/lib/utils/ascii.js +0 -31
  313. package/lib/utils/comparators.js +0 -171
  314. package/lib/utils/crypto.js +0 -174
  315. package/lib/utils/debug.js +0 -46
  316. package/lib/utils/debugLogger.js +0 -91
  317. package/lib/utils/env.js +0 -49
  318. package/lib/utils/eventsHelper.js +0 -38
  319. package/lib/utils/fileUtils.js +0 -205
  320. package/lib/utils/happy-eyeballs.js +0 -210
  321. package/lib/utils/headers.js +0 -52
  322. package/lib/utils/hostPlatform.js +0 -133
  323. package/lib/utils/httpServer.js +0 -237
  324. package/lib/utils/index.js +0 -368
  325. package/lib/utils/linuxUtils.js +0 -78
  326. package/lib/utils/manualPromise.js +0 -109
  327. package/lib/utils/multimap.js +0 -75
  328. package/lib/utils/network.js +0 -160
  329. package/lib/utils/processLauncher.js +0 -248
  330. package/lib/utils/profiler.js +0 -53
  331. package/lib/utils/rtti.js +0 -44
  332. package/lib/utils/semaphore.js +0 -51
  333. package/lib/utils/spawnAsync.js +0 -45
  334. package/lib/utils/stackTrace.js +0 -121
  335. package/lib/utils/task.js +0 -58
  336. package/lib/utils/time.js +0 -37
  337. package/lib/utils/timeoutRunner.js +0 -66
  338. package/lib/utils/traceUtils.js +0 -44
  339. package/lib/utils/userAgent.js +0 -105
  340. package/lib/utils/wsServer.js +0 -127
  341. package/lib/utils/zipFile.js +0 -75
  342. package/lib/utils/zones.js +0 -62
  343. package/lib/vite/htmlReport/index.html +0 -69
  344. package/lib/vite/recorder/assets/codeMirrorModule-B9YMkrwa.js +0 -24
  345. package/lib/vite/recorder/assets/codeMirrorModule-C3UTv-Ge.css +0 -1
  346. package/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
  347. package/lib/vite/recorder/assets/index-ELPgmkwA.js +0 -184
  348. package/lib/vite/recorder/assets/index-eHBmevrY.css +0 -1
  349. package/lib/vite/recorder/index.html +0 -29
  350. package/lib/vite/recorder/playwright-logo.svg +0 -9
  351. package/lib/vite/traceViewer/assets/codeMirrorModule-gU1OOCQO.js +0 -24
  352. package/lib/vite/traceViewer/assets/defaultSettingsView-B5n_FjMx.js +0 -1
  353. package/lib/vite/traceViewer/assets/inspectorTab-6Tru8Mn_.js +0 -235
  354. package/lib/vite/traceViewer/assets/workbench-B_Nj4NA2.js +0 -25
  355. package/lib/vite/traceViewer/assets/xtermModule-BoAIEibi.js +0 -9
  356. package/lib/vite/traceViewer/codeMirrorModule.C3UTv-Ge.css +0 -1
  357. package/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
  358. package/lib/vite/traceViewer/defaultSettingsView.CO3FR0CX.css +0 -1
  359. package/lib/vite/traceViewer/embedded.DpNPH6mk.js +0 -2
  360. package/lib/vite/traceViewer/embedded.html +0 -18
  361. package/lib/vite/traceViewer/embedded.mLhjB5IF.css +0 -1
  362. package/lib/vite/traceViewer/index.CFOW-Ezb.css +0 -1
  363. package/lib/vite/traceViewer/index.CuE3SYGw.js +0 -2
  364. package/lib/vite/traceViewer/index.html +0 -47
  365. package/lib/vite/traceViewer/inspectorTab.CXDulcFG.css +0 -1
  366. package/lib/vite/traceViewer/playwright-logo.svg +0 -9
  367. package/lib/vite/traceViewer/recorder.BD-uZJs7.js +0 -2
  368. package/lib/vite/traceViewer/recorder.html +0 -17
  369. package/lib/vite/traceViewer/recorder.tn0RQdqM.css +0 -0
  370. package/lib/vite/traceViewer/snapshot.html +0 -21
  371. package/lib/vite/traceViewer/sw.bundle.js +0 -3
  372. package/lib/vite/traceViewer/uiMode.BatfzHMG.css +0 -1
  373. package/lib/vite/traceViewer/uiMode.DHrNgddz.js +0 -5
  374. package/lib/vite/traceViewer/uiMode.html +0 -21
  375. package/lib/vite/traceViewer/workbench.B9vIAzH9.css +0 -1
  376. package/lib/vite/traceViewer/xtermModule.Beg8tuEN.css +0 -32
@@ -1,265 +1,270 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Tracing = void 0;
7
- exports.shouldCaptureSnapshot = shouldCaptureSnapshot;
8
- var _fs = _interopRequireDefault(require("fs"));
9
- var _os = _interopRequireDefault(require("os"));
10
- var _path = _interopRequireDefault(require("path"));
11
- var _snapshotter = require("./snapshotter");
12
- var _debug = require("../../../protocol/debug");
13
- var _assert = require("../../../utils/isomorphic/assert");
14
- var _time = require("../../../utils/isomorphic/time");
15
- var _eventsHelper = require("../../utils/eventsHelper");
16
- var _crypto = require("../../utils/crypto");
17
- var _artifact = require("../../artifact");
18
- var _browserContext = require("../../browserContext");
19
- var _dispatcher = require("../../dispatchers/dispatcher");
20
- var _errors = require("../../errors");
21
- var _fileUtils = require("../../utils/fileUtils");
22
- var _harTracer = require("../../har/harTracer");
23
- var _instrumentation = require("../../instrumentation");
24
- var _page = require("../../page");
25
- var _secretsFilter = require("../../../checkly/secretsFilter");
26
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
27
- /**
28
- * Copyright (c) Microsoft Corporation.
29
- *
30
- * Licensed under the Apache License, Version 2.0 (the "License");
31
- * you may not use this file except in compliance with the License.
32
- * You may obtain a copy of the License at
33
- *
34
- * http://www.apache.org/licenses/LICENSE-2.0
35
- *
36
- * Unless required by applicable law or agreed to in writing, software
37
- * distributed under the License is distributed on an "AS IS" BASIS,
38
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39
- * See the License for the specific language governing permissions and
40
- * limitations under the License.
41
- */
42
-
43
- const version = 7;
44
- const kScreencastOptions = {
45
- width: 800,
46
- height: 600,
47
- quality: 90
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;
48
19
  };
49
- class Tracing extends _instrumentation.SdkObject {
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
+ shouldCaptureSnapshot: () => shouldCaptureSnapshot
33
+ });
34
+ module.exports = __toCommonJS(tracing_exports);
35
+ var import_fs = __toESM(require("fs"));
36
+ var import_os = __toESM(require("os"));
37
+ var import_path = __toESM(require("path"));
38
+ var import_snapshotter = require("./snapshotter");
39
+ var import_protocolMetainfo = require("../../../utils/isomorphic/protocolMetainfo");
40
+ var import_assert = require("../../../utils/isomorphic/assert");
41
+ var import_time = require("../../../utils/isomorphic/time");
42
+ var import_eventsHelper = require("../../utils/eventsHelper");
43
+ var import_crypto = require("../../utils/crypto");
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_secretsFilter = require("../../../checkly/secretsFilter");
53
+ var import_progress = require("../../progress");
54
+ const version = 8;
55
+ const kScreencastOptions = { width: 800, height: 600, quality: 90 };
56
+ class Tracing extends import_instrumentation.SdkObject {
50
57
  constructor(context, tracesDir) {
51
- super(context, 'tracing');
52
- this._fs = new _fileUtils.SerializedFS();
53
- this._snapshotter = void 0;
54
- this._harTracer = void 0;
58
+ super(context, "tracing");
59
+ this._fs = new import_fileUtils.SerializedFS();
55
60
  this._screencastListeners = [];
56
61
  this._eventListeners = [];
57
- this._context = void 0;
58
- // Note: state should only be touched inside API methods, but not inside trace operations.
59
- this._state = void 0;
60
62
  this._isStopping = false;
61
- this._precreatedTracesDir = void 0;
62
- this._tracesTmpDir = void 0;
63
- this._allResources = new Set();
64
- this._contextCreatedEvent = void 0;
65
- this._pendingHarEntries = new Set();
66
- this._secretsFilter = void 0;
63
+ this._allResources = /* @__PURE__ */ new Set();
64
+ this._pendingHarEntries = /* @__PURE__ */ new Set();
67
65
  this._context = context;
68
66
  this._precreatedTracesDir = tracesDir;
69
- this._secretsFilter = (0, _secretsFilter.secretsFilter)();
70
- this._harTracer = new _harTracer.HarTracer(context, null, this, {
71
- content: 'attach',
67
+ this._secretsFilter = (0, import_secretsFilter.secretsFilter)();
68
+ this._harTracer = new import_harTracer.HarTracer(context, null, this, {
69
+ content: "attach",
72
70
  includeTraceInfo: true,
73
71
  recordRequestOverrides: false,
74
72
  waitForContentOnStop: false
75
73
  });
76
- const testIdAttributeName = 'selectors' in context ? context.selectors().testIdAttributeName() : undefined;
74
+ const testIdAttributeName = "selectors" in context ? context.selectors().testIdAttributeName() : void 0;
77
75
  this._contextCreatedEvent = {
78
76
  version,
79
- type: 'context-options',
80
- origin: 'library',
81
- browserName: '',
77
+ type: "context-options",
78
+ origin: "library",
79
+ browserName: "",
82
80
  options: {},
83
81
  platform: process.platform,
84
82
  wallTime: 0,
85
83
  monotonicTime: 0,
86
- sdkLanguage: context.attribution.playwright.options.sdkLanguage,
84
+ sdkLanguage: this._sdkLanguage(),
87
85
  testIdAttributeName,
88
86
  contextId: context.guid
89
87
  };
90
- if (context instanceof _browserContext.BrowserContext) {
91
- this._snapshotter = new _snapshotter.Snapshotter(context, this);
92
- (0, _assert.assert)(tracesDir, 'tracesDir must be specified for BrowserContext');
88
+ if (context instanceof import_browserContext.BrowserContext) {
89
+ this._snapshotter = new import_snapshotter.Snapshotter(context, this);
90
+ (0, import_assert.assert)(tracesDir, "tracesDir must be specified for BrowserContext");
93
91
  this._contextCreatedEvent.browserName = context._browser.options.name;
94
92
  this._contextCreatedEvent.channel = context._browser.options.channel;
95
93
  this._contextCreatedEvent.options = context._options;
96
94
  }
97
95
  }
98
- async resetForReuse() {
99
- var _this$_snapshotter;
100
- // Discard previous chunk if any and ignore any errors there.
101
- await this.stopChunk({
102
- mode: 'discard'
103
- }).catch(() => {});
104
- await this.stop();
105
- (_this$_snapshotter = this._snapshotter) === null || _this$_snapshotter === void 0 || _this$_snapshotter.resetForReuse();
106
- }
107
- async start(options) {
108
- if (this._isStopping) throw new Error('Cannot start tracing while stopping');
109
- if (this._state) throw new Error('Tracing has been already started');
110
-
111
- // Re-write for testing.
112
- this._contextCreatedEvent.sdkLanguage = this._context.attribution.playwright.options.sdkLanguage;
113
-
114
- // TODO: passing the same name for two contexts makes them write into a single file
115
- // and conflict.
116
- const traceName = options.name || (0, _crypto.createGuid)();
96
+ _sdkLanguage() {
97
+ return this._context instanceof import_browserContext.BrowserContext ? this._context._browser.sdkLanguage() : this._context.attribution.playwright.options.sdkLanguage;
98
+ }
99
+ async resetForReuse(progress) {
100
+ await this.stopChunk(progress, { mode: "discard" }).catch(() => {
101
+ });
102
+ await this.stop(progress);
103
+ if (this._snapshotter)
104
+ await progress.race(this._snapshotter.resetForReuse());
105
+ }
106
+ start(options) {
107
+ if (this._isStopping)
108
+ throw new Error("Cannot start tracing while stopping");
109
+ if (this._state)
110
+ throw new Error("Tracing has been already started");
111
+ this._contextCreatedEvent.sdkLanguage = this._sdkLanguage();
112
+ const traceName = options.name || (0, import_crypto.createGuid)();
117
113
  const tracesDir = this._createTracesDirIfNeeded();
118
-
119
- // Init the state synchronously.
120
114
  this._state = {
121
115
  options,
122
116
  traceName,
123
117
  tracesDir,
124
- traceFile: _path.default.join(tracesDir, traceName + '.trace'),
125
- networkFile: _path.default.join(tracesDir, traceName + '.network'),
126
- resourcesDir: _path.default.join(tracesDir, 'resources'),
118
+ traceFile: import_path.default.join(tracesDir, traceName + ".trace"),
119
+ networkFile: import_path.default.join(tracesDir, traceName + ".network"),
120
+ resourcesDir: import_path.default.join(tracesDir, "resources"),
127
121
  chunkOrdinal: 0,
128
- traceSha1s: new Set(),
129
- networkSha1s: new Set(),
122
+ traceSha1s: /* @__PURE__ */ new Set(),
123
+ networkSha1s: /* @__PURE__ */ new Set(),
130
124
  recording: false,
131
- callIds: new Set(),
125
+ callIds: /* @__PURE__ */ new Set(),
132
126
  groupStack: []
133
127
  };
134
128
  this._fs.mkdir(this._state.resourcesDir);
135
- this._fs.writeFile(this._state.networkFile, '');
136
- // Tracing is 10x bigger if we include scripts in every trace.
137
- if (options.snapshots) this._harTracer.start({
138
- omitScripts: !options.live
139
- });
140
- }
141
- async startChunk(options = {}) {
142
- var _this$_snapshotter2;
143
- if (this._state && this._state.recording) await this.stopChunk({
144
- mode: 'discard'
145
- });
146
- if (!this._state) throw new Error('Must start tracing before starting a new chunk');
147
- if (this._isStopping) throw new Error('Cannot start a trace chunk while stopping');
129
+ this._fs.writeFile(this._state.networkFile, "");
130
+ if (options.snapshots)
131
+ this._harTracer.start({ omitScripts: !options.live });
132
+ }
133
+ async startChunk(progress, options = {}) {
134
+ if (this._state && this._state.recording)
135
+ await this.stopChunk(progress, { mode: "discard" });
136
+ if (!this._state)
137
+ throw new Error("Must start tracing before starting a new chunk");
138
+ if (this._isStopping)
139
+ throw new Error("Cannot start a trace chunk while stopping");
148
140
  this._state.recording = true;
149
141
  this._state.callIds.clear();
150
-
151
- // - Browser context network trace is shared across chunks as it contains resources
152
- // used to serve page snapshots, so make a copy with the new name.
153
- // - APIRequestContext network traces are chunk-specific, always start from scratch.
154
- const preserveNetworkResources = this._context instanceof _browserContext.BrowserContext;
155
- if (options.name && options.name !== this._state.traceName) this._changeTraceName(this._state, options.name, preserveNetworkResources);else this._allocateNewTraceFile(this._state);
156
- if (!preserveNetworkResources) this._fs.writeFile(this._state.networkFile, '');
157
- this._fs.mkdir(_path.default.dirname(this._state.traceFile));
142
+ const preserveNetworkResources = this._context instanceof import_browserContext.BrowserContext;
143
+ if (options.name && options.name !== this._state.traceName)
144
+ this._changeTraceName(this._state, options.name, preserveNetworkResources);
145
+ else
146
+ this._allocateNewTraceFile(this._state);
147
+ if (!preserveNetworkResources)
148
+ this._fs.writeFile(this._state.networkFile, "");
149
+ this._fs.mkdir(import_path.default.dirname(this._state.traceFile));
158
150
  const event = {
159
151
  ...this._contextCreatedEvent,
160
152
  title: options.title,
161
153
  wallTime: Date.now(),
162
- monotonicTime: (0, _time.monotonicTime)()
154
+ monotonicTime: (0, import_time.monotonicTime)()
163
155
  };
164
156
  this._appendTraceEvent(event);
165
157
  this._context.instrumentation.addListener(this, this._context);
166
- this._eventListeners.push(_eventsHelper.eventsHelper.addEventListener(this._context, _browserContext.BrowserContext.Events.Console, this._onConsoleMessage.bind(this)), _eventsHelper.eventsHelper.addEventListener(this._context, _browserContext.BrowserContext.Events.PageError, this._onPageError.bind(this)));
167
- if (this._state.options.screenshots) this._startScreencast();
168
- if (this._state.options.snapshots) await ((_this$_snapshotter2 = this._snapshotter) === null || _this$_snapshotter2 === void 0 ? void 0 : _this$_snapshotter2.start());
169
- return {
170
- traceName: this._state.traceName
171
- };
158
+ this._eventListeners.push(
159
+ import_eventsHelper.eventsHelper.addEventListener(this._context, import_browserContext.BrowserContext.Events.Console, this._onConsoleMessage.bind(this)),
160
+ import_eventsHelper.eventsHelper.addEventListener(this._context, import_browserContext.BrowserContext.Events.PageError, this._onPageError.bind(this))
161
+ );
162
+ if (this._state.options.screenshots)
163
+ this._startScreencast();
164
+ if (this._state.options.snapshots)
165
+ await this._snapshotter?.start();
166
+ return { traceName: this._state.traceName };
172
167
  }
173
168
  _currentGroupId() {
174
- var _this$_state;
175
- return (_this$_state = this._state) !== null && _this$_state !== void 0 && _this$_state.groupStack.length ? this._state.groupStack[this._state.groupStack.length - 1] : undefined;
169
+ return this._state?.groupStack.length ? this._state.groupStack[this._state.groupStack.length - 1] : void 0;
176
170
  }
177
- async group(name, location, metadata) {
178
- var _ref;
179
- if (!this._state) return;
171
+ group(name, location, metadata) {
172
+ if (!this._state)
173
+ return;
180
174
  const stackFrames = [];
181
- const {
182
- file,
183
- line,
184
- column
185
- } = (_ref = location !== null && location !== void 0 ? location : metadata.location) !== null && _ref !== void 0 ? _ref : {};
175
+ const { file, line, column } = location ?? metadata.location ?? {};
186
176
  if (file) {
187
177
  stackFrames.push({
188
178
  file,
189
- line: line !== null && line !== void 0 ? line : 0,
190
- column: column !== null && column !== void 0 ? column : 0
179
+ line: line ?? 0,
180
+ column: column ?? 0
191
181
  });
192
182
  }
193
183
  const event = {
194
- type: 'before',
184
+ type: "before",
195
185
  callId: metadata.id,
196
186
  startTime: metadata.startTime,
197
- apiName: name,
198
- class: 'Tracing',
199
- method: 'tracingGroup',
187
+ title: name,
188
+ class: "Tracing",
189
+ method: "tracingGroup",
200
190
  params: {},
201
191
  stepId: metadata.stepId,
202
192
  stack: stackFrames
203
193
  };
204
- if (this._currentGroupId()) event.parentId = this._currentGroupId();
194
+ if (this._currentGroupId())
195
+ event.parentId = this._currentGroupId();
205
196
  this._state.groupStack.push(event.callId);
206
197
  this._appendTraceEvent(event);
207
198
  }
208
199
  groupEnd() {
209
- if (!this._state) return;
200
+ if (!this._state)
201
+ return;
210
202
  const callId = this._state.groupStack.pop();
211
- if (!callId) return;
203
+ if (!callId)
204
+ return;
212
205
  const event = {
213
- type: 'after',
206
+ type: "after",
214
207
  callId,
215
- endTime: (0, _time.monotonicTime)()
208
+ endTime: (0, import_time.monotonicTime)()
216
209
  };
217
210
  this._appendTraceEvent(event);
218
211
  }
219
212
  _startScreencast() {
220
- if (!(this._context instanceof _browserContext.BrowserContext)) return;
221
- for (const page of this._context.pages()) this._startScreencastInPage(page);
222
- this._screencastListeners.push(_eventsHelper.eventsHelper.addEventListener(this._context, _browserContext.BrowserContext.Events.Page, this._startScreencastInPage.bind(this)));
213
+ if (!(this._context instanceof import_browserContext.BrowserContext))
214
+ return;
215
+ for (const page of this._context.pages())
216
+ this._startScreencastInPage(page);
217
+ this._screencastListeners.push(
218
+ import_eventsHelper.eventsHelper.addEventListener(this._context, import_browserContext.BrowserContext.Events.Page, this._startScreencastInPage.bind(this))
219
+ );
223
220
  }
224
221
  _stopScreencast() {
225
- _eventsHelper.eventsHelper.removeEventListeners(this._screencastListeners);
226
- if (!(this._context instanceof _browserContext.BrowserContext)) return;
227
- for (const page of this._context.pages()) page.setScreencastOptions(null);
222
+ import_eventsHelper.eventsHelper.removeEventListeners(this._screencastListeners);
223
+ if (!(this._context instanceof import_browserContext.BrowserContext))
224
+ return;
225
+ for (const page of this._context.pages())
226
+ page.setScreencastOptions(null);
228
227
  }
229
228
  _allocateNewTraceFile(state) {
230
229
  const suffix = state.chunkOrdinal ? `-chunk${state.chunkOrdinal}` : ``;
231
230
  state.chunkOrdinal++;
232
- state.traceFile = _path.default.join(state.tracesDir, `${state.traceName}${suffix}.trace`);
231
+ state.traceFile = import_path.default.join(state.tracesDir, `${state.traceName}${suffix}.trace`);
233
232
  }
234
233
  _changeTraceName(state, name, preserveNetworkResources) {
235
234
  state.traceName = name;
236
- state.chunkOrdinal = 0; // Reset ordinal for the new name.
235
+ state.chunkOrdinal = 0;
237
236
  this._allocateNewTraceFile(state);
238
- const newNetworkFile = _path.default.join(state.tracesDir, name + '.network');
239
- if (preserveNetworkResources) this._fs.copyFile(state.networkFile, newNetworkFile);
237
+ const newNetworkFile = import_path.default.join(state.tracesDir, name + ".network");
238
+ if (preserveNetworkResources)
239
+ this._fs.copyFile(state.networkFile, newNetworkFile);
240
240
  state.networkFile = newNetworkFile;
241
241
  }
242
- async stop() {
243
- if (!this._state) return;
244
- if (this._isStopping) throw new Error(`Tracing is already stopping`);
245
- if (this._state.recording) throw new Error(`Must stop trace file before stopping tracing`);
242
+ async stop(progress) {
243
+ if (!this._state)
244
+ return;
245
+ if (this._isStopping)
246
+ throw new Error(`Tracing is already stopping`);
247
+ if (this._state.recording)
248
+ throw new Error(`Must stop trace file before stopping tracing`);
246
249
  this._closeAllGroups();
247
250
  this._harTracer.stop();
248
251
  this.flushHarEntries();
249
- await this._fs.syncAndGetError();
250
- this._state = undefined;
252
+ await progress.race(this._fs.syncAndGetError()).finally(() => {
253
+ this._state = void 0;
254
+ });
251
255
  }
252
256
  async deleteTmpTracesDir() {
253
- if (this._tracesTmpDir) await (0, _fileUtils.removeFolders)([this._tracesTmpDir]);
257
+ if (this._tracesTmpDir)
258
+ await (0, import_fileUtils.removeFolders)([this._tracesTmpDir]);
254
259
  }
255
260
  _createTracesDirIfNeeded() {
256
- if (this._precreatedTracesDir) return this._precreatedTracesDir;
257
- this._tracesTmpDir = _fs.default.mkdtempSync(_path.default.join(_os.default.tmpdir(), 'playwright-tracing-'));
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-"));
258
264
  return this._tracesTmpDir;
259
265
  }
260
266
  abort() {
261
- var _this$_snapshotter3;
262
- (_this$_snapshotter3 = this._snapshotter) === null || _this$_snapshotter3 === void 0 || _this$_snapshotter3.dispose();
267
+ this._snapshotter?.dispose();
263
268
  this._harTracer.stop();
264
269
  }
265
270
  async flush() {
@@ -267,120 +272,108 @@ class Tracing extends _instrumentation.SdkObject {
267
272
  await this._fs.syncAndGetError();
268
273
  }
269
274
  _closeAllGroups() {
270
- while (this._currentGroupId()) this.groupEnd();
275
+ while (this._currentGroupId())
276
+ this.groupEnd();
271
277
  }
272
- async stopChunk(params) {
273
- var _this$_snapshotter4;
274
- if (this._isStopping) throw new Error(`Tracing is already stopping`);
278
+ async stopChunk(progress, params) {
279
+ if (this._isStopping)
280
+ throw new Error(`Tracing is already stopping`);
275
281
  this._isStopping = true;
276
282
  if (!this._state || !this._state.recording) {
277
283
  this._isStopping = false;
278
- if (params.mode !== 'discard') throw new Error(`Must start tracing before stopping`);
284
+ if (params.mode !== "discard")
285
+ throw new Error(`Must start tracing before stopping`);
279
286
  return {};
280
287
  }
281
288
  this._closeAllGroups();
282
289
  this._context.instrumentation.removeListener(this);
283
- _eventsHelper.eventsHelper.removeEventListeners(this._eventListeners);
284
- if (this._state.options.screenshots) this._stopScreencast();
285
- if (this._state.options.snapshots) await ((_this$_snapshotter4 = this._snapshotter) === null || _this$_snapshotter4 === void 0 ? void 0 : _this$_snapshotter4.stop());
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();
286
295
  this.flushHarEntries();
287
-
288
- // Network file survives across chunks, make a snapshot before returning the resulting entries.
289
- // We should pick a name starting with "traceName" and ending with .network.
290
- // Something like <traceName>someSuffixHere.network.
291
- // However, this name must not clash with any other "traceName".network in the same tracesDir.
292
- // We can use <traceName>-<guid>.network, but "-pwnetcopy-0" suffix is more readable
293
- // and makes it easier to debug future issues.
294
- const newNetworkFile = _path.default.join(this._state.tracesDir, this._state.traceName + `-pwnetcopy-${this._state.chunkOrdinal}.network`);
296
+ const newNetworkFile = import_path.default.join(this._state.tracesDir, this._state.traceName + `-pwnetcopy-${this._state.chunkOrdinal}.network`);
295
297
  const entries = [];
296
- entries.push({
297
- name: 'trace.trace',
298
- value: this._state.traceFile
299
- });
300
- entries.push({
301
- name: 'trace.network',
302
- value: newNetworkFile
303
- });
304
- for (const sha1 of new Set([...this._state.traceSha1s, ...this._state.networkSha1s])) entries.push({
305
- name: _path.default.join('resources', sha1),
306
- value: _path.default.join(this._state.resourcesDir, sha1)
307
- });
308
-
309
- // Only reset trace sha1s, network resources are preserved between chunks.
310
- this._state.traceSha1s = new Set();
311
- if (params.mode === 'discard') {
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") {
312
304
  this._isStopping = false;
313
305
  this._state.recording = false;
314
306
  return {};
315
307
  }
316
308
  this._fs.copyFile(this._state.networkFile, newNetworkFile);
317
- const zipFileName = this._state.traceFile + '.zip';
318
- if (params.mode === 'archive') this._fs.zip(entries, zipFileName);
319
-
320
- // Make sure all file operations complete.
321
- const error = await this._fs.syncAndGetError();
309
+ const zipFileName = this._state.traceFile + ".zip";
310
+ if (params.mode === "archive")
311
+ this._fs.zip(entries, zipFileName);
312
+ const error = await progress.race(this._fs.syncAndGetError()).catch((e) => e);
322
313
  this._isStopping = false;
323
- if (this._state) this._state.recording = false;
324
-
325
- // IMPORTANT: no awaits after this point, to make sure recording state is correct.
326
-
314
+ if (this._state)
315
+ this._state.recording = false;
327
316
  if (error) {
328
- // This check is here because closing the browser removes the tracesDir and tracing
329
- // cannot access removed files. Clients are ready for the missing artifact.
330
- if (this._context instanceof _browserContext.BrowserContext && !this._context._browser.isConnected()) return {};
317
+ if (!(0, import_progress.isAbortError)(error) && this._context instanceof import_browserContext.BrowserContext && !this._context._browser.isConnected())
318
+ return {};
331
319
  throw error;
332
320
  }
333
- if (params.mode === 'entries') return {
334
- entries
335
- };
336
- const artifact = new _artifact.Artifact(this._context, zipFileName);
321
+ if (params.mode === "entries")
322
+ return { entries };
323
+ const artifact = new import_artifact.Artifact(this._context, zipFileName);
337
324
  artifact.reportFinished();
338
- return {
339
- artifact
340
- };
325
+ return { artifact };
341
326
  }
342
327
  async _captureSnapshot(snapshotName, sdkObject, metadata) {
343
- if (!this._snapshotter) return;
344
- if (!sdkObject.attribution.page) return;
345
- if (!this._snapshotter.started()) return;
346
- if (!shouldCaptureSnapshot(metadata)) return;
347
- await this._snapshotter.captureSnapshot(sdkObject.attribution.page, metadata.id, snapshotName).catch(() => {});
328
+ if (!this._snapshotter)
329
+ return;
330
+ if (!sdkObject.attribution.page)
331
+ return;
332
+ if (!this._snapshotter.started())
333
+ return;
334
+ if (!shouldCaptureSnapshot(metadata))
335
+ return;
336
+ await this._snapshotter.captureSnapshot(sdkObject.attribution.page, metadata.id, snapshotName).catch(() => {
337
+ });
348
338
  }
349
339
  onBeforeCall(sdkObject, metadata) {
350
- var _sdkObject$attributio, _this$_state2;
351
- // IMPORTANT: no awaits before this._appendTraceEvent in this method.
352
340
  const event = createBeforeActionTraceEvent(metadata, this._currentGroupId());
353
- if (!event) return Promise.resolve();
354
- (_sdkObject$attributio = sdkObject.attribution.page) === null || _sdkObject$attributio === void 0 || _sdkObject$attributio.temporarilyDisableTracingScreencastThrottling();
341
+ if (!event)
342
+ return Promise.resolve();
343
+ sdkObject.attribution.page?.temporarilyDisableTracingScreencastThrottling();
355
344
  event.beforeSnapshot = `before@${metadata.id}`;
356
- (_this$_state2 = this._state) === null || _this$_state2 === void 0 || _this$_state2.callIds.add(metadata.id);
345
+ this._state?.callIds.add(metadata.id);
357
346
  this._appendTraceEvent(event);
358
347
  return this._captureSnapshot(event.beforeSnapshot, sdkObject, metadata);
359
348
  }
360
349
  onBeforeInputAction(sdkObject, metadata) {
361
- var _this$_state3, _sdkObject$attributio2;
362
- if (!((_this$_state3 = this._state) !== null && _this$_state3 !== void 0 && _this$_state3.callIds.has(metadata.id))) return Promise.resolve();
363
- // IMPORTANT: no awaits before this._appendTraceEvent in this method.
350
+ if (!this._state?.callIds.has(metadata.id))
351
+ return Promise.resolve();
364
352
  const event = createInputActionTraceEvent(metadata);
365
- if (!event) return Promise.resolve();
366
- (_sdkObject$attributio2 = sdkObject.attribution.page) === null || _sdkObject$attributio2 === void 0 || _sdkObject$attributio2.temporarilyDisableTracingScreencastThrottling();
353
+ if (!event)
354
+ return Promise.resolve();
355
+ sdkObject.attribution.page?.temporarilyDisableTracingScreencastThrottling();
367
356
  event.inputSnapshot = `input@${metadata.id}`;
368
357
  this._appendTraceEvent(event);
369
358
  return this._captureSnapshot(event.inputSnapshot, sdkObject, metadata);
370
359
  }
371
360
  onCallLog(sdkObject, metadata, logName, message) {
372
- if (metadata.isServerSide || metadata.internal) return;
373
- if (logName !== 'api') return;
361
+ if (metadata.isServerSide || metadata.internal)
362
+ return;
363
+ if (logName !== "api")
364
+ return;
374
365
  const event = createActionLogTraceEvent(metadata, message);
375
- if (event) this._appendTraceEvent(event);
366
+ if (event)
367
+ this._appendTraceEvent(event);
376
368
  }
377
369
  async onAfterCall(sdkObject, metadata) {
378
- var _this$_state4, _this$_state5, _sdkObject$attributio3;
379
- if (!((_this$_state4 = this._state) !== null && _this$_state4 !== void 0 && _this$_state4.callIds.has(metadata.id))) return;
380
- (_this$_state5 = this._state) === null || _this$_state5 === void 0 || _this$_state5.callIds.delete(metadata.id);
370
+ if (!this._state?.callIds.has(metadata.id))
371
+ return;
372
+ this._state?.callIds.delete(metadata.id);
381
373
  const event = createAfterActionTraceEvent(metadata);
382
- if (!event) return;
383
- (_sdkObject$attributio3 = sdkObject.attribution.page) === null || _sdkObject$attributio3 === void 0 || _sdkObject$attributio3.temporarilyDisableTracingScreencastThrottling();
374
+ if (!event)
375
+ return;
376
+ sdkObject.attribution.page?.temporarilyDisableTracingScreencastThrottling();
384
377
  event.afterSnapshot = `after@${metadata.id}`;
385
378
  this._appendTraceEvent(event);
386
379
  return this._captureSnapshot(event.afterSnapshot, sdkObject, metadata);
@@ -390,25 +383,30 @@ class Tracing extends _instrumentation.SdkObject {
390
383
  }
391
384
  onEntryFinished(entry) {
392
385
  this._pendingHarEntries.delete(entry);
393
- const event = {
394
- type: 'resource-snapshot',
395
- snapshot: entry
396
- };
386
+ const event = { type: "resource-snapshot", snapshot: entry };
397
387
  const visited = visitTraceEvent(event, this._state.networkSha1s, this._secretsFilter);
398
- this._fs.appendFile(this._state.networkFile, JSON.stringify(visited) + '\n', true /* flush */);
388
+ this._fs.appendFile(
389
+ this._state.networkFile,
390
+ JSON.stringify(visited) + "\n",
391
+ true
392
+ /* flush */
393
+ );
399
394
  }
400
395
  flushHarEntries() {
401
396
  const harLines = [];
402
397
  for (const entry of this._pendingHarEntries) {
403
- const event = {
404
- type: 'resource-snapshot',
405
- snapshot: entry
406
- };
398
+ const event = { type: "resource-snapshot", snapshot: entry };
407
399
  const visited = visitTraceEvent(event, this._state.networkSha1s, this._secretsFilter);
408
400
  harLines.push(JSON.stringify(visited));
409
401
  }
410
402
  this._pendingHarEntries.clear();
411
- if (harLines.length) this._fs.appendFile(this._state.networkFile, harLines.join('\n') + '\n', true /* flush */);
403
+ if (harLines.length)
404
+ this._fs.appendFile(
405
+ this._state.networkFile,
406
+ harLines.join("\n") + "\n",
407
+ true
408
+ /* flush */
409
+ );
412
410
  }
413
411
  onContentBlob(sha1, buffer) {
414
412
  this._appendResource(sha1, buffer);
@@ -417,91 +415,67 @@ class Tracing extends _instrumentation.SdkObject {
417
415
  this._appendResource(blob.sha1, blob.buffer);
418
416
  }
419
417
  onFrameSnapshot(snapshot) {
420
- this._appendTraceEvent({
421
- type: 'frame-snapshot',
422
- snapshot
423
- });
418
+ this._appendTraceEvent({ type: "frame-snapshot", snapshot });
424
419
  }
425
420
  _onConsoleMessage(message) {
426
- var _message$page;
427
421
  const event = {
428
- type: 'console',
422
+ type: "console",
429
423
  messageType: message.type(),
430
424
  text: message.text(),
431
- args: message.args().map(a => ({
432
- preview: a.toString(),
433
- value: a.rawValue()
434
- })),
425
+ args: message.args().map((a) => ({ preview: a.toString(), value: a.rawValue() })),
435
426
  location: message.location(),
436
- time: (0, _time.monotonicTime)(),
437
- pageId: (_message$page = message.page()) === null || _message$page === void 0 ? void 0 : _message$page.guid
427
+ time: (0, import_time.monotonicTime)(),
428
+ pageId: message.page()?.guid
438
429
  };
439
430
  this._appendTraceEvent(event);
440
431
  }
441
432
  onDialog(dialog) {
442
433
  const event = {
443
- type: 'event',
444
- time: (0, _time.monotonicTime)(),
445
- class: 'BrowserContext',
446
- method: 'dialog',
447
- params: {
448
- pageId: dialog.page().guid,
449
- type: dialog.type(),
450
- message: dialog.message(),
451
- defaultValue: dialog.defaultValue()
452
- }
434
+ type: "event",
435
+ time: (0, import_time.monotonicTime)(),
436
+ class: "BrowserContext",
437
+ method: "dialog",
438
+ params: { pageId: dialog.page().guid, type: dialog.type(), message: dialog.message(), defaultValue: dialog.defaultValue() }
453
439
  };
454
440
  this._appendTraceEvent(event);
455
441
  }
456
442
  onDownload(page, download) {
457
443
  const event = {
458
- type: 'event',
459
- time: (0, _time.monotonicTime)(),
460
- class: 'BrowserContext',
461
- method: 'download',
462
- params: {
463
- pageId: page.guid,
464
- url: download.url,
465
- suggestedFilename: download.suggestedFilename()
466
- }
444
+ type: "event",
445
+ time: (0, import_time.monotonicTime)(),
446
+ class: "BrowserContext",
447
+ method: "download",
448
+ params: { pageId: page.guid, url: download.url, suggestedFilename: download.suggestedFilename() }
467
449
  };
468
450
  this._appendTraceEvent(event);
469
451
  }
470
452
  onPageOpen(page) {
471
- var _page$opener;
472
453
  const event = {
473
- type: 'event',
474
- time: (0, _time.monotonicTime)(),
475
- class: 'BrowserContext',
476
- method: 'page',
477
- params: {
478
- pageId: page.guid,
479
- openerPageId: (_page$opener = page.opener()) === null || _page$opener === void 0 ? void 0 : _page$opener.guid
480
- }
454
+ type: "event",
455
+ time: (0, import_time.monotonicTime)(),
456
+ class: "BrowserContext",
457
+ method: "page",
458
+ params: { pageId: page.guid, openerPageId: page.opener()?.guid }
481
459
  };
482
460
  this._appendTraceEvent(event);
483
461
  }
484
462
  onPageClose(page) {
485
463
  const event = {
486
- type: 'event',
487
- time: (0, _time.monotonicTime)(),
488
- class: 'BrowserContext',
489
- method: 'pageClosed',
490
- params: {
491
- pageId: page.guid
492
- }
464
+ type: "event",
465
+ time: (0, import_time.monotonicTime)(),
466
+ class: "BrowserContext",
467
+ method: "pageClosed",
468
+ params: { pageId: page.guid }
493
469
  };
494
470
  this._appendTraceEvent(event);
495
471
  }
496
472
  _onPageError(error, page) {
497
473
  const event = {
498
- type: 'event',
499
- time: (0, _time.monotonicTime)(),
500
- class: 'BrowserContext',
501
- method: 'pageError',
502
- params: {
503
- error: (0, _errors.serializeError)(error)
504
- },
474
+ type: "event",
475
+ time: (0, import_time.monotonicTime)(),
476
+ class: "BrowserContext",
477
+ method: "pageError",
478
+ params: { error: (0, import_errors.serializeError)(error) },
505
479
  pageId: page.guid
506
480
  };
507
481
  this._appendTraceEvent(event);
@@ -509,60 +483,68 @@ class Tracing extends _instrumentation.SdkObject {
509
483
  _startScreencastInPage(page) {
510
484
  page.setScreencastOptions(kScreencastOptions);
511
485
  const prefix = page.guid;
512
- this._screencastListeners.push(_eventsHelper.eventsHelper.addEventListener(page, _page.Page.Events.ScreencastFrame, params => {
513
- const suffix = params.timestamp || Date.now();
514
- const sha1 = `${prefix}-${suffix}.jpeg`;
515
- const event = {
516
- type: 'screencast-frame',
517
- pageId: page.guid,
518
- sha1,
519
- width: params.width,
520
- height: params.height,
521
- timestamp: (0, _time.monotonicTime)(),
522
- frameSwapWallTime: params.frameSwapWallTime
523
- };
524
- // Make sure to write the screencast frame before adding a reference to it.
525
- this._appendResource(sha1, params.buffer);
526
- this._appendTraceEvent(event);
527
- }));
486
+ this._screencastListeners.push(
487
+ import_eventsHelper.eventsHelper.addEventListener(page, import_page.Page.Events.ScreencastFrame, (params) => {
488
+ const suffix = params.timestamp || Date.now();
489
+ const sha1 = `${prefix}-${suffix}.jpeg`;
490
+ const event = {
491
+ type: "screencast-frame",
492
+ pageId: page.guid,
493
+ sha1,
494
+ width: params.width,
495
+ height: params.height,
496
+ timestamp: (0, import_time.monotonicTime)(),
497
+ frameSwapWallTime: params.frameSwapWallTime
498
+ };
499
+ this._appendResource(sha1, params.buffer);
500
+ this._appendTraceEvent(event);
501
+ })
502
+ );
528
503
  }
529
504
  _appendTraceEvent(event) {
530
505
  const visited = visitTraceEvent(event, this._state.traceSha1s, this._secretsFilter);
531
- // Do not flush (console) events, they are too noisy, unless we are in ui mode (live).
532
- const flush = this._state.options.live || event.type !== 'event' && event.type !== 'console' && event.type !== 'log';
533
- this._fs.appendFile(this._state.traceFile, JSON.stringify(visited) + '\n', flush);
506
+ const flush = this._state.options.live || event.type !== "event" && event.type !== "console" && event.type !== "log";
507
+ this._fs.appendFile(this._state.traceFile, JSON.stringify(visited) + "\n", flush);
534
508
  }
535
509
  _appendResource(sha1, buffer) {
536
- if (this._allResources.has(sha1)) return;
510
+ if (this._allResources.has(sha1))
511
+ return;
537
512
  this._allResources.add(sha1);
538
- const resourcePath = _path.default.join(this._state.resourcesDir, sha1);
539
- this._fs.writeFile(resourcePath, buffer, true /* skipIfExists */);
513
+ const resourcePath = import_path.default.join(this._state.resourcesDir, sha1);
514
+ this._fs.writeFile(
515
+ resourcePath,
516
+ buffer,
517
+ true
518
+ /* skipIfExists */
519
+ );
540
520
  }
541
521
  }
542
- exports.Tracing = Tracing;
543
- function visitTraceEvent(object, sha1s, secretsFilter) {
544
- if (Array.isArray(object)) return object.map(o => {
545
- if (typeof o === 'string' && new Date(o).toString() === 'Invalid Date') {
546
- return secretsFilter(o);
547
- }
548
- return visitTraceEvent(o, sha1s, secretsFilter);
549
- });
550
- if (object instanceof _dispatcher.Dispatcher) return `<${object._type}>`;
551
- if (object instanceof Buffer) return `<Buffer>`;
552
- if (object instanceof Date) return object;
553
- if (typeof object === 'object') {
522
+ function visitTraceEvent(object, sha1s, secretsFilter2) {
523
+ if (Array.isArray(object)) {
524
+ return object.map((o) => {
525
+ if (typeof o === "string" && new Date(o).toString() === "Invalid Date")
526
+ return secretsFilter2(o);
527
+ return visitTraceEvent(o, sha1s, secretsFilter2);
528
+ });
529
+ }
530
+ if (object instanceof import_dispatcher.Dispatcher)
531
+ return `<${object._type}>`;
532
+ if (object instanceof Buffer)
533
+ return `<Buffer>`;
534
+ if (object instanceof Date)
535
+ return object;
536
+ if (typeof object === "object") {
554
537
  const result = {};
555
538
  for (const key in object) {
556
539
  const value = object[key];
557
- if (key === 'sha1' || key === '_sha1' || key.endsWith('Sha1')) {
558
- if (value) sha1s.add(value);
540
+ if (key === "sha1" || key === "_sha1" || key.endsWith("Sha1")) {
541
+ if (value)
542
+ sha1s.add(value);
559
543
  }
560
- if (typeof value === 'string') {
561
- // Some values like numbers or certain strings shouldn't be scrubbed,
562
- // Otherwise parts of the trace will be unreadable.
563
- result[key] = key.endsWith('Sha1') || ['pageref', '_sha1', 'downloadsPath', 'tracesDir', 'pageId', 'sha1'].includes(key) ? value : secretsFilter(value);
544
+ if (typeof value === "string") {
545
+ result[key] = key.endsWith("Sha1") || ["pageref", "_sha1", "downloadsPath", "tracesDir", "pageId", "sha1"].includes(key) ? value : secretsFilter2(value);
564
546
  } else {
565
- result[key] = visitTraceEvent(value, sha1s, secretsFilter);
547
+ result[key] = visitTraceEvent(value, sha1s, secretsFilter2);
566
548
  }
567
549
  }
568
550
  return result;
@@ -570,50 +552,60 @@ function visitTraceEvent(object, sha1s, secretsFilter) {
570
552
  return object;
571
553
  }
572
554
  function shouldCaptureSnapshot(metadata) {
573
- return _debug.commandsWithTracingSnapshots.has(metadata.type + '.' + metadata.method);
555
+ const metainfo = import_protocolMetainfo.methodMetainfo.get(metadata.type + "." + metadata.method);
556
+ return !!metainfo?.snapshot;
574
557
  }
575
558
  function createBeforeActionTraceEvent(metadata, parentId) {
576
- if (metadata.internal || metadata.method.startsWith('tracing')) return null;
559
+ if (metadata.internal || metadata.method.startsWith("tracing"))
560
+ return null;
577
561
  const event = {
578
- type: 'before',
562
+ type: "before",
579
563
  callId: metadata.id,
580
564
  startTime: metadata.startTime,
581
- apiName: metadata.apiName || metadata.type + '.' + metadata.method,
565
+ title: metadata.title,
582
566
  class: metadata.type,
583
567
  method: metadata.method,
584
568
  params: metadata.params,
585
569
  stepId: metadata.stepId,
586
570
  pageId: metadata.pageId
587
571
  };
588
- if (parentId) event.parentId = parentId;
572
+ if (parentId)
573
+ event.parentId = parentId;
589
574
  return event;
590
575
  }
591
576
  function createInputActionTraceEvent(metadata) {
592
- if (metadata.internal || metadata.method.startsWith('tracing')) return null;
577
+ if (metadata.internal || metadata.method.startsWith("tracing"))
578
+ return null;
593
579
  return {
594
- type: 'input',
580
+ type: "input",
595
581
  callId: metadata.id,
596
582
  point: metadata.point
597
583
  };
598
584
  }
599
585
  function createActionLogTraceEvent(metadata, message) {
600
- if (metadata.internal || metadata.method.startsWith('tracing')) return null;
586
+ if (metadata.internal || metadata.method.startsWith("tracing"))
587
+ return null;
601
588
  return {
602
- type: 'log',
589
+ type: "log",
603
590
  callId: metadata.id,
604
- time: (0, _time.monotonicTime)(),
591
+ time: (0, import_time.monotonicTime)(),
605
592
  message
606
593
  };
607
594
  }
608
595
  function createAfterActionTraceEvent(metadata) {
609
- var _metadata$error;
610
- if (metadata.internal || metadata.method.startsWith('tracing')) return null;
596
+ if (metadata.internal || metadata.method.startsWith("tracing"))
597
+ return null;
611
598
  return {
612
- type: 'after',
599
+ type: "after",
613
600
  callId: metadata.id,
614
601
  endTime: metadata.endTime,
615
- error: (_metadata$error = metadata.error) === null || _metadata$error === void 0 ? void 0 : _metadata$error.error,
602
+ error: metadata.error?.error,
616
603
  result: metadata.result,
617
604
  point: metadata.point
618
605
  };
619
- }
606
+ }
607
+ // Annotate the CommonJS export names for ESM import in node:
608
+ 0 && (module.exports = {
609
+ Tracing,
610
+ shouldCaptureSnapshot
611
+ });