patchright-core 1.57.0 → 1.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (307) hide show
  1. package/ThirdPartyNotices.txt +2688 -297
  2. package/browsers.json +23 -22
  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 +48 -413
  8. package/lib/client/android.js +4 -4
  9. package/lib/client/api.js +3 -0
  10. package/lib/client/browser.js +11 -5
  11. package/lib/client/browserContext.js +20 -23
  12. package/lib/client/browserType.js +23 -54
  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 -0
  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 -1
  25. package/lib/client/events.js +3 -0
  26. package/lib/client/fetch.js +2 -4
  27. package/lib/client/frame.js +9 -13
  28. package/lib/client/harRouter.js +13 -1
  29. package/lib/client/jsHandle.js +4 -8
  30. package/lib/client/locator.js +13 -36
  31. package/lib/client/network.js +14 -11
  32. package/lib/client/page.js +44 -50
  33. package/lib/client/screencast.js +88 -0
  34. package/lib/client/selectors.js +3 -1
  35. package/lib/client/tracing.js +11 -5
  36. package/lib/client/video.js +13 -20
  37. package/lib/client/worker.js +6 -6
  38. package/lib/generated/bindingsControllerSource.js +1 -1
  39. package/lib/generated/clockSource.js +1 -1
  40. package/lib/generated/injectedScriptSource.js +1 -1
  41. package/lib/generated/pollingRecorderSource.js +1 -1
  42. package/lib/generated/storageScriptSource.js +1 -1
  43. package/lib/generated/utilityScriptSource.js +1 -1
  44. package/lib/mcpBundle.js +78 -0
  45. package/lib/mcpBundleImpl.js +91 -0
  46. package/lib/protocol/serializers.js +5 -0
  47. package/lib/protocol/validator.js +228 -58
  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 +14 -10
  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/artifact.js +1 -1
  56. package/lib/server/bidi/bidiBrowser.js +80 -14
  57. package/lib/server/bidi/bidiChromium.js +23 -14
  58. package/lib/server/bidi/bidiConnection.js +1 -0
  59. package/lib/server/bidi/bidiDeserializer.js +116 -0
  60. package/lib/server/bidi/bidiExecutionContext.js +75 -29
  61. package/lib/server/bidi/bidiFirefox.js +6 -8
  62. package/lib/server/bidi/bidiNetworkManager.js +40 -12
  63. package/lib/server/bidi/bidiPage.js +67 -40
  64. package/lib/server/bidi/third_party/bidiProtocolCore.js +1 -0
  65. package/lib/server/bidi/third_party/firefoxPrefs.js +3 -1
  66. package/lib/server/browser.js +84 -21
  67. package/lib/server/browserContext.js +137 -77
  68. package/lib/server/browserType.js +26 -16
  69. package/lib/server/chromium/chromium.js +28 -31
  70. package/lib/server/chromium/chromiumSwitches.js +16 -4
  71. package/lib/server/chromium/crBrowser.js +40 -27
  72. package/lib/server/chromium/crConnection.js +0 -5
  73. package/lib/server/chromium/crDevTools.js +1 -2
  74. package/lib/server/chromium/crNetworkManager.js +54 -229
  75. package/lib/server/chromium/crPage.js +74 -260
  76. package/lib/server/chromium/crServiceWorker.js +7 -14
  77. package/lib/server/clock.js +33 -41
  78. package/lib/server/codegen/javascript.js +6 -29
  79. package/lib/server/console.js +5 -1
  80. package/lib/server/debugController.js +12 -6
  81. package/lib/server/debugger.js +40 -47
  82. package/lib/server/deviceDescriptorsSource.json +137 -137
  83. package/lib/server/dispatchers/browserContextDispatcher.js +30 -30
  84. package/lib/server/dispatchers/browserDispatcher.js +11 -5
  85. package/lib/server/dispatchers/browserTypeDispatcher.js +7 -0
  86. package/lib/server/dispatchers/cdpSessionDispatcher.js +4 -1
  87. package/lib/server/dispatchers/debuggerDispatcher.js +84 -0
  88. package/lib/server/dispatchers/dispatcher.js +7 -14
  89. package/lib/server/dispatchers/disposableDispatcher.js +39 -0
  90. package/lib/server/dispatchers/electronDispatcher.js +2 -1
  91. package/lib/server/dispatchers/frameDispatcher.js +7 -7
  92. package/lib/server/dispatchers/localUtilsDispatcher.js +37 -1
  93. package/lib/server/dispatchers/networkDispatchers.js +6 -5
  94. package/lib/server/dispatchers/pageDispatcher.js +101 -34
  95. package/lib/server/dispatchers/webSocketRouteDispatcher.js +4 -5
  96. package/lib/server/disposable.js +41 -0
  97. package/lib/server/dom.js +56 -29
  98. package/lib/server/download.js +3 -2
  99. package/lib/server/electron/electron.js +17 -9
  100. package/lib/server/firefox/ffBrowser.js +9 -29
  101. package/lib/server/firefox/ffConnection.js +0 -5
  102. package/lib/server/firefox/ffInput.js +21 -5
  103. package/lib/server/firefox/ffNetworkManager.js +4 -4
  104. package/lib/server/firefox/ffPage.js +27 -33
  105. package/lib/server/firefox/firefox.js +6 -8
  106. package/lib/server/frameSelectors.js +14 -169
  107. package/lib/server/frames.js +263 -551
  108. package/lib/server/har/harRecorder.js +2 -2
  109. package/lib/server/har/harTracer.js +5 -4
  110. package/lib/server/input.js +49 -4
  111. package/lib/server/instrumentation.js +8 -0
  112. package/lib/server/javascript.js +6 -22
  113. package/lib/server/launchApp.js +0 -1
  114. package/lib/server/localUtils.js +6 -6
  115. package/lib/server/network.js +59 -20
  116. package/lib/server/overlay.js +138 -0
  117. package/lib/server/page.js +179 -157
  118. package/lib/server/progress.js +32 -6
  119. package/lib/server/recorder/recorderApp.js +84 -104
  120. package/lib/server/recorder.js +76 -40
  121. package/lib/server/registry/browserFetcher.js +6 -4
  122. package/lib/server/registry/index.js +222 -226
  123. package/lib/server/registry/nativeDeps.js +1 -0
  124. package/lib/server/registry/oopDownloadBrowserMain.js +3 -0
  125. package/lib/server/screencast.js +137 -0
  126. package/lib/server/trace/recorder/snapshotter.js +2 -2
  127. package/lib/server/trace/recorder/snapshotterInjected.js +21 -1
  128. package/lib/server/trace/recorder/tracing.js +98 -47
  129. package/lib/server/trace/viewer/traceViewer.js +24 -21
  130. package/lib/server/usKeyboardLayout.js +7 -0
  131. package/lib/server/utils/comparators.js +1 -1
  132. package/lib/server/utils/disposable.js +32 -0
  133. package/lib/server/utils/eventsHelper.js +3 -1
  134. package/lib/server/utils/expectUtils.js +87 -2
  135. package/lib/server/utils/fileUtils.js +16 -2
  136. package/lib/server/utils/happyEyeballs.js +15 -12
  137. package/lib/server/utils/httpServer.js +10 -23
  138. package/lib/server/utils/network.js +39 -29
  139. package/lib/server/utils/processLauncher.js +8 -6
  140. package/lib/server/utils/zipFile.js +2 -2
  141. package/lib/server/videoRecorder.js +194 -0
  142. package/lib/server/webkit/webkit.js +4 -6
  143. package/lib/server/webkit/wkBrowser.js +1 -10
  144. package/lib/server/webkit/wkConnection.js +1 -6
  145. package/lib/server/webkit/wkInterceptableRequest.js +29 -1
  146. package/lib/server/webkit/wkPage.js +88 -57
  147. package/lib/server/webkit/wkWorkers.js +2 -1
  148. package/lib/serverRegistry.js +156 -0
  149. package/lib/tools/backend/browserBackend.js +79 -0
  150. package/lib/tools/backend/common.js +63 -0
  151. package/lib/tools/backend/config.js +41 -0
  152. package/lib/tools/backend/console.js +66 -0
  153. package/lib/tools/backend/context.js +296 -0
  154. package/lib/tools/backend/cookies.js +152 -0
  155. package/lib/tools/backend/devtools.js +69 -0
  156. package/lib/tools/backend/dialogs.js +59 -0
  157. package/lib/tools/backend/evaluate.js +64 -0
  158. package/lib/tools/backend/files.js +60 -0
  159. package/lib/tools/backend/form.js +64 -0
  160. package/lib/tools/backend/keyboard.js +155 -0
  161. package/lib/tools/backend/logFile.js +95 -0
  162. package/lib/tools/backend/mouse.js +168 -0
  163. package/lib/tools/backend/navigate.js +106 -0
  164. package/lib/tools/backend/network.js +135 -0
  165. package/lib/tools/backend/pdf.js +48 -0
  166. package/lib/tools/backend/response.js +305 -0
  167. package/lib/tools/backend/route.js +140 -0
  168. package/lib/tools/backend/runCode.js +77 -0
  169. package/lib/tools/backend/screenshot.js +88 -0
  170. package/lib/tools/backend/sessionLog.js +74 -0
  171. package/lib/tools/backend/snapshot.js +208 -0
  172. package/lib/tools/backend/storage.js +68 -0
  173. package/lib/tools/backend/tab.js +445 -0
  174. package/lib/tools/backend/tabs.js +67 -0
  175. package/lib/tools/backend/tool.js +47 -0
  176. package/lib/tools/backend/tools.js +102 -0
  177. package/lib/tools/backend/tracing.js +78 -0
  178. package/lib/tools/backend/utils.js +83 -0
  179. package/lib/tools/backend/verify.js +151 -0
  180. package/lib/tools/backend/video.js +98 -0
  181. package/lib/tools/backend/wait.js +63 -0
  182. package/lib/tools/backend/webstorage.js +223 -0
  183. package/lib/tools/cli-client/cli.js +6 -0
  184. package/lib/tools/cli-client/help.json +399 -0
  185. package/lib/tools/cli-client/minimist.js +128 -0
  186. package/lib/tools/cli-client/program.js +350 -0
  187. package/lib/tools/cli-client/registry.js +176 -0
  188. package/lib/tools/cli-client/session.js +289 -0
  189. package/lib/tools/cli-client/skill/SKILL.md +328 -0
  190. package/lib/tools/cli-client/skill/references/element-attributes.md +23 -0
  191. package/lib/tools/cli-client/skill/references/playwright-tests.md +39 -0
  192. package/lib/tools/cli-client/skill/references/request-mocking.md +87 -0
  193. package/lib/tools/cli-client/skill/references/running-code.md +231 -0
  194. package/lib/tools/cli-client/skill/references/session-management.md +169 -0
  195. package/lib/tools/cli-client/skill/references/storage-state.md +275 -0
  196. package/lib/tools/cli-client/skill/references/test-generation.md +88 -0
  197. package/lib/tools/cli-client/skill/references/tracing.md +139 -0
  198. package/lib/tools/cli-client/skill/references/video-recording.md +143 -0
  199. package/lib/tools/cli-daemon/command.js +73 -0
  200. package/lib/tools/cli-daemon/commands.js +956 -0
  201. package/lib/tools/cli-daemon/daemon.js +157 -0
  202. package/lib/tools/cli-daemon/helpGenerator.js +177 -0
  203. package/lib/tools/cli-daemon/program.js +129 -0
  204. package/lib/tools/dashboard/appIcon.png +0 -0
  205. package/lib/tools/dashboard/dashboardApp.js +284 -0
  206. package/lib/tools/dashboard/dashboardController.js +296 -0
  207. package/lib/tools/exports.js +60 -0
  208. package/lib/tools/mcp/browserFactory.js +233 -0
  209. package/lib/tools/mcp/cdpRelay.js +352 -0
  210. package/lib/tools/mcp/cli-stub.js +7 -0
  211. package/lib/tools/mcp/config.d.js +16 -0
  212. package/lib/tools/mcp/config.js +446 -0
  213. package/lib/tools/mcp/configIni.js +189 -0
  214. package/lib/tools/mcp/extensionContextFactory.js +55 -0
  215. package/lib/tools/mcp/index.js +62 -0
  216. package/lib/tools/mcp/log.js +35 -0
  217. package/lib/tools/mcp/program.js +107 -0
  218. package/lib/tools/mcp/protocol.js +28 -0
  219. package/lib/tools/mcp/watchdog.js +44 -0
  220. package/lib/tools/trace/SKILL.md +171 -0
  221. package/lib/tools/trace/installSkill.js +48 -0
  222. package/lib/tools/trace/traceActions.js +142 -0
  223. package/lib/tools/trace/traceAttachments.js +69 -0
  224. package/lib/tools/trace/traceCli.js +87 -0
  225. package/lib/tools/trace/traceConsole.js +97 -0
  226. package/lib/tools/trace/traceErrors.js +55 -0
  227. package/lib/tools/trace/traceOpen.js +69 -0
  228. package/lib/tools/trace/traceParser.js +96 -0
  229. package/lib/tools/trace/traceRequests.js +182 -0
  230. package/lib/tools/trace/traceScreenshot.js +68 -0
  231. package/lib/tools/trace/traceSnapshot.js +149 -0
  232. package/lib/tools/trace/traceUtils.js +153 -0
  233. package/lib/tools/utils/connect.js +32 -0
  234. package/lib/tools/utils/mcp/http.js +152 -0
  235. package/lib/tools/utils/mcp/server.js +230 -0
  236. package/lib/tools/utils/mcp/tool.js +47 -0
  237. package/lib/tools/utils/socketConnection.js +108 -0
  238. package/lib/utils/isomorphic/ariaSnapshot.js +60 -2
  239. package/lib/utils/isomorphic/formatUtils.js +64 -0
  240. package/lib/utils/isomorphic/jsonSchema.js +89 -0
  241. package/lib/utils/isomorphic/lruCache.js +51 -0
  242. package/lib/utils/isomorphic/mimeType.js +7 -2
  243. package/lib/utils/isomorphic/protocolFormatter.js +2 -2
  244. package/lib/utils/isomorphic/protocolMetainfo.js +127 -98
  245. package/lib/utils/isomorphic/stringUtils.js +49 -0
  246. package/lib/utils/isomorphic/timeoutRunner.js +3 -3
  247. package/lib/utils/isomorphic/trace/entries.js +16 -0
  248. package/lib/utils/isomorphic/trace/snapshotRenderer.js +492 -0
  249. package/lib/utils/isomorphic/trace/snapshotServer.js +120 -0
  250. package/lib/utils/isomorphic/trace/snapshotStorage.js +89 -0
  251. package/lib/utils/isomorphic/trace/traceLoader.js +132 -0
  252. package/lib/utils/isomorphic/trace/traceModel.js +366 -0
  253. package/lib/utils/isomorphic/trace/traceModernizer.js +401 -0
  254. package/lib/utils/isomorphic/trace/versions/traceV3.js +16 -0
  255. package/lib/utils/isomorphic/trace/versions/traceV4.js +16 -0
  256. package/lib/utils/isomorphic/trace/versions/traceV5.js +16 -0
  257. package/lib/utils/isomorphic/trace/versions/traceV6.js +16 -0
  258. package/lib/utils/isomorphic/trace/versions/traceV7.js +16 -0
  259. package/lib/utils/isomorphic/trace/versions/traceV8.js +16 -0
  260. package/lib/utils/isomorphic/urlMatch.js +54 -1
  261. package/lib/utils/isomorphic/utilityScriptSerializers.js +11 -0
  262. package/lib/utils/isomorphic/yaml.js +84 -0
  263. package/lib/utils.js +8 -2
  264. package/lib/utilsBundle.js +5 -26
  265. package/lib/utilsBundleImpl/index.js +172 -173
  266. package/lib/vite/dashboard/assets/index-BAOybkp8.js +50 -0
  267. package/lib/vite/dashboard/assets/index-CZAYOG76.css +1 -0
  268. package/lib/vite/dashboard/index.html +28 -0
  269. package/lib/vite/htmlReport/index.html +2 -70
  270. package/lib/vite/htmlReport/report.css +1 -0
  271. package/lib/vite/htmlReport/report.js +72 -0
  272. package/lib/vite/recorder/assets/codeMirrorModule-C8KMvO9L.js +32 -0
  273. package/lib/vite/recorder/assets/{codeMirrorModule-C3UTv-Ge.css → codeMirrorModule-DYBRYzYX.css} +1 -1
  274. package/lib/vite/recorder/assets/{index-Ri0uHF7I.css → index-BSjZa4pk.css} +1 -1
  275. package/lib/vite/recorder/assets/index-CqAYX1I3.js +193 -0
  276. package/lib/vite/recorder/index.html +2 -2
  277. package/lib/vite/traceViewer/assets/codeMirrorModule-DS0FLvoc.js +32 -0
  278. package/lib/vite/traceViewer/assets/defaultSettingsView-GTWI-W_B.js +262 -0
  279. package/lib/vite/traceViewer/{codeMirrorModule.C3UTv-Ge.css → codeMirrorModule.DYBRYzYX.css} +1 -1
  280. package/lib/vite/traceViewer/defaultSettingsView.B4dS75f0.css +1 -0
  281. package/lib/vite/traceViewer/index.CzXZzn5A.css +1 -0
  282. package/lib/vite/traceViewer/index.Dtstcb7U.js +2 -0
  283. package/lib/vite/traceViewer/index.html +4 -4
  284. package/lib/vite/traceViewer/sw.bundle.js +5 -3
  285. package/lib/vite/traceViewer/uiMode.Vipi55dB.js +6 -0
  286. package/lib/vite/traceViewer/uiMode.html +3 -3
  287. package/lib/zipBundleImpl.js +2 -2
  288. package/lib/zodBundle.js +39 -0
  289. package/lib/zodBundleImpl.js +40 -0
  290. package/package.json +7 -1
  291. package/types/protocol.d.ts +1696 -221
  292. package/types/types.d.ts +879 -112
  293. package/lib/server/bidi/third_party/bidiDeserializer.js +0 -98
  294. package/lib/server/chromium/videoRecorder.js +0 -115
  295. package/lib/server/pageBinding.js +0 -87
  296. package/lib/server/trace/test/inMemorySnapshotter.js +0 -87
  297. package/lib/utils/isomorphic/oldUtilityScriptSerializers.js +0 -248
  298. package/lib/vite/recorder/assets/codeMirrorModule-CBbSe-ZI.js +0 -25
  299. package/lib/vite/recorder/assets/index-CpZVd2nA.js +0 -193
  300. package/lib/vite/traceViewer/assets/codeMirrorModule-DHz0wP2C.js +0 -25
  301. package/lib/vite/traceViewer/assets/defaultSettingsView-WsZP88O6.js +0 -266
  302. package/lib/vite/traceViewer/defaultSettingsView.ConWv5KN.css +0 -1
  303. package/lib/vite/traceViewer/index.C4Y3Aw8n.css +0 -1
  304. package/lib/vite/traceViewer/index.C8xAeo93.js +0 -2
  305. package/lib/vite/traceViewer/uiMode.BltraIJB.js +0 -5
  306. /package/lib/{server/utils → utils/isomorphic}/imageUtils.js +0 -0
  307. /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");
