patchright-core 1.52.4 → 1.55.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 (218) hide show
  1. package/ThirdPartyNotices.txt +65 -123
  2. package/bin/reinstall_chrome_beta_mac.sh +1 -1
  3. package/bin/reinstall_chrome_stable_mac.sh +1 -1
  4. package/bin/reinstall_msedge_beta_mac.sh +1 -1
  5. package/bin/reinstall_msedge_dev_mac.sh +1 -1
  6. package/bin/reinstall_msedge_stable_mac.sh +1 -1
  7. package/browsers.json +14 -14
  8. package/index.js +1 -1
  9. package/lib/androidServerImpl.js +4 -2
  10. package/lib/browserServerImpl.js +47 -12
  11. package/lib/cli/program.js +116 -50
  12. package/lib/cli/programWithTestStub.js +1 -1
  13. package/lib/client/android.js +30 -34
  14. package/lib/client/browser.js +54 -17
  15. package/lib/client/browserContext.js +67 -71
  16. package/lib/client/browserType.js +25 -34
  17. package/lib/client/channelOwner.js +20 -24
  18. package/lib/client/connection.js +6 -10
  19. package/lib/client/electron.js +8 -3
  20. package/lib/client/elementHandle.js +18 -21
  21. package/lib/client/fetch.js +5 -3
  22. package/lib/client/frame.js +57 -35
  23. package/lib/client/input.js +3 -1
  24. package/lib/client/jsHandle.js +4 -0
  25. package/lib/client/localUtils.js +0 -1
  26. package/lib/client/locator.js +32 -28
  27. package/lib/client/network.js +5 -12
  28. package/lib/client/page.js +32 -32
  29. package/lib/client/playwright.js +6 -16
  30. package/lib/client/selectors.js +18 -38
  31. package/lib/client/timeoutSettings.js +12 -8
  32. package/lib/client/tracing.js +24 -20
  33. package/lib/client/waiter.js +2 -2
  34. package/lib/client/webSocket.js +4 -22
  35. package/lib/generated/bindingsControllerSource.js +28 -0
  36. package/lib/generated/clockSource.js +1 -1
  37. package/lib/generated/injectedScriptSource.js +1 -1
  38. package/lib/generated/pollingRecorderSource.js +1 -1
  39. package/lib/generated/storageScriptSource.js +28 -0
  40. package/lib/generated/utilityScriptSource.js +1 -1
  41. package/lib/generated/webSocketMockSource.js +12 -50
  42. package/lib/inProcessFactory.js +9 -6
  43. package/lib/outofprocess.js +0 -2
  44. package/lib/protocol/validator.js +423 -346
  45. package/lib/protocol/validatorPrimitives.js +18 -4
  46. package/lib/remote/playwrightConnection.js +29 -166
  47. package/lib/remote/playwrightServer.js +233 -35
  48. package/lib/server/android/android.js +97 -83
  49. package/lib/server/android/backendAdb.js +0 -2
  50. package/lib/server/bidi/bidiBrowser.js +139 -73
  51. package/lib/server/bidi/bidiChromium.js +23 -22
  52. package/lib/server/bidi/bidiExecutionContext.js +2 -1
  53. package/lib/server/bidi/bidiFirefox.js +17 -14
  54. package/lib/server/bidi/bidiInput.js +22 -22
  55. package/lib/server/bidi/bidiNetworkManager.js +8 -11
  56. package/lib/server/bidi/bidiPage.js +42 -86
  57. package/lib/server/bidi/third_party/bidiProtocol.js +5 -133
  58. package/lib/server/bidi/third_party/bidiProtocolCore.js +179 -0
  59. package/lib/server/{dispatchers/selectorsDispatcher.js → bidi/third_party/bidiProtocolPermissions.js} +20 -18
  60. package/lib/server/browser.js +30 -21
  61. package/lib/server/browserContext.js +203 -165
  62. package/lib/server/browserType.js +109 -107
  63. package/lib/server/chromium/chromium.js +84 -69
  64. package/lib/server/chromium/chromiumSwitches.js +13 -20
  65. package/lib/server/chromium/crBrowser.js +74 -40
  66. package/lib/server/chromium/crConnection.js +8 -9
  67. package/lib/server/chromium/crCoverage.js +11 -8
  68. package/lib/server/chromium/crDragDrop.js +25 -20
  69. package/lib/server/chromium/crExecutionContext.js +2 -1
  70. package/lib/server/chromium/crInput.js +32 -29
  71. package/lib/server/chromium/crNetworkManager.js +45 -33
  72. package/lib/server/chromium/crPage.js +98 -73
  73. package/lib/server/chromium/crServiceWorker.js +13 -18
  74. package/lib/server/chromium/videoRecorder.js +10 -18
  75. package/lib/server/clock.js +51 -39
  76. package/lib/server/codegen/csharp.js +10 -5
  77. package/lib/server/codegen/java.js +1 -1
  78. package/lib/server/codegen/javascript.js +1 -1
  79. package/lib/server/codegen/jsonl.js +2 -1
  80. package/lib/server/codegen/language.js +22 -1
  81. package/lib/server/codegen/languages.js +4 -4
  82. package/lib/server/codegen/python.js +1 -1
  83. package/lib/server/cookieStore.js +3 -1
  84. package/lib/server/debugController.js +105 -71
  85. package/lib/server/debugger.js +6 -23
  86. package/lib/server/deviceDescriptorsSource.json +237 -127
  87. package/lib/server/dialog.js +50 -6
  88. package/lib/server/dispatchers/androidDispatcher.js +77 -62
  89. package/lib/server/dispatchers/artifactDispatcher.js +18 -18
  90. package/lib/server/dispatchers/browserContextDispatcher.js +141 -91
  91. package/lib/server/dispatchers/browserDispatcher.js +55 -88
  92. package/lib/server/dispatchers/browserTypeDispatcher.js +18 -9
  93. package/lib/server/dispatchers/cdpSessionDispatcher.js +4 -4
  94. package/lib/server/dispatchers/debugControllerDispatcher.js +12 -21
  95. package/lib/server/dispatchers/dialogDispatcher.js +4 -4
  96. package/lib/server/dispatchers/dispatcher.js +78 -53
  97. package/lib/server/dispatchers/electronDispatcher.js +19 -20
  98. package/lib/server/dispatchers/elementHandlerDispatcher.js +83 -93
  99. package/lib/server/dispatchers/frameDispatcher.js +99 -102
  100. package/lib/server/dispatchers/jsHandleDispatcher.js +21 -16
  101. package/lib/server/dispatchers/jsonPipeDispatcher.js +4 -4
  102. package/lib/server/dispatchers/localUtilsDispatcher.js +53 -59
  103. package/lib/server/dispatchers/networkDispatchers.js +41 -35
  104. package/lib/server/dispatchers/pageDispatcher.js +156 -107
  105. package/lib/server/dispatchers/playwrightDispatcher.js +37 -25
  106. package/lib/server/dispatchers/streamDispatcher.js +15 -8
  107. package/lib/server/dispatchers/tracingDispatcher.js +22 -13
  108. package/lib/server/dispatchers/webSocketRouteDispatcher.js +46 -35
  109. package/lib/server/dispatchers/writableStreamDispatcher.js +16 -10
  110. package/lib/server/dom.js +198 -266
  111. package/lib/server/download.js +3 -3
  112. package/lib/server/electron/electron.js +96 -103
  113. package/lib/server/electron/loader.js +1 -1
  114. package/lib/server/fetch.js +22 -41
  115. package/lib/server/fileUploadUtils.js +1 -1
  116. package/lib/server/firefox/ffBrowser.js +79 -55
  117. package/lib/server/firefox/ffExecutionContext.js +2 -1
  118. package/lib/server/firefox/ffInput.js +23 -23
  119. package/lib/server/firefox/ffNetworkManager.js +8 -6
  120. package/lib/server/firefox/ffPage.js +39 -36
  121. package/lib/server/firefox/firefox.js +9 -10
  122. package/lib/server/frameSelectors.js +65 -22
  123. package/lib/server/frames.js +516 -544
  124. package/lib/server/har/harRecorder.js +1 -1
  125. package/lib/server/har/harTracer.js +4 -2
  126. package/lib/server/helper.js +3 -7
  127. package/lib/server/index.js +0 -3
  128. package/lib/server/input.js +47 -54
  129. package/lib/server/instrumentation.js +8 -14
  130. package/lib/server/javascript.js +9 -17
  131. package/lib/server/launchApp.js +48 -30
  132. package/lib/server/localUtils.js +45 -38
  133. package/lib/server/network.js +44 -10
  134. package/lib/server/page.js +233 -178
  135. package/lib/server/pageBinding.js +6 -7
  136. package/lib/server/playwright.js +4 -14
  137. package/lib/server/progress.js +57 -49
  138. package/lib/server/recorder/recorderApp.js +298 -95
  139. package/lib/server/recorder/recorderRunner.js +23 -24
  140. package/lib/server/recorder/recorderSignalProcessor.js +83 -0
  141. package/lib/server/recorder/recorderUtils.js +67 -10
  142. package/lib/server/recorder.js +284 -146
  143. package/lib/server/registry/index.js +83 -48
  144. package/lib/server/registry/nativeDeps.js +175 -0
  145. package/lib/server/registry/oopDownloadBrowserMain.js +1 -1
  146. package/lib/server/screenshotter.js +84 -83
  147. package/lib/server/selectors.js +12 -12
  148. package/lib/server/socksClientCertificatesInterceptor.js +198 -136
  149. package/lib/server/trace/recorder/snapshotter.js +12 -19
  150. package/lib/server/trace/recorder/tracing.js +36 -27
  151. package/lib/server/trace/viewer/traceViewer.js +11 -20
  152. package/lib/server/transport.js +20 -22
  153. package/lib/server/utils/comparators.js +2 -2
  154. package/lib/server/utils/debug.js +3 -8
  155. package/lib/server/utils/debugLogger.js +8 -0
  156. package/lib/server/utils/hostPlatform.js +3 -1
  157. package/lib/server/utils/network.js +35 -25
  158. package/lib/server/utils/nodePlatform.js +1 -1
  159. package/lib/server/utils/processLauncher.js +4 -1
  160. package/lib/server/utils/wsServer.js +11 -17
  161. package/lib/server/webkit/webkit.js +5 -2
  162. package/lib/server/webkit/wkBrowser.js +51 -28
  163. package/lib/server/webkit/wkExecutionContext.js +2 -1
  164. package/lib/server/webkit/wkInput.js +25 -25
  165. package/lib/server/webkit/wkInterceptableRequest.js +1 -1
  166. package/lib/server/webkit/wkPage.js +80 -59
  167. package/lib/server/webkit/wkProvisionalPage.js +1 -1
  168. package/lib/server/webkit/wkWorkers.js +7 -7
  169. package/lib/utils/isomorphic/ariaSnapshot.js +13 -7
  170. package/lib/utils/isomorphic/cssParser.js +1 -2
  171. package/lib/utils/isomorphic/locatorGenerators.js +18 -0
  172. package/lib/utils/isomorphic/manualPromise.js +1 -2
  173. package/lib/utils/isomorphic/mimeType.js +1 -2
  174. package/lib/utils/isomorphic/multimap.js +1 -2
  175. package/lib/utils/isomorphic/oldUtilityScriptSerializers.js +248 -0
  176. package/lib/utils/isomorphic/protocolFormatter.js +78 -0
  177. package/lib/utils/isomorphic/protocolMetainfo.js +318 -0
  178. package/lib/utils/isomorphic/selectorParser.js +3 -4
  179. package/lib/utils/isomorphic/stringUtils.js +3 -24
  180. package/lib/utils/isomorphic/time.js +9 -4
  181. package/lib/utils/isomorphic/timeoutRunner.js +3 -4
  182. package/lib/utils/isomorphic/traceUtils.js +2 -3
  183. package/lib/utils/isomorphic/urlMatch.js +21 -7
  184. package/lib/utils/isomorphic/utilityScriptSerializers.js +208 -205
  185. package/lib/utils.js +8 -2
  186. package/lib/utilsBundleImpl/index.js +160 -150
  187. package/lib/vite/htmlReport/index.html +17 -17
  188. package/lib/vite/recorder/assets/{codeMirrorModule-CXVeovup.js → codeMirrorModule-DzQ0k89p.js} +1 -1
  189. package/lib/vite/recorder/assets/{index-eHBmevrY.css → index-CI4HQ-Zb.css} +1 -1
  190. package/lib/vite/recorder/assets/index-D7C7daHH.js +184 -0
  191. package/lib/vite/recorder/index.html +3 -3
  192. package/lib/vite/traceViewer/assets/{codeMirrorModule-_GLjJL-7.js → codeMirrorModule-Di48jgWx.js} +1 -1
  193. package/lib/vite/traceViewer/assets/defaultSettingsView-szBn8781.js +256 -0
  194. package/lib/vite/traceViewer/defaultSettingsView.DVJHpiGt.css +1 -0
  195. package/lib/vite/traceViewer/index.BFsek2M6.css +1 -0
  196. package/lib/vite/traceViewer/index.DQvXoPLL.js +2 -0
  197. package/lib/vite/traceViewer/index.html +6 -6
  198. package/lib/vite/traceViewer/sw.bundle.js +3 -3
  199. package/lib/vite/traceViewer/uiMode.dBV3oN9h.js +5 -0
  200. package/lib/vite/traceViewer/uiMode.html +4 -4
  201. package/lib/zipBundleImpl.js +4 -4
  202. package/package.json +1 -1
  203. package/types/protocol.d.ts +712 -107
  204. package/types/types.d.ts +148 -37
  205. package/lib/generated/consoleApiSource.js +0 -28
  206. package/lib/protocol/debug.js +0 -211
  207. package/lib/server/recorder/contextRecorder.js +0 -286
  208. package/lib/server/recorder/recorderCollection.js +0 -116
  209. package/lib/server/recorder/recorderFrontend.js +0 -16
  210. package/lib/server/storageScript.js +0 -154
  211. package/lib/server/timeoutSettings.js +0 -89
  212. package/lib/utils/isomorphic/builtins.js +0 -86
  213. package/lib/vite/recorder/assets/index-BsWQsSGl.js +0 -184
  214. package/lib/vite/traceViewer/assets/defaultSettingsView-DtCQiGHe.js +0 -265
  215. package/lib/vite/traceViewer/defaultSettingsView.QdHITyLI.css +0 -1
  216. package/lib/vite/traceViewer/index.CFOW-Ezb.css +0 -1
  217. package/lib/vite/traceViewer/index.cFZzK9RN.js +0 -2
  218. package/lib/vite/traceViewer/uiMode.XVPIqBeS.js +0 -5
