patchright-bun-core 1.58.2 → 1.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (272) 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 +18 -37
  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/{webSocket.js → connect.js} +57 -7
  16. package/lib/client/connection.js +8 -4
  17. package/lib/client/consoleMessage.js +3 -0
  18. package/lib/client/debugger.js +57 -0
  19. package/lib/client/dialog.js +8 -1
  20. package/lib/client/disposable.js +76 -0
  21. package/lib/client/electron.js +1 -0
  22. package/lib/client/elementHandle.js +1 -4
  23. package/lib/client/events.js +3 -3
  24. package/lib/client/fetch.js +0 -1
  25. package/lib/client/frame.js +0 -5
  26. package/lib/client/harRouter.js +13 -1
  27. package/lib/client/jsHandle.js +0 -4
  28. package/lib/client/locator.js +5 -7
  29. package/lib/client/network.js +14 -11
  30. package/lib/client/page.js +34 -48
  31. package/lib/client/platform.js +0 -3
  32. package/lib/client/screencast.js +88 -0
  33. package/lib/client/selectors.js +3 -1
  34. package/lib/client/tracing.js +11 -4
  35. package/lib/client/video.js +13 -20
  36. package/lib/generated/bindingsControllerSource.js +1 -1
  37. package/lib/generated/clockSource.js +1 -1
  38. package/lib/generated/injectedScriptSource.js +1 -1
  39. package/lib/generated/pollingRecorderSource.js +1 -1
  40. package/lib/generated/storageScriptSource.js +1 -1
  41. package/lib/generated/utilityScriptSource.js +1 -1
  42. package/lib/mcpBundle.js +0 -6
  43. package/lib/mcpBundleImpl.js +91 -0
  44. package/lib/protocol/validator.js +216 -118
  45. package/lib/protocol/validatorPrimitives.js +1 -1
  46. package/lib/remote/playwrightConnection.js +10 -8
  47. package/lib/remote/playwrightPipeServer.js +100 -0
  48. package/lib/remote/playwrightServer.js +13 -8
  49. package/lib/remote/playwrightWebSocketServer.js +73 -0
  50. package/lib/remote/serverTransport.js +96 -0
  51. package/lib/server/android/android.js +2 -2
  52. package/lib/server/bidi/bidiBrowser.js +30 -8
  53. package/lib/server/bidi/bidiChromium.js +18 -5
  54. package/lib/server/bidi/bidiNetworkManager.js +39 -11
  55. package/lib/server/bidi/bidiPage.js +31 -15
  56. package/lib/server/bidi/third_party/firefoxPrefs.js +3 -1
  57. package/lib/server/browser.js +84 -21
  58. package/lib/server/browserContext.js +97 -58
  59. package/lib/server/browserType.js +14 -12
  60. package/lib/server/chromium/chromium.js +15 -13
  61. package/lib/server/chromium/crBrowser.js +18 -10
  62. package/lib/server/chromium/crNetworkManager.js +4 -4
  63. package/lib/server/chromium/crPage.js +26 -64
  64. package/lib/server/chromium/crServiceWorker.js +5 -4
  65. package/lib/server/clock.js +33 -33
  66. package/lib/server/console.js +5 -1
  67. package/lib/server/debugController.js +12 -6
  68. package/lib/server/debugger.js +40 -47
  69. package/lib/server/deviceDescriptorsSource.json +137 -137
  70. package/lib/server/dispatchers/browserContextDispatcher.js +27 -30
  71. package/lib/server/dispatchers/browserDispatcher.js +11 -5
  72. package/lib/server/dispatchers/browserTypeDispatcher.js +7 -0
  73. package/lib/server/dispatchers/cdpSessionDispatcher.js +4 -1
  74. package/lib/server/dispatchers/debuggerDispatcher.js +84 -0
  75. package/lib/server/dispatchers/dispatcher.js +1 -1
  76. package/lib/server/dispatchers/disposableDispatcher.js +39 -0
  77. package/lib/server/dispatchers/electronDispatcher.js +2 -1
  78. package/lib/server/dispatchers/frameDispatcher.js +3 -3
  79. package/lib/server/dispatchers/localUtilsDispatcher.js +37 -1
  80. package/lib/server/dispatchers/networkDispatchers.js +6 -5
  81. package/lib/server/dispatchers/pageDispatcher.js +101 -38
  82. package/lib/server/dispatchers/webSocketRouteDispatcher.js +4 -5
  83. package/lib/server/disposable.js +41 -0
  84. package/lib/server/dom.js +44 -26
  85. package/lib/server/download.js +3 -2
  86. package/lib/server/electron/electron.js +12 -7
  87. package/lib/server/firefox/ffBrowser.js +9 -19
  88. package/lib/server/firefox/ffInput.js +21 -5
  89. package/lib/server/firefox/ffNetworkManager.js +2 -2
  90. package/lib/server/firefox/ffPage.js +24 -27
  91. package/lib/server/frames.js +40 -11
  92. package/lib/server/har/harRecorder.js +2 -2
  93. package/lib/server/har/harTracer.js +5 -4
  94. package/lib/server/input.js +49 -4
  95. package/lib/server/instrumentation.js +5 -0
  96. package/lib/server/launchApp.js +0 -1
  97. package/lib/server/localUtils.js +6 -6
  98. package/lib/server/network.js +9 -8
  99. package/lib/server/overlay.js +138 -0
  100. package/lib/server/page.js +111 -51
  101. package/lib/server/progress.js +6 -0
  102. package/lib/server/recorder/recorderApp.js +9 -8
  103. package/lib/server/recorder.js +76 -40
  104. package/lib/server/registry/index.js +54 -81
  105. package/lib/server/registry/nativeDeps.js +1 -0
  106. package/lib/server/screencast.js +90 -143
  107. package/lib/server/trace/recorder/snapshotter.js +2 -2
  108. package/lib/server/trace/recorder/tracing.js +87 -36
  109. package/lib/server/trace/viewer/traceViewer.js +3 -4
  110. package/lib/server/usKeyboardLayout.js +7 -0
  111. package/lib/server/utils/comparators.js +1 -1
  112. package/lib/server/utils/disposable.js +32 -0
  113. package/lib/server/utils/eventsHelper.js +3 -1
  114. package/lib/server/utils/fileUtils.js +16 -2
  115. package/lib/server/utils/happyEyeballs.js +15 -12
  116. package/lib/server/utils/hostPlatform.js +0 -15
  117. package/lib/server/utils/httpServer.js +5 -3
  118. package/lib/server/utils/network.js +2 -1
  119. package/lib/server/utils/nodePlatform.js +0 -6
  120. package/lib/server/utils/processLauncher.js +8 -6
  121. package/lib/server/utils/zipFile.js +2 -2
  122. package/lib/server/videoRecorder.js +82 -12
  123. package/lib/server/webkit/wkBrowser.js +1 -6
  124. package/lib/server/webkit/wkPage.js +27 -25
  125. package/lib/server/webkit/wkWorkers.js +2 -1
  126. package/lib/serverRegistry.js +156 -0
  127. package/lib/tools/backend/browserBackend.js +79 -0
  128. package/lib/tools/backend/common.js +63 -0
  129. package/lib/tools/backend/config.js +41 -0
  130. package/lib/tools/backend/console.js +66 -0
  131. package/lib/tools/backend/context.js +296 -0
  132. package/lib/tools/backend/cookies.js +152 -0
  133. package/lib/tools/backend/devtools.js +69 -0
  134. package/lib/tools/backend/dialogs.js +59 -0
  135. package/lib/tools/backend/evaluate.js +64 -0
  136. package/lib/tools/backend/files.js +60 -0
  137. package/lib/tools/backend/form.js +64 -0
  138. package/lib/tools/backend/keyboard.js +155 -0
  139. package/lib/tools/backend/logFile.js +95 -0
  140. package/lib/tools/backend/mouse.js +168 -0
  141. package/lib/tools/backend/navigate.js +106 -0
  142. package/lib/tools/backend/network.js +135 -0
  143. package/lib/tools/backend/pdf.js +48 -0
  144. package/lib/tools/backend/response.js +305 -0
  145. package/lib/tools/backend/route.js +140 -0
  146. package/lib/tools/backend/runCode.js +77 -0
  147. package/lib/tools/backend/screenshot.js +88 -0
  148. package/lib/tools/backend/sessionLog.js +74 -0
  149. package/lib/tools/backend/snapshot.js +208 -0
  150. package/lib/tools/backend/storage.js +68 -0
  151. package/lib/tools/backend/tab.js +445 -0
  152. package/lib/tools/backend/tabs.js +67 -0
  153. package/lib/tools/backend/tool.js +47 -0
  154. package/lib/tools/backend/tools.js +102 -0
  155. package/lib/tools/backend/tracing.js +78 -0
  156. package/lib/tools/backend/utils.js +83 -0
  157. package/lib/tools/backend/verify.js +151 -0
  158. package/lib/tools/backend/video.js +98 -0
  159. package/lib/tools/backend/wait.js +63 -0
  160. package/lib/tools/backend/webstorage.js +223 -0
  161. package/lib/tools/cli-client/cli.js +6 -0
  162. package/lib/tools/cli-client/help.json +399 -0
  163. package/lib/tools/cli-client/minimist.js +128 -0
  164. package/lib/tools/cli-client/program.js +350 -0
  165. package/lib/tools/cli-client/registry.js +176 -0
  166. package/lib/tools/cli-client/session.js +289 -0
  167. package/lib/tools/cli-client/skill/SKILL.md +328 -0
  168. package/lib/tools/cli-client/skill/references/element-attributes.md +23 -0
  169. package/lib/tools/cli-client/skill/references/playwright-tests.md +39 -0
  170. package/lib/tools/cli-client/skill/references/request-mocking.md +87 -0
  171. package/lib/tools/cli-client/skill/references/running-code.md +231 -0
  172. package/lib/tools/cli-client/skill/references/session-management.md +169 -0
  173. package/lib/tools/cli-client/skill/references/storage-state.md +275 -0
  174. package/lib/tools/cli-client/skill/references/test-generation.md +88 -0
  175. package/lib/tools/cli-client/skill/references/tracing.md +139 -0
  176. package/lib/tools/cli-client/skill/references/video-recording.md +143 -0
  177. package/lib/tools/cli-daemon/command.js +73 -0
  178. package/lib/tools/cli-daemon/commands.js +956 -0
  179. package/lib/tools/cli-daemon/daemon.js +157 -0
  180. package/lib/tools/cli-daemon/helpGenerator.js +177 -0
  181. package/lib/tools/cli-daemon/program.js +129 -0
  182. package/lib/tools/dashboard/appIcon.png +0 -0
  183. package/lib/tools/dashboard/dashboardApp.js +284 -0
  184. package/lib/tools/dashboard/dashboardController.js +296 -0
  185. package/lib/tools/exports.js +60 -0
  186. package/lib/tools/mcp/browserFactory.js +233 -0
  187. package/lib/tools/mcp/cdpRelay.js +352 -0
  188. package/lib/tools/mcp/cli-stub.js +7 -0
  189. package/lib/tools/mcp/config.d.js +16 -0
  190. package/lib/tools/mcp/config.js +446 -0
  191. package/lib/tools/mcp/configIni.js +189 -0
  192. package/lib/tools/mcp/extensionContextFactory.js +55 -0
  193. package/lib/tools/mcp/index.js +62 -0
  194. package/lib/tools/mcp/log.js +35 -0
  195. package/lib/tools/mcp/program.js +107 -0
  196. package/lib/tools/mcp/protocol.js +28 -0
  197. package/lib/tools/mcp/watchdog.js +44 -0
  198. package/lib/tools/trace/SKILL.md +171 -0
  199. package/lib/{server/trace/viewer/traceParser.js → tools/trace/installSkill.js} +15 -39
  200. package/lib/tools/trace/traceActions.js +142 -0
  201. package/lib/tools/trace/traceAttachments.js +69 -0
  202. package/lib/tools/trace/traceCli.js +87 -0
  203. package/lib/tools/trace/traceConsole.js +97 -0
  204. package/lib/tools/trace/traceErrors.js +55 -0
  205. package/lib/tools/trace/traceOpen.js +69 -0
  206. package/lib/tools/trace/traceParser.js +96 -0
  207. package/lib/tools/trace/traceRequests.js +182 -0
  208. package/lib/tools/trace/traceScreenshot.js +68 -0
  209. package/lib/tools/trace/traceSnapshot.js +149 -0
  210. package/lib/tools/trace/traceUtils.js +153 -0
  211. package/lib/tools/utils/connect.js +32 -0
  212. package/lib/tools/utils/mcp/http.js +152 -0
  213. package/lib/tools/utils/mcp/server.js +230 -0
  214. package/lib/tools/utils/mcp/tool.js +47 -0
  215. package/lib/tools/utils/socketConnection.js +108 -0
  216. package/lib/utils/isomorphic/formatUtils.js +64 -0
  217. package/lib/utils/isomorphic/jsonSchema.js +89 -0
  218. package/lib/utils/isomorphic/mimeType.js +7 -2
  219. package/lib/utils/isomorphic/protocolFormatter.js +2 -2
  220. package/lib/utils/isomorphic/protocolMetainfo.js +127 -106
  221. package/lib/utils/isomorphic/stringUtils.js +3 -3
  222. package/lib/utils/isomorphic/timeoutRunner.js +3 -3
  223. package/lib/utils/isomorphic/trace/snapshotRenderer.js +35 -42
  224. package/lib/utils/isomorphic/trace/traceLoader.js +15 -14
  225. package/lib/utils/isomorphic/trace/traceModel.js +3 -2
  226. package/lib/utils/isomorphic/trace/traceModernizer.js +1 -0
  227. package/lib/utils/isomorphic/urlMatch.js +54 -1
  228. package/lib/utils/isomorphic/utilityScriptSerializers.js +11 -0
  229. package/lib/utils.js +6 -2
  230. package/lib/utilsBundle.js +3 -21
  231. package/lib/utilsBundleImpl/index.js +132 -133
  232. package/lib/vite/dashboard/assets/index-BAOybkp8.js +50 -0
  233. package/lib/vite/dashboard/assets/index-CZAYOG76.css +1 -0
  234. package/lib/vite/dashboard/index.html +28 -0
  235. package/lib/vite/htmlReport/index.html +2 -70
  236. package/lib/vite/htmlReport/report.css +1 -0
  237. package/lib/vite/htmlReport/report.js +72 -0
  238. package/lib/vite/recorder/assets/{codeMirrorModule-DadYNm1I.js → codeMirrorModule-C8KMvO9L.js} +20 -20
  239. package/lib/vite/recorder/assets/index-CqAYX1I3.js +193 -0
  240. package/lib/vite/recorder/index.html +1 -1
  241. package/lib/vite/traceViewer/assets/{codeMirrorModule-a5XoALAZ.js → codeMirrorModule-DS0FLvoc.js} +20 -20
  242. package/lib/vite/traceViewer/assets/defaultSettingsView-GTWI-W_B.js +262 -0
  243. package/lib/vite/traceViewer/defaultSettingsView.B4dS75f0.css +1 -0
  244. package/lib/vite/traceViewer/{index.BVu7tZDe.css → index.CzXZzn5A.css} +1 -1
  245. package/lib/vite/traceViewer/{index.BDwrLSGN.js → index.Dtstcb7U.js} +1 -1
  246. package/lib/vite/traceViewer/index.html +4 -4
  247. package/lib/vite/traceViewer/sw.bundle.js +4 -4
  248. package/lib/vite/traceViewer/uiMode.Vipi55dB.js +6 -0
  249. package/lib/vite/traceViewer/uiMode.html +3 -3
  250. package/lib/zipBundleImpl.js +2 -2
  251. package/lib/zodBundle.js +39 -0
  252. package/lib/zodBundleImpl.js +40 -0
  253. package/package.json +6 -1
  254. package/types/protocol.d.ts +947 -51
  255. package/types/types.d.ts +854 -74
  256. package/lib/client/pageAgent.js +0 -64
  257. package/lib/mcpBundleImpl/index.js +0 -147
  258. package/lib/server/agent/actionRunner.js +0 -335
  259. package/lib/server/agent/actions.js +0 -128
  260. package/lib/server/agent/codegen.js +0 -111
  261. package/lib/server/agent/context.js +0 -150
  262. package/lib/server/agent/expectTools.js +0 -156
  263. package/lib/server/agent/pageAgent.js +0 -204
  264. package/lib/server/agent/performTools.js +0 -262
  265. package/lib/server/agent/tool.js +0 -109
  266. package/lib/server/dispatchers/pageAgentDispatcher.js +0 -96
  267. package/lib/vite/recorder/assets/index-BhTWtUlo.js +0 -193
  268. package/lib/vite/traceViewer/assets/defaultSettingsView-CJSZINFr.js +0 -266
  269. package/lib/vite/traceViewer/defaultSettingsView.7ch9cixO.css +0 -1
  270. package/lib/vite/traceViewer/uiMode.CQJ9SCIQ.js +0 -5
  271. /package/lib/{server/utils → utils/isomorphic}/imageUtils.js +0 -0
  272. /package/lib/utils/isomorphic/{traceUtils.js → trace/traceUtils.js} +0 -0