@@ -181,7 +178,7 @@ class FrameManager {
181
178
  const navigationEvent = { url, name, newDocument: frame._currentDocument, isPublic: true };
182
179
  this._fireInternalFrameNavigation(frame, navigationEvent);
183
180
  if (!initial) {
184
- import_debugLogger.debugLogger.log("api", ` navigated to "${url}"`);
181
+ frame.apiLog(` navigated to "${url}"`);
185
182
  this._page.frameNavigatedToNewDocument(frame);
186
183
  }
187
184
  frame.setPendingDocument(keepPending);
@@ -197,7 +194,7 @@ class FrameManager {
197
194
  frame._url = url;
198
195
  const navigationEvent = { url, name: frame._name, isPublic: true };
199
196
  this._fireInternalFrameNavigation(frame, navigationEvent);
200
- import_debugLogger.debugLogger.log("api", ` navigated to "${url}"`);
197
+ frame.apiLog(` navigated to "${url}"`);
201
198
  }
202
199
  frameAbortedNavigation(frameId, errorText, documentId) {
203
200
  const frame = this._frames.get(frameId);
@@ -352,6 +349,11 @@ class FrameManager {
352
349
  frame.emit(Frame.Events.InternalNavigation, event);
353
350
  }
354
351
  }
352
+ const FrameEvent = {
353
+ InternalNavigation: "internalnavigation",
354
+ AddLifecycle: "addlifecycle",
355
+ RemoveLifecycle: "removelifecycle"
356
+ };
355
357
  class Frame extends import_instrumentation.SdkObject {
356
358
  constructor(page, id, parentFrame) {
357
359
  super(page, "frame");
@@ -384,11 +386,7 @@ class Frame extends import_instrumentation.SdkObject {
384
386
  this._startNetworkIdleTimer();
385
387
  }
386
388
  static {
387
- this.Events = {
388
- InternalNavigation: "internalnavigation",
389
- AddLifecycle: "addlifecycle",
390
- RemoveLifecycle: "removelifecycle"
391
- };
389
+ this.Events = FrameEvent;
392
390
  }
393
391
  isDetached() {
394
392
  return this._detachedScope.isClosed();
@@ -399,13 +397,10 @@ class Frame extends import_instrumentation.SdkObject {
399
397
  this._firedLifecycleEvents.add(event);
400
398
  this.emit(Frame.Events.AddLifecycle, event);
401
399
  if (this === this._page.mainFrame() && this._url !== "about:blank")
402
- import_debugLogger.debugLogger.log("api", ` "${event}" event fired`);
400
+ this.apiLog(` "${event}" event fired`);
403
401
  this._page.mainFrame()._recalculateNetworkIdle();
404
402
  }
405
403
  _onClearLifecycle() {
406
- this._isolatedWorld = void 0;
407
- this._mainWorld = void 0;
408
- this._iframeWorld = void 0;
409
404
  for (const event of this._firedLifecycleEvents)
410
405
  this.emit(Frame.Events.RemoveLifecycle, event);
411
406
  this._firedLifecycleEvents.clear();
@@ -474,7 +469,7 @@ class Frame extends import_instrumentation.SdkObject {
474
469
  this._firedLifecycleEvents.add("networkidle");
475
470
  this.emit(Frame.Events.AddLifecycle, "networkidle");
476
471
  if (this === this._page.mainFrame() && this._url !== "about:blank")
477
- import_debugLogger.debugLogger.log("api", ` "networkidle" event fired`);
472
+ this.apiLog(` "networkidle" event fired`);
478
473
  }
479
474
  if (frameThatAllowsRemovingNetworkIdle !== this && this._firedLifecycleEvents.has("networkidle") && !isNetworkIdle) {
480
475
  this._firedLifecycleEvents.delete("networkidle");
@@ -574,7 +569,7 @@ class Frame extends import_instrumentation.SdkObject {
574
569
  const request = navigationEvent.newDocument ? navigationEvent.newDocument.request : void 0;
575
570
  return request ? progress.race(request._finalRequest().response()) : null;
576
571
  }
577
- async _waitForLoadState(progress, state) {
572
+ async waitForLoadState(progress, state) {
578
573
  const waitUntil = verifyLifecycle("state", state);
579
574
  if (!this._firedLifecycleEvents.has(waitUntil))
580
575
  await import_helper.helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, (e) => e === waitUntil).promise;
@@ -582,72 +577,12 @@ class Frame extends import_instrumentation.SdkObject {
582
577
  async frameElement() {
583
578
  return this._page.delegate.getFrameElement(this);
584
579
  }
585
- async _context(world) {
586
- if (this.isDetached()) throw new Error("Frame was detached");
587
- try {
588
- var client = this._page.delegate._sessionForFrame(this)._client;
589
- } catch (e) {
590
- var client = this._page.delegate._mainFrameSession._client;
591
- }
592
- var iframeExecutionContextId = await this._getFrameMainFrameContextId(client);
593
- if (world == "main") {
594
- if (this != this._page.mainFrame() && iframeExecutionContextId && this._iframeWorld == void 0) {
595
- var executionContextId = iframeExecutionContextId;
596
- var crContext = new import_crExecutionContext.CRExecutionContext(client, { id: executionContextId }, this._id);
597
- this._iframeWorld = new import_dom.FrameExecutionContext(crContext, this, world);
598
- this._page.delegate._mainFrameSession._onExecutionContextCreated({
599
- id: executionContextId,
600
- origin: world,
601
- name: world,
602
- auxData: { isDefault: this === this._page.mainFrame(), type: "isolated", frameId: this._id }
603
- });
604
- } else if (this._mainWorld == void 0) {
605
- var globalThis2 = await client._sendMayFail("Runtime.evaluate", {
606
- expression: "globalThis",
607
- serializationOptions: { serialization: "idOnly" }
608
- });
609
- if (!globalThis2) {
610
- return;
611
- }
612
- var globalThisObjId = globalThis2["result"]["objectId"];
613
- var executionContextId = parseInt(globalThisObjId.split(".")[1], 10);
614
- var crContext = new import_crExecutionContext.CRExecutionContext(client, { id: executionContextId }, this._id);
615
- this._mainWorld = new import_dom.FrameExecutionContext(crContext, this, world);
616
- this._page.delegate._mainFrameSession._onExecutionContextCreated({
617
- id: executionContextId,
618
- origin: world,
619
- name: world,
620
- auxData: { isDefault: this === this._page.mainFrame(), type: "isolated", frameId: this._id }
621
- });
622
- }
623
- }
624
- if (world != "main" && this._isolatedWorld == void 0) {
625
- world = "utility";
626
- var result = await client._sendMayFail("Page.createIsolatedWorld", {
627
- frameId: this._id,
628
- grantUniveralAccess: true,
629
- worldName: world
630
- });
631
- if (!result) {
632
- return;
633
- }
634
- var executionContextId = result.executionContextId;
635
- var crContext = new import_crExecutionContext.CRExecutionContext(client, { id: executionContextId }, this._id);
636
- this._isolatedWorld = new import_dom.FrameExecutionContext(crContext, this, world);
637
- this._page.delegate._mainFrameSession._onExecutionContextCreated({
638
- id: executionContextId,
639
- origin: world,
640
- name: world,
641
- auxData: { isDefault: this === this._page.mainFrame(), type: "isolated", frameId: this._id }
642
- });
643
- }
644
- if (world != "main") {
645
- return this._isolatedWorld;
646
- } else if (this != this._page.mainFrame() && iframeExecutionContextId) {
647
- return this._iframeWorld;
648
- } else {
649
- return this._mainWorld;
650
- }
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
+ });
651
586
  }
652
587
  _mainContext() {
653
588
  return this._context("main");
@@ -664,18 +599,13 @@ class Frame extends import_instrumentation.SdkObject {
664
599
  return value;
665
600
  }
666
601
  async evaluateExpressionHandle(expression, options = {}, arg) {
667
- const context = await this._context(options.world ?? "utility");
602
+ const context = await this._context(options.world ?? "main");
668
603
  const value = await context.evaluateExpressionHandle(expression, options, arg);
669
604
  return value;
670
605
  }
671
606
  async querySelector(selector, options) {
672
- return this.querySelectorAll(selector, options).then((handles) => {
673
- if (handles.length === 0)
674
- return null;
675
- if (handles.length > 1 && options?.strict)
676
- throw new Error(`Strict mode: expected one element matching selector "${selector}", found ${handles.length}`);
677
- return handles[0];
678
- });
607
+ this.apiLog(` finding element using the selector "${selector}"`);
608
+ return this.selectors.query(selector, options);
679
609
  }
680
610
  async waitForSelector(progress, selector, performActionPreChecksAndLog, options, scope) {
681
611
  if (options.visibility)
@@ -687,37 +617,57 @@ class Frame extends import_instrumentation.SdkObject {
687
617
  throw new Error(`state: expected one of (attached|detached|visible|hidden)`);
688
618
  if (performActionPreChecksAndLog)
689
619
  progress.log(`waiting for ${this._asLocator(selector)}${state === "attached" ? "" : " to be " + state}`);
690
- const promise = this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, async (handle) => {
691
- const attached = !!handle;
692
- var visible = false;
693
- if (attached) {
694
- if (handle.parentNode.constructor.name == "ElementHandle") {
695
- visible = await handle.parentNode.evaluateInUtility(([injected, node, { handle: handle2 }]) => {
696
- return handle2 ? injected.utils.isElementVisible(handle2) : false;
697
- }, { handle });
698
- } else {
699
- visible = await handle.parentNode.evaluate((injected, { handle: handle2 }) => {
700
- return handle2 ? injected.utils.isElementVisible(handle2) : false;
701
- }, { handle });
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;
628
+ }
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)}`;
702
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;
653
+ }
654
+ if (options.omitReturnValue) {
655
+ result.dispose();
656
+ return null;
703
657
  }
704
- const success = {
705
- attached,
706
- detached: !attached,
707
- visible,
708
- hidden: !visible
709
- }[state];
710
- if (!success) return "internal:continuepolling";
711
- if (options.omitReturnValue) return null;
712
- const element = state === "attached" || state === "visible" ? handle : null;
713
- if (!element) return null;
714
- if (options.__testHookBeforeAdoptNode) await options.__testHookBeforeAdoptNode();
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());
715
664
  try {
716
- return element;
665
+ const mainContext = await progress.race(resolved.frame._mainContext());
666
+ return await progress.race(element._adoptTo(mainContext));
717
667
  } catch (e) {
718
- return "internal:continuepolling";
668
+ return continuePolling;
719
669
  }
720
- }, "returnOnNotResolved");
670
+ });
721
671
  return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
722
672
  }
723
673
  async dispatchEvent(progress, selector, type, eventInit = {}, options, scope) {
@@ -728,22 +678,16 @@ class Frame extends import_instrumentation.SdkObject {
728
678
  async evalOnSelector(selector, strict, expression, isFunction, arg, scope) {
729
679
  const handle = await this.selectors.query(selector, { strict }, scope);
730
680
  if (!handle)
731
- throw new Error("Failed to find element matching selector " + selector);
732
- 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);
733
683
  handle.dispose();
734
684
  return result;
735
685
  }
736
- async evalOnSelectorAll(selector, expression, isFunction, arg, scope, isolatedContext) {
737
- try {
738
- isolatedContext = this.selectors._parseSelector(selector, { strict: false }).world !== "main" && isolatedContext;
739
- const arrayHandle = await this.selectors.queryArrayInMainWorld(selector, scope, isolatedContext);
740
- const result = await arrayHandle.evaluateExpression(expression, { isFunction }, arg, isolatedContext);
741
- arrayHandle.dispose();
742
- return result;
743
- } catch (e) {
744
- if ("JSHandles can be evaluated only in the context they were created!" === e.message) return await this.evalOnSelectorAll(selector, expression, isFunction, arg, scope, isolatedContext);
745
- throw e;
746
- }
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;
747
691
  }
748
692
  async maskSelectors(selectors, color) {
749
693
  const context = await this._utilityContext();
@@ -753,30 +697,16 @@ class Frame extends import_instrumentation.SdkObject {
753
697
  }, { parsed: selectors, color });
754
698
  }
755
699
  async querySelectorAll(selector) {
756
- const metadata = { internal: false, log: [], method: "querySelectorAll" };
757
- const progress = {
758
- log: (message) => metadata.log.push(message),
759
- metadata,
760
- race: (promise) => Promise.race(Array.isArray(promise) ? promise : [promise])
761
- };
762
- return await this._retryWithoutProgress(progress, selector, null, false, async (result) => {
763
- if (!result || !result[0]) return [];
764
- return result[1];
765
- }, "returnAll", null);
700
+ return this.selectors.queryAll(selector);
766
701
  }
767
702
  async queryCount(selector, options) {
768
- const metadata = { internal: false, log: [], method: "queryCount" };
769
- const progress = {
770
- log: (message) => metadata.log.push(message),
771
- metadata,
772
- race: (promise) => Promise.race(Array.isArray(promise) ? promise : [promise])
773
- };
774
- return await this._retryWithoutProgress(progress, selector, null, false, async (result) => {
775
- if (!result) return 0;
776
- const handle = result[0];
777
- const handles = result[1];
778
- return handle ? handles.length : 0;
779
- }, "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
+ }
780
710
  }
781
711
  async content() {
782
712
  try {
@@ -796,19 +726,27 @@ class Frame extends import_instrumentation.SdkObject {
796
726
  }
797
727
  }
798
728
  async setContent(progress, html, options) {
729
+ const tag = `--playwright--set--content--${this._id}--${++this._setContentCounter}--`;
799
730
  await this.raceNavigationAction(progress, async () => {
800
731
  const waitUntil = options.waitUntil === void 0 ? "load" : options.waitUntil;
801
732
  progress.log(`setting frame content, waiting until "${waitUntil}"`);
802
- 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, () => {
803
736
  this._onClearLifecycle();
804
- this._waitForLoadState(progress, waitUntil).then(resolve).catch(reject);
805
- });
806
- const setContentPromise = this._page.delegate._mainFrameSession._client.send("Page.setDocumentContent", {
807
- frameId: this._id,
808
- html
737
+ tagPromise.resolve();
809
738
  });
810
- 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]);
811
747
  return null;
748
+ }).finally(() => {
749
+ this._page.frameManager._consoleMessageTags.delete(tag);
812
750
  });
813
751
  }
814
752
  name() {
@@ -968,26 +906,74 @@ class Frame extends import_instrumentation.SdkObject {
968
906
  return true;
969
907
  return false;
970
908
  }
971
- async _retryWithProgressIfNotConnected(progress, selector, strict, performActionPreChecks, action, returnAction) {
972
- 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;
973
913
  return this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling) => {
974
- return this._retryWithoutProgress(progress, selector, strict, performActionPreChecks, 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
+ }
975
961
  });
976
962
  }
977
963
  async rafrafTimeoutScreenshotElementWithProgress(progress, selector, timeout, options) {
978
- return await this._retryWithProgressIfNotConnected(progress, selector, true, true, async (handle) => {
964
+ return await this._retryWithProgressIfNotConnected(progress, selector, { strict: true, performActionPreChecks: true }, async (handle) => {
979
965
  await handle._frame.rafrafTimeout(progress, timeout);
980
966
  return await this._page.screenshotter.screenshotElement(progress, handle, options);
981
967
  });
982
968
  }
983
969
  async click(progress, selector, options) {
984
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._click(progress, { ...options, waitAfter: !options.noWaitAfter })));
970
+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options, (handle) => handle._click(progress, { ...options, waitAfter: !options.noWaitAfter })));
985
971
  }
986
972
  async dblclick(progress, selector, options) {
987
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._dblclick(progress, options)));
973
+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options, (handle) => handle._dblclick(progress, options)));
988
974
  }
989
975
  async dragAndDrop(progress, source, target, options) {
990
- dom.assertDone(await this._retryWithProgressIfNotConnected(progress, source, options.strict, !options.force, async (handle) => {
976
+ dom.assertDone(await this._retryWithProgressIfNotConnected(progress, source, options, async (handle) => {
991
977
  return handle._retryPointerAction(progress, "move and down", false, async (point) => {
992
978
  await this._page.mouse.move(progress, point.x, point.y);
993
979
  await this._page.mouse.down(progress);
@@ -997,7 +983,7 @@ class Frame extends import_instrumentation.SdkObject {
997
983
  position: options.sourcePosition
998
984
  });
999
985
  }));
1000
- dom.assertDone(await this._retryWithProgressIfNotConnected(progress, target, options.strict, false, async (handle) => {
986
+ dom.assertDone(await this._retryWithProgressIfNotConnected(progress, target, { ...options, performActionPreChecks: false }, async (handle) => {
1001
987
  return handle._retryPointerAction(progress, "move and up", false, async (point) => {
1002
988
  await this._page.mouse.move(progress, point.x, point.y, { steps: options.steps });
1003
989
  await this._page.mouse.up(progress);
@@ -1011,16 +997,16 @@ class Frame extends import_instrumentation.SdkObject {
1011
997
  async tap(progress, selector, options) {
1012
998
  if (!this._page.browserContext._options.hasTouch)
1013
999
  throw new Error("The page does not support tap. Use hasTouch context option to enable touch support.");
1014
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._tap(progress, options)));
1000
+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options, (handle) => handle._tap(progress, options)));
1015
1001
  }
1016
1002
  async fill(progress, selector, value, options) {
1017
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._fill(progress, value, options)));
1003
+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options, (handle) => handle._fill(progress, value, options)));
1018
1004
  }
1019
1005
  async focus(progress, selector, options) {
1020
- dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle) => handle._focus(progress)));
1006
+ dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options, (handle) => handle._focus(progress)));
1021
1007
  }
1022
1008
  async blur(progress, selector, options) {
1023
- dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle) => handle._blur(progress)));
1009
+ dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options, (handle) => handle._blur(progress)));
1024
1010
  }
1025
1011
  async resolveSelector(progress, selector, options = {}) {
1026
1012
  const element = await progress.race(this.selectors.query(selector, options));
@@ -1104,56 +1090,17 @@ class Frame extends import_instrumentation.SdkObject {
1104
1090
  }
1105
1091
  async isVisibleInternal(progress, selector, options = {}, scope) {
1106
1092
  try {
1107
- const metadata = { internal: false, log: [], method: "isVisible" };
1108
- const progress2 = {
1109
- log: (message) => metadata.log.push(message),
1110
- metadata,
1111
- race: (promise) => Promise.race(Array.isArray(promise) ? promise : [promise])
1112
- };
1113
- progress2.log("waiting for " + this._asLocator(selector));
1114
- if (selector === ":scope") {
1115
- const scopeParentNode = scope.parentNode || scope;
1116
- if (scopeParentNode.constructor.name == "ElementHandle") {
1117
- return await scopeParentNode.evaluateInUtility(([injected, node, { scope: handle2 }]) => {
1118
- const state = handle2 ? injected.elementState(handle2, "visible") : {
1119
- matches: false,
1120
- received: "error:notconnected"
1121
- };
1122
- return state.matches;
1123
- }, { scope });
1124
- } else {
1125
- return await scopeParentNode.evaluate((injected, node, { scope: handle2 }) => {
1126
- const state = handle2 ? injected.elementState(handle2, "visible") : {
1127
- matches: false,
1128
- received: "error:notconnected"
1129
- };
1130
- return state.matches;
1131
- }, { scope });
1132
- }
1133
- } else {
1134
- return await this._retryWithoutProgress(progress2, selector, options.strict, false, async (handle) => {
1135
- if (!handle) return false;
1136
- if (handle.parentNode.constructor.name == "ElementHandle") {
1137
- return await handle.parentNode.evaluateInUtility(([injected, node, { handle: handle2 }]) => {
1138
- const state = handle2 ? injected.elementState(handle2, "visible") : {
1139
- matches: false,
1140
- received: "error:notconnected"
1141
- };
1142
- return state.matches;
1143
- }, { handle });
1144
- } else {
1145
- return await handle.parentNode.evaluate((injected, { handle: handle2 }) => {
1146
- const state = handle2 ? injected.elementState(handle2, "visible") : {
1147
- matches: false,
1148
- received: "error:notconnected"
1149
- };
1150
- return state.matches;
1151
- }, { handle });
1152
- }
1153
- }, "returnOnNotResolved", null);
1154
- }
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 }));
1155
1101
  } catch (e) {
1156
- if (this.isNonRetriableError(e)) throw e;
1102
+ if (this.isNonRetriableError(e))
1103
+ throw e;
1157
1104
  return false;
1158
1105
  }
1159
1106
  }
@@ -1173,35 +1120,32 @@ class Frame extends import_instrumentation.SdkObject {
1173
1120
  return this._elementState(progress, selector, "checked", options, scope);
1174
1121
  }
1175
1122
  async hover(progress, selector, options) {
1176
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._hover(progress, options)));
1123
+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options, (handle) => handle._hover(progress, options)));
1177
1124
  }
1178
1125
  async selectOption(progress, selector, elements, values, options) {
1179
- return await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._selectOption(progress, elements, values, options));
1126
+ return await this._retryWithProgressIfNotConnected(progress, selector, options, (handle) => handle._selectOption(progress, elements, values, options));
1180
1127
  }
1181
1128
  async setInputFiles(progress, selector, params) {
1182
1129
  const inputFileItems = await (0, import_fileUploadUtils.prepareFilesForUpload)(this, params);
1183
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, params.strict, true, (handle) => handle._setInputFiles(progress, inputFileItems)));
1130
+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, params, (handle) => handle._setInputFiles(progress, inputFileItems)));
1184
1131
  }
1185
1132
  async type(progress, selector, text, options) {
1186
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle) => handle._type(progress, text, options)));
1133
+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options, (handle) => handle._type(progress, text, options)));
1187
1134
  }
1188
1135
  async press(progress, selector, key, options) {
1189
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle) => handle._press(progress, key, options)));
1136
+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options, (handle) => handle._press(progress, key, options)));
1190
1137
  }
1191
1138
  async check(progress, selector, options) {
1192
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._setChecked(progress, true, options)));
1139
+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options, (handle) => handle._setChecked(progress, true, options)));
1193
1140
  }
1194
1141
  async uncheck(progress, selector, options) {
1195
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._setChecked(progress, false, options)));
1142
+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options, (handle) => handle._setChecked(progress, false, options)));
1196
1143
  }
1197
1144
  async waitForTimeout(progress, timeout) {
1198
1145
  return progress.wait(timeout);
1199
1146
  }
1200
- async ariaSnapshot(progress, selector) {
1201
- return await this._retryWithProgressIfNotConnected(progress, selector, true, true, (handle) => progress.race(handle.ariaSnapshot()));
1202
- }
1203
- async expect(progress, selector, options, timeout) {
1204
- progress.log(`${(0, import_utils.renderTitleForCall)(progress.metadata)}${timeout ? ` with timeout ${timeout}ms` : ""}`);
1147
+ async expect(progress, selector, options) {
1148
+ progress.log(`${(0, import_utils.renderTitleForCall)(progress.metadata)}${options.timeoutForLogs ? ` with timeout ${options.timeoutForLogs}ms` : ""}`);
1205
1149
  const lastIntermediateResult = { isSet: false };
1206
1150
  const fixupMetadataError = (result) => {
1207
1151
  if (result.matches === options.isNot)
@@ -1210,17 +1154,19 @@ class Frame extends import_instrumentation.SdkObject {
1210
1154
  try {
1211
1155
  if (selector)
1212
1156
  progress.log(`waiting for ${this._asLocator(selector)}`);
1213
- await this._page.performActionPreChecks(progress);
1157
+ if (!options.noAutoWaiting)
1158
+ await this._page.performActionPreChecks(progress);
1214
1159
  try {
1215
1160
  const resultOneShot = await this._expectInternal(progress, selector, options, lastIntermediateResult, true);
1216
- if (resultOneShot.matches !== options.isNot)
1161
+ if (options.noAutoWaiting || resultOneShot.matches !== options.isNot)
1217
1162
  return resultOneShot;
1218
1163
  } catch (e) {
1219
- if (this.isNonRetriableError(e))
1164
+ if (options.noAutoWaiting || this.isNonRetriableError(e))
1220
1165
  throw e;
1221
1166
  }
1222
1167
  const result = await this.retryWithProgressAndTimeouts(progress, [100, 250, 500, 1e3], async (continuePolling) => {
1223
- await this._page.performActionPreChecks(progress);
1168
+ if (!options.noAutoWaiting)
1169
+ await this._page.performActionPreChecks(progress);
1224
1170
  const { matches, received } = await this._expectInternal(progress, selector, options, lastIntermediateResult, false);
1225
1171
  if (matches === options.isNot) {
1226
1172
  return continuePolling;
@@ -1247,55 +1193,36 @@ class Frame extends import_instrumentation.SdkObject {
1247
1193
  }
1248
1194
  async _expectInternal(progress, selector, options, lastIntermediateResult, noAbort) {
1249
1195
  const race = (p) => noAbort ? p : progress.race(p);
1250
- const isArray = options.expression === "to.have.count" || options.expression.endsWith(".array");
1251
- var log, matches, received, missingReceived;
1252
- if (selector) {
1253
- const { frame, info } = await race(this.selectors.resolveFrameForSelector(selector, { strict: true }));
1254
- const action = async (result) => {
1255
- if (!result) {
1256
- if (options.expectedNumber === 0)
1257
- return { matches: true };
1258
- if (!options.isNot && options.expression === "to.be.hidden")
1259
- return { matches: true };
1260
- if (options.isNot && options.expression === "to.be.visible")
1261
- return { matches: false };
1262
- if (!options.isNot && options.expression === "to.be.detached")
1263
- return { matches: true };
1264
- if (options.isNot && options.expression === "to.be.attached")
1265
- return { matches: false };
1266
- if (options.isNot && options.expression === "to.be.in.viewport")
1267
- return { matches: false };
1268
- return { matches: options.isNot, missingReceived: true };
1269
- }
1270
- const handle = result[0];
1271
- const handles = result[1];
1272
- if (handle.parentNode.constructor.name == "ElementHandle") {
1273
- return await handle.parentNode.evaluateInUtility(async ([injected, node, { handle: handle2, options: options2, handles: handles2 }]) => {
1274
- return await injected.expect(handle2, options2, handles2);
1275
- }, { handle, options, handles });
1276
- } else {
1277
- return await handle.parentNode.evaluate(async (injected, { handle: handle2, options: options2, handles: handles2 }) => {
1278
- return await injected.expect(handle2, options2, handles2);
1279
- }, { handle, options, handles });
1280
- }
1281
- };
1282
- if (noAbort) {
1283
- var { log, matches, received, missingReceived } = await this._retryWithoutProgress(progress, selector, !isArray, false, action, "returnAll", null);
1284
- } else {
1285
- var { log, matches, received, missingReceived } = await race(this._retryWithProgressIfNotConnected(progress, selector, !isArray, false, action, "returnAll"));
1286
- }
1287
- } else {
1288
- const world = options.expression === "to.have.property" ? "main" : "utility";
1289
- const context = await race(this._context(world));
1290
- const injected = await race(context.injectedScript());
1291
- var { matches, received, missingReceived } = await race(injected.evaluate(async (injected2, { options: options2, callId }) => {
1292
- return { ...await injected2.expect(void 0, options2, []) };
1293
- }, { options, callId: progress.metadata.id }));
1294
- }
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 }));
1295
1217
  if (log)
1296
1218
  progress.log(log);
1297
1219
  if (matches === options.isNot) {
1298
- lastIntermediateResult.received = missingReceived ? "<element(s) not found>" : received;
1220
+ if (missingReceived) {
1221
+ lastIntermediateResult.errorMessage = "Error: element(s) not found";
1222
+ } else {
1223
+ lastIntermediateResult.errorMessage = void 0;
1224
+ lastIntermediateResult.received = received;
1225
+ }
1299
1226
  lastIntermediateResult.isSet = true;
1300
1227
  if (!missingReceived && !Array.isArray(received))
1301
1228
  progress.log(` unexpected value "${renderUnexpectedValue(options.expression, received)}"`);
@@ -1375,8 +1302,17 @@ class Frame extends import_instrumentation.SdkObject {
1375
1302
  return JSON.parse(handle.rawValue());
1376
1303
  }
1377
1304
  async title() {
1378
- const context = await this._utilityContext();
1379
- 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
+ }
1380
1316
  }
1381
1317
  async rafrafTimeout(progress, timeout) {
1382
1318
  if (timeout === 0)
@@ -1406,54 +1342,27 @@ class Frame extends import_instrumentation.SdkObject {
1406
1342
  }
1407
1343
  async _callOnElementOnceMatches(progress, selector, body, taskData, options, scope) {
1408
1344
  const callbackText = body.toString();
1409
- progress.log("waiting for " + this._asLocator(selector));
1410
- var promise;
1411
- if (selector === ":scope") {
1412
- const scopeParentNode = scope.parentNode || scope;
1413
- if (scopeParentNode.constructor.name == "ElementHandle") {
1414
- promise = scopeParentNode.evaluateInUtility(([injected, node, { callbackText: callbackText2, scope: handle2, taskData: taskData2 }]) => {
1415
- const callback = injected.eval(callbackText2);
1416
- const haha = callback(injected, handle2, taskData2);
1417
- return haha;
1418
- }, {
1419
- callbackText,
1420
- scope,
1421
- taskData
1422
- });
1423
- } else {
1424
- promise = scopeParentNode.evaluate((injected, { callbackText: callbackText2, scope: handle2, taskData: taskData2 }) => {
1425
- const callback = injected.eval(callbackText2);
1426
- return callback(injected, handle2, taskData2);
1427
- }, {
1428
- callbackText,
1429
- scope,
1430
- taskData
1431
- });
1432
- }
1433
- } else {
1434
- promise = this._retryWithProgressIfNotConnected(progress, selector, options.strict, false, async (handle) => {
1435
- if (handle.parentNode.constructor.name == "ElementHandle") {
1436
- return await handle.parentNode.evaluateInUtility(([injected, node, { callbackText: callbackText2, handle: handle2, taskData: taskData2 }]) => {
1437
- const callback = injected.eval(callbackText2);
1438
- const haha = callback(injected, handle2, taskData2);
1439
- return haha;
1440
- }, {
1441
- callbackText,
1442
- handle,
1443
- taskData
1444
- });
1445
- } else {
1446
- return await handle.parentNode.evaluate((injected, { callbackText: callbackText2, handle: handle2, taskData: taskData2 }) => {
1447
- const callback = injected.eval(callbackText2);
1448
- return callback(injected, handle2, taskData2);
1449
- }, {
1450
- callbackText,
1451
- handle,
1452
- taskData
1453
- });
1454
- }
1455
- });
1456
- }
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
+ });
1457
1366
  return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
1458
1367
  }
1459
1368
  _setContext(world, context) {
@@ -1503,229 +1412,32 @@ class Frame extends import_instrumentation.SdkObject {
1503
1412
  injectedScript.extend(source2, arg2);
1504
1413
  }, { source, arg });
1505
1414
  }
1506
- _asLocator(selector) {
1507
- return (0, import_utils.asLocator)(this._page.browserContext._browser.sdkLanguage(), selector);
1508
- }
1509
- async _getFrameMainFrameContextId(client) {
1510
- try {
1511
- var globalDocument = await client._sendMayFail("DOM.getFrameOwner", { frameId: this._id });
1512
- if (globalDocument && globalDocument.nodeId) {
1513
- var describedNode = await client._sendMayFail("DOM.describeNode", {
1514
- backendNodeId: globalDocument.backendNodeId
1515
- });
1516
- if (describedNode) {
1517
- var resolvedNode = await client._sendMayFail("DOM.resolveNode", {
1518
- nodeId: describedNode.node.contentDocument.nodeId
1519
- });
1520
- var _executionContextId = parseInt(resolvedNode.object.objectId.split(".")[1], 10);
1521
- return _executionContextId;
1522
- }
1523
- }
1524
- } catch (e) {
1525
- }
1526
- return 0;
1527
- }
1528
- async _retryWithoutProgress(progress, selector, strict, performActionPreChecks, action, returnAction, continuePolling) {
1529
- if (performActionPreChecks) await this._page.performActionPreChecks(progress);
1530
- const resolved = await this.selectors.resolveInjectedForSelector(selector, { strict });
1531
- if (!resolved) {
1532
- if (returnAction === "returnOnNotResolved" || returnAction === "returnAll") {
1533
- const result2 = await action(null);
1534
- return result2 === "internal:continuepolling" ? continuePolling : result2;
1535
- }
1536
- return continuePolling;
1537
- }
1538
- try {
1539
- var client = this._page.delegate._sessionForFrame(resolved.frame)._client;
1540
- } catch (e) {
1541
- var client = this._page.delegate._mainFrameSession._client;
1542
- }
1543
- var utilityContext = await resolved.frame._utilityContext();
1544
- var mainContext = await resolved.frame._mainContext();
1545
- const documentNode = await client._sendMayFail("Runtime.evaluate", {
1546
- expression: "document",
1547
- serializationOptions: {
1548
- serialization: "idOnly"
1549
- },
1550
- contextId: utilityContext.delegate._contextId
1551
- });
1552
- if (!documentNode) return continuePolling;
1553
- const documentScope = new dom.ElementHandle(utilityContext, documentNode.result.objectId);
1554
- let currentScopingElements;
1555
- try {
1556
- currentScopingElements = await this._customFindElementsByParsed(resolved, client, mainContext, documentScope, progress, resolved.info.parsed);
1557
- } catch (e) {
1558
- if ("JSHandles can be evaluated only in the context they were created!" === e.message) return continuePolling3;
1559
- await progress.race(resolved.injected.evaluateHandle((injected, { error }) => {
1560
- throw error;
1561
- }, { error: e }));
1562
- }
1563
- if (currentScopingElements.length == 0) {
1564
- if (returnAction === "returnOnNotResolved" || returnAction === "returnAll") {
1565
- const result2 = await action(null);
1566
- return result2 === "internal:continuepolling" ? continuePolling2 : result2;
1567
- }
1568
- return continuePolling;
1569
- }
1570
- const resultElement = currentScopingElements[0];
1571
- if (currentScopingElements.length > 1) {
1572
- if (resolved.info.strict) {
1573
- await progress.race(resolved.injected.evaluateHandle((injected, {
1574
- info,
1575
- elements
1576
- }) => {
1577
- throw injected.strictModeViolationError(info.parsed, elements);
1578
- }, {
1579
- info: resolved.info,
1580
- elements: currentScopingElements
1581
- }));
1582
- }
1583
- progress.log(" locator resolved to " + currentScopingElements.length + " elements. Proceeding with the first one: " + resultElement.preview());
1584
- } else if (resultElement) {
1585
- progress.log(" locator resolved to " + resultElement.preview());
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 };
1586
1423
  }
1587
- try {
1588
- var result = null;
1589
- if (returnAction === "returnAll") {
1590
- result = await action([resultElement, currentScopingElements]);
1591
- } else {
1592
- result = await action(resultElement);
1593
- }
1594
- if (result === "error:notconnected") {
1595
- progress.log("element was detached from the DOM, retrying");
1596
- return continuePolling;
1597
- } else if (result === "internal:continuepolling") {
1598
- return continuePolling;
1599
- }
1600
- return result;
1601
- } 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;
1602
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 };
1603
1438
  }
1604
- async _customFindElementsByParsed(resolved, client, context, documentScope, progress, parsed) {
1605
- var parsedEdits = { ...parsed };
1606
- var currentScopingElements = [documentScope];
1607
- while (parsed.parts.length > 0) {
1608
- var part = parsed.parts.shift();
1609
- parsedEdits.parts = [part];
1610
- var elements = [];
1611
- var elementsIndexes = [];
1612
- if (part.name == "nth") {
1613
- const partNth = Number(part.body);
1614
- if (currentScopingElements.length == 0) return [];
1615
- if (partNth > currentScopingElements.length - 1 || partNth < -(currentScopingElements.length - 1)) {
1616
- if (parsed.capture !== void 0) throw new Error("Can't query n-th element in a request with the capture.");
1617
- return [];
1618
- } else {
1619
- currentScopingElements = [currentScopingElements.at(partNth)];
1620
- continue;
1621
- }
1622
- } else if (part.name == "internal:or") {
1623
- var orredElements = await this._customFindElementsByParsed(resolved, client, context, documentScope, progress, part.body.parsed);
1624
- elements = currentScopingElements.concat(orredElements);
1625
- } else if (part.name == "internal:and") {
1626
- var andedElements = await this._customFindElementsByParsed(resolved, client, context, documentScope, progress, part.body.parsed);
1627
- const backendNodeIds = new Set(andedElements.map((item) => item.backendNodeId));
1628
- elements = currentScopingElements.filter((item) => backendNodeIds.has(item.backendNodeId));
1629
- } else {
1630
- for (const scope of currentScopingElements) {
1631
- let findClosedShadowRoots2 = function(node, results = []) {
1632
- if (!node || typeof node !== "object") return results;
1633
- if (node.shadowRoots && Array.isArray(node.shadowRoots)) {
1634
- for (const shadowRoot2 of node.shadowRoots) {
1635
- if (shadowRoot2.shadowRootType === "closed" && shadowRoot2.backendNodeId) {
1636
- results.push(shadowRoot2.backendNodeId);
1637
- }
1638
- findClosedShadowRoots2(shadowRoot2, results);
1639
- }
1640
- }
1641
- if (node.nodeName !== "IFRAME" && node.children && Array.isArray(node.children)) {
1642
- for (const child of node.children) {
1643
- findClosedShadowRoots2(child, results);
1644
- }
1645
- }
1646
- return results;
1647
- };
1648
- var findClosedShadowRoots = findClosedShadowRoots2;
1649
- const describedScope = await client.send("DOM.describeNode", {
1650
- objectId: scope._objectId,
1651
- depth: -1,
1652
- pierce: true
1653
- });
1654
- var queryingElements = [];
1655
- var shadowRootBackendIds = findClosedShadowRoots2(describedScope.node);
1656
- var shadowRoots = [];
1657
- for (var shadowRootBackendId of shadowRootBackendIds) {
1658
- var resolvedShadowRoot = await client.send("DOM.resolveNode", {
1659
- backendNodeId: shadowRootBackendId,
1660
- contextId: context.delegate._contextId
1661
- });
1662
- shadowRoots.push(new dom.ElementHandle(context, resolvedShadowRoot.object.objectId));
1663
- }
1664
- for (var shadowRoot of shadowRoots) {
1665
- const shadowElements = await shadowRoot.evaluateHandleInUtility(([injected, node, { parsed: parsed2, callId }]) => {
1666
- const elements2 = injected.querySelectorAll(parsed2, node);
1667
- if (callId) injected.markTargetElements(new Set(elements2), callId);
1668
- return elements2;
1669
- }, {
1670
- parsed: parsedEdits,
1671
- callId: progress.metadata.id
1672
- });
1673
- const shadowElementsAmount = await shadowElements.getProperty("length");
1674
- queryingElements.push([shadowElements, shadowElementsAmount, shadowRoot]);
1675
- }
1676
- const rootElements = await scope.evaluateHandleInUtility(([injected, node, { parsed: parsed2, callId }]) => {
1677
- const elements2 = injected.querySelectorAll(parsed2, node);
1678
- if (callId) injected.markTargetElements(new Set(elements2), callId);
1679
- return elements2;
1680
- }, {
1681
- parsed: parsedEdits,
1682
- callId: progress.metadata.id
1683
- });
1684
- const rootElementsAmount = await rootElements.getProperty("length");
1685
- queryingElements.push([rootElements, rootElementsAmount, scope]);
1686
- for (var queryedElement of queryingElements) {
1687
- var elementsToCheck = queryedElement[0];
1688
- var elementsAmount = await queryedElement[1].jsonValue();
1689
- var parentNode = queryedElement[2];
1690
- for (var i = 0; i < elementsAmount; i++) {
1691
- if (parentNode.constructor.name == "ElementHandle") {
1692
- var elementToCheck = await parentNode.evaluateHandleInUtility(([injected, node, { index, elementsToCheck: elementsToCheck2 }]) => {
1693
- return elementsToCheck2[index];
1694
- }, { index: i, elementsToCheck });
1695
- } else {
1696
- var elementToCheck = await parentNode.evaluateHandle((injected, { index, elementsToCheck: elementsToCheck2 }) => {
1697
- return elementsToCheck2[index];
1698
- }, { index: i, elementsToCheck });
1699
- }
1700
- elementToCheck.parentNode = parentNode;
1701
- var resolvedElement = await client.send("DOM.describeNode", {
1702
- objectId: elementToCheck._objectId,
1703
- depth: -1
1704
- });
1705
- elementToCheck.backendNodeId = resolvedElement.node.backendNodeId;
1706
- elementToCheck.nodePosition = this.selectors._findElementPositionInDomTree(elementToCheck, describedScope.node, context, "");
1707
- elements.push(elementToCheck);
1708
- }
1709
- }
1710
- }
1711
- }
1712
- const getParts = (pos) => (pos || "").split("").map(Number);
1713
- elements.sort((a, b) => {
1714
- const partA = getParts(a.nodePosition);
1715
- const partB = getParts(b.nodePosition);
1716
- const maxLength = Math.max(partA.length, partB.length);
1717
- for (let i2 = 0; i2 < maxLength; i2++) {
1718
- const aVal = partA[i2] ?? -1;
1719
- const bVal = partB[i2] ?? -1;
1720
- if (aVal !== bVal) return aVal - bVal;
1721
- }
1722
- return 0;
1723
- });
1724
- currentScopingElements = Array.from(
1725
- new Map(elements.map((e) => [e.backendNodeId, e])).values()
1726
- );
1727
- }
1728
- return currentScopingElements;
1439
+ _asLocator(selector) {
1440
+ return (0, import_utils.asLocator)(this._page.browserContext._browser.sdkLanguage(), selector);
1729
1441
  }
1730
1442
  }
1731
1443
  class SignalBarrier {