@@ -51,7 +51,6 @@ class Request extends import_channelOwner.ChannelOwner {
51
51
  this._redirectedTo = null;
52
52
  this._failureText = null;
53
53
  this._fallbackOverrides = {};
54
- this.markAsInternalType();
55
54
  this._redirectedFrom = Request.fromNullable(initializer.redirectedFrom);
56
55
  if (this._redirectedFrom)
57
56
  this._redirectedFrom._redirectedTo = this;
@@ -121,7 +120,7 @@ class Request extends import_channelOwner.ChannelOwner {
121
120
  if (!this._actualHeadersPromise) {
122
121
  this._actualHeadersPromise = this._wrapApiCall(async () => {
123
122
  return new RawHeaders((await this._channel.rawRequestHeaders()).headers);
124
- });
123
+ }, { internal: true });
125
124
  }
126
125
  return await this._actualHeadersPromise;
127
126
  }
@@ -138,9 +137,7 @@ class Request extends import_channelOwner.ChannelOwner {
138
137
  return Response.fromNullable((await this._channel.response()).response);
139
138
  }
140
139
  async _internalResponse() {
141
- return await this._wrapApiCall(async () => {
142
- return Response.fromNullable((await this._channel.response()).response);
143
- }, true);
140
+ return Response.fromNullable((await this._channel.response()).response);
144
141
  }
