pure-patchright 1.52.5__py3-none-any.whl
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.
- patchright/__init__.py +5 -0
- patchright/__main__.py +18 -0
- patchright/_impl/__init__.py +0 -0
- patchright/_impl/__pyinstaller/__init__.py +20 -0
- patchright/_impl/__pyinstaller/hook-playwright.async_api.py +3 -0
- patchright/_impl/__pyinstaller/hook-playwright.sync_api.py +3 -0
- patchright/_impl/_accessibility.py +50 -0
- patchright/_impl/_api_structures.py +277 -0
- patchright/_impl/_artifact.py +45 -0
- patchright/_impl/_assertions.py +867 -0
- patchright/_impl/_async_base.py +92 -0
- patchright/_impl/_browser.py +248 -0
- patchright/_impl/_browser_context.py +743 -0
- patchright/_impl/_browser_type.py +276 -0
- patchright/_impl/_cdp_session.py +21 -0
- patchright/_impl/_clock.py +57 -0
- patchright/_impl/_connection.py +562 -0
- patchright/_impl/_console_message.py +45 -0
- patchright/_impl/_dialog.py +40 -0
- patchright/_impl/_download.py +50 -0
- patchright/_impl/_driver.py +24 -0
- patchright/_impl/_element_handle.py +376 -0
- patchright/_impl/_errors.py +44 -0
- patchright/_impl/_event_context_manager.py +20 -0
- patchright/_impl/_fetch.py +518 -0
- patchright/_impl/_file_chooser.py +43 -0
- patchright/_impl/_frame.py +779 -0
- patchright/_impl/_glob.py +46 -0
- patchright/_impl/_greenlets.py +39 -0
- patchright/_impl/_har_router.py +99 -0
- patchright/_impl/_helper.py +481 -0
- patchright/_impl/_impl_to_api_mapping.py +123 -0
- patchright/_impl/_input.py +71 -0
- patchright/_impl/_js_handle.py +300 -0
- patchright/_impl/_json_pipe.py +56 -0
- patchright/_impl/_local_utils.py +73 -0
- patchright/_impl/_locator.py +814 -0
- patchright/_impl/_map.py +19 -0
- patchright/_impl/_network.py +958 -0
- patchright/_impl/_object_factory.py +91 -0
- patchright/_impl/_page.py +1485 -0
- patchright/_impl/_path_utils.py +11 -0
- patchright/_impl/_playwright.py +51 -0
- patchright/_impl/_selectors.py +62 -0
- patchright/_impl/_set_input_files_helpers.py +135 -0
- patchright/_impl/_str_utils.py +57 -0
- patchright/_impl/_stream.py +32 -0
- patchright/_impl/_sync_base.py +134 -0
- patchright/_impl/_tracing.py +110 -0
- patchright/_impl/_transport.py +150 -0
- patchright/_impl/_video.py +57 -0
- patchright/_impl/_waiter.py +142 -0
- patchright/_impl/_web_error.py +27 -0
- patchright/_impl/_writable_stream.py +27 -0
- patchright/_repo_version.py +1 -0
- patchright/async_api/__init__.py +179 -0
- patchright/async_api/_context_manager.py +39 -0
- patchright/async_api/_generated.py +20416 -0
- patchright/driver/README.md +1 -0
- patchright/driver/package/README.md +3 -0
- patchright/driver/package/ThirdPartyNotices.txt +1560 -0
- patchright/driver/package/bin/install_media_pack.ps1 +5 -0
- patchright/driver/package/bin/reinstall_chrome_beta_linux.sh +42 -0
- patchright/driver/package/bin/reinstall_chrome_beta_mac.sh +13 -0
- patchright/driver/package/bin/reinstall_chrome_beta_win.ps1 +24 -0
- patchright/driver/package/bin/reinstall_chrome_stable_linux.sh +42 -0
- patchright/driver/package/bin/reinstall_chrome_stable_mac.sh +12 -0
- patchright/driver/package/bin/reinstall_chrome_stable_win.ps1 +24 -0
- patchright/driver/package/bin/reinstall_msedge_beta_linux.sh +48 -0
- patchright/driver/package/bin/reinstall_msedge_beta_mac.sh +11 -0
- patchright/driver/package/bin/reinstall_msedge_beta_win.ps1 +23 -0
- patchright/driver/package/bin/reinstall_msedge_dev_linux.sh +48 -0
- patchright/driver/package/bin/reinstall_msedge_dev_mac.sh +11 -0
- patchright/driver/package/bin/reinstall_msedge_dev_win.ps1 +23 -0
- patchright/driver/package/bin/reinstall_msedge_stable_linux.sh +48 -0
- patchright/driver/package/bin/reinstall_msedge_stable_mac.sh +11 -0
- patchright/driver/package/bin/reinstall_msedge_stable_win.ps1 +24 -0
- patchright/driver/package/browsers.json +80 -0
- patchright/driver/package/cli.js +18 -0
- patchright/driver/package/index.js +32 -0
- patchright/driver/package/index.mjs +28 -0
- patchright/driver/package/lib/androidServerImpl.js +63 -0
- patchright/driver/package/lib/browserServerImpl.js +88 -0
- patchright/driver/package/lib/cli/driver.js +97 -0
- patchright/driver/package/lib/cli/program.js +567 -0
- patchright/driver/package/lib/cli/programWithTestStub.js +74 -0
- patchright/driver/package/lib/client/accessibility.js +49 -0
- patchright/driver/package/lib/client/android.js +365 -0
- patchright/driver/package/lib/client/api.js +137 -0
- patchright/driver/package/lib/client/artifact.js +79 -0
- patchright/driver/package/lib/client/browser.js +136 -0
- patchright/driver/package/lib/client/browserContext.js +539 -0
- patchright/driver/package/lib/client/browserType.js +193 -0
- patchright/driver/package/lib/client/cdpSession.js +51 -0
- patchright/driver/package/lib/client/channelOwner.js +205 -0
- patchright/driver/package/lib/client/clientHelper.js +64 -0
- patchright/driver/package/lib/client/clientInstrumentation.js +55 -0
- patchright/driver/package/lib/client/clientStackTrace.js +69 -0
- patchright/driver/package/lib/client/clock.js +68 -0
- patchright/driver/package/lib/client/connection.js +318 -0
- patchright/driver/package/lib/client/consoleMessage.js +55 -0
- patchright/driver/package/lib/client/coverage.js +44 -0
- patchright/driver/package/lib/client/dialog.js +56 -0
- patchright/driver/package/lib/client/download.js +62 -0
- patchright/driver/package/lib/client/electron.js +133 -0
- patchright/driver/package/lib/client/elementHandle.js +284 -0
- patchright/driver/package/lib/client/errors.js +77 -0
- patchright/driver/package/lib/client/eventEmitter.js +314 -0
- patchright/driver/package/lib/client/events.js +98 -0
- patchright/driver/package/lib/client/fetch.js +367 -0
- patchright/driver/package/lib/client/fileChooser.js +46 -0
- patchright/driver/package/lib/client/fileUtils.js +34 -0
- patchright/driver/package/lib/client/frame.js +386 -0
- patchright/driver/package/lib/client/harRouter.js +87 -0
- patchright/driver/package/lib/client/input.js +82 -0
- patchright/driver/package/lib/client/jsHandle.js +105 -0
- patchright/driver/package/lib/client/jsonPipe.js +39 -0
- patchright/driver/package/lib/client/localUtils.js +61 -0
- patchright/driver/package/lib/client/locator.js +362 -0
- patchright/driver/package/lib/client/network.js +751 -0
- patchright/driver/package/lib/client/page.js +709 -0
- patchright/driver/package/lib/client/platform.js +74 -0
- patchright/driver/package/lib/client/playwright.js +85 -0
- patchright/driver/package/lib/client/selectors.js +75 -0
- patchright/driver/package/lib/client/stream.js +39 -0
- patchright/driver/package/lib/client/timeoutSettings.js +75 -0
- patchright/driver/package/lib/client/tracing.js +114 -0
- patchright/driver/package/lib/client/types.js +28 -0
- patchright/driver/package/lib/client/video.js +59 -0
- patchright/driver/package/lib/client/waiter.js +142 -0
- patchright/driver/package/lib/client/webError.js +39 -0
- patchright/driver/package/lib/client/webSocket.js +111 -0
- patchright/driver/package/lib/client/worker.js +63 -0
- patchright/driver/package/lib/client/writableStream.js +39 -0
- patchright/driver/package/lib/generated/clockSource.js +28 -0
- patchright/driver/package/lib/generated/consoleApiSource.js +28 -0
- patchright/driver/package/lib/generated/injectedScriptSource.js +28 -0
- patchright/driver/package/lib/generated/pollingRecorderSource.js +28 -0
- patchright/driver/package/lib/generated/utilityScriptSource.js +28 -0
- patchright/driver/package/lib/generated/webSocketMockSource.js +374 -0
- patchright/driver/package/lib/inProcessFactory.js +59 -0
- patchright/driver/package/lib/inprocess.js +3 -0
- patchright/driver/package/lib/outofprocess.js +78 -0
- patchright/driver/package/lib/protocol/debug.js +211 -0
- patchright/driver/package/lib/protocol/serializers.js +192 -0
- patchright/driver/package/lib/protocol/validator.js +2832 -0
- patchright/driver/package/lib/protocol/validatorPrimitives.js +179 -0
- patchright/driver/package/lib/remote/playwrightConnection.js +266 -0
- patchright/driver/package/lib/remote/playwrightServer.js +139 -0
- patchright/driver/package/lib/server/accessibility.js +69 -0
- patchright/driver/package/lib/server/android/android.js +451 -0
- patchright/driver/package/lib/server/android/backendAdb.js +179 -0
- patchright/driver/package/lib/server/artifact.js +127 -0
- patchright/driver/package/lib/server/bidi/bidiBrowser.js +380 -0
- patchright/driver/package/lib/server/bidi/bidiChromium.js +152 -0
- patchright/driver/package/lib/server/bidi/bidiConnection.js +187 -0
- patchright/driver/package/lib/server/bidi/bidiExecutionContext.js +220 -0
- patchright/driver/package/lib/server/bidi/bidiFirefox.js +112 -0
- patchright/driver/package/lib/server/bidi/bidiInput.js +146 -0
- patchright/driver/package/lib/server/bidi/bidiNetworkManager.js +320 -0
- patchright/driver/package/lib/server/bidi/bidiOverCdp.js +102 -0
- patchright/driver/package/lib/server/bidi/bidiPage.js +530 -0
- patchright/driver/package/lib/server/bidi/bidiPdf.js +106 -0
- patchright/driver/package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
- patchright/driver/package/lib/server/bidi/third_party/bidiDeserializer.js +98 -0
- patchright/driver/package/lib/server/bidi/third_party/bidiKeyboard.js +256 -0
- patchright/driver/package/lib/server/bidi/third_party/bidiProtocol.js +152 -0
- patchright/driver/package/lib/server/bidi/third_party/bidiSerializer.js +148 -0
- patchright/driver/package/lib/server/bidi/third_party/firefoxPrefs.js +259 -0
- patchright/driver/package/lib/server/browser.js +140 -0
- patchright/driver/package/lib/server/browserContext.js +646 -0
- patchright/driver/package/lib/server/browserType.js +326 -0
- patchright/driver/package/lib/server/callLog.js +82 -0
- patchright/driver/package/lib/server/chromium/appIcon.png +0 -0
- patchright/driver/package/lib/server/chromium/chromium.js +376 -0
- patchright/driver/package/lib/server/chromium/chromiumSwitches.js +89 -0
- patchright/driver/package/lib/server/chromium/crAccessibility.js +263 -0
- patchright/driver/package/lib/server/chromium/crBrowser.js +503 -0
- patchright/driver/package/lib/server/chromium/crConnection.js +203 -0
- patchright/driver/package/lib/server/chromium/crCoverage.js +232 -0
- patchright/driver/package/lib/server/chromium/crDevTools.js +112 -0
- patchright/driver/package/lib/server/chromium/crDragDrop.js +126 -0
- patchright/driver/package/lib/server/chromium/crExecutionContext.js +145 -0
- patchright/driver/package/lib/server/chromium/crInput.js +184 -0
- patchright/driver/package/lib/server/chromium/crNetworkManager.js +742 -0
- patchright/driver/package/lib/server/chromium/crPage.js +1134 -0
- patchright/driver/package/lib/server/chromium/crPdf.js +121 -0
- patchright/driver/package/lib/server/chromium/crProtocolHelper.js +145 -0
- patchright/driver/package/lib/server/chromium/crServiceWorker.js +126 -0
- patchright/driver/package/lib/server/chromium/defaultFontFamilies.js +162 -0
- patchright/driver/package/lib/server/chromium/protocol.d.js +16 -0
- patchright/driver/package/lib/server/chromium/videoRecorder.js +121 -0
- patchright/driver/package/lib/server/clock.js +145 -0
- patchright/driver/package/lib/server/codegen/csharp.js +329 -0
- patchright/driver/package/lib/server/codegen/java.js +270 -0
- patchright/driver/package/lib/server/codegen/javascript.js +268 -0
- patchright/driver/package/lib/server/codegen/jsonl.js +51 -0
- patchright/driver/package/lib/server/codegen/language.js +111 -0
- patchright/driver/package/lib/server/codegen/languages.js +68 -0
- patchright/driver/package/lib/server/codegen/python.js +277 -0
- patchright/driver/package/lib/server/codegen/types.js +16 -0
- patchright/driver/package/lib/server/console.js +53 -0
- patchright/driver/package/lib/server/cookieStore.js +204 -0
- patchright/driver/package/lib/server/debugController.js +185 -0
- patchright/driver/package/lib/server/debugger.js +136 -0
- patchright/driver/package/lib/server/deviceDescriptors.js +39 -0
- patchright/driver/package/lib/server/deviceDescriptorsSource.json +1669 -0
- patchright/driver/package/lib/server/dialog.js +72 -0
- patchright/driver/package/lib/server/dispatchers/androidDispatcher.js +293 -0
- patchright/driver/package/lib/server/dispatchers/artifactDispatcher.js +118 -0
- patchright/driver/package/lib/server/dispatchers/browserContextDispatcher.js +328 -0
- patchright/driver/package/lib/server/dispatchers/browserDispatcher.js +151 -0
- patchright/driver/package/lib/server/dispatchers/browserTypeDispatcher.js +55 -0
- patchright/driver/package/lib/server/dispatchers/cdpSessionDispatcher.js +44 -0
- patchright/driver/package/lib/server/dispatchers/debugControllerDispatcher.js +87 -0
- patchright/driver/package/lib/server/dispatchers/dialogDispatcher.js +47 -0
- patchright/driver/package/lib/server/dispatchers/dispatcher.js +346 -0
- patchright/driver/package/lib/server/dispatchers/electronDispatcher.js +90 -0
- patchright/driver/package/lib/server/dispatchers/elementHandlerDispatcher.js +191 -0
- patchright/driver/package/lib/server/dispatchers/frameDispatcher.js +230 -0
- patchright/driver/package/lib/server/dispatchers/jsHandleDispatcher.js +80 -0
- patchright/driver/package/lib/server/dispatchers/jsonPipeDispatcher.js +58 -0
- patchright/driver/package/lib/server/dispatchers/localUtilsDispatcher.js +155 -0
- patchright/driver/package/lib/server/dispatchers/networkDispatchers.js +204 -0
- patchright/driver/package/lib/server/dispatchers/pageDispatcher.js +328 -0
- patchright/driver/package/lib/server/dispatchers/playwrightDispatcher.js +100 -0
- patchright/driver/package/lib/server/dispatchers/selectorsDispatcher.js +40 -0
- patchright/driver/package/lib/server/dispatchers/streamDispatcher.js +60 -0
- patchright/driver/package/lib/server/dispatchers/tracingDispatcher.js +59 -0
- patchright/driver/package/lib/server/dispatchers/webSocketRouteDispatcher.js +154 -0
- patchright/driver/package/lib/server/dispatchers/writableStreamDispatcher.js +73 -0
- patchright/driver/package/lib/server/dom.js +869 -0
- patchright/driver/package/lib/server/download.js +70 -0
- patchright/driver/package/lib/server/electron/electron.js +277 -0
- patchright/driver/package/lib/server/electron/loader.js +29 -0
- patchright/driver/package/lib/server/errors.js +69 -0
- patchright/driver/package/lib/server/fetch.js +640 -0
- patchright/driver/package/lib/server/fileChooser.js +43 -0
- patchright/driver/package/lib/server/fileUploadUtils.js +84 -0
- patchright/driver/package/lib/server/firefox/ffAccessibility.js +238 -0
- patchright/driver/package/lib/server/firefox/ffBrowser.js +404 -0
- patchright/driver/package/lib/server/firefox/ffConnection.js +147 -0
- patchright/driver/package/lib/server/firefox/ffExecutionContext.js +149 -0
- patchright/driver/package/lib/server/firefox/ffInput.js +159 -0
- patchright/driver/package/lib/server/firefox/ffNetworkManager.js +254 -0
- patchright/driver/package/lib/server/firefox/ffPage.js +501 -0
- patchright/driver/package/lib/server/firefox/firefox.js +106 -0
- patchright/driver/package/lib/server/firefox/protocol.d.js +16 -0
- patchright/driver/package/lib/server/formData.js +147 -0
- patchright/driver/package/lib/server/frameSelectors.js +274 -0
- patchright/driver/package/lib/server/frames.js +1834 -0
- patchright/driver/package/lib/server/har/harRecorder.js +147 -0
- patchright/driver/package/lib/server/har/harTracer.js +606 -0
- patchright/driver/package/lib/server/harBackend.js +157 -0
- patchright/driver/package/lib/server/helper.js +100 -0
- patchright/driver/package/lib/server/index.js +61 -0
- patchright/driver/package/lib/server/input.js +280 -0
- patchright/driver/package/lib/server/instrumentation.js +75 -0
- patchright/driver/package/lib/server/javascript.js +315 -0
- patchright/driver/package/lib/server/launchApp.js +110 -0
- patchright/driver/package/lib/server/localUtils.js +211 -0
- patchright/driver/package/lib/server/macEditingCommands.js +143 -0
- patchright/driver/package/lib/server/network.js +583 -0
- patchright/driver/package/lib/server/page.js +775 -0
- patchright/driver/package/lib/server/pageBinding.js +88 -0
- patchright/driver/package/lib/server/pipeTransport.js +89 -0
- patchright/driver/package/lib/server/playwright.js +81 -0
- patchright/driver/package/lib/server/progress.js +104 -0
- patchright/driver/package/lib/server/protocolError.js +52 -0
- patchright/driver/package/lib/server/recorder/chat.js +161 -0
- patchright/driver/package/lib/server/recorder/contextRecorder.js +286 -0
- patchright/driver/package/lib/server/recorder/recorderApp.js +184 -0
- patchright/driver/package/lib/server/recorder/recorderCollection.js +116 -0
- patchright/driver/package/lib/server/recorder/recorderFrontend.js +16 -0
- patchright/driver/package/lib/server/recorder/recorderRunner.js +135 -0
- patchright/driver/package/lib/server/recorder/recorderUtils.js +100 -0
- patchright/driver/package/lib/server/recorder/throttledFile.js +57 -0
- patchright/driver/package/lib/server/recorder.js +360 -0
- patchright/driver/package/lib/server/registry/browserFetcher.js +175 -0
- patchright/driver/package/lib/server/registry/dependencies.js +371 -0
- patchright/driver/package/lib/server/registry/index.js +1271 -0
- patchright/driver/package/lib/server/registry/nativeDeps.js +1105 -0
- patchright/driver/package/lib/server/registry/oopDownloadBrowserMain.js +120 -0
- patchright/driver/package/lib/server/screenshotter.js +332 -0
- patchright/driver/package/lib/server/selectors.js +112 -0
- patchright/driver/package/lib/server/socksClientCertificatesInterceptor.js +321 -0
- patchright/driver/package/lib/server/socksInterceptor.js +95 -0
- patchright/driver/package/lib/server/storageScript.js +154 -0
- patchright/driver/package/lib/server/timeoutSettings.js +89 -0
- patchright/driver/package/lib/server/trace/recorder/snapshotter.js +143 -0
- patchright/driver/package/lib/server/trace/recorder/snapshotterInjected.js +539 -0
- patchright/driver/package/lib/server/trace/recorder/tracing.js +593 -0
- patchright/driver/package/lib/server/trace/test/inMemorySnapshotter.js +87 -0
- patchright/driver/package/lib/server/trace/viewer/traceViewer.js +249 -0
- patchright/driver/package/lib/server/transport.js +183 -0
- patchright/driver/package/lib/server/types.js +28 -0
- patchright/driver/package/lib/server/usKeyboardLayout.js +145 -0
- patchright/driver/package/lib/server/utils/ascii.js +44 -0
- patchright/driver/package/lib/server/utils/comparators.js +161 -0
- patchright/driver/package/lib/server/utils/crypto.js +216 -0
- patchright/driver/package/lib/server/utils/debug.js +47 -0
- patchright/driver/package/lib/server/utils/debugLogger.js +114 -0
- patchright/driver/package/lib/server/utils/env.js +68 -0
- patchright/driver/package/lib/server/utils/eventsHelper.js +39 -0
- patchright/driver/package/lib/server/utils/expectUtils.js +38 -0
- patchright/driver/package/lib/server/utils/fileUtils.js +191 -0
- patchright/driver/package/lib/server/utils/happyEyeballs.js +207 -0
- patchright/driver/package/lib/server/utils/hostPlatform.js +109 -0
- patchright/driver/package/lib/server/utils/httpServer.js +218 -0
- patchright/driver/package/lib/server/utils/image_tools/colorUtils.js +89 -0
- patchright/driver/package/lib/server/utils/image_tools/compare.js +109 -0
- patchright/driver/package/lib/server/utils/image_tools/imageChannel.js +78 -0
- patchright/driver/package/lib/server/utils/image_tools/stats.js +102 -0
- patchright/driver/package/lib/server/utils/linuxUtils.js +71 -0
- patchright/driver/package/lib/server/utils/network.js +217 -0
- patchright/driver/package/lib/server/utils/nodePlatform.js +148 -0
- patchright/driver/package/lib/server/utils/pipeTransport.js +84 -0
- patchright/driver/package/lib/server/utils/processLauncher.js +238 -0
- patchright/driver/package/lib/server/utils/profiler.js +65 -0
- patchright/driver/package/lib/server/utils/socksProxy.js +511 -0
- patchright/driver/package/lib/server/utils/spawnAsync.js +41 -0
- patchright/driver/package/lib/server/utils/task.js +51 -0
- patchright/driver/package/lib/server/utils/userAgent.js +98 -0
- patchright/driver/package/lib/server/utils/wsServer.js +132 -0
- patchright/driver/package/lib/server/utils/zipFile.js +74 -0
- patchright/driver/package/lib/server/utils/zones.js +57 -0
- patchright/driver/package/lib/server/webkit/protocol.d.js +16 -0
- patchright/driver/package/lib/server/webkit/webkit.js +100 -0
- patchright/driver/package/lib/server/webkit/wkAccessibility.js +237 -0
- patchright/driver/package/lib/server/webkit/wkBrowser.js +312 -0
- patchright/driver/package/lib/server/webkit/wkConnection.js +149 -0
- patchright/driver/package/lib/server/webkit/wkExecutionContext.js +153 -0
- patchright/driver/package/lib/server/webkit/wkInput.js +181 -0
- patchright/driver/package/lib/server/webkit/wkInterceptableRequest.js +169 -0
- patchright/driver/package/lib/server/webkit/wkPage.js +1114 -0
- patchright/driver/package/lib/server/webkit/wkProvisionalPage.js +83 -0
- patchright/driver/package/lib/server/webkit/wkWorkers.js +104 -0
- patchright/driver/package/lib/third_party/pixelmatch.js +255 -0
- patchright/driver/package/lib/utils/isomorphic/ariaSnapshot.js +384 -0
- patchright/driver/package/lib/utils/isomorphic/assert.js +31 -0
- patchright/driver/package/lib/utils/isomorphic/builtins.js +86 -0
- patchright/driver/package/lib/utils/isomorphic/colors.js +72 -0
- patchright/driver/package/lib/utils/isomorphic/cssParser.js +246 -0
- patchright/driver/package/lib/utils/isomorphic/cssTokenizer.js +1051 -0
- patchright/driver/package/lib/utils/isomorphic/headers.js +53 -0
- patchright/driver/package/lib/utils/isomorphic/locatorGenerators.js +655 -0
- patchright/driver/package/lib/utils/isomorphic/locatorParser.js +176 -0
- patchright/driver/package/lib/utils/isomorphic/locatorUtils.js +81 -0
- patchright/driver/package/lib/utils/isomorphic/manualPromise.js +115 -0
- patchright/driver/package/lib/utils/isomorphic/mimeType.js +460 -0
- patchright/driver/package/lib/utils/isomorphic/multimap.js +81 -0
- patchright/driver/package/lib/utils/isomorphic/rtti.js +43 -0
- patchright/driver/package/lib/utils/isomorphic/selectorParser.js +387 -0
- patchright/driver/package/lib/utils/isomorphic/semaphore.js +54 -0
- patchright/driver/package/lib/utils/isomorphic/stackTrace.js +158 -0
- patchright/driver/package/lib/utils/isomorphic/stringUtils.js +176 -0
- patchright/driver/package/lib/utils/isomorphic/time.js +44 -0
- patchright/driver/package/lib/utils/isomorphic/timeoutRunner.js +67 -0
- patchright/driver/package/lib/utils/isomorphic/traceUtils.js +59 -0
- patchright/driver/package/lib/utils/isomorphic/types.js +16 -0
- patchright/driver/package/lib/utils/isomorphic/urlMatch.js +167 -0
- patchright/driver/package/lib/utils/isomorphic/utilityScriptSerializers.js +248 -0
- patchright/driver/package/lib/utils.js +101 -0
- patchright/driver/package/lib/utilsBundle.js +106 -0
- patchright/driver/package/lib/utilsBundleImpl/index.js +208 -0
- patchright/driver/package/lib/utilsBundleImpl/xdg-open +1066 -0
- patchright/driver/package/lib/zipBundle.js +34 -0
- patchright/driver/package/lib/zipBundleImpl.js +5 -0
- patchright/driver/package/package.json +44 -0
- patchright/driver/package/protocol.yml +3313 -0
- patchright/py.typed +0 -0
- patchright/sync_api/__init__.py +179 -0
- patchright/sync_api/_context_manager.py +74 -0
- patchright/sync_api/_generated.py +20632 -0
- pure_patchright-1.52.5.dist-info/LICENSE +201 -0
- pure_patchright-1.52.5.dist-info/METADATA +96 -0
- pure_patchright-1.52.5.dist-info/RECORD +381 -0
- pure_patchright-1.52.5.dist-info/WHEEL +4 -0
- pure_patchright-1.52.5.dist-info/entry_points.txt +5 -0
- pure_patchright-1.52.5.dist-info/licenses/LICENSE +202 -0
- pure_patchright-1.52.5.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1834 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var frames_exports = {};
|
|
30
|
+
__export(frames_exports, {
|
|
31
|
+
Frame: () => Frame,
|
|
32
|
+
FrameManager: () => FrameManager,
|
|
33
|
+
NavigationAbortedError: () => NavigationAbortedError
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(frames_exports);
|
|
36
|
+
var import_crExecutionContext = require("./chromium/crExecutionContext");
|
|
37
|
+
var import_dom = require("./dom");
|
|
38
|
+
var import_crypto = __toESM(require("crypto"));
|
|
39
|
+
var import_browserContext = require("./browserContext");
|
|
40
|
+
var dom = __toESM(require("./dom"));
|
|
41
|
+
var import_errors = require("./errors");
|
|
42
|
+
var import_fileUploadUtils = require("./fileUploadUtils");
|
|
43
|
+
var import_frameSelectors = require("./frameSelectors");
|
|
44
|
+
var import_helper = require("./helper");
|
|
45
|
+
var import_instrumentation = require("./instrumentation");
|
|
46
|
+
var js = __toESM(require("./javascript"));
|
|
47
|
+
var network = __toESM(require("./network"));
|
|
48
|
+
var import_page = require("./page");
|
|
49
|
+
var import_progress = require("./progress");
|
|
50
|
+
var types = __toESM(require("./types"));
|
|
51
|
+
var import_utils = require("../utils");
|
|
52
|
+
var import_protocolError = require("./protocolError");
|
|
53
|
+
var import_debugLogger = require("./utils/debugLogger");
|
|
54
|
+
var import_eventsHelper = require("./utils/eventsHelper");
|
|
55
|
+
var import_selectorParser = require("../utils/isomorphic/selectorParser");
|
|
56
|
+
var import_manualPromise = require("../utils/isomorphic/manualPromise");
|
|
57
|
+
var import_callLog = require("./callLog");
|
|
58
|
+
class NavigationAbortedError extends Error {
|
|
59
|
+
constructor(documentId, message) {
|
|
60
|
+
super(message);
|
|
61
|
+
this.documentId = documentId;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const kDummyFrameId = "<dummy>";
|
|
65
|
+
class FrameManager {
|
|
66
|
+
constructor(page) {
|
|
67
|
+
this._frames = /* @__PURE__ */ new Map();
|
|
68
|
+
this._consoleMessageTags = /* @__PURE__ */ new Map();
|
|
69
|
+
this._signalBarriers = /* @__PURE__ */ new Set();
|
|
70
|
+
this._webSockets = /* @__PURE__ */ new Map();
|
|
71
|
+
this._openedDialogs = /* @__PURE__ */ new Set();
|
|
72
|
+
this._closeAllOpeningDialogs = false;
|
|
73
|
+
this._page = page;
|
|
74
|
+
this._mainFrame = void 0;
|
|
75
|
+
}
|
|
76
|
+
createDummyMainFrameIfNeeded() {
|
|
77
|
+
if (!this._mainFrame)
|
|
78
|
+
this.frameAttached(kDummyFrameId, null);
|
|
79
|
+
}
|
|
80
|
+
dispose() {
|
|
81
|
+
for (const frame of this._frames.values()) {
|
|
82
|
+
frame._stopNetworkIdleTimer();
|
|
83
|
+
frame._invalidateNonStallingEvaluations("Target crashed");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
mainFrame() {
|
|
87
|
+
return this._mainFrame;
|
|
88
|
+
}
|
|
89
|
+
frames() {
|
|
90
|
+
const frames = [];
|
|
91
|
+
collect(this._mainFrame);
|
|
92
|
+
return frames;
|
|
93
|
+
function collect(frame) {
|
|
94
|
+
frames.push(frame);
|
|
95
|
+
for (const subframe of frame.childFrames())
|
|
96
|
+
collect(subframe);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
frame(frameId) {
|
|
100
|
+
return this._frames.get(frameId) || null;
|
|
101
|
+
}
|
|
102
|
+
frameAttached(frameId, parentFrameId) {
|
|
103
|
+
const parentFrame = parentFrameId ? this._frames.get(parentFrameId) : null;
|
|
104
|
+
if (!parentFrame) {
|
|
105
|
+
if (this._mainFrame) {
|
|
106
|
+
this._frames.delete(this._mainFrame._id);
|
|
107
|
+
this._mainFrame._id = frameId;
|
|
108
|
+
} else {
|
|
109
|
+
(0, import_utils.assert)(!this._frames.has(frameId));
|
|
110
|
+
this._mainFrame = new Frame(this._page, frameId, parentFrame);
|
|
111
|
+
}
|
|
112
|
+
this._frames.set(frameId, this._mainFrame);
|
|
113
|
+
return this._mainFrame;
|
|
114
|
+
} else {
|
|
115
|
+
(0, import_utils.assert)(!this._frames.has(frameId));
|
|
116
|
+
const frame = new Frame(this._page, frameId, parentFrame);
|
|
117
|
+
this._frames.set(frameId, frame);
|
|
118
|
+
this._page.emit(import_page.Page.Events.FrameAttached, frame);
|
|
119
|
+
return frame;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async waitForSignalsCreatedBy(progress, waitAfter, action) {
|
|
123
|
+
if (!waitAfter)
|
|
124
|
+
return action();
|
|
125
|
+
const barrier = new SignalBarrier(progress);
|
|
126
|
+
this._signalBarriers.add(barrier);
|
|
127
|
+
if (progress)
|
|
128
|
+
progress.cleanupWhenAborted(() => this._signalBarriers.delete(barrier));
|
|
129
|
+
const result = await action();
|
|
130
|
+
await this._page._delegate.inputActionEpilogue();
|
|
131
|
+
await barrier.waitFor();
|
|
132
|
+
this._signalBarriers.delete(barrier);
|
|
133
|
+
await new Promise((0, import_utils.makeWaitForNextTask)());
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
frameWillPotentiallyRequestNavigation() {
|
|
137
|
+
for (const barrier of this._signalBarriers)
|
|
138
|
+
barrier.retain();
|
|
139
|
+
}
|
|
140
|
+
frameDidPotentiallyRequestNavigation() {
|
|
141
|
+
for (const barrier of this._signalBarriers)
|
|
142
|
+
barrier.release();
|
|
143
|
+
}
|
|
144
|
+
frameRequestedNavigation(frameId, documentId) {
|
|
145
|
+
const frame = this._frames.get(frameId);
|
|
146
|
+
if (!frame)
|
|
147
|
+
return;
|
|
148
|
+
for (const barrier of this._signalBarriers)
|
|
149
|
+
barrier.addFrameNavigation(frame);
|
|
150
|
+
if (frame.pendingDocument() && frame.pendingDocument().documentId === documentId) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const request = documentId ? Array.from(frame._inflightRequests).find((request2) => request2._documentId === documentId) : void 0;
|
|
154
|
+
frame.setPendingDocument({ documentId, request });
|
|
155
|
+
}
|
|
156
|
+
frameCommittedNewDocumentNavigation(frameId, url, name, documentId, initial) {
|
|
157
|
+
const frame = this._frames.get(frameId);
|
|
158
|
+
this.removeChildFramesRecursively(frame);
|
|
159
|
+
this.clearWebSockets(frame);
|
|
160
|
+
frame._url = url;
|
|
161
|
+
frame._name = name;
|
|
162
|
+
let keepPending;
|
|
163
|
+
const pendingDocument = frame.pendingDocument();
|
|
164
|
+
if (pendingDocument) {
|
|
165
|
+
if (pendingDocument.documentId === void 0) {
|
|
166
|
+
pendingDocument.documentId = documentId;
|
|
167
|
+
}
|
|
168
|
+
if (pendingDocument.documentId === documentId) {
|
|
169
|
+
frame._currentDocument = pendingDocument;
|
|
170
|
+
} else {
|
|
171
|
+
keepPending = pendingDocument;
|
|
172
|
+
frame._currentDocument = { documentId, request: void 0 };
|
|
173
|
+
}
|
|
174
|
+
frame.setPendingDocument(void 0);
|
|
175
|
+
} else {
|
|
176
|
+
frame._currentDocument = { documentId, request: void 0 };
|
|
177
|
+
}
|
|
178
|
+
frame._onClearLifecycle();
|
|
179
|
+
const navigationEvent = { url, name, newDocument: frame._currentDocument, isPublic: true };
|
|
180
|
+
this._fireInternalFrameNavigation(frame, navigationEvent);
|
|
181
|
+
if (!initial) {
|
|
182
|
+
import_debugLogger.debugLogger.log("api", ` navigated to "${url}"`);
|
|
183
|
+
this._page.frameNavigatedToNewDocument(frame);
|
|
184
|
+
}
|
|
185
|
+
frame.setPendingDocument(keepPending);
|
|
186
|
+
}
|
|
187
|
+
frameCommittedSameDocumentNavigation(frameId, url) {
|
|
188
|
+
const frame = this._frames.get(frameId);
|
|
189
|
+
if (!frame)
|
|
190
|
+
return;
|
|
191
|
+
const pending = frame.pendingDocument();
|
|
192
|
+
if (pending && pending.documentId === void 0 && pending.request === void 0) {
|
|
193
|
+
frame.setPendingDocument(void 0);
|
|
194
|
+
}
|
|
195
|
+
frame._url = url;
|
|
196
|
+
const navigationEvent = { url, name: frame._name, isPublic: true };
|
|
197
|
+
this._fireInternalFrameNavigation(frame, navigationEvent);
|
|
198
|
+
import_debugLogger.debugLogger.log("api", ` navigated to "${url}"`);
|
|
199
|
+
}
|
|
200
|
+
frameAbortedNavigation(frameId, errorText, documentId) {
|
|
201
|
+
const frame = this._frames.get(frameId);
|
|
202
|
+
if (!frame || !frame.pendingDocument())
|
|
203
|
+
return;
|
|
204
|
+
if (documentId !== void 0 && frame.pendingDocument().documentId !== documentId)
|
|
205
|
+
return;
|
|
206
|
+
const navigationEvent = {
|
|
207
|
+
url: frame._url,
|
|
208
|
+
name: frame._name,
|
|
209
|
+
newDocument: frame.pendingDocument(),
|
|
210
|
+
error: new NavigationAbortedError(documentId, errorText),
|
|
211
|
+
isPublic: !(documentId && frame._redirectedNavigations.has(documentId))
|
|
212
|
+
};
|
|
213
|
+
frame.setPendingDocument(void 0);
|
|
214
|
+
this._fireInternalFrameNavigation(frame, navigationEvent);
|
|
215
|
+
}
|
|
216
|
+
frameDetached(frameId) {
|
|
217
|
+
const frame = this._frames.get(frameId);
|
|
218
|
+
if (frame) {
|
|
219
|
+
this._removeFramesRecursively(frame);
|
|
220
|
+
this._page.mainFrame()._recalculateNetworkIdle();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
frameLifecycleEvent(frameId, event) {
|
|
224
|
+
const frame = this._frames.get(frameId);
|
|
225
|
+
if (frame)
|
|
226
|
+
frame._onLifecycleEvent(event);
|
|
227
|
+
}
|
|
228
|
+
requestStarted(request, route) {
|
|
229
|
+
const frame = request.frame();
|
|
230
|
+
this._inflightRequestStarted(request);
|
|
231
|
+
if (request._documentId)
|
|
232
|
+
frame.setPendingDocument({ documentId: request._documentId, request });
|
|
233
|
+
if (request._isFavicon) {
|
|
234
|
+
route?.abort("aborted").catch(() => {
|
|
235
|
+
});
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
this._page.emitOnContext(import_browserContext.BrowserContext.Events.Request, request);
|
|
239
|
+
if (route) {
|
|
240
|
+
const r = new network.Route(request, route);
|
|
241
|
+
if (this._page._serverRequestInterceptor?.(r, request))
|
|
242
|
+
return;
|
|
243
|
+
if (this._page._clientRequestInterceptor?.(r, request))
|
|
244
|
+
return;
|
|
245
|
+
if (this._page._browserContext._requestInterceptor?.(r, request))
|
|
246
|
+
return;
|
|
247
|
+
r.continue({ isFallback: true }).catch(() => {
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
requestReceivedResponse(response) {
|
|
252
|
+
if (response.request()._isFavicon)
|
|
253
|
+
return;
|
|
254
|
+
this._page.emitOnContext(import_browserContext.BrowserContext.Events.Response, response);
|
|
255
|
+
}
|
|
256
|
+
reportRequestFinished(request, response) {
|
|
257
|
+
this._inflightRequestFinished(request);
|
|
258
|
+
if (request._isFavicon)
|
|
259
|
+
return;
|
|
260
|
+
this._page.emitOnContext(import_browserContext.BrowserContext.Events.RequestFinished, { request, response });
|
|
261
|
+
}
|
|
262
|
+
requestFailed(request, canceled) {
|
|
263
|
+
const frame = request.frame();
|
|
264
|
+
this._inflightRequestFinished(request);
|
|
265
|
+
if (frame.pendingDocument() && frame.pendingDocument().request === request) {
|
|
266
|
+
let errorText = request.failure().errorText;
|
|
267
|
+
if (canceled)
|
|
268
|
+
errorText += "; maybe frame was detached?";
|
|
269
|
+
this.frameAbortedNavigation(frame._id, errorText, frame.pendingDocument().documentId);
|
|
270
|
+
}
|
|
271
|
+
if (request._isFavicon)
|
|
272
|
+
return;
|
|
273
|
+
this._page.emitOnContext(import_browserContext.BrowserContext.Events.RequestFailed, request);
|
|
274
|
+
}
|
|
275
|
+
dialogDidOpen(dialog) {
|
|
276
|
+
for (const frame of this._frames.values())
|
|
277
|
+
frame._invalidateNonStallingEvaluations("JavaScript dialog interrupted evaluation");
|
|
278
|
+
if (this._closeAllOpeningDialogs)
|
|
279
|
+
dialog.close().then(() => {
|
|
280
|
+
});
|
|
281
|
+
else
|
|
282
|
+
this._openedDialogs.add(dialog);
|
|
283
|
+
}
|
|
284
|
+
dialogWillClose(dialog) {
|
|
285
|
+
this._openedDialogs.delete(dialog);
|
|
286
|
+
}
|
|
287
|
+
async closeOpenDialogs() {
|
|
288
|
+
await Promise.all([...this._openedDialogs].map((dialog) => dialog.close())).catch(() => {
|
|
289
|
+
});
|
|
290
|
+
this._openedDialogs.clear();
|
|
291
|
+
}
|
|
292
|
+
setCloseAllOpeningDialogs(closeDialogs) {
|
|
293
|
+
this._closeAllOpeningDialogs = closeDialogs;
|
|
294
|
+
}
|
|
295
|
+
removeChildFramesRecursively(frame) {
|
|
296
|
+
for (const child of frame.childFrames())
|
|
297
|
+
this._removeFramesRecursively(child);
|
|
298
|
+
}
|
|
299
|
+
_removeFramesRecursively(frame) {
|
|
300
|
+
this.removeChildFramesRecursively(frame);
|
|
301
|
+
frame._onDetached();
|
|
302
|
+
this._frames.delete(frame._id);
|
|
303
|
+
if (!this._page.isClosed())
|
|
304
|
+
this._page.emit(import_page.Page.Events.FrameDetached, frame);
|
|
305
|
+
}
|
|
306
|
+
_inflightRequestFinished(request) {
|
|
307
|
+
const frame = request.frame();
|
|
308
|
+
if (request._isFavicon)
|
|
309
|
+
return;
|
|
310
|
+
if (!frame._inflightRequests.has(request))
|
|
311
|
+
return;
|
|
312
|
+
frame._inflightRequests.delete(request);
|
|
313
|
+
if (frame._inflightRequests.size === 0)
|
|
314
|
+
frame._startNetworkIdleTimer();
|
|
315
|
+
}
|
|
316
|
+
_inflightRequestStarted(request) {
|
|
317
|
+
const frame = request.frame();
|
|
318
|
+
if (request._isFavicon)
|
|
319
|
+
return;
|
|
320
|
+
frame._inflightRequests.add(request);
|
|
321
|
+
if (frame._inflightRequests.size === 1)
|
|
322
|
+
frame._stopNetworkIdleTimer();
|
|
323
|
+
}
|
|
324
|
+
interceptConsoleMessage(message) {
|
|
325
|
+
if (message.type() !== "debug")
|
|
326
|
+
return false;
|
|
327
|
+
const tag = message.text();
|
|
328
|
+
const handler = this._consoleMessageTags.get(tag);
|
|
329
|
+
if (!handler)
|
|
330
|
+
return false;
|
|
331
|
+
this._consoleMessageTags.delete(tag);
|
|
332
|
+
handler();
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
clearWebSockets(frame) {
|
|
336
|
+
if (frame.parentFrame())
|
|
337
|
+
return;
|
|
338
|
+
this._webSockets.clear();
|
|
339
|
+
}
|
|
340
|
+
onWebSocketCreated(requestId, url) {
|
|
341
|
+
const ws = new network.WebSocket(this._page, url);
|
|
342
|
+
this._webSockets.set(requestId, ws);
|
|
343
|
+
}
|
|
344
|
+
onWebSocketRequest(requestId) {
|
|
345
|
+
const ws = this._webSockets.get(requestId);
|
|
346
|
+
if (ws && ws.markAsNotified())
|
|
347
|
+
this._page.emit(import_page.Page.Events.WebSocket, ws);
|
|
348
|
+
}
|
|
349
|
+
onWebSocketResponse(requestId, status, statusText) {
|
|
350
|
+
const ws = this._webSockets.get(requestId);
|
|
351
|
+
if (status < 400)
|
|
352
|
+
return;
|
|
353
|
+
if (ws)
|
|
354
|
+
ws.error(`${statusText}: ${status}`);
|
|
355
|
+
}
|
|
356
|
+
onWebSocketFrameSent(requestId, opcode, data) {
|
|
357
|
+
const ws = this._webSockets.get(requestId);
|
|
358
|
+
if (ws)
|
|
359
|
+
ws.frameSent(opcode, data);
|
|
360
|
+
}
|
|
361
|
+
webSocketFrameReceived(requestId, opcode, data) {
|
|
362
|
+
const ws = this._webSockets.get(requestId);
|
|
363
|
+
if (ws)
|
|
364
|
+
ws.frameReceived(opcode, data);
|
|
365
|
+
}
|
|
366
|
+
webSocketClosed(requestId) {
|
|
367
|
+
const ws = this._webSockets.get(requestId);
|
|
368
|
+
if (ws)
|
|
369
|
+
ws.closed();
|
|
370
|
+
this._webSockets.delete(requestId);
|
|
371
|
+
}
|
|
372
|
+
webSocketError(requestId, errorMessage) {
|
|
373
|
+
const ws = this._webSockets.get(requestId);
|
|
374
|
+
if (ws)
|
|
375
|
+
ws.error(errorMessage);
|
|
376
|
+
}
|
|
377
|
+
_fireInternalFrameNavigation(frame, event) {
|
|
378
|
+
frame.emit(Frame.Events.InternalNavigation, event);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
class Frame extends import_instrumentation.SdkObject {
|
|
382
|
+
constructor(page, id, parentFrame) {
|
|
383
|
+
super(page, "frame");
|
|
384
|
+
this._firedLifecycleEvents = /* @__PURE__ */ new Set();
|
|
385
|
+
this._firedNetworkIdleSelf = false;
|
|
386
|
+
this._url = "";
|
|
387
|
+
this._contextData = /* @__PURE__ */ new Map();
|
|
388
|
+
this._childFrames = /* @__PURE__ */ new Set();
|
|
389
|
+
this._name = "";
|
|
390
|
+
this._inflightRequests = /* @__PURE__ */ new Set();
|
|
391
|
+
this._setContentCounter = 0;
|
|
392
|
+
this._detachedScope = new import_utils.LongStandingScope();
|
|
393
|
+
this._raceAgainstEvaluationStallingEventsPromises = /* @__PURE__ */ new Set();
|
|
394
|
+
this._redirectedNavigations = /* @__PURE__ */ new Map();
|
|
395
|
+
this.attribution.frame = this;
|
|
396
|
+
this._id = id;
|
|
397
|
+
this._page = page;
|
|
398
|
+
this._parentFrame = parentFrame;
|
|
399
|
+
this._currentDocument = { documentId: void 0, request: void 0 };
|
|
400
|
+
this.selectors = new import_frameSelectors.FrameSelectors(this);
|
|
401
|
+
this._contextData.set("main", { contextPromise: new import_manualPromise.ManualPromise(), context: null });
|
|
402
|
+
this._contextData.set("utility", { contextPromise: new import_manualPromise.ManualPromise(), context: null });
|
|
403
|
+
this._setContext("main", null);
|
|
404
|
+
this._setContext("utility", null);
|
|
405
|
+
if (this._parentFrame)
|
|
406
|
+
this._parentFrame._childFrames.add(this);
|
|
407
|
+
this._firedLifecycleEvents.add("commit");
|
|
408
|
+
if (id !== kDummyFrameId)
|
|
409
|
+
this._startNetworkIdleTimer();
|
|
410
|
+
}
|
|
411
|
+
static {
|
|
412
|
+
this.Events = {
|
|
413
|
+
InternalNavigation: "internalnavigation",
|
|
414
|
+
AddLifecycle: "addlifecycle",
|
|
415
|
+
RemoveLifecycle: "removelifecycle"
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
isDetached() {
|
|
419
|
+
return this._detachedScope.isClosed();
|
|
420
|
+
}
|
|
421
|
+
_onLifecycleEvent(event) {
|
|
422
|
+
if (this._firedLifecycleEvents.has(event))
|
|
423
|
+
return;
|
|
424
|
+
this._firedLifecycleEvents.add(event);
|
|
425
|
+
this.emit(Frame.Events.AddLifecycle, event);
|
|
426
|
+
if (this === this._page.mainFrame() && this._url !== "about:blank")
|
|
427
|
+
import_debugLogger.debugLogger.log("api", ` "${event}" event fired`);
|
|
428
|
+
this._page.mainFrame()._recalculateNetworkIdle();
|
|
429
|
+
}
|
|
430
|
+
_onClearLifecycle() {
|
|
431
|
+
this._isolatedWorld = void 0;
|
|
432
|
+
this._mainWorld = void 0;
|
|
433
|
+
this._iframeWorld = void 0;
|
|
434
|
+
for (const event of this._firedLifecycleEvents)
|
|
435
|
+
this.emit(Frame.Events.RemoveLifecycle, event);
|
|
436
|
+
this._firedLifecycleEvents.clear();
|
|
437
|
+
this._inflightRequests = new Set(Array.from(this._inflightRequests).filter((request) => request === this._currentDocument.request));
|
|
438
|
+
this._stopNetworkIdleTimer();
|
|
439
|
+
if (this._inflightRequests.size === 0)
|
|
440
|
+
this._startNetworkIdleTimer();
|
|
441
|
+
this._page.mainFrame()._recalculateNetworkIdle(this);
|
|
442
|
+
this._onLifecycleEvent("commit");
|
|
443
|
+
}
|
|
444
|
+
setPendingDocument(documentInfo) {
|
|
445
|
+
this._pendingDocument = documentInfo;
|
|
446
|
+
if (documentInfo)
|
|
447
|
+
this._invalidateNonStallingEvaluations("Navigation interrupted the evaluation");
|
|
448
|
+
}
|
|
449
|
+
pendingDocument() {
|
|
450
|
+
return this._pendingDocument;
|
|
451
|
+
}
|
|
452
|
+
_invalidateNonStallingEvaluations(message) {
|
|
453
|
+
if (!this._raceAgainstEvaluationStallingEventsPromises.size)
|
|
454
|
+
return;
|
|
455
|
+
const error = new Error(message);
|
|
456
|
+
for (const promise of this._raceAgainstEvaluationStallingEventsPromises)
|
|
457
|
+
promise.reject(error);
|
|
458
|
+
}
|
|
459
|
+
async raceAgainstEvaluationStallingEvents(cb) {
|
|
460
|
+
if (this._pendingDocument)
|
|
461
|
+
throw new Error("Frame is currently attempting a navigation");
|
|
462
|
+
if (this._page._frameManager._openedDialogs.size)
|
|
463
|
+
throw new Error("Open JavaScript dialog prevents evaluation");
|
|
464
|
+
const promise = new import_manualPromise.ManualPromise();
|
|
465
|
+
this._raceAgainstEvaluationStallingEventsPromises.add(promise);
|
|
466
|
+
try {
|
|
467
|
+
return await Promise.race([
|
|
468
|
+
cb(),
|
|
469
|
+
promise
|
|
470
|
+
]);
|
|
471
|
+
} finally {
|
|
472
|
+
this._raceAgainstEvaluationStallingEventsPromises.delete(promise);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
nonStallingRawEvaluateInExistingMainContext(expression) {
|
|
476
|
+
return this.raceAgainstEvaluationStallingEvents(() => {
|
|
477
|
+
const context = this._existingMainContext();
|
|
478
|
+
if (!context)
|
|
479
|
+
throw new Error("Frame does not yet have a main execution context");
|
|
480
|
+
return context.rawEvaluateJSON(expression);
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
nonStallingEvaluateInExistingContext(expression, world) {
|
|
484
|
+
return this.raceAgainstEvaluationStallingEvents(() => {
|
|
485
|
+
const context = this._contextData.get(world)?.context;
|
|
486
|
+
if (!context)
|
|
487
|
+
throw new Error("Frame does not yet have the execution context");
|
|
488
|
+
return context.evaluateExpression(expression, { isFunction: false });
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
_recalculateNetworkIdle(frameThatAllowsRemovingNetworkIdle) {
|
|
492
|
+
let isNetworkIdle = this._firedNetworkIdleSelf;
|
|
493
|
+
for (const child of this._childFrames) {
|
|
494
|
+
child._recalculateNetworkIdle(frameThatAllowsRemovingNetworkIdle);
|
|
495
|
+
if (!child._firedLifecycleEvents.has("networkidle"))
|
|
496
|
+
isNetworkIdle = false;
|
|
497
|
+
}
|
|
498
|
+
if (isNetworkIdle && !this._firedLifecycleEvents.has("networkidle")) {
|
|
499
|
+
this._firedLifecycleEvents.add("networkidle");
|
|
500
|
+
this.emit(Frame.Events.AddLifecycle, "networkidle");
|
|
501
|
+
if (this === this._page.mainFrame() && this._url !== "about:blank")
|
|
502
|
+
import_debugLogger.debugLogger.log("api", ` "networkidle" event fired`);
|
|
503
|
+
}
|
|
504
|
+
if (frameThatAllowsRemovingNetworkIdle !== this && this._firedLifecycleEvents.has("networkidle") && !isNetworkIdle) {
|
|
505
|
+
this._firedLifecycleEvents.delete("networkidle");
|
|
506
|
+
this.emit(Frame.Events.RemoveLifecycle, "networkidle");
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
async raceNavigationAction(progress, options, action) {
|
|
510
|
+
return import_utils.LongStandingScope.raceMultiple([
|
|
511
|
+
this._detachedScope,
|
|
512
|
+
this._page.openScope
|
|
513
|
+
], action().catch((e) => {
|
|
514
|
+
if (e instanceof NavigationAbortedError && e.documentId) {
|
|
515
|
+
const data = this._redirectedNavigations.get(e.documentId);
|
|
516
|
+
if (data) {
|
|
517
|
+
progress.log(`waiting for redirected navigation to "${data.url}"`);
|
|
518
|
+
return data.gotoPromise;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
throw e;
|
|
522
|
+
}));
|
|
523
|
+
}
|
|
524
|
+
redirectNavigation(url, documentId, referer) {
|
|
525
|
+
const controller = new import_progress.ProgressController((0, import_instrumentation.serverSideCallMetadata)(), this);
|
|
526
|
+
const data = {
|
|
527
|
+
url,
|
|
528
|
+
gotoPromise: controller.run((progress) => this._gotoAction(progress, url, { referer }), 0)
|
|
529
|
+
};
|
|
530
|
+
this._redirectedNavigations.set(documentId, data);
|
|
531
|
+
data.gotoPromise.finally(() => this._redirectedNavigations.delete(documentId));
|
|
532
|
+
}
|
|
533
|
+
async goto(metadata, url, options = {}) {
|
|
534
|
+
const constructedNavigationURL = (0, import_utils.constructURLBasedOnBaseURL)(this._page._browserContext._options.baseURL, url);
|
|
535
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
536
|
+
return controller.run((progress) => this._goto(progress, constructedNavigationURL, options), this._page._timeoutSettings.navigationTimeout(options));
|
|
537
|
+
}
|
|
538
|
+
async _goto(progress, url, options) {
|
|
539
|
+
return this.raceNavigationAction(progress, options, async () => this._gotoAction(progress, url, options));
|
|
540
|
+
}
|
|
541
|
+
async _gotoAction(progress, url, options) {
|
|
542
|
+
const waitUntil = verifyLifecycle("waitUntil", options.waitUntil === void 0 ? "load" : options.waitUntil);
|
|
543
|
+
progress.log(`navigating to "${url}", waiting until "${waitUntil}"`);
|
|
544
|
+
const headers = this._page.extraHTTPHeaders() || [];
|
|
545
|
+
const refererHeader = headers.find((h) => h.name.toLowerCase() === "referer");
|
|
546
|
+
let referer = refererHeader ? refererHeader.value : void 0;
|
|
547
|
+
if (options.referer !== void 0) {
|
|
548
|
+
if (referer !== void 0 && referer !== options.referer)
|
|
549
|
+
throw new Error('"referer" is already specified as extra HTTP header');
|
|
550
|
+
referer = options.referer;
|
|
551
|
+
}
|
|
552
|
+
url = import_helper.helper.completeUserURL(url);
|
|
553
|
+
const navigationEvents = [];
|
|
554
|
+
const collectNavigations = (arg) => navigationEvents.push(arg);
|
|
555
|
+
this.on(Frame.Events.InternalNavigation, collectNavigations);
|
|
556
|
+
const navigateResult = await this._page._delegate.navigateFrame(this, url, referer).finally(
|
|
557
|
+
() => this.off(Frame.Events.InternalNavigation, collectNavigations)
|
|
558
|
+
);
|
|
559
|
+
let event;
|
|
560
|
+
if (navigateResult.newDocumentId) {
|
|
561
|
+
const predicate = (event2) => {
|
|
562
|
+
return event2.newDocument && (event2.newDocument.documentId === navigateResult.newDocumentId || !event2.error);
|
|
563
|
+
};
|
|
564
|
+
const events = navigationEvents.filter(predicate);
|
|
565
|
+
if (events.length)
|
|
566
|
+
event = events[0];
|
|
567
|
+
else
|
|
568
|
+
event = await import_helper.helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, predicate).promise;
|
|
569
|
+
if (event.newDocument.documentId !== navigateResult.newDocumentId) {
|
|
570
|
+
throw new NavigationAbortedError(navigateResult.newDocumentId, `Navigation to "${url}" is interrupted by another navigation to "${event.url}"`);
|
|
571
|
+
}
|
|
572
|
+
if (event.error)
|
|
573
|
+
throw event.error;
|
|
574
|
+
} else {
|
|
575
|
+
const predicate = (e) => !e.newDocument;
|
|
576
|
+
const events = navigationEvents.filter(predicate);
|
|
577
|
+
if (events.length)
|
|
578
|
+
event = events[0];
|
|
579
|
+
else
|
|
580
|
+
event = await import_helper.helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, predicate).promise;
|
|
581
|
+
}
|
|
582
|
+
if (!this._firedLifecycleEvents.has(waitUntil))
|
|
583
|
+
await import_helper.helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, (e) => e === waitUntil).promise;
|
|
584
|
+
const request = event.newDocument ? event.newDocument.request : void 0;
|
|
585
|
+
const response = request ? request._finalRequest().response() : null;
|
|
586
|
+
return response;
|
|
587
|
+
}
|
|
588
|
+
async _waitForNavigation(progress, requiresNewDocument, options) {
|
|
589
|
+
const waitUntil = verifyLifecycle("waitUntil", options.waitUntil === void 0 ? "load" : options.waitUntil);
|
|
590
|
+
progress.log(`waiting for navigation until "${waitUntil}"`);
|
|
591
|
+
const navigationEvent = await import_helper.helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, (event) => {
|
|
592
|
+
if (event.error)
|
|
593
|
+
return true;
|
|
594
|
+
if (requiresNewDocument && !event.newDocument)
|
|
595
|
+
return false;
|
|
596
|
+
progress.log(` navigated to "${this._url}"`);
|
|
597
|
+
return true;
|
|
598
|
+
}).promise;
|
|
599
|
+
if (navigationEvent.error)
|
|
600
|
+
throw navigationEvent.error;
|
|
601
|
+
if (!this._firedLifecycleEvents.has(waitUntil))
|
|
602
|
+
await import_helper.helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, (e) => e === waitUntil).promise;
|
|
603
|
+
const request = navigationEvent.newDocument ? navigationEvent.newDocument.request : void 0;
|
|
604
|
+
return request ? request._finalRequest().response() : null;
|
|
605
|
+
}
|
|
606
|
+
async _waitForLoadState(progress, state) {
|
|
607
|
+
const waitUntil = verifyLifecycle("state", state);
|
|
608
|
+
if (!this._firedLifecycleEvents.has(waitUntil))
|
|
609
|
+
await import_helper.helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, (e) => e === waitUntil).promise;
|
|
610
|
+
}
|
|
611
|
+
async frameElement() {
|
|
612
|
+
return this._page._delegate.getFrameElement(this);
|
|
613
|
+
}
|
|
614
|
+
async _context(world) {
|
|
615
|
+
if (this.isDetached()) throw new Error("Frame was detached");
|
|
616
|
+
try {
|
|
617
|
+
var client = this._page._delegate._sessionForFrame(this)._client;
|
|
618
|
+
} catch (e) {
|
|
619
|
+
var client = this._page._delegate._mainFrameSession._client;
|
|
620
|
+
}
|
|
621
|
+
var iframeExecutionContextId = await this._getFrameMainFrameContextId(client);
|
|
622
|
+
if (world == "main") {
|
|
623
|
+
if (this != this._page.mainFrame() && iframeExecutionContextId && this._iframeWorld == void 0) {
|
|
624
|
+
var executionContextId = iframeExecutionContextId;
|
|
625
|
+
var crContext = new import_crExecutionContext.CRExecutionContext(client, { id: executionContextId }, this._id);
|
|
626
|
+
this._iframeWorld = new import_dom.FrameExecutionContext(crContext, this, world);
|
|
627
|
+
this._page._delegate._mainFrameSession._onExecutionContextCreated({
|
|
628
|
+
id: executionContextId,
|
|
629
|
+
origin: world,
|
|
630
|
+
name: world,
|
|
631
|
+
auxData: { isDefault: this === this._page.mainFrame(), type: "isolated", frameId: this._id }
|
|
632
|
+
});
|
|
633
|
+
} else if (this._mainWorld == void 0) {
|
|
634
|
+
var globalThis2 = await client._sendMayFail("Runtime.evaluate", {
|
|
635
|
+
expression: "globalThis",
|
|
636
|
+
serializationOptions: { serialization: "idOnly" }
|
|
637
|
+
});
|
|
638
|
+
if (!globalThis2) {
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
var globalThisObjId = globalThis2["result"]["objectId"];
|
|
642
|
+
var executionContextId = parseInt(globalThisObjId.split(".")[1], 10);
|
|
643
|
+
var crContext = new import_crExecutionContext.CRExecutionContext(client, { id: executionContextId }, this._id);
|
|
644
|
+
this._mainWorld = new import_dom.FrameExecutionContext(crContext, this, world);
|
|
645
|
+
this._page._delegate._mainFrameSession._onExecutionContextCreated({
|
|
646
|
+
id: executionContextId,
|
|
647
|
+
origin: world,
|
|
648
|
+
name: world,
|
|
649
|
+
auxData: { isDefault: this === this._page.mainFrame(), type: "isolated", frameId: this._id }
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
if (world != "main" && this._isolatedWorld == void 0) {
|
|
654
|
+
world = "utility";
|
|
655
|
+
var result = await client._sendMayFail("Page.createIsolatedWorld", {
|
|
656
|
+
frameId: this._id,
|
|
657
|
+
grantUniveralAccess: true,
|
|
658
|
+
worldName: world
|
|
659
|
+
});
|
|
660
|
+
if (!result) {
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
var executionContextId = result.executionContextId;
|
|
664
|
+
var crContext = new import_crExecutionContext.CRExecutionContext(client, { id: executionContextId }, this._id);
|
|
665
|
+
this._isolatedWorld = new import_dom.FrameExecutionContext(crContext, this, world);
|
|
666
|
+
this._page._delegate._mainFrameSession._onExecutionContextCreated({
|
|
667
|
+
id: executionContextId,
|
|
668
|
+
origin: world,
|
|
669
|
+
name: world,
|
|
670
|
+
auxData: { isDefault: this === this._page.mainFrame(), type: "isolated", frameId: this._id }
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
if (world != "main") {
|
|
674
|
+
return this._isolatedWorld;
|
|
675
|
+
} else if (this != this._page.mainFrame() && iframeExecutionContextId) {
|
|
676
|
+
return this._iframeWorld;
|
|
677
|
+
} else {
|
|
678
|
+
return this._mainWorld;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
_mainContext() {
|
|
682
|
+
return this._context("main");
|
|
683
|
+
}
|
|
684
|
+
_existingMainContext() {
|
|
685
|
+
return this._contextData.get("main")?.context || null;
|
|
686
|
+
}
|
|
687
|
+
_utilityContext() {
|
|
688
|
+
return this._context("utility");
|
|
689
|
+
}
|
|
690
|
+
async evaluateExpression(expression, options = {}, arg) {
|
|
691
|
+
const context = await this._context(options.world ?? "main");
|
|
692
|
+
const value = await context.evaluateExpression(expression, options, arg);
|
|
693
|
+
return value;
|
|
694
|
+
}
|
|
695
|
+
async evaluateExpressionHandle(expression, options = {}, arg) {
|
|
696
|
+
const context = await this._context(options.world ?? "main");
|
|
697
|
+
const value = await context.evaluateExpressionHandle(expression, options, arg);
|
|
698
|
+
return value;
|
|
699
|
+
}
|
|
700
|
+
async querySelector(selector, options) {
|
|
701
|
+
import_debugLogger.debugLogger.log("api", ` finding element using the selector "${selector}"`);
|
|
702
|
+
return this.selectors.query(selector, options);
|
|
703
|
+
}
|
|
704
|
+
async waitForSelector(metadata, selector, options, scope) {
|
|
705
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
706
|
+
if (options.visibility)
|
|
707
|
+
throw new Error("options.visibility is not supported, did you mean options.state?");
|
|
708
|
+
if (options.waitFor && options.waitFor !== "visible")
|
|
709
|
+
throw new Error("options.waitFor is not supported, did you mean options.state?");
|
|
710
|
+
const { state = "visible" } = options;
|
|
711
|
+
if (!["attached", "detached", "visible", "hidden"].includes(state))
|
|
712
|
+
throw new Error(`state: expected one of (attached|detached|visible|hidden)`);
|
|
713
|
+
return controller.run(async (progress) => {
|
|
714
|
+
progress.log(`waiting for ${this._asLocator(selector)}${state === "attached" ? "" : " to be " + state}`);
|
|
715
|
+
return await this.waitForSelectorInternal(progress, selector, true, options, scope);
|
|
716
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
717
|
+
}
|
|
718
|
+
async waitForSelectorInternal(progress, selector, performActionPreChecks, options, scope) {
|
|
719
|
+
const {
|
|
720
|
+
state = "visible"
|
|
721
|
+
} = options;
|
|
722
|
+
const promise = this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, async (handle) => {
|
|
723
|
+
const attached = !!handle;
|
|
724
|
+
var visible = false;
|
|
725
|
+
if (attached) {
|
|
726
|
+
if (handle.parentNode.constructor.name == "ElementHandle") {
|
|
727
|
+
visible = await handle.parentNode.evaluateInUtility(([injected, node, { handle: handle2 }]) => {
|
|
728
|
+
return handle2 ? injected.utils.isElementVisible(handle2) : false;
|
|
729
|
+
}, {
|
|
730
|
+
handle
|
|
731
|
+
});
|
|
732
|
+
} else {
|
|
733
|
+
visible = await handle.parentNode.evaluate((injected, { handle: handle2 }) => {
|
|
734
|
+
return handle2 ? injected.utils.isElementVisible(handle2) : false;
|
|
735
|
+
}, {
|
|
736
|
+
handle
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
const success = {
|
|
741
|
+
attached,
|
|
742
|
+
detached: !attached,
|
|
743
|
+
visible,
|
|
744
|
+
hidden: !visible
|
|
745
|
+
}[state];
|
|
746
|
+
if (!success) {
|
|
747
|
+
return "internal:continuepolling";
|
|
748
|
+
}
|
|
749
|
+
if (options.omitReturnValue) {
|
|
750
|
+
return null;
|
|
751
|
+
}
|
|
752
|
+
const element = state === "attached" || state === "visible" ? handle : null;
|
|
753
|
+
if (!element) return null;
|
|
754
|
+
if (options.__testHookBeforeAdoptNode) await options.__testHookBeforeAdoptNode();
|
|
755
|
+
try {
|
|
756
|
+
return element;
|
|
757
|
+
} catch (e) {
|
|
758
|
+
return "internal:continuepolling";
|
|
759
|
+
}
|
|
760
|
+
}, "returnOnNotResolved");
|
|
761
|
+
return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
|
|
762
|
+
}
|
|
763
|
+
async dispatchEvent(metadata, selector, type, eventInit = {}, options = {}, scope) {
|
|
764
|
+
await this._callOnElementOnceMatches(metadata, selector, (injectedScript, element, data) => {
|
|
765
|
+
injectedScript.dispatchEvent(element, data.type, data.eventInit);
|
|
766
|
+
}, { type, eventInit }, { mainWorld: true, ...options }, scope);
|
|
767
|
+
}
|
|
768
|
+
async evalOnSelector(selector, strict, expression, isFunction, arg, scope) {
|
|
769
|
+
const handle = await this.selectors.query(selector, { strict }, scope);
|
|
770
|
+
if (!handle)
|
|
771
|
+
throw new Error("Failed to find element matching selector " + selector);
|
|
772
|
+
const result = await handle.evaluateExpression(expression, { isFunction }, arg, true);
|
|
773
|
+
handle.dispose();
|
|
774
|
+
return result;
|
|
775
|
+
}
|
|
776
|
+
async evalOnSelectorAll(selector, expression, isFunction, arg, scope, isolatedContext) {
|
|
777
|
+
try {
|
|
778
|
+
const arrayHandle = await this.selectors.queryArrayInMainWorld(selector, scope, isolatedContext);
|
|
779
|
+
const result = await arrayHandle.evaluateExpression(expression, { isFunction }, arg, isolatedContext);
|
|
780
|
+
arrayHandle.dispose();
|
|
781
|
+
return result;
|
|
782
|
+
} catch (e) {
|
|
783
|
+
if ("JSHandles can be evaluated only in the context they were created!" === e.message) return await this.evalOnSelectorAll(selector, expression, isFunction, arg, scope, isolatedContext);
|
|
784
|
+
throw e;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
async maskSelectors(selectors, color) {
|
|
788
|
+
const context = await this._utilityContext();
|
|
789
|
+
const injectedScript = await context.injectedScript();
|
|
790
|
+
await injectedScript.evaluate((injected, { parsed, color: color2 }) => {
|
|
791
|
+
injected.maskSelectors(parsed, color2);
|
|
792
|
+
}, { parsed: selectors, color });
|
|
793
|
+
}
|
|
794
|
+
async querySelectorAll(selector) {
|
|
795
|
+
return this.selectors.queryAll(selector);
|
|
796
|
+
}
|
|
797
|
+
async queryCount(selector) {
|
|
798
|
+
const customMetadata = {
|
|
799
|
+
"internal": false,
|
|
800
|
+
"log": [],
|
|
801
|
+
"method": "queryCount"
|
|
802
|
+
};
|
|
803
|
+
const controller = new import_progress.ProgressController(customMetadata, this);
|
|
804
|
+
const resultPromise = await controller.run(async (progress) => {
|
|
805
|
+
progress.log("waiting for " + this._asLocator(selector));
|
|
806
|
+
const promise = await this._retryWithProgressIfNotConnected(progress, selector, null, false, async (result) => {
|
|
807
|
+
if (!result) return 0;
|
|
808
|
+
const handle = result[0];
|
|
809
|
+
const handles = result[1];
|
|
810
|
+
return handle ? handles.length : 0;
|
|
811
|
+
}, "returnAll");
|
|
812
|
+
return promise;
|
|
813
|
+
}, 1e4);
|
|
814
|
+
return resultPromise ? resultPromise : 0;
|
|
815
|
+
}
|
|
816
|
+
async content() {
|
|
817
|
+
try {
|
|
818
|
+
const context = await this._utilityContext();
|
|
819
|
+
return await context.evaluate(() => {
|
|
820
|
+
let retVal = "";
|
|
821
|
+
if (document.doctype)
|
|
822
|
+
retVal = new XMLSerializer().serializeToString(document.doctype);
|
|
823
|
+
if (document.documentElement)
|
|
824
|
+
retVal += document.documentElement.outerHTML;
|
|
825
|
+
return retVal;
|
|
826
|
+
});
|
|
827
|
+
} catch (e) {
|
|
828
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_protocolError.isSessionClosedError)(e))
|
|
829
|
+
throw e;
|
|
830
|
+
throw new Error(`Unable to retrieve content because the page is navigating and changing the content.`);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
async setContent(metadata, html, options = {}) {
|
|
834
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
835
|
+
return controller.run(async (progress) => {
|
|
836
|
+
await this.raceNavigationAction(progress, options, async () => {
|
|
837
|
+
const waitUntil = options.waitUntil === void 0 ? "load" : options.waitUntil;
|
|
838
|
+
progress.log(`setting frame content, waiting until "${waitUntil}"`);
|
|
839
|
+
const tag = `--playwright--set--content--${this._id}--${++this._setContentCounter}--`;
|
|
840
|
+
const bindingName = "_tagDebug" + import_crypto.default.randomBytes(20).toString("hex");
|
|
841
|
+
const context = await this._utilityContext();
|
|
842
|
+
await this._page._delegate._mainFrameSession._client.send("Runtime.addBinding", { name: bindingName });
|
|
843
|
+
const lifecyclePromise = new Promise(async (resolve, reject) => {
|
|
844
|
+
await this._page.exposeBinding(bindingName, false, (tag2) => {
|
|
845
|
+
this._onClearLifecycle();
|
|
846
|
+
this._waitForLoadState(progress, waitUntil).then(resolve).catch(reject);
|
|
847
|
+
});
|
|
848
|
+
});
|
|
849
|
+
const contentPromise = context.evaluate(({ html: html2, tag: tag2, bindingName: bindingName2 }) => {
|
|
850
|
+
document.open();
|
|
851
|
+
var _tagDebug = window[bindingName2].bind({});
|
|
852
|
+
delete window[bindingName2];
|
|
853
|
+
_tagDebug('{ "name": "' + bindingName2 + '", "seq": 1, "serializedArgs": ["' + tag2 + '"] }');
|
|
854
|
+
console.debug(tag2);
|
|
855
|
+
document.write(html2);
|
|
856
|
+
document.close();
|
|
857
|
+
}, {
|
|
858
|
+
html,
|
|
859
|
+
tag,
|
|
860
|
+
bindingName
|
|
861
|
+
});
|
|
862
|
+
await Promise.all([contentPromise, lifecyclePromise]);
|
|
863
|
+
return null;
|
|
864
|
+
});
|
|
865
|
+
}, this._page._timeoutSettings.navigationTimeout(options));
|
|
866
|
+
}
|
|
867
|
+
name() {
|
|
868
|
+
return this._name || "";
|
|
869
|
+
}
|
|
870
|
+
url() {
|
|
871
|
+
return this._url;
|
|
872
|
+
}
|
|
873
|
+
origin() {
|
|
874
|
+
if (!this._url.startsWith("http"))
|
|
875
|
+
return;
|
|
876
|
+
return network.parseURL(this._url)?.origin;
|
|
877
|
+
}
|
|
878
|
+
parentFrame() {
|
|
879
|
+
return this._parentFrame;
|
|
880
|
+
}
|
|
881
|
+
childFrames() {
|
|
882
|
+
return Array.from(this._childFrames);
|
|
883
|
+
}
|
|
884
|
+
async addScriptTag(params) {
|
|
885
|
+
const {
|
|
886
|
+
url = null,
|
|
887
|
+
content = null,
|
|
888
|
+
type = ""
|
|
889
|
+
} = params;
|
|
890
|
+
if (!url && !content)
|
|
891
|
+
throw new Error("Provide an object with a `url`, `path` or `content` property");
|
|
892
|
+
const context = await this._mainContext();
|
|
893
|
+
return this._raceWithCSPError(async () => {
|
|
894
|
+
if (url !== null)
|
|
895
|
+
return (await context.evaluateHandle(addScriptUrl, { url, type })).asElement();
|
|
896
|
+
const result = (await context.evaluateHandle(addScriptContent, { content, type })).asElement();
|
|
897
|
+
if (this._page._delegate.cspErrorsAsynchronousForInlineScripts)
|
|
898
|
+
await context.evaluate(() => true);
|
|
899
|
+
return result;
|
|
900
|
+
});
|
|
901
|
+
async function addScriptUrl(params2) {
|
|
902
|
+
const script = document.createElement("script");
|
|
903
|
+
script.src = params2.url;
|
|
904
|
+
if (params2.type)
|
|
905
|
+
script.type = params2.type;
|
|
906
|
+
const promise = new Promise((res, rej) => {
|
|
907
|
+
script.onload = res;
|
|
908
|
+
script.onerror = (e) => rej(typeof e === "string" ? new Error(e) : new Error(`Failed to load script at ${script.src}`));
|
|
909
|
+
});
|
|
910
|
+
document.head.appendChild(script);
|
|
911
|
+
await promise;
|
|
912
|
+
return script;
|
|
913
|
+
}
|
|
914
|
+
function addScriptContent(params2) {
|
|
915
|
+
const script = document.createElement("script");
|
|
916
|
+
script.type = params2.type || "text/javascript";
|
|
917
|
+
script.text = params2.content;
|
|
918
|
+
let error = null;
|
|
919
|
+
script.onerror = (e) => error = e;
|
|
920
|
+
document.head.appendChild(script);
|
|
921
|
+
if (error)
|
|
922
|
+
throw error;
|
|
923
|
+
return script;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
async addStyleTag(params) {
|
|
927
|
+
const {
|
|
928
|
+
url = null,
|
|
929
|
+
content = null
|
|
930
|
+
} = params;
|
|
931
|
+
if (!url && !content)
|
|
932
|
+
throw new Error("Provide an object with a `url`, `path` or `content` property");
|
|
933
|
+
const context = await this._mainContext();
|
|
934
|
+
return this._raceWithCSPError(async () => {
|
|
935
|
+
if (url !== null)
|
|
936
|
+
return (await context.evaluateHandle(addStyleUrl, url)).asElement();
|
|
937
|
+
return (await context.evaluateHandle(addStyleContent, content)).asElement();
|
|
938
|
+
});
|
|
939
|
+
async function addStyleUrl(url2) {
|
|
940
|
+
const link = document.createElement("link");
|
|
941
|
+
link.rel = "stylesheet";
|
|
942
|
+
link.href = url2;
|
|
943
|
+
const promise = new Promise((res, rej) => {
|
|
944
|
+
link.onload = res;
|
|
945
|
+
link.onerror = rej;
|
|
946
|
+
});
|
|
947
|
+
document.head.appendChild(link);
|
|
948
|
+
await promise;
|
|
949
|
+
return link;
|
|
950
|
+
}
|
|
951
|
+
async function addStyleContent(content2) {
|
|
952
|
+
const style = document.createElement("style");
|
|
953
|
+
style.type = "text/css";
|
|
954
|
+
style.appendChild(document.createTextNode(content2));
|
|
955
|
+
const promise = new Promise((res, rej) => {
|
|
956
|
+
style.onload = res;
|
|
957
|
+
style.onerror = rej;
|
|
958
|
+
});
|
|
959
|
+
document.head.appendChild(style);
|
|
960
|
+
await promise;
|
|
961
|
+
return style;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
async _raceWithCSPError(func) {
|
|
965
|
+
const listeners = [];
|
|
966
|
+
let result;
|
|
967
|
+
let error;
|
|
968
|
+
let cspMessage;
|
|
969
|
+
const actionPromise = func().then((r) => result = r).catch((e) => error = e);
|
|
970
|
+
const errorPromise = new Promise((resolve) => {
|
|
971
|
+
listeners.push(import_eventsHelper.eventsHelper.addEventListener(this._page._browserContext, import_browserContext.BrowserContext.Events.Console, (message) => {
|
|
972
|
+
if (message.page() !== this._page || message.type() !== "error")
|
|
973
|
+
return;
|
|
974
|
+
if (message.text().includes("Content-Security-Policy") || message.text().includes("Content Security Policy")) {
|
|
975
|
+
cspMessage = message;
|
|
976
|
+
resolve();
|
|
977
|
+
}
|
|
978
|
+
}));
|
|
979
|
+
});
|
|
980
|
+
await Promise.race([actionPromise, errorPromise]);
|
|
981
|
+
import_eventsHelper.eventsHelper.removeEventListeners(listeners);
|
|
982
|
+
if (cspMessage)
|
|
983
|
+
throw new Error(cspMessage.text());
|
|
984
|
+
if (error)
|
|
985
|
+
throw error;
|
|
986
|
+
return result;
|
|
987
|
+
}
|
|
988
|
+
async retryWithProgressAndTimeouts(progress, timeouts, action) {
|
|
989
|
+
const continuePolling = Symbol("continuePolling");
|
|
990
|
+
timeouts = [0, ...timeouts];
|
|
991
|
+
let timeoutIndex = 0;
|
|
992
|
+
while (progress.isRunning()) {
|
|
993
|
+
const timeout = timeouts[Math.min(timeoutIndex++, timeouts.length - 1)];
|
|
994
|
+
if (timeout) {
|
|
995
|
+
const actionPromise = new Promise((f) => setTimeout(f, timeout));
|
|
996
|
+
await import_utils.LongStandingScope.raceMultiple([
|
|
997
|
+
this._page.openScope,
|
|
998
|
+
this._detachedScope
|
|
999
|
+
], actionPromise);
|
|
1000
|
+
}
|
|
1001
|
+
progress.throwIfAborted();
|
|
1002
|
+
try {
|
|
1003
|
+
const result = await action(continuePolling);
|
|
1004
|
+
if (result === continuePolling)
|
|
1005
|
+
continue;
|
|
1006
|
+
return result;
|
|
1007
|
+
} catch (e) {
|
|
1008
|
+
if (this._isErrorThatCannotBeRetried(e))
|
|
1009
|
+
throw e;
|
|
1010
|
+
continue;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
progress.throwIfAborted();
|
|
1014
|
+
return void 0;
|
|
1015
|
+
}
|
|
1016
|
+
_isErrorThatCannotBeRetried(e) {
|
|
1017
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_protocolError.isSessionClosedError)(e))
|
|
1018
|
+
return true;
|
|
1019
|
+
if (dom.isNonRecoverableDOMError(e) || (0, import_selectorParser.isInvalidSelectorError)(e))
|
|
1020
|
+
return true;
|
|
1021
|
+
if (this.isDetached())
|
|
1022
|
+
return true;
|
|
1023
|
+
return false;
|
|
1024
|
+
}
|
|
1025
|
+
async _retryWithProgressIfNotConnected(progress, selector, strict, performActionPreChecks, action, returnAction) {
|
|
1026
|
+
progress.log("waiting for " + this._asLocator(selector));
|
|
1027
|
+
return this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling) => {
|
|
1028
|
+
if (performActionPreChecks) await this._page.performActionPreChecks(progress);
|
|
1029
|
+
const resolved = await this.selectors.resolveInjectedForSelector(selector, {
|
|
1030
|
+
strict
|
|
1031
|
+
});
|
|
1032
|
+
progress.throwIfAborted();
|
|
1033
|
+
if (!resolved) {
|
|
1034
|
+
if (returnAction === "returnOnNotResolved" || returnAction === "returnAll") {
|
|
1035
|
+
const result2 = await action(null);
|
|
1036
|
+
return result2 === "internal:continuepolling" ? continuePolling2 : result2;
|
|
1037
|
+
}
|
|
1038
|
+
return continuePolling;
|
|
1039
|
+
}
|
|
1040
|
+
try {
|
|
1041
|
+
var client = this._page._delegate._sessionForFrame(resolved.frame)._client;
|
|
1042
|
+
} catch (e) {
|
|
1043
|
+
var client = this._page._delegate._mainFrameSession._client;
|
|
1044
|
+
}
|
|
1045
|
+
var utilityContext = await resolved.frame._utilityContext();
|
|
1046
|
+
var mainContext = await resolved.frame._mainContext();
|
|
1047
|
+
const documentNode = await client.send("Runtime.evaluate", {
|
|
1048
|
+
expression: "document",
|
|
1049
|
+
serializationOptions: {
|
|
1050
|
+
serialization: "idOnly"
|
|
1051
|
+
},
|
|
1052
|
+
contextId: utilityContext.delegate._contextId
|
|
1053
|
+
});
|
|
1054
|
+
const documentScope = new dom.ElementHandle(utilityContext, documentNode.result.objectId);
|
|
1055
|
+
let currentScopingElements;
|
|
1056
|
+
try {
|
|
1057
|
+
currentScopingElements = await this._customFindElementsByParsed(resolved, client, mainContext, documentScope, progress, resolved.info.parsed);
|
|
1058
|
+
} catch (e) {
|
|
1059
|
+
if ("JSHandles can be evaluated only in the context they were created!" === e.message) return continuePolling3;
|
|
1060
|
+
await resolved.injected.evaluateHandle((injected, { error }) => {
|
|
1061
|
+
throw error;
|
|
1062
|
+
}, { error: e });
|
|
1063
|
+
}
|
|
1064
|
+
if (currentScopingElements.length == 0) {
|
|
1065
|
+
if (returnAction === "returnOnNotResolved" || returnAction === "returnAll") {
|
|
1066
|
+
const result2 = await action(null);
|
|
1067
|
+
return result2 === "internal:continuepolling" ? continuePolling2 : result2;
|
|
1068
|
+
}
|
|
1069
|
+
return continuePolling;
|
|
1070
|
+
}
|
|
1071
|
+
const resultElement = currentScopingElements[0];
|
|
1072
|
+
if (currentScopingElements.length > 1) {
|
|
1073
|
+
if (resolved.info.strict) {
|
|
1074
|
+
await resolved.injected.evaluateHandle((injected, {
|
|
1075
|
+
info,
|
|
1076
|
+
elements
|
|
1077
|
+
}) => {
|
|
1078
|
+
throw injected.strictModeViolationError(info.parsed, elements);
|
|
1079
|
+
}, {
|
|
1080
|
+
info: resolved.info,
|
|
1081
|
+
elements: currentScopingElements
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
progress.log(" locator resolved to " + currentScopingElements.length + " elements. Proceeding with the first one: " + resultElement.preview());
|
|
1085
|
+
} else if (resultElement) {
|
|
1086
|
+
progress.log(" locator resolved to " + resultElement.preview());
|
|
1087
|
+
}
|
|
1088
|
+
try {
|
|
1089
|
+
var result = null;
|
|
1090
|
+
if (returnAction === "returnAll") {
|
|
1091
|
+
result = await action([resultElement, currentScopingElements]);
|
|
1092
|
+
} else {
|
|
1093
|
+
result = await action(resultElement);
|
|
1094
|
+
}
|
|
1095
|
+
if (result === "error:notconnected") {
|
|
1096
|
+
progress.log("element was detached from the DOM, retrying");
|
|
1097
|
+
return continuePolling;
|
|
1098
|
+
} else if (result === "internal:continuepolling") {
|
|
1099
|
+
return continuePolling;
|
|
1100
|
+
}
|
|
1101
|
+
return result;
|
|
1102
|
+
} finally {
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
async rafrafTimeoutScreenshotElementWithProgress(progress, selector, timeout, options) {
|
|
1107
|
+
return await this._retryWithProgressIfNotConnected(progress, selector, true, true, async (handle) => {
|
|
1108
|
+
await handle._frame.rafrafTimeout(timeout);
|
|
1109
|
+
return await this._page._screenshotter.screenshotElement(progress, handle, options);
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
async click(metadata, selector, options) {
|
|
1113
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1114
|
+
return controller.run(async (progress) => {
|
|
1115
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._click(progress, { ...options, waitAfter: !options.noWaitAfter })));
|
|
1116
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
1117
|
+
}
|
|
1118
|
+
async dblclick(metadata, selector, options = {}) {
|
|
1119
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1120
|
+
return controller.run(async (progress) => {
|
|
1121
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._dblclick(progress, options)));
|
|
1122
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
1123
|
+
}
|
|
1124
|
+
async dragAndDrop(metadata, source, target, options = {}) {
|
|
1125
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1126
|
+
await controller.run(async (progress) => {
|
|
1127
|
+
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, source, options.strict, !options.force, async (handle) => {
|
|
1128
|
+
return handle._retryPointerAction(progress, "move and down", false, async (point) => {
|
|
1129
|
+
await this._page.mouse.move(point.x, point.y);
|
|
1130
|
+
await this._page.mouse.down();
|
|
1131
|
+
}, {
|
|
1132
|
+
...options,
|
|
1133
|
+
waitAfter: "disabled",
|
|
1134
|
+
position: options.sourcePosition,
|
|
1135
|
+
timeout: progress.timeUntilDeadline()
|
|
1136
|
+
});
|
|
1137
|
+
}));
|
|
1138
|
+
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, target, options.strict, false, async (handle) => {
|
|
1139
|
+
return handle._retryPointerAction(progress, "move and up", false, async (point) => {
|
|
1140
|
+
await this._page.mouse.move(point.x, point.y);
|
|
1141
|
+
await this._page.mouse.up();
|
|
1142
|
+
}, {
|
|
1143
|
+
...options,
|
|
1144
|
+
waitAfter: "disabled",
|
|
1145
|
+
position: options.targetPosition,
|
|
1146
|
+
timeout: progress.timeUntilDeadline()
|
|
1147
|
+
});
|
|
1148
|
+
}));
|
|
1149
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
1150
|
+
}
|
|
1151
|
+
async tap(metadata, selector, options) {
|
|
1152
|
+
if (!this._page._browserContext._options.hasTouch)
|
|
1153
|
+
throw new Error("The page does not support tap. Use hasTouch context option to enable touch support.");
|
|
1154
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1155
|
+
return controller.run(async (progress) => {
|
|
1156
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._tap(progress, options)));
|
|
1157
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
1158
|
+
}
|
|
1159
|
+
async fill(metadata, selector, value, options) {
|
|
1160
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1161
|
+
return controller.run(async (progress) => {
|
|
1162
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._fill(progress, value, options)));
|
|
1163
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
1164
|
+
}
|
|
1165
|
+
async focus(metadata, selector, options = {}) {
|
|
1166
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1167
|
+
await controller.run(async (progress) => {
|
|
1168
|
+
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle) => handle._focus(progress)));
|
|
1169
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
1170
|
+
}
|
|
1171
|
+
async blur(metadata, selector, options = {}) {
|
|
1172
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1173
|
+
await controller.run(async (progress) => {
|
|
1174
|
+
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle) => handle._blur(progress)));
|
|
1175
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
1176
|
+
}
|
|
1177
|
+
async textContent(metadata, selector, options = {}, scope) {
|
|
1178
|
+
return this._callOnElementOnceMatches(metadata, selector, (injected, element) => element.textContent, void 0, options, scope);
|
|
1179
|
+
}
|
|
1180
|
+
async innerText(metadata, selector, options = {}, scope) {
|
|
1181
|
+
return this._callOnElementOnceMatches(metadata, selector, (injectedScript, element) => {
|
|
1182
|
+
if (element.namespaceURI !== "http://www.w3.org/1999/xhtml")
|
|
1183
|
+
throw injectedScript.createStacklessError("Node is not an HTMLElement");
|
|
1184
|
+
return element.innerText;
|
|
1185
|
+
}, void 0, options, scope);
|
|
1186
|
+
}
|
|
1187
|
+
async innerHTML(metadata, selector, options = {}, scope) {
|
|
1188
|
+
return this._callOnElementOnceMatches(metadata, selector, (injected, element) => element.innerHTML, void 0, options, scope);
|
|
1189
|
+
}
|
|
1190
|
+
async getAttribute(metadata, selector, name, options = {}, scope) {
|
|
1191
|
+
return this._callOnElementOnceMatches(metadata, selector, (injected, element, data) => element.getAttribute(data.name), { name }, options, scope);
|
|
1192
|
+
}
|
|
1193
|
+
async inputValue(metadata, selector, options = {}, scope) {
|
|
1194
|
+
return this._callOnElementOnceMatches(metadata, selector, (injectedScript, node) => {
|
|
1195
|
+
const element = injectedScript.retarget(node, "follow-label");
|
|
1196
|
+
if (!element || element.nodeName !== "INPUT" && element.nodeName !== "TEXTAREA" && element.nodeName !== "SELECT")
|
|
1197
|
+
throw injectedScript.createStacklessError("Node is not an <input>, <textarea> or <select> element");
|
|
1198
|
+
return element.value;
|
|
1199
|
+
}, void 0, options, scope);
|
|
1200
|
+
}
|
|
1201
|
+
async highlight(selector) {
|
|
1202
|
+
const resolved = await this.selectors.resolveInjectedForSelector(selector);
|
|
1203
|
+
if (!resolved)
|
|
1204
|
+
return;
|
|
1205
|
+
return await resolved.injected.evaluate((injected, { info }) => {
|
|
1206
|
+
return injected.highlight(info.parsed);
|
|
1207
|
+
}, { info: resolved.info });
|
|
1208
|
+
}
|
|
1209
|
+
async hideHighlight() {
|
|
1210
|
+
return this.raceAgainstEvaluationStallingEvents(async () => {
|
|
1211
|
+
const context = await this._utilityContext();
|
|
1212
|
+
const injectedScript = await context.injectedScript();
|
|
1213
|
+
return await injectedScript.evaluate((injected) => {
|
|
1214
|
+
return injected.hideHighlight();
|
|
1215
|
+
});
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
async _elementState(metadata, selector, state, options = {}, scope) {
|
|
1219
|
+
const result = await this._callOnElementOnceMatches(metadata, selector, (injected, element, data) => {
|
|
1220
|
+
return injected.elementState(element, data.state);
|
|
1221
|
+
}, { state }, options, scope);
|
|
1222
|
+
if (result.received === "error:notconnected")
|
|
1223
|
+
dom.throwElementIsNotAttached();
|
|
1224
|
+
return result.matches;
|
|
1225
|
+
}
|
|
1226
|
+
async isVisible(metadata, selector, options = {}, scope) {
|
|
1227
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1228
|
+
return controller.run(async (progress) => {
|
|
1229
|
+
progress.log(` checking visibility of ${this._asLocator(selector)}`);
|
|
1230
|
+
return await this.isVisibleInternal(selector, options, scope);
|
|
1231
|
+
}, this._page._timeoutSettings.timeout({}));
|
|
1232
|
+
}
|
|
1233
|
+
async isVisibleInternal(selector, options = {}, scope) {
|
|
1234
|
+
try {
|
|
1235
|
+
const customMetadata = { "internal": false, "log": [], "method": "isVisible" };
|
|
1236
|
+
const controller = new import_progress.ProgressController(customMetadata, this);
|
|
1237
|
+
return await controller.run(async (progress) => {
|
|
1238
|
+
progress.log("waiting for " + this._asLocator(selector));
|
|
1239
|
+
const promise = this._retryWithProgressIfNotConnected(progress, selector, options.strict, false, async (handle) => {
|
|
1240
|
+
if (!handle) return false;
|
|
1241
|
+
if (handle.parentNode.constructor.name == "ElementHandle") {
|
|
1242
|
+
return await handle.parentNode.evaluateInUtility(([injected, node, { handle: handle2 }]) => {
|
|
1243
|
+
const state = handle2 ? injected.elementState(handle2, "visible") : {
|
|
1244
|
+
matches: false,
|
|
1245
|
+
received: "error:notconnected"
|
|
1246
|
+
};
|
|
1247
|
+
return state.matches;
|
|
1248
|
+
}, { handle });
|
|
1249
|
+
} else {
|
|
1250
|
+
return await handle.parentNode.evaluate((injected, { handle: handle2 }) => {
|
|
1251
|
+
const state = handle2 ? injected.elementState(handle2, "visible") : {
|
|
1252
|
+
matches: false,
|
|
1253
|
+
received: "error:notconnected"
|
|
1254
|
+
};
|
|
1255
|
+
return state.matches;
|
|
1256
|
+
}, { handle });
|
|
1257
|
+
}
|
|
1258
|
+
}, "returnOnNotResolved");
|
|
1259
|
+
return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
|
|
1260
|
+
}, 1e4) || false;
|
|
1261
|
+
} catch (e) {
|
|
1262
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_selectorParser.isInvalidSelectorError)(e) || (0, import_protocolError.isSessionClosedError)(e)) throw e;
|
|
1263
|
+
return false;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
async isHidden(metadata, selector, options = {}, scope) {
|
|
1267
|
+
return !await this.isVisible(metadata, selector, options, scope);
|
|
1268
|
+
}
|
|
1269
|
+
async isDisabled(metadata, selector, options = {}, scope) {
|
|
1270
|
+
return this._elementState(metadata, selector, "disabled", options, scope);
|
|
1271
|
+
}
|
|
1272
|
+
async isEnabled(metadata, selector, options = {}, scope) {
|
|
1273
|
+
return this._elementState(metadata, selector, "enabled", options, scope);
|
|
1274
|
+
}
|
|
1275
|
+
async isEditable(metadata, selector, options = {}, scope) {
|
|
1276
|
+
return this._elementState(metadata, selector, "editable", options, scope);
|
|
1277
|
+
}
|
|
1278
|
+
async isChecked(metadata, selector, options = {}, scope) {
|
|
1279
|
+
return this._elementState(metadata, selector, "checked", options, scope);
|
|
1280
|
+
}
|
|
1281
|
+
async hover(metadata, selector, options = {}) {
|
|
1282
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1283
|
+
return controller.run(async (progress) => {
|
|
1284
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._hover(progress, options)));
|
|
1285
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
1286
|
+
}
|
|
1287
|
+
async selectOption(metadata, selector, elements, values, options = {}) {
|
|
1288
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1289
|
+
return controller.run(async (progress) => {
|
|
1290
|
+
return await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._selectOption(progress, elements, values, options));
|
|
1291
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
1292
|
+
}
|
|
1293
|
+
async setInputFiles(metadata, selector, params) {
|
|
1294
|
+
const inputFileItems = await (0, import_fileUploadUtils.prepareFilesForUpload)(this, params);
|
|
1295
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1296
|
+
return controller.run(async (progress) => {
|
|
1297
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, params.strict, true, (handle) => handle._setInputFiles(progress, inputFileItems)));
|
|
1298
|
+
}, this._page._timeoutSettings.timeout(params));
|
|
1299
|
+
}
|
|
1300
|
+
async type(metadata, selector, text, options = {}) {
|
|
1301
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1302
|
+
return controller.run(async (progress) => {
|
|
1303
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle) => handle._type(progress, text, options)));
|
|
1304
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
1305
|
+
}
|
|
1306
|
+
async press(metadata, selector, key, options = {}) {
|
|
1307
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1308
|
+
return controller.run(async (progress) => {
|
|
1309
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle) => handle._press(progress, key, options)));
|
|
1310
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
1311
|
+
}
|
|
1312
|
+
async check(metadata, selector, options = {}) {
|
|
1313
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1314
|
+
return controller.run(async (progress) => {
|
|
1315
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._setChecked(progress, true, options)));
|
|
1316
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
1317
|
+
}
|
|
1318
|
+
async uncheck(metadata, selector, options = {}) {
|
|
1319
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1320
|
+
return controller.run(async (progress) => {
|
|
1321
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._setChecked(progress, false, options)));
|
|
1322
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
1323
|
+
}
|
|
1324
|
+
async waitForTimeout(metadata, timeout) {
|
|
1325
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1326
|
+
return controller.run(async () => {
|
|
1327
|
+
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
async ariaSnapshot(metadata, selector, options = {}) {
|
|
1331
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1332
|
+
return controller.run(async (progress) => {
|
|
1333
|
+
return await this._retryWithProgressIfNotConnected(progress, selector, true, true, (handle) => handle.ariaSnapshot(options));
|
|
1334
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
1335
|
+
}
|
|
1336
|
+
async expect(metadata, selector, options) {
|
|
1337
|
+
const result = await this._expectImpl(metadata, selector, options);
|
|
1338
|
+
if (result.matches === options.isNot)
|
|
1339
|
+
metadata.error = { error: { name: "Expect", message: "Expect failed" } };
|
|
1340
|
+
return result;
|
|
1341
|
+
}
|
|
1342
|
+
async _expectImpl(metadata, selector, options) {
|
|
1343
|
+
const lastIntermediateResult = { isSet: false };
|
|
1344
|
+
try {
|
|
1345
|
+
let timeout = this._page._timeoutSettings.timeout(options);
|
|
1346
|
+
const start = timeout > 0 ? (0, import_utils.monotonicTime)() : 0;
|
|
1347
|
+
await new import_progress.ProgressController(metadata, this).run(async (progress) => {
|
|
1348
|
+
progress.log(`${metadata.apiName}${timeout ? ` with timeout ${timeout}ms` : ""}`);
|
|
1349
|
+
progress.log(`waiting for ${this._asLocator(selector)}`);
|
|
1350
|
+
await this._page.performActionPreChecks(progress);
|
|
1351
|
+
}, timeout);
|
|
1352
|
+
try {
|
|
1353
|
+
const resultOneShot = await new import_progress.ProgressController(metadata, this).run(async (progress) => {
|
|
1354
|
+
return await this._expectInternal(progress, selector, options, lastIntermediateResult);
|
|
1355
|
+
});
|
|
1356
|
+
if (resultOneShot.matches !== options.isNot)
|
|
1357
|
+
return resultOneShot;
|
|
1358
|
+
} catch (e) {
|
|
1359
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_selectorParser.isInvalidSelectorError)(e))
|
|
1360
|
+
throw e;
|
|
1361
|
+
}
|
|
1362
|
+
if (timeout > 0) {
|
|
1363
|
+
const elapsed = (0, import_utils.monotonicTime)() - start;
|
|
1364
|
+
timeout -= elapsed;
|
|
1365
|
+
}
|
|
1366
|
+
if (timeout < 0)
|
|
1367
|
+
return { matches: options.isNot, log: (0, import_callLog.compressCallLog)(metadata.log), timedOut: true, received: lastIntermediateResult.received };
|
|
1368
|
+
return await new import_progress.ProgressController(metadata, this).run(async (progress) => {
|
|
1369
|
+
return await this.retryWithProgressAndTimeouts(progress, [100, 250, 500, 1e3], async (continuePolling) => {
|
|
1370
|
+
await this._page.performActionPreChecks(progress);
|
|
1371
|
+
const { matches, received } = await this._expectInternal(progress, selector, options, lastIntermediateResult);
|
|
1372
|
+
if (matches === options.isNot) {
|
|
1373
|
+
return continuePolling;
|
|
1374
|
+
}
|
|
1375
|
+
return { matches, received };
|
|
1376
|
+
});
|
|
1377
|
+
}, timeout);
|
|
1378
|
+
} catch (e) {
|
|
1379
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_selectorParser.isInvalidSelectorError)(e))
|
|
1380
|
+
throw e;
|
|
1381
|
+
const result = { matches: options.isNot, log: (0, import_callLog.compressCallLog)(metadata.log) };
|
|
1382
|
+
if (lastIntermediateResult.isSet)
|
|
1383
|
+
result.received = lastIntermediateResult.received;
|
|
1384
|
+
if (e instanceof import_errors.TimeoutError)
|
|
1385
|
+
result.timedOut = true;
|
|
1386
|
+
return result;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
async _expectInternal(progress, selector, options, lastIntermediateResult) {
|
|
1390
|
+
progress.log("waiting for " + this._asLocator(selector));
|
|
1391
|
+
const isArray = options.expression === "to.have.count" || options.expression.endsWith(".array");
|
|
1392
|
+
const promise = await this._retryWithProgressIfNotConnected(progress, selector, !isArray, false, async (result) => {
|
|
1393
|
+
if (!result) {
|
|
1394
|
+
if (options.expectedNumber === 0)
|
|
1395
|
+
return { matches: true };
|
|
1396
|
+
if (!options.isNot && options.expression === "to.be.hidden")
|
|
1397
|
+
return { matches: true };
|
|
1398
|
+
if (options.isNot && options.expression === "to.be.visible")
|
|
1399
|
+
return { matches: false };
|
|
1400
|
+
if (!options.isNot && options.expression === "to.be.detached")
|
|
1401
|
+
return { matches: true };
|
|
1402
|
+
if (options.isNot && options.expression === "to.be.attached")
|
|
1403
|
+
return { matches: false };
|
|
1404
|
+
if (options.isNot && options.expression === "to.be.in.viewport")
|
|
1405
|
+
return { matches: false };
|
|
1406
|
+
return { matches: options.isNot, missingReceived: true };
|
|
1407
|
+
}
|
|
1408
|
+
const handle = result[0];
|
|
1409
|
+
const handles = result[1];
|
|
1410
|
+
if (handle.parentNode.constructor.name == "ElementHandle") {
|
|
1411
|
+
return await handle.parentNode.evaluateInUtility(async ([injected, node, { handle: handle2, options: options2, handles: handles2 }]) => {
|
|
1412
|
+
return await injected.expect(handle2, options2, handles2);
|
|
1413
|
+
}, { handle, options, handles });
|
|
1414
|
+
} else {
|
|
1415
|
+
return await handle.parentNode.evaluate(async (injected, { handle: handle2, options: options2, handles: handles2 }) => {
|
|
1416
|
+
return await injected.expect(handle2, options2, handles2);
|
|
1417
|
+
}, { handle, options, handles });
|
|
1418
|
+
}
|
|
1419
|
+
}, "returnAll");
|
|
1420
|
+
var matches = false;
|
|
1421
|
+
var received = 0;
|
|
1422
|
+
var missingReceived = null;
|
|
1423
|
+
if (promise) {
|
|
1424
|
+
matches = promise.matches;
|
|
1425
|
+
received = promise.received;
|
|
1426
|
+
missingReceived = promise.missingReceived;
|
|
1427
|
+
} else if (options.expectedNumber === 0) {
|
|
1428
|
+
matches = true;
|
|
1429
|
+
}
|
|
1430
|
+
if (matches === options.isNot) {
|
|
1431
|
+
lastIntermediateResult.received = missingReceived ? "<element(s) not found>" : received;
|
|
1432
|
+
lastIntermediateResult.isSet = true;
|
|
1433
|
+
if (!missingReceived && !Array.isArray(received)) progress.log(' unexpected value "' + renderUnexpectedValue(options.expression, received) + '"');
|
|
1434
|
+
}
|
|
1435
|
+
return {
|
|
1436
|
+
matches,
|
|
1437
|
+
received
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
async _waitForFunctionExpression(metadata, expression, isFunction, arg, options, world = "main") {
|
|
1441
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1442
|
+
if (typeof options.pollingInterval === "number")
|
|
1443
|
+
(0, import_utils.assert)(options.pollingInterval > 0, "Cannot poll with non-positive interval: " + options.pollingInterval);
|
|
1444
|
+
expression = js.normalizeEvaluationExpression(expression, isFunction);
|
|
1445
|
+
return controller.run(async (progress) => {
|
|
1446
|
+
return this.retryWithProgressAndTimeouts(progress, [100], async () => {
|
|
1447
|
+
const context = world === "main" ? await this._mainContext() : await this._utilityContext();
|
|
1448
|
+
const injectedScript = await context.injectedScript();
|
|
1449
|
+
const handle = await injectedScript.evaluateHandle((injected, { expression: expression2, isFunction: isFunction2, polling, arg: arg2 }) => {
|
|
1450
|
+
const predicate = () => {
|
|
1451
|
+
let result2 = globalThis.eval(expression2);
|
|
1452
|
+
if (isFunction2 === true) {
|
|
1453
|
+
result2 = result2(arg2);
|
|
1454
|
+
} else if (isFunction2 === false) {
|
|
1455
|
+
result2 = result2;
|
|
1456
|
+
} else {
|
|
1457
|
+
if (typeof result2 === "function")
|
|
1458
|
+
result2 = result2(arg2);
|
|
1459
|
+
}
|
|
1460
|
+
return result2;
|
|
1461
|
+
};
|
|
1462
|
+
let fulfill;
|
|
1463
|
+
let reject;
|
|
1464
|
+
let aborted = false;
|
|
1465
|
+
const result = new Promise((f, r) => {
|
|
1466
|
+
fulfill = f;
|
|
1467
|
+
reject = r;
|
|
1468
|
+
});
|
|
1469
|
+
const next = () => {
|
|
1470
|
+
if (aborted)
|
|
1471
|
+
return;
|
|
1472
|
+
try {
|
|
1473
|
+
const success = predicate();
|
|
1474
|
+
if (success) {
|
|
1475
|
+
fulfill(success);
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
if (typeof polling !== "number")
|
|
1479
|
+
injected.utils.builtins.requestAnimationFrame(next);
|
|
1480
|
+
else
|
|
1481
|
+
injected.utils.builtins.setTimeout(next, polling);
|
|
1482
|
+
} catch (e) {
|
|
1483
|
+
reject(e);
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1486
|
+
next();
|
|
1487
|
+
return { result, abort: () => aborted = true };
|
|
1488
|
+
}, { expression, isFunction, polling: options.pollingInterval, arg });
|
|
1489
|
+
progress.cleanupWhenAborted(() => handle.evaluate((h) => h.abort()).catch(() => {
|
|
1490
|
+
}));
|
|
1491
|
+
return handle.evaluateHandle((h) => h.result);
|
|
1492
|
+
});
|
|
1493
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
1494
|
+
}
|
|
1495
|
+
async waitForFunctionValueInUtility(progress, pageFunction) {
|
|
1496
|
+
const expression = `() => {
|
|
1497
|
+
const result = (${pageFunction})();
|
|
1498
|
+
if (!result)
|
|
1499
|
+
return result;
|
|
1500
|
+
return JSON.stringify(result);
|
|
1501
|
+
}`;
|
|
1502
|
+
const handle = await this._waitForFunctionExpression((0, import_instrumentation.serverSideCallMetadata)(), expression, true, void 0, { timeout: progress.timeUntilDeadline() }, "utility");
|
|
1503
|
+
return JSON.parse(handle.rawValue());
|
|
1504
|
+
}
|
|
1505
|
+
async title() {
|
|
1506
|
+
const context = await this._utilityContext();
|
|
1507
|
+
return context.evaluate(() => document.title);
|
|
1508
|
+
}
|
|
1509
|
+
async rafrafTimeout(timeout) {
|
|
1510
|
+
if (timeout === 0)
|
|
1511
|
+
return;
|
|
1512
|
+
const context = await this._utilityContext();
|
|
1513
|
+
await Promise.all([
|
|
1514
|
+
// wait for double raf
|
|
1515
|
+
context.evaluate(() => new Promise((x) => {
|
|
1516
|
+
requestAnimationFrame(() => {
|
|
1517
|
+
requestAnimationFrame(x);
|
|
1518
|
+
});
|
|
1519
|
+
})),
|
|
1520
|
+
new Promise((fulfill) => setTimeout(fulfill, timeout))
|
|
1521
|
+
]);
|
|
1522
|
+
}
|
|
1523
|
+
_onDetached() {
|
|
1524
|
+
this._stopNetworkIdleTimer();
|
|
1525
|
+
this._detachedScope.close(new Error("Frame was detached"));
|
|
1526
|
+
for (const data of this._contextData.values()) {
|
|
1527
|
+
if (data.context)
|
|
1528
|
+
data.context.contextDestroyed("Frame was detached");
|
|
1529
|
+
data.contextPromise.resolve({ destroyedReason: "Frame was detached" });
|
|
1530
|
+
}
|
|
1531
|
+
if (this._parentFrame)
|
|
1532
|
+
this._parentFrame._childFrames.delete(this);
|
|
1533
|
+
this._parentFrame = null;
|
|
1534
|
+
}
|
|
1535
|
+
async _callOnElementOnceMatches(metadata, selector, body, taskData, options = {}, scope) {
|
|
1536
|
+
const callbackText = body.toString();
|
|
1537
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1538
|
+
return controller.run(async (progress) => {
|
|
1539
|
+
progress.log("waiting for " + this._asLocator(selector));
|
|
1540
|
+
const promise = this._retryWithProgressIfNotConnected(progress, selector, options.strict, false, async (handle) => {
|
|
1541
|
+
if (handle.parentNode.constructor.name == "ElementHandle") {
|
|
1542
|
+
return await handle.parentNode.evaluateInUtility(([injected, node, { callbackText: callbackText2, handle: handle2, taskData: taskData2 }]) => {
|
|
1543
|
+
const callback = injected.eval(callbackText2);
|
|
1544
|
+
return callback(injected, handle2, taskData2);
|
|
1545
|
+
}, {
|
|
1546
|
+
callbackText,
|
|
1547
|
+
handle,
|
|
1548
|
+
taskData
|
|
1549
|
+
});
|
|
1550
|
+
} else {
|
|
1551
|
+
return await handle.parentNode.evaluate((injected, { callbackText: callbackText2, handle: handle2, taskData: taskData2 }) => {
|
|
1552
|
+
const callback = injected.eval(callbackText2);
|
|
1553
|
+
return callback(injected, handle2, taskData2);
|
|
1554
|
+
}, {
|
|
1555
|
+
callbackText,
|
|
1556
|
+
handle,
|
|
1557
|
+
taskData
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
});
|
|
1561
|
+
return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
|
|
1562
|
+
}, this._page._timeoutSettings.timeout(options));
|
|
1563
|
+
}
|
|
1564
|
+
_setContext(world, context) {
|
|
1565
|
+
const data = this._contextData.get(world);
|
|
1566
|
+
data.context = context;
|
|
1567
|
+
if (context)
|
|
1568
|
+
data.contextPromise.resolve(context);
|
|
1569
|
+
else
|
|
1570
|
+
data.contextPromise = new import_manualPromise.ManualPromise();
|
|
1571
|
+
}
|
|
1572
|
+
_contextCreated(world, context) {
|
|
1573
|
+
const data = this._contextData.get(world);
|
|
1574
|
+
if (data.context) {
|
|
1575
|
+
data.context.contextDestroyed("Execution context was destroyed, most likely because of a navigation");
|
|
1576
|
+
this._setContext(world, null);
|
|
1577
|
+
}
|
|
1578
|
+
this._setContext(world, context);
|
|
1579
|
+
}
|
|
1580
|
+
_contextDestroyed(context) {
|
|
1581
|
+
if (this._detachedScope.isClosed())
|
|
1582
|
+
return;
|
|
1583
|
+
context.contextDestroyed("Execution context was destroyed, most likely because of a navigation");
|
|
1584
|
+
for (const [world, data] of this._contextData) {
|
|
1585
|
+
if (data.context === context)
|
|
1586
|
+
this._setContext(world, null);
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
_startNetworkIdleTimer() {
|
|
1590
|
+
(0, import_utils.assert)(!this._networkIdleTimer);
|
|
1591
|
+
if (this._firedLifecycleEvents.has("networkidle") || this._detachedScope.isClosed())
|
|
1592
|
+
return;
|
|
1593
|
+
this._networkIdleTimer = setTimeout(() => {
|
|
1594
|
+
this._firedNetworkIdleSelf = true;
|
|
1595
|
+
this._page.mainFrame()._recalculateNetworkIdle();
|
|
1596
|
+
}, 500);
|
|
1597
|
+
}
|
|
1598
|
+
_stopNetworkIdleTimer() {
|
|
1599
|
+
if (this._networkIdleTimer)
|
|
1600
|
+
clearTimeout(this._networkIdleTimer);
|
|
1601
|
+
this._networkIdleTimer = void 0;
|
|
1602
|
+
this._firedNetworkIdleSelf = false;
|
|
1603
|
+
}
|
|
1604
|
+
async extendInjectedScript(source, arg) {
|
|
1605
|
+
const context = await this._context("main");
|
|
1606
|
+
const injectedScriptHandle = await context.injectedScript();
|
|
1607
|
+
return injectedScriptHandle.evaluateHandle((injectedScript, { source: source2, arg: arg2 }) => {
|
|
1608
|
+
return injectedScript.extend(source2, arg2);
|
|
1609
|
+
}, { source, arg });
|
|
1610
|
+
}
|
|
1611
|
+
async resetStorageForCurrentOriginBestEffort(newStorage) {
|
|
1612
|
+
const context = await this._utilityContext();
|
|
1613
|
+
await context.evaluate(async ({ ls }) => {
|
|
1614
|
+
sessionStorage.clear();
|
|
1615
|
+
localStorage.clear();
|
|
1616
|
+
for (const entry of ls || [])
|
|
1617
|
+
localStorage[entry.name] = entry.value;
|
|
1618
|
+
const registrations = navigator.serviceWorker ? await navigator.serviceWorker.getRegistrations() : [];
|
|
1619
|
+
await Promise.all(registrations.map(async (r) => {
|
|
1620
|
+
if (!r.installing && !r.waiting && !r.active)
|
|
1621
|
+
r.unregister().catch(() => {
|
|
1622
|
+
});
|
|
1623
|
+
else
|
|
1624
|
+
await r.unregister().catch(() => {
|
|
1625
|
+
});
|
|
1626
|
+
}));
|
|
1627
|
+
for (const db of await indexedDB.databases?.() || []) {
|
|
1628
|
+
if (db.name)
|
|
1629
|
+
indexedDB.deleteDatabase(db.name);
|
|
1630
|
+
}
|
|
1631
|
+
}, { ls: newStorage?.localStorage }).catch(() => {
|
|
1632
|
+
});
|
|
1633
|
+
}
|
|
1634
|
+
_asLocator(selector) {
|
|
1635
|
+
return (0, import_utils.asLocator)(this._page.attribution.playwright.options.sdkLanguage, selector);
|
|
1636
|
+
}
|
|
1637
|
+
async _getFrameMainFrameContextId(client) {
|
|
1638
|
+
try {
|
|
1639
|
+
var globalDocument = await client._sendMayFail("DOM.getFrameOwner", { frameId: this._id });
|
|
1640
|
+
if (globalDocument && globalDocument.nodeId) {
|
|
1641
|
+
var describedNode = await client._sendMayFail("DOM.describeNode", {
|
|
1642
|
+
backendNodeId: globalDocument.backendNodeId
|
|
1643
|
+
});
|
|
1644
|
+
if (describedNode) {
|
|
1645
|
+
var resolvedNode = await client._sendMayFail("DOM.resolveNode", {
|
|
1646
|
+
nodeId: describedNode.node.contentDocument.nodeId
|
|
1647
|
+
});
|
|
1648
|
+
var _executionContextId = parseInt(resolvedNode.object.objectId.split(".")[1], 10);
|
|
1649
|
+
return _executionContextId;
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
} catch (e) {
|
|
1653
|
+
}
|
|
1654
|
+
return 0;
|
|
1655
|
+
}
|
|
1656
|
+
async _customFindElementsByParsed(resolved, client, context, documentScope, progress, parsed) {
|
|
1657
|
+
var parsedEdits = { ...parsed };
|
|
1658
|
+
var currentScopingElements = [documentScope];
|
|
1659
|
+
while (parsed.parts.length > 0) {
|
|
1660
|
+
var part = parsed.parts.shift();
|
|
1661
|
+
parsedEdits.parts = [part];
|
|
1662
|
+
var elements = [];
|
|
1663
|
+
var elementsIndexes = [];
|
|
1664
|
+
if (part.name == "nth") {
|
|
1665
|
+
const partNth = Number(part.body);
|
|
1666
|
+
if (partNth > currentScopingElements.length - 1 || partNth < -(currentScopingElements.length - 1)) {
|
|
1667
|
+
throw new Error("Can't query n-th element");
|
|
1668
|
+
} else {
|
|
1669
|
+
currentScopingElements = [currentScopingElements.at(partNth)];
|
|
1670
|
+
continue;
|
|
1671
|
+
}
|
|
1672
|
+
} else if (part.name == "internal:or") {
|
|
1673
|
+
var orredElements = await this._customFindElementsByParsed(resolved, client, context, documentScope, progress, part.body.parsed);
|
|
1674
|
+
elements = currentScopingElements.concat(orredElements);
|
|
1675
|
+
} else if (part.name == "internal:and") {
|
|
1676
|
+
var andedElements = await this._customFindElementsByParsed(resolved, client, context, documentScope, progress, part.body.parsed);
|
|
1677
|
+
const backendNodeIds = new Set(andedElements.map((item) => item.backendNodeId));
|
|
1678
|
+
elements = currentScopingElements.filter((item) => backendNodeIds.has(item.backendNodeId));
|
|
1679
|
+
} else {
|
|
1680
|
+
for (const scope of currentScopingElements) {
|
|
1681
|
+
let findClosedShadowRoots2 = function(node, results = []) {
|
|
1682
|
+
if (!node || typeof node !== "object") return results;
|
|
1683
|
+
if (node.shadowRoots && Array.isArray(node.shadowRoots)) {
|
|
1684
|
+
for (const shadowRoot2 of node.shadowRoots) {
|
|
1685
|
+
if (shadowRoot2.shadowRootType === "closed" && shadowRoot2.backendNodeId) {
|
|
1686
|
+
results.push(shadowRoot2.backendNodeId);
|
|
1687
|
+
}
|
|
1688
|
+
findClosedShadowRoots2(shadowRoot2, results);
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
if (node.nodeName !== "IFRAME" && node.children && Array.isArray(node.children)) {
|
|
1692
|
+
for (const child of node.children) {
|
|
1693
|
+
findClosedShadowRoots2(child, results);
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
return results;
|
|
1697
|
+
};
|
|
1698
|
+
var findClosedShadowRoots = findClosedShadowRoots2;
|
|
1699
|
+
const describedScope = await client.send("DOM.describeNode", {
|
|
1700
|
+
objectId: scope._objectId,
|
|
1701
|
+
depth: -1,
|
|
1702
|
+
pierce: true
|
|
1703
|
+
});
|
|
1704
|
+
var queryingElements = [];
|
|
1705
|
+
var shadowRootBackendIds = findClosedShadowRoots2(describedScope.node);
|
|
1706
|
+
var shadowRoots = [];
|
|
1707
|
+
for (var shadowRootBackendId of shadowRootBackendIds) {
|
|
1708
|
+
var resolvedShadowRoot = await client.send("DOM.resolveNode", {
|
|
1709
|
+
backendNodeId: shadowRootBackendId,
|
|
1710
|
+
contextId: context.delegate._contextId
|
|
1711
|
+
});
|
|
1712
|
+
shadowRoots.push(new dom.ElementHandle(context, resolvedShadowRoot.object.objectId));
|
|
1713
|
+
}
|
|
1714
|
+
for (var shadowRoot of shadowRoots) {
|
|
1715
|
+
const shadowElements = await shadowRoot.evaluateHandleInUtility(([injected, node, { parsed: parsed2, callId }]) => {
|
|
1716
|
+
const elements2 = injected.querySelectorAll(parsed2, node);
|
|
1717
|
+
if (callId) injected.markTargetElements(new Set(elements2), callId);
|
|
1718
|
+
return elements2;
|
|
1719
|
+
}, {
|
|
1720
|
+
parsed: parsedEdits,
|
|
1721
|
+
callId: progress.metadata.id
|
|
1722
|
+
});
|
|
1723
|
+
const shadowElementsAmount = await shadowElements.getProperty("length");
|
|
1724
|
+
queryingElements.push([shadowElements, shadowElementsAmount, shadowRoot]);
|
|
1725
|
+
}
|
|
1726
|
+
const rootElements = await scope.evaluateHandleInUtility(([injected, node, { parsed: parsed2, callId }]) => {
|
|
1727
|
+
const elements2 = injected.querySelectorAll(parsed2, node);
|
|
1728
|
+
if (callId) injected.markTargetElements(new Set(elements2), callId);
|
|
1729
|
+
return elements2;
|
|
1730
|
+
}, {
|
|
1731
|
+
parsed: parsedEdits,
|
|
1732
|
+
callId: progress.metadata.id
|
|
1733
|
+
});
|
|
1734
|
+
const rootElementsAmount = await rootElements.getProperty("length");
|
|
1735
|
+
queryingElements.push([rootElements, rootElementsAmount, scope]);
|
|
1736
|
+
for (var queryedElement of queryingElements) {
|
|
1737
|
+
var elementsToCheck = queryedElement[0];
|
|
1738
|
+
var elementsAmount = await queryedElement[1].jsonValue();
|
|
1739
|
+
var parentNode = queryedElement[2];
|
|
1740
|
+
for (var i = 0; i < elementsAmount; i++) {
|
|
1741
|
+
if (parentNode.constructor.name == "ElementHandle") {
|
|
1742
|
+
var elementToCheck = await parentNode.evaluateHandleInUtility(([injected, node, { index, elementsToCheck: elementsToCheck2 }]) => {
|
|
1743
|
+
return elementsToCheck2[index];
|
|
1744
|
+
}, { index: i, elementsToCheck });
|
|
1745
|
+
} else {
|
|
1746
|
+
var elementToCheck = await parentNode.evaluateHandle((injected, { index, elementsToCheck: elementsToCheck2 }) => {
|
|
1747
|
+
return elementsToCheck2[index];
|
|
1748
|
+
}, { index: i, elementsToCheck });
|
|
1749
|
+
}
|
|
1750
|
+
elementToCheck.parentNode = parentNode;
|
|
1751
|
+
var resolvedElement = await client.send("DOM.describeNode", {
|
|
1752
|
+
objectId: elementToCheck._objectId,
|
|
1753
|
+
depth: -1
|
|
1754
|
+
});
|
|
1755
|
+
elementToCheck.backendNodeId = resolvedElement.node.backendNodeId;
|
|
1756
|
+
elements.push(elementToCheck);
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
currentScopingElements = [];
|
|
1762
|
+
for (var element of elements) {
|
|
1763
|
+
var elemIndex = element.backendNodeId;
|
|
1764
|
+
if (elementsIndexes.includes(elemIndex)) continue;
|
|
1765
|
+
var elemPos = elementsIndexes.findIndex((index) => index > elemIndex);
|
|
1766
|
+
if (elemPos === -1) {
|
|
1767
|
+
currentScopingElements.push(element);
|
|
1768
|
+
elementsIndexes.push(elemIndex);
|
|
1769
|
+
} else {
|
|
1770
|
+
currentScopingElements.splice(elemPos, 0, element);
|
|
1771
|
+
elementsIndexes.splice(elemPos, 0, elemIndex);
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
return currentScopingElements;
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
class SignalBarrier {
|
|
1779
|
+
constructor(progress) {
|
|
1780
|
+
this._protectCount = 0;
|
|
1781
|
+
this._promise = new import_manualPromise.ManualPromise();
|
|
1782
|
+
this._progress = progress;
|
|
1783
|
+
this.retain();
|
|
1784
|
+
}
|
|
1785
|
+
waitFor() {
|
|
1786
|
+
this.release();
|
|
1787
|
+
return this._promise;
|
|
1788
|
+
}
|
|
1789
|
+
async addFrameNavigation(frame) {
|
|
1790
|
+
if (frame.parentFrame())
|
|
1791
|
+
return;
|
|
1792
|
+
this.retain();
|
|
1793
|
+
const waiter = import_helper.helper.waitForEvent(null, frame, Frame.Events.InternalNavigation, (e) => {
|
|
1794
|
+
if (!e.isPublic)
|
|
1795
|
+
return false;
|
|
1796
|
+
if (!e.error && this._progress)
|
|
1797
|
+
this._progress.log(` navigated to "${frame._url}"`);
|
|
1798
|
+
return true;
|
|
1799
|
+
});
|
|
1800
|
+
await import_utils.LongStandingScope.raceMultiple([
|
|
1801
|
+
frame._page.openScope,
|
|
1802
|
+
frame._detachedScope
|
|
1803
|
+
], waiter.promise).catch(() => {
|
|
1804
|
+
});
|
|
1805
|
+
waiter.dispose();
|
|
1806
|
+
this.release();
|
|
1807
|
+
}
|
|
1808
|
+
retain() {
|
|
1809
|
+
++this._protectCount;
|
|
1810
|
+
}
|
|
1811
|
+
release() {
|
|
1812
|
+
--this._protectCount;
|
|
1813
|
+
if (!this._protectCount)
|
|
1814
|
+
this._promise.resolve();
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
function verifyLifecycle(name, waitUntil) {
|
|
1818
|
+
if (waitUntil === "networkidle0")
|
|
1819
|
+
waitUntil = "networkidle";
|
|
1820
|
+
if (!types.kLifecycleEvents.has(waitUntil))
|
|
1821
|
+
throw new Error(`${name}: expected one of (load|domcontentloaded|networkidle|commit)`);
|
|
1822
|
+
return waitUntil;
|
|
1823
|
+
}
|
|
1824
|
+
function renderUnexpectedValue(expression, received) {
|
|
1825
|
+
if (expression === "to.match.aria")
|
|
1826
|
+
return received ? received.raw : received;
|
|
1827
|
+
return received;
|
|
1828
|
+
}
|
|
1829
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1830
|
+
0 && (module.exports = {
|
|
1831
|
+
Frame,
|
|
1832
|
+
FrameManager,
|
|
1833
|
+
NavigationAbortedError
|
|
1834
|
+
});
|