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