patchright-core 1.58.2 → 1.59.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/ThirdPartyNotices.txt +126 -650
  2. package/browsers.json +16 -14
  3. package/lib/bootstrap.js +77 -0
  4. package/lib/cli/browserActions.js +308 -0
  5. package/lib/cli/driver.js +3 -2
  6. package/lib/cli/installActions.js +171 -0
  7. package/lib/cli/program.js +47 -411
  8. package/lib/client/android.js +4 -4
  9. package/lib/client/api.js +3 -3
  10. package/lib/client/browser.js +8 -0
  11. package/lib/client/browserContext.js +22 -61
  12. package/lib/client/browserType.js +19 -51
  13. package/lib/client/cdpSession.js +6 -2
  14. package/lib/client/channelOwner.js +1 -1
  15. package/lib/client/clientHelper.js +2 -1
  16. package/lib/client/clock.js +0 -1
  17. package/lib/client/{webSocket.js → connect.js} +57 -7
  18. package/lib/client/connection.js +8 -4
  19. package/lib/client/consoleMessage.js +3 -0
  20. package/lib/client/debugger.js +57 -0
  21. package/lib/client/dialog.js +8 -1
  22. package/lib/client/disposable.js +76 -0
  23. package/lib/client/electron.js +1 -0
  24. package/lib/client/elementHandle.js +1 -4
  25. package/lib/client/events.js +3 -3
  26. package/lib/client/fetch.js +0 -1
  27. package/lib/client/frame.js +10 -23
  28. package/lib/client/harRouter.js +13 -1
  29. package/lib/client/jsHandle.js +4 -8
  30. package/lib/client/locator.js +13 -44
  31. package/lib/client/network.js +15 -16
  32. package/lib/client/page.js +41 -75
  33. package/lib/client/platform.js +0 -3
  34. package/lib/client/screencast.js +88 -0
  35. package/lib/client/selectors.js +3 -1
  36. package/lib/client/tracing.js +11 -5
  37. package/lib/client/video.js +13 -20
  38. package/lib/client/worker.js +6 -6
  39. package/lib/generated/bindingsControllerSource.js +1 -1
  40. package/lib/generated/clockSource.js +1 -1
  41. package/lib/generated/injectedScriptSource.js +1 -1
  42. package/lib/generated/pollingRecorderSource.js +1 -1
  43. package/lib/generated/storageScriptSource.js +1 -1
  44. package/lib/generated/utilityScriptSource.js +1 -1
  45. package/lib/mcpBundle.js +0 -6
  46. package/lib/mcpBundleImpl.js +91 -0
  47. package/lib/protocol/validator.js +224 -138
  48. package/lib/protocol/validatorPrimitives.js +1 -1
  49. package/lib/remote/playwrightConnection.js +10 -8
  50. package/lib/remote/playwrightPipeServer.js +100 -0
  51. package/lib/remote/playwrightServer.js +13 -8
  52. package/lib/remote/playwrightWebSocketServer.js +73 -0
  53. package/lib/remote/serverTransport.js +96 -0
  54. package/lib/server/android/android.js +2 -2
  55. package/lib/server/bidi/bidiBrowser.js +30 -8
  56. package/lib/server/bidi/bidiChromium.js +18 -5
  57. package/lib/server/bidi/bidiNetworkManager.js +39 -11
  58. package/lib/server/bidi/bidiPage.js +31 -15
  59. package/lib/server/bidi/third_party/firefoxPrefs.js +3 -1
  60. package/lib/server/browser.js +84 -21
  61. package/lib/server/browserContext.js +110 -58
  62. package/lib/server/browserType.js +14 -12
  63. package/lib/server/chromium/chromium.js +15 -12
  64. package/lib/server/chromium/chromiumSwitches.js +14 -2
  65. package/lib/server/chromium/crBrowser.js +20 -17
  66. package/lib/server/chromium/crCoverage.js +1 -13
  67. package/lib/server/chromium/crDevTools.js +1 -0
  68. package/lib/server/chromium/crNetworkManager.js +12 -267
  69. package/lib/server/chromium/crPage.js +67 -199
  70. package/lib/server/chromium/crServiceWorker.js +7 -14
  71. package/lib/server/clock.js +33 -41
  72. package/lib/server/console.js +5 -1
  73. package/lib/server/debugController.js +12 -6
  74. package/lib/server/debugger.js +40 -47
  75. package/lib/server/deviceDescriptorsSource.json +137 -137
  76. package/lib/server/dispatchers/browserContextDispatcher.js +29 -30
  77. package/lib/server/dispatchers/browserDispatcher.js +11 -5
  78. package/lib/server/dispatchers/browserTypeDispatcher.js +7 -0
  79. package/lib/server/dispatchers/cdpSessionDispatcher.js +4 -1
  80. package/lib/server/dispatchers/debuggerDispatcher.js +84 -0
  81. package/lib/server/dispatchers/dispatcher.js +1 -1
  82. package/lib/server/dispatchers/disposableDispatcher.js +39 -0
  83. package/lib/server/dispatchers/electronDispatcher.js +2 -1
  84. package/lib/server/dispatchers/frameDispatcher.js +6 -6
  85. package/lib/server/dispatchers/jsHandleDispatcher.js +2 -2
  86. package/lib/server/dispatchers/localUtilsDispatcher.js +37 -1
  87. package/lib/server/dispatchers/networkDispatchers.js +6 -5
  88. package/lib/server/dispatchers/pageDispatcher.js +101 -38
  89. package/lib/server/dispatchers/webSocketRouteDispatcher.js +4 -5
  90. package/lib/server/disposable.js +41 -0
  91. package/lib/server/dom.js +44 -26
  92. package/lib/server/download.js +3 -2
  93. package/lib/server/electron/electron.js +12 -7
  94. package/lib/server/firefox/ffBrowser.js +9 -19
  95. package/lib/server/firefox/ffInput.js +21 -5
  96. package/lib/server/firefox/ffNetworkManager.js +2 -2
  97. package/lib/server/firefox/ffPage.js +24 -27
  98. package/lib/server/frameSelectors.js +5 -172
  99. package/lib/server/frames.js +234 -687
  100. package/lib/server/har/harRecorder.js +2 -2
  101. package/lib/server/har/harTracer.js +5 -4
  102. package/lib/server/input.js +49 -4
  103. package/lib/server/instrumentation.js +5 -0
  104. package/lib/server/javascript.js +6 -26
  105. package/lib/server/launchApp.js +1 -3
  106. package/lib/server/localUtils.js +6 -6
  107. package/lib/server/network.js +9 -8
  108. package/lib/server/overlay.js +138 -0
  109. package/lib/server/page.js +157 -105
  110. package/lib/server/progress.js +6 -0
  111. package/lib/server/recorder/recorderApp.js +9 -8
  112. package/lib/server/recorder.js +76 -40
  113. package/lib/server/registry/index.js +55 -82
  114. package/lib/server/registry/nativeDeps.js +1 -0
  115. package/lib/server/screencast.js +90 -143
  116. package/lib/server/screenshotter.js +0 -6
  117. package/lib/server/trace/recorder/snapshotter.js +8 -17
  118. package/lib/server/trace/recorder/snapshotterInjected.js +82 -20
  119. package/lib/server/trace/recorder/tracing.js +87 -44
  120. package/lib/server/trace/viewer/traceViewer.js +3 -4
  121. package/lib/server/usKeyboardLayout.js +7 -0
  122. package/lib/server/utils/comparators.js +1 -1
  123. package/lib/server/utils/disposable.js +32 -0
  124. package/lib/server/utils/eventsHelper.js +3 -1
  125. package/lib/server/utils/fileUtils.js +16 -2
  126. package/lib/server/utils/happyEyeballs.js +15 -12
  127. package/lib/server/utils/hostPlatform.js +0 -15
  128. package/lib/server/utils/httpServer.js +5 -3
  129. package/lib/server/utils/network.js +2 -1
  130. package/lib/server/utils/nodePlatform.js +0 -6
  131. package/lib/server/utils/processLauncher.js +6 -5
  132. package/lib/server/utils/zipFile.js +2 -2
  133. package/lib/server/videoRecorder.js +82 -12
  134. package/lib/server/webkit/wkBrowser.js +1 -6
  135. package/lib/server/webkit/wkPage.js +27 -25
  136. package/lib/server/webkit/wkWorkers.js +2 -1
  137. package/lib/serverRegistry.js +156 -0
  138. package/lib/tools/backend/browserBackend.js +79 -0
  139. package/lib/tools/backend/common.js +63 -0
  140. package/lib/tools/backend/config.js +41 -0
  141. package/lib/tools/backend/console.js +66 -0
  142. package/lib/tools/backend/context.js +296 -0
  143. package/lib/tools/backend/cookies.js +152 -0
  144. package/lib/tools/backend/devtools.js +69 -0
  145. package/lib/tools/backend/dialogs.js +59 -0
  146. package/lib/tools/backend/evaluate.js +64 -0
  147. package/lib/tools/backend/files.js +60 -0
  148. package/lib/tools/backend/form.js +64 -0
  149. package/lib/tools/backend/keyboard.js +155 -0
  150. package/lib/tools/backend/logFile.js +95 -0
  151. package/lib/tools/backend/mouse.js +168 -0
  152. package/lib/tools/backend/navigate.js +106 -0
  153. package/lib/tools/backend/network.js +135 -0
  154. package/lib/tools/backend/pdf.js +48 -0
  155. package/lib/tools/backend/response.js +305 -0
  156. package/lib/tools/backend/route.js +140 -0
  157. package/lib/tools/backend/runCode.js +77 -0
  158. package/lib/tools/backend/screenshot.js +88 -0
  159. package/lib/tools/backend/sessionLog.js +74 -0
  160. package/lib/tools/backend/snapshot.js +208 -0
  161. package/lib/tools/backend/storage.js +68 -0
  162. package/lib/tools/backend/tab.js +445 -0
  163. package/lib/tools/backend/tabs.js +67 -0
  164. package/lib/tools/backend/tool.js +47 -0
  165. package/lib/tools/backend/tools.js +102 -0
  166. package/lib/tools/backend/tracing.js +78 -0
  167. package/lib/tools/backend/utils.js +83 -0
  168. package/lib/tools/backend/verify.js +151 -0
  169. package/lib/tools/backend/video.js +98 -0
  170. package/lib/tools/backend/wait.js +63 -0
  171. package/lib/tools/backend/webstorage.js +223 -0
  172. package/lib/tools/cli-client/cli.js +6 -0
  173. package/lib/tools/cli-client/help.json +399 -0
  174. package/lib/tools/cli-client/minimist.js +128 -0
  175. package/lib/tools/cli-client/program.js +350 -0
  176. package/lib/tools/cli-client/registry.js +176 -0
  177. package/lib/tools/cli-client/session.js +289 -0
  178. package/lib/tools/cli-client/skill/SKILL.md +328 -0
  179. package/lib/tools/cli-client/skill/references/element-attributes.md +23 -0
  180. package/lib/tools/cli-client/skill/references/playwright-tests.md +39 -0
  181. package/lib/tools/cli-client/skill/references/request-mocking.md +87 -0
  182. package/lib/tools/cli-client/skill/references/running-code.md +231 -0
  183. package/lib/tools/cli-client/skill/references/session-management.md +169 -0
  184. package/lib/tools/cli-client/skill/references/storage-state.md +275 -0
  185. package/lib/tools/cli-client/skill/references/test-generation.md +88 -0
  186. package/lib/tools/cli-client/skill/references/tracing.md +139 -0
  187. package/lib/tools/cli-client/skill/references/video-recording.md +143 -0
  188. package/lib/tools/cli-daemon/command.js +73 -0
  189. package/lib/tools/cli-daemon/commands.js +956 -0
  190. package/lib/tools/cli-daemon/daemon.js +157 -0
  191. package/lib/tools/cli-daemon/helpGenerator.js +177 -0
  192. package/lib/tools/cli-daemon/program.js +129 -0
  193. package/lib/tools/dashboard/appIcon.png +0 -0
  194. package/lib/tools/dashboard/dashboardApp.js +284 -0
  195. package/lib/tools/dashboard/dashboardController.js +296 -0
  196. package/lib/tools/exports.js +60 -0
  197. package/lib/tools/mcp/browserFactory.js +233 -0
  198. package/lib/tools/mcp/cdpRelay.js +352 -0
  199. package/lib/tools/mcp/cli-stub.js +7 -0
  200. package/lib/tools/mcp/config.d.js +16 -0
  201. package/lib/tools/mcp/config.js +446 -0
  202. package/lib/tools/mcp/configIni.js +189 -0
  203. package/lib/tools/mcp/extensionContextFactory.js +55 -0
  204. package/lib/tools/mcp/index.js +62 -0
  205. package/lib/tools/mcp/log.js +35 -0
  206. package/lib/tools/mcp/program.js +107 -0
  207. package/lib/tools/mcp/protocol.js +28 -0
  208. package/lib/tools/mcp/watchdog.js +44 -0
  209. package/lib/tools/trace/SKILL.md +171 -0
  210. package/lib/{server/trace/viewer/traceParser.js → tools/trace/installSkill.js} +15 -39
  211. package/lib/tools/trace/traceActions.js +142 -0
  212. package/lib/tools/trace/traceAttachments.js +69 -0
  213. package/lib/tools/trace/traceCli.js +87 -0
  214. package/lib/tools/trace/traceConsole.js +97 -0
  215. package/lib/tools/trace/traceErrors.js +55 -0
  216. package/lib/tools/trace/traceOpen.js +69 -0
  217. package/lib/tools/trace/traceParser.js +96 -0
  218. package/lib/tools/trace/traceRequests.js +182 -0
  219. package/lib/tools/trace/traceScreenshot.js +68 -0
  220. package/lib/tools/trace/traceSnapshot.js +149 -0
  221. package/lib/tools/trace/traceUtils.js +153 -0
  222. package/lib/tools/utils/connect.js +32 -0
  223. package/lib/tools/utils/mcp/http.js +152 -0
  224. package/lib/tools/utils/mcp/server.js +230 -0
  225. package/lib/tools/utils/mcp/tool.js +47 -0
  226. package/lib/tools/utils/socketConnection.js +108 -0
  227. package/lib/utils/isomorphic/formatUtils.js +64 -0
  228. package/lib/utils/isomorphic/jsonSchema.js +89 -0
  229. package/lib/utils/isomorphic/mimeType.js +7 -2
  230. package/lib/utils/isomorphic/protocolFormatter.js +2 -2
  231. package/lib/utils/isomorphic/protocolMetainfo.js +127 -106
  232. package/lib/utils/isomorphic/stringUtils.js +3 -3
  233. package/lib/utils/isomorphic/timeoutRunner.js +3 -3
  234. package/lib/utils/isomorphic/trace/snapshotRenderer.js +35 -42
  235. package/lib/utils/isomorphic/trace/traceLoader.js +15 -14
  236. package/lib/utils/isomorphic/trace/traceModel.js +3 -2
  237. package/lib/utils/isomorphic/trace/traceModernizer.js +1 -0
  238. package/lib/utils/isomorphic/urlMatch.js +54 -1
  239. package/lib/utils/isomorphic/utilityScriptSerializers.js +11 -0
  240. package/lib/utils.js +6 -2
  241. package/lib/utilsBundle.js +3 -21
  242. package/lib/utilsBundleImpl/index.js +132 -133
  243. package/lib/vite/dashboard/assets/index-BAOybkp8.js +50 -0
  244. package/lib/vite/dashboard/assets/index-CZAYOG76.css +1 -0
  245. package/lib/vite/dashboard/index.html +28 -0
  246. package/lib/vite/htmlReport/index.html +2 -70
  247. package/lib/vite/htmlReport/report.css +1 -0
  248. package/lib/vite/htmlReport/report.js +72 -0
  249. package/lib/vite/recorder/assets/{codeMirrorModule-CFUTFUO7.js → codeMirrorModule-C8KMvO9L.js} +20 -20
  250. package/lib/vite/recorder/assets/index-CqAYX1I3.js +193 -0
  251. package/lib/vite/recorder/index.html +1 -1
  252. package/lib/vite/traceViewer/assets/{codeMirrorModule-BVA4h_ZY.js → codeMirrorModule-DS0FLvoc.js} +20 -20
  253. package/lib/vite/traceViewer/assets/defaultSettingsView-GTWI-W_B.js +262 -0
  254. package/lib/vite/traceViewer/defaultSettingsView.B4dS75f0.css +1 -0
  255. package/lib/vite/traceViewer/{index.BtyWtaE-.js → index.C5466mMT.js} +1 -1
  256. package/lib/vite/traceViewer/{index.BVu7tZDe.css → index.CzXZzn5A.css} +1 -1
  257. package/lib/vite/traceViewer/index.html +4 -4
  258. package/lib/vite/traceViewer/sw.bundle.js +4 -4
  259. package/lib/vite/traceViewer/uiMode.Vipi55dB.js +6 -0
  260. package/lib/vite/traceViewer/uiMode.html +3 -3
  261. package/lib/zipBundleImpl.js +2 -2
  262. package/lib/zodBundle.js +39 -0
  263. package/lib/zodBundleImpl.js +40 -0
  264. package/package.json +6 -1
  265. package/types/protocol.d.ts +947 -51
  266. package/types/types.d.ts +854 -74
  267. package/lib/client/pageAgent.js +0 -64
  268. package/lib/mcpBundleImpl/index.js +0 -147
  269. package/lib/server/agent/actionRunner.js +0 -335
  270. package/lib/server/agent/actions.js +0 -128
  271. package/lib/server/agent/codegen.js +0 -111
  272. package/lib/server/agent/context.js +0 -150
  273. package/lib/server/agent/expectTools.js +0 -156
  274. package/lib/server/agent/pageAgent.js +0 -204
  275. package/lib/server/agent/performTools.js +0 -262
  276. package/lib/server/agent/tool.js +0 -109
  277. package/lib/server/dispatchers/pageAgentDispatcher.js +0 -96
  278. package/lib/server/pageBinding.js +0 -87
  279. package/lib/utils/isomorphic/oldUtilityScriptSerializers.js +0 -248
  280. package/lib/vite/recorder/assets/index-CVkBxsGf.js +0 -193
  281. package/lib/vite/traceViewer/assets/defaultSettingsView-CjfmcdOz.js +0 -266
  282. package/lib/vite/traceViewer/defaultSettingsView.7ch9cixO.css +0 -1
  283. package/lib/vite/traceViewer/uiMode.fyrXARf2.js +0 -5
  284. /package/lib/{server/utils → utils/isomorphic}/imageUtils.js +0 -0
  285. /package/lib/utils/isomorphic/{traceUtils.js → trace/traceUtils.js} +0 -0
