patchright-core 1.52.5 → 1.55.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +54 -32
  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 +30 -26
  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 +421 -345
  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 +43 -31
  72. package/lib/server/chromium/crPage.js +98 -72
  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 +98 -101
  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 +63 -20
  123. package/lib/server/frames.js +495 -555
  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 +8 -16
  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 +232 -177
  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 +128 -17
  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
@@ -39,16 +39,18 @@ var import_cdpSessionDispatcher = require("./cdpSessionDispatcher");
39
39
  var import_dialogDispatcher = require("./dialogDispatcher");
40
40
  var import_dispatcher = require("./dispatcher");
41
41
  var import_elementHandlerDispatcher = require("./elementHandlerDispatcher");
42
+ var import_frameDispatcher = require("./frameDispatcher");
43
+ var import_jsHandleDispatcher = require("./jsHandleDispatcher");
42
44
  var import_networkDispatchers = require("./networkDispatchers");
43
45
  var import_pageDispatcher = require("./pageDispatcher");
44
46
  var import_crBrowser = require("../chromium/crBrowser");
45
47
  var import_errors = require("../errors");
46
- var import_recorder = require("../recorder");
47
48
  var import_tracingDispatcher = require("./tracingDispatcher");
48
49
  var import_webSocketRouteDispatcher = require("./webSocketRouteDispatcher");
49
50
  var import_writableStreamDispatcher = require("./writableStreamDispatcher");
50
51
  var import_crypto = require("../utils/crypto");
51
52
  var import_urlMatch = require("../../utils/isomorphic/urlMatch");
53
+ var import_recorder = require("../recorder");
52
54
  var import_recorderApp = require("../recorder/recorderApp");
53
55
  class BrowserContextDispatcher extends import_dispatcher.Dispatcher {
54
56
  constructor(parentScope, context) {
@@ -56,16 +58,30 @@ class BrowserContextDispatcher extends import_dispatcher.Dispatcher {
56
58
  const tracing = import_tracingDispatcher.TracingDispatcher.from(parentScope, context.tracing);
57
59
  super(parentScope, context, "BrowserContext", {
58
60
  isChromium: context._browser.options.isChromium,
59
- isLocalBrowserOnServer: context._browser._isCollocatedWithServer,
60
61
  requestContext,
61
- tracing
62
+ tracing,
63
+ options: context._options
62
64
  });
63
65
  this._type_EventTarget = true;
64
66
  this._type_BrowserContext = true;
65
67
  this._subscriptions = /* @__PURE__ */ new Set();
66
68
  this._webSocketInterceptionPatterns = [];
69
+ this._bindings = [];
70
+ this._initScripts = [];
71
+ this._clockPaused = false;
72
+ this._interceptionUrlMatchers = [];
67
73
  this.adopt(requestContext);
68
74
  this.adopt(tracing);
75
+ this._requestInterceptor = (route, request) => {
76
+ const matchesSome = this._interceptionUrlMatchers.some((urlMatch) => (0, import_urlMatch.urlMatches)(this._context._options.baseURL, request.url(), urlMatch));
77
+ const routeDispatcher = this.connection.existingDispatcher(route);
78
+ if (!matchesSome || routeDispatcher) {
79
+ route.continue({ isFallback: true }).catch(() => {
80
+ });
81
+ return;
82
+ }
83
+ this._dispatchEvent("route", { route: new import_networkDispatchers.RouteDispatcher(import_networkDispatchers.RequestDispatcher.from(this, request), route) });
84
+ };
69
85
  this._context = context;
70
86
  const onVideo = (artifact) => {
71
87
  const artifactDispatcher = import_artifactDispatcher.ArtifactDispatcher.from(parentScope, artifact);
@@ -96,18 +112,23 @@ class BrowserContextDispatcher extends import_dispatcher.Dispatcher {
96
112
  page: pageDispatcher,
97
113
  type: message.type(),
98
114
  text: message.text(),
99
- args: message.args().map((a) => import_elementHandlerDispatcher.ElementHandleDispatcher.fromJSHandle(pageDispatcher, a)),
115
+ args: message.args().map((a) => {
116
+ const elementHandle = a.asElement();
117
+ if (elementHandle)
118
+ return import_elementHandlerDispatcher.ElementHandleDispatcher.from(import_frameDispatcher.FrameDispatcher.from(this, elementHandle._frame), elementHandle);
119
+ return import_jsHandleDispatcher.JSHandleDispatcher.fromJSHandle(pageDispatcher, a);
120
+ }),
100
121
  location: message.location()
101
122
  });
102
123
  }
103
124
  });
