rebrowser-playwright-core 1.49.1 → 1.64.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (393) hide show
  1. package/ThirdPartyNotices.txt +7 -1228
  2. package/bin/install_webkit_wsl.ps1 +33 -0
  3. package/bin/reinstall_chrome_beta_linux.sh +1 -1
  4. package/bin/reinstall_chrome_beta_mac.sh +1 -1
  5. package/bin/reinstall_chrome_stable_linux.sh +1 -1
  6. package/bin/reinstall_chrome_stable_mac.sh +1 -1
  7. package/bin/reinstall_msedge_beta_linux.sh +7 -1
  8. package/bin/reinstall_msedge_beta_mac.sh +1 -1
  9. package/bin/reinstall_msedge_dev_linux.sh +7 -1
  10. package/bin/reinstall_msedge_dev_mac.sh +1 -1
  11. package/bin/reinstall_msedge_stable_linux.sh +7 -1
  12. package/bin/reinstall_msedge_stable_mac.sh +1 -1
  13. package/browsers.json +21 -34
  14. package/cli.js +5 -1
  15. package/index.js +2 -18
  16. package/lib/bootstrap.js +149 -0
  17. package/lib/coreBundle.js +78218 -0
  18. package/lib/entry/cliDaemon.js +5 -0
  19. package/lib/entry/dashboardApp.js +3 -0
  20. package/lib/entry/mcp.js +10 -0
  21. package/lib/entry/oopBrowserDownload.js +3 -0
  22. package/lib/package.js +50 -0
  23. package/lib/server/electron/loader.js +109 -43
  24. package/lib/serverRegistry.js +1939 -0
  25. package/lib/serverRegistry.js.LICENSE +65 -0
  26. package/lib/tools/cli-client/channelSessions.js +141 -0
  27. package/lib/tools/cli-client/cli.js +7 -0
  28. package/lib/tools/cli-client/help.json +808 -0
  29. package/lib/tools/cli-client/minimist.js +128 -0
  30. package/lib/tools/cli-client/output.js +352 -0
  31. package/lib/tools/cli-client/program.js +422 -0
  32. package/lib/tools/cli-client/registry.js +180 -0
  33. package/lib/tools/cli-client/session.js +261 -0
  34. package/lib/tools/dashboard/appIcon.png +0 -0
  35. package/lib/tools/skills/playwright-cli/SKILL.md +493 -0
  36. package/lib/tools/skills/playwright-cli/references/element-attributes.md +23 -0
  37. package/lib/tools/skills/playwright-cli/references/playwright-tests.md +39 -0
  38. package/lib/tools/skills/playwright-cli/references/pr-attachments.md +60 -0
  39. package/lib/tools/skills/playwright-cli/references/request-mocking.md +87 -0
  40. package/lib/tools/skills/playwright-cli/references/running-code.md +245 -0
  41. package/lib/tools/skills/playwright-cli/references/session-management.md +227 -0
  42. package/lib/tools/skills/playwright-cli/references/storage-state.md +275 -0
  43. package/lib/tools/skills/playwright-cli/references/test-generation.md +433 -0
  44. package/lib/tools/skills/playwright-cli/references/tracing.md +139 -0
  45. package/lib/tools/skills/playwright-cli/references/video-recording.md +216 -0
  46. package/lib/tools/skills/playwright-component-testing/SKILL.md +136 -0
  47. package/lib/tools/skills/playwright-component-testing/references/gallery-spec.md +144 -0
  48. package/lib/tools/skills/playwright-component-testing/references/migration.md +89 -0
  49. package/lib/tools/skills/playwright-component-testing/references/react.md +69 -0
  50. package/lib/tools/skills/playwright-component-testing/references/typing.md +173 -0
  51. package/lib/tools/skills/playwright-component-testing/references/vue.md +77 -0
  52. package/lib/tools/skills/playwright-trace/SKILL.md +174 -0
  53. package/lib/tools/utils/extension.js +112 -0
  54. package/lib/tools/utils/socketConnection.js +108 -0
  55. package/lib/utilsBundle.js +86076 -79
  56. package/lib/utilsBundle.js.LICENSE +1890 -0
  57. package/lib/vite/dashboard/assets/codeMirrorModule--QdMvsKi.css +1 -0
  58. package/lib/vite/dashboard/assets/codeMirrorModule-CQ8RZGBm.js +32 -0
  59. package/lib/vite/dashboard/assets/codicon-DCmgc-ay.ttf +0 -0
  60. package/lib/vite/dashboard/assets/firefox-1bWoP6pv.svg +1 -0
  61. package/lib/vite/dashboard/assets/firefox-beta-k3eOH_eK.svg +1 -0
  62. package/lib/vite/dashboard/assets/firefox-nightly-Cp5nfeDT.svg +1 -0
  63. package/lib/vite/dashboard/assets/index-AwgwcYie.css +1 -0
  64. package/lib/vite/dashboard/assets/index-hRvO4yU2.js +12 -0
  65. package/lib/vite/dashboard/assets/safari-na3_-uQk.svg +1 -0
  66. package/lib/vite/dashboard/index.html +29 -0
  67. package/lib/vite/dashboard/playwright-logo.svg +24 -0
  68. package/lib/vite/htmlReport/index.html +3 -56
  69. package/lib/vite/htmlReport/report.css +2 -0
  70. package/lib/vite/htmlReport/report.js +32 -0
  71. package/lib/vite/recorder/assets/codeMirrorModule--QdMvsKi.css +1 -0
  72. package/lib/vite/recorder/assets/codeMirrorModule-DK72OMRi.js +32 -0
  73. package/lib/vite/recorder/assets/index-BZpYJZ-P.css +1 -0
  74. package/lib/vite/recorder/assets/index-Cn0mmDuv.js +129 -0
  75. package/lib/vite/recorder/index.html +3 -3
  76. package/lib/vite/traceViewer/assets/codeMirrorModule-BEB2e8M3.js +32 -0
  77. package/lib/vite/traceViewer/assets/defaultSettingsView-D-g2vrvf.js +184 -0
  78. package/lib/vite/traceViewer/assets/urlMatch-L3liM589.js +1 -0
  79. package/lib/vite/traceViewer/assets/xtermModule-B794rD2Z.js +7 -0
  80. package/lib/vite/traceViewer/codeMirrorModule.-QdMvsKi.css +1 -0
  81. package/lib/vite/traceViewer/defaultSettingsView.C8BeHuxd.css +1 -0
  82. package/lib/vite/traceViewer/index.B_TqY17P.css +1 -0
  83. package/lib/vite/traceViewer/index.html +9 -11
  84. package/lib/vite/traceViewer/index.oNry3Hjv.js +1 -0
  85. package/lib/vite/traceViewer/manifest.webmanifest +16 -0
  86. package/lib/vite/traceViewer/snapshot.B_Jk1wbt.js +1 -0
  87. package/lib/vite/traceViewer/snapshot.html +4 -15
  88. package/lib/vite/traceViewer/sw.bundle.js +4 -3
  89. package/lib/vite/traceViewer/uiMode.CYwC_gH1.js +5 -0
  90. package/lib/vite/traceViewer/uiMode.CyMfwkXJ.css +1 -0
  91. package/lib/vite/traceViewer/uiMode.html +6 -8
  92. package/lib/vite/traceViewer/xtermModule.kHJ-D0s7.css +1 -0
  93. package/lib/webp_codec.LICENSE +173 -0
  94. package/lib/webp_codec.wasm +0 -0
  95. package/lib/{utilsBundleImpl/xdg-open → xdg-open} +338 -137
  96. package/package.json +6 -16
  97. package/types/protocol.d.ts +9357 -6200
  98. package/types/structs.d.ts +8 -1
  99. package/types/types.d.ts +9490 -4947
  100. package/bin/PrintDeps.exe +0 -0
  101. package/bin/README.md +0 -2
  102. package/lib/androidServerImpl.js +0 -69
  103. package/lib/browserServerImpl.js +0 -92
  104. package/lib/cli/driver.js +0 -95
  105. package/lib/cli/program.js +0 -607
  106. package/lib/cli/programWithTestStub.js +0 -67
  107. package/lib/client/accessibility.js +0 -50
  108. package/lib/client/android.js +0 -473
  109. package/lib/client/api.js +0 -285
  110. package/lib/client/artifact.js +0 -79
  111. package/lib/client/browser.js +0 -145
  112. package/lib/client/browserContext.js +0 -559
  113. package/lib/client/browserType.js +0 -241
  114. package/lib/client/cdpSession.js +0 -53
  115. package/lib/client/channelOwner.js +0 -235
  116. package/lib/client/clientHelper.js +0 -57
  117. package/lib/client/clientInstrumentation.js +0 -50
  118. package/lib/client/clock.js +0 -68
  119. package/lib/client/connection.js +0 -333
  120. package/lib/client/consoleMessage.js +0 -55
  121. package/lib/client/coverage.js +0 -41
  122. package/lib/client/dialog.js +0 -57
  123. package/lib/client/download.js +0 -62
  124. package/lib/client/electron.js +0 -135
  125. package/lib/client/elementHandle.js +0 -321
  126. package/lib/client/errors.js +0 -77
  127. package/lib/client/eventEmitter.js +0 -314
  128. package/lib/client/events.js +0 -94
  129. package/lib/client/fetch.js +0 -391
  130. package/lib/client/fileChooser.js +0 -45
  131. package/lib/client/frame.js +0 -504
  132. package/lib/client/harRouter.js +0 -99
  133. package/lib/client/input.js +0 -111
  134. package/lib/client/jsHandle.js +0 -121
  135. package/lib/client/jsonPipe.js +0 -35
  136. package/lib/client/localUtils.js +0 -36
  137. package/lib/client/locator.js +0 -448
  138. package/lib/client/network.js +0 -767
  139. package/lib/client/page.js +0 -748
  140. package/lib/client/playwright.js +0 -80
  141. package/lib/client/selectors.js +0 -67
  142. package/lib/client/stream.js +0 -54
  143. package/lib/client/tracing.js +0 -147
  144. package/lib/client/types.js +0 -24
  145. package/lib/client/video.js +0 -51
  146. package/lib/client/waiter.js +0 -162
  147. package/lib/client/webError.js +0 -37
  148. package/lib/client/worker.js +0 -71
  149. package/lib/client/writableStream.js +0 -54
  150. package/lib/common/socksProxy.js +0 -569
  151. package/lib/common/timeoutSettings.js +0 -73
  152. package/lib/common/types.js +0 -5
  153. package/lib/generated/clockSource.js +0 -7
  154. package/lib/generated/consoleApiSource.js +0 -7
  155. package/lib/generated/injectedScriptSource.js +0 -7
  156. package/lib/generated/pollingRecorderSource.js +0 -7
  157. package/lib/generated/utilityScriptSource.js +0 -7
  158. package/lib/generated/webSocketMockSource.js +0 -7
  159. package/lib/image_tools/colorUtils.js +0 -98
  160. package/lib/image_tools/compare.js +0 -108
  161. package/lib/image_tools/imageChannel.js +0 -70
  162. package/lib/image_tools/stats.js +0 -102
  163. package/lib/inProcessFactory.js +0 -54
  164. package/lib/inprocess.js +0 -20
  165. package/lib/outofprocess.js +0 -67
  166. package/lib/protocol/debug.js +0 -27
  167. package/lib/protocol/serializers.js +0 -173
  168. package/lib/protocol/transport.js +0 -82
  169. package/lib/protocol/validator.js +0 -2780
  170. package/lib/protocol/validatorPrimitives.js +0 -139
  171. package/lib/remote/playwrightConnection.js +0 -274
  172. package/lib/remote/playwrightServer.js +0 -110
  173. package/lib/server/accessibility.js +0 -62
  174. package/lib/server/android/android.js +0 -441
  175. package/lib/server/android/backendAdb.js +0 -172
  176. package/lib/server/ariaSnapshot.js +0 -33
  177. package/lib/server/artifact.js +0 -104
  178. package/lib/server/bidi/bidiBrowser.js +0 -311
  179. package/lib/server/bidi/bidiChromium.js +0 -124
  180. package/lib/server/bidi/bidiConnection.js +0 -204
  181. package/lib/server/bidi/bidiExecutionContext.js +0 -156
  182. package/lib/server/bidi/bidiFirefox.js +0 -104
  183. package/lib/server/bidi/bidiInput.js +0 -158
  184. package/lib/server/bidi/bidiNetworkManager.js +0 -338
  185. package/lib/server/bidi/bidiOverCdp.js +0 -103
  186. package/lib/server/bidi/bidiPage.js +0 -529
  187. package/lib/server/bidi/bidiPdf.js +0 -140
  188. package/lib/server/bidi/third_party/bidiDeserializer.js +0 -93
  189. package/lib/server/bidi/third_party/bidiKeyboard.js +0 -238
  190. package/lib/server/bidi/third_party/bidiProtocol.js +0 -139
  191. package/lib/server/bidi/third_party/bidiSerializer.js +0 -144
  192. package/lib/server/bidi/third_party/firefoxPrefs.js +0 -221
  193. package/lib/server/browser.js +0 -148
  194. package/lib/server/browserContext.js +0 -667
  195. package/lib/server/browserType.js +0 -338
  196. package/lib/server/chromium/chromium.js +0 -354
  197. package/lib/server/chromium/chromiumSwitches.js +0 -46
  198. package/lib/server/chromium/crAccessibility.js +0 -237
  199. package/lib/server/chromium/crBrowser.js +0 -516
  200. package/lib/server/chromium/crConnection.js +0 -381
  201. package/lib/server/chromium/crCoverage.js +0 -246
  202. package/lib/server/chromium/crDevTools.js +0 -108
  203. package/lib/server/chromium/crDragDrop.js +0 -143
  204. package/lib/server/chromium/crExecutionContext.js +0 -136
  205. package/lib/server/chromium/crInput.js +0 -171
  206. package/lib/server/chromium/crNetworkManager.js +0 -767
  207. package/lib/server/chromium/crPage.js +0 -1143
  208. package/lib/server/chromium/crPdf.js +0 -153
  209. package/lib/server/chromium/crProtocolHelper.js +0 -133
  210. package/lib/server/chromium/crServiceWorker.js +0 -114
  211. package/lib/server/chromium/defaultFontFamilies.js +0 -145
  212. package/lib/server/chromium/videoRecorder.js +0 -155
  213. package/lib/server/clock.js +0 -125
  214. package/lib/server/codegen/csharp.js +0 -294
  215. package/lib/server/codegen/java.js +0 -232
  216. package/lib/server/codegen/javascript.js +0 -245
  217. package/lib/server/codegen/jsonl.js +0 -47
  218. package/lib/server/codegen/language.js +0 -88
  219. package/lib/server/codegen/languages.js +0 -30
  220. package/lib/server/codegen/python.js +0 -261
  221. package/lib/server/codegen/types.js +0 -5
  222. package/lib/server/console.js +0 -57
  223. package/lib/server/cookieStore.js +0 -185
  224. package/lib/server/debugController.js +0 -237
  225. package/lib/server/debugger.js +0 -132
  226. package/lib/server/deviceDescriptors.js +0 -26
  227. package/lib/server/deviceDescriptorsSource.json +0 -1669
  228. package/lib/server/dialog.js +0 -71
  229. package/lib/server/dispatchers/androidDispatcher.js +0 -204
  230. package/lib/server/dispatchers/artifactDispatcher.js +0 -118
  231. package/lib/server/dispatchers/browserContextDispatcher.js +0 -368
  232. package/lib/server/dispatchers/browserDispatcher.js +0 -170
  233. package/lib/server/dispatchers/browserTypeDispatcher.js +0 -55
  234. package/lib/server/dispatchers/cdpSessionDispatcher.js +0 -48
  235. package/lib/server/dispatchers/debugControllerDispatcher.js +0 -103
  236. package/lib/server/dispatchers/dialogDispatcher.js +0 -44
  237. package/lib/server/dispatchers/dispatcher.js +0 -395
  238. package/lib/server/dispatchers/electronDispatcher.js +0 -93
  239. package/lib/server/dispatchers/elementHandlerDispatcher.js +0 -228
  240. package/lib/server/dispatchers/frameDispatcher.js +0 -293
  241. package/lib/server/dispatchers/jsHandleDispatcher.js +0 -97
  242. package/lib/server/dispatchers/jsonPipeDispatcher.js +0 -59
  243. package/lib/server/dispatchers/localUtilsDispatcher.js +0 -413
  244. package/lib/server/dispatchers/networkDispatchers.js +0 -221
  245. package/lib/server/dispatchers/pageDispatcher.js +0 -367
  246. package/lib/server/dispatchers/playwrightDispatcher.js +0 -107
  247. package/lib/server/dispatchers/selectorsDispatcher.js +0 -36
  248. package/lib/server/dispatchers/streamDispatcher.js +0 -62
  249. package/lib/server/dispatchers/tracingDispatcher.js +0 -64
  250. package/lib/server/dispatchers/webSocketRouteDispatcher.js +0 -189
  251. package/lib/server/dispatchers/writableStreamDispatcher.js +0 -58
  252. package/lib/server/dom.js +0 -888
  253. package/lib/server/download.js +0 -60
  254. package/lib/server/electron/electron.js +0 -296
  255. package/lib/server/errors.js +0 -68
  256. package/lib/server/fetch.js +0 -669
  257. package/lib/server/fileChooser.js +0 -42
  258. package/lib/server/fileUploadUtils.js +0 -75
  259. package/lib/server/firefox/ffAccessibility.js +0 -216
  260. package/lib/server/firefox/ffBrowser.js +0 -460
  261. package/lib/server/firefox/ffConnection.js +0 -168
  262. package/lib/server/firefox/ffExecutionContext.js +0 -123
  263. package/lib/server/firefox/ffInput.js +0 -150
  264. package/lib/server/firefox/ffNetworkManager.js +0 -233
  265. package/lib/server/firefox/ffPage.js +0 -559
  266. package/lib/server/firefox/firefox.js +0 -99
  267. package/lib/server/formData.js +0 -75
  268. package/lib/server/frameSelectors.js +0 -171
  269. package/lib/server/frames.js +0 -1691
  270. package/lib/server/har/harRecorder.js +0 -139
  271. package/lib/server/har/harTracer.js +0 -542
  272. package/lib/server/helper.js +0 -103
  273. package/lib/server/index.js +0 -108
  274. package/lib/server/input.js +0 -310
  275. package/lib/server/instrumentation.js +0 -70
  276. package/lib/server/isomorphic/utilityScriptSerializers.js +0 -226
  277. package/lib/server/javascript.js +0 -293
  278. package/lib/server/launchApp.js +0 -91
  279. package/lib/server/macEditingCommands.js +0 -139
  280. package/lib/server/network.js +0 -617
  281. package/lib/server/page.js +0 -873
  282. package/lib/server/pipeTransport.js +0 -85
  283. package/lib/server/playwright.js +0 -88
  284. package/lib/server/progress.js +0 -99
  285. package/lib/server/protocolError.js +0 -49
  286. package/lib/server/recorder/contextRecorder.js +0 -299
  287. package/lib/server/recorder/recorderApp.js +0 -187
  288. package/lib/server/recorder/recorderCollection.js +0 -116
  289. package/lib/server/recorder/recorderFrontend.js +0 -5
  290. package/lib/server/recorder/recorderInTraceViewer.js +0 -144
  291. package/lib/server/recorder/recorderRunner.js +0 -155
  292. package/lib/server/recorder/recorderUtils.js +0 -113
  293. package/lib/server/recorder/throttledFile.js +0 -46
  294. package/lib/server/recorder.js +0 -364
  295. package/lib/server/registry/browserFetcher.js +0 -168
  296. package/lib/server/registry/dependencies.js +0 -322
  297. package/lib/server/registry/index.js +0 -1052
  298. package/lib/server/registry/nativeDeps.js +0 -493
  299. package/lib/server/registry/oopDownloadBrowserMain.js +0 -138
  300. package/lib/server/screenshotter.js +0 -348
  301. package/lib/server/selectors.js +0 -73
  302. package/lib/server/socksClientCertificatesInterceptor.js +0 -340
  303. package/lib/server/socksInterceptor.js +0 -100
  304. package/lib/server/trace/recorder/snapshotter.js +0 -161
  305. package/lib/server/trace/recorder/snapshotterInjected.js +0 -511
  306. package/lib/server/trace/recorder/tracing.js +0 -596
  307. package/lib/server/trace/test/inMemorySnapshotter.js +0 -93
  308. package/lib/server/trace/viewer/traceViewer.js +0 -214
  309. package/lib/server/transport.js +0 -191
  310. package/lib/server/types.js +0 -24
  311. package/lib/server/usKeyboardLayout.js +0 -555
  312. package/lib/server/webkit/webkit.js +0 -87
  313. package/lib/server/webkit/wkAccessibility.js +0 -194
  314. package/lib/server/webkit/wkBrowser.js +0 -329
  315. package/lib/server/webkit/wkConnection.js +0 -173
  316. package/lib/server/webkit/wkExecutionContext.js +0 -130
  317. package/lib/server/webkit/wkInput.js +0 -169
  318. package/lib/server/webkit/wkInterceptableRequest.js +0 -162
  319. package/lib/server/webkit/wkPage.js +0 -1225
  320. package/lib/server/webkit/wkProvisionalPage.js +0 -94
  321. package/lib/server/webkit/wkWorkers.js +0 -104
  322. package/lib/third_party/pixelmatch.js +0 -255
  323. package/lib/utils/ascii.js +0 -31
  324. package/lib/utils/comparators.js +0 -153
  325. package/lib/utils/crypto.js +0 -171
  326. package/lib/utils/debug.js +0 -46
  327. package/lib/utils/debugLogger.js +0 -91
  328. package/lib/utils/env.js +0 -49
  329. package/lib/utils/eventsHelper.js +0 -38
  330. package/lib/utils/expectUtils.js +0 -33
  331. package/lib/utils/fileUtils.js +0 -205
  332. package/lib/utils/happy-eyeballs.js +0 -194
  333. package/lib/utils/headers.js +0 -52
  334. package/lib/utils/hostPlatform.js +0 -139
  335. package/lib/utils/httpServer.js +0 -237
  336. package/lib/utils/index.js +0 -368
  337. package/lib/utils/isomorphic/ariaSnapshot.js +0 -267
  338. package/lib/utils/isomorphic/cssParser.js +0 -250
  339. package/lib/utils/isomorphic/cssTokenizer.js +0 -979
  340. package/lib/utils/isomorphic/locatorGenerators.js +0 -660
  341. package/lib/utils/isomorphic/locatorParser.js +0 -179
  342. package/lib/utils/isomorphic/locatorUtils.js +0 -62
  343. package/lib/utils/isomorphic/mimeType.js +0 -29
  344. package/lib/utils/isomorphic/recorderUtils.js +0 -227
  345. package/lib/utils/isomorphic/selectorParser.js +0 -397
  346. package/lib/utils/isomorphic/stringUtils.js +0 -169
  347. package/lib/utils/isomorphic/traceUtils.js +0 -39
  348. package/lib/utils/isomorphic/urlMatch.js +0 -124
  349. package/lib/utils/linuxUtils.js +0 -78
  350. package/lib/utils/manualPromise.js +0 -109
  351. package/lib/utils/multimap.js +0 -75
  352. package/lib/utils/network.js +0 -160
  353. package/lib/utils/processLauncher.js +0 -248
  354. package/lib/utils/profiler.js +0 -53
  355. package/lib/utils/rtti.js +0 -44
  356. package/lib/utils/semaphore.js +0 -51
  357. package/lib/utils/sequence.js +0 -64
  358. package/lib/utils/spawnAsync.js +0 -45
  359. package/lib/utils/stackTrace.js +0 -134
  360. package/lib/utils/task.js +0 -58
  361. package/lib/utils/time.js +0 -37
  362. package/lib/utils/timeoutRunner.js +0 -66
  363. package/lib/utils/traceUtils.js +0 -44
  364. package/lib/utils/userAgent.js +0 -105
  365. package/lib/utils/wsServer.js +0 -127
  366. package/lib/utils/zipFile.js +0 -75
  367. package/lib/utils/zones.js +0 -71
  368. package/lib/utilsBundleImpl/index.js +0 -210
  369. package/lib/vite/recorder/assets/codeMirrorModule-C5j27SYZ.js +0 -24
  370. package/lib/vite/recorder/assets/codeMirrorModule-ez37Vkbh.css +0 -1
  371. package/lib/vite/recorder/assets/index-iA1aAGZg.css +0 -1
  372. package/lib/vite/recorder/assets/index-m0XdVJHe.js +0 -184
  373. package/lib/vite/traceViewer/assets/codeMirrorModule-BBCX0spr.js +0 -24
  374. package/lib/vite/traceViewer/assets/inspectorTab-B4Iw34Ow.js +0 -68
  375. package/lib/vite/traceViewer/assets/testServerConnection-DeE2kSzz.js +0 -1
  376. package/lib/vite/traceViewer/assets/workbench-DFlGYqou.js +0 -9
  377. package/lib/vite/traceViewer/assets/xtermModule-BeNbaIVa.js +0 -9
  378. package/lib/vite/traceViewer/codeMirrorModule.ez37Vkbh.css +0 -1
  379. package/lib/vite/traceViewer/embedded.CmarehFk.js +0 -2
  380. package/lib/vite/traceViewer/embedded.html +0 -18
  381. package/lib/vite/traceViewer/embedded.w7WN2u1R.css +0 -1
  382. package/lib/vite/traceViewer/index.CrbWWHbf.css +0 -1
  383. package/lib/vite/traceViewer/index.FBucu_gE.js +0 -2
  384. package/lib/vite/traceViewer/inspectorTab.DEOUW62d.css +0 -1
  385. package/lib/vite/traceViewer/recorder.B_SY1GJM.css +0 -0
  386. package/lib/vite/traceViewer/recorder.CW_rzcEp.js +0 -2
  387. package/lib/vite/traceViewer/recorder.html +0 -17
  388. package/lib/vite/traceViewer/uiMode.CDUVjusr.js +0 -5
  389. package/lib/vite/traceViewer/uiMode.voC1ZiOQ.css +0 -1
  390. package/lib/vite/traceViewer/workbench.C-zR9ysA.css +0 -1
  391. package/lib/vite/traceViewer/xtermModule.DSXBckUd.css +0 -32
  392. package/lib/zipBundle.js +0 -25
  393. package/lib/zipBundleImpl.js +0 -5
