patchright-core 1.58.2 → 1.59.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/ThirdPartyNotices.txt +126 -650
  2. package/browsers.json +16 -14
  3. package/lib/bootstrap.js +77 -0
  4. package/lib/cli/browserActions.js +308 -0
  5. package/lib/cli/driver.js +3 -2
  6. package/lib/cli/installActions.js +171 -0
  7. package/lib/cli/program.js +47 -411
  8. package/lib/client/android.js +4 -4
  9. package/lib/client/api.js +3 -3
  10. package/lib/client/browser.js +8 -0
  11. package/lib/client/browserContext.js +22 -61
  12. package/lib/client/browserType.js +19 -51
  13. package/lib/client/cdpSession.js +6 -2
  14. package/lib/client/channelOwner.js +1 -1
  15. package/lib/client/clientHelper.js +2 -1
  16. package/lib/client/clock.js +0 -1
  17. package/lib/client/{webSocket.js → connect.js} +57 -7
  18. package/lib/client/connection.js +8 -4
  19. package/lib/client/consoleMessage.js +3 -0
  20. package/lib/client/debugger.js +57 -0
  21. package/lib/client/dialog.js +8 -1
  22. package/lib/client/disposable.js +76 -0
  23. package/lib/client/electron.js +1 -0
  24. package/lib/client/elementHandle.js +1 -4
  25. package/lib/client/events.js +3 -3
  26. package/lib/client/fetch.js +0 -1
  27. package/lib/client/frame.js +10 -23
  28. package/lib/client/harRouter.js +13 -1
  29. package/lib/client/jsHandle.js +4 -8
  30. package/lib/client/locator.js +13 -44
  31. package/lib/client/network.js +15 -16
  32. package/lib/client/page.js +41 -75
  33. package/lib/client/platform.js +0 -3
  34. package/lib/client/screencast.js +88 -0
  35. package/lib/client/selectors.js +3 -1
  36. package/lib/client/tracing.js +11 -5
  37. package/lib/client/video.js +13 -20
  38. package/lib/client/worker.js +6 -6
  39. package/lib/generated/bindingsControllerSource.js +1 -1
  40. package/lib/generated/clockSource.js +1 -1
  41. package/lib/generated/injectedScriptSource.js +1 -1
  42. package/lib/generated/pollingRecorderSource.js +1 -1
  43. package/lib/generated/storageScriptSource.js +1 -1
  44. package/lib/generated/utilityScriptSource.js +1 -1
  45. package/lib/mcpBundle.js +0 -6
  46. package/lib/mcpBundleImpl.js +91 -0
  47. package/lib/protocol/validator.js +224 -138
  48. package/lib/protocol/validatorPrimitives.js +1 -1
  49. package/lib/remote/playwrightConnection.js +10 -8
  50. package/lib/remote/playwrightPipeServer.js +100 -0
  51. package/lib/remote/playwrightServer.js +13 -8
  52. package/lib/remote/playwrightWebSocketServer.js +73 -0
  53. package/lib/remote/serverTransport.js +96 -0
  54. package/lib/server/android/android.js +2 -2
  55. package/lib/server/bidi/bidiBrowser.js +30 -8
  56. package/lib/server/bidi/bidiChromium.js +18 -5
  57. package/lib/server/bidi/bidiNetworkManager.js +39 -11
  58. package/lib/server/bidi/bidiPage.js +31 -15
  59. package/lib/server/bidi/third_party/firefoxPrefs.js +3 -1
  60. package/lib/server/browser.js +84 -21
  61. package/lib/server/browserContext.js +110 -58
  62. package/lib/server/browserType.js +14 -12
  63. package/lib/server/chromium/chromium.js +15 -12
  64. package/lib/server/chromium/chromiumSwitches.js +14 -2
  65. package/lib/server/chromium/crBrowser.js +20 -17
  66. package/lib/server/chromium/crCoverage.js +1 -13
  67. package/lib/server/chromium/crDevTools.js +1 -0
  68. package/lib/server/chromium/crNetworkManager.js +12 -267
  69. package/lib/server/chromium/crPage.js +67 -199
  70. package/lib/server/chromium/crServiceWorker.js +7 -14
  71. package/lib/server/clock.js +33 -41
  72. package/lib/server/console.js +5 -1
  73. package/lib/server/debugController.js +12 -6
  74. package/lib/server/debugger.js +40 -47
  75. package/lib/server/deviceDescriptorsSource.json +137 -137
  76. package/lib/server/dispatchers/browserContextDispatcher.js +29 -30
  77. package/lib/server/dispatchers/browserDispatcher.js +11 -5
  78. package/lib/server/dispatchers/browserTypeDispatcher.js +7 -0
  79. package/lib/server/dispatchers/cdpSessionDispatcher.js +4 -1
  80. package/lib/server/dispatchers/debuggerDispatcher.js +84 -0
  81. package/lib/server/dispatchers/dispatcher.js +1 -1
  82. package/lib/server/dispatchers/disposableDispatcher.js +39 -0
  83. package/lib/server/dispatchers/electronDispatcher.js +2 -1
  84. package/lib/server/dispatchers/frameDispatcher.js +6 -6
  85. package/lib/server/dispatchers/jsHandleDispatcher.js +2 -2
  86. package/lib/server/dispatchers/localUtilsDispatcher.js +37 -1
  87. package/lib/server/dispatchers/networkDispatchers.js +6 -5
  88. package/lib/server/dispatchers/pageDispatcher.js +101 -38
  89. package/lib/server/dispatchers/webSocketRouteDispatcher.js +4 -5
  90. package/lib/server/disposable.js +41 -0
  91. package/lib/server/dom.js +44 -26
  92. package/lib/server/download.js +3 -2
  93. package/lib/server/electron/electron.js +12 -7
  94. package/lib/server/firefox/ffBrowser.js +9 -19
  95. package/lib/server/firefox/ffInput.js +21 -5
  96. package/lib/server/firefox/ffNetworkManager.js +2 -2
  97. package/lib/server/firefox/ffPage.js +24 -27
  98. package/lib/server/frameSelectors.js +5 -172
  99. package/lib/server/frames.js +234 -687
  100. package/lib/server/har/harRecorder.js +2 -2
  101. package/lib/server/har/harTracer.js +5 -4
  102. package/lib/server/input.js +49 -4
  103. package/lib/server/instrumentation.js +5 -0
  104. package/lib/server/javascript.js +6 -26
  105. package/lib/server/launchApp.js +1 -3
  106. package/lib/server/localUtils.js +6 -6
  107. package/lib/server/network.js +9 -8
  108. package/lib/server/overlay.js +138 -0
  109. package/lib/server/page.js +157 -105
  110. package/lib/server/progress.js +6 -0
  111. package/lib/server/recorder/recorderApp.js +9 -8
  112. package/lib/server/recorder.js +76 -40
  113. package/lib/server/registry/index.js +55 -82
  114. package/lib/server/registry/nativeDeps.js +1 -0
  115. package/lib/server/screencast.js +90 -143
  116. package/lib/server/screenshotter.js +0 -6
  117. package/lib/server/trace/recorder/snapshotter.js +8 -17
  118. package/lib/server/trace/recorder/snapshotterInjected.js +82 -20
  119. package/lib/server/trace/recorder/tracing.js +87 -44
  120. package/lib/server/trace/viewer/traceViewer.js +3 -4
  121. package/lib/server/usKeyboardLayout.js +7 -0
  122. package/lib/server/utils/comparators.js +1 -1
  123. package/lib/server/utils/disposable.js +32 -0
  124. package/lib/server/utils/eventsHelper.js +3 -1
  125. package/lib/server/utils/fileUtils.js +16 -2
  126. package/lib/server/utils/happyEyeballs.js +15 -12
  127. package/lib/server/utils/hostPlatform.js +0 -15
  128. package/lib/server/utils/httpServer.js +5 -3
  129. package/lib/server/utils/network.js +2 -1
  130. package/lib/server/utils/nodePlatform.js +0 -6
  131. package/lib/server/utils/processLauncher.js +6 -5
  132. package/lib/server/utils/zipFile.js +2 -2
  133. package/lib/server/videoRecorder.js +82 -12
  134. package/lib/server/webkit/wkBrowser.js +1 -6
  135. package/lib/server/webkit/wkPage.js +27 -25
  136. package/lib/server/webkit/wkWorkers.js +2 -1
  137. package/lib/serverRegistry.js +156 -0
  138. package/lib/tools/backend/browserBackend.js +79 -0
  139. package/lib/tools/backend/common.js +63 -0
  140. package/lib/tools/backend/config.js +41 -0
  141. package/lib/tools/backend/console.js +66 -0
  142. package/lib/tools/backend/context.js +296 -0
  143. package/lib/tools/backend/cookies.js +152 -0
  144. package/lib/tools/backend/devtools.js +69 -0
  145. package/lib/tools/backend/dialogs.js +59 -0
  146. package/lib/tools/backend/evaluate.js +64 -0
  147. package/lib/tools/backend/files.js +60 -0
  148. package/lib/tools/backend/form.js +64 -0
  149. package/lib/tools/backend/keyboard.js +155 -0
  150. package/lib/tools/backend/logFile.js +95 -0
  151. package/lib/tools/backend/mouse.js +168 -0
  152. package/lib/tools/backend/navigate.js +106 -0
  153. package/lib/tools/backend/network.js +135 -0
  154. package/lib/tools/backend/pdf.js +48 -0
  155. package/lib/tools/backend/response.js +305 -0
  156. package/lib/tools/backend/route.js +140 -0
  157. package/lib/tools/backend/runCode.js +77 -0
  158. package/lib/tools/backend/screenshot.js +88 -0
  159. package/lib/tools/backend/sessionLog.js +74 -0
  160. package/lib/tools/backend/snapshot.js +208 -0
  161. package/lib/tools/backend/storage.js +68 -0
  162. package/lib/tools/backend/tab.js +445 -0
  163. package/lib/tools/backend/tabs.js +67 -0
  164. package/lib/tools/backend/tool.js +47 -0
  165. package/lib/tools/backend/tools.js +102 -0
  166. package/lib/tools/backend/tracing.js +78 -0
  167. package/lib/tools/backend/utils.js +83 -0
  168. package/lib/tools/backend/verify.js +151 -0
  169. package/lib/tools/backend/video.js +98 -0
  170. package/lib/tools/backend/wait.js +63 -0
  171. package/lib/tools/backend/webstorage.js +223 -0
  172. package/lib/tools/cli-client/cli.js +6 -0
  173. package/lib/tools/cli-client/help.json +399 -0
  174. package/lib/tools/cli-client/minimist.js +128 -0
  175. package/lib/tools/cli-client/program.js +350 -0
  176. package/lib/tools/cli-client/registry.js +176 -0
  177. package/lib/tools/cli-client/session.js +289 -0
  178. package/lib/tools/cli-client/skill/SKILL.md +328 -0
  179. package/lib/tools/cli-client/skill/references/element-attributes.md +23 -0
  180. package/lib/tools/cli-client/skill/references/playwright-tests.md +39 -0
  181. package/lib/tools/cli-client/skill/references/request-mocking.md +87 -0
  182. package/lib/tools/cli-client/skill/references/running-code.md +231 -0
  183. package/lib/tools/cli-client/skill/references/session-management.md +169 -0
  184. package/lib/tools/cli-client/skill/references/storage-state.md +275 -0
  185. package/lib/tools/cli-client/skill/references/test-generation.md +88 -0
  186. package/lib/tools/cli-client/skill/references/tracing.md +139 -0
  187. package/lib/tools/cli-client/skill/references/video-recording.md +143 -0
  188. package/lib/tools/cli-daemon/command.js +73 -0
  189. package/lib/tools/cli-daemon/commands.js +956 -0
  190. package/lib/tools/cli-daemon/daemon.js +157 -0
  191. package/lib/tools/cli-daemon/helpGenerator.js +177 -0
  192. package/lib/tools/cli-daemon/program.js +129 -0
  193. package/lib/tools/dashboard/appIcon.png +0 -0
  194. package/lib/tools/dashboard/dashboardApp.js +284 -0
  195. package/lib/tools/dashboard/dashboardController.js +296 -0
  196. package/lib/tools/exports.js +60 -0
  197. package/lib/tools/mcp/browserFactory.js +233 -0
  198. package/lib/tools/mcp/cdpRelay.js +352 -0
  199. package/lib/tools/mcp/cli-stub.js +7 -0
  200. package/lib/tools/mcp/config.d.js +16 -0
  201. package/lib/tools/mcp/config.js +446 -0
  202. package/lib/tools/mcp/configIni.js +189 -0
  203. package/lib/tools/mcp/extensionContextFactory.js +55 -0
  204. package/lib/tools/mcp/index.js +62 -0
  205. package/lib/tools/mcp/log.js +35 -0
  206. package/lib/tools/mcp/program.js +107 -0
  207. package/lib/tools/mcp/protocol.js +28 -0
  208. package/lib/tools/mcp/watchdog.js +44 -0
  209. package/lib/tools/trace/SKILL.md +171 -0
  210. package/lib/{server/trace/viewer/traceParser.js → tools/trace/installSkill.js} +15 -39
  211. package/lib/tools/trace/traceActions.js +142 -0
  212. package/lib/tools/trace/traceAttachments.js +69 -0
  213. package/lib/tools/trace/traceCli.js +87 -0
  214. package/lib/tools/trace/traceConsole.js +97 -0
  215. package/lib/tools/trace/traceErrors.js +55 -0
  216. package/lib/tools/trace/traceOpen.js +69 -0
  217. package/lib/tools/trace/traceParser.js +96 -0
  218. package/lib/tools/trace/traceRequests.js +182 -0
  219. package/lib/tools/trace/traceScreenshot.js +68 -0
  220. package/lib/tools/trace/traceSnapshot.js +149 -0
  221. package/lib/tools/trace/traceUtils.js +153 -0
  222. package/lib/tools/utils/connect.js +32 -0
  223. package/lib/tools/utils/mcp/http.js +152 -0
  224. package/lib/tools/utils/mcp/server.js +230 -0
  225. package/lib/tools/utils/mcp/tool.js +47 -0
  226. package/lib/tools/utils/socketConnection.js +108 -0
  227. package/lib/utils/isomorphic/formatUtils.js +64 -0
  228. package/lib/utils/isomorphic/jsonSchema.js +89 -0
  229. package/lib/utils/isomorphic/mimeType.js +7 -2
  230. package/lib/utils/isomorphic/protocolFormatter.js +2 -2
  231. package/lib/utils/isomorphic/protocolMetainfo.js +127 -106
  232. package/lib/utils/isomorphic/stringUtils.js +3 -3
  233. package/lib/utils/isomorphic/timeoutRunner.js +3 -3
  234. package/lib/utils/isomorphic/trace/snapshotRenderer.js +35 -42
  235. package/lib/utils/isomorphic/trace/traceLoader.js +15 -14
  236. package/lib/utils/isomorphic/trace/traceModel.js +3 -2
  237. package/lib/utils/isomorphic/trace/traceModernizer.js +1 -0
  238. package/lib/utils/isomorphic/urlMatch.js +54 -1
  239. package/lib/utils/isomorphic/utilityScriptSerializers.js +11 -0
  240. package/lib/utils.js +6 -2
  241. package/lib/utilsBundle.js +3 -21
  242. package/lib/utilsBundleImpl/index.js +132 -133
  243. package/lib/vite/dashboard/assets/index-BAOybkp8.js +50 -0
  244. package/lib/vite/dashboard/assets/index-CZAYOG76.css +1 -0
  245. package/lib/vite/dashboard/index.html +28 -0
  246. package/lib/vite/htmlReport/index.html +2 -70
  247. package/lib/vite/htmlReport/report.css +1 -0
  248. package/lib/vite/htmlReport/report.js +72 -0
  249. package/lib/vite/recorder/assets/{codeMirrorModule-CFUTFUO7.js → codeMirrorModule-C8KMvO9L.js} +20 -20
  250. package/lib/vite/recorder/assets/index-CqAYX1I3.js +193 -0
  251. package/lib/vite/recorder/index.html +1 -1
  252. package/lib/vite/traceViewer/assets/{codeMirrorModule-BVA4h_ZY.js → codeMirrorModule-DS0FLvoc.js} +20 -20
  253. package/lib/vite/traceViewer/assets/defaultSettingsView-GTWI-W_B.js +262 -0
  254. package/lib/vite/traceViewer/defaultSettingsView.B4dS75f0.css +1 -0
  255. package/lib/vite/traceViewer/{index.BtyWtaE-.js → index.C5466mMT.js} +1 -1
  256. package/lib/vite/traceViewer/{index.BVu7tZDe.css → index.CzXZzn5A.css} +1 -1
  257. package/lib/vite/traceViewer/index.html +4 -4
  258. package/lib/vite/traceViewer/sw.bundle.js +4 -4
  259. package/lib/vite/traceViewer/uiMode.Vipi55dB.js +6 -0
  260. package/lib/vite/traceViewer/uiMode.html +3 -3
  261. package/lib/zipBundleImpl.js +2 -2
  262. package/lib/zodBundle.js +39 -0
  263. package/lib/zodBundleImpl.js +40 -0
  264. package/package.json +6 -1
  265. package/types/protocol.d.ts +947 -51
  266. package/types/types.d.ts +854 -74
  267. package/lib/client/pageAgent.js +0 -64
  268. package/lib/mcpBundleImpl/index.js +0 -147
  269. package/lib/server/agent/actionRunner.js +0 -335
  270. package/lib/server/agent/actions.js +0 -128
  271. package/lib/server/agent/codegen.js +0 -111
  272. package/lib/server/agent/context.js +0 -150
  273. package/lib/server/agent/expectTools.js +0 -156
  274. package/lib/server/agent/pageAgent.js +0 -204
  275. package/lib/server/agent/performTools.js +0 -262
  276. package/lib/server/agent/tool.js +0 -109
  277. package/lib/server/dispatchers/pageAgentDispatcher.js +0 -96
  278. package/lib/server/pageBinding.js +0 -87
  279. package/lib/utils/isomorphic/oldUtilityScriptSerializers.js +0 -248
  280. package/lib/vite/recorder/assets/index-CVkBxsGf.js +0 -193
  281. package/lib/vite/traceViewer/assets/defaultSettingsView-CjfmcdOz.js +0 -266
  282. package/lib/vite/traceViewer/defaultSettingsView.7ch9cixO.css +0 -1
  283. package/lib/vite/traceViewer/uiMode.fyrXARf2.js +0 -5
  284. /package/lib/{server/utils → utils/isomorphic}/imageUtils.js +0 -0
  285. /package/lib/utils/isomorphic/{traceUtils.js → trace/traceUtils.js} +0 -0
