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