145
142
  frame() {
146
143
  if (!this._initializer.frame) {
@@ -222,7 +219,6 @@ class Route extends import_channelOwner.ChannelOwner {
222
219
  super(parent, type, guid, initializer);
223
220
  this._handlingPromise = null;
224
221
  this._didThrow = false;
225
- this.markAsInternalType();
226
222
  }
227
223
  static from(route) {
228
224
  return route._object;
@@ -259,9 +255,7 @@ class Route extends import_channelOwner.ChannelOwner {
259
255
  }
260
256
  async fulfill(options = {}) {
261
257
  await this._handleRoute(async () => {
262
- await this._wrapApiCall(async () => {
263
- await this._innerFulfill(options);
264
- });
258
+ await this._innerFulfill(options);
265
259
  });
266
260
  }
267
261
  async _handleRoute(callback) {
@@ -358,7 +352,6 @@ class WebSocketRoute extends import_channelOwner.ChannelOwner {
358
352
  constructor(parent, type, guid, initializer) {
359
353
  super(parent, type, guid, initializer);
360
354
  this._connected = false;
361
- this.markAsInternalType();
362
355
  this._server = {
363
356
  onMessage: (handler) => {
364
357
  this._onServerMessage = handler;
@@ -455,7 +448,8 @@ class WebSocketRoute extends import_channelOwner.ChannelOwner {
455
448
  async _afterHandle() {
456
449
  if (this._connected)
457
450
  return;
458
- await this._channel.ensureOpened();
451
+ await this._channel.ensureOpened().catch(() => {
452
+ });
459
453
  }
460
454
  }
461
455
  class WebSocketRouteHandler {
@@ -492,7 +486,6 @@ class Response extends import_channelOwner.ChannelOwner {
492
486
  constructor(parent, type, guid, initializer) {
493
487
  super(parent, type, guid, initializer);
494
488
  this._finishedPromise = new import_manualPromise.ManualPromise();
495
- this.markAsInternalType();
496
489
  this._provisionalHeaders = new RawHeaders(initializer.headers);
497
490
  this._request = Request.from(this._initializer.request);
498
491
  Object.assign(this._request._timing, this._initializer.timing);
@@ -74,7 +74,7 @@ class Page extends import_channelOwner.ChannelOwner {
74
74
  this._mainFrame = import_frame.Frame.from(initializer.mainFrame);
75
75
  this._mainFrame._page = this;
76
76
  this._frames.add(this._mainFrame);
77
- this._viewportSize = initializer.viewportSize || null;
77
+ this._viewportSize = initializer.viewportSize;
78
78
  this._closed = initializer.isClosed;
79
79
  this._opener = Page.fromNullable(initializer.opener);
80
80
  this._channel.on("bindingCall", ({ binding }) => this._onBinding(BindingCall.from(binding)));
@@ -94,6 +94,7 @@ class Page extends import_channelOwner.ChannelOwner {
94
94
  const artifactObject = import_artifact.Artifact.from(artifact);
95
95
  this._forceVideo()._artifactReady(artifactObject);
96
96
  });
97
+ this._channel.on("viewportSizeChanged", ({ viewportSize }) => this._viewportSize = viewportSize);
97
98
  this._channel.on("webSocket", ({ webSocket }) => this.emit(import_events.Events.Page.WebSocket, import_network.WebSocket.from(webSocket)));
98
99
  this._channel.on("worker", ({ worker }) => this._onWorker(import_worker.Worker.from(worker)));
99
100
  this.coverage = new import_coverage.Coverage(this._channel);
@@ -133,7 +134,7 @@ class Page extends import_channelOwner.ChannelOwner {
133
134
  route._context = this.context();
134
135
  const routeHandlers = this._routes.slice();
135
136
  for (const routeHandler of routeHandlers) {
136
- if (this._closeWasCalled || this._browserContext._closeWasCalled)
137
+ if (this._closeWasCalled || this._browserContext._closingStatus !== "none")
137
138
  return;
138
139
  if (!routeHandler.matches(route.request().url()))
139
140
  continue;
@@ -144,7 +145,7 @@ class Page extends import_channelOwner.ChannelOwner {
144
145
  this._routes.splice(index, 1);
145
146
  const handled = await routeHandler.handle(route);
146
147
  if (!this._routes.length)
147
- this._wrapApiCall(() => this._updateInterceptionPatterns(), true).catch(() => {
148
+ this._updateInterceptionPatterns({ internal: true }).catch(() => {
148
149
  });
149
150
  if (handled)
150
151
  return;
@@ -207,17 +208,9 @@ class Page extends import_channelOwner.ChannelOwner {
207
208
  }
208
209
  setDefaultNavigationTimeout(timeout) {
209
210
  this._timeoutSettings.setDefaultNavigationTimeout(timeout);
210
- this._wrapApiCall(async () => {
211
- await this._channel.setDefaultNavigationTimeoutNoReply({ timeout });
212
- }, true).catch(() => {
213
- });
214
211
  }
215
212
  setDefaultTimeout(timeout) {
216
213
  this._timeoutSettings.setDefaultTimeout(timeout);
217
- this._wrapApiCall(async () => {
218
- await this._channel.setDefaultTimeoutNoReply({ timeout });
219
- }, true).catch(() => {
220
- });
221
214
  }
222
215
  _forceVideo() {
223
216
  if (!this._video)
@@ -288,7 +281,7 @@ class Page extends import_channelOwner.ChannelOwner {
288
281
  }
289
282
  async reload(options = {}) {
290
283
  const waitUntil = (0, import_frame.verifyLoadState)("waitUntil", options.waitUntil === void 0 ? "load" : options.waitUntil);
291
- return import_network.Response.fromNullable((await this._channel.reload({ ...options, waitUntil })).response);
284
+ return import_network.Response.fromNullable((await this._channel.reload({ ...options, waitUntil, timeout: this._timeoutSettings.navigationTimeout(options) })).response);
292
285
  }
293
286
  async addLocatorHandler(locator, handler, options = {}) {
294
287
  if (locator._frame !== this._mainFrame)
@@ -311,7 +304,7 @@ class Page extends import_channelOwner.ChannelOwner {
311
304
  } finally {
312
305
  if (remove)
313
306
  this._locatorHandlers.delete(uid);
314
- this._wrapApiCall(() => this._channel.resolveLocatorHandlerNoReply({ uid, remove }), true).catch(() => {
307
+ this._channel.resolveLocatorHandlerNoReply({ uid, remove }).catch(() => {
315
308
  });
316
309
  }
317
310
  }
@@ -378,11 +371,11 @@ class Page extends import_channelOwner.ChannelOwner {
378
371
  }
379
372
  async goBack(options = {}) {
380
373
  const waitUntil = (0, import_frame.verifyLoadState)("waitUntil", options.waitUntil === void 0 ? "load" : options.waitUntil);
381
- return import_network.Response.fromNullable((await this._channel.goBack({ ...options, waitUntil })).response);
374
+ return import_network.Response.fromNullable((await this._channel.goBack({ ...options, waitUntil, timeout: this._timeoutSettings.navigationTimeout(options) })).response);
382
375
  }
383
376
  async goForward(options = {}) {
384
377
  const waitUntil = (0, import_frame.verifyLoadState)("waitUntil", options.waitUntil === void 0 ? "load" : options.waitUntil);
385
- return import_network.Response.fromNullable((await this._channel.goForward({ ...options, waitUntil })).response);
378
+ return import_network.Response.fromNullable((await this._channel.goForward({ ...options, waitUntil, timeout: this._timeoutSettings.navigationTimeout(options) })).response);
386
379
  }
387
380
  async requestGC() {
388
381
  await this._channel.requestGC();
@@ -401,12 +394,15 @@ class Page extends import_channelOwner.ChannelOwner {
401
394
  await this._channel.setViewportSize({ viewportSize });
402
395
  }
403
396
  viewportSize() {
404
- return this._viewportSize;
397
+ return this._viewportSize || null;
405
398
  }
406
399
  async evaluate(pageFunction, arg, isolatedContext = true) {
407
400
  (0, import_jsHandle.assertMaxArguments)(arguments.length, 3);
408
401
  return await this._mainFrame.evaluate(pageFunction, arg, isolatedContext);
409
402
  }
403
+ async _evaluateFunction(functionDeclaration) {
404
+ return this._mainFrame._evaluateFunction(functionDeclaration);
405
+ }
410
406
  async addInitScript(script, arg) {
411
407
  await this.installInjectRoute();
412
408
  const source = await (0, import_clientHelper.evaluationScript)(this._platform, script, arg);
@@ -414,7 +410,7 @@ class Page extends import_channelOwner.ChannelOwner {
414
410
  }
415
411
  async route(url, handler, options = {}) {
416
412
  this._routes.unshift(new import_network.RouteHandler(this._platform, this._browserContext._options.baseURL, url, handler, options.times));
417
- await this._updateInterceptionPatterns();
413
+ await this._updateInterceptionPatterns({ title: "Route requests" });
418
414
  }
419
415
  async routeFromHAR(har, options = {}) {
420
416
  const localUtils = this._connection.localUtils();
@@ -430,7 +426,7 @@ class Page extends import_channelOwner.ChannelOwner {
430
426
  }
431
427
  async routeWebSocket(url, handler) {
432
428
  this._webSocketRoutes.unshift(new import_network.WebSocketRouteHandler(this._browserContext._options.baseURL, url, handler));
433
- await this._updateWebSocketInterceptionPatterns();
429
+ await this._updateWebSocketInterceptionPatterns({ title: "Route WebSockets" });
434
430
  }
435
431
  _disposeHarRouters() {
436
432
  this._harRouters.forEach((router) => router.dispose());
@@ -453,23 +449,23 @@ class Page extends import_channelOwner.ChannelOwner {
453
449
  }
454
450
  async _unrouteInternal(removed, remaining, behavior) {
455
451
  this._routes = remaining;
456
- await this._updateInterceptionPatterns();
457
- if (!behavior || behavior === "default")
458
- return;
459
- const promises = removed.map((routeHandler) => routeHandler.stop(behavior));
460
- await Promise.all(promises);
452
+ if (behavior && behavior !== "default") {
453
+ const promises = removed.map((routeHandler) => routeHandler.stop(behavior));
454
+ await Promise.all(promises);
455
+ }
456
+ await this._updateInterceptionPatterns({ title: "Unroute requests" });
461
457
  }
462
- async _updateInterceptionPatterns() {
458
+ async _updateInterceptionPatterns(options) {
463
459
  const patterns = import_network.RouteHandler.prepareInterceptionPatterns(this._routes);
464
- await this._channel.setNetworkInterceptionPatterns({ patterns });
460
+ await this._wrapApiCall(() => this._channel.setNetworkInterceptionPatterns({ patterns }), options);
465
461
  }
466
- async _updateWebSocketInterceptionPatterns() {
462
+ async _updateWebSocketInterceptionPatterns(options) {
467
463
  const patterns = import_network.WebSocketRouteHandler.prepareInterceptionPatterns(this._webSocketRoutes);
468
- await this._channel.setWebSocketInterceptionPatterns({ patterns });
464
+ await this._wrapApiCall(() => this._channel.setWebSocketInterceptionPatterns({ patterns }), options);
469
465
  }
470
466
  async screenshot(options = {}) {
471
467
  const mask = options.mask;
472
- const copy = { ...options, mask: void 0 };
468
+ const copy = { ...options, mask: void 0, timeout: this._timeoutSettings.timeout(options) };
473
469
  if (!copy.type)
474
470
  copy.type = (0, import_elementHandle.determineScreenshotType)(options);
475
471
  if (mask) {
@@ -534,7 +530,7 @@ class Page extends import_channelOwner.ChannelOwner {
534
530
  return await this._mainFrame.dragAndDrop(source, target, options);
535
531
  }
536
532
  async dblclick(selector, options) {
537
- return await this._mainFrame.dblclick(selector, options);
533
+ await this._mainFrame.dblclick(selector, options);
538
534
  }
539
535
  async tap(selector, options) {
540
536
  return await this._mainFrame.tap(selector, options);
@@ -671,18 +667,22 @@ class Page extends import_channelOwner.ChannelOwner {
671
667
  }
672
668
  return result.pdf;
673
669
  }
670
+ async _snapshotForAI(options = {}) {
671
+ const result = await this._channel.snapshotForAI({ timeout: this._timeoutSettings.timeout(options) });
672
+ return result.snapshot;
673
+ }
674
674
  async installInjectRoute() {
675
675
  if (this.routeInjecting || this.context().routeInjecting) return;
676
676
  await this.route("**/*", async (route) => {
677
677
  try {
678
678
  if (route.request().resourceType() === "document" && route.request().url().startsWith("http")) {
679
679
  const protocol = route.request().url().split(":")[0];
680
- await route.continue({ url: protocol + "://patchright-init-script-inject.internal/" });
680
+ await route.fallback({ url: protocol + "://patchright-init-script-inject.internal/" });
681
681
  } else {
682
- await route.continue();
682
+ await route.fallback();
683
683
  }
684
684
  } catch (error) {
685
- await route.continue();
685
+ await route.fallback();
686
686
  }
687
687
  });
688
688
  }
@@ -40,26 +40,16 @@ class Playwright extends import_channelOwner.ChannelOwner {
40
40
  this.webkit = import_browserType.BrowserType.from(initializer.webkit);
41
41
  this.webkit._playwright = this;
42
42
  this._android = import_android.Android.from(initializer.android);
43
+ this._android._playwright = this;
43
44
  this._electron = import_electron.Electron.from(initializer.electron);
44
- this._bidiChromium = import_browserType.BrowserType.from(initializer.bidiChromium);
45
+ this._electron._playwright = this;
46
+ this._bidiChromium = import_browserType.BrowserType.from(initializer._bidiChromium);
45
47
  this._bidiChromium._playwright = this;
46
- this._bidiFirefox = import_browserType.BrowserType.from(initializer.bidiFirefox);
48
+ this._bidiFirefox = import_browserType.BrowserType.from(initializer._bidiFirefox);
47
49
  this._bidiFirefox._playwright = this;
48
50
  this.devices = this._connection.localUtils()?.devices ?? {};
49
- this.selectors = new import_selectors.Selectors();
51
+ this.selectors = new import_selectors.Selectors(this._connection._platform);
50
52
  this.errors = { TimeoutError: import_errors.TimeoutError };
51
- const selectorsOwner = import_selectors.SelectorsOwner.from(initializer.selectors);
52
- this.selectors._addChannel(selectorsOwner);
53
- this._connection.on("close", () => {
54
- this.selectors._removeChannel(selectorsOwner);
55
- });
56
- global._playwrightInstance = this;
57
- }
58
- _setSelectors(selectors) {
59
- const selectorsOwner = import_selectors.SelectorsOwner.from(this._initializer.selectors);
60
- this.selectors._removeChannel(selectorsOwner);
61
- this.selectors = selectors;
62
- this.selectors._addChannel(selectorsOwner);
63
53
  }
64
54
  static from(channel) {
65
55
  return channel._object;
@@ -69,7 +59,7 @@ class Playwright extends import_channelOwner.ChannelOwner {
69
59
  }
70
60
  _preLaunchedBrowser() {
71
61
  const browser = import_browser.Browser.from(this._initializer.preLaunchedBrowser);
72
- browser._browserType = this[browser._name];
62
+ browser._connectToBrowserType(this[browser._name], {}, void 0);
73
63
  return browser;
74
64
  }
75
65
  _allContexts() {
@@ -18,58 +18,38 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var selectors_exports = {};
20
20
  __export(selectors_exports, {
21
- Selectors: () => Selectors,
22
- SelectorsOwner: () => SelectorsOwner,
23
- setPlatformForSelectors: () => setPlatformForSelectors
21
+ Selectors: () => Selectors
24
22
  });
25
23
  module.exports = __toCommonJS(selectors_exports);
26
- var import_channelOwner = require("./channelOwner");
27
24
  var import_clientHelper = require("./clientHelper");
28
25
  var import_locator = require("./locator");
29
- var import_platform = require("./platform");
30
- let platform = import_platform.emptyPlatform;
31
- function setPlatformForSelectors(p) {
32
- platform = p;
33
- }
34
26
  class Selectors {
35
- constructor() {
36
- this._channels = /* @__PURE__ */ new Set();
37
- this._registrations = [];
27
+ constructor(platform) {
28
+ this._selectorEngines = [];
29
+ this._contextsForSelectors = /* @__PURE__ */ new Set();
30
+ this._platform = platform;
38
31
  }
39
32
  async register(name, script, options = {}) {
40
- const source = await (0, import_clientHelper.evaluationScript)(platform, script, void 0, false);
41
- const params = { ...options, name, source };
42
- for (const channel of this._channels)
43
- await channel._channel.register(params);
44
- this._registrations.push(params);
33
+ if (this._selectorEngines.some((engine) => engine.name === name))
34
+ throw new Error(`selectors.register: "${name}" selector engine has been already registered`);
35
+ const source = await (0, import_clientHelper.evaluationScript)(this._platform, script, void 0, false);
36
+ const selectorEngine = { ...options, name, source };
37
+ for (const context of this._contextsForSelectors)
38
+ await context._channel.registerSelectorEngine({ selectorEngine });
39
+ this._selectorEngines.push(selectorEngine);
45
40
  }
46
41
  setTestIdAttribute(attributeName) {
42
+ this._testIdAttributeName = attributeName;
47
43
  (0, import_locator.setTestIdAttribute)(attributeName);
48
- for (const channel of this._channels)
49
- channel._channel.setTestIdAttributeName({ testIdAttributeName: attributeName }).catch(() => {
50
- });
51
- }
52
- _addChannel(channel) {
53
- this._channels.add(channel);
54
- for (const params of this._registrations) {
55
- channel._channel.register(params).catch(() => {
44
+ for (const context of this._contextsForSelectors)
45
+ context._channel.setTestIdAttributeName({ testIdAttributeName: attributeName }).catch(() => {
56
46
  });
57
- channel._channel.setTestIdAttributeName({ testIdAttributeName: (0, import_locator.testIdAttributeName)() }).catch(() => {
58
- });
59
- }
60
- }
61
- _removeChannel(channel) {
62
- this._channels.delete(channel);
63
47
  }
64
- }
65
- class SelectorsOwner extends import_channelOwner.ChannelOwner {
66
- static from(browser) {
67
- return browser._object;
48
+ _withSelectorOptions(options) {
49
+ return { ...options, selectorEngines: this._selectorEngines, testIdAttributeName: this._testIdAttributeName };
68
50
  }
69
51
  }
70
52
  // Annotate the CommonJS export names for ESM import in node:
71
53
  0 && (module.exports = {
72
- Selectors,
73
- SelectorsOwner,
74
- setPlatformForSelectors
54
+ Selectors
75
55
  });
@@ -18,13 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var timeoutSettings_exports = {};
20
20
  __export(timeoutSettings_exports, {
21
- DEFAULT_LAUNCH_TIMEOUT: () => DEFAULT_LAUNCH_TIMEOUT,
22
- DEFAULT_TIMEOUT: () => DEFAULT_TIMEOUT,
23
21
  TimeoutSettings: () => TimeoutSettings
24
22
  });
25
23
  module.exports = __toCommonJS(timeoutSettings_exports);
26
- const DEFAULT_TIMEOUT = 3e4;
27
- const DEFAULT_LAUNCH_TIMEOUT = 3 * 60 * 1e3;
24
+ var import_time = require("../utils/isomorphic/time");
28
25
  class TimeoutSettings {
29
26
  constructor(platform, parent) {
30
27
  this._parent = parent;
@@ -53,7 +50,7 @@ class TimeoutSettings {
53
50
  return this._defaultTimeout;
54
51
  if (this._parent)
55
52
  return this._parent.navigationTimeout(options);
56
- return DEFAULT_TIMEOUT;
53
+ return import_time.DEFAULT_PLAYWRIGHT_TIMEOUT;
57
54
  }
58
55
  timeout(options) {
59
56
  if (typeof options.timeout === "number")
@@ -64,12 +61,19 @@ class TimeoutSettings {
64
61
  return this._defaultTimeout;
65
62
  if (this._parent)
66
63
  return this._parent.timeout(options);
67
- return DEFAULT_TIMEOUT;
64
+ return import_time.DEFAULT_PLAYWRIGHT_TIMEOUT;
65
+ }
66
+ launchTimeout(options) {
67
+ if (typeof options.timeout === "number")
68
+ return options.timeout;
69
+ if (this._platform.isDebugMode())
70
+ return 0;
71
+ if (this._parent)
72
+ return this._parent.launchTimeout(options);
73
+ return import_time.DEFAULT_PLAYWRIGHT_LAUNCH_TIMEOUT;
68
74
  }
69
75
  }
70
76
  // Annotate the CommonJS export names for ESM import in node:
71
77
  0 && (module.exports = {
72
- DEFAULT_LAUNCH_TIMEOUT,
73
- DEFAULT_TIMEOUT,
74
78
  TimeoutSettings
75
79
  });
@@ -28,35 +28,35 @@ class Tracing extends import_channelOwner.ChannelOwner {
28
28
  super(parent, type, guid, initializer);
29
29
  this._includeSources = false;
30
30
  this._isTracing = false;
31
- this.markAsInternalType();
32
31
  }
33
32
  static from(channel) {
34
33
  return channel._object;
35
34
  }
36
35
  async start(options = {}) {
37
- this._includeSources = !!options.sources;
38
- await this._channel.tracingStart({
39
- name: options.name,
40
- snapshots: options.snapshots,
41
- screenshots: options.screenshots,
42
- live: options._live
36
+ await this._parent.installInjectRoute();
37
+ await this._wrapApiCall(async () => {
38
+ this._includeSources = !!options.sources;
39
+ await this._channel.tracingStart({
40
+ name: options.name,
41
+ snapshots: options.snapshots,
42
+ screenshots: options.screenshots,
43
+ live: options._live
44
+ });
45
+ const { traceName } = await this._channel.tracingStartChunk({ name: options.name, title: options.title });
46
+ await this._startCollectingStacks(traceName);
43
47
  });
44
- const { traceName } = await this._channel.tracingStartChunk({ name: options.name, title: options.title });
45
- await this._startCollectingStacks(traceName);
46
48
  }
47
49
  async startChunk(options = {}) {
48
- const { traceName } = await this._channel.tracingStartChunk(options);
49
- await this._startCollectingStacks(traceName);
50
+ await this._wrapApiCall(async () => {
51
+ const { traceName } = await this._channel.tracingStartChunk(options);
52
+ await this._startCollectingStacks(traceName);
53
+ });
50
54
  }
51
55
  async group(name, options = {}) {
52
- await this._wrapApiCall(async () => {
53
- await this._channel.tracingGroup({ name, location: options.location });
54
- }, false);
56
+ await this._channel.tracingGroup({ name, location: options.location });
55
57
  }
56
58
  async groupEnd() {
57
- await this._wrapApiCall(async () => {
58
- await this._channel.tracingGroupEnd();
59
- }, false);
59
+ await this._channel.tracingGroupEnd();
60
60
  }
61
61
  async _startCollectingStacks(traceName) {
62
62
  if (!this._isTracing) {
@@ -67,11 +67,15 @@ class Tracing extends import_channelOwner.ChannelOwner {
67
67
  this._stacksId = result?.stacksId;
68
68
  }
69
69
  async stopChunk(options = {}) {
70
- await this._doStopChunk(options.path);
70
+ await this._wrapApiCall(async () => {
71
+ await this._doStopChunk(options.path);
72
+ });
71
73
  }
72
74
  async stop(options = {}) {
73
- await this._doStopChunk(options.path);
74
- await this._channel.tracingStop();
75
+ await this._wrapApiCall(async () => {
76
+ await this._doStopChunk(options.path);
77
+ await this._channel.tracingStop();
78
+ });
75
79
  }
76
80
  async _doStopChunk(filePath) {
77
81
  this._resetStackCounter();
@@ -35,7 +35,7 @@ class Waiter {
35
35
  this._dispose = [
36
36
  () => this._channelOwner._wrapApiCall(async () => {
37
37
  await this._channelOwner._channel.waitForEventInfo({ info: { waitId: this._waitId, phase: "after", error: this._error } });
38
- }, true).catch(() => {
38
+ }, { internal: true }).catch(() => {
39
39
  })
40
40
  ];
41
41
  }
@@ -88,7 +88,7 @@ class Waiter {
88
88
  this._logs.push(s);
89
89
  this._channelOwner._wrapApiCall(async () => {
90
90
  await this._channelOwner._channel.waitForEventInfo({ info: { waitId: this._waitId, phase: "log", message: s } });
91
- }, true).catch(() => {
91
+ }, { internal: true }).catch(() => {
92
92
  });
93
93
  }
94
94
  _rejectOn(promise, dispose) {
@@ -51,24 +51,12 @@ class JsonPipeTransport {
51
51
  this._owner = owner;
52
52
  }
53
53
  async connect(params) {
54
- const { pipe, headers: connectHeaders } = await this._owner._wrapApiCall(
55
- async () => {
56
- return await this._owner._channel.connect(params);
57
- },
58
- /* isInternal */
59
- true
60
- );
54
+ const { pipe, headers: connectHeaders } = await this._owner._channel.connect(params);
61
55
  this._pipe = pipe;
62
56
  return connectHeaders;
63
57
  }
64
58
  async send(message) {
65
- await this._owner._wrapApiCall(
66
- async () => {
67
- await this._pipe.send({ message });
68
- },
69
- /* isInternal */
70
- true
71
- );
59
+ await this._pipe.send({ message });
72
60
  }
73
61
  onMessage(callback) {
74
62
  this._pipe.on("message", ({ message }) => callback(message));
@@ -77,14 +65,8 @@ class JsonPipeTransport {
77
65
  this._pipe.on("closed", ({ reason }) => callback(reason));
78
66
  }
79
67
  async close() {
80
- await this._owner._wrapApiCall(
81
- async () => {
82
- await this._pipe.close().catch(() => {
83
- });
84
- },
85
- /* isInternal */
86
- true
87
- );
68
+ await this._pipe.close().catch(() => {
69
+ });
88
70
  }
89
71
  }
90
72
  class WebSocketTransport {
@@ -0,0 +1,28 @@
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 bindingsControllerSource_exports = {};
20
+ __export(bindingsControllerSource_exports, {
21
+ source: () => source
22
+ });
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 // eslint-disable-next-line no-restricted-globals\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
+ // Annotate the CommonJS export names for ESM import in node:
26
+ 0 && (module.exports = {
27
+ source
28
+ });