@@ -33,8 +33,6 @@ __export(frames_exports, {
33
33
  NavigationAbortedError: () => NavigationAbortedError
34
34
  });
35
35
  module.exports = __toCommonJS(frames_exports);
36
- var import_crExecutionContext = require("./chromium/crExecutionContext");
37
- var import_dom = require("./dom");
38
36
  var import_browserContext = require("./browserContext");
39
37
  var dom = __toESM(require("./dom"));
40
38
  var import_errors = require("./errors");
@@ -49,7 +47,6 @@ var import_progress = require("./progress");
49
47
  var types = __toESM(require("./types"));
50
48
  var import_utils = require("../utils");
51
49
  var import_protocolError = require("./protocolError");
52
- var import_debugLogger = require("./utils/debugLogger");
53
50
  var import_eventsHelper = require("./utils/eventsHelper");
54
51
  var import_selectorParser = require("../utils/isomorphic/selectorParser");
55
52
  var import_manualPromise = require("../utils/isomorphic/manualPromise");
@@ -177,14 +174,11 @@ class FrameManager {
177
174
  } else {
178
175
  frame._currentDocument = { documentId, request: void 0 };
179
176
  }
180
- frame._iframeWorld = void 0;
181
- frame._mainWorld = void 0;
182
- frame._isolatedWorld = void 0;
183
177
  frame._onClearLifecycle();