@@ -1,1691 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.NavigationAbortedError = exports.FrameManager = exports.Frame = void 0;
7
- var dom = _interopRequireWildcard(require("./dom"));
8
- var _helper = require("./helper");
9
- var _eventsHelper = require("../utils/eventsHelper");
10
- var js = _interopRequireWildcard(require("./javascript"));
11
- var network = _interopRequireWildcard(require("./network"));
12
- var _page = require("./page");
13
- var types = _interopRequireWildcard(require("./types"));
14
- var _browserContext = require("./browserContext");
15
- var _progress = require("./progress");
16
- var _utils = require("../utils");
17
- var _manualPromise = require("../utils/manualPromise");
18
- var _debugLogger = require("../utils/debugLogger");
19
- var _instrumentation = require("./instrumentation");
20
- var _protocolError = require("./protocolError");
21
- var _selectorParser = require("../utils/isomorphic/selectorParser");
22
- var _frameSelectors = require("./frameSelectors");
23
- var _errors = require("./errors");
24
- var _fileUploadUtils = require("./fileUploadUtils");
25
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
26
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
27
- /**
28
- * Copyright 2017 Google Inc. All rights reserved.
29
- * Modifications copyright (c) Microsoft Corporation.
30
- *
31
- * Licensed under the Apache License, Version 2.0 (the "License");
32
- * you may not use this file except in compliance with the License.
33
- * You may obtain a copy of the License at
34
- *
35
- * http://www.apache.org/licenses/LICENSE-2.0
36
- *
37
- * Unless required by applicable law or agreed to in writing, software
38
- * distributed under the License is distributed on an "AS IS" BASIS,
39
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40
- * See the License for the specific language governing permissions and
41
- * limitations under the License.
42
- */
43
-
44
- class NavigationAbortedError extends Error {
45
- constructor(documentId, message) {
46
- super(message);
47
- this.documentId = void 0;
48
- this.documentId = documentId;
49
- }
50
- }
51
- exports.NavigationAbortedError = NavigationAbortedError;
52
- const kDummyFrameId = '<dummy>';
53
- class FrameManager {
54
- constructor(page) {
55
- this._page = void 0;
56
- this._frames = new Map();
57
- this._mainFrame = void 0;
58
- this._consoleMessageTags = new Map();
59
- this._signalBarriers = new Set();
60
- this._webSockets = new Map();
61
- this._openedDialogs = new Set();
62
- this._closeAllOpeningDialogs = false;
63
- this._page = page;
64
- this._mainFrame = undefined;
65
- }
66
- createDummyMainFrameIfNeeded() {
67
- if (!this._mainFrame) this.frameAttached(kDummyFrameId, null);
68
- }
69
- dispose() {
70
- for (const frame of this._frames.values()) {
71
- frame._stopNetworkIdleTimer();
72
- frame._invalidateNonStallingEvaluations('Target crashed');
73
- }
74
- }
75
- mainFrame() {
76
- return this._mainFrame;
77
- }
78
- frames() {
79
- const frames = [];
80
- collect(this._mainFrame);
81
- return frames;
82
- function collect(frame) {
83
- frames.push(frame);
84
- for (const subframe of frame.childFrames()) collect(subframe);
85
- }
86
- }
87
- frame(frameId) {
88
- return this._frames.get(frameId) || null;
89
- }
90
- frameAttached(frameId, parentFrameId) {
91
- const parentFrame = parentFrameId ? this._frames.get(parentFrameId) : null;
92
- if (!parentFrame) {
93
- if (this._mainFrame) {
94
- // Update frame id to retain frame identity on cross-process navigation.
95
- this._frames.delete(this._mainFrame._id);
96
- this._mainFrame._id = frameId;
97
- } else {
98
- (0, _utils.assert)(!this._frames.has(frameId));
99
- this._mainFrame = new Frame(this._page, frameId, parentFrame);
100
- }
101
- this._frames.set(frameId, this._mainFrame);
102
- return this._mainFrame;
103
- } else {
104
- (0, _utils.assert)(!this._frames.has(frameId));
105
- const frame = new Frame(this._page, frameId, parentFrame);
106
- this._frames.set(frameId, frame);
107
- this._page.emit(_page.Page.Events.FrameAttached, frame);
108
- return frame;
109
- }
110
- }
111
- async waitForSignalsCreatedBy(progress, waitAfter, action) {
112
- if (!waitAfter) return action();
113
- const barrier = new SignalBarrier(progress);
114
- this._signalBarriers.add(barrier);
115
- if (progress) progress.cleanupWhenAborted(() => this._signalBarriers.delete(barrier));
116
- const result = await action();
117
- await this._page._delegate.inputActionEpilogue();
118
- await barrier.waitFor();
119
- this._signalBarriers.delete(barrier);
120
- // Resolve in the next task, after all waitForNavigations.
121
- await new Promise((0, _utils.makeWaitForNextTask)());
122
- return result;
123
- }
124
- frameWillPotentiallyRequestNavigation() {
125
- for (const barrier of this._signalBarriers) barrier.retain();
126
- }
127
- frameDidPotentiallyRequestNavigation() {
128
- for (const barrier of this._signalBarriers) barrier.release();
129
- }
130
- frameRequestedNavigation(frameId, documentId) {
131
- const frame = this._frames.get(frameId);
132
- if (!frame) return;
133
- for (const barrier of this._signalBarriers) barrier.addFrameNavigation(frame);
134
- if (frame.pendingDocument() && frame.pendingDocument().documentId === documentId) {
135
- // Do not override request with undefined.
136
- return;
137
- }
138
- const request = documentId ? Array.from(frame._inflightRequests).find(request => request._documentId === documentId) : undefined;
139
- frame.setPendingDocument({
140
- documentId,
141
- request
142
- });
143
- }
144
- frameCommittedNewDocumentNavigation(frameId, url, name, documentId, initial) {
145
- const frame = this._frames.get(frameId);
146
- this.removeChildFramesRecursively(frame);
147
- this.clearWebSockets(frame);
148
- frame._url = url;
149
- frame._name = name;
150
- let keepPending;
151
- const pendingDocument = frame.pendingDocument();
152
- if (pendingDocument) {
153
- if (pendingDocument.documentId === undefined) {
154
- // Pending with unknown documentId - assume it is the one being committed.
155
- pendingDocument.documentId = documentId;
156
- }
157
- if (pendingDocument.documentId === documentId) {
158
- // Committing a pending document.
159
- frame._currentDocument = pendingDocument;
160
- } else {
161
- // Sometimes, we already have a new pending when the old one commits.
162
- // An example would be Chromium error page followed by a new navigation request,
163
- // where the error page commit arrives after Network.requestWillBeSent for the
164
- // new navigation.
165
- // We commit, but keep the pending request since it's not done yet.
166
- keepPending = pendingDocument;
167
- frame._currentDocument = {
168
- documentId,
169
- request: undefined
170
- };
171
- }
172
- frame.setPendingDocument(undefined);
173
- } else {
174
- // No pending - just commit a new document.
175
- frame._currentDocument = {
176
- documentId,
177
- request: undefined
178
- };
179
- }
180
- frame._onClearLifecycle();
181
- const navigationEvent = {
182
- url,
183
- name,
184
- newDocument: frame._currentDocument,
185
- isPublic: true
186
- };
187
- this._fireInternalFrameNavigation(frame, navigationEvent);
188
- if (!initial) {
189
- _debugLogger.debugLogger.log('api', ` navigated to "${url}"`);
190
- this._page.frameNavigatedToNewDocument(frame);
191
- }
192
- // Restore pending if any - see comments above about keepPending.
193
- frame.setPendingDocument(keepPending);
194
- }
195
- frameCommittedSameDocumentNavigation(frameId, url) {
196
- const frame = this._frames.get(frameId);
197
- if (!frame) return;
198
- const pending = frame.pendingDocument();
199
- if (pending && pending.documentId === undefined && pending.request === undefined) {
200
- // WebKit has notified about the same-document navigation being requested, so clear it.
201
- frame.setPendingDocument(undefined);
202
- }
203
- frame._url = url;
204
- const navigationEvent = {
205
- url,
206
- name: frame._name,
207
- isPublic: true
208
- };
209
- this._fireInternalFrameNavigation(frame, navigationEvent);
210
- _debugLogger.debugLogger.log('api', ` navigated to "${url}"`);
211
- }
212
- frameAbortedNavigation(frameId, errorText, documentId) {
213
- const frame = this._frames.get(frameId);
214
- if (!frame || !frame.pendingDocument()) return;
215
- if (documentId !== undefined && frame.pendingDocument().documentId !== documentId) return;
216
- const navigationEvent = {
217
- url: frame._url,
218
- name: frame._name,
219
- newDocument: frame.pendingDocument(),
220
- error: new NavigationAbortedError(documentId, errorText),
221
- isPublic: !(documentId && frame._redirectedNavigations.has(documentId))
222
- };
223
- frame.setPendingDocument(undefined);
224
- this._fireInternalFrameNavigation(frame, navigationEvent);
225
- }
226
- frameDetached(frameId) {
227
- const frame = this._frames.get(frameId);
228
- if (frame) {
229
- this._removeFramesRecursively(frame);
230
- this._page.mainFrame()._recalculateNetworkIdle();
231
- }
232
- }
233
- frameLifecycleEvent(frameId, event) {
234
- const frame = this._frames.get(frameId);
235
- if (frame) frame._onLifecycleEvent(event);
236
- }
237
- requestStarted(request, route) {
238
- const frame = request.frame();
239
- this._inflightRequestStarted(request);
240
- if (request._documentId) frame.setPendingDocument({
241
- documentId: request._documentId,
242
- request
243
- });
244
- if (request._isFavicon) {
245
- route === null || route === void 0 || route.continue({
246
- isFallback: true
247
- }).catch(() => {});
248
- return;
249
- }
250
- this._page.emitOnContext(_browserContext.BrowserContext.Events.Request, request);
251
- if (route) {
252
- var _this$_page$_serverRe, _this$_page, _this$_page$_clientRe, _this$_page2, _this$_page$_browserC, _this$_page$_browserC2;
253
- const r = new network.Route(request, route);
254
- if ((_this$_page$_serverRe = (_this$_page = this._page)._serverRequestInterceptor) !== null && _this$_page$_serverRe !== void 0 && _this$_page$_serverRe.call(_this$_page, r, request)) return;
255
- if ((_this$_page$_clientRe = (_this$_page2 = this._page)._clientRequestInterceptor) !== null && _this$_page$_clientRe !== void 0 && _this$_page$_clientRe.call(_this$_page2, r, request)) return;
256
- if ((_this$_page$_browserC = (_this$_page$_browserC2 = this._page._browserContext)._requestInterceptor) !== null && _this$_page$_browserC !== void 0 && _this$_page$_browserC.call(_this$_page$_browserC2, r, request)) return;
257
- r.continue({
258
- isFallback: true
259
- }).catch(() => {});
260
- }
261
- }
262
- requestReceivedResponse(response) {
263
- if (response.request()._isFavicon) return;
264
- this._page.emitOnContext(_browserContext.BrowserContext.Events.Response, response);
265
- }
266
- reportRequestFinished(request, response) {
267
- this._inflightRequestFinished(request);
268
- if (request._isFavicon) return;
269
- this._page.emitOnContext(_browserContext.BrowserContext.Events.RequestFinished, {
270
- request,
271
- response
272
- });
273
- }
274
- requestFailed(request, canceled) {
275
- const frame = request.frame();
276
- this._inflightRequestFinished(request);
277
- if (frame.pendingDocument() && frame.pendingDocument().request === request) {
278
- let errorText = request.failure().errorText;
279
- if (canceled) errorText += '; maybe frame was detached?';
280
- this.frameAbortedNavigation(frame._id, errorText, frame.pendingDocument().documentId);
281
- }
282
- if (request._isFavicon) return;
283
- this._page.emitOnContext(_browserContext.BrowserContext.Events.RequestFailed, request);
284
- }
285
- dialogDidOpen(dialog) {
286
- // Any ongoing evaluations will be stalled until the dialog is closed.
287
- for (const frame of this._frames.values()) frame._invalidateNonStallingEvaluations('JavaScript dialog interrupted evaluation');
288
- if (this._closeAllOpeningDialogs) dialog.close().then(() => {});else this._openedDialogs.add(dialog);
289
- }
290
- dialogWillClose(dialog) {
291
- this._openedDialogs.delete(dialog);
292
- }
293
- async closeOpenDialogs() {
294
- await Promise.all([...this._openedDialogs].map(dialog => dialog.close())).catch(() => {});
295
- this._openedDialogs.clear();
296
- }
297
- setCloseAllOpeningDialogs(closeDialogs) {
298
- this._closeAllOpeningDialogs = closeDialogs;
299
- }
300
- removeChildFramesRecursively(frame) {
301
- for (const child of frame.childFrames()) this._removeFramesRecursively(child);
302
- }
303
- _removeFramesRecursively(frame) {
304
- this.removeChildFramesRecursively(frame);
305
- frame._onDetached();
306
- this._frames.delete(frame._id);
307
- if (!this._page.isClosed()) this._page.emit(_page.Page.Events.FrameDetached, frame);
308
- }
309
- _inflightRequestFinished(request) {
310
- const frame = request.frame();
311
- if (request._isFavicon) return;
312
- if (!frame._inflightRequests.has(request)) return;
313
- frame._inflightRequests.delete(request);
314
- if (frame._inflightRequests.size === 0) frame._startNetworkIdleTimer();
315
- }
316
- _inflightRequestStarted(request) {
317
- const frame = request.frame();
318
- if (request._isFavicon) return;
319
- frame._inflightRequests.add(request);
320
- if (frame._inflightRequests.size === 1) frame._stopNetworkIdleTimer();
321
- }
322
- interceptConsoleMessage(message) {
323
- if (message.type() !== 'debug') return false;
324
- const tag = message.text();
325
- const handler = this._consoleMessageTags.get(tag);
326
- if (!handler) return false;
327
- this._consoleMessageTags.delete(tag);
328
- handler();
329
- return true;
330
- }
331
- clearWebSockets(frame) {
332
- // TODO: attribute sockets to frames.
333
- if (frame.parentFrame()) return;
334
- this._webSockets.clear();
335
- }
336
- onWebSocketCreated(requestId, url) {
337
- const ws = new network.WebSocket(this._page, url);
338
- this._webSockets.set(requestId, ws);
339
- }
340
- onWebSocketRequest(requestId) {
341
- const ws = this._webSockets.get(requestId);
342
- if (ws && ws.markAsNotified()) this._page.emit(_page.Page.Events.WebSocket, ws);
343
- }
344
- onWebSocketResponse(requestId, status, statusText) {
345
- const ws = this._webSockets.get(requestId);
346
- if (status < 400) return;
347
- if (ws) ws.error(`${statusText}: ${status}`);
348
- }
349
- onWebSocketFrameSent(requestId, opcode, data) {
350
- const ws = this._webSockets.get(requestId);
351
- if (ws) ws.frameSent(opcode, data);
352
- }
353
- webSocketFrameReceived(requestId, opcode, data) {
354
- const ws = this._webSockets.get(requestId);
355
- if (ws) ws.frameReceived(opcode, data);
356
- }
357
- webSocketClosed(requestId) {
358
- const ws = this._webSockets.get(requestId);
359
- if (ws) ws.closed();
360
- this._webSockets.delete(requestId);
361
- }
362
- webSocketError(requestId, errorMessage) {
363
- const ws = this._webSockets.get(requestId);
364
- if (ws) ws.error(errorMessage);
365
- }
366
- _fireInternalFrameNavigation(frame, event) {
367
- frame.emit(Frame.Events.InternalNavigation, event);
368
- }
369
- }
370
- exports.FrameManager = FrameManager;
371
- class Frame extends _instrumentation.SdkObject {
372
- constructor(page, id, parentFrame) {
373
- super(page, 'frame');
374
- this._id = void 0;
375
- this._firedLifecycleEvents = new Set();
376
- this._firedNetworkIdleSelf = false;
377
- this._currentDocument = void 0;
378
- this._pendingDocument = void 0;
379
- this._page = void 0;
380
- this._parentFrame = void 0;
381
- this._url = '';
382
- this._contextData = new Map();
383
- this._childFrames = new Set();
384
- this._name = '';
385
- this._inflightRequests = new Set();
386
- this._networkIdleTimer = void 0;
387
- this._setContentCounter = 0;
388
- this._detachedScope = new _utils.LongStandingScope();
389
- this._raceAgainstEvaluationStallingEventsPromises = new Set();
390
- this._redirectedNavigations = new Map();
391
- // documentId -> data
392
- this.selectors = void 0;
393
- this.attribution.frame = this;
394
- this._id = id;
395
- this._page = page;
396
- this._parentFrame = parentFrame;
397
- this._currentDocument = {
398
- documentId: undefined,
399
- request: undefined
400
- };
401
- this.selectors = new _frameSelectors.FrameSelectors(this);
402
- this._contextData.set('main', {
403
- contextPromise: new _manualPromise.ManualPromise(),
404
- context: null
405
- });
406
- this._contextData.set('utility', {
407
- contextPromise: new _manualPromise.ManualPromise(),
408
- context: null
409
- });
410
- this._setContext('main', null);
411
- this._setContext('utility', null);
412
- if (this._parentFrame) this._parentFrame._childFrames.add(this);
413
- this._firedLifecycleEvents.add('commit');
414
- if (id !== kDummyFrameId) this._startNetworkIdleTimer();
415
- }
416
- isDetached() {
417
- return this._detachedScope.isClosed();
418
- }
419
- _onLifecycleEvent(event) {
420
- if (this._firedLifecycleEvents.has(event)) return;
421
- this._firedLifecycleEvents.add(event);
422
- this.emit(Frame.Events.AddLifecycle, event);
423
- if (this === this._page.mainFrame() && this._url !== 'about:blank') _debugLogger.debugLogger.log('api', ` "${event}" event fired`);
424
- this._page.mainFrame()._recalculateNetworkIdle();
425
- }
426
- _onClearLifecycle() {
427
- for (const event of this._firedLifecycleEvents) this.emit(Frame.Events.RemoveLifecycle, event);
428
- this._firedLifecycleEvents.clear();
429
- // Keep the current navigation request if any.
430
- this._inflightRequests = new Set(Array.from(this._inflightRequests).filter(request => request === this._currentDocument.request));
431
- this._stopNetworkIdleTimer();
432
- if (this._inflightRequests.size === 0) this._startNetworkIdleTimer();
433
- this._page.mainFrame()._recalculateNetworkIdle(this);
434
- this._onLifecycleEvent('commit');
435
- const crSession = (this._page._delegate._sessions.get(this._id) || this._page._delegate._mainFrameSession)._client;
436
- crSession.emit('Runtime.executionContextsCleared');
437
- }
438
- setPendingDocument(documentInfo) {
439
- this._pendingDocument = documentInfo;
440
- if (documentInfo) this._invalidateNonStallingEvaluations('Navigation interrupted the evaluation');
441
- }
442
- pendingDocument() {
443
- return this._pendingDocument;
444
- }
445
- _invalidateNonStallingEvaluations(message) {
446
- if (!this._raceAgainstEvaluationStallingEventsPromises.size) return;
447
- const error = new Error(message);
448
- for (const promise of this._raceAgainstEvaluationStallingEventsPromises) promise.reject(error);
449
- }
450
- async raceAgainstEvaluationStallingEvents(cb) {
451
- if (this._pendingDocument) throw new Error('Frame is currently attempting a navigation');
452
- if (this._page._frameManager._openedDialogs.size) throw new Error('Open JavaScript dialog prevents evaluation');
453
- const promise = new _manualPromise.ManualPromise();
454
- this._raceAgainstEvaluationStallingEventsPromises.add(promise);
455
- try {
456
- return await Promise.race([cb(), promise]);
457
- } finally {
458
- this._raceAgainstEvaluationStallingEventsPromises.delete(promise);
459
- }
460
- }
461
- nonStallingRawEvaluateInExistingMainContext(expression) {
462
- return this.raceAgainstEvaluationStallingEvents(() => {
463
- const context = this._existingMainContext();
464
- if (!context) throw new Error('Frame does not yet have a main execution context');
465
- return context.rawEvaluateJSON(expression);
466
- });
467
- }
468
- nonStallingEvaluateInExistingContext(expression, world) {
469
- return this.raceAgainstEvaluationStallingEvents(() => {
470
- var _this$_contextData$ge;
471
- const context = (_this$_contextData$ge = this._contextData.get(world)) === null || _this$_contextData$ge === void 0 ? void 0 : _this$_contextData$ge.context;
472
- if (!context) throw new Error('Frame does not yet have the execution context');
473
- return context.evaluateExpression(expression, {
474
- isFunction: false
475
- });
476
- });
477
- }
478
- _recalculateNetworkIdle(frameThatAllowsRemovingNetworkIdle) {
479
- let isNetworkIdle = this._firedNetworkIdleSelf;
480
- for (const child of this._childFrames) {
481
- child._recalculateNetworkIdle(frameThatAllowsRemovingNetworkIdle);
482
- // We require networkidle event to be fired in the whole frame subtree, and then consider it done.
483
- if (!child._firedLifecycleEvents.has('networkidle')) isNetworkIdle = false;
484
- }
485
- if (isNetworkIdle && !this._firedLifecycleEvents.has('networkidle')) {
486
- this._firedLifecycleEvents.add('networkidle');
487
- this.emit(Frame.Events.AddLifecycle, 'networkidle');
488
- if (this === this._page.mainFrame() && this._url !== 'about:blank') _debugLogger.debugLogger.log('api', ` "networkidle" event fired`);
489
- }
490
- if (frameThatAllowsRemovingNetworkIdle !== this && this._firedLifecycleEvents.has('networkidle') && !isNetworkIdle) {
491
- // Usually, networkidle is fired once and not removed after that.
492
- // However, when we clear them right before a new commit, this is allowed for a particular frame.
493
- this._firedLifecycleEvents.delete('networkidle');
494
- this.emit(Frame.Events.RemoveLifecycle, 'networkidle');
495
- }
496
- }
497
- async raceNavigationAction(progress, options, action) {
498
- return _utils.LongStandingScope.raceMultiple([this._detachedScope, this._page.openScope], action().catch(e => {
499
- if (e instanceof NavigationAbortedError && e.documentId) {
500
- const data = this._redirectedNavigations.get(e.documentId);
501
- if (data) {
502
- progress.log(`waiting for redirected navigation to "${data.url}"`);
503
- return data.gotoPromise;
504
- }
505
- }
506
- throw e;
507
- }));
508
- }
509
- redirectNavigation(url, documentId, referer) {
510
- const controller = new _progress.ProgressController((0, _instrumentation.serverSideCallMetadata)(), this);
511
- const data = {
512
- url,
513
- gotoPromise: controller.run(progress => this._gotoAction(progress, url, {
514
- referer
515
- }), 0)
516
- };
517
- this._redirectedNavigations.set(documentId, data);
518
- data.gotoPromise.finally(() => this._redirectedNavigations.delete(documentId));
519
- }
520
- async goto(metadata, url, options = {}) {
521
- const constructedNavigationURL = (0, _utils.constructURLBasedOnBaseURL)(this._page._browserContext._options.baseURL, url);
522
- const controller = new _progress.ProgressController(metadata, this);
523
- return controller.run(progress => this._goto(progress, constructedNavigationURL, options), this._page._timeoutSettings.navigationTimeout(options));
524
- }
525
- async _goto(progress, url, options) {
526
- return this.raceNavigationAction(progress, options, async () => this._gotoAction(progress, url, options));
527
- }
528
- async _gotoAction(progress, url, options) {
529
- const waitUntil = verifyLifecycle('waitUntil', options.waitUntil === undefined ? 'load' : options.waitUntil);
530
- progress.log(`navigating to "${url}", waiting until "${waitUntil}"`);
531
- const headers = this._page.extraHTTPHeaders() || [];
532
- const refererHeader = headers.find(h => h.name.toLowerCase() === 'referer');
533
- let referer = refererHeader ? refererHeader.value : undefined;
534
- if (options.referer !== undefined) {
535
- if (referer !== undefined && referer !== options.referer) throw new Error('"referer" is already specified as extra HTTP header');
536
- referer = options.referer;
537
- }
538
- url = _helper.helper.completeUserURL(url);
539
- const navigationEvents = [];
540
- const collectNavigations = arg => navigationEvents.push(arg);
541
- this.on(Frame.Events.InternalNavigation, collectNavigations);
542
- const navigateResult = await this._page._delegate.navigateFrame(this, url, referer).finally(() => this.off(Frame.Events.InternalNavigation, collectNavigations));
543
- let event;
544
- if (navigateResult.newDocumentId) {
545
- const predicate = event => {
546
- // We are interested either in this specific document, or any other document that
547
- // did commit and replaced the expected document.
548
- return event.newDocument && (event.newDocument.documentId === navigateResult.newDocumentId || !event.error);
549
- };
550
- const events = navigationEvents.filter(predicate);
551
- if (events.length) event = events[0];else event = await _helper.helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, predicate).promise;
552
- if (event.newDocument.documentId !== navigateResult.newDocumentId) {
553
- // This is just a sanity check. In practice, new navigation should
554
- // cancel the previous one and report "request cancelled"-like error.
555
- throw new NavigationAbortedError(navigateResult.newDocumentId, `Navigation to "${url}" is interrupted by another navigation to "${event.url}"`);
556
- }
557
- if (event.error) throw event.error;
558
- } else {
559
- // Wait for same document navigation.
560
- const predicate = e => !e.newDocument;
561
- const events = navigationEvents.filter(predicate);
562
- if (events.length) event = events[0];else event = await _helper.helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, predicate).promise;
563
- }
564
- if (!this._firedLifecycleEvents.has(waitUntil)) await _helper.helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, e => e === waitUntil).promise;
565
- const request = event.newDocument ? event.newDocument.request : undefined;
566
- const response = request ? request._finalRequest().response() : null;
567
- return response;
568
- }
569
- async _waitForNavigation(progress, requiresNewDocument, options) {
570
- const waitUntil = verifyLifecycle('waitUntil', options.waitUntil === undefined ? 'load' : options.waitUntil);
571
- progress.log(`waiting for navigation until "${waitUntil}"`);
572
- const navigationEvent = await _helper.helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, event => {
573
- // Any failed navigation results in a rejection.
574
- if (event.error) return true;
575
- if (requiresNewDocument && !event.newDocument) return false;
576
- progress.log(` navigated to "${this._url}"`);
577
- return true;
578
- }).promise;
579
- if (navigationEvent.error) throw navigationEvent.error;
580
- if (!this._firedLifecycleEvents.has(waitUntil)) await _helper.helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, e => e === waitUntil).promise;
581
- const request = navigationEvent.newDocument ? navigationEvent.newDocument.request : undefined;
582
- return request ? request._finalRequest().response() : null;
583
- }
584
- async _waitForLoadState(progress, state) {
585
- const waitUntil = verifyLifecycle('state', state);
586
- if (!this._firedLifecycleEvents.has(waitUntil)) await _helper.helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, e => e === waitUntil).promise;
587
- }
588
- async frameElement() {
589
- return this._page._delegate.getFrameElement(this);
590
- }
591
- _context(world, useContextPromise = false) {
592
- if (process.env['REBROWSER_PATCHES_RUNTIME_FIX_MODE'] === '0' || this._contextData.get(world).context || useContextPromise) {
593
- return this._contextData.get(world).contextPromise.then(contextOrDestroyedReason => {
594
- if (contextOrDestroyedReason instanceof js.ExecutionContext) return contextOrDestroyedReason;
595
- throw new Error(contextOrDestroyedReason.destroyedReason);
596
- });
597
- }
598
- const crSession = (this._page._delegate._sessions.get(this._id) || this._page._delegate._mainFrameSession)._client;
599
- return crSession.__re__emitExecutionContext({
600
- world,
601
- targetId: this._id,
602
- frame: this
603
- }).then(() => {
604
- return this._context(world, true);
605
- }).catch(error => {
606
- if (error.message.includes('No frame for given id found')) {
607
- // ignore, frame is already gone
608
- return {
609
- destroyedReason: 'Frame was detached'
610
- };
611
- }
612
- _debugLogger.debugLogger.log('error', error);
613
- console.error('[rebrowser-patches][frames._context] cannot get world, error:', error);
614
- });
615
- }
616
- _mainContext() {
617
- return this._context('main');
618
- }
619
- _existingMainContext() {
620
- var _this$_contextData$ge2;
621
- return ((_this$_contextData$ge2 = this._contextData.get('main')) === null || _this$_contextData$ge2 === void 0 ? void 0 : _this$_contextData$ge2.context) || null;
622
- }
623
- _utilityContext() {
624
- return this._context('utility');
625
- }
626
- async evaluateExpression(expression, options = {}, arg) {
627
- var _options$world;
628
- const context = await this._context((_options$world = options.world) !== null && _options$world !== void 0 ? _options$world : 'main');
629
- const value = await context.evaluateExpression(expression, options, arg);
630
- return value;
631
- }
632
- async evaluateExpressionHandle(expression, options = {}, arg) {
633
- var _options$world2;
634
- const context = await this._context((_options$world2 = options.world) !== null && _options$world2 !== void 0 ? _options$world2 : 'main');
635
- const value = await context.evaluateExpressionHandle(expression, options, arg);
636
- return value;
637
- }
638
- async querySelector(selector, options) {
639
- _debugLogger.debugLogger.log('api', ` finding element using the selector "${selector}"`);
640
- return this.selectors.query(selector, options);
641
- }
642
- async waitForSelector(metadata, selector, options, scope) {
643
- const controller = new _progress.ProgressController(metadata, this);
644
- if (options.visibility) throw new Error('options.visibility is not supported, did you mean options.state?');
645
- if (options.waitFor && options.waitFor !== 'visible') throw new Error('options.waitFor is not supported, did you mean options.state?');
646
- const {
647
- state = 'visible'
648
- } = options;
649
- if (!['attached', 'detached', 'visible', 'hidden'].includes(state)) throw new Error(`state: expected one of (attached|detached|visible|hidden)`);
650
- return controller.run(async progress => {
651
- progress.log(`waiting for ${this._asLocator(selector)}${state === 'attached' ? '' : ' to be ' + state}`);
652
- return await this.waitForSelectorInternal(progress, selector, true, options, scope);
653
- }, this._page._timeoutSettings.timeout(options));
654
- }
655
- async waitForSelectorInternal(progress, selector, performActionPreChecks, options, scope) {
656
- const {
657
- state = 'visible'
658
- } = options;
659
- const promise = this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async continuePolling => {
660
- if (performActionPreChecks) await this._page.performActionPreChecks(progress);
661
- const resolved = await this.selectors.resolveInjectedForSelector(selector, options, scope);
662
- progress.throwIfAborted();
663
- if (!resolved) {
664
- if (state === 'hidden' || state === 'detached') return null;
665
- return continuePolling;
666
- }
667
- const result = await resolved.injected.evaluateHandle((injected, {
668
- info,
669
- root
670
- }) => {
671
- if (root && !root.isConnected) throw injected.createStacklessError('Element is not attached to the DOM');
672
- const elements = injected.querySelectorAll(info.parsed, root || document);
673
- const element = elements[0];
674
- const visible = element ? injected.utils.isElementVisible(element) : false;
675
- let log = '';
676
- if (elements.length > 1) {
677
- if (info.strict) throw injected.strictModeViolationError(info.parsed, elements);
678
- log = ` locator resolved to ${elements.length} elements. Proceeding with the first one: ${injected.previewNode(elements[0])}`;
679
- } else if (element) {
680
- log = ` locator resolved to ${visible ? 'visible' : 'hidden'} ${injected.previewNode(element)}`;
681
- }
682
- return {
683
- log,
684
- element,
685
- visible,
686
- attached: !!element
687
- };
688
- }, {
689
- info: resolved.info,
690
- root: resolved.frame === this ? scope : undefined
691
- });
692
- const {
693
- log,
694
- visible,
695
- attached
696
- } = await result.evaluate(r => ({
697
- log: r.log,
698
- visible: r.visible,
699
- attached: r.attached
700
- }));
701
- if (log) progress.log(log);
702
- const success = {
703
- attached,
704
- detached: !attached,
705
- visible,
706
- hidden: !visible
707
- }[state];
708
- if (!success) {
709
- result.dispose();
710
- return continuePolling;
711
- }
712
- if (options.omitReturnValue) {
713
- result.dispose();
714
- return null;
715
- }
716
- const element = state === 'attached' || state === 'visible' ? await result.evaluateHandle(r => r.element) : null;
717
- result.dispose();
718
- if (!element) return null;
719
- if (options.__testHookBeforeAdoptNode) await options.__testHookBeforeAdoptNode();
720
- try {
721
- return await element._adoptTo(await resolved.frame._mainContext());
722
- } catch (e) {
723
- return continuePolling;
724
- }
725
- });
726
- return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
727
- }
728
- async dispatchEvent(metadata, selector, type, eventInit = {}, options = {}, scope) {
729
- await this._callOnElementOnceMatches(metadata, selector, (injectedScript, element, data) => {
730
- injectedScript.dispatchEvent(element, data.type, data.eventInit);
731
- }, {
732
- type,
733
- eventInit
734
- }, {
735
- mainWorld: true,
736
- ...options
737
- }, scope);
738
- }
739
- async evalOnSelector(selector, strict, expression, isFunction, arg, scope) {
740
- const handle = await this.selectors.query(selector, {
741
- strict
742
- }, scope);
743
- if (!handle) throw new Error(`Failed to find element matching selector "${selector}"`);
744
- const result = await handle.evaluateExpression(expression, {
745
- isFunction
746
- }, arg);
747
- handle.dispose();
748
- return result;
749
- }
750
- async evalOnSelectorAll(selector, expression, isFunction, arg, scope) {
751
- const arrayHandle = await this.selectors.queryArrayInMainWorld(selector, scope);
752
- const result = await arrayHandle.evaluateExpression(expression, {
753
- isFunction
754
- }, arg);
755
- arrayHandle.dispose();
756
- return result;
757
- }
758
- async maskSelectors(selectors, color) {
759
- const context = await this._utilityContext();
760
- const injectedScript = await context.injectedScript();
761
- await injectedScript.evaluate((injected, {
762
- parsed,
763
- color
764
- }) => {
765
- injected.maskSelectors(parsed, color);
766
- }, {
767
- parsed: selectors,
768
- color: color
769
- });
770
- }
771
- async querySelectorAll(selector) {
772
- return this.selectors.queryAll(selector);
773
- }
774
- async queryCount(selector) {
775
- return await this.selectors.queryCount(selector);
776
- }
777
- async content() {
778
- try {
779
- const context = await this._utilityContext();
780
- return await context.evaluate(() => {
781
- let retVal = '';
782
- if (document.doctype) retVal = new XMLSerializer().serializeToString(document.doctype);
783
- if (document.documentElement) retVal += document.documentElement.outerHTML;
784
- return retVal;
785
- });
786
- } catch (e) {
787
- if (js.isJavaScriptErrorInEvaluate(e) || (0, _protocolError.isSessionClosedError)(e)) throw e;
788
- throw new Error(`Unable to retrieve content because the page is navigating and changing the content.`);
789
- }
790
- }
791
- async setContent(metadata, html, options = {}) {
792
- const controller = new _progress.ProgressController(metadata, this);
793
- return controller.run(async progress => {
794
- await this.raceNavigationAction(progress, options, async () => {
795
- const waitUntil = options.waitUntil === undefined ? 'load' : options.waitUntil;
796
- progress.log(`setting frame content, waiting until "${waitUntil}"`);
797
- const tag = `--playwright--set--content--${this._id}--${++this._setContentCounter}--`;
798
- const context = await this._utilityContext();
799
- const lifecyclePromise = new Promise((resolve, reject) => {
800
- this._page._frameManager._consoleMessageTags.set(tag, () => {
801
- // Clear lifecycle right after document.open() - see 'tag' below.
802
- this._onClearLifecycle();
803
- this._waitForLoadState(progress, waitUntil).then(resolve).catch(reject);
804
- });
805
- });
806
- const contentPromise = context.evaluate(({
807
- html,
808
- tag
809
- }) => {
810
- document.open();
811
- console.debug(tag); // eslint-disable-line no-console
812
- document.write(html);
813
- document.close();
814
- }, {
815
- html,
816
- tag
817
- });
818
- await Promise.all([contentPromise, lifecyclePromise]);
819
- return null;
820
- });
821
- }, this._page._timeoutSettings.navigationTimeout(options));
822
- }
823
- name() {
824
- return this._name || '';
825
- }
826
- url() {
827
- return this._url;
828
- }
829
- origin() {
830
- var _network$parsedURL;
831
- if (!this._url.startsWith('http')) return;
832
- return (_network$parsedURL = network.parsedURL(this._url)) === null || _network$parsedURL === void 0 ? void 0 : _network$parsedURL.origin;
833
- }
834
- parentFrame() {
835
- return this._parentFrame;
836
- }
837
- childFrames() {
838
- return Array.from(this._childFrames);
839
- }
840
- async addScriptTag(params) {
841
- const {
842
- url = null,
843
- content = null,
844
- type = ''
845
- } = params;
846
- if (!url && !content) throw new Error('Provide an object with a `url`, `path` or `content` property');
847
- const context = await this._mainContext();
848
- return this._raceWithCSPError(async () => {
849
- if (url !== null) return (await context.evaluateHandle(addScriptUrl, {
850
- url,
851
- type
852
- })).asElement();
853
- const result = (await context.evaluateHandle(addScriptContent, {
854
- content: content,
855
- type
856
- })).asElement();
857
- // Another round trip to the browser to ensure that we receive CSP error messages
858
- // (if any) logged asynchronously in a separate task on the content main thread.
859
- if (this._page._delegate.cspErrorsAsynchronousForInlineScripts) await context.evaluate(() => true);
860
- return result;
861
- });
862
- async function addScriptUrl(params) {
863
- const script = document.createElement('script');
864
- script.src = params.url;
865
- if (params.type) script.type = params.type;
866
- const promise = new Promise((res, rej) => {
867
- script.onload = res;
868
- script.onerror = e => rej(typeof e === 'string' ? new Error(e) : new Error(`Failed to load script at ${script.src}`));
869
- });
870
- document.head.appendChild(script);
871
- await promise;
872
- return script;
873
- }
874
- function addScriptContent(params) {
875
- const script = document.createElement('script');
876
- script.type = params.type || 'text/javascript';
877
- script.text = params.content;
878
- let error = null;
879
- script.onerror = e => error = e;
880
- document.head.appendChild(script);
881
- if (error) throw error;
882
- return script;
883
- }
884
- }
885
- async addStyleTag(params) {
886
- const {
887
- url = null,
888
- content = null
889
- } = params;
890
- if (!url && !content) throw new Error('Provide an object with a `url`, `path` or `content` property');
891
- const context = await this._mainContext();
892
- return this._raceWithCSPError(async () => {
893
- if (url !== null) return (await context.evaluateHandle(addStyleUrl, url)).asElement();
894
- return (await context.evaluateHandle(addStyleContent, content)).asElement();
895
- });
896
- async function addStyleUrl(url) {
897
- const link = document.createElement('link');
898
- link.rel = 'stylesheet';
899
- link.href = url;
900
- const promise = new Promise((res, rej) => {
901
- link.onload = res;
902
- link.onerror = rej;
903
- });
904
- document.head.appendChild(link);
905
- await promise;
906
- return link;
907
- }
908
- async function addStyleContent(content) {
909
- const style = document.createElement('style');
910
- style.type = 'text/css';
911
- style.appendChild(document.createTextNode(content));
912
- const promise = new Promise((res, rej) => {
913
- style.onload = res;
914
- style.onerror = rej;
915
- });
916
- document.head.appendChild(style);
917
- await promise;
918
- return style;
919
- }
920
- }
921
- async _raceWithCSPError(func) {
922
- const listeners = [];
923
- let result;
924
- let error;
925
- let cspMessage;
926
- const actionPromise = func().then(r => result = r).catch(e => error = e);
927
- const errorPromise = new Promise(resolve => {
928
- listeners.push(_eventsHelper.eventsHelper.addEventListener(this._page._browserContext, _browserContext.BrowserContext.Events.Console, message => {
929
- if (message.page() !== this._page || message.type() !== 'error') return;
930
- if (message.text().includes('Content-Security-Policy') || message.text().includes('Content Security Policy')) {
931
- cspMessage = message;
932
- resolve();
933
- }
934
- }));
935
- });
936
- await Promise.race([actionPromise, errorPromise]);
937
- _eventsHelper.eventsHelper.removeEventListeners(listeners);
938
- if (cspMessage) throw new Error(cspMessage.text());
939
- if (error) throw error;
940
- return result;
941
- }
942
- async retryWithProgressAndTimeouts(progress, timeouts, action) {
943
- const continuePolling = Symbol('continuePolling');
944
- timeouts = [0, ...timeouts];
945
- let timeoutIndex = 0;
946
- while (progress.isRunning()) {
947
- const timeout = timeouts[Math.min(timeoutIndex++, timeouts.length - 1)];
948
- if (timeout) {
949
- // Make sure we react immediately upon page close or frame detach.
950
- // We need this to show expected/received values in time.
951
- const actionPromise = new Promise(f => setTimeout(f, timeout));
952
- await _utils.LongStandingScope.raceMultiple([this._page.openScope, this._detachedScope], actionPromise);
953
- }
954
- progress.throwIfAborted();
955
- try {
956
- const result = await action(continuePolling);
957
- if (result === continuePolling) continue;
958
- return result;
959
- } catch (e) {
960
- if (this._isErrorThatCannotBeRetried(e)) throw e;
961
- continue;
962
- }
963
- }
964
- progress.throwIfAborted();
965
- return undefined;
966
- }
967
- _isErrorThatCannotBeRetried(e) {
968
- // Always fail on JavaScript errors or when the main connection is closed.
969
- if (js.isJavaScriptErrorInEvaluate(e) || (0, _protocolError.isSessionClosedError)(e)) return true;
970
- // Certain errors opt-out of the retries, throw.
971
- if (dom.isNonRecoverableDOMError(e) || (0, _selectorParser.isInvalidSelectorError)(e)) return true;
972
- // If the call is made on the detached frame - throw.
973
- if (this.isDetached()) return true;
974
- // Retry upon all other errors.
975
- return false;
976
- }
977
- async _retryWithProgressIfNotConnected(progress, selector, strict, performActionPreChecks, action) {
978
- progress.log(`waiting for ${this._asLocator(selector)}`);
979
- return this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async continuePolling => {
980
- if (performActionPreChecks) await this._page.performActionPreChecks(progress);
981
- const resolved = await this.selectors.resolveInjectedForSelector(selector, {
982
- strict
983
- });
984
- progress.throwIfAborted();
985
- if (!resolved) return continuePolling;
986
- const result = await resolved.injected.evaluateHandle((injected, {
987
- info,
988
- callId
989
- }) => {
990
- const elements = injected.querySelectorAll(info.parsed, document);
991
- if (callId) injected.markTargetElements(new Set(elements), callId);
992
- const element = elements[0];
993
- let log = '';
994
- if (elements.length > 1) {
995
- if (info.strict) throw injected.strictModeViolationError(info.parsed, elements);
996
- log = ` locator resolved to ${elements.length} elements. Proceeding with the first one: ${injected.previewNode(elements[0])}`;
997
- } else if (element) {
998
- log = ` locator resolved to ${injected.previewNode(element)}`;
999
- }
1000
- return {
1001
- log,
1002
- success: !!element,
1003
- element
1004
- };
1005
- }, {
1006
- info: resolved.info,
1007
- callId: progress.metadata.id
1008
- });
1009
- const {
1010
- log,
1011
- success
1012
- } = await result.evaluate(r => ({
1013
- log: r.log,
1014
- success: r.success
1015
- }));
1016
- if (log) progress.log(log);
1017
- if (!success) {
1018
- result.dispose();
1019
- return continuePolling;
1020
- }
1021
- const element = await result.evaluateHandle(r => r.element);
1022
- result.dispose();
1023
- try {
1024
- const result = await action(element);
1025
- if (result === 'error:notconnected') {
1026
- progress.log('element was detached from the DOM, retrying');
1027
- return continuePolling;
1028
- }
1029
- return result;
1030
- } finally {
1031
- element === null || element === void 0 || element.dispose();
1032
- }
1033
- });
1034
- }
1035
- async rafrafTimeoutScreenshotElementWithProgress(progress, selector, timeout, options) {
1036
- return await this._retryWithProgressIfNotConnected(progress, selector, true /* strict */, true /* performActionPreChecks */, async handle => {
1037
- await handle._frame.rafrafTimeout(timeout);
1038
- return await this._page._screenshotter.screenshotElement(progress, handle, options);
1039
- });
1040
- }
1041
- async click(metadata, selector, options) {
1042
- const controller = new _progress.ProgressController(metadata, this);
1043
- return controller.run(async progress => {
1044
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._click(progress, {
1045
- ...options,
1046
- waitAfter: !options.noWaitAfter
1047
- })));
1048
- }, this._page._timeoutSettings.timeout(options));
1049
- }
1050
- async dblclick(metadata, selector, options = {}) {
1051
- const controller = new _progress.ProgressController(metadata, this);
1052
- return controller.run(async progress => {
1053
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._dblclick(progress, options)));
1054
- }, this._page._timeoutSettings.timeout(options));
1055
- }
1056
- async dragAndDrop(metadata, source, target, options = {}) {
1057
- const controller = new _progress.ProgressController(metadata, this);
1058
- await controller.run(async progress => {
1059
- dom.assertDone(await this._retryWithProgressIfNotConnected(progress, source, options.strict, !options.force /* performActionPreChecks */, async handle => {
1060
- return handle._retryPointerAction(progress, 'move and down', false, async point => {
1061
- await this._page.mouse.move(point.x, point.y);
1062
- await this._page.mouse.down();
1063
- }, {
1064
- ...options,
1065
- waitAfter: 'disabled',
1066
- position: options.sourcePosition,
1067
- timeout: progress.timeUntilDeadline()
1068
- });
1069
- }));
1070
- // Note: do not perform locator handlers checkpoint to avoid moving the mouse in the middle of a drag operation.
1071
- dom.assertDone(await this._retryWithProgressIfNotConnected(progress, target, options.strict, false /* performActionPreChecks */, async handle => {
1072
- return handle._retryPointerAction(progress, 'move and up', false, async point => {
1073
- await this._page.mouse.move(point.x, point.y);
1074
- await this._page.mouse.up();
1075
- }, {
1076
- ...options,
1077
- waitAfter: 'disabled',
1078
- position: options.targetPosition,
1079
- timeout: progress.timeUntilDeadline()
1080
- });
1081
- }));
1082
- }, this._page._timeoutSettings.timeout(options));
1083
- }
1084
- async tap(metadata, selector, options) {
1085
- if (!this._page._browserContext._options.hasTouch) throw new Error('The page does not support tap. Use hasTouch context option to enable touch support.');
1086
- const controller = new _progress.ProgressController(metadata, this);
1087
- return controller.run(async progress => {
1088
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._tap(progress, options)));
1089
- }, this._page._timeoutSettings.timeout(options));
1090
- }
1091
- async fill(metadata, selector, value, options) {
1092
- const controller = new _progress.ProgressController(metadata, this);
1093
- return controller.run(async progress => {
1094
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._fill(progress, value, options)));
1095
- }, this._page._timeoutSettings.timeout(options));
1096
- }
1097
- async focus(metadata, selector, options = {}) {
1098
- const controller = new _progress.ProgressController(metadata, this);
1099
- await controller.run(async progress => {
1100
- dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true /* performActionPreChecks */, handle => handle._focus(progress)));
1101
- }, this._page._timeoutSettings.timeout(options));
1102
- }
1103
- async blur(metadata, selector, options = {}) {
1104
- const controller = new _progress.ProgressController(metadata, this);
1105
- await controller.run(async progress => {
1106
- dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true /* performActionPreChecks */, handle => handle._blur(progress)));
1107
- }, this._page._timeoutSettings.timeout(options));
1108
- }
1109
- async textContent(metadata, selector, options = {}, scope) {
1110
- return this._callOnElementOnceMatches(metadata, selector, (injected, element) => element.textContent, undefined, options, scope);
1111
- }
1112
- async innerText(metadata, selector, options = {}, scope) {
1113
- return this._callOnElementOnceMatches(metadata, selector, (injectedScript, element) => {
1114
- if (element.namespaceURI !== 'http://www.w3.org/1999/xhtml') throw injectedScript.createStacklessError('Node is not an HTMLElement');
1115
- return element.innerText;
1116
- }, undefined, options, scope);
1117
- }
1118
- async innerHTML(metadata, selector, options = {}, scope) {
1119
- return this._callOnElementOnceMatches(metadata, selector, (injected, element) => element.innerHTML, undefined, options, scope);
1120
- }
1121
- async getAttribute(metadata, selector, name, options = {}, scope) {
1122
- return this._callOnElementOnceMatches(metadata, selector, (injected, element, data) => element.getAttribute(data.name), {
1123
- name
1124
- }, options, scope);
1125
- }
1126
- async inputValue(metadata, selector, options = {}, scope) {
1127
- return this._callOnElementOnceMatches(metadata, selector, (injectedScript, node) => {
1128
- const element = injectedScript.retarget(node, 'follow-label');
1129
- if (!element || element.nodeName !== 'INPUT' && element.nodeName !== 'TEXTAREA' && element.nodeName !== 'SELECT') throw injectedScript.createStacklessError('Node is not an <input>, <textarea> or <select> element');
1130
- return element.value;
1131
- }, undefined, options, scope);
1132
- }
1133
- async highlight(selector) {
1134
- const resolved = await this.selectors.resolveInjectedForSelector(selector);
1135
- if (!resolved) return;
1136
- return await resolved.injected.evaluate((injected, {
1137
- info
1138
- }) => {
1139
- return injected.highlight(info.parsed);
1140
- }, {
1141
- info: resolved.info
1142
- });
1143
- }
1144
- async hideHighlight() {
1145
- return this.raceAgainstEvaluationStallingEvents(async () => {
1146
- const context = await this._utilityContext();
1147
- const injectedScript = await context.injectedScript();
1148
- return await injectedScript.evaluate(injected => {
1149
- return injected.hideHighlight();
1150
- });
1151
- });
1152
- }
1153
- async _elementState(metadata, selector, state, options = {}, scope) {
1154
- const result = await this._callOnElementOnceMatches(metadata, selector, (injected, element, data) => {
1155
- return injected.elementState(element, data.state);
1156
- }, {
1157
- state
1158
- }, options, scope);
1159
- return dom.throwRetargetableDOMError(result);
1160
- }
1161
- async isVisible(metadata, selector, options = {}, scope) {
1162
- const controller = new _progress.ProgressController(metadata, this);
1163
- return controller.run(async progress => {
1164
- progress.log(` checking visibility of ${this._asLocator(selector)}`);
1165
- return await this.isVisibleInternal(selector, options, scope);
1166
- }, this._page._timeoutSettings.timeout({}));
1167
- }
1168
- async isVisibleInternal(selector, options = {}, scope) {
1169
- try {
1170
- const resolved = await this.selectors.resolveInjectedForSelector(selector, options, scope);
1171
- if (!resolved) return false;
1172
- return await resolved.injected.evaluate((injected, {
1173
- info,
1174
- root
1175
- }) => {
1176
- const element = injected.querySelector(info.parsed, root || document, info.strict);
1177
- const state = element ? injected.elementState(element, 'visible') : false;
1178
- return state === 'error:notconnected' ? false : state;
1179
- }, {
1180
- info: resolved.info,
1181
- root: resolved.frame === this ? scope : undefined
1182
- });
1183
- } catch (e) {
1184
- if (js.isJavaScriptErrorInEvaluate(e) || (0, _selectorParser.isInvalidSelectorError)(e) || (0, _protocolError.isSessionClosedError)(e)) throw e;
1185
- return false;
1186
- }
1187
- }
1188
- async isHidden(metadata, selector, options = {}, scope) {
1189
- return !(await this.isVisible(metadata, selector, options, scope));
1190
- }
1191
- async isDisabled(metadata, selector, options = {}, scope) {
1192
- return this._elementState(metadata, selector, 'disabled', options, scope);
1193
- }
1194
- async isEnabled(metadata, selector, options = {}, scope) {
1195
- return this._elementState(metadata, selector, 'enabled', options, scope);
1196
- }
1197
- async isEditable(metadata, selector, options = {}, scope) {
1198
- return this._elementState(metadata, selector, 'editable', options, scope);
1199
- }
1200
- async isChecked(metadata, selector, options = {}, scope) {
1201
- return this._elementState(metadata, selector, 'checked', options, scope);
1202
- }
1203
- async hover(metadata, selector, options = {}) {
1204
- const controller = new _progress.ProgressController(metadata, this);
1205
- return controller.run(async progress => {
1206
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._hover(progress, options)));
1207
- }, this._page._timeoutSettings.timeout(options));
1208
- }
1209
- async selectOption(metadata, selector, elements, values, options = {}) {
1210
- const controller = new _progress.ProgressController(metadata, this);
1211
- return controller.run(async progress => {
1212
- return await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._selectOption(progress, elements, values, options));
1213
- }, this._page._timeoutSettings.timeout(options));
1214
- }
1215
- async setInputFiles(metadata, selector, params) {
1216
- const inputFileItems = await (0, _fileUploadUtils.prepareFilesForUpload)(this, params);
1217
- const controller = new _progress.ProgressController(metadata, this);
1218
- return controller.run(async progress => {
1219
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, params.strict, true /* performActionPreChecks */, handle => handle._setInputFiles(progress, inputFileItems)));
1220
- }, this._page._timeoutSettings.timeout(params));
1221
- }
1222
- async type(metadata, selector, text, options = {}) {
1223
- const controller = new _progress.ProgressController(metadata, this);
1224
- return controller.run(async progress => {
1225
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true /* performActionPreChecks */, handle => handle._type(progress, text, options)));
1226
- }, this._page._timeoutSettings.timeout(options));
1227
- }
1228
- async press(metadata, selector, key, options = {}) {
1229
- const controller = new _progress.ProgressController(metadata, this);
1230
- return controller.run(async progress => {
1231
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true /* performActionPreChecks */, handle => handle._press(progress, key, options)));
1232
- }, this._page._timeoutSettings.timeout(options));
1233
- }
1234
- async check(metadata, selector, options = {}) {
1235
- const controller = new _progress.ProgressController(metadata, this);
1236
- return controller.run(async progress => {
1237
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._setChecked(progress, true, options)));
1238
- }, this._page._timeoutSettings.timeout(options));
1239
- }
1240
- async uncheck(metadata, selector, options = {}) {
1241
- const controller = new _progress.ProgressController(metadata, this);
1242
- return controller.run(async progress => {
1243
- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._setChecked(progress, false, options)));
1244
- }, this._page._timeoutSettings.timeout(options));
1245
- }
1246
- async waitForTimeout(metadata, timeout) {
1247
- const controller = new _progress.ProgressController(metadata, this);
1248
- return controller.run(async () => {
1249
- await new Promise(resolve => setTimeout(resolve, timeout));
1250
- });
1251
- }
1252
- async ariaSnapshot(metadata, selector, options = {}) {
1253
- const controller = new _progress.ProgressController(metadata, this);
1254
- return controller.run(async progress => {
1255
- return await this._retryWithProgressIfNotConnected(progress, selector, true /* strict */, true /* performActionPreChecks */, handle => handle.ariaSnapshot());
1256
- }, this._page._timeoutSettings.timeout(options));
1257
- }
1258
- async expect(metadata, selector, options) {
1259
- const result = await this._expectImpl(metadata, selector, options);
1260
- // Library mode special case for the expect errors which are return values, not exceptions.
1261
- if (result.matches === options.isNot) metadata.error = {
1262
- error: {
1263
- name: 'Expect',
1264
- message: 'Expect failed'
1265
- }
1266
- };
1267
- return result;
1268
- }
1269
- async _expectImpl(metadata, selector, options) {
1270
- const lastIntermediateResult = {
1271
- isSet: false
1272
- };
1273
- try {
1274
- let timeout = this._page._timeoutSettings.timeout(options);
1275
- const start = timeout > 0 ? (0, _utils.monotonicTime)() : 0;
1276
-
1277
- // Step 1: perform locator handlers checkpoint with a specified timeout.
1278
- await new _progress.ProgressController(metadata, this).run(async progress => {
1279
- progress.log(`${metadata.apiName}${timeout ? ` with timeout ${timeout}ms` : ''}`);
1280
- progress.log(`waiting for ${this._asLocator(selector)}`);
1281
- await this._page.performActionPreChecks(progress);
1282
- }, timeout);
1283
-
1284
- // Step 2: perform one-shot expect check without a timeout.
1285
- // Supports the case of `expect(locator).toBeVisible({ timeout: 1 })`
1286
- // that should succeed when the locator is already visible.
1287
- try {
1288
- const resultOneShot = await new _progress.ProgressController(metadata, this).run(async progress => {
1289
- return await this._expectInternal(progress, selector, options, lastIntermediateResult);
1290
- });
1291
- if (resultOneShot.matches !== options.isNot) return resultOneShot;
1292
- } catch (e) {
1293
- if (js.isJavaScriptErrorInEvaluate(e) || (0, _selectorParser.isInvalidSelectorError)(e)) throw e;
1294
- // Ignore any other errors from one-shot, we'll handle them during retries.
1295
- }
1296
- if (timeout > 0) {
1297
- const elapsed = (0, _utils.monotonicTime)() - start;
1298
- timeout -= elapsed;
1299
- }
1300
- if (timeout < 0) return {
1301
- matches: options.isNot,
1302
- log: (0, _utils.compressCallLog)(metadata.log),
1303
- timedOut: true,
1304
- received: lastIntermediateResult.received
1305
- };
1306
-
1307
- // Step 3: auto-retry expect with increasing timeouts. Bounded by the total remaining time.
1308
- return await new _progress.ProgressController(metadata, this).run(async progress => {
1309
- return await this.retryWithProgressAndTimeouts(progress, [100, 250, 500, 1000], async continuePolling => {
1310
- await this._page.performActionPreChecks(progress);
1311
- const {
1312
- matches,
1313
- received
1314
- } = await this._expectInternal(progress, selector, options, lastIntermediateResult);
1315
- if (matches === options.isNot) {
1316
- // Keep waiting in these cases:
1317
- // expect(locator).conditionThatDoesNotMatch
1318
- // expect(locator).not.conditionThatDoesMatch
1319
- return continuePolling;
1320
- }
1321
- return {
1322
- matches,
1323
- received
1324
- };
1325
- });
1326
- }, timeout);
1327
- } catch (e) {
1328
- // Q: Why not throw upon isSessionClosedError(e) as in other places?
1329
- // A: We want user to receive a friendly message containing the last intermediate result.
1330
- if (js.isJavaScriptErrorInEvaluate(e) || (0, _selectorParser.isInvalidSelectorError)(e)) throw e;
1331
- const result = {
1332
- matches: options.isNot,
1333
- log: (0, _utils.compressCallLog)(metadata.log)
1334
- };
1335
- if (lastIntermediateResult.isSet) result.received = lastIntermediateResult.received;
1336
- if (e instanceof _errors.TimeoutError) result.timedOut = true;
1337
- return result;
1338
- }
1339
- }
1340
- async _expectInternal(progress, selector, options, lastIntermediateResult) {
1341
- var _info$world;
1342
- const selectorInFrame = await this.selectors.resolveFrameForSelector(selector, {
1343
- strict: true
1344
- });
1345
- progress.throwIfAborted();
1346
- const {
1347
- frame,
1348
- info
1349
- } = selectorInFrame || {
1350
- frame: this,
1351
- info: undefined
1352
- };
1353
- const world = options.expression === 'to.have.property' ? 'main' : (_info$world = info === null || info === void 0 ? void 0 : info.world) !== null && _info$world !== void 0 ? _info$world : 'utility';
1354
- const context = await frame._context(world);
1355
- const injected = await context.injectedScript();
1356
- progress.throwIfAborted();
1357
- const {
1358
- log,
1359
- matches,
1360
- received,
1361
- missingReceived
1362
- } = await injected.evaluate(async (injected, {
1363
- info,
1364
- options,
1365
- callId
1366
- }) => {
1367
- const elements = info ? injected.querySelectorAll(info.parsed, document) : [];
1368
- if (callId) injected.markTargetElements(new Set(elements), callId);
1369
- const isArray = options.expression === 'to.have.count' || options.expression.endsWith('.array');
1370
- let log = '';
1371
- if (isArray) log = ` locator resolved to ${elements.length} element${elements.length === 1 ? '' : 's'}`;else if (elements.length > 1) throw injected.strictModeViolationError(info.parsed, elements);else if (elements.length) log = ` locator resolved to ${injected.previewNode(elements[0])}`;
1372
- return {
1373
- log,
1374
- ...(await injected.expect(elements[0], options, elements))
1375
- };
1376
- }, {
1377
- info,
1378
- options,
1379
- callId: progress.metadata.id
1380
- });
1381
- if (log) progress.log(log);
1382
- // Note: missingReceived avoids `unexpected value "undefined"` when element was not found.
1383
- if (matches === options.isNot) {
1384
- lastIntermediateResult.received = missingReceived ? '<element(s) not found>' : received;
1385
- lastIntermediateResult.isSet = true;
1386
- if (!missingReceived && !Array.isArray(received)) progress.log(` unexpected value "${renderUnexpectedValue(options.expression, received)}"`);
1387
- }
1388
- return {
1389
- matches,
1390
- received
1391
- };
1392
- }
1393
- async _waitForFunctionExpression(metadata, expression, isFunction, arg, options, world = 'main') {
1394
- const controller = new _progress.ProgressController(metadata, this);
1395
- if (typeof options.pollingInterval === 'number') (0, _utils.assert)(options.pollingInterval > 0, 'Cannot poll with non-positive interval: ' + options.pollingInterval);
1396
- expression = js.normalizeEvaluationExpression(expression, isFunction);
1397
- return controller.run(async progress => {
1398
- return this.retryWithProgressAndTimeouts(progress, [100], async () => {
1399
- const context = world === 'main' ? await this._mainContext() : await this._utilityContext();
1400
- const injectedScript = await context.injectedScript();
1401
- const handle = await injectedScript.evaluateHandle((injected, {
1402
- expression,
1403
- isFunction,
1404
- polling,
1405
- arg
1406
- }) => {
1407
- const predicate = () => {
1408
- // NOTE: make sure to use `globalThis.eval` instead of `self.eval` due to a bug with sandbox isolation
1409
- // in firefox.
1410
- // See https://bugzilla.mozilla.org/show_bug.cgi?id=1814898
1411
- let result = globalThis.eval(expression);
1412
- if (isFunction === true) {
1413
- result = result(arg);
1414
- } else if (isFunction === false) {
1415
- result = result;
1416
- } else {
1417
- // auto detect.
1418
- if (typeof result === 'function') result = result(arg);
1419
- }
1420
- return result;
1421
- };
1422
- let fulfill;
1423
- let reject;
1424
- let aborted = false;
1425
- const result = new Promise((f, r) => {
1426
- fulfill = f;
1427
- reject = r;
1428
- });
1429
- const next = () => {
1430
- if (aborted) return;
1431
- try {
1432
- const success = predicate();
1433
- if (success) {
1434
- fulfill(success);
1435
- return;
1436
- }
1437
- if (typeof polling !== 'number') injected.builtinRequestAnimationFrame(next);else injected.builtinSetTimeout(next, polling);
1438
- } catch (e) {
1439
- reject(e);
1440
- }
1441
- };
1442
- next();
1443
- return {
1444
- result,
1445
- abort: () => aborted = true
1446
- };
1447
- }, {
1448
- expression,
1449
- isFunction,
1450
- polling: options.pollingInterval,
1451
- arg
1452
- });
1453
- progress.cleanupWhenAborted(() => handle.evaluate(h => h.abort()).catch(() => {}));
1454
- return handle.evaluateHandle(h => h.result);
1455
- });
1456
- }, this._page._timeoutSettings.timeout(options));
1457
- }
1458
- async waitForFunctionValueInUtility(progress, pageFunction) {
1459
- const expression = `() => {
1460
- const result = (${pageFunction})();
1461
- if (!result)
1462
- return result;
1463
- return JSON.stringify(result);
1464
- }`;
1465
- const handle = await this._waitForFunctionExpression((0, _instrumentation.serverSideCallMetadata)(), expression, true, undefined, {
1466
- timeout: progress.timeUntilDeadline()
1467
- }, 'utility');
1468
- return JSON.parse(handle.rawValue());
1469
- }
1470
- async title() {
1471
- const context = await this._utilityContext();
1472
- return context.evaluate(() => document.title);
1473
- }
1474
- async rafrafTimeout(timeout) {
1475
- if (timeout === 0) return;
1476
- const context = await this._utilityContext();
1477
- await Promise.all([
1478
- // wait for double raf
1479
- context.evaluate(() => new Promise(x => {
1480
- requestAnimationFrame(() => {
1481
- requestAnimationFrame(x);
1482
- });
1483
- })), new Promise(fulfill => setTimeout(fulfill, timeout))]);
1484
- }
1485
- _onDetached() {
1486
- this._stopNetworkIdleTimer();
1487
- this._detachedScope.close(new Error('Frame was detached'));
1488
- for (const data of this._contextData.values()) {
1489
- if (data.context) data.context.contextDestroyed('Frame was detached');
1490
- data.contextPromise.resolve({
1491
- destroyedReason: 'Frame was detached'
1492
- });
1493
- }
1494
- if (this._parentFrame) this._parentFrame._childFrames.delete(this);
1495
- this._parentFrame = null;
1496
- }
1497
- async _callOnElementOnceMatches(metadata, selector, body, taskData, options = {}, scope) {
1498
- const callbackText = body.toString();
1499
- const controller = new _progress.ProgressController(metadata, this);
1500
- return controller.run(async progress => {
1501
- progress.log(`waiting for ${this._asLocator(selector)}`);
1502
- const promise = this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async continuePolling => {
1503
- const resolved = await this.selectors.resolveInjectedForSelector(selector, options, scope);
1504
- progress.throwIfAborted();
1505
- if (!resolved) return continuePolling;
1506
- const {
1507
- log,
1508
- success,
1509
- value
1510
- } = await resolved.injected.evaluate((injected, {
1511
- info,
1512
- callbackText,
1513
- taskData,
1514
- callId,
1515
- root
1516
- }) => {
1517
- const callback = injected.eval(callbackText);
1518
- const element = injected.querySelector(info.parsed, root || document, info.strict);
1519
- if (!element) return {
1520
- success: false
1521
- };
1522
- const log = ` locator resolved to ${injected.previewNode(element)}`;
1523
- if (callId) injected.markTargetElements(new Set([element]), callId);
1524
- return {
1525
- log,
1526
- success: true,
1527
- value: callback(injected, element, taskData)
1528
- };
1529
- }, {
1530
- info: resolved.info,
1531
- callbackText,
1532
- taskData,
1533
- callId: progress.metadata.id,
1534
- root: resolved.frame === this ? scope : undefined
1535
- });
1536
- if (log) progress.log(log);
1537
- if (!success) return continuePolling;
1538
- return value;
1539
- });
1540
- return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
1541
- }, this._page._timeoutSettings.timeout(options));
1542
- }
1543
- _setContext(world, context) {
1544
- const data = this._contextData.get(world);
1545
- data.context = context;
1546
- if (context) data.contextPromise.resolve(context);else data.contextPromise = new _manualPromise.ManualPromise();
1547
- }
1548
- _contextCreated(world, context) {
1549
- const data = this._contextData.get(world);
1550
- // In case of multiple sessions to the same target, there's a race between
1551
- // connections so we might end up creating multiple isolated worlds.
1552
- // We can use either.
1553
- if (data.context) {
1554
- data.context.contextDestroyed('Execution context was destroyed, most likely because of a navigation');
1555
- this._setContext(world, null);
1556
- }
1557
- this._setContext(world, context);
1558
- }
1559
- _contextDestroyed(context) {
1560
- // Sometimes we get this after detach, in which case we should not reset
1561
- // our already destroyed contexts to something that will never resolve.
1562
- if (this._detachedScope.isClosed()) return;
1563
- context.contextDestroyed('Execution context was destroyed, most likely because of a navigation');
1564
- for (const [world, data] of this._contextData) {
1565
- if (data.context === context) this._setContext(world, null);
1566
- }
1567
- }
1568
- _startNetworkIdleTimer() {
1569
- (0, _utils.assert)(!this._networkIdleTimer);
1570
- // We should not start a timer and report networkidle in detached frames.
1571
- // This happens at least in Firefox for child frames, where we may get requestFinished
1572
- // after the frame was detached - probably a race in the Firefox itself.
1573
- if (this._firedLifecycleEvents.has('networkidle') || this._detachedScope.isClosed()) return;
1574
- this._networkIdleTimer = setTimeout(() => {
1575
- this._firedNetworkIdleSelf = true;
1576
- this._page.mainFrame()._recalculateNetworkIdle();
1577
- }, 500);
1578
- }
1579
- _stopNetworkIdleTimer() {
1580
- if (this._networkIdleTimer) clearTimeout(this._networkIdleTimer);
1581
- this._networkIdleTimer = undefined;
1582
- this._firedNetworkIdleSelf = false;
1583
- }
1584
- async extendInjectedScript(source, arg) {
1585
- const context = await this._context('main');
1586
- const injectedScriptHandle = await context.injectedScript();
1587
- return injectedScriptHandle.evaluateHandle((injectedScript, {
1588
- source,
1589
- arg
1590
- }) => {
1591
- return injectedScript.extend(source, arg);
1592
- }, {
1593
- source,
1594
- arg
1595
- });
1596
- }
1597
- async resetStorageForCurrentOriginBestEffort(newStorage) {
1598
- const context = await this._utilityContext();
1599
- await context.evaluate(async ({
1600
- ls
1601
- }) => {
1602
- // Clean DOMStorage.
1603
- sessionStorage.clear();
1604
- localStorage.clear();
1605
-
1606
- // Add new DOM Storage values.
1607
- for (const entry of ls || []) localStorage[entry.name] = entry.value;
1608
-
1609
- // Clean Service Workers
1610
- const registrations = navigator.serviceWorker ? await navigator.serviceWorker.getRegistrations() : [];
1611
- await Promise.all(registrations.map(async r => {
1612
- // Heuristic for service workers that stalled during main script fetch or importScripts:
1613
- // Waiting for them to finish unregistering takes ages so we do not await.
1614
- // However, they will unregister immediately after fetch finishes and should not affect next page load.
1615
- // Unfortunately, loading next page in Chromium still takes 5 seconds waiting for
1616
- // some operation on this bogus service worker to finish.
1617
- if (!r.installing && !r.waiting && !r.active) r.unregister().catch(() => {});else await r.unregister().catch(() => {});
1618
- }));
1619
-
1620
- // Clean IndexedDB
1621
- for (const db of (await ((_indexedDB$databases = (_indexedDB = indexedDB).databases) === null || _indexedDB$databases === void 0 ? void 0 : _indexedDB$databases.call(_indexedDB))) || []) {
1622
- var _indexedDB$databases, _indexedDB;
1623
- // Do not wait for the callback - it is called on timer in Chromium (slow).
1624
- if (db.name) indexedDB.deleteDatabase(db.name);
1625
- }
1626
- }, {
1627
- ls: newStorage === null || newStorage === void 0 ? void 0 : newStorage.localStorage
1628
- }).catch(() => {});
1629
- }
1630
- _asLocator(selector) {
1631
- return (0, _utils.asLocator)(this._page.attribution.playwright.options.sdkLanguage, selector);
1632
- }
1633
- }
1634
- exports.Frame = Frame;
1635
- Frame.Events = {
1636
- InternalNavigation: 'internalnavigation',
1637
- AddLifecycle: 'addlifecycle',
1638
- RemoveLifecycle: 'removelifecycle'
1639
- };
1640
- class SignalBarrier {
1641
- constructor(progress) {
1642
- this._progress = void 0;
1643
- this._protectCount = 0;
1644
- this._promise = new _manualPromise.ManualPromise();
1645
- this._progress = progress;
1646
- this.retain();
1647
- }
1648
- waitFor() {
1649
- this.release();
1650
- return this._promise;
1651
- }
1652
- async addFrameNavigation(frame) {
1653
- // Auto-wait top-level navigations only.
1654
- if (frame.parentFrame()) return;
1655
- this.retain();
1656
- const waiter = _helper.helper.waitForEvent(null, frame, Frame.Events.InternalNavigation, e => {
1657
- if (!e.isPublic) return false;
1658
- if (!e.error && this._progress) this._progress.log(` navigated to "${frame._url}"`);
1659
- return true;
1660
- });
1661
- await _utils.LongStandingScope.raceMultiple([frame._page.openScope, frame._detachedScope], waiter.promise).catch(() => {});
1662
- waiter.dispose();
1663
- this.release();
1664
- }
1665
- retain() {
1666
- ++this._protectCount;
1667
- }
1668
- release() {
1669
- --this._protectCount;
1670
- if (!this._protectCount) this._promise.resolve();
1671
- }
1672
- }
1673
- function verifyLifecycle(name, waitUntil) {
1674
- if (waitUntil === 'networkidle0') waitUntil = 'networkidle';
1675
- if (!types.kLifecycleEvents.has(waitUntil)) throw new Error(`${name}: expected one of (load|domcontentloaded|networkidle|commit)`);
1676
- return waitUntil;
1677
- }
1678
- function renderUnexpectedValue(expression, received) {
1679
- if (expression === 'to.be.checked') return received ? 'checked' : 'unchecked';
1680
- if (expression === 'to.be.unchecked') return received ? 'unchecked' : 'checked';
1681
- if (expression === 'to.be.visible') return received ? 'visible' : 'hidden';
1682
- if (expression === 'to.be.hidden') return received ? 'hidden' : 'visible';
1683
- if (expression === 'to.be.enabled') return received ? 'enabled' : 'disabled';
1684
- if (expression === 'to.be.disabled') return received ? 'disabled' : 'enabled';
1685
- if (expression === 'to.be.editable') return received ? 'editable' : 'readonly';
1686
- if (expression === 'to.be.readonly') return received ? 'readonly' : 'editable';
1687
- if (expression === 'to.be.empty') return received ? 'empty' : 'not empty';
1688
- if (expression === 'to.be.focused') return received ? 'focused' : 'not focused';
1689
- if (expression === 'to.match.aria') return received ? received.raw : received;
1690
- return received;
1691
- }