104
- this.addObjectListener(import_browserContext.BrowserContext.Events.Dialog, (dialog) => {
105
- if (this._shouldDispatchEvent(dialog.page(), "dialog"))
106
- this._dispatchEvent("dialog", { dialog: new import_dialogDispatcher.DialogDispatcher(this, dialog) });
107
- else
108
- dialog.close().catch(() => {
109
- });
110
- });
125
+ this._dialogHandler = (dialog) => {
126
+ if (!this._shouldDispatchEvent(dialog.page(), "dialog"))
127
+ return false;
128
+ this._dispatchEvent("dialog", { dialog: new import_dialogDispatcher.DialogDispatcher(this, dialog) });
129
+ return true;
130
+ };
131
+ context.dialogManager.addDialogHandler(this._dialogHandler);
111
132
  if (context._browser.options.name === "chromium") {
112
133
  for (const page of context.backgroundPages())
113
134
  this._dispatchEvent("backgroundPage", { page: import_pageDispatcher.PageDispatcher.from(this, page) });
@@ -117,7 +138,7 @@ class BrowserContextDispatcher extends import_dispatcher.Dispatcher {
117
138
  this.addObjectListener(import_crBrowser.CRBrowserContext.CREvents.ServiceWorker, (serviceWorker) => this._dispatchEvent("serviceWorker", { worker: new import_pageDispatcher.WorkerDispatcher(this, serviceWorker) }));
118
139
  }
119
140
  this.addObjectListener(import_browserContext.BrowserContext.Events.Request, (request) => {
120
- const redirectFromDispatcher = request.redirectedFrom() && (0, import_dispatcher.existingDispatcher)(request.redirectedFrom());
141
+ const redirectFromDispatcher = request.redirectedFrom() && this.connection.existingDispatcher(request.redirectedFrom());
121
142
  if (!redirectFromDispatcher && !this._shouldDispatchNetworkEvent(request, "request") && !request.isNavigationRequest())
122
143
  return;
123
144
  const requestDispatcher = import_networkDispatchers.RequestDispatcher.from(this, request);
@@ -127,7 +148,7 @@ class BrowserContextDispatcher extends import_dispatcher.Dispatcher {
127
148
  });
128
149
  });
