@stablyai/internal-playwright-core 0.1.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 (405) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +3 -0
  4. package/ThirdPartyNotices.txt +1134 -0
  5. package/bin/install_media_pack.ps1 +5 -0
  6. package/bin/install_webkit_wsl.ps1 +35 -0
  7. package/bin/reinstall_chrome_beta_linux.sh +42 -0
  8. package/bin/reinstall_chrome_beta_mac.sh +13 -0
  9. package/bin/reinstall_chrome_beta_win.ps1 +24 -0
  10. package/bin/reinstall_chrome_stable_linux.sh +42 -0
  11. package/bin/reinstall_chrome_stable_mac.sh +12 -0
  12. package/bin/reinstall_chrome_stable_win.ps1 +24 -0
  13. package/bin/reinstall_msedge_beta_linux.sh +48 -0
  14. package/bin/reinstall_msedge_beta_mac.sh +11 -0
  15. package/bin/reinstall_msedge_beta_win.ps1 +23 -0
  16. package/bin/reinstall_msedge_dev_linux.sh +48 -0
  17. package/bin/reinstall_msedge_dev_mac.sh +11 -0
  18. package/bin/reinstall_msedge_dev_win.ps1 +23 -0
  19. package/bin/reinstall_msedge_stable_linux.sh +48 -0
  20. package/bin/reinstall_msedge_stable_mac.sh +11 -0
  21. package/bin/reinstall_msedge_stable_win.ps1 +24 -0
  22. package/browsers.json +80 -0
  23. package/cli.js +18 -0
  24. package/index.d.ts +17 -0
  25. package/index.js +32 -0
  26. package/index.mjs +28 -0
  27. package/lib/androidServerImpl.js +65 -0
  28. package/lib/browserServerImpl.js +120 -0
  29. package/lib/cli/cli.js +58 -0
  30. package/lib/cli/driver.js +97 -0
  31. package/lib/cli/program.js +634 -0
  32. package/lib/cli/programWithTestStub.js +74 -0
  33. package/lib/client/accessibility.js +49 -0
  34. package/lib/client/android.js +361 -0
  35. package/lib/client/api.js +137 -0
  36. package/lib/client/artifact.js +79 -0
  37. package/lib/client/browser.js +163 -0
  38. package/lib/client/browserContext.js +529 -0
  39. package/lib/client/browserType.js +184 -0
  40. package/lib/client/cdpSession.js +51 -0
  41. package/lib/client/channelOwner.js +194 -0
  42. package/lib/client/clientHelper.js +64 -0
  43. package/lib/client/clientInstrumentation.js +55 -0
  44. package/lib/client/clientStackTrace.js +69 -0
  45. package/lib/client/clock.js +68 -0
  46. package/lib/client/connection.js +314 -0
  47. package/lib/client/consoleMessage.js +54 -0
  48. package/lib/client/coverage.js +44 -0
  49. package/lib/client/dialog.js +56 -0
  50. package/lib/client/download.js +62 -0
  51. package/lib/client/electron.js +138 -0
  52. package/lib/client/elementHandle.js +281 -0
  53. package/lib/client/errors.js +77 -0
  54. package/lib/client/eventEmitter.js +314 -0
  55. package/lib/client/events.js +99 -0
  56. package/lib/client/fetch.js +369 -0
  57. package/lib/client/fileChooser.js +46 -0
  58. package/lib/client/fileUtils.js +34 -0
  59. package/lib/client/frame.js +408 -0
  60. package/lib/client/harRouter.js +87 -0
  61. package/lib/client/input.js +84 -0
  62. package/lib/client/jsHandle.js +109 -0
  63. package/lib/client/jsonPipe.js +39 -0
  64. package/lib/client/localUtils.js +60 -0
  65. package/lib/client/locator.js +368 -0
  66. package/lib/client/network.js +747 -0
  67. package/lib/client/page.js +721 -0
  68. package/lib/client/platform.js +74 -0
  69. package/lib/client/playwright.js +71 -0
  70. package/lib/client/selectors.js +55 -0
  71. package/lib/client/stream.js +39 -0
  72. package/lib/client/timeoutSettings.js +79 -0
  73. package/lib/client/tracing.js +117 -0
  74. package/lib/client/types.js +28 -0
  75. package/lib/client/video.js +59 -0
  76. package/lib/client/waiter.js +142 -0
  77. package/lib/client/webError.js +39 -0
  78. package/lib/client/webSocket.js +93 -0
  79. package/lib/client/worker.js +63 -0
  80. package/lib/client/writableStream.js +39 -0
  81. package/lib/common/debugLogger.js +90 -0
  82. package/lib/common/socksProxy.js +569 -0
  83. package/lib/common/timeoutSettings.js +73 -0
  84. package/lib/common/types.js +5 -0
  85. package/lib/generated/bindingsControllerSource.js +28 -0
  86. package/lib/generated/clockSource.js +28 -0
  87. package/lib/generated/consoleApiSource.js +28 -0
  88. package/lib/generated/injectedScriptSource.js +28 -0
  89. package/lib/generated/pollingRecorderSource.js +28 -0
  90. package/lib/generated/recorderSource.js +28 -0
  91. package/lib/generated/storageScriptSource.js +28 -0
  92. package/lib/generated/utilityScriptSource.js +28 -0
  93. package/lib/generated/webSocketMockSource.js +336 -0
  94. package/lib/image_tools/colorUtils.js +98 -0
  95. package/lib/image_tools/compare.js +108 -0
  96. package/lib/image_tools/imageChannel.js +70 -0
  97. package/lib/image_tools/stats.js +102 -0
  98. package/lib/inProcessFactory.js +60 -0
  99. package/lib/index.js +19 -0
  100. package/lib/inprocess.js +3 -0
  101. package/lib/outofprocess.js +76 -0
  102. package/lib/protocol/debug.js +27 -0
  103. package/lib/protocol/serializers.js +192 -0
  104. package/lib/protocol/transport.js +82 -0
  105. package/lib/protocol/validator.js +2919 -0
  106. package/lib/protocol/validatorPrimitives.js +193 -0
  107. package/lib/remote/playwrightConnection.js +129 -0
  108. package/lib/remote/playwrightServer.js +335 -0
  109. package/lib/server/accessibility.js +69 -0
  110. package/lib/server/android/android.js +465 -0
  111. package/lib/server/android/backendAdb.js +177 -0
  112. package/lib/server/artifact.js +127 -0
  113. package/lib/server/bidi/bidiBrowser.js +490 -0
  114. package/lib/server/bidi/bidiChromium.js +153 -0
  115. package/lib/server/bidi/bidiConnection.js +212 -0
  116. package/lib/server/bidi/bidiExecutionContext.js +221 -0
  117. package/lib/server/bidi/bidiFirefox.js +130 -0
  118. package/lib/server/bidi/bidiInput.js +146 -0
  119. package/lib/server/bidi/bidiNetworkManager.js +383 -0
  120. package/lib/server/bidi/bidiOverCdp.js +102 -0
  121. package/lib/server/bidi/bidiPage.js +552 -0
  122. package/lib/server/bidi/bidiPdf.js +106 -0
  123. package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
  124. package/lib/server/bidi/third_party/bidiDeserializer.js +98 -0
  125. package/lib/server/bidi/third_party/bidiKeyboard.js +256 -0
  126. package/lib/server/bidi/third_party/bidiProtocol.js +24 -0
  127. package/lib/server/bidi/third_party/bidiProtocolCore.js +179 -0
  128. package/lib/server/bidi/third_party/bidiProtocolPermissions.js +42 -0
  129. package/lib/server/bidi/third_party/bidiSerializer.js +148 -0
  130. package/lib/server/bidi/third_party/firefoxPrefs.js +259 -0
  131. package/lib/server/browser.js +149 -0
  132. package/lib/server/browserContext.js +695 -0
  133. package/lib/server/browserType.js +328 -0
  134. package/lib/server/callLog.js +82 -0
  135. package/lib/server/chromium/appIcon.png +0 -0
  136. package/lib/server/chromium/chromium.js +402 -0
  137. package/lib/server/chromium/chromiumSwitches.js +95 -0
  138. package/lib/server/chromium/crAccessibility.js +263 -0
  139. package/lib/server/chromium/crBrowser.js +501 -0
  140. package/lib/server/chromium/crConnection.js +202 -0
  141. package/lib/server/chromium/crCoverage.js +235 -0
  142. package/lib/server/chromium/crDevTools.js +113 -0
  143. package/lib/server/chromium/crDragDrop.js +131 -0
  144. package/lib/server/chromium/crExecutionContext.js +146 -0
  145. package/lib/server/chromium/crInput.js +187 -0
  146. package/lib/server/chromium/crNetworkManager.js +666 -0
  147. package/lib/server/chromium/crPage.js +1069 -0
  148. package/lib/server/chromium/crPdf.js +121 -0
  149. package/lib/server/chromium/crProtocolHelper.js +145 -0
  150. package/lib/server/chromium/crServiceWorker.js +123 -0
  151. package/lib/server/chromium/defaultFontFamilies.js +162 -0
  152. package/lib/server/chromium/protocol.d.js +16 -0
  153. package/lib/server/chromium/videoRecorder.js +113 -0
  154. package/lib/server/clock.js +149 -0
  155. package/lib/server/codegen/csharp.js +327 -0
  156. package/lib/server/codegen/java.js +274 -0
  157. package/lib/server/codegen/javascript.js +270 -0
  158. package/lib/server/codegen/jsonl.js +52 -0
  159. package/lib/server/codegen/language.js +132 -0
  160. package/lib/server/codegen/languages.js +68 -0
  161. package/lib/server/codegen/python.js +279 -0
  162. package/lib/server/codegen/types.js +16 -0
  163. package/lib/server/console.js +53 -0
  164. package/lib/server/cookieStore.js +206 -0
  165. package/lib/server/debugController.js +191 -0
  166. package/lib/server/debugger.js +119 -0
  167. package/lib/server/deviceDescriptors.js +39 -0
  168. package/lib/server/deviceDescriptorsSource.json +1779 -0
  169. package/lib/server/dialog.js +116 -0
  170. package/lib/server/dispatchers/androidDispatcher.js +325 -0
  171. package/lib/server/dispatchers/artifactDispatcher.js +118 -0
  172. package/lib/server/dispatchers/browserContextDispatcher.js +364 -0
  173. package/lib/server/dispatchers/browserDispatcher.js +118 -0
  174. package/lib/server/dispatchers/browserTypeDispatcher.js +64 -0
  175. package/lib/server/dispatchers/cdpSessionDispatcher.js +44 -0
  176. package/lib/server/dispatchers/debugControllerDispatcher.js +78 -0
  177. package/lib/server/dispatchers/dialogDispatcher.js +47 -0
  178. package/lib/server/dispatchers/dispatcher.js +371 -0
  179. package/lib/server/dispatchers/electronDispatcher.js +89 -0
  180. package/lib/server/dispatchers/elementHandlerDispatcher.js +181 -0
  181. package/lib/server/dispatchers/frameDispatcher.js +227 -0
  182. package/lib/server/dispatchers/jsHandleDispatcher.js +85 -0
  183. package/lib/server/dispatchers/jsonPipeDispatcher.js +58 -0
  184. package/lib/server/dispatchers/localUtilsDispatcher.js +149 -0
  185. package/lib/server/dispatchers/networkDispatchers.js +213 -0
  186. package/lib/server/dispatchers/pageDispatcher.js +401 -0
  187. package/lib/server/dispatchers/playwrightDispatcher.js +108 -0
  188. package/lib/server/dispatchers/selectorsDispatcher.js +36 -0
  189. package/lib/server/dispatchers/streamDispatcher.js +67 -0
  190. package/lib/server/dispatchers/tracingDispatcher.js +68 -0
  191. package/lib/server/dispatchers/webSocketRouteDispatcher.js +165 -0
  192. package/lib/server/dispatchers/writableStreamDispatcher.js +79 -0
  193. package/lib/server/dom.js +806 -0
  194. package/lib/server/download.js +70 -0
  195. package/lib/server/electron/electron.js +270 -0
  196. package/lib/server/electron/loader.js +29 -0
  197. package/lib/server/errors.js +69 -0
  198. package/lib/server/fetch.js +621 -0
  199. package/lib/server/fileChooser.js +43 -0
  200. package/lib/server/fileUploadUtils.js +84 -0
  201. package/lib/server/firefox/ffAccessibility.js +238 -0
  202. package/lib/server/firefox/ffBrowser.js +428 -0
  203. package/lib/server/firefox/ffConnection.js +147 -0
  204. package/lib/server/firefox/ffExecutionContext.js +150 -0
  205. package/lib/server/firefox/ffInput.js +159 -0
  206. package/lib/server/firefox/ffNetworkManager.js +256 -0
  207. package/lib/server/firefox/ffPage.js +503 -0
  208. package/lib/server/firefox/firefox.js +116 -0
  209. package/lib/server/firefox/protocol.d.js +16 -0
  210. package/lib/server/formData.js +147 -0
  211. package/lib/server/frameSelectors.js +156 -0
  212. package/lib/server/frames.js +1502 -0
  213. package/lib/server/har/harRecorder.js +147 -0
  214. package/lib/server/har/harTracer.js +607 -0
  215. package/lib/server/harBackend.js +157 -0
  216. package/lib/server/helper.js +96 -0
  217. package/lib/server/index.js +58 -0
  218. package/lib/server/input.js +273 -0
  219. package/lib/server/instrumentation.js +69 -0
  220. package/lib/server/isomorphic/utilityScriptSerializers.js +212 -0
  221. package/lib/server/javascript.js +291 -0
  222. package/lib/server/launchApp.js +128 -0
  223. package/lib/server/localUtils.js +218 -0
  224. package/lib/server/macEditingCommands.js +143 -0
  225. package/lib/server/network.js +629 -0
  226. package/lib/server/page.js +871 -0
  227. package/lib/server/pipeTransport.js +89 -0
  228. package/lib/server/playwright.js +69 -0
  229. package/lib/server/progress.js +112 -0
  230. package/lib/server/protocolError.js +52 -0
  231. package/lib/server/recorder/chat.js +161 -0
  232. package/lib/server/recorder/codeGenerator.js +153 -0
  233. package/lib/server/recorder/csharp.js +310 -0
  234. package/lib/server/recorder/java.js +248 -0
  235. package/lib/server/recorder/javascript.js +229 -0
  236. package/lib/server/recorder/jsonl.js +47 -0
  237. package/lib/server/recorder/language.js +44 -0
  238. package/lib/server/recorder/python.js +276 -0
  239. package/lib/server/recorder/recorderActions.js +5 -0
  240. package/lib/server/recorder/recorderApp.js +387 -0
  241. package/lib/server/recorder/recorderRunner.js +138 -0
  242. package/lib/server/recorder/recorderSignalProcessor.js +83 -0
  243. package/lib/server/recorder/recorderUtils.js +157 -0
  244. package/lib/server/recorder/throttledFile.js +57 -0
  245. package/lib/server/recorder/utils.js +45 -0
  246. package/lib/server/recorder.js +499 -0
  247. package/lib/server/registry/browserFetcher.js +175 -0
  248. package/lib/server/registry/dependencies.js +371 -0
  249. package/lib/server/registry/index.js +1331 -0
  250. package/lib/server/registry/nativeDeps.js +1280 -0
  251. package/lib/server/registry/oopDownloadBrowserMain.js +120 -0
  252. package/lib/server/screenshotter.js +333 -0
  253. package/lib/server/selectors.js +112 -0
  254. package/lib/server/socksClientCertificatesInterceptor.js +383 -0
  255. package/lib/server/socksInterceptor.js +95 -0
  256. package/lib/server/stably/ai-tools/http-request.js +70 -0
  257. package/lib/server/stably/ai-tools/stablyApiCaller.js +137 -0
  258. package/lib/server/stably/autohealing/elementHandleFromCoordinates.js +64 -0
  259. package/lib/server/stably/autohealing/healingService.js +228 -0
  260. package/lib/server/stably/autohealing/screenshotFrame.js +41 -0
  261. package/lib/server/stably/constants.js +31 -0
  262. package/lib/server/trace/recorder/snapshotter.js +147 -0
  263. package/lib/server/trace/recorder/snapshotterInjected.js +541 -0
  264. package/lib/server/trace/recorder/tracing.js +602 -0
  265. package/lib/server/trace/test/inMemorySnapshotter.js +87 -0
  266. package/lib/server/trace/viewer/traceViewer.js +240 -0
  267. package/lib/server/transport.js +181 -0
  268. package/lib/server/types.js +28 -0
  269. package/lib/server/usKeyboardLayout.js +145 -0
  270. package/lib/server/utils/ascii.js +44 -0
  271. package/lib/server/utils/comparators.js +161 -0
  272. package/lib/server/utils/crypto.js +216 -0
  273. package/lib/server/utils/debug.js +42 -0
  274. package/lib/server/utils/debugLogger.js +122 -0
  275. package/lib/server/utils/env.js +73 -0
  276. package/lib/server/utils/eventsHelper.js +39 -0
  277. package/lib/server/utils/expectUtils.js +38 -0
  278. package/lib/server/utils/fileUtils.js +191 -0
  279. package/lib/server/utils/happyEyeballs.js +207 -0
  280. package/lib/server/utils/hostPlatform.js +111 -0
  281. package/lib/server/utils/httpServer.js +218 -0
  282. package/lib/server/utils/image_tools/colorUtils.js +89 -0
  283. package/lib/server/utils/image_tools/compare.js +109 -0
  284. package/lib/server/utils/image_tools/imageChannel.js +78 -0
  285. package/lib/server/utils/image_tools/stats.js +102 -0
  286. package/lib/server/utils/linuxUtils.js +71 -0
  287. package/lib/server/utils/network.js +233 -0
  288. package/lib/server/utils/nodePlatform.js +148 -0
  289. package/lib/server/utils/pipeTransport.js +84 -0
  290. package/lib/server/utils/processLauncher.js +241 -0
  291. package/lib/server/utils/profiler.js +65 -0
  292. package/lib/server/utils/socksProxy.js +511 -0
  293. package/lib/server/utils/spawnAsync.js +41 -0
  294. package/lib/server/utils/task.js +51 -0
  295. package/lib/server/utils/userAgent.js +98 -0
  296. package/lib/server/utils/wsServer.js +121 -0
  297. package/lib/server/utils/zipFile.js +74 -0
  298. package/lib/server/utils/zones.js +57 -0
  299. package/lib/server/webkit/protocol.d.js +16 -0
  300. package/lib/server/webkit/webkit.js +119 -0
  301. package/lib/server/webkit/wkAccessibility.js +237 -0
  302. package/lib/server/webkit/wkBrowser.js +339 -0
  303. package/lib/server/webkit/wkConnection.js +149 -0
  304. package/lib/server/webkit/wkExecutionContext.js +154 -0
  305. package/lib/server/webkit/wkInput.js +181 -0
  306. package/lib/server/webkit/wkInterceptableRequest.js +169 -0
  307. package/lib/server/webkit/wkPage.js +1134 -0
  308. package/lib/server/webkit/wkProvisionalPage.js +83 -0
  309. package/lib/server/webkit/wkWorkers.js +104 -0
  310. package/lib/server/webkit/wsl/webkit-wsl-transport-client.js +74 -0
  311. package/lib/server/webkit/wsl/webkit-wsl-transport-server.js +113 -0
  312. package/lib/third_party/diff_match_patch.js +2222 -0
  313. package/lib/third_party/pixelmatch.js +255 -0
  314. package/lib/utils/ascii.js +31 -0
  315. package/lib/utils/comparators.js +171 -0
  316. package/lib/utils/crypto.js +33 -0
  317. package/lib/utils/debug.js +46 -0
  318. package/lib/utils/debugLogger.js +89 -0
  319. package/lib/utils/env.js +49 -0
  320. package/lib/utils/eventsHelper.js +38 -0
  321. package/lib/utils/fileUtils.js +205 -0
  322. package/lib/utils/glob.js +83 -0
  323. package/lib/utils/happy-eyeballs.js +160 -0
  324. package/lib/utils/headers.js +52 -0
  325. package/lib/utils/hostPlatform.js +128 -0
  326. package/lib/utils/httpServer.js +236 -0
  327. package/lib/utils/index.js +346 -0
  328. package/lib/utils/isomorphic/ariaSnapshot.js +392 -0
  329. package/lib/utils/isomorphic/assert.js +31 -0
  330. package/lib/utils/isomorphic/colors.js +72 -0
  331. package/lib/utils/isomorphic/cssParser.js +245 -0
  332. package/lib/utils/isomorphic/cssTokenizer.js +1051 -0
  333. package/lib/utils/isomorphic/headers.js +53 -0
  334. package/lib/utils/isomorphic/locatorGenerators.js +673 -0
  335. package/lib/utils/isomorphic/locatorParser.js +176 -0
  336. package/lib/utils/isomorphic/locatorUtils.js +81 -0
  337. package/lib/utils/isomorphic/manualPromise.js +114 -0
  338. package/lib/utils/isomorphic/mimeType.js +459 -0
  339. package/lib/utils/isomorphic/multimap.js +80 -0
  340. package/lib/utils/isomorphic/protocolFormatter.js +78 -0
  341. package/lib/utils/isomorphic/protocolMetainfo.js +321 -0
  342. package/lib/utils/isomorphic/rtti.js +43 -0
  343. package/lib/utils/isomorphic/selectorParser.js +386 -0
  344. package/lib/utils/isomorphic/semaphore.js +54 -0
  345. package/lib/utils/isomorphic/stackTrace.js +158 -0
  346. package/lib/utils/isomorphic/stringUtils.js +155 -0
  347. package/lib/utils/isomorphic/time.js +49 -0
  348. package/lib/utils/isomorphic/timeoutRunner.js +66 -0
  349. package/lib/utils/isomorphic/traceUtils.js +58 -0
  350. package/lib/utils/isomorphic/types.js +16 -0
  351. package/lib/utils/isomorphic/urlMatch.js +176 -0
  352. package/lib/utils/isomorphic/utilityScriptSerializers.js +251 -0
  353. package/lib/utils/linuxUtils.js +78 -0
  354. package/lib/utils/manualPromise.js +109 -0
  355. package/lib/utils/mimeType.js +29 -0
  356. package/lib/utils/multimap.js +75 -0
  357. package/lib/utils/network.js +188 -0
  358. package/lib/utils/processLauncher.js +248 -0
  359. package/lib/utils/profiler.js +53 -0
  360. package/lib/utils/rtti.js +44 -0
  361. package/lib/utils/semaphore.js +51 -0
  362. package/lib/utils/spawnAsync.js +45 -0
  363. package/lib/utils/stackTrace.js +121 -0
  364. package/lib/utils/task.js +58 -0
  365. package/lib/utils/time.js +37 -0
  366. package/lib/utils/timeoutRunner.js +66 -0
  367. package/lib/utils/traceUtils.js +44 -0
  368. package/lib/utils/userAgent.js +105 -0
  369. package/lib/utils/wsServer.js +127 -0
  370. package/lib/utils/zipFile.js +75 -0
  371. package/lib/utils/zones.js +62 -0
  372. package/lib/utils.js +107 -0
  373. package/lib/utilsBundle.js +109 -0
  374. package/lib/utilsBundleImpl/index.js +218 -0
  375. package/lib/utilsBundleImpl/xdg-open +1066 -0
  376. package/lib/vite/htmlReport/index.html +84 -0
  377. package/lib/vite/recorder/assets/codeMirrorModule-C3UTv-Ge.css +1 -0
  378. package/lib/vite/recorder/assets/codeMirrorModule-RJCXzfmE.js +24 -0
  379. package/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
  380. package/lib/vite/recorder/assets/index-Ri0uHF7I.css +1 -0
  381. package/lib/vite/recorder/assets/index-Y-X2TGJv.js +193 -0
  382. package/lib/vite/recorder/index.html +29 -0
  383. package/lib/vite/recorder/playwright-logo.svg +9 -0
  384. package/lib/vite/traceViewer/assets/codeMirrorModule-Bhnc5o2x.js +24 -0
  385. package/lib/vite/traceViewer/assets/defaultSettingsView-ClwvkA2N.js +265 -0
  386. package/lib/vite/traceViewer/assets/xtermModule-CsJ4vdCR.js +9 -0
  387. package/lib/vite/traceViewer/codeMirrorModule.C3UTv-Ge.css +1 -0
  388. package/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
  389. package/lib/vite/traceViewer/defaultSettingsView.TQ8_7ybu.css +1 -0
  390. package/lib/vite/traceViewer/index.DFO9NNF5.js +2 -0
  391. package/lib/vite/traceViewer/index.I8N9v4jT.css +1 -0
  392. package/lib/vite/traceViewer/index.html +43 -0
  393. package/lib/vite/traceViewer/playwright-logo.svg +9 -0
  394. package/lib/vite/traceViewer/snapshot.html +21 -0
  395. package/lib/vite/traceViewer/sw.bundle.js +3 -0
  396. package/lib/vite/traceViewer/uiMode.Btcz36p_.css +1 -0
  397. package/lib/vite/traceViewer/uiMode.Shu3QS-1.js +5 -0
  398. package/lib/vite/traceViewer/uiMode.html +17 -0
  399. package/lib/vite/traceViewer/xtermModule.DYP7pi_n.css +32 -0
  400. package/lib/zipBundle.js +34 -0
  401. package/lib/zipBundleImpl.js +5 -0
  402. package/package.json +43 -0
  403. package/types/protocol.d.ts +23130 -0
  404. package/types/structs.d.ts +45 -0
  405. package/types/types.d.ts +22857 -0