184
178
  const navigationEvent = { url, name, newDocument: frame._currentDocument, isPublic: true };
185
179
  this._fireInternalFrameNavigation(frame, navigationEvent);
186
180
  if (!initial) {
187
- import_debugLogger.debugLogger.log("api", ` navigated to "${url}"`);
181
+ frame.apiLog(` navigated to "${url}"`);
188
182
  this._page.frameNavigatedToNewDocument(frame);
189
183
  }
190
184
  frame.setPendingDocument(keepPending);
@@ -200,7 +194,7 @@ class FrameManager {
200
194
  frame._url = url;
201
195
  const navigationEvent = { url, name: frame._name, isPublic: true };
202
196
  this._fireInternalFrameNavigation(frame, navigationEvent);
203
- import_debugLogger.debugLogger.log("api", ` navigated to "${url}"`);
197
+ frame.apiLog(` navigated to "${url}"`);
204
198
  }
205
199
  frameAbortedNavigation(frameId, errorText, documentId) {
206
200
  const frame = this._frames.get(frameId);
@@ -403,7 +397,7 @@ class Frame extends import_instrumentation.SdkObject {
403
397
  this._firedLifecycleEvents.add(event);
404
398
  this.emit(Frame.Events.AddLifecycle, event);
405
399
  if (this === this._page.mainFrame() && this._url !== "about:blank")
406
- import_debugLogger.debugLogger.log("api", ` "${event}" event fired`);
400
+ this.apiLog(` "${event}" event fired`);
407
401
  this._page.mainFrame()._recalculateNetworkIdle();
408
402
  }
409
403
  _onClearLifecycle() {
@@ -457,11 +451,7 @@ class Frame extends import_instrumentation.SdkObject {
457
451
  });
458
452
  }