@@ -37,7 +37,6 @@ var import_artifact = require("../artifact");
37
37
  var import_harTracer = require("./harTracer");
38
38
  var import_crypto = require("../utils/crypto");
39
39
  var import_manualPromise = require("../../utils/isomorphic/manualPromise");
40
- var import_zipBundle = require("../../zipBundle");
41
40
  class HarRecorder {
42
41
  constructor(context, page, options) {
43
42
  this._isFlushed = false;
@@ -56,7 +55,8 @@ class HarRecorder {
56
55
  waitForContentOnStop: true,
57
56
  urlFilter: urlFilterRe ?? options.urlGlob
58
57
  });
59
- this._zipFile = content === "attach" || expectsZip ? new import_zipBundle.yazl.ZipFile() : null;
58
+ const { yazl } = require("../../zipBundle");
59
+ this._zipFile = content === "attach" || expectsZip ? new yazl.ZipFile() : null;
60
60
  this._tracer.start({ omitScripts: false });
61
61
  }
62
62
  onEntryStarted(entry) {
@@ -278,9 +278,6 @@ class HarTracer {
278
278
  harEntry._securityDetails = details;
279
279
  }));
280
280
  }
281
- const httpVersion = response.httpVersion();
282
- harEntry.request.httpVersion = httpVersion;
283
- harEntry.response.httpVersion = httpVersion;
284
281
  const compressionCalculationBarrier = this._options.omitSizes ? void 0 : {
285
282
  _encodedBodySize: -1,
286
283
  _decodedBodySize: -1,
@@ -317,6 +314,10 @@ class HarTracer {
317
314
  this._delegate.onEntryFinished(harEntry);
318
315
  });