129
150
  this.addObjectListener(import_browserContext.BrowserContext.Events.Response, (response) => {
130
- const requestDispatcher = (0, import_dispatcher.existingDispatcher)(response.request());
151
+ const requestDispatcher = this.connection.existingDispatcher(response.request());
131
152
  if (!requestDispatcher && !this._shouldDispatchNetworkEvent(response.request(), "response"))
132
153
  return;
133
154
  this._dispatchEvent("response", {
@@ -136,7 +157,7 @@ class BrowserContextDispatcher extends import_dispatcher.Dispatcher {
136
157
  });
137
158
  });
138
159
  this.addObjectListener(import_browserContext.BrowserContext.Events.RequestFailed, (request) => {
139
- const requestDispatcher = (0, import_dispatcher.existingDispatcher)(request);
160
+ const requestDispatcher = this.connection.existingDispatcher(request);
140
161
  if (!requestDispatcher && !this._shouldDispatchNetworkEvent(request, "requestFailed"))
141
162
  return;
142
163
  this._dispatchEvent("requestFailed", {
@@ -147,7 +168,7 @@ class BrowserContextDispatcher extends import_dispatcher.Dispatcher {
147
168
  });
148
169
  });
149
170
  this.addObjectListener(import_browserContext.BrowserContext.Events.RequestFinished, ({ request, response }) => {
150
- const requestDispatcher = (0, import_dispatcher.existingDispatcher)(request);
171
+ const requestDispatcher = this.connection.existingDispatcher(request);
151
172
  if (!requestDispatcher && !this._shouldDispatchNetworkEvent(request, "requestFinished"))
152
173
  return;
153
174
  this._dispatchEvent("requestFinished", {
@@ -157,6 +178,13 @@ class BrowserContextDispatcher extends import_dispatcher.Dispatcher {
157
178
  page: import_pageDispatcher.PageDispatcher.fromNullable(this, request.frame()?._page.initializedOrUndefined())
158
179
  });
159
180
  });
181
+ this.addObjectListener(import_browserContext.BrowserContext.Events.RecorderEvent, ({ event, data, page, code }) => {
182
+ this._dispatchEvent("recorderEvent", { event, data, code, page: import_pageDispatcher.PageDispatcher.from(this, page) });
183
+ });
184
+ }
185
+ static from(parentScope, context) {
186
+ const result = parentScope.connection.existingDispatcher(context);
187
+ return result || new BrowserContextDispatcher(parentScope, context);
160
188
  }
161
189
  _shouldDispatchNetworkEvent(request, event) {
162
190
  return this._shouldDispatchEvent(request.frame()?._page?.initializedOrUndefined(), event);
@@ -164,52 +192,47 @@ class BrowserContextDispatcher extends import_dispatcher.Dispatcher {
164
192
  _shouldDispatchEvent(page, event) {
165
193
  if (this._subscriptions.has(event))
166
194
  return true;
167
- const pageDispatcher = page ? (0, import_dispatcher.existingDispatcher)(page) : void 0;
195
+ const pageDispatcher = page ? this.connection.existingDispatcher(page) : void 0;
168
196
  if (pageDispatcher?._subscriptions.has(event))
169
197
  return true;
170
198
  return false;
171
199
  }
172
- async createTempFiles(params) {
200
+ async createTempFiles(params, progress) {
173
201
  const dir = this._context._browser.options.artifactsDir;
174
202
  const tmpDir = import_path.default.join(dir, "upload-" + (0, import_crypto.createGuid)());
175
203
  const tempDirWithRootName = params.rootDirName ? import_path.default.join(tmpDir, import_path.default.basename(params.rootDirName)) : tmpDir;
176
- await import_fs.default.promises.mkdir(tempDirWithRootName, { recursive: true });
204
+ await progress.race(import_fs.default.promises.mkdir(tempDirWithRootName, { recursive: true }));
177
205
  this._context._tempDirs.push(tmpDir);
178
206
  return {
179
207
  rootDir: params.rootDirName ? new import_writableStreamDispatcher.WritableStreamDispatcher(this, tempDirWithRootName) : void 0,
180
208
  writableStreams: await Promise.all(params.items.map(async (item) => {
181
- await import_fs.default.promises.mkdir(import_path.default.dirname(import_path.default.join(tempDirWithRootName, item.name)), { recursive: true });
209
+ await progress.race(import_fs.default.promises.mkdir(import_path.default.dirname(import_path.default.join(tempDirWithRootName, item.name)), { recursive: true }));
182
210
  const file = import_fs.default.createWriteStream(import_path.default.join(tempDirWithRootName, item.name));
183
211
  return new import_writableStreamDispatcher.WritableStreamDispatcher(this, file, item.lastModifiedMs);
184
212
  }))
185
213
  };
186
214
  }
187
- async setDefaultNavigationTimeoutNoReply(params) {
188
- this._context.setDefaultNavigationTimeout(params.timeout);
189
- }
190
- async setDefaultTimeoutNoReply(params) {
191
- this._context.setDefaultTimeout(params.timeout);
192
- }
193
- async exposeBinding(params) {
194
- await this._context.exposeBinding(params.name, !!params.needsHandle, (source, ...args) => {
215
+ async exposeBinding(params, progress) {
216
+ const binding = await this._context.exposeBinding(progress, params.name, !!params.needsHandle, (source, ...args) => {
195
217
  if (this._disposed)
196
218
  return;
197
219
  const pageDispatcher = import_pageDispatcher.PageDispatcher.from(this, source.page);
198
- const binding = new import_pageDispatcher.BindingCallDispatcher(pageDispatcher, params.name, !!params.needsHandle, source, args);
199
- this._dispatchEvent("bindingCall", { binding });
200
- return binding.promise();
220
+ const binding2 = new import_pageDispatcher.BindingCallDispatcher(pageDispatcher, params.name, !!params.needsHandle, source, args);
221
+ this._dispatchEvent("bindingCall", { binding: binding2 });
222
+ return binding2.promise();
201
223
  });
224
+ this._bindings.push(binding);
202
225
  }
203
- async newPage(params, metadata) {
204
- return { page: import_pageDispatcher.PageDispatcher.from(this, await this._context.newPage(metadata)) };
226
+ async newPage(params, progress) {
227
+ return { page: import_pageDispatcher.PageDispatcher.from(this, await this._context.newPage(progress)) };
205
228
  }
206
- async cookies(params) {
207
- return { cookies: await this._context.cookies(params.urls) };
229
+ async cookies(params, progress) {
230
+ return { cookies: await progress.race(this._context.cookies(params.urls)) };
208
231
  }
209
- async addCookies(params) {
232
+ async addCookies(params, progress) {
210
233
  await this._context.addCookies(params.cookies);
211
234
  }
212
- async clearCookies(params) {
235
+ async clearCookies(params, progress) {
213
236
  const nameRe = params.nameRegexSource !== void 0 && params.nameRegexFlags !== void 0 ? new RegExp(params.nameRegexSource, params.nameRegexFlags) : void 0;
214
237
  const domainRe = params.domainRegexSource !== void 0 && params.domainRegexFlags !== void 0 ? new RegExp(params.domainRegexSource, params.domainRegexFlags) : void 0;
215
238
  const pathRe = params.pathRegexSource !== void 0 && params.pathRegexFlags !== void 0 ? new RegExp(params.pathRegexSource, params.pathRegexFlags) : void 0;
@@ -219,107 +242,134 @@ class BrowserContextDispatcher extends import_dispatcher.Dispatcher {
219
242
  path: pathRe || params.path
220
243
  });
221
244
  }
222
- async grantPermissions(params) {
245
+ async grantPermissions(params, progress) {
223
246
  await this._context.grantPermissions(params.permissions, params.origin);
224
247
  }
225
- async clearPermissions() {
248
+ async clearPermissions(params, progress) {
226
249
  await this._context.clearPermissions();
227
250
  }
228
- async setGeolocation(params) {
251
+ async setGeolocation(params, progress) {
229
252
  await this._context.setGeolocation(params.geolocation);
230
253
  }
231
- async setExtraHTTPHeaders(params) {
232
- await this._context.setExtraHTTPHeaders(params.headers);
254
+ async setExtraHTTPHeaders(params, progress) {
255
+ await this._context.setExtraHTTPHeaders(progress, params.headers);
233
256
  }
234
- async setOffline(params) {
235
- await this._context.setOffline(params.offline);
257
+ async setOffline(params, progress) {
258
+ await this._context.setOffline(progress, params.offline);
236
259
  }
237
- async setHTTPCredentials(params) {
238
- await this._context.setHTTPCredentials(params.httpCredentials);
260
+ async setHTTPCredentials(params, progress) {
261
+ await progress.race(this._context.setHTTPCredentials(params.httpCredentials));
239
262
  }
240
- async addInitScript(params) {
241
- await this._context.addInitScript(params.source);
263
+ async addInitScript(params, progress) {
264
+ this._initScripts.push(await this._context.addInitScript(progress, params.source));
242
265
  }
243
- async setNetworkInterceptionPatterns(params) {
266
+ async setNetworkInterceptionPatterns(params, progress) {
267
+ const hadMatchers = this._interceptionUrlMatchers.length > 0;
244
268
  if (!params.patterns.length) {
245
- await this._context.setRequestInterceptor(void 0);
246
- return;
269
+ if (hadMatchers)
270
+ await this._context.removeRequestInterceptor(this._requestInterceptor);
271
+ this._interceptionUrlMatchers = [];
272
+ } else {
273
+ this._interceptionUrlMatchers = params.patterns.map((pattern) => pattern.regexSource ? new RegExp(pattern.regexSource, pattern.regexFlags) : pattern.glob);
274
+ if (!hadMatchers)
275
+ await this._context.addRequestInterceptor(progress, this._requestInterceptor);
247
276
  }
248
- const urlMatchers = params.patterns.map((pattern) => pattern.regexSource ? new RegExp(pattern.regexSource, pattern.regexFlags) : pattern.glob);
249
- await this._context.setRequestInterceptor((route, request) => {
250
- const matchesSome = urlMatchers.some((urlMatch) => (0, import_urlMatch.urlMatches)(this._context._options.baseURL, request.url(), urlMatch));
251
- if (!matchesSome)
252
- return false;
253
- this._dispatchEvent("route", { route: import_networkDispatchers.RouteDispatcher.from(import_networkDispatchers.RequestDispatcher.from(this, request), route) });
254
- return true;
255
- });
256
277
  }
257
- async setWebSocketInterceptionPatterns(params, metadata) {
278
+ async setWebSocketInterceptionPatterns(params, progress) {
258
279
  this._webSocketInterceptionPatterns = params.patterns;
259
- if (params.patterns.length)
260
- await import_webSocketRouteDispatcher.WebSocketRouteDispatcher.installIfNeeded(this._context);
280
+ if (params.patterns.length && !this._routeWebSocketInitScript)
281
+ this._routeWebSocketInitScript = await import_webSocketRouteDispatcher.WebSocketRouteDispatcher.install(progress, this.connection, this._context);
261
282
  }
262
- async storageState(params, metadata) {
263
- return await this._context.storageState(params.indexedDB);
283
+ async storageState(params, progress) {
284
+ return await progress.race(this._context.storageState(progress, params.indexedDB));
264
285
  }
265
- async close(params, metadata) {
266
- metadata.potentiallyClosesScope = true;
286
+ async close(params, progress) {
287
+ progress.metadata.potentiallyClosesScope = true;
267
288
  await this._context.close(params);
268
289
  }
269
- async enableRecorder(params) {
270
- await import_recorder.Recorder.show(this._context, import_recorderApp.RecorderApp.factory(this._context), params);
290
+ async enableRecorder(params, progress) {
291
+ await import_recorderApp.RecorderApp.show(this._context, params);
292
+ }
293
+ async disableRecorder(params, progress) {
294
+ const recorder = import_recorder.Recorder.existingForContext(this._context);
295
+ if (recorder)
296
+ recorder.setMode("none");
271
297
  }
272
- async pause(params, metadata) {
298
+ async pause(params, progress) {
273
299
  }
274
- async newCDPSession(params) {
300
+ async newCDPSession(params, progress) {
275
301
  if (!this._object._browser.options.isChromium)
276
302
  throw new Error(`CDP session is only available in Chromium`);
277
303
  if (!params.page && !params.frame || params.page && params.frame)
278
304
  throw new Error(`CDP session must be initiated with either Page or Frame, not none or both`);
279
305
  const crBrowserContext = this._object;
280
- return { session: new import_cdpSessionDispatcher.CDPSessionDispatcher(this, await crBrowserContext.newCDPSession((params.page ? params.page : params.frame)._object)) };
306
+ return { session: new import_cdpSessionDispatcher.CDPSessionDispatcher(this, await progress.race(crBrowserContext.newCDPSession((params.page ? params.page : params.frame)._object))) };
281
307
  }
282
- async harStart(params) {
283
- const harId = await this._context._harStart(params.page ? params.page._object : null, params.options);
308
+ async harStart(params, progress) {
309
+ const harId = this._context.harStart(params.page ? params.page._object : null, params.options);
284
310
  return { harId };
285
311
  }
286
- async harExport(params) {
287
- const artifact = await this._context._harExport(params.harId);
312
+ async harExport(params, progress) {
313
+ const artifact = await progress.race(this._context.harExport(params.harId));
288
314
  if (!artifact)
289
315
  throw new Error("No HAR artifact. Ensure record.harPath is set.");
290
316
  return { artifact: import_artifactDispatcher.ArtifactDispatcher.from(this, artifact) };
291
317
  }
292
- async clockFastForward(params, metadata) {
293
- await this._context.clock.fastForward(params.ticksString ?? params.ticksNumber ?? 0);
318
+ async clockFastForward(params, progress) {
319
+ await this._context.clock.fastForward(progress, params.ticksString ?? params.ticksNumber ?? 0);
294
320
  }
295
- async clockInstall(params, metadata) {
296
- await this._context.clock.install(params.timeString ?? params.timeNumber ?? void 0);
321
+ async clockInstall(params, progress) {
322
+ await this._context.clock.install(progress, params.timeString ?? params.timeNumber ?? void 0);
297
323
  }
298
- async clockPauseAt(params, metadata) {
299
- await this._context.clock.pauseAt(params.timeString ?? params.timeNumber ?? 0);
324
+ async clockPauseAt(params, progress) {
325
+ await this._context.clock.pauseAt(progress, params.timeString ?? params.timeNumber ?? 0);
326
+ this._clockPaused = true;
300
327
  }
301
- async clockResume(params, metadata) {
302
- await this._context.clock.resume();
328
+ async clockResume(params, progress) {
329
+ await this._context.clock.resume(progress);
330
+ this._clockPaused = false;
303
331
  }
304
- async clockRunFor(params, metadata) {
305
- await this._context.clock.runFor(params.ticksString ?? params.ticksNumber ?? 0);
332
+ async clockRunFor(params, progress) {
333
+ await this._context.clock.runFor(progress, params.ticksString ?? params.ticksNumber ?? 0);
306
334
  }
307
- async clockSetFixedTime(params, metadata) {
308
- await this._context.clock.setFixedTime(params.timeString ?? params.timeNumber ?? 0);
335
+ async clockSetFixedTime(params, progress) {
336
+ await this._context.clock.setFixedTime(progress, params.timeString ?? params.timeNumber ?? 0);
309
337
  }
310
- async clockSetSystemTime(params, metadata) {
311
- await this._context.clock.setSystemTime(params.timeString ?? params.timeNumber ?? 0);
338
+ async clockSetSystemTime(params, progress) {
339
+ await this._context.clock.setSystemTime(progress, params.timeString ?? params.timeNumber ?? 0);
312
340
  }
313
- async updateSubscription(params) {
341
+ async updateSubscription(params, progress) {
314
342
  if (params.enabled)
315
343
  this._subscriptions.add(params.event);
316
344
  else
317
345
  this._subscriptions.delete(params.event);
318
346
  }
347
+ async registerSelectorEngine(params, progress) {
348
+ this._object.selectors().register(params.selectorEngine);
349
+ }
350
+ async setTestIdAttributeName(params, progress) {
351
+ this._object.selectors().setTestIdAttributeName(params.testIdAttributeName);
352
+ }
319
353
  _onDispose() {
320
- if (!this._context.isClosingOrClosed())
321
- this._context.setRequestInterceptor(void 0).catch(() => {
354
+ if (this._context.isClosingOrClosed())
355
+ return;
356
+ this._context.dialogManager.removeDialogHandler(this._dialogHandler);
357
+ this._interceptionUrlMatchers = [];
358
+ this._context.removeRequestInterceptor(this._requestInterceptor).catch(() => {
359
+ });
360
+ this._context.removeExposedBindings(this._bindings).catch(() => {
361
+ });
362
+ this._bindings = [];
363
+ this._context.removeInitScripts(this._initScripts).catch(() => {
364
+ });
365
+ this._initScripts = [];
366
+ if (this._routeWebSocketInitScript)
367
+ import_webSocketRouteDispatcher.WebSocketRouteDispatcher.uninstall(this.connection, this._context, this._routeWebSocketInitScript).catch(() => {
322
368
  });
369
+ this._routeWebSocketInitScript = void 0;
370
+ if (this._clockPaused)
371
+ this._context.clock.resumeNoReply();
372
+ this._clockPaused = false;
323
373
  }
324
374
  }
325
375
  // Annotate the CommonJS export names for ESM import in node:
@@ -18,134 +18,101 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var browserDispatcher_exports = {};
20
20
  __export(browserDispatcher_exports, {
21
- BrowserDispatcher: () => BrowserDispatcher,
22
- ConnectedBrowserDispatcher: () => ConnectedBrowserDispatcher
21
+ BrowserDispatcher: () => BrowserDispatcher
23
22
  });
24
23
  module.exports = __toCommonJS(browserDispatcher_exports);
25
24
  var import_browser = require("../browser");
26
25
  var import_browserContextDispatcher = require("./browserContextDispatcher");
27
26
  var import_cdpSessionDispatcher = require("./cdpSessionDispatcher");
28
27
  var import_dispatcher = require("./dispatcher");
29
- var import_dispatcher2 = require("./dispatcher");
30
28
  var import_browserContext = require("../browserContext");
31
- var import_selectors = require("../selectors");
32
29
  var import_artifactDispatcher = require("./artifactDispatcher");
33
- class BrowserDispatcher extends import_dispatcher2.Dispatcher {
34
- constructor(scope, browser) {
30
+ class BrowserDispatcher extends import_dispatcher.Dispatcher {
31
+ constructor(scope, browser, options = {}) {
35
32
  super(scope, browser, "Browser", { version: browser.version(), name: browser.options.name });
36
33
  this._type_Browser = true;
37
- this.addObjectListener(import_browser.Browser.Events.Disconnected, () => this._didClose());
34
+ this._isolatedContexts = /* @__PURE__ */ new Set();
35
+ this._options = options;
36
+ if (!options.isolateContexts) {
37
+ this.addObjectListener(import_browser.Browser.Events.Context, (context) => this._dispatchEvent("context", { context: import_browserContextDispatcher.BrowserContextDispatcher.from(this, context) }));
38
+ this.addObjectListener(import_browser.Browser.Events.Disconnected, () => this._didClose());
39
+ if (browser._defaultContext)
40
+ this._dispatchEvent("context", { context: import_browserContextDispatcher.BrowserContextDispatcher.from(this, browser._defaultContext) });
41
+ for (const context of browser.contexts())
42
+ this._dispatchEvent("context", { context: import_browserContextDispatcher.BrowserContextDispatcher.from(this, context) });
43
+ }
38
44
  }
39
45
  _didClose() {
40
46
  this._dispatchEvent("close");
41
47
  this._dispose();
42
48
  }
43
- async newContext(params, metadata) {
44
- const context = await this._object.newContext(metadata, params);
45
- return { context: new import_browserContextDispatcher.BrowserContextDispatcher(this, context) };
46
- }
47
- async newContextForReuse(params, metadata) {
48
- return await newContextForReuse(this._object, this, params, null, metadata);
49
- }
50
- async stopPendingOperations(params, metadata) {
51
- await this._object.stopPendingOperations(params.reason);
52
- }
53
- async close(params, metadata) {
54
- metadata.potentiallyClosesScope = true;
49
+ async newContext(params, progress) {
50
+ if (params.recordVideo && this._object.attribution.playwright.options.isServer)
51
+ params.recordVideo.dir = this._object.options.artifactsDir;
52
+ if (!this._options.isolateContexts) {
53
+ const context2 = await this._object.newContext(progress, params);
54
+ const contextDispatcher2 = import_browserContextDispatcher.BrowserContextDispatcher.from(this, context2);
55
+ return { context: contextDispatcher2 };
56
+ }
57
+ const context = await this._object.newContext(progress, params);
58
+ this._isolatedContexts.add(context);
59
+ context.on(import_browserContext.BrowserContext.Events.Close, () => this._isolatedContexts.delete(context));
60
+ const contextDispatcher = import_browserContextDispatcher.BrowserContextDispatcher.from(this, context);
61
+ this._dispatchEvent("context", { context: contextDispatcher });
62
+ return { context: contextDispatcher };
63
+ }
64
+ async newContextForReuse(params, progress) {
65
+ const context = await this._object.newContextForReuse(progress, params);
66
+ const contextDispatcher = import_browserContextDispatcher.BrowserContextDispatcher.from(this, context);
67
+ this._dispatchEvent("context", { context: contextDispatcher });
68
+ return { context: contextDispatcher };
69
+ }
70
+ async disconnectFromReusedContext(params, progress) {
71
+ const context = this._object.contextForReuse();
72
+ const contextDispatcher = context ? this.connection.existingDispatcher(context) : void 0;
73
+ if (contextDispatcher) {
74
+ await contextDispatcher.stopPendingOperations(new Error(params.reason));
75
+ contextDispatcher._dispose();
76
+ }
77
+ }
78
+ async close(params, progress) {
79
+ if (this._options.ignoreStopAndKill)
80
+ return;
81
+ progress.metadata.potentiallyClosesScope = true;
55
82
  await this._object.close(params);
56
83
  }
57
- async killForTests(_, metadata) {
58
- metadata.potentiallyClosesScope = true;
84
+ async killForTests(params, progress) {
85
+ if (this._options.ignoreStopAndKill)
86
+ return;
87
+ progress.metadata.potentiallyClosesScope = true;
59
88
  await this._object.killForTests();
60
89
  }
61
90
  async defaultUserAgentForTest() {
62
91
  return { userAgent: this._object.userAgent() };
63
92
  }
64
- async newBrowserCDPSession() {
93
+ async newBrowserCDPSession(params, progress) {
65
94
  if (!this._object.options.isChromium)
66
95
  throw new Error(`CDP session is only available in Chromium`);
67
96
  const crBrowser = this._object;
68
97
  return { session: new import_cdpSessionDispatcher.CDPSessionDispatcher(this, await crBrowser.newBrowserCDPSession()) };
69
98
  }
70
- async startTracing(params) {
99
+ async startTracing(params, progress) {
71
100
  if (!this._object.options.isChromium)
72
101
  throw new Error(`Tracing is only available in Chromium`);
73
102
  const crBrowser = this._object;
74
103
  await crBrowser.startTracing(params.page ? params.page._object : void 0, params);
75
104
  }
76
- async stopTracing() {
77
- if (!this._object.options.isChromium)
78
- throw new Error(`Tracing is only available in Chromium`);
79
- const crBrowser = this._object;
80
- return { artifact: import_artifactDispatcher.ArtifactDispatcher.from(this, await crBrowser.stopTracing()) };
81
- }
82
- }
83
- class ConnectedBrowserDispatcher extends import_dispatcher2.Dispatcher {
84
- constructor(scope, browser) {
85
- super(scope, browser, "Browser", { version: browser.version(), name: browser.options.name });
86
- this._type_Browser = true;
87
- this._contexts = /* @__PURE__ */ new Set();
88
- this.selectors = new import_selectors.Selectors();
89
- }
90
- async newContext(params, metadata) {
91
- if (params.recordVideo)
92
- params.recordVideo.dir = this._object.options.artifactsDir;
93
- const context = await this._object.newContext(metadata, params);
94
- this._contexts.add(context);
95
- context.setSelectors(this.selectors);
96
- context.on(import_browserContext.BrowserContext.Events.Close, () => this._contexts.delete(context));
97
- return { context: new import_browserContextDispatcher.BrowserContextDispatcher(this, context) };
98
- }
99
- async newContextForReuse(params, metadata) {
100
- return await newContextForReuse(this._object, this, params, this.selectors, metadata);
101
- }
102
- async stopPendingOperations(params, metadata) {
103
- await this._object.stopPendingOperations(params.reason);
104
- }
105
- async close() {
106
- }
107
- async killForTests() {
108
- }
109
- async defaultUserAgentForTest() {
110
- throw new Error("Client should not send us Browser.defaultUserAgentForTest");
111
- }
112
- async newBrowserCDPSession() {
113
- if (!this._object.options.isChromium)
114
- throw new Error(`CDP session is only available in Chromium`);
115
- const crBrowser = this._object;
116
- return { session: new import_cdpSessionDispatcher.CDPSessionDispatcher(this, await crBrowser.newBrowserCDPSession()) };
117
- }
118
- async startTracing(params) {
119
- if (!this._object.options.isChromium)
120
- throw new Error(`Tracing is only available in Chromium`);
121
- const crBrowser = this._object;
122
- await crBrowser.startTracing(params.page ? params.page._object : void 0, params);
123
- }
124
- async stopTracing() {
105
+ async stopTracing(params, progress) {
125
106
  if (!this._object.options.isChromium)
126
107
  throw new Error(`Tracing is only available in Chromium`);
127
108
  const crBrowser = this._object;
128
109
  return { artifact: import_artifactDispatcher.ArtifactDispatcher.from(this, await crBrowser.stopTracing()) };
129
110
  }
130
111
  async cleanupContexts() {
131
- await Promise.all(Array.from(this._contexts).map((context) => context.close({ reason: "Global context cleanup (connection terminated)" })));
132
- }
133
- }
134
- async function newContextForReuse(browser, scope, params, selectors, metadata) {
135
- const { context, needsReset } = await browser.newContextForReuse(params, metadata);
136
- if (needsReset) {
137
- const oldContextDispatcher = (0, import_dispatcher.existingDispatcher)(context);
138
- if (oldContextDispatcher)
139
- oldContextDispatcher._dispose();
140
- await context.resetForReuse(metadata, params);
112
+ await Promise.all(Array.from(this._isolatedContexts).map((context) => context.close({ reason: "Global context cleanup (connection terminated)" })));
141
113
  }
142
- if (selectors)
143
- context.setSelectors(selectors);
144
- const contextDispatcher = new import_browserContextDispatcher.BrowserContextDispatcher(scope, context);
145
- return { context: contextDispatcher };
146
114
  }
147
115
  // Annotate the CommonJS export names for ESM import in node:
148
116
  0 && (module.exports = {
149
- BrowserDispatcher,
150
- ConnectedBrowserDispatcher
117
+ BrowserDispatcher
151
118
  });
@@ -25,27 +25,36 @@ var import_browserContextDispatcher = require("./browserContextDispatcher");
25
25
  var import_browserDispatcher = require("./browserDispatcher");
26
26
  var import_dispatcher = require("./dispatcher");
27
27
  class BrowserTypeDispatcher extends import_dispatcher.Dispatcher {
28
- constructor(scope, browserType) {
28
+ constructor(scope, browserType, denyLaunch) {
29
29
  super(scope, browserType, "BrowserType", {
30
30
  executablePath: browserType.executablePath(),
31
31
  name: browserType.name()
32
32
  });
33
33
  this._type_BrowserType = true;
34
+ this._denyLaunch = denyLaunch;
34
35
  }
35
- async launch(params, metadata) {
36
- const browser = await this._object.launch(metadata, params);
36
+ async launch(params, progress) {
37
+ if (this._denyLaunch)
38
+ throw new Error(`Launching more browsers is not allowed.`);
39
+ const browser = await this._object.launch(progress, params);
37
40
  return { browser: new import_browserDispatcher.BrowserDispatcher(this, browser) };
38
41
  }
39
- async launchPersistentContext(params, metadata) {
40
- const browserContext = await this._object.launchPersistentContext(metadata, params.userDataDir, params);
41
- return { context: new import_browserContextDispatcher.BrowserContextDispatcher(this, browserContext) };
42
+ async launchPersistentContext(params, progress) {
43
+ if (this._denyLaunch)
44
+ throw new Error(`Launching more browsers is not allowed.`);
45
+ const browserContext = await this._object.launchPersistentContext(progress, params.userDataDir, params);
46
+ const browserDispatcher = new import_browserDispatcher.BrowserDispatcher(this, browserContext._browser);
47
+ const contextDispatcher = import_browserContextDispatcher.BrowserContextDispatcher.from(browserDispatcher, browserContext);
48
+ return { browser: browserDispatcher, context: contextDispatcher };
42
49
  }
43
- async connectOverCDP(params, metadata) {
44
- const browser = await this._object.connectOverCDP(metadata, params.endpointURL, params);
50
+ async connectOverCDP(params, progress) {
51
+ if (this._denyLaunch)
52
+ throw new Error(`Launching more browsers is not allowed.`);
53
+ const browser = await this._object.connectOverCDP(progress, params.endpointURL, params);
45
54
  const browserDispatcher = new import_browserDispatcher.BrowserDispatcher(this, browser);
46
55
  return {
47
56
  browser: browserDispatcher,
48
- defaultContext: browser._defaultContext ? new import_browserContextDispatcher.BrowserContextDispatcher(browserDispatcher, browser._defaultContext) : void 0
57
+ defaultContext: browser._defaultContext ? import_browserContextDispatcher.BrowserContextDispatcher.from(browserDispatcher, browser._defaultContext) : void 0
49
58
  };
50
59
  }
51
60
  }
@@ -30,11 +30,11 @@ class CDPSessionDispatcher extends import_dispatcher.Dispatcher {
30
30
  this.addObjectListener(import_crConnection.CDPSession.Events.Event, ({ method, params }) => this._dispatchEvent("event", { method, params }));
31
31
  this.addObjectListener(import_crConnection.CDPSession.Events.Closed, () => this._dispose());
32
32
  }
33
- async send(params) {
34
- return { result: await this._object.send(params.method, params.params) };
33
+ async send(params, progress) {
34
+ return { result: await progress.race(this._object.send(params.method, params.params)) };
35
35
  }
36
- async detach(_, metadata) {
37
- metadata.potentiallyClosesScope = true;
36
+ async detach(_, progress) {
37
+ progress.metadata.potentiallyClosesScope = true;
38
38
  await this._object.detach();
39
39
  }
40
40
  }