@@ -0,0 +1,1502 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var frames_exports = {};
30
+ __export(frames_exports, {
31
+ Frame: () => Frame,
32
+ FrameManager: () => FrameManager,
33
+ NavigationAbortedError: () => NavigationAbortedError
34
+ });
35
+ module.exports = __toCommonJS(frames_exports);
36
+ var import_browserContext = require("./browserContext");
37
+ var dom = __toESM(require("./dom"));
38
+ var import_errors = require("./errors");
39
+ var import_fileUploadUtils = require("./fileUploadUtils");
40
+ var import_frameSelectors = require("./frameSelectors");
41
+ var import_helper = require("./helper");
42
+ var import_instrumentation = require("./instrumentation");
43
+ var js = __toESM(require("./javascript"));
44
+ var network = __toESM(require("./network"));
45
+ var import_page = require("./page");
46
+ var import_progress = require("./progress");
47
+ var types = __toESM(require("./types"));
48
+ var import_utils = require("../utils");
49
+ var import_protocolError = require("./protocolError");
50
+ var import_debugLogger = require("./utils/debugLogger");
51
+ var import_eventsHelper = require("./utils/eventsHelper");
52
+ var import_selectorParser = require("../utils/isomorphic/selectorParser");
53
+ var import_manualPromise = require("../utils/isomorphic/manualPromise");
54
+ var import_callLog = require("./callLog");
55
+ var import_healingService = require("./stably/autohealing/healingService");
56
+ class NavigationAbortedError extends Error {
57
+ constructor(documentId, message) {
58
+ super(message);
59
+ this.documentId = documentId;
60
+ }
61
+ }
62
+ const kDummyFrameId = "<dummy>";
63
+ class FrameManager {
64
+ constructor(page) {
65
+ this._frames = /* @__PURE__ */ new Map();
66
+ this._consoleMessageTags = /* @__PURE__ */ new Map();
67
+ this._signalBarriers = /* @__PURE__ */ new Set();
68
+ this._webSockets = /* @__PURE__ */ new Map();
69
+ this._page = page;
70
+ this._mainFrame = void 0;
71
+ }
72
+ createDummyMainFrameIfNeeded() {
73
+ if (!this._mainFrame)
74
+ this.frameAttached(kDummyFrameId, null);
75
+ }
76
+ dispose() {
77
+ for (const frame of this._frames.values()) {
78
+ frame._stopNetworkIdleTimer();
79
+ frame._invalidateNonStallingEvaluations("Target crashed");
80
+ }
81
+ }
82
+ mainFrame() {
83
+ return this._mainFrame;
84
+ }
85
+ frames() {
86
+ const frames = [];
87
+ collect(this._mainFrame);
88
+ return frames;
89
+ function collect(frame) {
90
+ frames.push(frame);
91
+ for (const subframe of frame.childFrames())
92
+ collect(subframe);
93
+ }
94
+ }
95
+ frame(frameId) {
96
+ return this._frames.get(frameId) || null;
97
+ }
98
+ frameAttached(frameId, parentFrameId) {
99
+ const parentFrame = parentFrameId ? this._frames.get(parentFrameId) : null;
100
+ if (!parentFrame) {
101
+ if (this._mainFrame) {
102
+ this._frames.delete(this._mainFrame._id);
103
+ this._mainFrame._id = frameId;
104
+ } else {
105
+ (0, import_utils.assert)(!this._frames.has(frameId));
106
+ this._mainFrame = new Frame(this._page, frameId, parentFrame);
107
+ }
108
+ this._frames.set(frameId, this._mainFrame);
109
+ return this._mainFrame;
110
+ } else {
111
+ (0, import_utils.assert)(!this._frames.has(frameId));
112
+ const frame = new Frame(this._page, frameId, parentFrame);
113
+ this._frames.set(frameId, frame);
114
+ this._page.emit(import_page.Page.Events.FrameAttached, frame);
115
+ return frame;
116
+ }
117
+ }
118
+ async waitForSignalsCreatedBy(progress, waitAfter, action) {
119
+ if (!waitAfter)
120
+ return action();
121
+ const barrier = new SignalBarrier(progress);
122
+ this._signalBarriers.add(barrier);
123
+ try {
124
+ const result = await action();
125
+ await progress.race(this._page.delegate.inputActionEpilogue());
126
+ await barrier.waitFor();
127
+ await new Promise((0, import_utils.makeWaitForNextTask)());
128
+ return result;
129
+ } finally {
130
+ this._signalBarriers.delete(barrier);
131
+ }
132
+ }
133
+ frameWillPotentiallyRequestNavigation() {
134
+ for (const barrier of this._signalBarriers)
135
+ barrier.retain();
136
+ }
137
+ frameDidPotentiallyRequestNavigation() {
138
+ for (const barrier of this._signalBarriers)
139
+ barrier.release();
140
+ }
141
+ frameRequestedNavigation(frameId, documentId) {
142
+ const frame = this._frames.get(frameId);
143
+ if (!frame)
144
+ return;
145
+ for (const barrier of this._signalBarriers)
146
+ barrier.addFrameNavigation(frame);
147
+ if (frame.pendingDocument() && frame.pendingDocument().documentId === documentId) {
148
+ return;
149
+ }
150
+ const request = documentId ? Array.from(frame._inflightRequests).find((request2) => request2._documentId === documentId) : void 0;
151
+ frame.setPendingDocument({ documentId, request });
152
+ }
153
+ frameCommittedNewDocumentNavigation(frameId, url, name, documentId, initial) {
154
+ const frame = this._frames.get(frameId);
155
+ this.removeChildFramesRecursively(frame);
156
+ this.clearWebSockets(frame);
157
+ frame._url = url;
158
+ frame._name = name;
159
+ let keepPending;
160
+ const pendingDocument = frame.pendingDocument();
161
+ if (pendingDocument) {
162
+ if (pendingDocument.documentId === void 0) {
163
+ pendingDocument.documentId = documentId;
164
+ }
165
+ if (pendingDocument.documentId === documentId) {
166
+ frame._currentDocument = pendingDocument;
167
+ } else {
168
+ keepPending = pendingDocument;
169
+ frame._currentDocument = { documentId, request: void 0 };
170
+ }
171
+ frame.setPendingDocument(void 0);
172
+ } else {
173
+ frame._currentDocument = { documentId, request: void 0 };
174
+ }
175
+ frame._onClearLifecycle();
176
+ const navigationEvent = { url, name, newDocument: frame._currentDocument, isPublic: true };
177
+ this._fireInternalFrameNavigation(frame, navigationEvent);
178
+ if (!initial) {
179
+ import_debugLogger.debugLogger.log("api", ` navigated to "${url}"`);
180
+ this._page.frameNavigatedToNewDocument(frame);
181
+ }
182
+ frame.setPendingDocument(keepPending);
183
+ }
184
+ frameCommittedSameDocumentNavigation(frameId, url) {
185
+ const frame = this._frames.get(frameId);
186
+ if (!frame)
187
+ return;
188
+ const pending = frame.pendingDocument();
189
+ if (pending && pending.documentId === void 0 && pending.request === void 0) {
190
+ frame.setPendingDocument(void 0);
191
+ }
192
+ frame._url = url;
193
+ const navigationEvent = { url, name: frame._name, isPublic: true };
194
+ this._fireInternalFrameNavigation(frame, navigationEvent);
195
+ import_debugLogger.debugLogger.log("api", ` navigated to "${url}"`);
196
+ }
197
+ frameAbortedNavigation(frameId, errorText, documentId) {
198
+ const frame = this._frames.get(frameId);
199
+ if (!frame || !frame.pendingDocument())
200
+ return;
201
+ if (documentId !== void 0 && frame.pendingDocument().documentId !== documentId)
202
+ return;
203
+ const navigationEvent = {
204
+ url: frame._url,
205
+ name: frame._name,
206
+ newDocument: frame.pendingDocument(),
207
+ error: new NavigationAbortedError(documentId, errorText),
208
+ isPublic: !(documentId && frame._redirectedNavigations.has(documentId))
209
+ };
210
+ frame.setPendingDocument(void 0);
211
+ this._fireInternalFrameNavigation(frame, navigationEvent);
212
+ }
213
+ frameDetached(frameId) {
214
+ const frame = this._frames.get(frameId);
215
+ if (frame) {
216
+ this._removeFramesRecursively(frame);
217
+ this._page.mainFrame()._recalculateNetworkIdle();
218
+ }
219
+ }
220
+ frameLifecycleEvent(frameId, event) {
221
+ const frame = this._frames.get(frameId);
222
+ if (frame)
223
+ frame._onLifecycleEvent(event);
224
+ }
225
+ requestStarted(request, route) {
226
+ const frame = request.frame();
227
+ this._inflightRequestStarted(request);
228
+ if (request._documentId)
229
+ frame.setPendingDocument({ documentId: request._documentId, request });
230
+ if (request._isFavicon) {
231
+ route?.abort("aborted").catch(() => {
232
+ });
233
+ return;
234
+ }
235
+ this._page.addNetworkRequest(request);
236
+ this._page.emitOnContext(import_browserContext.BrowserContext.Events.Request, request);
237
+ if (route)
238
+ new network.Route(request, route).handle([...this._page.requestInterceptors, ...this._page.browserContext.requestInterceptors]);
239
+ }
240
+ requestReceivedResponse(response) {
241
+ if (response.request()._isFavicon)
242
+ return;
243
+ this._page.emitOnContext(import_browserContext.BrowserContext.Events.Response, response);
244
+ }
245
+ reportRequestFinished(request, response) {
246
+ this._inflightRequestFinished(request);
247
+ if (request._isFavicon)
248
+ return;
249
+ this._page.emitOnContext(import_browserContext.BrowserContext.Events.RequestFinished, { request, response });
250
+ }
251
+ requestFailed(request, canceled) {
252
+ const frame = request.frame();
253
+ this._inflightRequestFinished(request);
254
+ if (frame.pendingDocument() && frame.pendingDocument().request === request) {
255
+ let errorText = request.failure().errorText;
256
+ if (canceled)
257
+ errorText += "; maybe frame was detached?";
258
+ this.frameAbortedNavigation(frame._id, errorText, frame.pendingDocument().documentId);
259
+ }
260
+ if (request._isFavicon)
261
+ return;
262
+ this._page.emitOnContext(import_browserContext.BrowserContext.Events.RequestFailed, request);
263
+ }
264
+ removeChildFramesRecursively(frame) {
265
+ for (const child of frame.childFrames())
266
+ this._removeFramesRecursively(child);
267
+ }
268
+ _removeFramesRecursively(frame) {
269
+ this.removeChildFramesRecursively(frame);
270
+ frame._onDetached();
271
+ this._frames.delete(frame._id);
272
+ if (!this._page.isClosed())
273
+ this._page.emit(import_page.Page.Events.FrameDetached, frame);
274
+ }
275
+ _inflightRequestFinished(request) {
276
+ const frame = request.frame();
277
+ if (request._isFavicon)
278
+ return;
279
+ if (!frame._inflightRequests.has(request))
280
+ return;
281
+ frame._inflightRequests.delete(request);
282
+ if (frame._inflightRequests.size === 0)
283
+ frame._startNetworkIdleTimer();
284
+ }
285
+ _inflightRequestStarted(request) {
286
+ const frame = request.frame();
287
+ if (request._isFavicon)
288
+ return;
289
+ frame._inflightRequests.add(request);
290
+ if (frame._inflightRequests.size === 1)
291
+ frame._stopNetworkIdleTimer();
292
+ }
293
+ interceptConsoleMessage(message) {
294
+ if (message.type() !== "debug")
295
+ return false;
296
+ const tag = message.text();
297
+ const handler = this._consoleMessageTags.get(tag);
298
+ if (!handler)
299
+ return false;
300
+ this._consoleMessageTags.delete(tag);
301
+ handler();
302
+ return true;
303
+ }
304
+ clearWebSockets(frame) {
305
+ if (frame.parentFrame())
306
+ return;
307
+ this._webSockets.clear();
308
+ }
309
+ onWebSocketCreated(requestId, url) {
310
+ const ws = new network.WebSocket(this._page, url);
311
+ this._webSockets.set(requestId, ws);
312
+ }
313
+ onWebSocketRequest(requestId) {
314
+ const ws = this._webSockets.get(requestId);
315
+ if (ws && ws.markAsNotified())
316
+ this._page.emit(import_page.Page.Events.WebSocket, ws);
317
+ }
318
+ onWebSocketResponse(requestId, status, statusText) {
319
+ const ws = this._webSockets.get(requestId);
320
+ if (status < 400)
321
+ return;
322
+ if (ws)
323
+ ws.error(`${statusText}: ${status}`);
324
+ }
325
+ onWebSocketFrameSent(requestId, opcode, data) {
326
+ const ws = this._webSockets.get(requestId);
327
+ if (ws)
328
+ ws.frameSent(opcode, data);
329
+ }
330
+ webSocketFrameReceived(requestId, opcode, data) {
331
+ const ws = this._webSockets.get(requestId);
332
+ if (ws)
333
+ ws.frameReceived(opcode, data);
334
+ }
335
+ webSocketClosed(requestId) {
336
+ const ws = this._webSockets.get(requestId);
337
+ if (ws)
338
+ ws.closed();
339
+ this._webSockets.delete(requestId);
340
+ }
341
+ webSocketError(requestId, errorMessage) {
342
+ const ws = this._webSockets.get(requestId);
343
+ if (ws)
344
+ ws.error(errorMessage);
345
+ }
346
+ _fireInternalFrameNavigation(frame, event) {
347
+ frame.emit(Frame.Events.InternalNavigation, event);
348
+ }
349
+ }
350
+ class Frame extends import_instrumentation.SdkObject {
351
+ constructor(page, id, parentFrame) {
352
+ super(page, "frame");
353
+ this._firedLifecycleEvents = /* @__PURE__ */ new Set();
354
+ this._firedNetworkIdleSelf = false;
355
+ this._url = "";
356
+ this._contextData = /* @__PURE__ */ new Map();
357
+ this._childFrames = /* @__PURE__ */ new Set();
358
+ this._name = "";
359
+ this._inflightRequests = /* @__PURE__ */ new Set();
360
+ this._setContentCounter = 0;
361
+ this._detachedScope = new import_utils.LongStandingScope();
362
+ this._raceAgainstEvaluationStallingEventsPromises = /* @__PURE__ */ new Set();
363
+ this._redirectedNavigations = /* @__PURE__ */ new Map();
364
+ this.attribution.frame = this;
365
+ this._id = id;
366
+ this._page = page;
367
+ this._parentFrame = parentFrame;
368
+ this._currentDocument = { documentId: void 0, request: void 0 };
369
+ this.selectors = new import_frameSelectors.FrameSelectors(this);
370
+ this._contextData.set("main", { contextPromise: new import_manualPromise.ManualPromise(), context: null });
371
+ this._contextData.set("utility", { contextPromise: new import_manualPromise.ManualPromise(), context: null });
372
+ this._setContext("main", null);
373
+ this._setContext("utility", null);
374
+ if (this._parentFrame)
375
+ this._parentFrame._childFrames.add(this);
376
+ this._firedLifecycleEvents.add("commit");
377
+ if (id !== kDummyFrameId)
378
+ this._startNetworkIdleTimer();
379
+ }
380
+ static {
381
+ this.Events = {
382
+ InternalNavigation: "internalnavigation",
383
+ AddLifecycle: "addlifecycle",
384
+ RemoveLifecycle: "removelifecycle"
385
+ };
386
+ }
387
+ isDetached() {
388
+ return this._detachedScope.isClosed();
389
+ }
390
+ _onLifecycleEvent(event) {
391
+ if (this._firedLifecycleEvents.has(event))
392
+ return;
393
+ this._firedLifecycleEvents.add(event);
394
+ this.emit(Frame.Events.AddLifecycle, event);
395
+ if (this === this._page.mainFrame() && this._url !== "about:blank")
396
+ import_debugLogger.debugLogger.log("api", ` "${event}" event fired`);
397
+ this._page.mainFrame()._recalculateNetworkIdle();
398
+ }
399
+ _onClearLifecycle() {
400
+ for (const event of this._firedLifecycleEvents)
401
+ this.emit(Frame.Events.RemoveLifecycle, event);
402
+ this._firedLifecycleEvents.clear();
403
+ this._inflightRequests = new Set(Array.from(this._inflightRequests).filter((request) => request === this._currentDocument.request));
404
+ this._stopNetworkIdleTimer();
405
+ if (this._inflightRequests.size === 0)
406
+ this._startNetworkIdleTimer();
407
+ this._page.mainFrame()._recalculateNetworkIdle(this);
408
+ this._onLifecycleEvent("commit");
409
+ }
410
+ setPendingDocument(documentInfo) {
411
+ this._pendingDocument = documentInfo;
412
+ if (documentInfo)
413
+ this._invalidateNonStallingEvaluations("Navigation interrupted the evaluation");
414
+ }
415
+ pendingDocument() {
416
+ return this._pendingDocument;
417
+ }
418
+ _invalidateNonStallingEvaluations(message) {
419
+ if (!this._raceAgainstEvaluationStallingEventsPromises.size)
420
+ return;
421
+ const error = new Error(message);
422
+ for (const promise of this._raceAgainstEvaluationStallingEventsPromises)
423
+ promise.reject(error);
424
+ }
425
+ async raceAgainstEvaluationStallingEvents(cb) {
426
+ if (this._pendingDocument)
427
+ throw new Error("Frame is currently attempting a navigation");
428
+ if (this._page.browserContext.dialogManager.hasOpenDialogsForPage(this._page))
429
+ throw new Error("Open JavaScript dialog prevents evaluation");
430
+ const promise = new import_manualPromise.ManualPromise();
431
+ this._raceAgainstEvaluationStallingEventsPromises.add(promise);
432
+ try {
433
+ return await Promise.race([
434
+ cb(),
435
+ promise
436
+ ]);
437
+ } finally {
438
+ this._raceAgainstEvaluationStallingEventsPromises.delete(promise);
439
+ }
440
+ }
441
+ nonStallingRawEvaluateInExistingMainContext(expression) {
442
+ return this.raceAgainstEvaluationStallingEvents(() => {
443
+ const context = this._existingMainContext();
444
+ if (!context)
445
+ throw new Error("Frame does not yet have a main execution context");
446
+ return context.rawEvaluateJSON(expression);
447
+ });
448
+ }
449
+ nonStallingEvaluateInExistingContext(expression, world) {
450
+ return this.raceAgainstEvaluationStallingEvents(() => {
451
+ const context = this._contextData.get(world)?.context;
452
+ if (!context)
453
+ throw new Error("Frame does not yet have the execution context");
454
+ return context.evaluateExpression(expression, { isFunction: false });
455
+ });
456
+ }
457
+ _recalculateNetworkIdle(frameThatAllowsRemovingNetworkIdle) {
458
+ let isNetworkIdle = this._firedNetworkIdleSelf;
459
+ for (const child of this._childFrames) {
460
+ child._recalculateNetworkIdle(frameThatAllowsRemovingNetworkIdle);
461
+ if (!child._firedLifecycleEvents.has("networkidle"))
462
+ isNetworkIdle = false;
463
+ }
464
+ if (isNetworkIdle && !this._firedLifecycleEvents.has("networkidle")) {
465
+ this._firedLifecycleEvents.add("networkidle");
466
+ this.emit(Frame.Events.AddLifecycle, "networkidle");
467
+ if (this === this._page.mainFrame() && this._url !== "about:blank")
468
+ import_debugLogger.debugLogger.log("api", ` "networkidle" event fired`);
469
+ }
470
+ if (frameThatAllowsRemovingNetworkIdle !== this && this._firedLifecycleEvents.has("networkidle") && !isNetworkIdle) {
471
+ this._firedLifecycleEvents.delete("networkidle");
472
+ this.emit(Frame.Events.RemoveLifecycle, "networkidle");
473
+ }
474
+ }
475
+ async raceNavigationAction(progress, action) {
476
+ return import_utils.LongStandingScope.raceMultiple([
477
+ this._detachedScope,
478
+ this._page.openScope
479
+ ], action().catch((e) => {
480
+ if (e instanceof NavigationAbortedError && e.documentId) {
481
+ const data = this._redirectedNavigations.get(e.documentId);
482
+ if (data) {
483
+ progress.log(`waiting for redirected navigation to "${data.url}"`);
484
+ return progress.race(data.gotoPromise);
485
+ }
486
+ }
487
+ throw e;
488
+ }));
489
+ }
490
+ redirectNavigation(url, documentId, referer) {
491
+ const controller = new import_progress.ProgressController();
492
+ const data = {
493
+ url,
494
+ gotoPromise: controller.run((progress) => this.gotoImpl(progress, url, { referer }), 0)
495
+ };
496
+ this._redirectedNavigations.set(documentId, data);
497
+ data.gotoPromise.finally(() => this._redirectedNavigations.delete(documentId));
498
+ }
499
+ async goto(progress, url, options = {}) {
500
+ const constructedNavigationURL = (0, import_utils.constructURLBasedOnBaseURL)(this._page.browserContext._options.baseURL, url);
501
+ return this.raceNavigationAction(progress, async () => this.gotoImpl(progress, constructedNavigationURL, options));
502
+ }
503
+ async gotoImpl(progress, url, options) {
504
+ const waitUntil = verifyLifecycle("waitUntil", options.waitUntil === void 0 ? "load" : options.waitUntil);
505
+ progress.log(`navigating to "${url}", waiting until "${waitUntil}"`);
506
+ const headers = this._page.extraHTTPHeaders() || [];
507
+ const refererHeader = headers.find((h) => h.name.toLowerCase() === "referer");
508
+ let referer = refererHeader ? refererHeader.value : void 0;
509
+ if (options.referer !== void 0) {
510
+ if (referer !== void 0 && referer !== options.referer)
511
+ throw new Error('"referer" is already specified as extra HTTP header');
512
+ referer = options.referer;
513
+ }
514
+ url = import_helper.helper.completeUserURL(url);
515
+ const navigationEvents = [];
516
+ const collectNavigations = (arg) => navigationEvents.push(arg);
517
+ this.on(Frame.Events.InternalNavigation, collectNavigations);
518
+ const navigateResult = await progress.race(this._page.delegate.navigateFrame(this, url, referer)).finally(
519
+ () => this.off(Frame.Events.InternalNavigation, collectNavigations)
520
+ );
521
+ let event;
522
+ if (navigateResult.newDocumentId) {
523
+ const predicate = (event2) => {
524
+ return event2.newDocument && (event2.newDocument.documentId === navigateResult.newDocumentId || !event2.error);
525
+ };
526
+ const events = navigationEvents.filter(predicate);
527
+ if (events.length)
528
+ event = events[0];
529
+ else
530
+ event = await import_helper.helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, predicate).promise;
531
+ if (event.newDocument.documentId !== navigateResult.newDocumentId) {
532
+ throw new NavigationAbortedError(navigateResult.newDocumentId, `Navigation to "${url}" is interrupted by another navigation to "${event.url}"`);
533
+ }
534
+ if (event.error)
535
+ throw event.error;
536
+ } else {
537
+ const predicate = (e) => !e.newDocument;
538
+ const events = navigationEvents.filter(predicate);
539
+ if (events.length)
540
+ event = events[0];
541
+ else
542
+ event = await import_helper.helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, predicate).promise;
543
+ }
544
+ if (!this._firedLifecycleEvents.has(waitUntil))
545
+ await import_helper.helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, (e) => e === waitUntil).promise;
546
+ const request = event.newDocument ? event.newDocument.request : void 0;
547
+ const response = request ? progress.race(request._finalRequest().response()) : null;
548
+ return response;
549
+ }
550
+ async _waitForNavigation(progress, requiresNewDocument, options) {
551
+ const waitUntil = verifyLifecycle("waitUntil", options.waitUntil === void 0 ? "load" : options.waitUntil);
552
+ progress.log(`waiting for navigation until "${waitUntil}"`);
553
+ const navigationEvent = await import_helper.helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, (event) => {
554
+ if (event.error)
555
+ return true;
556
+ if (requiresNewDocument && !event.newDocument)
557
+ return false;
558
+ progress.log(` navigated to "${this._url}"`);
559
+ return true;
560
+ }).promise;
561
+ if (navigationEvent.error)
562
+ throw navigationEvent.error;
563
+ if (!this._firedLifecycleEvents.has(waitUntil))
564
+ await import_helper.helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, (e) => e === waitUntil).promise;
565
+ const request = navigationEvent.newDocument ? navigationEvent.newDocument.request : void 0;
566
+ return request ? progress.race(request._finalRequest().response()) : null;
567
+ }
568
+ async _waitForLoadState(progress, state) {
569
+ const waitUntil = verifyLifecycle("state", state);
570
+ if (!this._firedLifecycleEvents.has(waitUntil))
571
+ await import_helper.helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, (e) => e === waitUntil).promise;
572
+ }
573
+ async frameElement() {
574
+ return this._page.delegate.getFrameElement(this);
575
+ }
576
+ _context(world) {
577
+ return this._contextData.get(world).contextPromise.then((contextOrDestroyedReason) => {
578
+ if (contextOrDestroyedReason instanceof js.ExecutionContext)
579
+ return contextOrDestroyedReason;
580
+ throw new Error(contextOrDestroyedReason.destroyedReason);
581
+ });
582
+ }
583
+ _mainContext() {
584
+ return this._context("main");
585
+ }
586
+ _existingMainContext() {
587
+ return this._contextData.get("main")?.context || null;
588
+ }
589
+ _utilityContext() {
590
+ return this._context("utility");
591
+ }
592
+ async evaluateExpression(expression, options = {}, arg) {
593
+ const context = await this._context(options.world ?? "main");
594
+ const value = await context.evaluateExpression(expression, options, arg);
595
+ return value;
596
+ }
597
+ async evaluateExpressionHandle(expression, options = {}, arg) {
598
+ const context = await this._context(options.world ?? "main");
599
+ const value = await context.evaluateExpressionHandle(expression, options, arg);
600
+ return value;
601
+ }
602
+ async querySelector(selector, options) {
603
+ import_debugLogger.debugLogger.log("api", ` finding element using the selector "${selector}"`);
604
+ return this.selectors.query(selector, options);
605
+ }
606
+ async waitForSelector(progress, selector, performActionPreChecksAndLog, options, scope) {
607
+ if (options.visibility)
608
+ throw new Error("options.visibility is not supported, did you mean options.state?");
609
+ if (options.waitFor && options.waitFor !== "visible")
610
+ throw new Error("options.waitFor is not supported, did you mean options.state?");
611
+ const { state = "visible" } = options;
612
+ if (!["attached", "detached", "visible", "hidden"].includes(state))
613
+ throw new Error(`state: expected one of (attached|detached|visible|hidden)`);
614
+ if (performActionPreChecksAndLog)
615
+ progress.log(`waiting for ${this._asLocator(selector)}${state === "attached" ? "" : " to be " + state}`);
616
+ const promise = this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling) => {
617
+ if (performActionPreChecksAndLog)
618
+ await this._page.performActionPreChecks(progress);
619
+ const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector, options, scope));
620
+ if (!resolved) {
621
+ if (state === "hidden" || state === "detached")
622
+ return null;
623
+ return continuePolling;
624
+ }
625
+ const result = await progress.race(resolved.injected.evaluateHandle((injected, { info, root }) => {
626
+ if (root && !root.isConnected)
627
+ throw injected.createStacklessError("Element is not attached to the DOM");
628
+ const elements = injected.querySelectorAll(info.parsed, root || document);
629
+ const element2 = elements[0];
630
+ const visible2 = element2 ? injected.utils.isElementVisible(element2) : false;
631
+ let log2 = "";
632
+ if (elements.length > 1) {
633
+ if (info.strict)
634
+ throw injected.strictModeViolationError(info.parsed, elements);
635
+ log2 = ` locator resolved to ${elements.length} elements. Proceeding with the first one: ${injected.previewNode(elements[0])}`;
636
+ } else if (element2) {
637
+ log2 = ` locator resolved to ${visible2 ? "visible" : "hidden"} ${injected.previewNode(element2)}`;
638
+ }
639
+ return { log: log2, element: element2, visible: visible2, attached: !!element2 };
640
+ }, { info: resolved.info, root: resolved.frame === this ? scope : void 0 }));
641
+ const { log, visible, attached } = await progress.race(result.evaluate((r) => ({ log: r.log, visible: r.visible, attached: r.attached })));
642
+ if (log)
643
+ progress.log(log);
644
+ const success = { attached, detached: !attached, visible, hidden: !visible }[state];
645
+ if (!success) {
646
+ result.dispose();
647
+ return continuePolling;
648
+ }
649
+ if (options.omitReturnValue) {
650
+ result.dispose();
651
+ return null;
652
+ }
653
+ const element = state === "attached" || state === "visible" ? await progress.race(result.evaluateHandle((r) => r.element)) : null;
654
+ result.dispose();
655
+ if (!element)
656
+ return null;
657
+ if (options.__testHookBeforeAdoptNode)
658
+ await progress.race(options.__testHookBeforeAdoptNode());
659
+ try {
660
+ const mainContext = await progress.race(resolved.frame._mainContext());
661
+ return await progress.race(element._adoptTo(mainContext));
662
+ } catch (e) {
663
+ return continuePolling;
664
+ }
665
+ });
666
+ return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
667
+ }
668
+ async dispatchEvent(progress, selector, type, eventInit = {}, options, scope) {
669
+ await this._callOnElementOnceMatches(progress, selector, (injectedScript, element, data) => {
670
+ injectedScript.dispatchEvent(element, data.type, data.eventInit);
671
+ }, { type, eventInit }, { mainWorld: true, ...options }, scope);
672
+ }
673
+ async evalOnSelector(selector, strict, expression, isFunction, arg, scope) {
674
+ const handle = await this.selectors.query(selector, { strict }, scope);
675
+ if (!handle)
676
+ throw new Error(`Failed to find element matching selector "${selector}"`);
677
+ const result = await handle.evaluateExpression(expression, { isFunction }, arg);
678
+ handle.dispose();
679
+ return result;
680
+ }
681
+ async evalOnSelectorAll(selector, expression, isFunction, arg, scope) {
682
+ const arrayHandle = await this.selectors.queryArrayInMainWorld(selector, scope);
683
+ const result = await arrayHandle.evaluateExpression(expression, { isFunction }, arg);
684
+ arrayHandle.dispose();
685
+ return result;
686
+ }
687
+ async maskSelectors(selectors, color) {
688
+ const context = await this._utilityContext();
689
+ const injectedScript = await context.injectedScript();
690
+ await injectedScript.evaluate((injected, { parsed, color: color2 }) => {
691
+ injected.maskSelectors(parsed, color2);
692
+ }, { parsed: selectors, color });
693
+ }
694
+ async querySelectorAll(selector) {
695
+ return this.selectors.queryAll(selector);
696
+ }
697
+ async queryCount(selector, options) {
698
+ try {
699
+ return await this.selectors.queryCount(selector, options);
700
+ } catch (e) {
701
+ if (this.isNonRetriableError(e))
702
+ throw e;
703
+ return 0;
704
+ }
705
+ }
706
+ async content() {
707
+ try {
708
+ const context = await this._utilityContext();
709
+ return await context.evaluate(() => {
710
+ let retVal = "";
711
+ if (document.doctype)
712
+ retVal = new XMLSerializer().serializeToString(document.doctype);
713
+ if (document.documentElement)
714
+ retVal += document.documentElement.outerHTML;
715
+ return retVal;
716
+ });
717
+ } catch (e) {
718
+ if (this.isNonRetriableError(e))
719
+ throw e;
720
+ throw new Error(`Unable to retrieve content because the page is navigating and changing the content.`);
721
+ }
722
+ }
723
+ async setContent(progress, html, options) {
724
+ const tag = `--playwright--set--content--${this._id}--${++this._setContentCounter}--`;
725
+ await this.raceNavigationAction(progress, async () => {
726
+ const waitUntil = options.waitUntil === void 0 ? "load" : options.waitUntil;
727
+ progress.log(`setting frame content, waiting until "${waitUntil}"`);
728
+ const context = await progress.race(this._utilityContext());
729
+ const tagPromise = new import_manualPromise.ManualPromise();
730
+ this._page.frameManager._consoleMessageTags.set(tag, () => {
731
+ this._onClearLifecycle();
732
+ tagPromise.resolve();
733
+ });
734
+ const lifecyclePromise = progress.race(tagPromise).then(() => this._waitForLoadState(progress, waitUntil));
735
+ const contentPromise = progress.race(context.evaluate(({ html: html2, tag: tag2 }) => {
736
+ document.open();
737
+ console.debug(tag2);
738
+ document.write(html2);
739
+ document.close();
740
+ }, { html, tag }));
741
+ await Promise.all([contentPromise, lifecyclePromise]);
742
+ return null;
743
+ }).finally(() => {
744
+ this._page.frameManager._consoleMessageTags.delete(tag);
745
+ });
746
+ }
747
+ name() {
748
+ return this._name || "";
749
+ }
750
+ url() {
751
+ return this._url;
752
+ }
753
+ origin() {
754
+ if (!this._url.startsWith("http"))
755
+ return;
756
+ return network.parseURL(this._url)?.origin;
757
+ }
758
+ parentFrame() {
759
+ return this._parentFrame;
760
+ }
761
+ childFrames() {
762
+ return Array.from(this._childFrames);
763
+ }
764
+ async addScriptTag(params) {
765
+ const {
766
+ url = null,
767
+ content = null,
768
+ type = ""
769
+ } = params;
770
+ if (!url && !content)
771
+ throw new Error("Provide an object with a `url`, `path` or `content` property");
772
+ const context = await this._mainContext();
773
+ return this._raceWithCSPError(async () => {
774
+ if (url !== null)
775
+ return (await context.evaluateHandle(addScriptUrl, { url, type })).asElement();
776
+ const result = (await context.evaluateHandle(addScriptContent, { content, type })).asElement();
777
+ if (this._page.delegate.cspErrorsAsynchronousForInlineScripts)
778
+ await context.evaluate(() => true);
779
+ return result;
780
+ });
781
+ async function addScriptUrl(params2) {
782
+ const script = document.createElement("script");
783
+ script.src = params2.url;
784
+ if (params2.type)
785
+ script.type = params2.type;
786
+ const promise = new Promise((res, rej) => {
787
+ script.onload = res;
788
+ script.onerror = (e) => rej(typeof e === "string" ? new Error(e) : new Error(`Failed to load script at ${script.src}`));
789
+ });
790
+ document.head.appendChild(script);
791
+ await promise;
792
+ return script;
793
+ }
794
+ function addScriptContent(params2) {
795
+ const script = document.createElement("script");
796
+ script.type = params2.type || "text/javascript";
797
+ script.text = params2.content;
798
+ let error = null;
799
+ script.onerror = (e) => error = e;
800
+ document.head.appendChild(script);
801
+ if (error)
802
+ throw error;
803
+ return script;
804
+ }
805
+ }
806
+ async addStyleTag(params) {
807
+ const {
808
+ url = null,
809
+ content = null
810
+ } = params;
811
+ if (!url && !content)
812
+ throw new Error("Provide an object with a `url`, `path` or `content` property");
813
+ const context = await this._mainContext();
814
+ return this._raceWithCSPError(async () => {
815
+ if (url !== null)
816
+ return (await context.evaluateHandle(addStyleUrl, url)).asElement();
817
+ return (await context.evaluateHandle(addStyleContent, content)).asElement();
818
+ });
819
+ async function addStyleUrl(url2) {
820
+ const link = document.createElement("link");
821
+ link.rel = "stylesheet";
822
+ link.href = url2;
823
+ const promise = new Promise((res, rej) => {
824
+ link.onload = res;
825
+ link.onerror = rej;
826
+ });
827
+ document.head.appendChild(link);
828
+ await promise;
829
+ return link;
830
+ }
831
+ async function addStyleContent(content2) {
832
+ const style = document.createElement("style");
833
+ style.type = "text/css";
834
+ style.appendChild(document.createTextNode(content2));
835
+ const promise = new Promise((res, rej) => {
836
+ style.onload = res;
837
+ style.onerror = rej;
838
+ });
839
+ document.head.appendChild(style);
840
+ await promise;
841
+ return style;
842
+ }
843
+ }
844
+ async _raceWithCSPError(func) {
845
+ const listeners = [];
846
+ let result;
847
+ let error;
848
+ let cspMessage;
849
+ const actionPromise = func().then((r) => result = r).catch((e) => error = e);
850
+ const errorPromise = new Promise((resolve) => {
851
+ listeners.push(import_eventsHelper.eventsHelper.addEventListener(this._page.browserContext, import_browserContext.BrowserContext.Events.Console, (message) => {
852
+ if (message.page() !== this._page || message.type() !== "error")
853
+ return;
854
+ if (message.text().includes("Content-Security-Policy") || message.text().includes("Content Security Policy")) {
855
+ cspMessage = message;
856
+ resolve();
857
+ }
858
+ }));
859
+ });
860
+ await Promise.race([actionPromise, errorPromise]);
861
+ import_eventsHelper.eventsHelper.removeEventListeners(listeners);
862
+ if (cspMessage)
863
+ throw new Error(cspMessage.text());
864
+ if (error)
865
+ throw error;
866
+ return result;
867
+ }
868
+ async retryWithProgressAndTimeouts(progress, timeouts, action) {
869
+ const continuePolling = Symbol("continuePolling");
870
+ timeouts = [0, ...timeouts];
871
+ let timeoutIndex = 0;
872
+ while (true) {
873
+ const timeout = timeouts[Math.min(timeoutIndex++, timeouts.length - 1)];
874
+ if (timeout) {
875
+ const actionPromise = new Promise((f) => setTimeout(f, timeout));
876
+ await progress.race(import_utils.LongStandingScope.raceMultiple([
877
+ this._page.openScope,
878
+ this._detachedScope
879
+ ], actionPromise));
880
+ }
881
+ try {
882
+ const result = await action(continuePolling);
883
+ if (result === continuePolling)
884
+ continue;
885
+ return result;
886
+ } catch (e) {
887
+ if (this.isNonRetriableError(e))
888
+ throw e;
889
+ continue;
890
+ }
891
+ }
892
+ }
893
+ isNonRetriableError(e) {
894
+ if ((0, import_progress.isAbortError)(e))
895
+ return true;
896
+ if (js.isJavaScriptErrorInEvaluate(e) || (0, import_protocolError.isSessionClosedError)(e))
897
+ return true;
898
+ if (dom.isNonRecoverableDOMError(e) || (0, import_selectorParser.isInvalidSelectorError)(e))
899
+ return true;
900
+ if (this.isDetached())
901
+ return true;
902
+ return false;
903
+ }
904
+ async _attemptHealingRetry(progress, selector, actionName, error, retryOperation) {
905
+ if (!(error instanceof import_errors.TimeoutError || error instanceof Error && error.message.includes("Timeout")))
906
+ return void 0;
907
+ const healedSelector = await (0, import_healingService.attemptAutohealLocator)({
908
+ frame: this,
909
+ selector,
910
+ actionName,
911
+ error
912
+ });
913
+ if (!healedSelector)
914
+ return void 0;
915
+ progress.log(`[Auto-Healing] Retrying with healed selector: ${healedSelector}`);
916
+ const healingTimeout = (0, import_healingService.getHealingConfig)().timeout;
917
+ const healingController = new import_progress.ProgressController(progress.metadata);
918
+ return await healingController.run(async (healingProgress) => {
919
+ return await retryOperation(healingProgress, healedSelector);
920
+ }, healingTimeout);
921
+ }
922
+ async _retryWithProgressIfNotConnectedWithHealing(progress, selector, strict, performActionPreChecks, action, actionName, autoHeal) {
923
+ try {
924
+ return await this._retryWithProgressIfNotConnected(progress, selector, strict, performActionPreChecks, action);
925
+ } catch (error) {
926
+ const isAutoHealEnabled = autoHeal ?? (0, import_healingService.isHealingEnabled)();
927
+ if (!isAutoHealEnabled)
928
+ throw error;
929
+ const healedResult = await this._attemptHealingRetry(
930
+ progress,
931
+ selector,
932
+ actionName,
933
+ error,
934
+ async (healingProgress, healedSelector) => {
935
+ return await this._retryWithProgressIfNotConnected(healingProgress, healedSelector, strict, performActionPreChecks, action);
936
+ }
937
+ );
938
+ if (healedResult !== void 0)
939
+ return healedResult;
940
+ throw error;
941
+ }
942
+ }
943
+ async _retryWithProgressIfNotConnected(progress, selector, strict, performActionPreChecks, action) {
944
+ progress.log(`waiting for ${this._asLocator(selector)}`);
945
+ return this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling) => {
946
+ if (performActionPreChecks)
947
+ await this._page.performActionPreChecks(progress);
948
+ const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector, { strict }));
949
+ if (!resolved)
950
+ return continuePolling;
951
+ const result = await progress.race(resolved.injected.evaluateHandle((injected, { info, callId }) => {
952
+ const elements = injected.querySelectorAll(info.parsed, document);
953
+ if (callId)
954
+ injected.markTargetElements(new Set(elements), callId);
955
+ const element2 = elements[0];
956
+ let log2 = "";
957
+ if (elements.length > 1) {
958
+ if (info.strict)
959
+ throw injected.strictModeViolationError(info.parsed, elements);
960
+ log2 = ` locator resolved to ${elements.length} elements. Proceeding with the first one: ${injected.previewNode(elements[0])}`;
961
+ } else if (element2) {
962
+ log2 = ` locator resolved to ${injected.previewNode(element2)}`;
963
+ }
964
+ return { log: log2, success: !!element2, element: element2 };
965
+ }, { info: resolved.info, callId: progress.metadata.id }));
966
+ const { log, success } = await progress.race(result.evaluate((r) => ({ log: r.log, success: r.success })));
967
+ if (log)
968
+ progress.log(log);
969
+ if (!success) {
970
+ result.dispose();
971
+ return continuePolling;
972
+ }
973
+ const element = await progress.race(result.evaluateHandle((r) => r.element));
974
+ result.dispose();
975
+ try {
976
+ const result2 = await action(element, progress);
977
+ if (result2 === "error:notconnected") {
978
+ progress.log("element was detached from the DOM, retrying");
979
+ return continuePolling;
980
+ }
981
+ return result2;
982
+ } finally {
983
+ element?.dispose();
984
+ }
985
+ });
986
+ }
987
+ async rafrafTimeoutScreenshotElementWithProgress(progress, selector, timeout, options) {
988
+ return await this._retryWithProgressIfNotConnected(progress, selector, true, true, async (handle) => {
989
+ await handle._frame.rafrafTimeout(progress, timeout);
990
+ return await this._page.screenshotter.screenshotElement(progress, handle, options);
991
+ });
992
+ }
993
+ async click(progress, selector, options) {
994
+ return dom.assertDone(await this._retryWithProgressIfNotConnectedWithHealing(progress, selector, options.strict, !options.force, (handle, p) => handle._click(p, { ...options, waitAfter: !options.noWaitAfter }), "click", options.autoHeal));
995
+ }
996
+ async dblclick(progress, selector, options) {
997
+ return dom.assertDone(await this._retryWithProgressIfNotConnectedWithHealing(progress, selector, options.strict, !options.force, (handle, p) => handle._dblclick(p, options), "dblclick", options.autoHeal));
998
+ }
999
+ async dragAndDrop(progress, source, target, options) {
1000
+ dom.assertDone(await this._retryWithProgressIfNotConnected(progress, source, options.strict, !options.force, async (handle, p) => {
1001
+ return handle._retryPointerAction(p, "move and down", false, async (point) => {
1002
+ await this._page.mouse.move(p, point.x, point.y);
1003
+ await this._page.mouse.down(p);
1004
+ }, {
1005
+ ...options,
1006
+ waitAfter: "disabled",
1007
+ position: options.sourcePosition
1008
+ });
1009
+ }));
1010
+ dom.assertDone(await this._retryWithProgressIfNotConnected(progress, target, options.strict, false, async (handle, p) => {
1011
+ return handle._retryPointerAction(p, "move and up", false, async (point) => {
1012
+ await this._page.mouse.move(p, point.x, point.y);
1013
+ await this._page.mouse.up(p);
1014
+ }, {
1015
+ ...options,
1016
+ waitAfter: "disabled",
1017
+ position: options.targetPosition
1018
+ });
1019
+ }));
1020
+ }
1021
+ async tap(progress, selector, options) {
1022
+ if (!this._page.browserContext._options.hasTouch)
1023
+ throw new Error("The page does not support tap. Use hasTouch context option to enable touch support.");
1024
+ return dom.assertDone(await this._retryWithProgressIfNotConnectedWithHealing(progress, selector, options.strict, !options.force, (handle, p) => handle._tap(p, options), "tap", options.autoHeal));
1025
+ }
1026
+ async fill(progress, selector, value, options) {
1027
+ return dom.assertDone(await this._retryWithProgressIfNotConnectedWithHealing(progress, selector, options.strict, !options.force, (handle, p) => handle._fill(p, value, options), "fill", options.autoHeal));
1028
+ }
1029
+ async focus(progress, selector, options) {
1030
+ dom.assertDone(await this._retryWithProgressIfNotConnectedWithHealing(progress, selector, options.strict, true, (handle, p) => handle._focus(p), "focus", options.autoHeal));
1031
+ }
1032
+ async blur(progress, selector, options) {
1033
+ dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle, p) => handle._blur(p)));
1034
+ }
1035
+ async resolveSelector(progress, selector, options = {}) {
1036
+ const element = await progress.race(this.selectors.query(selector, options));
1037
+ if (!element)
1038
+ throw new Error(`No element matching ${selector}`);
1039
+ const generated = await progress.race(element.evaluateInUtility(async ([injected, node]) => {
1040
+ return injected.generateSelectorSimple(node);
1041
+ }, {}));
1042
+ if (!generated)
1043
+ throw new Error(`Unable to generate locator for ${selector}`);
1044
+ let frame = element._frame;
1045
+ const result = [generated];
1046
+ while (frame?.parentFrame()) {
1047
+ const frameElement = await progress.race(frame.frameElement());
1048
+ if (frameElement) {
1049
+ const generated2 = await progress.race(frameElement.evaluateInUtility(async ([injected, node]) => {
1050
+ return injected.generateSelectorSimple(node);
1051
+ }, {}));
1052
+ frameElement.dispose();
1053
+ if (generated2 === "error:notconnected" || !generated2)
1054
+ throw new Error(`Unable to generate locator for ${selector}`);
1055
+ result.push(generated2);
1056
+ }
1057
+ frame = frame.parentFrame();
1058
+ }
1059
+ const resolvedSelector = result.reverse().join(" >> internal:control=enter-frame >> ");
1060
+ return { resolvedSelector };
1061
+ }
1062
+ async textContent(progress, selector, options, scope) {
1063
+ return this._callOnElementOnceMatches(progress, selector, (injected, element) => element.textContent, void 0, options, scope);
1064
+ }
1065
+ async innerText(progress, selector, options, scope) {
1066
+ return this._callOnElementOnceMatches(progress, selector, (injectedScript, element) => {
1067
+ if (element.namespaceURI !== "http://www.w3.org/1999/xhtml")
1068
+ throw injectedScript.createStacklessError("Node is not an HTMLElement");
1069
+ return element.innerText;
1070
+ }, void 0, options, scope);
1071
+ }
1072
+ async innerHTML(progress, selector, options, scope) {
1073
+ return this._callOnElementOnceMatches(progress, selector, (injected, element) => element.innerHTML, void 0, options, scope);
1074
+ }
1075
+ async getAttribute(progress, selector, name, options, scope) {
1076
+ return this._callOnElementOnceMatches(progress, selector, (injected, element, data) => element.getAttribute(data.name), { name }, options, scope);
1077
+ }
1078
+ async inputValue(progress, selector, options, scope) {
1079
+ return this._callOnElementOnceMatches(progress, selector, (injectedScript, node) => {
1080
+ const element = injectedScript.retarget(node, "follow-label");
1081
+ if (!element || element.nodeName !== "INPUT" && element.nodeName !== "TEXTAREA" && element.nodeName !== "SELECT")
1082
+ throw injectedScript.createStacklessError("Node is not an <input>, <textarea> or <select> element");
1083
+ return element.value;
1084
+ }, void 0, options, scope);
1085
+ }
1086
+ async highlight(progress, selector) {
1087
+ const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector));
1088
+ if (!resolved)
1089
+ return;
1090
+ return await progress.race(resolved.injected.evaluate((injected, { info }) => {
1091
+ return injected.highlight(info.parsed);
1092
+ }, { info: resolved.info }));
1093
+ }
1094
+ async hideHighlight() {
1095
+ return this.raceAgainstEvaluationStallingEvents(async () => {
1096
+ const context = await this._utilityContext();
1097
+ const injectedScript = await context.injectedScript();
1098
+ return await injectedScript.evaluate((injected) => {
1099
+ return injected.hideHighlight();
1100
+ });
1101
+ });
1102
+ }
1103
+ async _elementState(progress, selector, state, options, scope) {
1104
+ const result = await this._callOnElementOnceMatches(progress, selector, (injected, element, data) => {
1105
+ return injected.elementState(element, data.state);
1106
+ }, { state }, options, scope);
1107
+ if (result.received === "error:notconnected")
1108
+ dom.throwElementIsNotAttached();
1109
+ return result.matches;
1110
+ }
1111
+ async isVisible(progress, selector, options = {}, scope) {
1112
+ progress.log(` checking visibility of ${this._asLocator(selector)}`);
1113
+ return await this.isVisibleInternal(progress, selector, options, scope);
1114
+ }
1115
+ async isVisibleInternal(progress, selector, options = {}, scope) {
1116
+ try {
1117
+ const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector, options, scope));
1118
+ if (!resolved)
1119
+ return false;
1120
+ return await progress.race(resolved.injected.evaluate((injected, { info, root }) => {
1121
+ const element = injected.querySelector(info.parsed, root || document, info.strict);
1122
+ const state = element ? injected.elementState(element, "visible") : { matches: false, received: "error:notconnected" };
1123
+ return state.matches;
1124
+ }, { info: resolved.info, root: resolved.frame === this ? scope : void 0 }));
1125
+ } catch (e) {
1126
+ if (this.isNonRetriableError(e))
1127
+ throw e;
1128
+ return false;
1129
+ }
1130
+ }
1131
+ async isHidden(progress, selector, options = {}, scope) {
1132
+ return !await this.isVisible(progress, selector, options, scope);
1133
+ }
1134
+ async isDisabled(progress, selector, options, scope) {
1135
+ return this._elementState(progress, selector, "disabled", options, scope);
1136
+ }
1137
+ async isEnabled(progress, selector, options, scope) {
1138
+ return this._elementState(progress, selector, "enabled", options, scope);
1139
+ }
1140
+ async isEditable(progress, selector, options, scope) {
1141
+ return this._elementState(progress, selector, "editable", options, scope);
1142
+ }
1143
+ async isChecked(progress, selector, options, scope) {
1144
+ return this._elementState(progress, selector, "checked", options, scope);
1145
+ }
1146
+ async hover(progress, selector, options) {
1147
+ return dom.assertDone(await this._retryWithProgressIfNotConnectedWithHealing(progress, selector, options.strict, !options.force, (handle, p) => handle._hover(p, options), "hover", options.autoHeal));
1148
+ }
1149
+ async selectOption(progress, selector, elements, values, options) {
1150
+ return await this._retryWithProgressIfNotConnectedWithHealing(progress, selector, options.strict, !options.force, (handle, p) => handle._selectOption(p, elements, values, options), "selectOption", options.autoHeal);
1151
+ }
1152
+ async setInputFiles(progress, selector, params) {
1153
+ const inputFileItems = await (0, import_fileUploadUtils.prepareFilesForUpload)(this, params);
1154
+ return dom.assertDone(await this._retryWithProgressIfNotConnectedWithHealing(progress, selector, params.strict, true, (handle, p) => handle._setInputFiles(p, inputFileItems), "setInputFiles", params.autoHeal));
1155
+ }
1156
+ async type(progress, selector, text, options) {
1157
+ return dom.assertDone(await this._retryWithProgressIfNotConnectedWithHealing(progress, selector, options.strict, true, (handle, p) => handle._type(p, text, options), "type", options.autoHeal));
1158
+ }
1159
+ async press(progress, selector, key, options) {
1160
+ return dom.assertDone(await this._retryWithProgressIfNotConnectedWithHealing(progress, selector, options.strict, true, (handle, p) => handle._press(p, key, options), "press", options.autoHeal));
1161
+ }
1162
+ async check(progress, selector, options) {
1163
+ return dom.assertDone(await this._retryWithProgressIfNotConnectedWithHealing(progress, selector, options.strict, !options.force, (handle, p) => handle._setChecked(p, true, options), "check", options.autoHeal));
1164
+ }
1165
+ async uncheck(progress, selector, options) {
1166
+ return dom.assertDone(await this._retryWithProgressIfNotConnectedWithHealing(progress, selector, options.strict, !options.force, (handle, p) => handle._setChecked(p, false, options), "uncheck", options.autoHeal));
1167
+ }
1168
+ async waitForTimeout(progress, timeout) {
1169
+ return progress.wait(timeout);
1170
+ }
1171
+ async ariaSnapshot(progress, selector) {
1172
+ return await this._retryWithProgressIfNotConnected(progress, selector, true, true, (handle, p) => p.race(handle.ariaSnapshot()));
1173
+ }
1174
+ async expect(progress, selector, options, timeout) {
1175
+ progress.log(`${(0, import_utils.renderTitleForCall)(progress.metadata)}${timeout ? ` with timeout ${timeout}ms` : ""}`);
1176
+ const lastIntermediateResult = { isSet: false };
1177
+ const fixupMetadataError = (result) => {
1178
+ if (result.matches === options.isNot)
1179
+ progress.metadata.error = { error: { name: "Expect", message: "Expect failed" } };
1180
+ };
1181
+ try {
1182
+ if (selector)
1183
+ progress.log(`waiting for ${this._asLocator(selector)}`);
1184
+ await this._page.performActionPreChecks(progress);
1185
+ try {
1186
+ const resultOneShot = await this._expectInternal(progress, selector, options, lastIntermediateResult, true);
1187
+ if (resultOneShot.matches !== options.isNot)
1188
+ return resultOneShot;
1189
+ } catch (e) {
1190
+ if (this.isNonRetriableError(e))
1191
+ throw e;
1192
+ }
1193
+ const result = await this.retryWithProgressAndTimeouts(progress, [100, 250, 500, 1e3], async (continuePolling) => {
1194
+ await this._page.performActionPreChecks(progress);
1195
+ const { matches, received } = await this._expectInternal(progress, selector, options, lastIntermediateResult, false);
1196
+ if (matches === options.isNot) {
1197
+ return continuePolling;
1198
+ }
1199
+ return { matches, received };
1200
+ });
1201
+ fixupMetadataError(result);
1202
+ return result;
1203
+ } catch (e) {
1204
+ if (selector) {
1205
+ const actionName = `expect(${options.expression})`;
1206
+ const healedResult = await this._attemptHealingRetry(
1207
+ progress,
1208
+ selector,
1209
+ actionName,
1210
+ e,
1211
+ async (healingProgress, healedSelector) => {
1212
+ return await this.expect(healingProgress, healedSelector, options, timeout);
1213
+ }
1214
+ );
1215
+ if (healedResult !== void 0)
1216
+ return healedResult;
1217
+ }
1218
+ const result = { matches: options.isNot, log: (0, import_callLog.compressCallLog)(progress.metadata.log) };
1219
+ if ((0, import_selectorParser.isInvalidSelectorError)(e)) {
1220
+ result.errorMessage = "Error: " + e.message;
1221
+ } else if (js.isJavaScriptErrorInEvaluate(e)) {
1222
+ result.errorMessage = e.message;
1223
+ } else if (lastIntermediateResult.isSet) {
1224
+ result.received = lastIntermediateResult.received;
1225
+ result.errorMessage = lastIntermediateResult.errorMessage;
1226
+ }
1227
+ if (e instanceof import_errors.TimeoutError)
1228
+ result.timedOut = true;
1229
+ fixupMetadataError(result);
1230
+ return result;
1231
+ }
1232
+ }
1233
+ async _expectInternal(progress, selector, options, lastIntermediateResult, noAbort) {
1234
+ const race = (p) => noAbort ? p : progress.race(p);
1235
+ const selectorInFrame = selector ? await race(this.selectors.resolveFrameForSelector(selector, { strict: true })) : void 0;
1236
+ const { frame, info } = selectorInFrame || { frame: this, info: void 0 };
1237
+ const world = options.expression === "to.have.property" ? "main" : info?.world ?? "utility";
1238
+ const context = await race(frame._context(world));
1239
+ const injected = await race(context.injectedScript());
1240
+ const { log, matches, received, missingReceived } = await race(injected.evaluate(async (injected2, { info: info2, options: options2, callId }) => {
1241
+ const elements = info2 ? injected2.querySelectorAll(info2.parsed, document) : [];
1242
+ if (callId)
1243
+ injected2.markTargetElements(new Set(elements), callId);
1244
+ const isArray = options2.expression === "to.have.count" || options2.expression.endsWith(".array");
1245
+ let log2 = "";
1246
+ if (isArray)
1247
+ log2 = ` locator resolved to ${elements.length} element${elements.length === 1 ? "" : "s"}`;
1248
+ else if (elements.length > 1)
1249
+ throw injected2.strictModeViolationError(info2.parsed, elements);
1250
+ else if (elements.length)
1251
+ log2 = ` locator resolved to ${injected2.previewNode(elements[0])}`;
1252
+ return { log: log2, ...await injected2.expect(elements[0], options2, elements) };
1253
+ }, { info, options, callId: progress.metadata.id }));
1254
+ if (log)
1255
+ progress.log(log);
1256
+ if (matches === options.isNot) {
1257
+ if (missingReceived)
1258
+ lastIntermediateResult.errorMessage = "Error: element(s) not found";
1259
+ else
1260
+ lastIntermediateResult.received = received;
1261
+ lastIntermediateResult.isSet = true;
1262
+ if (!missingReceived && !Array.isArray(received))
1263
+ progress.log(` unexpected value "${renderUnexpectedValue(options.expression, received)}"`);
1264
+ }
1265
+ return { matches, received };
1266
+ }
1267
+ async waitForFunctionExpression(progress, expression, isFunction, arg, options, world = "main") {
1268
+ if (typeof options.pollingInterval === "number")
1269
+ (0, import_utils.assert)(options.pollingInterval > 0, "Cannot poll with non-positive interval: " + options.pollingInterval);
1270
+ expression = js.normalizeEvaluationExpression(expression, isFunction);
1271
+ return this.retryWithProgressAndTimeouts(progress, [100], async () => {
1272
+ const context = world === "main" ? await progress.race(this._mainContext()) : await progress.race(this._utilityContext());
1273
+ const injectedScript = await progress.race(context.injectedScript());
1274
+ const handle = await progress.race(injectedScript.evaluateHandle((injected, { expression: expression2, isFunction: isFunction2, polling, arg: arg2 }) => {
1275
+ let evaledExpression;
1276
+ const predicate = () => {
1277
+ let result2 = evaledExpression ?? globalThis.eval(expression2);
1278
+ if (isFunction2 === true) {
1279
+ evaledExpression = result2;
1280
+ result2 = result2(arg2);
1281
+ } else if (isFunction2 === false) {
1282
+ result2 = result2;
1283
+ } else {
1284
+ if (typeof result2 === "function") {
1285
+ evaledExpression = result2;
1286
+ result2 = result2(arg2);
1287
+ }
1288
+ }
1289
+ return result2;
1290
+ };
1291
+ let fulfill;
1292
+ let reject;
1293
+ let aborted = false;
1294
+ const result = new Promise((f, r) => {
1295
+ fulfill = f;
1296
+ reject = r;
1297
+ });
1298
+ const next = () => {
1299
+ if (aborted)
1300
+ return;
1301
+ try {
1302
+ const success = predicate();
1303
+ if (success) {
1304
+ fulfill(success);
1305
+ return;
1306
+ }
1307
+ if (typeof polling !== "number")
1308
+ injected.utils.builtins.requestAnimationFrame(next);
1309
+ else
1310
+ injected.utils.builtins.setTimeout(next, polling);
1311
+ } catch (e) {
1312
+ reject(e);
1313
+ }
1314
+ };
1315
+ next();
1316
+ return { result, abort: () => aborted = true };
1317
+ }, { expression, isFunction, polling: options.pollingInterval, arg }));
1318
+ try {
1319
+ return await progress.race(handle.evaluateHandle((h) => h.result));
1320
+ } catch (error) {
1321
+ await handle.evaluate((h) => h.abort()).catch(() => {
1322
+ });
1323
+ throw error;
1324
+ } finally {
1325
+ handle.dispose();
1326
+ }
1327
+ });
1328
+ }
1329
+ async waitForFunctionValueInUtility(progress, pageFunction) {
1330
+ const expression = `() => {
1331
+ const result = (${pageFunction})();
1332
+ if (!result)
1333
+ return result;
1334
+ return JSON.stringify(result);
1335
+ }`;
1336
+ const handle = await this.waitForFunctionExpression(progress, expression, true, void 0, {}, "utility");
1337
+ return JSON.parse(handle.rawValue());
1338
+ }
1339
+ async title() {
1340
+ const context = await this._utilityContext();
1341
+ return context.evaluate(() => document.title);
1342
+ }
1343
+ async rafrafTimeout(progress, timeout) {
1344
+ if (timeout === 0)
1345
+ return;
1346
+ const context = await progress.race(this._utilityContext());
1347
+ await Promise.all([
1348
+ // wait for double raf
1349
+ progress.race(context.evaluate(() => new Promise((x) => {
1350
+ requestAnimationFrame(() => {
1351
+ requestAnimationFrame(x);
1352
+ });
1353
+ }))),
1354
+ progress.wait(timeout)
1355
+ ]);
1356
+ }
1357
+ _onDetached() {
1358
+ this._stopNetworkIdleTimer();
1359
+ this._detachedScope.close(new Error("Frame was detached"));
1360
+ for (const data of this._contextData.values()) {
1361
+ if (data.context)
1362
+ data.context.contextDestroyed("Frame was detached");
1363
+ data.contextPromise.resolve({ destroyedReason: "Frame was detached" });
1364
+ }
1365
+ if (this._parentFrame)
1366
+ this._parentFrame._childFrames.delete(this);
1367
+ this._parentFrame = null;
1368
+ }
1369
+ async _callOnElementOnceMatches(progress, selector, body, taskData, options, scope) {
1370
+ const callbackText = body.toString();
1371
+ progress.log(`waiting for ${this._asLocator(selector)}`);
1372
+ const promise = this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling) => {
1373
+ const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector, options, scope));
1374
+ if (!resolved)
1375
+ return continuePolling;
1376
+ const { log, success, value } = await progress.race(resolved.injected.evaluate((injected, { info, callbackText: callbackText2, taskData: taskData2, callId, root }) => {
1377
+ const callback = injected.eval(callbackText2);
1378
+ const element = injected.querySelector(info.parsed, root || document, info.strict);
1379
+ if (!element)
1380
+ return { success: false };
1381
+ const log2 = ` locator resolved to ${injected.previewNode(element)}`;
1382
+ if (callId)
1383
+ injected.markTargetElements(/* @__PURE__ */ new Set([element]), callId);
1384
+ return { log: log2, success: true, value: callback(injected, element, taskData2) };
1385
+ }, { info: resolved.info, callbackText, taskData, callId: progress.metadata.id, root: resolved.frame === this ? scope : void 0 }));
1386
+ if (log)
1387
+ progress.log(log);
1388
+ if (!success)
1389
+ return continuePolling;
1390
+ return value;
1391
+ });
1392
+ return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
1393
+ }
1394
+ _setContext(world, context) {
1395
+ const data = this._contextData.get(world);
1396
+ data.context = context;
1397
+ if (context)
1398
+ data.contextPromise.resolve(context);
1399
+ else
1400
+ data.contextPromise = new import_manualPromise.ManualPromise();
1401
+ }
1402
+ _contextCreated(world, context) {
1403
+ const data = this._contextData.get(world);
1404
+ if (data.context) {
1405
+ data.context.contextDestroyed("Execution context was destroyed, most likely because of a navigation");
1406
+ this._setContext(world, null);
1407
+ }
1408
+ this._setContext(world, context);
1409
+ }
1410
+ _contextDestroyed(context) {
1411
+ if (this._detachedScope.isClosed())
1412
+ return;
1413
+ context.contextDestroyed("Execution context was destroyed, most likely because of a navigation");
1414
+ for (const [world, data] of this._contextData) {
1415
+ if (data.context === context)
1416
+ this._setContext(world, null);
1417
+ }
1418
+ }
1419
+ _startNetworkIdleTimer() {
1420
+ (0, import_utils.assert)(!this._networkIdleTimer);
1421
+ if (this._firedLifecycleEvents.has("networkidle") || this._detachedScope.isClosed())
1422
+ return;
1423
+ this._networkIdleTimer = setTimeout(() => {
1424
+ this._firedNetworkIdleSelf = true;
1425
+ this._page.mainFrame()._recalculateNetworkIdle();
1426
+ }, 500);
1427
+ }
1428
+ _stopNetworkIdleTimer() {
1429
+ if (this._networkIdleTimer)
1430
+ clearTimeout(this._networkIdleTimer);
1431
+ this._networkIdleTimer = void 0;
1432
+ this._firedNetworkIdleSelf = false;
1433
+ }
1434
+ async extendInjectedScript(source, arg) {
1435
+ const context = await this._context("main");
1436
+ const injectedScriptHandle = await context.injectedScript();
1437
+ await injectedScriptHandle.evaluate((injectedScript, { source: source2, arg: arg2 }) => {
1438
+ injectedScript.extend(source2, arg2);
1439
+ }, { source, arg });
1440
+ }
1441
+ _asLocator(selector) {
1442
+ return (0, import_utils.asLocator)(this._page.browserContext._browser.sdkLanguage(), selector);
1443
+ }
1444
+ }
1445
+ class SignalBarrier {
1446
+ constructor(progress) {
1447
+ this._protectCount = 0;
1448
+ this._promise = new import_manualPromise.ManualPromise();
1449
+ this._progress = progress;
1450
+ this.retain();
1451
+ }
1452
+ waitFor() {
1453
+ this.release();
1454
+ return this._progress.race(this._promise);
1455
+ }
1456
+ addFrameNavigation(frame) {
1457
+ if (frame.parentFrame())
1458
+ return;
1459
+ this.retain();
1460
+ const waiter = import_helper.helper.waitForEvent(this._progress, frame, Frame.Events.InternalNavigation, (e) => {
1461
+ if (!e.isPublic)
1462
+ return false;
1463
+ if (!e.error && this._progress)
1464
+ this._progress.log(` navigated to "${frame._url}"`);
1465
+ return true;
1466
+ });
1467
+ import_utils.LongStandingScope.raceMultiple([
1468
+ frame._page.openScope,
1469
+ frame._detachedScope
1470
+ ], waiter.promise).catch(() => {
1471
+ }).finally(() => {
1472
+ waiter.dispose();
1473
+ this.release();
1474
+ });
1475
+ }
1476
+ retain() {
1477
+ ++this._protectCount;
1478
+ }
1479
+ release() {
1480
+ --this._protectCount;
1481
+ if (!this._protectCount)
1482
+ this._promise.resolve();
1483
+ }
1484
+ }
1485
+ function verifyLifecycle(name, waitUntil) {
1486
+ if (waitUntil === "networkidle0")
1487
+ waitUntil = "networkidle";
1488
+ if (!types.kLifecycleEvents.has(waitUntil))
1489
+ throw new Error(`${name}: expected one of (load|domcontentloaded|networkidle|commit)`);
1490
+ return waitUntil;
1491
+ }
1492
+ function renderUnexpectedValue(expression, received) {
1493
+ if (expression === "to.match.aria")
1494
+ return received ? received.raw : received;
1495
+ return received;
1496
+ }
1497
+ // Annotate the CommonJS export names for ESM import in node:
1498
+ 0 && (module.exports = {
1499
+ Frame,
1500
+ FrameManager,
1501
+ NavigationAbortedError
1502
+ });