319
316
  this._addBarrier(page || request.serviceWorker(), promise);
317
+ this._addBarrier(page || request.serviceWorker(), response.httpVersion().then((httpVersion) => {
318
+ harEntry.request.httpVersion = httpVersion;
319
+ harEntry.response.httpVersion = httpVersion;
320
+ }));
320
321
  const timing = response.timing();
321
322
  harEntry.timings.receive = response.request()._responseEndTiming !== -1 ? import_helper.helper.millisToRoundishMillis(response.request()._responseEndTiming - timing.responseStart) : -1;
322
323
  this._computeHarEntryTotalTime(harEntry);
@@ -389,7 +390,7 @@ class HarTracer {
389
390
  harEntry.response = {
390
391
  status: response.status(),
391
392
  statusText: response.statusText(),
392
- httpVersion: response.httpVersion(),
393
+ httpVersion: FALLBACK_HTTP_VERSION,
393
394
  // These are bad values that will be overwritten below.
394
395
  cookies: [],
395
396
  headers: [],
@@ -48,6 +48,10 @@ class Keyboard {
48
48
  this._raw = raw;
49
49
  this._page = page;
50
50
  }
51
+ async apiDown(progress, key) {
52
+ await this._page.instrumentation.onBeforeInputAction(this._page, progress.metadata);
53
+ await this.down(progress, key);
54
+ }
51
55
  async down(progress, key) {
52
56
  const description = this._keyDescriptionForString(key);
53
57
  const autoRepeat = this._pressedKeys.has(description.code);
@@ -67,6 +71,10 @@ class Keyboard {
67
71
  return { ...description, text: "" };
68
72
  return description;
69
73
  }
74
+ async apiUp(progress, key) {
75
+ await this._page.instrumentation.onBeforeInputAction(this._page, progress.metadata);
76
+ await this.up(progress, key);
77
+ }
70
78
  async up(progress, key) {
71
79
  const description = this._keyDescriptionForString(key);
72
80
  if (kModifiers.includes(description.key))
@@ -74,9 +82,17 @@ class Keyboard {
74
82
  this._pressedKeys.delete(description.code);
75
83
  await this._raw.keyup(progress, this._pressedModifiers, key, description);
76
84
  }
77
- async insertText(progress, text) {
85
+ async apiInsertText(progress, text) {
86
+ await this._page.instrumentation.onBeforeInputAction(this._page, progress.metadata);
87
+ await this._insertText(progress, text);
88
+ }
89
+ async _insertText(progress, text) {
78
90
  await this._raw.sendText(progress, text);
79
91
  }
92
+ async apiType(progress, text, options) {
93
+ await this._page.instrumentation.onBeforeInputAction(this._page, progress.metadata);
94
+ await this.type(progress, text, options);
95
+ }
80
96
  async type(progress, text, options) {
81
97
  const delay = options && options.delay || void 0;
82
98
  for (const char of text) {
@@ -85,10 +101,14 @@ class Keyboard {
85
101
  } else {
86
102
  if (delay)
87
103
  await progress.wait(delay);
88
- await this.insertText(progress, char);
104
+ await this._insertText(progress, char);
89
105
  }
90
106
  }
91
107
  }
108
+ async apiPress(progress, key, options = {}) {
109
+ await this._page.instrumentation.onBeforeInputAction(this._page, progress.metadata);
110
+ await this.press(progress, key, options);
111
+ }
92
112
  async press(progress, key, options = {}) {
93
113
  function split(keyString) {
94
114
  const keys = [];
@@ -157,6 +177,11 @@ class Mouse {
157
177
  currentPoint() {
158
178
  return { x: this._x, y: this._y };
159
179
  }
180
+ async apiMove(progress, x, y, options = {}) {
181
+ progress.metadata.point = { x, y };
182
+ await this._page.instrumentation.onBeforeInputAction(this._page, progress.metadata);
183
+ await this.move(progress, x, y, options);
184
+ }
160
185
  async move(progress, x, y, options = {}) {
161
186
  const { steps = 1 } = options;
162
187
  const fromX = this._x;
@@ -169,18 +194,33 @@ class Mouse {
169
194
  await this._raw.move(progress, middleX, middleY, this._lastButton, this._buttons, this._keyboard._modifiers(), !!options.forClick);
170
195
  }
171
196
  }
197
+ async apiDown(progress, options = {}) {
198
+ progress.metadata.point = this.currentPoint();
199
+ await this._page.instrumentation.onBeforeInputAction(this._page, progress.metadata);
200
+ await this.down(progress, options);
201
+ }
172
202
  async down(progress, options = {}) {
173
203
  const { button = "left", clickCount = 1 } = options;
174
204
  this._lastButton = button;
175
205
  this._buttons.add(button);
176
206
  await this._raw.down(progress, this._x, this._y, this._lastButton, this._buttons, this._keyboard._modifiers(), clickCount);
177
207
  }
208
+ async apiUp(progress, options = {}) {
209
+ progress.metadata.point = this.currentPoint();
210
+ await this._page.instrumentation.onBeforeInputAction(this._page, progress.metadata);
211
+ await this.up(progress, options);
212
+ }
178
213
  async up(progress, options = {}) {
179
214
  const { button = "left", clickCount = 1 } = options;
180
215
  this._lastButton = "none";
181
216
  this._buttons.delete(button);
182
217
  await this._raw.up(progress, this._x, this._y, button, this._buttons, this._keyboard._modifiers(), clickCount);
183
218
  }
219
+ async apiClick(progress, x, y, options = {}) {
220
+ progress.metadata.point = { x, y };
221
+ await this._page.instrumentation.onBeforeInputAction(this._page, progress.metadata);
222
+ await this.click(progress, x, y, options);
223
+ }
184
224
  async click(progress, x, y, options = {}) {
185
225
  const { delay = null, clickCount = 1, steps } = options;
186
226
  if (delay) {
@@ -206,7 +246,8 @@ class Mouse {
206
246
  await Promise.all(promises);
207
247
  }
208
248
  }
209
- async wheel(progress, deltaX, deltaY) {
249
+ async apiWheel(progress, deltaX, deltaY) {
250
+ await this._page.instrumentation.onBeforeInputAction(this._page, progress.metadata);
210
251
  await this._raw.wheel(progress, this._x, this._y, this._buttons, this._keyboard._modifiers(), deltaX, deltaY);
211
252
  }
212
253
  }
@@ -260,9 +301,13 @@ class Touchscreen {
260
301
  this._raw = raw;
261
302
  this._page = page;
262
303
  }
263
- async tap(progress, x, y) {
304
+ async apiTap(progress, x, y) {
264
305
  if (!this._page.browserContext._options.hasTouch)
265
306
  throw new Error("hasTouch must be enabled on the browser context before using the touchscreen.");
307
+ await this._page.instrumentation.onBeforeInputAction(this._page, progress.metadata);
308
+ await this.tap(progress, x, y);
309
+ }
310
+ async tap(progress, x, y) {
266
311
  await this._raw.tap(progress, x, y, this._page.keyboard._modifiers());
267
312
  }
268
313
  }
@@ -25,6 +25,7 @@ __export(instrumentation_exports, {
25
25
  module.exports = __toCommonJS(instrumentation_exports);
26
26
  var import_events = require("events");
27
27
  var import_crypto = require("./utils/crypto");
28
+ var import_debugLogger = require("./utils/debugLogger");
28
29
  class SdkObject extends import_events.EventEmitter {
29
30
  constructor(parent, guidPrefix, guid) {
30
31
  super();
@@ -33,6 +34,10 @@ class SdkObject extends import_events.EventEmitter {
33
34
  this.attribution = { ...parent.attribution };
34
35
  this.instrumentation = parent.instrumentation;
35
36
  }
37
+ apiLog(message) {
38
+ if (!this.attribution.playwright.options.isInternalPlaywright)
39
+ import_debugLogger.debugLogger.log("api", message);
40
+ }
36
41
  closeReason() {
37
42
  return this.attribution.page?._closeReason || this.attribution.context?._closeReason || this.attribution.browser?._closeReason;
38
43
  }
@@ -113,34 +113,14 @@ class JSHandle extends import_instrumentation.SdkObject {
113
113
  async evaluateHandle(pageFunction, arg) {
114
114
  return evaluate(this._context, false, pageFunction, this, arg);
115
115
  }
116
- async evaluateExpression(expression, options, arg, isolatedContext) {
117
- let context = this._context;
118
- if (context.constructor.name === "FrameExecutionContext") {
119
- const frame = context.frame;
120
- if (frame) {
121
- if (isolatedContext === true) context = await frame._utilityContext();
122
- else if (isolatedContext === false) context = await frame._mainContext();
123
- }
124
- }
125
- if (context !== this._context && context.adoptIfNeeded(this) === null)
126
- context = this._context;
127
- const value = await evaluateExpression(context, expression, { ...options, returnByValue: true }, this, arg);
128
- await context.doSlowMo();
116
+ async evaluateExpression(expression, options, arg) {
117
+ const value = await evaluateExpression(this._context, expression, { ...options, returnByValue: true }, this, arg);
118
+ await this._context.doSlowMo();
129
119
  return value;
130
120
  }
131
- async evaluateExpressionHandle(expression, options, arg, isolatedContext) {
132
- let context = this._context;
133
- if (context.constructor.name === "FrameExecutionContext") {
134
- const frame = this._context.frame;
135
- if (frame) {
136
- if (isolatedContext === true) context = await frame._utilityContext();
137
- else if (isolatedContext === false) context = await frame._mainContext();
138
- }
139
- }
140
- if (context !== this._context && context.adoptIfNeeded(this) === null)
141
- context = this._context;
142
- const value = await evaluateExpression(context, expression, { ...options, returnByValue: false }, this, arg);
143
- await context.doSlowMo();
121
+ async evaluateExpressionHandle(expression, options, arg) {
122
+ const value = await evaluateExpression(this._context, expression, { ...options, returnByValue: false }, this, arg);
123
+ await this._context.doSlowMo();
144
124
  return value;
145
125
  }
146
126
  async getProperty(propertyName) {
@@ -106,7 +106,6 @@ async function syncLocalStorageWithSettings(page, appName) {
106
106
  });
107
107
  const settings = await import_fs.default.promises.readFile(settingsFile, "utf-8").catch(() => "{}");
108
108
  await page.addInitScript(
109
- progress,
110
109
  `(${String((settings2) => {
111
110
  if (location && location.protocol === "data:")
112
111
  return;
@@ -114,8 +113,7 @@ async function syncLocalStorageWithSettings(page, appName) {
114
113
  return;
115
114
  Object.entries(settings2).map(([k, v]) => localStorage[k] = v);
116
115
  window.saveSettings = () => {
117
- if (typeof window._saveSerializedSettings === "function")
118
- window._saveSerializedSettings(JSON.stringify({ ...localStorage }));
116
+ window._saveSerializedSettings(JSON.stringify({ ...localStorage }));
119
117
  };
120
118
  })})(${settings});
121
119
  `
@@ -45,13 +45,13 @@ var import_crypto = require("./utils/crypto");
45
45
  var import_harBackend = require("./harBackend");
46
46
  var import_manualPromise = require("../utils/isomorphic/manualPromise");
47
47
  var import_zipFile = require("./utils/zipFile");
48
- var import_zipBundle = require("../zipBundle");
49
- var import_traceUtils = require("../utils/isomorphic/traceUtils");
48
+ var import_traceUtils = require("../utils/isomorphic/trace/traceUtils");
50
49
  var import_assert = require("../utils/isomorphic/assert");
51
50
  var import_fileUtils = require("./utils/fileUtils");
52
51
  async function zip(progress, stackSessions, params) {
53
52
  const promise = new import_manualPromise.ManualPromise();
54
- const zipFile = new import_zipBundle.yazl.ZipFile();
53
+ const { yauzl, yazl } = require("../zipBundle");
54
+ const zipFile = new yazl.ZipFile();
55
55
  zipFile.on("error", (error) => promise.reject(error));
56
56
  const addFile = (file, name) => {
57
57
  try {
@@ -69,7 +69,7 @@ async function zip(progress, stackSessions, params) {
69
69
  zipFile.addBuffer(buffer, "trace.stacks");
70
70
  }
71
71
  if (params.includeSources) {
72
- const sourceFiles = /* @__PURE__ */ new Set();
72
+ const sourceFiles = new Set(params.additionalSources);
73
73
  for (const { stack } of stackSession?.callStacks || []) {
74
74
  if (!stack)
75
75
  continue;
@@ -77,7 +77,7 @@ async function zip(progress, stackSessions, params) {
77
77
  sourceFiles.add(file);
78
78
  }
79
79
  for (const sourceFile of sourceFiles)
80
- addFile(sourceFile, "resources/src@" + await (0, import_crypto.calculateSha1)(sourceFile) + ".txt");
80
+ addFile(sourceFile, "resources/src@" + (0, import_crypto.calculateSha1)(sourceFile) + ".txt");
81
81
  }
82
82
  if (params.mode === "write") {
83
83
  await progress.race(import_fs.default.promises.mkdir(import_path.default.dirname(params.zipFile), { recursive: true }));
@@ -90,7 +90,7 @@ async function zip(progress, stackSessions, params) {
90
90
  }
91
91
  const tempFile = params.zipFile + ".tmp";
92
92
  await progress.race(import_fs.default.promises.rename(params.zipFile, tempFile));
93
- import_zipBundle.yauzl.open(tempFile, (err, inZipFile) => {
93
+ yauzl.open(tempFile, (err, inZipFile) => {
94
94
  if (err) {
95
95
  promise.reject(err);
96
96
  return;
@@ -373,7 +373,7 @@ class Route extends import_instrumentation.SdkObject {
373
373
  }
374
374
  }
375
375
  class Response extends import_instrumentation.SdkObject {
376
- constructor(request, status, statusText2, headers, timing, getResponseBodyCallback, fromServiceWorker, httpVersion) {
376
+ constructor(request, status, statusText2, headers, timing, getResponseBodyCallback, fromServiceWorker) {
377
377
  super(request.frame() || request._context, "response");
378
378
  this._contentPromise = null;
379
379
  this._finishedPromise = new import_manualPromise.ManualPromise();
@@ -381,6 +381,7 @@ class Response extends import_instrumentation.SdkObject {
381
381
  this._serverAddrPromise = new import_manualPromise.ManualPromise();
382
382
  this._securityDetailsPromise = new import_manualPromise.ManualPromise();
383
383
  this._rawResponseHeadersPromise = new import_manualPromise.ManualPromise();
384
+ this._httpVersionPromise = new import_manualPromise.ManualPromise();
384
385
  this._encodedBodySizePromise = new import_manualPromise.ManualPromise();
385
386
  this._transferSizePromise = new import_manualPromise.ManualPromise();
386
387
  this._responseHeadersSizePromise = new import_manualPromise.ManualPromise();
@@ -394,7 +395,6 @@ class Response extends import_instrumentation.SdkObject {
394
395
  this._headersMap.set(name.toLowerCase(), value);
395
396
  this._getResponseBodyCallback = getResponseBodyCallback;
396
397
  this._request._setResponse(this);
397
- this._httpVersion = httpVersion;
398
398
  this._fromServiceWorker = fromServiceWorker;
399
399
  }
400
400
  _serverAddrFinished(addr) {
@@ -410,7 +410,7 @@ class Response extends import_instrumentation.SdkObject {
410
410
  this._finishedPromise.resolve();
411
411
  }
412
412
  _setHttpVersion(httpVersion) {
413
- this._httpVersion = httpVersion;
413
+ this._httpVersionPromise.resolve(httpVersion);
414
414
  }
415
415
  url() {
416
416
  return this._url;
@@ -476,14 +476,15 @@ class Response extends import_instrumentation.SdkObject {
476
476
  frame() {
477
477
  return this._request.frame();
478
478
  }
479
- httpVersion() {
480
- if (!this._httpVersion)
479
+ async httpVersion() {
480
+ const httpVersion = await this._httpVersionPromise || null;
481
+ if (!httpVersion)
481
482
  return "HTTP/1.1";
482
- if (this._httpVersion === "http/1.1")
483
+ if (httpVersion === "http/1.1")
483
484
  return "HTTP/1.1";
484
- if (this._httpVersion === "h2")
485
+ if (httpVersion === "h2")
485
486
  return "HTTP/2.0";
486
- return this._httpVersion;
487
+ return httpVersion;
487
488
  }
488
489
  fromServiceWorker() {
489
490
  return this._fromServiceWorker;
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var overlay_exports = {};
20
+ __export(overlay_exports, {
21
+ Overlay: () => Overlay
22
+ });
23
+ module.exports = __toCommonJS(overlay_exports);
24
+ var import_utils = require("../utils");
25
+ var import_page = require("./page");
26
+ class Overlay {
27
+ constructor(page) {
28
+ this._overlays = /* @__PURE__ */ new Map();
29
+ this._page = page;
30
+ this._page.on(import_page.Page.Events.InternalFrameNavigatedToNewDocument, (frame) => {
31
+ if (frame.parentFrame())
32
+ return;
33
+ for (const [id, html] of this._overlays)
34
+ this._doAdd(id, html).catch((e) => import_utils.debugLogger.log("error", e));
35
+ });
36
+ }
37
+ dispose() {
38
+ }
39
+ async show(html, duration) {
40
+ const id = (0, import_utils.createGuid)();
41
+ this._overlays.set(id, html);
42
+ await this._doAdd(id, html).catch((e) => import_utils.debugLogger.log("error", e));
43
+ if (duration) {
44
+ await new Promise((f) => setTimeout(f, duration));
45
+ await this.remove(id);
46
+ }
47
+ return id;
48
+ }
49
+ async _doAdd(id, html) {
50
+ const utility = await this._page.mainFrame()._utilityContext();
51
+ await utility.evaluate(({ injected, html: html2, id: id2 }) => {
52
+ return injected.addUserOverlay(id2, html2);
53
+ }, { injected: await utility.injectedScript(), html, id });
54
+ }
55
+ async remove(id) {
56
+ this._overlays.delete(id);
57
+ const utility = await this._page.mainFrame()._utilityContext();
58
+ await utility.evaluate(({ injected, id: id2 }) => {
59
+ injected.removeUserOverlay(id2);
60
+ }, { injected: await utility.injectedScript(), id }).catch((e) => import_utils.debugLogger.log("error", e));
61
+ }
62
+ async chapter(options) {
63
+ const fadeDuration = 300;
64
+ const descriptionHtml = options.description ? `<div id="description">${(0, import_utils.escapeHTML)(options.description)}</div>` : "";
65
+ const styleSheet = `
66
+ @keyframes pw-chapter-fade-in {
67
+ from { opacity: 0; }
68
+ to { opacity: 1; }
69
+ }
70
+ @keyframes pw-chapter-fade-out {
71
+ from { opacity: 1; }
72
+ to { opacity: 0; }
73
+ }
74
+ #background {
75
+ position: absolute;
76
+ inset: 0;
77
+ display: flex;
78
+ align-items: center;
79
+ justify-content: center;
80
+ backdrop-filter: blur(2px);
81
+ animation: pw-chapter-fade-in ${fadeDuration}ms ease-out forwards;
82
+ }
83
+ #background.fade-out {
84
+ animation: pw-chapter-fade-out ${fadeDuration}ms ease-in forwards;
85
+ }
86
+ #content {
87
+ background: rgba(0, 0, 0, 0.7);
88
+ border: 1px solid rgba(255, 255, 255, 0.15);
89
+ border-radius: 16px;
90
+ padding: 40px 56px;
91
+ max-width: 560px;
92
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
93
+ }
94
+ #title {
95
+ color: white;
96
+ font-family: system-ui, -apple-system, sans-serif;
97
+ font-size: 28px;
98
+ font-weight: 600;
99
+ line-height: 1.3;
100
+ text-align: center;
101
+ letter-spacing: -0.01em;
102
+ }
103
+ #description {
104
+ color: rgba(255, 255, 255, 0.7);
105
+ font-family: system-ui, -apple-system, sans-serif;
106
+ font-size: 15px;
107
+ line-height: 1.5;
108
+ margin-top: 12px;
109
+ text-align: center;
110
+ }
111
+ `;
112
+ const duration = options.duration ?? 2e3;
113
+ const html = `<style>${styleSheet}</style><div id="background"><div id="content"><div id="title">${(0, import_utils.escapeHTML)(options.title)}</div>${descriptionHtml}</div></div>`;
114
+ const id = await this.show(html);
115
+ await new Promise((f) => setTimeout(f, duration));
116
+ const utility = await this._page.mainFrame()._utilityContext();
117
+ await utility.evaluate(({ injected, id: id2, fadeDuration: fadeDuration2 }) => {
118
+ const overlay = injected.getUserOverlay(id2);
119
+ const bg = overlay?.querySelector("#background");
120
+ if (bg)
121
+ bg.classList.add("fade-out");
122
+ return new Promise((f) => injected.utils.builtins.setTimeout(f, fadeDuration2));
123
+ }, { injected: await utility.injectedScript(), id, fadeDuration }).catch((e) => import_utils.debugLogger.log("error", e));
124
+ await this.remove(id);
125
+ }
126
+ async setVisible(visible) {
127
+ if (!this._overlays.size)
128
+ return;
129
+ const utility = await this._page.mainFrame()._utilityContext();
130
+ await utility.evaluate(({ injected, visible: visible2 }) => {
131
+ injected.setUserOverlaysVisible(visible2);
132
+ }, { injected: await utility.injectedScript(), visible }).catch((e) => import_utils.debugLogger.log("error", e));
133
+ }
134
+ }
135
+ // Annotate the CommonJS export names for ESM import in node:
136
+ 0 && (module.exports = {
137
+ Overlay
138
+ });