@@ -100,9 +100,6 @@ class Locator {
100
100
  async evaluate(pageFunction, arg, options) {
101
101
  return await this._withElement((h) => h.evaluate(pageFunction, arg), { title: "Evaluate", timeout: options?.timeout });
102
102
  }
103
- async _evaluateFunction(functionDeclaration, options) {
104
- return await this._withElement((h) => h._evaluateFunction(functionDeclaration), { title: "Evaluate", timeout: options?.timeout });
105
- }
106
103
  async evaluateAll(pageFunction, arg) {
107
104
  return await this._frame.$$eval(this._selector, pageFunction, arg);
108
105
  }
@@ -199,8 +196,9 @@ class Locator {
199
196
  async count(_options) {
200
197
  return await this._frame._queryCount(this._selector, _options);
201
198
  }
202
- async _resolveSelector() {
203
- return await this._frame._channel.resolveSelector({ selector: this._selector });
199
+ async normalize() {
200
+ const { resolvedSelector } = await this._frame._channel.resolveSelector({ selector: this._selector });
201
+ return new Locator(this._frame, resolvedSelector);
204
202
  }
205
203
  async getAttribute(name, options) {
206
204
  return await this._frame.getAttribute(this._selector, name, { strict: true, ...options });
@@ -242,8 +240,8 @@ class Locator {
242
240
  const mask = options.mask;
243
241
  return await this._withElement((h, timeout) => h.screenshot({ ...options, mask, timeout }), { title: "Screenshot", timeout: options.timeout });
244
242
  }
245
- async ariaSnapshot(options) {
246
- const result = await this._frame._channel.ariaSnapshot({ ...options, selector: this._selector, timeout: this._frame._timeout(options) });
243
+ async ariaSnapshot(options = {}) {
244
+ const result = await this._frame._channel.ariaSnapshot({ timeout: this._frame._timeout(options), mode: options.mode, selector: this._selector, depth: options.depth });
247
245
  return result.snapshot;
248
246
  }
249
247
  async scrollIntoViewIfNeeded(options = {}) {
@@ -50,8 +50,8 @@ class Request extends import_channelOwner.ChannelOwner {
50
50
  this._redirectedFrom = null;
51
51
  this._redirectedTo = null;
52
52
  this._failureText = null;
53
+ this._response = null;
53
54
  this._fallbackOverrides = {};
54
- this._hasResponse = false;
55
55
  this._redirectedFrom = Request.fromNullable(initializer.redirectedFrom);
56
56
  if (this._redirectedFrom)
57
57
  this._redirectedFrom._redirectedTo = this;
@@ -67,8 +67,6 @@ class Request extends import_channelOwner.ChannelOwner {
67
67
  responseStart: -1,
68
68
  responseEnd: -1
69
69
  };
70
- this._hasResponse = this._initializer.hasResponse;
71
- this._channel.on("response", () => this._hasResponse = true);
72
70
  }
73
71
  static from(request) {
74
72
  return request._object;
@@ -142,6 +140,9 @@ class Request extends import_channelOwner.ChannelOwner {
142
140
  async _internalResponse() {
143
141
  return Response.fromNullable((await this._channel.response()).response);
144
142
  }
143
+ existingResponse() {
144
+ return this._response;
145
+ }
145
146
  frame() {
146
147
  if (!this._initializer.frame) {
147
148
  (0, import_assert.assert)(this.serviceWorker());
@@ -465,10 +466,9 @@ class WebSocketRouteHandler {
465
466
  const patterns = [];
466
467
  let all = false;
467
468
  for (const handler of handlers) {
468
- if ((0, import_rtti.isString)(handler.url))
469
- patterns.push({ glob: handler.url });
470
- else if ((0, import_rtti.isRegExp)(handler.url))
471
- patterns.push({ regexSource: handler.url.source, regexFlags: handler.url.flags });
469
+ const serialized = (0, import_urlMatch.serializeURLMatch)(handler.url);
470
+ if (serialized)
471
+ patterns.push(serialized);
472
472
  else
473
473
  all = true;
474
474
  }
@@ -491,6 +491,7 @@ class Response extends import_channelOwner.ChannelOwner {
491
491
  this._finishedPromise = new import_manualPromise.ManualPromise();
492
492
  this._provisionalHeaders = new RawHeaders(initializer.headers);
493
493
  this._request = Request.from(this._initializer.request);
494
+ this._request._response = this;
494
495
  Object.assign(this._request._timing, this._initializer.timing);
495
496
  }
496
497
  static from(response) {
@@ -566,6 +567,9 @@ class Response extends import_channelOwner.ChannelOwner {
566
567
  async securityDetails() {
567
568
  return (await this._channel.securityDetails()).value || null;
568
569
  }
570
+ async httpVersion() {
571
+ return (await this._channel.httpVersion()).value;
572
+ }
569
573
  }
570
574
  class WebSocket extends import_channelOwner.ChannelOwner {
571
575
  static from(webSocket) {
@@ -638,10 +642,9 @@ class RouteHandler {
638
642
  const patterns = [];
639
643
  let all = false;
640
644
  for (const handler of handlers) {
641
- if ((0, import_rtti.isString)(handler.url))
642
- patterns.push({ glob: handler.url });
643
- else if ((0, import_rtti.isRegExp)(handler.url))
644
- patterns.push({ regexSource: handler.url.source, regexFlags: handler.url.flags });
645
+ const serialized = (0, import_urlMatch.serializeURLMatch)(handler.url);
646
+ if (serialized)
647
+ patterns.push(serialized);
645
648
  else
646
649
  all = true;
647
650
  }
@@ -26,6 +26,7 @@ var import_artifact = require("./artifact");
26
26
  var import_channelOwner = require("./channelOwner");
27
27
  var import_clientHelper = require("./clientHelper");
28
28
  var import_coverage = require("./coverage");
29
+ var import_disposable = require("./disposable");
29
30
  var import_download = require("./download");
30
31
  var import_elementHandle = require("./elementHandle");
31
32
  var import_errors = require("./errors");
@@ -37,6 +38,7 @@ var import_input = require("./input");
37
38
  var import_jsHandle = require("./jsHandle");
38
39
  var import_network = require("./network");
39
40
  var import_video = require("./video");
41
+ var import_screencast = require("./screencast");
40
42
  var import_waiter = require("./waiter");
41
43
  var import_worker = require("./worker");
42
44
  var import_timeoutSettings = require("./timeoutSettings");
@@ -48,7 +50,6 @@ var import_urlMatch = require("../utils/isomorphic/urlMatch");
48
50
  var import_manualPromise = require("../utils/isomorphic/manualPromise");
49
51
  var import_rtti = require("../utils/isomorphic/rtti");
50
52
  var import_consoleMessage = require("./consoleMessage");
51
- var import_pageAgent = require("./pageAgent");
52
53
  class Page extends import_channelOwner.ChannelOwner {
53
54
  constructor(parent, type, guid, initializer) {
54
55
  super(parent, type, guid, initializer);
@@ -59,7 +60,6 @@ class Page extends import_channelOwner.ChannelOwner {
59
60
  this._routes = [];
60
61
  this._webSocketRoutes = [];
61
62
  this._bindings = /* @__PURE__ */ new Map();
62
- this._video = null;
63
63
  this._closeWasCalled = false;
64
64
  this._harRouters = [];
65
65
  this._locatorHandlers = /* @__PURE__ */ new Map();
@@ -77,6 +77,8 @@ class Page extends import_channelOwner.ChannelOwner {
77
77
  this._viewportSize = initializer.viewportSize;
78
78
  this._closed = initializer.isClosed;
79
79
  this._opener = Page.fromNullable(initializer.opener);
80
+ this._video = new import_video.Video(this, this._connection, initializer.video ? import_artifact.Artifact.from(initializer.video) : void 0);
81
+ this.screencast = new import_screencast.Screencast(this);
80
82
  this._channel.on("bindingCall", ({ binding }) => this._onBinding(BindingCall.from(binding)));
81
83
  this._channel.on("close", () => this._onClose());
82
84
  this._channel.on("crash", () => this._onCrash());
@@ -90,10 +92,6 @@ class Page extends import_channelOwner.ChannelOwner {
90
92
  this._channel.on("locatorHandlerTriggered", ({ uid }) => this._onLocatorHandlerTriggered(uid));
91
93
  this._channel.on("route", ({ route }) => this._onRoute(import_network.Route.from(route)));
92
94
  this._channel.on("webSocketRoute", ({ webSocketRoute }) => this._onWebSocketRoute(import_network.WebSocketRoute.from(webSocketRoute)));
93
- this._channel.on("video", ({ artifact }) => {
94
- const artifactObject = import_artifact.Artifact.from(artifact);
95
- this._forceVideo()._artifactReady(artifactObject);
96
- });
97
95
  this._channel.on("viewportSizeChanged", ({ viewportSize }) => this._viewportSize = viewportSize);
98
96
  this._channel.on("webSocket", ({ webSocket }) => this.emit(import_events.Events.Page.WebSocket, import_network.WebSocket.from(webSocket)));
99
97
  this._channel.on("worker", ({ worker }) => this._onWorker(import_worker.Worker.from(worker)));
@@ -134,7 +132,7 @@ class Page extends import_channelOwner.ChannelOwner {
134
132
  route._context = this.context();
135
133
  const routeHandlers = this._routes.slice();
136
134
  for (const routeHandler of routeHandlers) {
137
- if (this._closeWasCalled || this._browserContext._closingStatus !== "none")
135
+ if (this._closeWasCalled || this._browserContext.isClosed())
138
136
  return;
139
137
  if (!routeHandler.matches(route.request().url()))
140
138
  continue;
@@ -211,15 +209,17 @@ class Page extends import_channelOwner.ChannelOwner {
211
209
  setDefaultTimeout(timeout) {
212
210
  this._timeoutSettings.setDefaultTimeout(timeout);
213
211
  }
214
- _forceVideo() {
215
- if (!this._video)
216
- this._video = new import_video.Video(this, this._connection);
217
- return this._video;
218
- }
219
212
  video() {
220
213
  if (!this._browserContext._options.recordVideo)
221
214
  return null;
222
- return this._forceVideo();
215
+ return this._video;
216
+ }
217
+ async pickLocator() {
218
+ const { selector } = await this._channel.pickLocator({});
219
+ return this.locator(selector);
220
+ }
221
+ async cancelPickLocator() {
222
+ await this._channel.cancelPickLocator({});
223
223
  }
224
224
  async $(selector, options) {
225
225
  return await this._mainFrame.$(selector, options);
@@ -252,13 +252,15 @@ class Page extends import_channelOwner.ChannelOwner {
252
252
  return await this._mainFrame.addStyleTag(options);
253
253
  }
254
254
  async exposeFunction(name, callback) {
255
- await this._channel.exposeBinding({ name });
255
+ const result = await this._channel.exposeBinding({ name });
256
256
  const binding = (source, ...args) => callback(...args);
257
257
  this._bindings.set(name, binding);
258
+ return import_disposable.DisposableObject.from(result.disposable);
258
259
  }
259
260
  async exposeBinding(name, callback, options = {}) {
260
- await this._channel.exposeBinding({ name, needsHandle: options.handle });
261
+ const result = await this._channel.exposeBinding({ name, needsHandle: options.handle });
261
262
  this._bindings.set(name, callback);
263
+ return import_disposable.DisposableObject.from(result.disposable);
262
264
  }
263
265
  async setExtraHTTPHeaders(headers) {
264
266
  (0, import_network.validateHeaders)(headers);
@@ -397,16 +399,14 @@ class Page extends import_channelOwner.ChannelOwner {
397
399
  (0, import_jsHandle.assertMaxArguments)(arguments.length, 2);
398
400
  return await this._mainFrame.evaluate(pageFunction, arg);
399
401
  }
400
- async _evaluateFunction(functionDeclaration) {
401
- return this._mainFrame._evaluateFunction(functionDeclaration);
402
- }
403
402
  async addInitScript(script, arg) {
404
403
  const source = await (0, import_clientHelper.evaluationScript)(this._platform, script, arg);
405
- await this._channel.addInitScript({ source });
404
+ return import_disposable.DisposableObject.from((await this._channel.addInitScript({ source })).disposable);
406
405
  }
407
406
  async route(url, handler, options = {}) {
408
407
  this._routes.unshift(new import_network.RouteHandler(this._platform, this._browserContext._options.baseURL, url, handler, options.times));
409
408
  await this._updateInterceptionPatterns({ title: "Route requests" });
409
+ return new import_disposable.DisposableStub(() => this.unroute(url, handler));
410
410
  }
411
411
  async routeFromHAR(har, options = {}) {
412
412
  const localUtils = this._connection.localUtils();
@@ -535,12 +535,18 @@ class Page extends import_channelOwner.ChannelOwner {
535
535
  async fill(selector, value, options) {
536
536
  return await this._mainFrame.fill(selector, value, options);
537
537
  }
538
- async consoleMessages() {
539
- const { messages } = await this._channel.consoleMessages();
538
+ async clearConsoleMessages() {
539
+ await this._channel.clearConsoleMessages();
540
+ }
541
+ async consoleMessages(options) {
542
+ const { messages } = await this._channel.consoleMessages({ filter: options?.filter });
540
543
  return messages.map((message) => new import_consoleMessage.ConsoleMessage(this._platform, message, this, null));
541
544
  }
542
- async pageErrors() {
543
- const { errors } = await this._channel.pageErrors();
545
+ async clearPageErrors() {
546
+ await this._channel.clearPageErrors();
547
+ }
548
+ async pageErrors(options) {
549
+ const { errors } = await this._channel.pageErrors({ filter: options?.filter });
544
550
  return errors.map((error) => (0, import_errors.parseError)(error));
545
551
  }
546
552
  locator(selector, options) {
@@ -676,32 +682,12 @@ class Page extends import_channelOwner.ChannelOwner {
676
682
  }
677
683
  return result.pdf;
678
684
  }
679
- // @ts-expect-error agents are hidden
680
- async agent(options = {}) {
681
- const params = {
682
- api: options.provider?.api,
683
- apiEndpoint: options.provider?.apiEndpoint,
684
- apiKey: options.provider?.apiKey,
685
- apiTimeout: options.provider?.apiTimeout,
686
- apiCacheFile: options.provider?._apiCacheFile,
687
- doNotRenderActive: options._doNotRenderActive,
688
- model: options.provider?.model,
689
- cacheFile: options.cache?.cacheFile,
690
- cacheOutFile: options.cache?.cacheOutFile,
691
- maxTokens: options.limits?.maxTokens,
692
- maxActions: options.limits?.maxActions,
693
- maxActionRetries: options.limits?.maxActionRetries,
694
- // @ts-expect-error runAgents is hidden
695
- secrets: options.secrets ? Object.entries(options.secrets).map(([name, value]) => ({ name, value })) : void 0,
696
- systemPrompt: options.systemPrompt
697
- };
698
- const { agent } = await this._channel.agent(params);
699
- const pageAgent = import_pageAgent.PageAgent.from(agent);
700
- pageAgent._expectTimeout = options?.expect?.timeout;
701
- return pageAgent;
685
+ async ariaSnapshot(options = {}) {
686
+ const result = await this.mainFrame()._channel.ariaSnapshot({ timeout: this._timeoutSettings.timeout(options), track: options._track, mode: options.mode, depth: options.depth });
687
+ return result.snapshot;
702
688
  }
703
- async _snapshotForAI(options = {}) {
704
- return await this._channel.snapshotForAI({ timeout: this._timeoutSettings.timeout(options), track: options.track });
689
+ async _setDockTile(image) {
690
+ await this._channel.setDockTile({ image });
705
691
  }
706
692
  }
707
693
  class BindingCall extends import_channelOwner.ChannelOwner {
@@ -66,9 +66,6 @@ const emptyPlatform = {
66
66
  streamWritable: (channel) => {
67
67
  throw new Error("Streams are not available");
68
68
  },
69
- zodToJsonSchema: (schema) => {
70
- throw new Error("Zod is not available");
71
- },
72
69
  zones: { empty: noopZone, current: () => noopZone }
73
70
  };
74
71
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1,88 @@
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 screencast_exports = {};
20
+ __export(screencast_exports, {
21
+ Screencast: () => Screencast
22
+ });
23
+ module.exports = __toCommonJS(screencast_exports);
24
+ var import_artifact = require("./artifact");
25
+ var import_disposable = require("./disposable");
26
+ class Screencast {
27
+ constructor(page) {
28
+ this._started = false;
29
+ this._onFrame = null;
30
+ this._page = page;
31
+ this._page._channel.on("screencastFrame", ({ data }) => {
32
+ void this._onFrame?.({ data });
33
+ });
34
+ }
35
+ async start(options = {}) {
36
+ if (this._started)
37
+ throw new Error("Screencast is already started");
38
+ this._started = true;
39
+ if (options.onFrame)
40
+ this._onFrame = options.onFrame;
41
+ const result = await this._page._channel.screencastStart({
42
+ size: options.size,
43
+ quality: options.quality,
44
+ sendFrames: !!options.onFrame,
45
+ record: !!options.path
46
+ });
47
+ if (result.artifact) {
48
+ this._artifact = import_artifact.Artifact.from(result.artifact);
49
+ this._savePath = options.path;
50
+ }
51
+ return new import_disposable.DisposableStub(() => this.stop());
52
+ }
53
+ async stop() {
54
+ await this._page._wrapApiCall(async () => {
55
+ this._started = false;
56
+ this._onFrame = null;
57
+ await this._page._channel.screencastStop();
58
+ if (this._savePath)
59
+ await this._artifact?.saveAs(this._savePath);
60
+ this._artifact = void 0;
61
+ this._savePath = void 0;
62
+ });
63
+ }
64
+ async showActions(options) {
65
+ await this._page._channel.screencastShowActions({ duration: options?.duration, position: options?.position, fontSize: options?.fontSize });
66
+ return new import_disposable.DisposableStub(() => this._page._channel.screencastHideActions());
67
+ }
68
+ async hideActions() {
69
+ await this._page._channel.screencastHideActions();
70
+ }
71
+ async showOverlay(html, options) {
72
+ const { id } = await this._page._channel.screencastShowOverlay({ html, duration: options?.duration });
73
+ return new import_disposable.DisposableStub(() => this._page._channel.screencastRemoveOverlay({ id }));
74
+ }
75
+ async showChapter(title, options) {
76
+ await this._page._channel.screencastChapter({ title, ...options });
77
+ }
78
+ async showOverlays() {
79
+ await this._page._channel.screencastSetOverlayVisible({ visible: true });
80
+ }
81
+ async hideOverlays() {
82
+ await this._page._channel.screencastSetOverlayVisible({ visible: false });
83
+ }
84
+ }
85
+ // Annotate the CommonJS export names for ESM import in node:
86
+ 0 && (module.exports = {
87
+ Screencast
88
+ });
@@ -41,9 +41,11 @@ class Selectors {
41
41
  setTestIdAttribute(attributeName) {
42
42
  this._testIdAttributeName = attributeName;
43
43
  (0, import_locator.setTestIdAttribute)(attributeName);
44
- for (const context of this._contextsForSelectors)
44
+ for (const context of this._contextsForSelectors) {
45
+ context._options.testIdAttributeName = attributeName;
45
46
  context._channel.setTestIdAttributeName({ testIdAttributeName: attributeName }).catch(() => {
46
47
  });
48
+ }
47
49
  }
48
50
  _withSelectorOptions(options) {
49
51
  return { ...options, selectorEngines: this._selectorEngines, testIdAttributeName: this._testIdAttributeName };
@@ -23,10 +23,12 @@ __export(tracing_exports, {
23
23
  module.exports = __toCommonJS(tracing_exports);
24
24
  var import_artifact = require("./artifact");
25
25
  var import_channelOwner = require("./channelOwner");
26
+ var import_disposable = require("./disposable");
26
27
  class Tracing extends import_channelOwner.ChannelOwner {
27
28
  constructor(parent, type, guid, initializer) {
28
29
  super(parent, type, guid, initializer);
29
30
  this._includeSources = false;
31
+ this._additionalSources = /* @__PURE__ */ new Set();
30
32
  this._isLive = false;
31
33
  this._isTracing = false;
32
34
  }
@@ -36,12 +38,12 @@ class Tracing extends import_channelOwner.ChannelOwner {
36
38
  async start(options = {}) {
37
39
  await this._wrapApiCall(async () => {
38
40
  this._includeSources = !!options.sources;
39
- this._isLive = !!options._live;
41
+ this._isLive = !!options.live;
40
42
  await this._channel.tracingStart({
41
43
  name: options.name,
42
44
  snapshots: options.snapshots,
43
45
  screenshots: options.screenshots,
44
- live: options._live
46
+ live: options.live
45
47
  });
46
48
  const { traceName } = await this._channel.tracingStartChunk({ name: options.name, title: options.title });
47
49
  await this._startCollectingStacks(traceName, this._isLive);
@@ -54,7 +56,10 @@ class Tracing extends import_channelOwner.ChannelOwner {
54
56
  });
55
57
  }
56
58
  async group(name, options = {}) {
59
+ if (options.location)
60
+ this._additionalSources.add(options.location.file);
57
61
  await this._channel.tracingGroup({ name, location: options.location });
62
+ return new import_disposable.DisposableStub(() => this.groupEnd());
58
63
  }
59
64
  async groupEnd() {
60
65
  await this._channel.tracingGroupEnd();
@@ -80,6 +85,8 @@ class Tracing extends import_channelOwner.ChannelOwner {
80
85
  }
81
86
  async _doStopChunk(filePath) {
82
87
  this._resetStackCounter();
88
+ const additionalSources = [...this._additionalSources];
89
+ this._additionalSources.clear();
83
90
  if (!filePath) {
84
91
  await this._channel.tracingStopChunk({ mode: "discard" });
85
92
  if (this._stacksId)
@@ -92,7 +99,7 @@ class Tracing extends import_channelOwner.ChannelOwner {
92
99
  const isLocal = !this._connection.isRemote();
93
100
  if (isLocal) {
94
101
  const result2 = await this._channel.tracingStopChunk({ mode: "entries" });
95
- await localUtils.zip({ zipFile: filePath, entries: result2.entries, mode: "write", stacksId: this._stacksId, includeSources: this._includeSources });
102
+ await localUtils.zip({ zipFile: filePath, entries: result2.entries, mode: "write", stacksId: this._stacksId, includeSources: this._includeSources, additionalSources });
96
103
  return;
97
104
  }
98
105
  const result = await this._channel.tracingStopChunk({ mode: "archive" });
@@ -104,7 +111,7 @@ class Tracing extends import_channelOwner.ChannelOwner {
104
111
  const artifact = import_artifact.Artifact.from(result.artifact);
105
112
  await artifact.saveAs(filePath);
106
113
  await artifact.delete();
107
- await localUtils.zip({ zipFile: filePath, entries: [], mode: "append", stacksId: this._stacksId, includeSources: this._includeSources });
114
+ await localUtils.zip({ zipFile: filePath, entries: [], mode: "append", stacksId: this._stacksId, includeSources: this._includeSources, additionalSources });
108
115
  }
109
116
  _resetStackCounter() {
110
117
  if (this._isTracing) {
@@ -21,36 +21,29 @@ __export(video_exports, {
21
21
  Video: () => Video
22
22
  });
23
23
  module.exports = __toCommonJS(video_exports);
24
- var import_manualPromise = require("../utils/isomorphic/manualPromise");
25
- class Video {
26
- constructor(page, connection) {
27
- this._artifact = null;
28
- this._artifactReadyPromise = new import_manualPromise.ManualPromise();
24
+ var import_eventEmitter = require("./eventEmitter");
25
+ class Video extends import_eventEmitter.EventEmitter {
26
+ constructor(page, connection, artifact) {
27
+ super(page._platform);
29
28
  this._isRemote = false;
30
29
  this._isRemote = connection.isRemote();
31
- this._artifact = page._closedOrCrashedScope.safeRace(this._artifactReadyPromise);
32
- }
33
- _artifactReady(artifact) {
34
- this._artifactReadyPromise.resolve(artifact);
30
+ this._artifact = artifact;
35
31
  }
36
32
  async path() {
37
33
  if (this._isRemote)
38
34
  throw new Error(`Path is not available when connecting remotely. Use saveAs() to save a local copy.`);
39
- const artifact = await this._artifact;
40
- if (!artifact)
41
- throw new Error("Page did not produce any video frames");
42
- return artifact._initializer.absolutePath;
35
+ if (!this._artifact)
36
+ throw new Error("Video recording has not been started.");
37
+ return this._artifact._initializer.absolutePath;
43
38
  }
44
39
  async saveAs(path) {
45
- const artifact = await this._artifact;
46
- if (!artifact)
47
- throw new Error("Page did not produce any video frames");
48
- return await artifact.saveAs(path);
40
+ if (!this._artifact)
41
+ throw new Error("Video recording has not been started.");
42
+ return await this._artifact.saveAs(path);
49
43
  }
50
44
  async delete() {
51
- const artifact = await this._artifact;
52
- if (artifact)
53
- await artifact.delete();
45
+ if (this._artifact)
46
+ await this._artifact.delete();
54
47
  }
55
48
  }
56
49
  // Annotate the CommonJS export names for ESM import in node:
@@ -21,7 +21,7 @@ __export(bindingsControllerSource_exports, {
21
21
  source: () => source
22
22
  });
23
23
  module.exports = __toCommonJS(bindingsControllerSource_exports);
24
- const source = '\nvar __commonJS = obj => {\n let required = false;\n let result;\n return function __require() {\n if (!required) {\n required = true;\n let fn;\n for (const name in obj) { fn = obj[name]; break; }\n const module = { exports: {} };\n fn(module.exports, module);\n result = module.exports;\n }\n return result;\n }\n};\nvar __export = (target, all) => {for (var name in all) target[name] = all[name];};\nvar __toESM = mod => ({ ...mod, \'default\': mod });\nvar __toCommonJS = mod => ({ ...mod, __esModule: true });\n\n\n// packages/injected/src/bindingsController.ts\nvar bindingsController_exports = {};\n__export(bindingsController_exports, {\n BindingsController: () => BindingsController\n});\nmodule.exports = __toCommonJS(bindingsController_exports);\n\n// packages/playwright-core/src/utils/isomorphic/utilityScriptSerializers.ts\nfunction isRegExp(obj) {\n try {\n return obj instanceof RegExp || Object.prototype.toString.call(obj) === "[object RegExp]";\n } catch (error) {\n return false;\n }\n}\nfunction isDate(obj) {\n try {\n return obj instanceof Date || Object.prototype.toString.call(obj) === "[object Date]";\n } catch (error) {\n return false;\n }\n}\nfunction isURL(obj) {\n try {\n return obj instanceof URL || Object.prototype.toString.call(obj) === "[object URL]";\n } catch (error) {\n return false;\n }\n}\nfunction isError(obj) {\n var _a;\n try {\n return obj instanceof Error || obj && ((_a = Object.getPrototypeOf(obj)) == null ? void 0 : _a.name) === "Error";\n } catch (error) {\n return false;\n }\n}\nfunction isTypedArray(obj, constructor) {\n try {\n return obj instanceof constructor || Object.prototype.toString.call(obj) === `[object ${constructor.name}]`;\n } catch (error) {\n return false;\n }\n}\nvar typedArrayConstructors = {\n i8: Int8Array,\n ui8: Uint8Array,\n ui8c: Uint8ClampedArray,\n i16: Int16Array,\n ui16: Uint16Array,\n i32: Int32Array,\n ui32: Uint32Array,\n // TODO: add Float16Array once it\'s in baseline\n f32: Float32Array,\n f64: Float64Array,\n bi64: BigInt64Array,\n bui64: BigUint64Array\n};\nfunction typedArrayToBase64(array) {\n if ("toBase64" in array)\n return array.toBase64();\n const binary = Array.from(new Uint8Array(array.buffer, array.byteOffset, array.byteLength)).map((b) => String.fromCharCode(b)).join("");\n return btoa(binary);\n}\nfunction serializeAsCallArgument(value, handleSerializer) {\n return serialize(value, handleSerializer, { visited: /* @__PURE__ */ new Map(), lastId: 0 });\n}\nfunction serialize(value, handleSerializer, visitorInfo) {\n if (value && typeof value === "object") {\n if (typeof globalThis.Window === "function" && value instanceof globalThis.Window)\n return "ref: <Window>";\n if (typeof globalThis.Document === "function" && value instanceof globalThis.Document)\n return "ref: <Document>";\n if (typeof globalThis.Node === "function" && value instanceof globalThis.Node)\n return "ref: <Node>";\n }\n return innerSerialize(value, handleSerializer, visitorInfo);\n}\nfunction innerSerialize(value, handleSerializer, visitorInfo) {\n var _a;\n const result = handleSerializer(value);\n if ("fallThrough" in result)\n value = result.fallThrough;\n else\n return result;\n if (typeof value === "symbol")\n return { v: "undefined" };\n if (Object.is(value, void 0))\n return { v: "undefined" };\n if (Object.is(value, null))\n return { v: "null" };\n if (Object.is(value, NaN))\n return { v: "NaN" };\n if (Object.is(value, Infinity))\n return { v: "Infinity" };\n if (Object.is(value, -Infinity))\n return { v: "-Infinity" };\n if (Object.is(value, -0))\n return { v: "-0" };\n if (typeof value === "boolean")\n return value;\n if (typeof value === "number")\n return value;\n if (typeof value === "string")\n return value;\n if (typeof value === "bigint")\n return { bi: value.toString() };\n if (isError(value)) {\n let stack;\n if ((_a = value.stack) == null ? void 0 : _a.startsWith(value.name + ": " + value.message)) {\n stack = value.stack;\n } else {\n stack = `${value.name}: ${value.message}\n${value.stack}`;\n }\n return { e: { n: value.name, m: value.message, s: stack } };\n }\n if (isDate(value))\n return { d: value.toJSON() };\n if (isURL(value))\n return { u: value.toJSON() };\n if (isRegExp(value))\n return { r: { p: value.source, f: value.flags } };\n for (const [k, ctor] of Object.entries(typedArrayConstructors)) {\n if (isTypedArray(value, ctor))\n return { ta: { b: typedArrayToBase64(value), k } };\n }\n const id = visitorInfo.visited.get(value);\n if (id)\n return { ref: id };\n if (Array.isArray(value)) {\n const a = [];\n const id2 = ++visitorInfo.lastId;\n visitorInfo.visited.set(value, id2);\n for (let i = 0; i < value.length; ++i)\n a.push(serialize(value[i], handleSerializer, visitorInfo));\n return { a, id: id2 };\n }\n if (typeof value === "object") {\n const o = [];\n const id2 = ++visitorInfo.lastId;\n visitorInfo.visited.set(value, id2);\n for (const name of Object.keys(value)) {\n let item;\n try {\n item = value[name];\n } catch (e) {\n continue;\n }\n if (name === "toJSON" && typeof item === "function")\n o.push({ k: name, v: { o: [], id: 0 } });\n else\n o.push({ k: name, v: serialize(item, handleSerializer, visitorInfo) });\n }\n let jsonWrapper;\n try {\n if (o.length === 0 && value.toJSON && typeof value.toJSON === "function")\n jsonWrapper = { value: value.toJSON() };\n } catch (e) {\n }\n if (jsonWrapper)\n return innerSerialize(jsonWrapper.value, handleSerializer, visitorInfo);\n return { o, id: id2 };\n }\n}\n\n// packages/injected/src/bindingsController.ts\nvar BindingsController = class {\n constructor(global, globalBindingName) {\n this._bindings = /* @__PURE__ */ new Map();\n this._global = global;\n this._globalBindingName = globalBindingName;\n }\n addBinding(bindingName, needsHandle) {\n const data = {\n callbacks: /* @__PURE__ */ new Map(),\n lastSeq: 0,\n handles: /* @__PURE__ */ new Map(),\n removed: false\n };\n this._bindings.set(bindingName, data);\n this._global[bindingName] = (...args) => {\n if (data.removed)\n throw new Error(`binding "${bindingName}" has been removed`);\n if (needsHandle && args.slice(1).some((arg) => arg !== void 0))\n throw new Error(`exposeBindingHandle supports a single argument, ${args.length} received`);\n const seq = ++data.lastSeq;\n const promise = new Promise((resolve, reject) => data.callbacks.set(seq, { resolve, reject }));\n let payload;\n if (needsHandle) {\n data.handles.set(seq, args[0]);\n payload = { name: bindingName, seq };\n } else {\n const serializedArgs = [];\n for (let i = 0; i < args.length; i++) {\n serializedArgs[i] = serializeAsCallArgument(args[i], (v) => {\n return { fallThrough: v };\n });\n }\n payload = { name: bindingName, seq, serializedArgs };\n }\n this._global[this._globalBindingName](JSON.stringify(payload));\n return promise;\n };\n }\n removeBinding(bindingName) {\n const data = this._bindings.get(bindingName);\n if (data)\n data.removed = true;\n this._bindings.delete(bindingName);\n delete this._global[bindingName];\n }\n takeBindingHandle(arg) {\n const handles = this._bindings.get(arg.name).handles;\n const handle = handles.get(arg.seq);\n handles.delete(arg.seq);\n return handle;\n }\n deliverBindingResult(arg) {\n const callbacks = this._bindings.get(arg.name).callbacks;\n if ("error" in arg)\n callbacks.get(arg.seq).reject(arg.error);\n else\n callbacks.get(arg.seq).resolve(arg.result);\n callbacks.delete(arg.seq);\n }\n};\n';
24
+ const source = '\nvar __commonJS = obj => {\n let required = false;\n let result;\n return function __require() {\n if (!required) {\n required = true;\n let fn;\n for (const name in obj) { fn = obj[name]; break; }\n const module = { exports: {} };\n fn(module.exports, module);\n result = module.exports;\n }\n return result;\n }\n};\nvar __export = (target, all) => {for (var name in all) target[name] = all[name];};\nvar __toESM = mod => ({ ...mod, \'default\': mod });\nvar __toCommonJS = mod => ({ ...mod, __esModule: true });\n\n\n// packages/injected/src/bindingsController.ts\nvar bindingsController_exports = {};\n__export(bindingsController_exports, {\n BindingsController: () => BindingsController\n});\nmodule.exports = __toCommonJS(bindingsController_exports);\n\n// packages/playwright-core/src/utils/isomorphic/utilityScriptSerializers.ts\nfunction isRegExp(obj) {\n try {\n return obj instanceof RegExp || Object.prototype.toString.call(obj) === "[object RegExp]";\n } catch (error) {\n return false;\n }\n}\nfunction isDate(obj) {\n try {\n return obj instanceof Date || Object.prototype.toString.call(obj) === "[object Date]";\n } catch (error) {\n return false;\n }\n}\nfunction isURL(obj) {\n try {\n return obj instanceof URL || Object.prototype.toString.call(obj) === "[object URL]";\n } catch (error) {\n return false;\n }\n}\nfunction isError(obj) {\n var _a;\n try {\n return obj instanceof Error || obj && ((_a = Object.getPrototypeOf(obj)) == null ? void 0 : _a.name) === "Error";\n } catch (error) {\n return false;\n }\n}\nfunction isTypedArray(obj, constructor) {\n try {\n return obj instanceof constructor || Object.prototype.toString.call(obj) === `[object ${constructor.name}]`;\n } catch (error) {\n return false;\n }\n}\nfunction isArrayBuffer(obj) {\n try {\n return obj instanceof ArrayBuffer || Object.prototype.toString.call(obj) === "[object ArrayBuffer]";\n } catch (error) {\n return false;\n }\n}\nvar typedArrayConstructors = {\n i8: Int8Array,\n ui8: Uint8Array,\n ui8c: Uint8ClampedArray,\n i16: Int16Array,\n ui16: Uint16Array,\n i32: Int32Array,\n ui32: Uint32Array,\n // TODO: add Float16Array once it\'s in baseline\n f32: Float32Array,\n f64: Float64Array,\n bi64: BigInt64Array,\n bui64: BigUint64Array\n};\nfunction typedArrayToBase64(array) {\n if ("toBase64" in array)\n return array.toBase64();\n const binary = Array.from(new Uint8Array(array.buffer, array.byteOffset, array.byteLength)).map((b) => String.fromCharCode(b)).join("");\n return btoa(binary);\n}\nfunction serializeAsCallArgument(value, handleSerializer) {\n return serialize(value, handleSerializer, { visited: /* @__PURE__ */ new Map(), lastId: 0 });\n}\nfunction serialize(value, handleSerializer, visitorInfo) {\n if (value && typeof value === "object") {\n if (typeof globalThis.Window === "function" && value instanceof globalThis.Window)\n return "ref: <Window>";\n if (typeof globalThis.Document === "function" && value instanceof globalThis.Document)\n return "ref: <Document>";\n if (typeof globalThis.Node === "function" && value instanceof globalThis.Node)\n return "ref: <Node>";\n }\n return innerSerialize(value, handleSerializer, visitorInfo);\n}\nfunction innerSerialize(value, handleSerializer, visitorInfo) {\n var _a;\n const result = handleSerializer(value);\n if ("fallThrough" in result)\n value = result.fallThrough;\n else\n return result;\n if (typeof value === "symbol")\n return { v: "undefined" };\n if (Object.is(value, void 0))\n return { v: "undefined" };\n if (Object.is(value, null))\n return { v: "null" };\n if (Object.is(value, NaN))\n return { v: "NaN" };\n if (Object.is(value, Infinity))\n return { v: "Infinity" };\n if (Object.is(value, -Infinity))\n return { v: "-Infinity" };\n if (Object.is(value, -0))\n return { v: "-0" };\n if (typeof value === "boolean")\n return value;\n if (typeof value === "number")\n return value;\n if (typeof value === "string")\n return value;\n if (typeof value === "bigint")\n return { bi: value.toString() };\n if (isError(value)) {\n let stack;\n if ((_a = value.stack) == null ? void 0 : _a.startsWith(value.name + ": " + value.message)) {\n stack = value.stack;\n } else {\n stack = `${value.name}: ${value.message}\n${value.stack}`;\n }\n return { e: { n: value.name, m: value.message, s: stack } };\n }\n if (isDate(value))\n return { d: value.toJSON() };\n if (isURL(value))\n return { u: value.toJSON() };\n if (isRegExp(value))\n return { r: { p: value.source, f: value.flags } };\n for (const [k, ctor] of Object.entries(typedArrayConstructors)) {\n if (isTypedArray(value, ctor))\n return { ta: { b: typedArrayToBase64(value), k } };\n }\n if (isArrayBuffer(value))\n return { ab: { b: typedArrayToBase64(new Uint8Array(value)) } };\n const id = visitorInfo.visited.get(value);\n if (id)\n return { ref: id };\n if (Array.isArray(value)) {\n const a = [];\n const id2 = ++visitorInfo.lastId;\n visitorInfo.visited.set(value, id2);\n for (let i = 0; i < value.length; ++i)\n a.push(serialize(value[i], handleSerializer, visitorInfo));\n return { a, id: id2 };\n }\n if (typeof value === "object") {\n const o = [];\n const id2 = ++visitorInfo.lastId;\n visitorInfo.visited.set(value, id2);\n for (const name of Object.keys(value)) {\n let item;\n try {\n item = value[name];\n } catch (e) {\n continue;\n }\n if (name === "toJSON" && typeof item === "function")\n o.push({ k: name, v: { o: [], id: 0 } });\n else\n o.push({ k: name, v: serialize(item, handleSerializer, visitorInfo) });\n }\n let jsonWrapper;\n try {\n if (o.length === 0 && value.toJSON && typeof value.toJSON === "function")\n jsonWrapper = { value: value.toJSON() };\n } catch (e) {\n }\n if (jsonWrapper)\n return innerSerialize(jsonWrapper.value, handleSerializer, visitorInfo);\n return { o, id: id2 };\n }\n}\n\n// packages/injected/src/bindingsController.ts\nvar BindingsController = class {\n constructor(global, globalBindingName) {\n this._bindings = /* @__PURE__ */ new Map();\n this._global = global;\n this._globalBindingName = globalBindingName;\n }\n addBinding(bindingName, needsHandle) {\n const data = {\n callbacks: /* @__PURE__ */ new Map(),\n lastSeq: 0,\n handles: /* @__PURE__ */ new Map(),\n removed: false\n };\n this._bindings.set(bindingName, data);\n this._global[bindingName] = (...args) => {\n if (data.removed)\n throw new Error(`binding "${bindingName}" has been removed`);\n if (needsHandle && args.slice(1).some((arg) => arg !== void 0))\n throw new Error(`exposeBindingHandle supports a single argument, ${args.length} received`);\n const seq = ++data.lastSeq;\n const promise = new Promise((resolve, reject) => data.callbacks.set(seq, { resolve, reject }));\n let payload;\n if (needsHandle) {\n data.handles.set(seq, args[0]);\n payload = { name: bindingName, seq };\n } else {\n const serializedArgs = [];\n for (let i = 0; i < args.length; i++) {\n serializedArgs[i] = serializeAsCallArgument(args[i], (v) => {\n return { fallThrough: v };\n });\n }\n payload = { name: bindingName, seq, serializedArgs };\n }\n this._global[this._globalBindingName](JSON.stringify(payload));\n return promise;\n };\n }\n removeBinding(bindingName) {\n const data = this._bindings.get(bindingName);\n if (data)\n data.removed = true;\n this._bindings.delete(bindingName);\n delete this._global[bindingName];\n }\n takeBindingHandle(arg) {\n const handles = this._bindings.get(arg.name).handles;\n const handle = handles.get(arg.seq);\n handles.delete(arg.seq);\n return handle;\n }\n deliverBindingResult(arg) {\n const callbacks = this._bindings.get(arg.name).callbacks;\n if ("error" in arg)\n callbacks.get(arg.seq).reject(arg.error);\n else\n callbacks.get(arg.seq).resolve(arg.result);\n callbacks.delete(arg.seq);\n }\n};\n';
25
25
  // Annotate the CommonJS export names for ESM import in node:
26
26
  0 && (module.exports = {
27
27
  source