459
453
  nonStallingEvaluateInExistingContext(expression, world) {
460
- return this.raceAgainstEvaluationStallingEvents(async () => {
461
- try {
462
- await this._context(world);
463
- } catch {
464
- }
454
+ return this.raceAgainstEvaluationStallingEvents(() => {
465
455
  const context = this._contextData.get(world)?.context;
466
456
  if (!context)
467
457
  throw new Error("Frame does not yet have the execution context");
@@ -479,7 +469,7 @@ class Frame extends import_instrumentation.SdkObject {
479
469
  this._firedLifecycleEvents.add("networkidle");
480
470
  this.emit(Frame.Events.AddLifecycle, "networkidle");
481
471
  if (this === this._page.mainFrame() && this._url !== "about:blank")
482
- import_debugLogger.debugLogger.log("api", ` "networkidle" event fired`);
472
+ this.apiLog(` "networkidle" event fired`);
483
473
  }
484
474
  if (frameThatAllowsRemovingNetworkIdle !== this && this._firedLifecycleEvents.has("networkidle") && !isNetworkIdle) {
485
475
  this._firedLifecycleEvents.delete("networkidle");
@@ -587,74 +577,12 @@ class Frame extends import_instrumentation.SdkObject {
587
577
  async frameElement() {
588
578
  return this._page.delegate.getFrameElement(this);
589
579
  }
590
- async _context(world) {
591
- if (this.isDetached()) throw new Error("Frame was detached");
592
- try {
593
- var client = this._page.delegate._sessionForFrame(this)._client;
594
- } catch (e) {
595
- var client = this._page.delegate._mainFrameSession._client;
596
- }
597
- var iframeExecutionContextId = await this._getFrameMainFrameContextId(client);
598
- if (world == "main") {
599
- if (this != this._page.mainFrame() && iframeExecutionContextId && this._iframeWorld == void 0) {
600
- var executionContextId = iframeExecutionContextId;
601
- var crContext = new import_crExecutionContext.CRExecutionContext(client, { id: executionContextId }, this._id);
602
- this._iframeWorld = new import_dom.FrameExecutionContext(crContext, this, world);
603
- this._page.delegate._sessionForFrame(this)._onExecutionContextCreated({
604
- id: executionContextId,
605
- origin: world,
606
- name: world,
607
- auxData: { isDefault: this === this._page.mainFrame(), type: "isolated", frameId: this._id }
608
- });
609
- } else if (this._mainWorld == void 0) {
610
- var globalThis2 = await client._sendMayFail("Runtime.evaluate", {
611
- expression: "globalThis",
612
- serializationOptions: { serialization: "idOnly" }
613
- });
614
- if (!globalThis2) {
615
- if (this.isDetached()) throw new Error("Frame was detached");
616
- return;
617
- }
618
- var globalThisObjId = globalThis2["result"]["objectId"];
619
- var executionContextId = parseInt(globalThisObjId.split(".")[1], 10);
620
- var crContext = new import_crExecutionContext.CRExecutionContext(client, { id: executionContextId }, this._id);
621
- this._mainWorld = new import_dom.FrameExecutionContext(crContext, this, world);
622
- this._page.delegate._sessionForFrame(this)._onExecutionContextCreated({
623
- id: executionContextId,
624
- origin: world,
625
- name: world,
626
- auxData: { isDefault: this === this._page.mainFrame(), type: "isolated", frameId: this._id }
627
- });
628
- }
629
- }
630
- if (world != "main" && this._isolatedWorld == void 0) {
631
- world = "utility";
632
- var result = await client._sendMayFail("Page.createIsolatedWorld", {
633
- frameId: this._id,
634
- grantUniveralAccess: true,
635
- worldName: world
636
- });
637
- if (!result) {
638
- if (this.isDetached()) throw new Error("Frame was detached");
639
- return;
640
- }
641
- var executionContextId = result.executionContextId;
642
- var crContext = new import_crExecutionContext.CRExecutionContext(client, { id: executionContextId }, this._id);
643
- this._isolatedWorld = new import_dom.FrameExecutionContext(crContext, this, world);
644
- this._page.delegate._sessionForFrame(this)._onExecutionContextCreated({
645
- id: executionContextId,
646
- origin: world,
647
- name: world,
648
- auxData: { isDefault: this === this._page.mainFrame(), type: "isolated", frameId: this._id }
649
- });
650
- }
651
- if (world != "main") {
652
- return this._isolatedWorld;
653
- } else if (this != this._page.mainFrame() && this._iframeWorld) {
654
- return this._iframeWorld;
655
- } else {
656
- return this._mainWorld;
657
- }
580
+ _context(world) {
581
+ return this._contextData.get(world).contextPromise.then((contextOrDestroyedReason) => {
582
+ if (contextOrDestroyedReason instanceof js.ExecutionContext)
583
+ return contextOrDestroyedReason;
584
+ throw new Error(contextOrDestroyedReason.destroyedReason);
585
+ });
658
586
  }
659
587
  _mainContext() {
660
588
  return this._context("main");
@@ -666,23 +594,18 @@ class Frame extends import_instrumentation.SdkObject {
666
594
  return this._context("utility");
667
595
  }
668
596
  async evaluateExpression(expression, options = {}, arg) {
669
- const context = await this._detachedScope.race(this._context(options.world ?? "main"));
670
- const value = await this._detachedScope.race(context.evaluateExpression(expression, options, arg));
597
+ const context = await this._context(options.world ?? "main");
598
+ const value = await context.evaluateExpression(expression, options, arg);
671
599
  return value;
672
600
  }
673
601
  async evaluateExpressionHandle(expression, options = {}, arg) {
674
- const context = await this._detachedScope.race(this._context(options.world ?? "utility"));
675
- const value = await this._detachedScope.race(context.evaluateExpressionHandle(expression, options, arg));
602
+ const context = await this._context(options.world ?? "main");
603
+ const value = await context.evaluateExpressionHandle(expression, options, arg);
676
604
  return value;
677
605
  }
678
606
  async querySelector(selector, options) {
679
- return this.querySelectorAll(selector, options).then((handles) => {
680
- if (handles.length === 0)
681
- return null;
682
- if (handles.length > 1 && options?.strict)
683
- throw new Error(`Strict mode: expected one element matching selector "${selector}", found ${handles.length}`);
684
- return handles[0];
685
- });
607
+ this.apiLog(` finding element using the selector "${selector}"`);
608
+ return this.selectors.query(selector, options);
686
609
  }
687
610
  async waitForSelector(progress, selector, performActionPreChecksAndLog, options, scope) {
688
611
  if (options.visibility)
@@ -694,109 +617,77 @@ class Frame extends import_instrumentation.SdkObject {
694
617
  throw new Error(`state: expected one of (attached|detached|visible|hidden)`);
695
618
  if (performActionPreChecksAndLog)
696
619
  progress.log(`waiting for ${this._asLocator(selector)}${state === "attached" ? "" : " to be " + state}`);
697
- const promise = this._retryWithProgressIfNotConnected(progress, selector, { ...options, performActionPreChecks: true, __patchrightWaitForSelector: true, __patchrightInitialScope: scope }, async (handle) => {
698
- if (scope) {
699
- const scopeIsConnected = await scope.evaluateInUtility(([injected, node]) => node.isConnected, {}).catch(() => false);
700
- if (scopeIsConnected !== true) {
701
- if (state === "hidden" || state === "detached")
702
- return null;
703
- throw new dom.NonRecoverableDOMError("Element is not attached to the DOM");
704
- }
620
+ const promise = this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling) => {
621
+ if (performActionPreChecksAndLog)
622
+ await this._page.performActionPreChecks(progress);
623
+ const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector, options, scope));
624
+ if (!resolved) {
625
+ if (state === "hidden" || state === "detached")
626
+ return null;
627
+ return continuePolling;
705
628
  }
706
- const attached = !!handle;
707
- var visible = false;
708
- if (attached) {
709
- if (handle.parentNode.constructor.name == "ElementHandle") {
710
- visible = await handle.parentNode.evaluateInUtility(([injected, node, { handle: handle2 }]) => {
711
- return handle2 ? injected.utils.isElementVisible(handle2) : false;
712
- }, { handle });
713
- } else {
714
- visible = await handle.parentNode.evaluate((injected, { handle: handle2 }) => {
715
- return handle2 ? injected.utils.isElementVisible(handle2) : false;
716
- }, { handle });
629
+ const result = await progress.race(resolved.injected.evaluateHandle((injected, { info, root }) => {
630
+ if (root && !root.isConnected)
631
+ throw injected.createStacklessError("Element is not attached to the DOM");
632
+ const elements = injected.querySelectorAll(info.parsed, root || document);
633
+ const element2 = elements[0];
634
+ const visible2 = element2 ? injected.utils.isElementVisible(element2) : false;
635
+ let log2 = "";
636
+ if (elements.length > 1) {
637
+ if (info.strict)
638
+ throw injected.strictModeViolationError(info.parsed, elements);
639
+ log2 = ` locator resolved to ${elements.length} elements. Proceeding with the first one: ${injected.previewNode(elements[0])}`;
640
+ } else if (element2) {
641
+ log2 = ` locator resolved to ${visible2 ? "visible" : "hidden"} ${injected.previewNode(element2)}`;
717
642
  }
643
+ injected.checkDeprecatedSelectorUsage(info.parsed, elements);
644
+ return { log: log2, element: element2, visible: visible2, attached: !!element2 };
645
+ }, { info: resolved.info, root: resolved.frame === this ? scope : void 0 }));
646
+ const { log, visible, attached } = await progress.race(result.evaluate((r) => ({ log: r.log, visible: r.visible, attached: r.attached })));
647
+ if (log)
648
+ progress.log(log);
649
+ const success = { attached, detached: !attached, visible, hidden: !visible }[state];
650
+ if (!success) {
651
+ result.dispose();
652
+ return continuePolling;
718
653
  }
719
- const success = {
720
- attached,
721
- detached: !attached,
722
- visible,
723
- hidden: !visible
724
- }[state];
725
- if (!success) return "internal:continuepolling";
726
- if (options.omitReturnValue) return null;
727
- const element = state === "attached" || state === "visible" ? handle : null;
728
- if (!element) return null;
729
- if (options.__testHookBeforeAdoptNode) await options.__testHookBeforeAdoptNode();
654
+ if (options.omitReturnValue) {
655
+ result.dispose();
656
+ return null;
657
+ }
658
+ const element = state === "attached" || state === "visible" ? await progress.race(result.evaluateHandle((r) => r.element)) : null;
659
+ result.dispose();
660
+ if (!element)
661
+ return null;
662
+ if (options.__testHookBeforeAdoptNode)
663
+ await progress.race(options.__testHookBeforeAdoptNode());
730
664
  try {
731
- return element;
665
+ const mainContext = await progress.race(resolved.frame._mainContext());
666
+ return await progress.race(element._adoptTo(mainContext));
732
667
  } catch (e) {
733
- return "internal:continuepolling";
668
+ return continuePolling;
734
669
  }
735
- }, "returnOnNotResolved");
736
- const resultPromise = scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
737
- return resultPromise.catch((e) => {
738
- if (this.isDetached() && e?.message?.includes("Execution context was destroyed"))
739
- throw new Error("Frame was detached");
740
- throw e;
741
670
  });
671
+ return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
742
672
  }
743
673
  async dispatchEvent(progress, selector, type, eventInit = {}, options, scope) {
744
- const eventInitHandles = [];
745
- const visited = /* @__PURE__ */ new WeakSet();
746
- const collectHandles = (value) => {
747
- if (!value || typeof value !== "object")
748
- return;
749
- if (value instanceof js.JSHandle) {
750
- eventInitHandles.push(value);
751
- return;
752
- }
753
- if (visited.has(value))
754
- return;
755
- visited.add(value);
756
- if (Array.isArray(value)) {
757
- for (const item of value)
758
- collectHandles(item);
759
- return;
760
- }
761
- for (const propertyValue of Object.values(value))
762
- collectHandles(propertyValue);
763
- };
764
- collectHandles(eventInit);
765
- const allHandlesFromSameFrame = eventInitHandles.length > 0 && eventInitHandles.every((handle) => handle._context?.frame === eventInitHandles[0]?._context?.frame);
766
- const handlesFrame = eventInitHandles[0]?._context?.frame;
767
- const canRetryInSecondaryContext = allHandlesFromSameFrame && (handlesFrame !== this || !selector.includes("internal:control=enter-frame"));
768
- const callback = (injectedScript, element, data) => {
674
+ await this._callOnElementOnceMatches(progress, selector, (injectedScript, element, data) => {
769
675
  injectedScript.dispatchEvent(element, data.type, data.eventInit);
770
- };
771
- try {
772
- await this._callOnElementOnceMatches(progress, selector, callback, { type, eventInit }, { mainWorld: true, ...options }, scope);
773
- } catch (e) {
774
- if ("JSHandles can be evaluated only in the context they were created!" === e.message && canRetryInSecondaryContext) {
775
- await this._callOnElementOnceMatches(progress, selector, callback, { type, eventInit }, { ...options }, scope);
776
- return;
777
- }
778
- throw e;
779
- }
676
+ }, { type, eventInit }, { mainWorld: true, ...options }, scope);
780
677
  }
781
678
  async evalOnSelector(selector, strict, expression, isFunction, arg, scope) {
782
679
  const handle = await this.selectors.query(selector, { strict }, scope);
783
680
  if (!handle)
784
- throw new Error('Failed to find element matching selector "' + selector + '"');
785
- const result = await handle.evaluateExpression(expression, { isFunction }, arg, true);
681
+ throw new Error(`Failed to find element matching selector "${selector}"`);
682
+ const result = await handle.evaluateExpression(expression, { isFunction }, arg);
786
683
  handle.dispose();
787
684
  return result;
788
685
  }
789
- async evalOnSelectorAll(selector, expression, isFunction, arg, scope, isolatedContext) {
790
- try {
791
- isolatedContext = this.selectors._parseSelector(selector, { strict: false }).world !== "main" && isolatedContext;
792
- const arrayHandle = await this.selectors.queryArrayInMainWorld(selector, scope, isolatedContext);
793
- const result = await arrayHandle.evaluateExpression(expression, { isFunction }, arg, isolatedContext);
794
- arrayHandle.dispose();
795
- return result;
796
- } catch (e) {
797
- if ("JSHandles can be evaluated only in the context they were created!" === e.message) return await this.evalOnSelectorAll(selector, expression, isFunction, arg, scope, isolatedContext);
798
- throw e;
799
- }
686
+ async evalOnSelectorAll(selector, expression, isFunction, arg, scope) {
687
+ const arrayHandle = await this.selectors.queryArrayInMainWorld(selector, scope);
688
+ const result = await arrayHandle.evaluateExpression(expression, { isFunction }, arg);
689
+ arrayHandle.dispose();
690
+ return result;
800
691
  }
801
692
  async maskSelectors(selectors, color) {
802
693
  const context = await this._utilityContext();
@@ -806,30 +697,16 @@ class Frame extends import_instrumentation.SdkObject {
806
697
  }, { parsed: selectors, color });
807
698
  }
808
699
  async querySelectorAll(selector) {
809
- const metadata = { internal: false, log: [], method: "querySelectorAll" };
810
- const progress = {
811
- log: (message) => metadata.log.push(message),
812
- metadata,
813
- race: (promise) => Promise.race(Array.isArray(promise) ? promise : [promise])
814
- };
815
- return await this._retryWithoutProgress(progress, selector, { strict: null, performActionPreChecks: false }, async (result) => {
816
- if (!result || !result[0]) return [];
817
- return result[1];
818
- }, "returnAll", null);
700
+ return this.selectors.queryAll(selector);
819
701
  }
820
702
  async queryCount(selector, options) {
821
- const metadata = { internal: false, log: [], method: "queryCount" };
822
- const progress = {
823
- log: (message) => metadata.log.push(message),
824
- metadata,
825
- race: (promise) => Promise.race(Array.isArray(promise) ? promise : [promise])
826
- };
827
- return await this._retryWithoutProgress(progress, selector, { strict: null, performActionPreChecks: false }, async (result) => {
828
- if (!result) return 0;
829
- const handle = result[0];
830
- const handles = result[1];
831
- return handle ? handles.length : 0;
832
- }, "returnAll", null);
703
+ try {
704
+ return await this.selectors.queryCount(selector, options);
705
+ } catch (e) {
706
+ if (this.isNonRetriableError(e))
707
+ throw e;
708
+ return 0;
709
+ }
833
710
  }
834
711
  async content() {
835
712
  try {
@@ -849,19 +726,27 @@ class Frame extends import_instrumentation.SdkObject {
849
726
  }
850
727
  }
851
728
  async setContent(progress, html, options) {
729
+ const tag = `--playwright--set--content--${this._id}--${++this._setContentCounter}--`;
852
730
  await this.raceNavigationAction(progress, async () => {
853
731
  const waitUntil = options.waitUntil === void 0 ? "load" : options.waitUntil;
854
732
  progress.log(`setting frame content, waiting until "${waitUntil}"`);
855
- const lifecyclePromise = new Promise((resolve, reject) => {
733
+ const context = await progress.race(this._utilityContext());
734
+ const tagPromise = new import_manualPromise.ManualPromise();
735
+ this._page.frameManager._consoleMessageTags.set(tag, () => {
856
736
  this._onClearLifecycle();
857
- this.waitForLoadState(progress, waitUntil).then(resolve).catch(reject);
858
- });
859
- const setContentPromise = this._page.delegate._sessionForFrame(this)._client.send("Page.setDocumentContent", {
860
- frameId: this._id,
861
- html
737
+ tagPromise.resolve();
862
738
  });
863
- await Promise.all([setContentPromise, lifecyclePromise]);
739
+ const lifecyclePromise = progress.race(tagPromise).then(() => this.waitForLoadState(progress, waitUntil));
740
+ const contentPromise = progress.race(context.evaluate(({ html: html2, tag: tag2 }) => {
741
+ document.open();
742
+ console.debug(tag2);
743
+ document.write(html2);
744
+ document.close();
745
+ }, { html, tag }));
746
+ await Promise.all([contentPromise, lifecyclePromise]);
864
747
  return null;
748
+ }).finally(() => {
749
+ this._page.frameManager._consoleMessageTags.delete(tag);
865
750
  });
866
751
  }
867
752
  name() {
@@ -1021,11 +906,58 @@ class Frame extends import_instrumentation.SdkObject {
1021
906
  return true;
1022
907
  return false;
1023
908
  }
1024
- async _retryWithProgressIfNotConnected(progress, selector, options, action, returnAction) {
1025
- if (!options?.__patchrightSkipRetryLogWaiting)
1026
- progress.log("waiting for " + this._asLocator(selector));
909
+ async _retryWithProgressIfNotConnected(progress, selector, options, action) {
910
+ progress.log(`waiting for ${this._asLocator(selector)}`);
911
+ const noAutoWaiting = options.__testHookNoAutoWaiting ?? options.noAutoWaiting;
912
+ const performActionPreChecks = (options.performActionPreChecks ?? !options.force) && !noAutoWaiting;
1027
913
  return this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling) => {
1028
- return this._retryWithoutProgress(progress, selector, options, action, returnAction, continuePolling);
914
+ if (performActionPreChecks)
915
+ await this._page.performActionPreChecks(progress);
916
+ const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector, { strict: options.strict }));
917
+ if (!resolved) {
918
+ if (noAutoWaiting)
919
+ throw new dom.NonRecoverableDOMError("Element(s) not found");
920
+ return continuePolling;
921
+ }
922
+ const result = await progress.race(resolved.injected.evaluateHandle((injected, { info, callId }) => {
923
+ const elements = injected.querySelectorAll(info.parsed, document);
924
+ if (callId)
925
+ injected.markTargetElements(new Set(elements), callId);
926
+ const element2 = elements[0];
927
+ let log2 = "";
928
+ if (elements.length > 1) {
929
+ if (info.strict)
930
+ throw injected.strictModeViolationError(info.parsed, elements);
931
+ log2 = ` locator resolved to ${elements.length} elements. Proceeding with the first one: ${injected.previewNode(elements[0])}`;
932
+ } else if (element2) {
933
+ log2 = ` locator resolved to ${injected.previewNode(element2)}`;
934
+ }
935
+ injected.checkDeprecatedSelectorUsage(info.parsed, elements);
936
+ return { log: log2, success: !!element2, element: element2 };
937
+ }, { info: resolved.info, callId: progress.metadata.id }));
938
+ const { log, success } = await progress.race(result.evaluate((r) => ({ log: r.log, success: r.success })));
939
+ if (log)
940
+ progress.log(log);
941
+ if (!success) {
942
+ if (noAutoWaiting)
943
+ throw new dom.NonRecoverableDOMError("Element(s) not found");
944
+ result.dispose();
945
+ return continuePolling;
946
+ }
947
+ const element = await progress.race(result.evaluateHandle((r) => r.element));
948
+ result.dispose();
949
+ try {
950
+ const result2 = await action(element);
951
+ if (result2 === "error:notconnected") {
952
+ if (noAutoWaiting)
953
+ throw new dom.NonRecoverableDOMError("Element is not attached to the DOM");
954
+ progress.log("element was detached from the DOM, retrying");
955
+ return continuePolling;
956
+ }
957
+ return result2;
958
+ } finally {
959
+ element?.dispose();
960
+ }
1029
961
  });
1030
962
  }
1031
963
  async rafrafTimeoutScreenshotElementWithProgress(progress, selector, timeout, options) {
@@ -1158,56 +1090,17 @@ class Frame extends import_instrumentation.SdkObject {
1158
1090
  }
1159
1091
  async isVisibleInternal(progress, selector, options = {}, scope) {
1160
1092
  try {
1161
- const metadata = { internal: false, log: [], method: "isVisible" };
1162
- const progress2 = {
1163
- log: (message) => metadata.log.push(message),
1164
- metadata,
1165
- race: (promise) => Promise.race(Array.isArray(promise) ? promise : [promise])
1166
- };
1167
- progress2.log("waiting for " + this._asLocator(selector));
1168
- if (selector === ":scope") {
1169
- const scopeParentNode = scope.parentNode || scope;
1170
- if (scopeParentNode.constructor.name == "ElementHandle") {
1171
- return await scopeParentNode.evaluateInUtility(([injected, node, { scope: handle2 }]) => {
1172
- const state = handle2 ? injected.elementState(handle2, "visible") : {
1173
- matches: false,
1174
- received: "error:notconnected"
1175
- };
1176
- return state.matches;
1177
- }, { scope });
1178
- } else {
1179
- return await scopeParentNode.evaluate((injected, node, { scope: handle2 }) => {
1180
- const state = handle2 ? injected.elementState(handle2, "visible") : {
1181
- matches: false,
1182
- received: "error:notconnected"
1183
- };
1184
- return state.matches;
1185
- }, { scope });
1186
- }
1187
- } else {
1188
- return await this._retryWithoutProgress(progress2, selector, { ...options, performActionPreChecks: false }, async (handle) => {
1189
- if (!handle) return false;
1190
- if (handle.parentNode.constructor.name == "ElementHandle") {
1191
- return await handle.parentNode.evaluateInUtility(([injected, node, { handle: handle2 }]) => {
1192
- const state = handle2 ? injected.elementState(handle2, "visible") : {
1193
- matches: false,
1194
- received: "error:notconnected"
1195
- };
1196
- return state.matches;
1197
- }, { handle });
1198
- } else {
1199
- return await handle.parentNode.evaluate((injected, { handle: handle2 }) => {
1200
- const state = handle2 ? injected.elementState(handle2, "visible") : {
1201
- matches: false,
1202
- received: "error:notconnected"
1203
- };
1204
- return state.matches;
1205
- }, { handle });
1206
- }
1207
- }, "returnOnNotResolved", null);
1208
- }
1093
+ const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector, options, scope));
1094
+ if (!resolved)
1095
+ return false;
1096
+ return await progress.race(resolved.injected.evaluate((injected, { info, root }) => {
1097
+ const element = injected.querySelector(info.parsed, root || document, info.strict);
1098
+ const state = element ? injected.elementState(element, "visible") : { matches: false, received: "error:notconnected" };
1099
+ return state.matches;
1100
+ }, { info: resolved.info, root: resolved.frame === this ? scope : void 0 }));
1209
1101
  } catch (e) {
1210
- if (this.isNonRetriableError(e)) throw e;
1102
+ if (this.isNonRetriableError(e))
1103
+ throw e;
1211
1104
  return false;
1212
1105
  }
1213
1106
  }
@@ -1251,9 +1144,6 @@ class Frame extends import_instrumentation.SdkObject {
1251
1144
  async waitForTimeout(progress, timeout) {
1252
1145
  return progress.wait(timeout);
1253
1146
  }
1254
- async ariaSnapshot(progress, selector) {
1255
- return await this._retryWithProgressIfNotConnected(progress, selector, { strict: true, performActionPreChecks: true }, (handle) => progress.race(handle.ariaSnapshot()));
1256
- }
1257
1147
  async expect(progress, selector, options) {
1258
1148
  progress.log(`${(0, import_utils.renderTitleForCall)(progress.metadata)}${options.timeoutForLogs ? ` with timeout ${options.timeoutForLogs}ms` : ""}`);
1259
1149
  const lastIntermediateResult = { isSet: false };
@@ -1303,63 +1193,27 @@ class Frame extends import_instrumentation.SdkObject {
1303
1193
  }
1304
1194
  async _expectInternal(progress, selector, options, lastIntermediateResult, noAbort) {
1305
1195
  const race = (p) => noAbort ? p : progress.race(p);
1306
- const isArray = options.expression === "to.have.count" || options.expression.endsWith(".array");
1307
- var log, matches, received, missingReceived;
1308
- if (selector) {
1309
- var frame, info;
1310
- try {
1311
- var { frame, info } = await race(this.selectors.resolveFrameForSelector(selector, { strict: true }));
1312
- } catch (e) {
1313
- }
1314
- const action = async (result) => {
1315
- if (!result) {
1316
- if (options.expectedNumber === 0)
1317
- return { matches: true };
1318
- if (options.isNot && options.expectedNumber)
1319
- return { matches: false, received: 0 };
1320
- if (!options.isNot && options.expression === "to.be.hidden")
1321
- return { matches: true };
1322
- if (options.isNot && options.expression === "to.be.visible")
1323
- return { matches: false };
1324
- if (!options.isNot && options.expression === "to.be.detached")
1325
- return { matches: true };
1326
- if (options.isNot && options.expression === "to.be.attached")
1327
- return { matches: false };
1328
- if (options.isNot && options.expression === "to.be.in.viewport")
1329
- return { matches: false };
1330
- if (options.expression === "to.have.text.array") {
1331
- if (options.expectedText.length === 0)
1332
- return { matches: true, received: [] };
1333
- if (options.isNot && options.expectedText.length !== 0)
1334
- return { matches: false, received: [] };
1335
- }
1336
- return { matches: options.isNot, missingReceived: true };
1337
- }
1338
- const handle = result[0];
1339
- const handles = result[1];
1340
- if (handle.parentNode.constructor.name == "ElementHandle") {
1341
- return await handle.parentNode.evaluateInUtility(async ([injected, node, { handle: handle2, options: options2, handles: handles2 }]) => {
1342
- return await injected.expect(handle2, options2, handles2);
1343
- }, { handle, options, handles });
1344
- } else {
1345
- return await handle.parentNode.evaluate(async (injected, { handle: handle2, options: options2, handles: handles2 }) => {
1346
- return await injected.expect(handle2, options2, handles2);
1347
- }, { handle, options, handles });
1348
- }
1349
- };
1350
- if (noAbort) {
1351
- var { log, matches, received, missingReceived } = await this._retryWithoutProgress(progress, selector, { strict: !isArray, performActionPreChecks: false }, action, "returnAll", null);
1352
- } else {
1353
- var { log, matches, received, missingReceived } = await race(this._retryWithProgressIfNotConnected(progress, selector, { strict: !isArray, performActionPreChecks: false, __patchrightSkipRetryLogWaiting: true }, action, "returnAll"));
1354
- }
1355
- } else {
1356
- const world = options.expression === "to.have.property" ? "main" : "utility";
1357
- const context = await race(this._context(world));
1358
- const injected = await race(context.injectedScript());
1359
- var { matches, received, missingReceived } = await race(injected.evaluate(async (injected2, { options: options2, callId }) => {
1360
- return { ...await injected2.expect(void 0, options2, []) };
1361
- }, { options, callId: progress.metadata.id }));
1362
- }
1196
+ const selectorInFrame = selector ? await race(this.selectors.resolveFrameForSelector(selector, { strict: true })) : void 0;
1197
+ const { frame, info } = selectorInFrame || { frame: this, info: void 0 };
1198
+ const world = options.expression === "to.have.property" ? "main" : info?.world ?? "utility";
1199
+ const context = await race(frame._context(world));
1200
+ const injected = await race(context.injectedScript());
1201
+ const { log, matches, received, missingReceived } = await race(injected.evaluate(async (injected2, { info: info2, options: options2, callId }) => {
1202
+ const elements = info2 ? injected2.querySelectorAll(info2.parsed, document) : [];
1203
+ if (callId)
1204
+ injected2.markTargetElements(new Set(elements), callId);
1205
+ const isArray = options2.expression === "to.have.count" || options2.expression.endsWith(".array");
1206
+ let log2 = "";
1207
+ if (isArray)
1208
+ log2 = ` locator resolved to ${elements.length} element${elements.length === 1 ? "" : "s"}`;
1209
+ else if (elements.length > 1)
1210
+ throw injected2.strictModeViolationError(info2.parsed, elements);
1211
+ else if (elements.length)
1212
+ log2 = ` locator resolved to ${injected2.previewNode(elements[0])}`;
1213
+ if (info2)
1214
+ injected2.checkDeprecatedSelectorUsage(info2.parsed, elements);
1215
+ return { log: log2, ...await injected2.expect(elements[0], options2, elements) };
1216
+ }, { info, options, callId: progress.metadata.id }));
1363
1217
  if (log)
1364
1218
  progress.log(log);
1365
1219
  if (matches === options.isNot) {
@@ -1370,11 +1224,8 @@ class Frame extends import_instrumentation.SdkObject {
1370
1224
  lastIntermediateResult.received = received;
1371
1225
  }
1372
1226
  lastIntermediateResult.isSet = true;
1373
- if (!missingReceived) {
1374
- const rendered = renderUnexpectedValue(options.expression, received);
1375
- if (rendered !== void 0)
1376
- progress.log(' unexpected value "' + rendered + '"');
1377
- }
1227
+ if (!missingReceived && !Array.isArray(received))
1228
+ progress.log(` unexpected value "${renderUnexpectedValue(options.expression, received)}"`);
1378
1229
  }
1379
1230
  return { matches, received };
1380
1231
  }
@@ -1430,7 +1281,7 @@ class Frame extends import_instrumentation.SdkObject {
1430
1281
  return { result, abort: () => aborted = true };
1431
1282
  }, { expression, isFunction, polling: options.pollingInterval, arg }));
1432
1283
  try {
1433
- return await progress.race(this._detachedScope.race(handle.evaluateHandle((h) => h.result)));
1284
+ return await progress.race(handle.evaluateHandle((h) => h.result));
1434
1285
  } catch (error) {
1435
1286
  await handle.evaluate((h) => h.abort()).catch(() => {
1436
1287
  });
@@ -1451,8 +1302,17 @@ class Frame extends import_instrumentation.SdkObject {
1451
1302
  return JSON.parse(handle.rawValue());
1452
1303
  }
1453
1304
  async title() {
1454
- const context = await this._utilityContext();
1455
- return context.evaluate(() => document.title);
1305
+ try {
1306
+ return await this.raceAgainstEvaluationStallingEvents(async () => {
1307
+ const context = await this._utilityContext();
1308
+ return await context.evaluate(() => document.title);
1309
+ });
1310
+ } catch {
1311
+ const url = this.pendingDocument()?.request?.url();
1312
+ if (url)
1313
+ return `Loading ${url}`;
1314
+ return "";
1315
+ }
1456
1316
  }
1457
1317
  async rafrafTimeout(progress, timeout) {
1458
1318
  if (timeout === 0)
@@ -1476,112 +1336,33 @@ class Frame extends import_instrumentation.SdkObject {
1476
1336
  data.context.contextDestroyed("Frame was detached");
1477
1337
  data.contextPromise.resolve({ destroyedReason: "Frame was detached" });
1478
1338
  }
1479
- if (this._mainWorld)
1480
- this._mainWorld.contextDestroyed("Frame was detached");
1481
- if (this._iframeWorld)
1482
- this._iframeWorld.contextDestroyed("Frame was detached");
1483
- if (this._isolatedWorld)
1484
- this._isolatedWorld.contextDestroyed("Frame was detached");
1485
1339
  if (this._parentFrame)
1486
1340
  this._parentFrame._childFrames.delete(this);
1487
1341
  this._parentFrame = null;
1488
1342
  }
1489
1343
  async _callOnElementOnceMatches(progress, selector, body, taskData, options, scope) {
1490
1344
  const callbackText = body.toString();
1491
- progress.log("waiting for " + this._asLocator(selector));
1492
- var promise;
1493
- if (selector === ":scope") {
1494
- const scopeParentNode = scope.parentNode || scope;
1495
- if (scopeParentNode.constructor.name == "ElementHandle") {
1496
- if (options?.mainWorld) {
1497
- promise = (async () => {
1498
- const mainContext = await this._mainContext();
1499
- const adoptedScope = await this._page.delegate.adoptElementHandle(scope, mainContext);
1500
- try {
1501
- return await mainContext.evaluate(([injected, node, { callbackText: callbackText2, scope: handle2, taskData: taskData2 }]) => {
1502
- const callback = injected.eval(callbackText2);
1503
- return callback(injected, handle2, taskData2);
1504
- }, [
1505
- await mainContext.injectedScript(),
1506
- adoptedScope,
1507
- { callbackText, scope: adoptedScope, taskData }
1508
- ]);
1509
- } finally {
1510
- adoptedScope.dispose();
1511
- }
1512
- })();
1513
- } else {
1514
- promise = scopeParentNode.evaluateInUtility(([injected, node, { callbackText: callbackText2, scope: handle2, taskData: taskData2 }]) => {
1515
- const callback = injected.eval(callbackText2);
1516
- return callback(injected, handle2, taskData2);
1517
- }, {
1518
- callbackText,
1519
- scope,
1520
- taskData
1521
- });
1522
- }
1523
- } else {
1524
- promise = scopeParentNode.evaluate((injected, { callbackText: callbackText2, scope: handle2, taskData: taskData2 }) => {
1525
- const callback = injected.eval(callbackText2);
1526
- return callback(injected, handle2, taskData2);
1527
- }, {
1528
- callbackText,
1529
- scope,
1530
- taskData
1531
- });
1532
- }
1533
- } else {
1534
- promise = this._retryWithProgressIfNotConnected(progress, selector, { ...options, performActionPreChecks: false }, async (handle) => {
1535
- if (handle.parentNode.constructor.name == "ElementHandle") {
1536
- if (options?.mainWorld) {
1537
- const mainContext = await handle._frame._mainContext();
1538
- const adoptedHandle = await this._page.delegate.adoptElementHandle(handle, mainContext);
1539
- try {
1540
- return await mainContext.evaluate(([injected, node, { callbackText: callbackText2, handle: handle2, taskData: taskData2 }]) => {
1541
- const callback = injected.eval(callbackText2);
1542
- return callback(injected, handle2, taskData2);
1543
- }, [
1544
- await mainContext.injectedScript(),
1545
- adoptedHandle,
1546
- { callbackText, handle: adoptedHandle, taskData }
1547
- ]);
1548
- } finally {
1549
- adoptedHandle.dispose();
1550
- }
1551
- }
1552
- const [taskScope] = Object.values(taskData?.eventInit ?? {});
1553
- if (taskScope) {
1554
- const taskScopeContext = taskScope._context;
1555
- const adoptedHandle = await handle._adoptTo(taskScopeContext);
1556
- return await taskScopeContext.evaluate(([injected, node, { callbackText: callbackText2, adoptedHandle: handle2, taskData: taskData2 }]) => {
1557
- const callback = injected.eval(callbackText2);
1558
- return callback(injected, handle2, taskData2);
1559
- }, [
1560
- await taskScopeContext.injectedScript(),
1561
- adoptedHandle,
1562
- { callbackText, adoptedHandle, taskData }
1563
- ]);
1564
- }
1565
- return await handle.parentNode.evaluateInUtility(([injected, node, { callbackText: callbackText2, handle: handle2, taskData: taskData2 }]) => {
1566
- const callback = injected.eval(callbackText2);
1567
- return callback(injected, handle2, taskData2);
1568
- }, {
1569
- callbackText,
1570
- handle,
1571
- taskData
1572
- });
1573
- } else {
1574
- return await handle.parentNode.evaluate((injected, { callbackText: callbackText2, handle: handle2, taskData: taskData2 }) => {
1575
- const callback = injected.eval(callbackText2);
1576
- return callback(injected, handle2, taskData2);
1577
- }, {
1578
- callbackText,
1579
- handle,
1580
- taskData
1581
- });
1582
- }
1583
- });
1584
- }
1345
+ progress.log(`waiting for ${this._asLocator(selector)}`);
1346
+ const promise = this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling) => {
1347
+ const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector, options, scope));
1348
+ if (!resolved)
1349
+ return continuePolling;
1350
+ const { log, success, value } = await progress.race(resolved.injected.evaluate((injected, { info, callbackText: callbackText2, taskData: taskData2, callId, root }) => {
1351
+ const callback = injected.eval(callbackText2);
1352
+ const element = injected.querySelector(info.parsed, root || document, info.strict);
1353
+ if (!element)
1354
+ return { success: false };
1355
+ const log2 = ` locator resolved to ${injected.previewNode(element)}`;
1356
+ if (callId)
1357
+ injected.markTargetElements(/* @__PURE__ */ new Set([element]), callId);
1358
+ return { log: log2, success: true, value: callback(injected, element, taskData2) };
1359
+ }, { info: resolved.info, callbackText, taskData, callId: progress.metadata.id, root: resolved.frame === this ? scope : void 0 }));
1360
+ if (log)
1361
+ progress.log(log);
1362
+ if (!success)
1363
+ return continuePolling;
1364
+ return value;
1365
+ });
1585
1366
  return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
1586
1367
  }
1587
1368
  _setContext(world, context) {
@@ -1631,266 +1412,32 @@ class Frame extends import_instrumentation.SdkObject {
1631
1412
  injectedScript.extend(source2, arg2);
1632
1413
  }, { source, arg });
1633
1414
  }
1634
- _asLocator(selector) {
1635
- return (0, import_utils.asLocator)(this._page.browserContext._browser.sdkLanguage(), selector);
1636
- }
1637
- async _getFrameMainFrameContextId(client) {
1638
- try {
1639
- var globalDocument = await client._sendMayFail("DOM.getFrameOwner", { frameId: this._id });
1640
- if (globalDocument && globalDocument.nodeId) {
1641
- var describedNode = await client._sendMayFail("DOM.describeNode", {
1642
- backendNodeId: globalDocument.backendNodeId
1643
- });
1644
- if (describedNode && describedNode.node.contentDocument) {
1645
- var resolvedNode = await client._sendMayFail("DOM.resolveNode", {
1646
- backendNodeId: describedNode.node.contentDocument.backendNodeId
1647
- });
1648
- if (resolvedNode && resolvedNode.object && resolvedNode.object.objectId) {
1649
- var _executionContextId = parseInt(resolvedNode.object.objectId.split(".")[1], 10);
1650
- return _executionContextId;
1651
- }
1652
- }
1653
- }
1654
- } catch (e) {
1655
- }
1656
- return 0;
1657
- }
1658
- async _retryWithoutProgress(progress, selector, options, action, returnAction, continuePolling) {
1659
- if (options.performActionPreChecks) await this._page.performActionPreChecks(progress);
1660
- const resolved = await this.selectors.resolveInjectedForSelector(selector, { strict: options.strict }, options.__patchrightInitialScope);
1661
- if (!resolved) {
1662
- if (returnAction === "returnOnNotResolved" || returnAction === "returnAll") {
1663
- const result2 = await action(null);
1664
- return result2 === "internal:continuepolling" ? continuePolling : result2;
1665
- }
1666
- return continuePolling;
1667
- }
1668
- try {
1669
- var client = this._page.delegate._sessionForFrame(resolved.frame)._client;
1670
- } catch (e) {
1671
- var client = this._page.delegate._mainFrameSession._client;
1672
- }
1673
- var utilityContext = await resolved.frame._utilityContext();
1674
- var mainContext = await resolved.frame._mainContext();
1675
- const documentNode = await client._sendMayFail("Runtime.evaluate", {
1676
- expression: "document",
1677
- serializationOptions: {
1678
- serialization: "idOnly"
1679
- },
1680
- contextId: utilityContext.delegate._contextId
1681
- });
1682
- if (!documentNode) return continuePolling;
1683
- let documentScope = new dom.ElementHandle(utilityContext, documentNode.result.objectId);
1684
- let initialScope = documentScope;
1685
- if (resolved.scope) {
1686
- const scopeBackendNodeId = resolved.scope._objectId ? (await client._sendMayFail("DOM.describeNode", { objectId: resolved.scope._objectId }))?.node?.backendNodeId : null;
1687
- if (scopeBackendNodeId) {
1688
- const scopeInUtility = await client._sendMayFail("DOM.resolveNode", { backendNodeId: scopeBackendNodeId, executionContextId: utilityContext.delegate._contextId });
1689
- if (scopeInUtility?.object?.objectId)
1690
- initialScope = new dom.ElementHandle(utilityContext, scopeInUtility.object.objectId);
1691
- }
1692
- }
1693
- progress.__patchrightInitialScope = resolved.scope;
1694
- const parsedSnapshot = options.__patchrightWaitForSelector ? JSON.parse(JSON.stringify(resolved.info.parsed)) : null;
1695
- let currentScopingElements;
1696
- try {
1697
- currentScopingElements = await this._customFindElementsByParsed(resolved, client, mainContext, initialScope, progress, resolved.info.parsed);
1698
- } catch (e) {
1699
- if ("JSHandles can be evaluated only in the context they were created!" === e.message) return continuePolling;
1700
- if (e instanceof TypeError && e.message.includes("is not a function")) return continuePolling;
1701
- await progress.race(resolved.injected.evaluateHandle((injected, { error }) => {
1702
- throw error;
1703
- }, { error: e }));
1704
- }
1705
- if (currentScopingElements.length == 0) {
1706
- if (options.__testHookNoAutoWaiting || options.noAutoWaiting)
1707
- throw new dom.NonRecoverableDOMError("Element(s) not found");
1708
- if (parsedSnapshot && (returnAction === "returnOnNotResolved" || returnAction === "returnAll")) {
1709
- const elementCount = await resolved.injected.evaluate((injected, { parsed }) => {
1710
- return injected.querySelectorAll(parsed, document).length;
1711
- }, { parsed: parsedSnapshot }).catch(() => 0);
1712
- if (elementCount > 0)
1713
- return continuePolling;
1714
- }
1715
- if (returnAction === "returnOnNotResolved" || returnAction === "returnAll") {
1716
- const result2 = await action(null);
1717
- return result2 === "internal:continuepolling" ? continuePolling : result2;
1718
- }
1719
- return continuePolling;
1720
- }
1721
- const resultElement = currentScopingElements[0];
1722
- await resultElement._initializePreview().catch(() => {
1723
- });
1724
- let visibilityQualifier = "";
1725
- if (options && options.__patchrightWaitForSelector) {
1726
- visibilityQualifier = await resultElement.evaluateInUtility(([injected, node]) => injected.utils.isElementVisible(node) ? "visible" : "hidden", {}).catch(() => "");
1727
- }
1728
- if (currentScopingElements.length > 1) {
1729
- if (resolved.info.strict) {
1730
- await progress.race(resolved.injected.evaluateHandle((injected, {
1731
- info,
1732
- elements
1733
- }) => {
1734
- throw injected.strictModeViolationError(info.parsed, elements);
1735
- }, {
1736
- info: resolved.info,
1737
- elements: currentScopingElements
1738
- }));
1739
- }
1740
- progress.log(" locator resolved to " + currentScopingElements.length + " elements. Proceeding with the first one: " + resultElement.preview());
1741
- } else if (resultElement) {
1742
- progress.log(" locator resolved to " + (visibilityQualifier ? visibilityQualifier + " " : "") + resultElement.preview().replace("JSHandle@", ""));
1415
+ async ariaSnapshot(progress, options = {}) {
1416
+ if (options.selector && options.track)
1417
+ throw new Error("Cannot specify both selector and track options");
1418
+ if (options.selector && options.mode !== "ai") {
1419
+ const snapshot2 = await this._retryWithProgressIfNotConnected(progress, options.selector, { strict: true, performActionPreChecks: true }, async (handle) => {
1420
+ return await progress.race(handle.evaluateInUtility(([injected, element, opts]) => injected.ariaSnapshot(element, opts), { mode: "default", depth: options.depth }));
1421
+ });
1422
+ return { snapshot: snapshot2 };
1743
1423
  }
1744
- try {
1745
- var result = null;
1746
- if (returnAction === "returnAll") {
1747
- result = await action([resultElement, currentScopingElements]);
1748
- } else {
1749
- result = await action(resultElement);
1750
- }
1751
- if (result === "error:notconnected") {
1752
- progress.log("element was detached from the DOM, retrying");
1753
- return continuePolling;
1754
- } else if (result === "internal:continuepolling") {
1755
- return continuePolling;
1756
- }
1757
- if (parsedSnapshot && result === null && (options.state === "hidden" || options.state === "detached")) {
1758
- const visibleCount = await resolved.injected.evaluate((injected, { parsed }) => {
1759
- const elements = injected.querySelectorAll(parsed, document);
1760
- return elements.filter((e) => injected.utils.isElementVisible(e)).length;
1761
- }, { parsed: parsedSnapshot }).catch(() => 0);
1762
- if (visibleCount > 0)
1763
- return continuePolling;
1764
- }
1765
- return result;
1766
- } finally {
1424
+ let targetFrame;
1425
+ let info;
1426
+ if (options.selector) {
1427
+ const resolved = await this.selectors.resolveInjectedForSelector(options.selector, { strict: true });
1428
+ if (!resolved)
1429
+ throw new Error(`Selector "${options.selector}" did not resolve to any element`);
1430
+ targetFrame = resolved.frame;
1431
+ info = resolved.info;
1432
+ } else {
1433
+ targetFrame = this;
1767
1434
  }
1435
+ const result = await (0, import_page.ariaSnapshotForFrame)(progress, targetFrame, { ...options, info });
1436
+ const snapshot = options.track && result.incremental ? result.incremental.join("\n") : result.full.join("\n");
1437
+ return { snapshot };
1768
1438
  }
1769
- async _customFindElementsByParsed(resolved, client, context, documentScope, progress, parsed) {
1770
- var parsedEdits = { ...parsed };
1771
- var currentScopingElements = [documentScope];
1772
- while (parsed.parts.length > 0) {
1773
- var part = parsed.parts.shift();
1774
- parsedEdits.parts = [part];
1775
- var elements = [];
1776
- var elementsIndexes = [];
1777
- if (part.name == "nth") {
1778
- const partNth = Number(part.body);
1779
- if (currentScopingElements.length == 0) return [];
1780
- if (partNth > currentScopingElements.length - 1 || partNth < -(currentScopingElements.length - 1)) {
1781
- if (parsed.capture !== void 0) throw new Error("Can't query n-th element in a request with the capture.");
1782
- return [];
1783
- } else {
1784
- currentScopingElements = [currentScopingElements.at(partNth)];
1785
- continue;
1786
- }
1787
- } else if (part.name == "internal:or") {
1788
- var orredElements = await this._customFindElementsByParsed(resolved, client, context, documentScope, progress, part.body.parsed);
1789
- elements = currentScopingElements.concat(orredElements);
1790
- } else if (part.name == "internal:and") {
1791
- var andedElements = await this._customFindElementsByParsed(resolved, client, context, documentScope, progress, part.body.parsed);
1792
- const backendNodeIds = new Set(andedElements.map((item) => item.backendNodeId));
1793
- elements = currentScopingElements.filter((item) => backendNodeIds.has(item.backendNodeId));
1794
- } else {
1795
- for (const scope of currentScopingElements) {
1796
- let findClosedShadowRoots2 = function(node, results = []) {
1797
- if (!node || typeof node !== "object") return results;
1798
- if (node.shadowRoots && Array.isArray(node.shadowRoots)) {
1799
- for (const shadowRoot2 of node.shadowRoots) {
1800
- if (shadowRoot2.shadowRootType === "closed" && shadowRoot2.backendNodeId) {
1801
- results.push(shadowRoot2.backendNodeId);
1802
- }
1803
- findClosedShadowRoots2(shadowRoot2, results);
1804
- }
1805
- }
1806
- if (node.nodeName !== "IFRAME" && node.children && Array.isArray(node.children)) {
1807
- for (const child of node.children) {
1808
- findClosedShadowRoots2(child, results);
1809
- }
1810
- }
1811
- return results;
1812
- };
1813
- var findClosedShadowRoots = findClosedShadowRoots2;
1814
- const describedScope = await client.send("DOM.describeNode", {
1815
- objectId: scope._objectId,
1816
- depth: -1,
1817
- pierce: true
1818
- });
1819
- var queryingElements = [];
1820
- var shadowRootBackendIds = findClosedShadowRoots2(describedScope.node);
1821
- var shadowRoots = [];
1822
- for (var shadowRootBackendId of shadowRootBackendIds) {
1823
- var resolvedShadowRoot = await client.send("DOM.resolveNode", {
1824
- backendNodeId: shadowRootBackendId,
1825
- contextId: context.delegate._contextId
1826
- });
1827
- shadowRoots.push(new dom.ElementHandle(context, resolvedShadowRoot.object.objectId));
1828
- }
1829
- for (var shadowRoot of shadowRoots) {
1830
- const shadowElements = await shadowRoot.evaluateHandleInUtility(([injected, node, { parsed: parsed2, callId }]) => {
1831
- const elements2 = injected.querySelectorAll(parsed2, node);
1832
- if (callId) injected.markTargetElements(new Set(elements2), callId);
1833
- return elements2;
1834
- }, {
1835
- parsed: parsedEdits,
1836
- callId: progress.metadata.id
1837
- });
1838
- const shadowElementsAmount = await shadowElements.getProperty("length");
1839
- queryingElements.push([shadowElements, shadowElementsAmount, shadowRoot]);
1840
- }
1841
- const rootElements = await scope.evaluateHandleInUtility(([injected, node, { parsed: parsed2, callId }]) => {
1842
- const elements2 = injected.querySelectorAll(parsed2, node);
1843
- if (callId) injected.markTargetElements(new Set(elements2), callId);
1844
- return elements2;
1845
- }, {
1846
- parsed: parsedEdits,
1847
- callId: progress.metadata.id
1848
- });
1849
- const rootElementsAmount = await rootElements.getProperty("length");
1850
- queryingElements.push([rootElements, rootElementsAmount, scope]);
1851
- for (var queryedElement of queryingElements) {
1852
- var elementsToCheck = queryedElement[0];
1853
- var elementsAmount = await queryedElement[1].jsonValue();
1854
- var parentNode = queryedElement[2];
1855
- for (var i = 0; i < elementsAmount; i++) {
1856
- if (parentNode.constructor.name == "ElementHandle") {
1857
- var elementToCheck = await parentNode.evaluateHandleInUtility(([injected, node, { index, elementsToCheck: elementsToCheck2 }]) => {
1858
- return elementsToCheck2[index];
1859
- }, { index: i, elementsToCheck });
1860
- } else {
1861
- var elementToCheck = await parentNode.evaluateHandle((injected, { index, elementsToCheck: elementsToCheck2 }) => {
1862
- return elementsToCheck2[index];
1863
- }, { index: i, elementsToCheck });
1864
- }
1865
- elementToCheck.parentNode = parentNode;
1866
- var resolvedElement = await client.send("DOM.describeNode", {
1867
- objectId: elementToCheck._objectId,
1868
- depth: -1
1869
- });
1870
- elementToCheck.backendNodeId = resolvedElement.node.backendNodeId;
1871
- elementToCheck.nodePosition = this.selectors._findElementPositionInDomTree(elementToCheck, describedScope.node, context, "");
1872
- elements.push(elementToCheck);
1873
- }
1874
- }
1875
- }
1876
- }
1877
- const getParts = (pos) => (pos || "").split(".").filter(Boolean).map(Number);
1878
- elements.sort((a, b) => {
1879
- const partA = getParts(a.nodePosition);
1880
- const partB = getParts(b.nodePosition);
1881
- const maxLength = Math.max(partA.length, partB.length);
1882
- for (let i2 = 0; i2 < maxLength; i2++) {
1883
- const aVal = partA[i2] ?? -1;
1884
- const bVal = partB[i2] ?? -1;
1885
- if (aVal !== bVal) return aVal - bVal;
1886
- }
1887
- return 0;
1888
- });
1889
- currentScopingElements = Array.from(
1890
- new Map(elements.map((e) => [e.backendNodeId, e])).values()
1891
- );
1892
- }
1893
- return currentScopingElements;
1439
+ _asLocator(selector) {
1440
+ return (0, import_utils.asLocator)(this._page.browserContext._browser.sdkLanguage(), selector);
1894
1441
  }
1895
1442
  }
1896
1443
  class SignalBarrier {