patchright 1.48.0__py3-none-win32.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 +17 -0
- patchright/_impl/__pyinstaller/hook-playwright.sync_api.py +17 -0
- patchright/_impl/_accessibility.py +50 -0
- patchright/_impl/_api_structures.py +271 -0
- patchright/_impl/_artifact.py +45 -0
- patchright/_impl/_assertions.py +779 -0
- patchright/_impl/_async_base.py +92 -0
- patchright/_impl/_browser.py +243 -0
- patchright/_impl/_browser_context.py +724 -0
- patchright/_impl/_browser_type.py +264 -0
- patchright/_impl/_cdp_session.py +21 -0
- patchright/_impl/_clock.py +57 -0
- patchright/_impl/_connection.py +554 -0
- patchright/_impl/_console_message.py +45 -0
- patchright/_impl/_dialog.py +40 -0
- patchright/_impl/_download.py +50 -0
- patchright/_impl/_driver.py +26 -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 +511 -0
- patchright/_impl/_file_chooser.py +43 -0
- patchright/_impl/_frame.py +755 -0
- patchright/_impl/_glob.py +51 -0
- patchright/_impl/_greenlets.py +39 -0
- patchright/_impl/_har_router.py +99 -0
- patchright/_impl/_helper.py +421 -0
- patchright/_impl/_impl_to_api_mapping.py +123 -0
- patchright/_impl/_input.py +71 -0
- patchright/_impl/_js_handle.py +234 -0
- patchright/_impl/_json_pipe.py +56 -0
- patchright/_impl/_local_utils.py +73 -0
- patchright/_impl/_locator.py +784 -0
- patchright/_impl/_map.py +19 -0
- patchright/_impl/_network.py +934 -0
- patchright/_impl/_object_factory.py +91 -0
- patchright/_impl/_page.py +1446 -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 +103 -0
- patchright/_impl/_transport.py +150 -0
- patchright/_impl/_video.py +57 -0
- patchright/_impl/_waiter.py +142 -0
- patchright/_impl/_web_error.py +22 -0
- patchright/_impl/_writable_stream.py +27 -0
- patchright/_repo_version.py +12 -0
- patchright/async_api/__init__.py +177 -0
- patchright/async_api/_context_manager.py +39 -0
- patchright/async_api/_generated.py +19960 -0
- patchright/driver/LICENSE +2174 -0
- patchright/driver/README.md +1 -0
- patchright/driver/node.exe +0 -0
- patchright/driver/package/README.md +3 -0
- patchright/driver/package/ThirdPartyNotices.txt +1548 -0
- patchright/driver/package/api.json +1 -0
- patchright/driver/package/bin/PrintDeps.exe +0 -0
- patchright/driver/package/bin/README.md +2 -0
- patchright/driver/package/bin/install_media_pack.ps1 +5 -0
- patchright/driver/package/bin/reinstall_chrome_beta_linux.sh +40 -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 +40 -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 +40 -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 +40 -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 +40 -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 +57 -0
- patchright/driver/package/cli.js +18 -0
- patchright/driver/package/index.d.ts +17 -0
- patchright/driver/package/index.js +33 -0
- patchright/driver/package/index.mjs +28 -0
- patchright/driver/package/lib/androidServerImpl.js +69 -0
- patchright/driver/package/lib/browserServerImpl.js +92 -0
- patchright/driver/package/lib/cli/driver.js +95 -0
- patchright/driver/package/lib/cli/program.js +587 -0
- patchright/driver/package/lib/cli/programWithTestStub.js +67 -0
- patchright/driver/package/lib/client/accessibility.js +50 -0
- patchright/driver/package/lib/client/android.js +473 -0
- patchright/driver/package/lib/client/api.js +285 -0
- patchright/driver/package/lib/client/artifact.js +79 -0
- patchright/driver/package/lib/client/browser.js +145 -0
- patchright/driver/package/lib/client/browserContext.js +559 -0
- patchright/driver/package/lib/client/browserType.js +241 -0
- patchright/driver/package/lib/client/cdpSession.js +53 -0
- patchright/driver/package/lib/client/channelOwner.js +235 -0
- patchright/driver/package/lib/client/clientHelper.js +57 -0
- patchright/driver/package/lib/client/clientInstrumentation.js +50 -0
- patchright/driver/package/lib/client/clock.js +68 -0
- patchright/driver/package/lib/client/connection.js +333 -0
- patchright/driver/package/lib/client/consoleMessage.js +55 -0
- patchright/driver/package/lib/client/coverage.js +41 -0
- patchright/driver/package/lib/client/dialog.js +57 -0
- patchright/driver/package/lib/client/download.js +62 -0
- patchright/driver/package/lib/client/electron.js +135 -0
- patchright/driver/package/lib/client/elementHandle.js +321 -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 +94 -0
- patchright/driver/package/lib/client/fetch.js +391 -0
- patchright/driver/package/lib/client/fileChooser.js +45 -0
- patchright/driver/package/lib/client/frame.js +504 -0
- patchright/driver/package/lib/client/harRouter.js +99 -0
- patchright/driver/package/lib/client/input.js +111 -0
- patchright/driver/package/lib/client/jsHandle.js +121 -0
- patchright/driver/package/lib/client/jsonPipe.js +35 -0
- patchright/driver/package/lib/client/localUtils.js +36 -0
- patchright/driver/package/lib/client/locator.js +441 -0
- patchright/driver/package/lib/client/network.js +762 -0
- patchright/driver/package/lib/client/page.js +746 -0
- patchright/driver/package/lib/client/playwright.js +80 -0
- patchright/driver/package/lib/client/selectors.js +67 -0
- patchright/driver/package/lib/client/stream.js +54 -0
- patchright/driver/package/lib/client/tracing.js +134 -0
- patchright/driver/package/lib/client/types.js +24 -0
- patchright/driver/package/lib/client/video.js +51 -0
- patchright/driver/package/lib/client/waiter.js +158 -0
- patchright/driver/package/lib/client/webError.js +37 -0
- patchright/driver/package/lib/client/worker.js +71 -0
- patchright/driver/package/lib/client/writableStream.js +54 -0
- patchright/driver/package/lib/common/socksProxy.js +569 -0
- patchright/driver/package/lib/common/timeoutSettings.js +73 -0
- patchright/driver/package/lib/common/types.js +5 -0
- patchright/driver/package/lib/generated/clockSource.js +7 -0
- patchright/driver/package/lib/generated/consoleApiSource.js +7 -0
- patchright/driver/package/lib/generated/injectedScriptSource.js +7 -0
- patchright/driver/package/lib/generated/pollingRecorderSource.js +7 -0
- patchright/driver/package/lib/generated/utilityScriptSource.js +7 -0
- patchright/driver/package/lib/generated/webSocketMockSource.js +7 -0
- patchright/driver/package/lib/image_tools/colorUtils.js +98 -0
- patchright/driver/package/lib/image_tools/compare.js +108 -0
- patchright/driver/package/lib/image_tools/imageChannel.js +70 -0
- patchright/driver/package/lib/image_tools/stats.js +102 -0
- patchright/driver/package/lib/inProcessFactory.js +54 -0
- patchright/driver/package/lib/inprocess.js +20 -0
- patchright/driver/package/lib/outofprocess.js +67 -0
- patchright/driver/package/lib/protocol/debug.js +27 -0
- patchright/driver/package/lib/protocol/serializers.js +173 -0
- patchright/driver/package/lib/protocol/transport.js +82 -0
- patchright/driver/package/lib/protocol/validator.js +2759 -0
- patchright/driver/package/lib/protocol/validatorPrimitives.js +139 -0
- patchright/driver/package/lib/remote/playwrightConnection.js +274 -0
- patchright/driver/package/lib/remote/playwrightServer.js +110 -0
- patchright/driver/package/lib/server/accessibility.js +62 -0
- patchright/driver/package/lib/server/android/android.js +441 -0
- patchright/driver/package/lib/server/android/backendAdb.js +172 -0
- patchright/driver/package/lib/server/artifact.js +104 -0
- patchright/driver/package/lib/server/bidi/bidiBrowser.js +311 -0
- patchright/driver/package/lib/server/bidi/bidiChromium.js +124 -0
- patchright/driver/package/lib/server/bidi/bidiConnection.js +206 -0
- patchright/driver/package/lib/server/bidi/bidiExecutionContext.js +159 -0
- patchright/driver/package/lib/server/bidi/bidiFirefox.js +104 -0
- patchright/driver/package/lib/server/bidi/bidiInput.js +158 -0
- patchright/driver/package/lib/server/bidi/bidiNetworkManager.js +338 -0
- patchright/driver/package/lib/server/bidi/bidiOverCdp.js +103 -0
- patchright/driver/package/lib/server/bidi/bidiPage.js +529 -0
- patchright/driver/package/lib/server/bidi/bidiPdf.js +140 -0
- patchright/driver/package/lib/server/bidi/third_party/bidiDeserializer.js +93 -0
- patchright/driver/package/lib/server/bidi/third_party/bidiKeyboard.js +238 -0
- patchright/driver/package/lib/server/bidi/third_party/bidiProtocol.js +139 -0
- patchright/driver/package/lib/server/bidi/third_party/bidiSerializer.js +144 -0
- patchright/driver/package/lib/server/bidi/third_party/firefoxPrefs.js +221 -0
- patchright/driver/package/lib/server/browser.js +148 -0
- patchright/driver/package/lib/server/browserContext.js +666 -0
- patchright/driver/package/lib/server/browserType.js +335 -0
- patchright/driver/package/lib/server/chromium/appIcon.png +0 -0
- patchright/driver/package/lib/server/chromium/chromium.js +350 -0
- patchright/driver/package/lib/server/chromium/chromiumSwitches.js +36 -0
- patchright/driver/package/lib/server/chromium/crAccessibility.js +237 -0
- patchright/driver/package/lib/server/chromium/crBrowser.js +522 -0
- patchright/driver/package/lib/server/chromium/crConnection.js +228 -0
- patchright/driver/package/lib/server/chromium/crCoverage.js +246 -0
- patchright/driver/package/lib/server/chromium/crDevTools.js +104 -0
- patchright/driver/package/lib/server/chromium/crDragDrop.js +143 -0
- patchright/driver/package/lib/server/chromium/crExecutionContext.js +149 -0
- patchright/driver/package/lib/server/chromium/crInput.js +171 -0
- patchright/driver/package/lib/server/chromium/crNetworkManager.js +809 -0
- patchright/driver/package/lib/server/chromium/crPage.js +1235 -0
- patchright/driver/package/lib/server/chromium/crPdf.js +153 -0
- patchright/driver/package/lib/server/chromium/crProtocolHelper.js +133 -0
- patchright/driver/package/lib/server/chromium/crServiceWorker.js +111 -0
- patchright/driver/package/lib/server/chromium/defaultFontFamilies.js +145 -0
- patchright/driver/package/lib/server/chromium/videoRecorder.js +155 -0
- patchright/driver/package/lib/server/clock.js +133 -0
- patchright/driver/package/lib/server/codegen/csharp.js +299 -0
- patchright/driver/package/lib/server/codegen/java.js +235 -0
- patchright/driver/package/lib/server/codegen/javascript.js +223 -0
- patchright/driver/package/lib/server/codegen/jsonl.js +47 -0
- patchright/driver/package/lib/server/codegen/language.js +88 -0
- patchright/driver/package/lib/server/codegen/languages.js +30 -0
- patchright/driver/package/lib/server/codegen/python.js +265 -0
- patchright/driver/package/lib/server/codegen/types.js +5 -0
- patchright/driver/package/lib/server/console.js +57 -0
- patchright/driver/package/lib/server/cookieStore.js +185 -0
- patchright/driver/package/lib/server/debugController.js +234 -0
- patchright/driver/package/lib/server/debugger.js +132 -0
- patchright/driver/package/lib/server/deviceDescriptors.js +26 -0
- patchright/driver/package/lib/server/deviceDescriptorsSource.json +1669 -0
- patchright/driver/package/lib/server/dialog.js +71 -0
- patchright/driver/package/lib/server/dispatchers/androidDispatcher.js +193 -0
- patchright/driver/package/lib/server/dispatchers/artifactDispatcher.js +118 -0
- patchright/driver/package/lib/server/dispatchers/browserContextDispatcher.js +368 -0
- patchright/driver/package/lib/server/dispatchers/browserDispatcher.js +170 -0
- patchright/driver/package/lib/server/dispatchers/browserTypeDispatcher.js +55 -0
- patchright/driver/package/lib/server/dispatchers/cdpSessionDispatcher.js +48 -0
- patchright/driver/package/lib/server/dispatchers/debugControllerDispatcher.js +103 -0
- patchright/driver/package/lib/server/dispatchers/dialogDispatcher.js +44 -0
- patchright/driver/package/lib/server/dispatchers/dispatcher.js +395 -0
- patchright/driver/package/lib/server/dispatchers/electronDispatcher.js +93 -0
- patchright/driver/package/lib/server/dispatchers/elementHandlerDispatcher.js +228 -0
- patchright/driver/package/lib/server/dispatchers/frameDispatcher.js +286 -0
- patchright/driver/package/lib/server/dispatchers/jsHandleDispatcher.js +97 -0
- patchright/driver/package/lib/server/dispatchers/jsonPipeDispatcher.js +59 -0
- patchright/driver/package/lib/server/dispatchers/localUtilsDispatcher.js +413 -0
- patchright/driver/package/lib/server/dispatchers/networkDispatchers.js +221 -0
- patchright/driver/package/lib/server/dispatchers/pageDispatcher.js +367 -0
- patchright/driver/package/lib/server/dispatchers/playwrightDispatcher.js +107 -0
- patchright/driver/package/lib/server/dispatchers/selectorsDispatcher.js +36 -0
- patchright/driver/package/lib/server/dispatchers/streamDispatcher.js +62 -0
- patchright/driver/package/lib/server/dispatchers/tracingDispatcher.js +54 -0
- patchright/driver/package/lib/server/dispatchers/webSocketRouteDispatcher.js +189 -0
- patchright/driver/package/lib/server/dispatchers/writableStreamDispatcher.js +58 -0
- patchright/driver/package/lib/server/dom.js +845 -0
- patchright/driver/package/lib/server/download.js +60 -0
- patchright/driver/package/lib/server/electron/electron.js +296 -0
- patchright/driver/package/lib/server/electron/loader.js +57 -0
- patchright/driver/package/lib/server/errors.js +68 -0
- patchright/driver/package/lib/server/fetch.js +656 -0
- patchright/driver/package/lib/server/fileChooser.js +42 -0
- patchright/driver/package/lib/server/fileUploadUtils.js +75 -0
- patchright/driver/package/lib/server/firefox/ffAccessibility.js +216 -0
- patchright/driver/package/lib/server/firefox/ffBrowser.js +460 -0
- patchright/driver/package/lib/server/firefox/ffConnection.js +168 -0
- patchright/driver/package/lib/server/firefox/ffExecutionContext.js +135 -0
- patchright/driver/package/lib/server/firefox/ffInput.js +150 -0
- patchright/driver/package/lib/server/firefox/ffNetworkManager.js +233 -0
- patchright/driver/package/lib/server/firefox/ffPage.js +559 -0
- patchright/driver/package/lib/server/firefox/firefox.js +99 -0
- patchright/driver/package/lib/server/formData.js +75 -0
- patchright/driver/package/lib/server/frameSelectors.js +171 -0
- patchright/driver/package/lib/server/frames.js +1808 -0
- patchright/driver/package/lib/server/har/harRecorder.js +139 -0
- patchright/driver/package/lib/server/har/harTracer.js +542 -0
- patchright/driver/package/lib/server/helper.js +103 -0
- patchright/driver/package/lib/server/index.js +114 -0
- patchright/driver/package/lib/server/input.js +310 -0
- patchright/driver/package/lib/server/instrumentation.js +70 -0
- patchright/driver/package/lib/server/isomorphic/utilityScriptSerializers.js +226 -0
- patchright/driver/package/lib/server/javascript.js +299 -0
- patchright/driver/package/lib/server/launchApp.js +91 -0
- patchright/driver/package/lib/server/macEditingCommands.js +139 -0
- patchright/driver/package/lib/server/network.js +617 -0
- patchright/driver/package/lib/server/page.js +819 -0
- patchright/driver/package/lib/server/pipeTransport.js +85 -0
- patchright/driver/package/lib/server/playwright.js +88 -0
- patchright/driver/package/lib/server/progress.js +102 -0
- patchright/driver/package/lib/server/protocolError.js +49 -0
- patchright/driver/package/lib/server/recorder/contextRecorder.js +299 -0
- patchright/driver/package/lib/server/recorder/recorderApp.js +196 -0
- patchright/driver/package/lib/server/recorder/recorderCollection.js +116 -0
- patchright/driver/package/lib/server/recorder/recorderFrontend.js +5 -0
- patchright/driver/package/lib/server/recorder/recorderInTraceViewer.js +144 -0
- patchright/driver/package/lib/server/recorder/recorderRunner.js +155 -0
- patchright/driver/package/lib/server/recorder/recorderUtils.js +112 -0
- patchright/driver/package/lib/server/recorder/throttledFile.js +46 -0
- patchright/driver/package/lib/server/recorder.js +327 -0
- patchright/driver/package/lib/server/registry/browserFetcher.js +168 -0
- patchright/driver/package/lib/server/registry/dependencies.js +322 -0
- patchright/driver/package/lib/server/registry/index.js +1005 -0
- patchright/driver/package/lib/server/registry/nativeDeps.js +490 -0
- patchright/driver/package/lib/server/registry/oopDownloadBrowserMain.js +138 -0
- patchright/driver/package/lib/server/screenshotter.js +348 -0
- patchright/driver/package/lib/server/selectors.js +73 -0
- patchright/driver/package/lib/server/socksClientCertificatesInterceptor.js +340 -0
- patchright/driver/package/lib/server/socksInterceptor.js +100 -0
- patchright/driver/package/lib/server/trace/recorder/snapshotter.js +172 -0
- patchright/driver/package/lib/server/trace/recorder/snapshotterInjected.js +493 -0
- patchright/driver/package/lib/server/trace/recorder/tracing.js +542 -0
- patchright/driver/package/lib/server/trace/test/inMemorySnapshotter.js +93 -0
- patchright/driver/package/lib/server/trace/viewer/traceViewer.js +213 -0
- patchright/driver/package/lib/server/transport.js +191 -0
- patchright/driver/package/lib/server/types.js +24 -0
- patchright/driver/package/lib/server/usKeyboardLayout.js +555 -0
- patchright/driver/package/lib/server/webkit/webkit.js +87 -0
- patchright/driver/package/lib/server/webkit/wkAccessibility.js +194 -0
- patchright/driver/package/lib/server/webkit/wkBrowser.js +329 -0
- patchright/driver/package/lib/server/webkit/wkConnection.js +173 -0
- patchright/driver/package/lib/server/webkit/wkExecutionContext.js +143 -0
- patchright/driver/package/lib/server/webkit/wkInput.js +169 -0
- patchright/driver/package/lib/server/webkit/wkInterceptableRequest.js +162 -0
- patchright/driver/package/lib/server/webkit/wkPage.js +1219 -0
- patchright/driver/package/lib/server/webkit/wkProvisionalPage.js +94 -0
- patchright/driver/package/lib/server/webkit/wkWorkers.js +104 -0
- patchright/driver/package/lib/third_party/diff_match_patch.js +2222 -0
- patchright/driver/package/lib/third_party/pixelmatch.js +255 -0
- patchright/driver/package/lib/utils/ascii.js +31 -0
- patchright/driver/package/lib/utils/comparators.js +171 -0
- patchright/driver/package/lib/utils/crypto.js +174 -0
- patchright/driver/package/lib/utils/debug.js +46 -0
- patchright/driver/package/lib/utils/debugLogger.js +91 -0
- patchright/driver/package/lib/utils/env.js +49 -0
- patchright/driver/package/lib/utils/eventsHelper.js +38 -0
- patchright/driver/package/lib/utils/expectUtils.js +33 -0
- patchright/driver/package/lib/utils/fileUtils.js +205 -0
- patchright/driver/package/lib/utils/happy-eyeballs.js +194 -0
- patchright/driver/package/lib/utils/headers.js +52 -0
- patchright/driver/package/lib/utils/hostPlatform.js +133 -0
- patchright/driver/package/lib/utils/httpServer.js +237 -0
- patchright/driver/package/lib/utils/index.js +368 -0
- patchright/driver/package/lib/utils/isomorphic/cssParser.js +250 -0
- patchright/driver/package/lib/utils/isomorphic/cssTokenizer.js +979 -0
- patchright/driver/package/lib/utils/isomorphic/locatorGenerators.js +642 -0
- patchright/driver/package/lib/utils/isomorphic/locatorParser.js +179 -0
- patchright/driver/package/lib/utils/isomorphic/locatorUtils.js +62 -0
- patchright/driver/package/lib/utils/isomorphic/mimeType.js +29 -0
- patchright/driver/package/lib/utils/isomorphic/recorderUtils.js +195 -0
- patchright/driver/package/lib/utils/isomorphic/selectorParser.js +397 -0
- patchright/driver/package/lib/utils/isomorphic/stringUtils.js +139 -0
- patchright/driver/package/lib/utils/isomorphic/traceUtils.js +39 -0
- patchright/driver/package/lib/utils/isomorphic/urlMatch.js +120 -0
- patchright/driver/package/lib/utils/linuxUtils.js +78 -0
- patchright/driver/package/lib/utils/manualPromise.js +109 -0
- patchright/driver/package/lib/utils/multimap.js +75 -0
- patchright/driver/package/lib/utils/network.js +160 -0
- patchright/driver/package/lib/utils/processLauncher.js +248 -0
- patchright/driver/package/lib/utils/profiler.js +53 -0
- patchright/driver/package/lib/utils/rtti.js +44 -0
- patchright/driver/package/lib/utils/semaphore.js +51 -0
- patchright/driver/package/lib/utils/spawnAsync.js +45 -0
- patchright/driver/package/lib/utils/stackTrace.js +121 -0
- patchright/driver/package/lib/utils/task.js +58 -0
- patchright/driver/package/lib/utils/time.js +37 -0
- patchright/driver/package/lib/utils/timeoutRunner.js +66 -0
- patchright/driver/package/lib/utils/traceUtils.js +44 -0
- patchright/driver/package/lib/utils/userAgent.js +105 -0
- patchright/driver/package/lib/utils/wsServer.js +127 -0
- patchright/driver/package/lib/utils/zipFile.js +75 -0
- patchright/driver/package/lib/utils/zones.js +62 -0
- patchright/driver/package/lib/utilsBundle.js +82 -0
- patchright/driver/package/lib/utilsBundleImpl/index.js +53 -0
- patchright/driver/package/lib/utilsBundleImpl/xdg-open +1066 -0
- patchright/driver/package/lib/vite/htmlReport/index.html +66 -0
- patchright/driver/package/lib/vite/recorder/assets/codeMirrorModule-d0KhC1qL.js +24 -0
- patchright/driver/package/lib/vite/recorder/assets/codeMirrorModule-ez37Vkbh.css +1 -0
- patchright/driver/package/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
- patchright/driver/package/lib/vite/recorder/assets/index-BW-aOBcL.css +1 -0
- patchright/driver/package/lib/vite/recorder/assets/index-Bxxcmxlu.js +42 -0
- patchright/driver/package/lib/vite/recorder/index.html +29 -0
- patchright/driver/package/lib/vite/recorder/playwright-logo.svg +9 -0
- patchright/driver/package/lib/vite/traceViewer/assets/codeMirrorModule-CZTtn9l8.js +24 -0
- patchright/driver/package/lib/vite/traceViewer/assets/inspectorTab-DTusvprx.js +64 -0
- patchright/driver/package/lib/vite/traceViewer/assets/testServerConnection-DeE2kSzz.js +1 -0
- patchright/driver/package/lib/vite/traceViewer/assets/workbench-DIEjrm3Z.js +9 -0
- patchright/driver/package/lib/vite/traceViewer/assets/xtermModule-BeNbaIVa.js +9 -0
- patchright/driver/package/lib/vite/traceViewer/codeMirrorModule.ez37Vkbh.css +1 -0
- patchright/driver/package/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
- patchright/driver/package/lib/vite/traceViewer/embedded.Do_J5Hgs.js +2 -0
- patchright/driver/package/lib/vite/traceViewer/embedded.html +18 -0
- patchright/driver/package/lib/vite/traceViewer/embedded.w7WN2u1R.css +1 -0
- patchright/driver/package/lib/vite/traceViewer/index.B21BXreT.js +2 -0
- patchright/driver/package/lib/vite/traceViewer/index.CrbWWHbf.css +1 -0
- patchright/driver/package/lib/vite/traceViewer/index.html +29 -0
- patchright/driver/package/lib/vite/traceViewer/inspectorTab.DLjBDrQR.css +1 -0
- patchright/driver/package/lib/vite/traceViewer/playwright-logo.svg +9 -0
- patchright/driver/package/lib/vite/traceViewer/recorder.B_SY1GJM.css +0 -0
- patchright/driver/package/lib/vite/traceViewer/recorder.Bfh_9UGt.js +2 -0
- patchright/driver/package/lib/vite/traceViewer/recorder.html +17 -0
- patchright/driver/package/lib/vite/traceViewer/snapshot.html +21 -0
- patchright/driver/package/lib/vite/traceViewer/sw.bundle.js +3 -0
- patchright/driver/package/lib/vite/traceViewer/uiMode.CAYqod-m.css +1 -0
- patchright/driver/package/lib/vite/traceViewer/uiMode.DloKQa-h.js +5 -0
- patchright/driver/package/lib/vite/traceViewer/uiMode.html +20 -0
- patchright/driver/package/lib/vite/traceViewer/workbench.D3JVcA9K.css +1 -0
- patchright/driver/package/lib/vite/traceViewer/xtermModule.DSXBckUd.css +32 -0
- patchright/driver/package/lib/zipBundle.js +25 -0
- patchright/driver/package/lib/zipBundleImpl.js +5 -0
- patchright/driver/package/package.json +44 -0
- patchright/driver/package/protocol.yml +3720 -0
- patchright/driver/package/types/protocol.d.ts +21571 -0
- patchright/driver/package/types/structs.d.ts +45 -0
- patchright/driver/package/types/types.d.ts +22519 -0
- patchright/py.typed +0 -0
- patchright/sync_api/__init__.py +177 -0
- patchright/sync_api/_context_manager.py +74 -0
- patchright/sync_api/_generated.py +20155 -0
- patchright-1.48.0.dist-info/LICENSE +202 -0
- patchright-1.48.0.dist-info/METADATA +83 -0
- patchright-1.48.0.dist-info/RECORD +406 -0
- patchright-1.48.0.dist-info/WHEEL +5 -0
- patchright-1.48.0.dist-info/entry_points.txt +5 -0
- patchright-1.48.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import collections.abc
|
|
3
|
+
import contextvars
|
|
4
|
+
import datetime
|
|
5
|
+
import inspect
|
|
6
|
+
import sys
|
|
7
|
+
import traceback
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import (
|
|
10
|
+
TYPE_CHECKING,
|
|
11
|
+
Any,
|
|
12
|
+
Callable,
|
|
13
|
+
Dict,
|
|
14
|
+
List,
|
|
15
|
+
Mapping,
|
|
16
|
+
Optional,
|
|
17
|
+
TypedDict,
|
|
18
|
+
Union,
|
|
19
|
+
cast,
|
|
20
|
+
)
|
|
21
|
+
from pyee import EventEmitter
|
|
22
|
+
from pyee.asyncio import AsyncIOEventEmitter
|
|
23
|
+
import patchright
|
|
24
|
+
from patchright._impl._errors import TargetClosedError, rewrite_error
|
|
25
|
+
from patchright._impl._greenlets import EventGreenlet
|
|
26
|
+
from patchright._impl._helper import Error, ParsedMessagePayload, parse_error
|
|
27
|
+
from patchright._impl._transport import Transport
|
|
28
|
+
|
|
29
|
+
if TYPE_CHECKING:
|
|
30
|
+
from patchright._impl._local_utils import LocalUtils
|
|
31
|
+
from patchright._impl._playwright import Playwright
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Channel(AsyncIOEventEmitter):
|
|
35
|
+
|
|
36
|
+
def __init__(self, connection: "Connection", object: "ChannelOwner") -> None:
|
|
37
|
+
super().__init__()
|
|
38
|
+
self._connection = connection
|
|
39
|
+
self._guid = object._guid
|
|
40
|
+
self._object = object
|
|
41
|
+
self.on("error", lambda exc: self._connection._on_event_listener_error(exc))
|
|
42
|
+
|
|
43
|
+
async def send(self, method: str, params: Dict = None) -> Any:
|
|
44
|
+
return await self._connection.wrap_api_call(
|
|
45
|
+
lambda: self.inner_send(method, params, False)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
async def send_return_as_dict(self, method: str, params: Dict = None) -> Any:
|
|
49
|
+
return await self._connection.wrap_api_call(
|
|
50
|
+
lambda: self.inner_send(method, params, True)
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
def send_no_reply(self, method: str, params: Dict = None) -> None:
|
|
54
|
+
self._connection.wrap_api_call_sync(
|
|
55
|
+
lambda: self._connection._send_message_to_server(
|
|
56
|
+
self._object, method, {} if params is None else params, True
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
async def inner_send(
|
|
61
|
+
self, method: str, params: Optional[Dict], return_as_dict: bool
|
|
62
|
+
) -> Any:
|
|
63
|
+
if params is None:
|
|
64
|
+
params = {}
|
|
65
|
+
if self._connection._error:
|
|
66
|
+
error = self._connection._error
|
|
67
|
+
self._connection._error = None
|
|
68
|
+
raise error
|
|
69
|
+
callback = self._connection._send_message_to_server(
|
|
70
|
+
self._object, method, _filter_none(params)
|
|
71
|
+
)
|
|
72
|
+
done, _ = await asyncio.wait(
|
|
73
|
+
{self._connection._transport.on_error_future, callback.future},
|
|
74
|
+
return_when=asyncio.FIRST_COMPLETED,
|
|
75
|
+
)
|
|
76
|
+
if not callback.future.done():
|
|
77
|
+
callback.future.cancel()
|
|
78
|
+
result = next(iter(done)).result()
|
|
79
|
+
if not result:
|
|
80
|
+
return None
|
|
81
|
+
assert isinstance(result, dict)
|
|
82
|
+
if return_as_dict:
|
|
83
|
+
return result
|
|
84
|
+
if len(result) == 0:
|
|
85
|
+
return None
|
|
86
|
+
assert len(result) == 1
|
|
87
|
+
key = next(iter(result))
|
|
88
|
+
return result[key]
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class ChannelOwner(AsyncIOEventEmitter):
|
|
92
|
+
|
|
93
|
+
def __init__(
|
|
94
|
+
self,
|
|
95
|
+
parent: Union["ChannelOwner", "Connection"],
|
|
96
|
+
type: str,
|
|
97
|
+
guid: str,
|
|
98
|
+
initializer: Dict,
|
|
99
|
+
) -> None:
|
|
100
|
+
super().__init__(loop=parent._loop)
|
|
101
|
+
self._loop: asyncio.AbstractEventLoop = parent._loop
|
|
102
|
+
self._dispatcher_fiber: Any = parent._dispatcher_fiber
|
|
103
|
+
self._type = type
|
|
104
|
+
self._guid: str = guid
|
|
105
|
+
self._connection: Connection = (
|
|
106
|
+
parent._connection if isinstance(parent, ChannelOwner) else parent
|
|
107
|
+
)
|
|
108
|
+
self._parent: Optional[ChannelOwner] = (
|
|
109
|
+
parent if isinstance(parent, ChannelOwner) else None
|
|
110
|
+
)
|
|
111
|
+
self._objects: Dict[str, "ChannelOwner"] = {}
|
|
112
|
+
self._channel: Channel = Channel(self._connection, self)
|
|
113
|
+
self._initializer = initializer
|
|
114
|
+
self._was_collected = False
|
|
115
|
+
self._is_internal_type = False
|
|
116
|
+
self._connection._objects[guid] = self
|
|
117
|
+
if self._parent:
|
|
118
|
+
self._parent._objects[guid] = self
|
|
119
|
+
self._event_to_subscription_mapping: Dict[str, str] = {}
|
|
120
|
+
|
|
121
|
+
def _dispose(self, reason: Optional[str]) -> None:
|
|
122
|
+
if self._parent:
|
|
123
|
+
del self._parent._objects[self._guid]
|
|
124
|
+
del self._connection._objects[self._guid]
|
|
125
|
+
self._was_collected = reason == "gc"
|
|
126
|
+
for object in list(self._objects.values()):
|
|
127
|
+
object._dispose(reason)
|
|
128
|
+
self._objects.clear()
|
|
129
|
+
|
|
130
|
+
def _adopt(self, child: "ChannelOwner") -> None:
|
|
131
|
+
del cast("ChannelOwner", child._parent)._objects[child._guid]
|
|
132
|
+
self._objects[child._guid] = child
|
|
133
|
+
child._parent = self
|
|
134
|
+
|
|
135
|
+
def mark_as_internal_type(self) -> None:
|
|
136
|
+
self._is_internal_type = True
|
|
137
|
+
|
|
138
|
+
def _set_event_to_subscription_mapping(self, mapping: Dict[str, str]) -> None:
|
|
139
|
+
self._event_to_subscription_mapping = mapping
|
|
140
|
+
|
|
141
|
+
def _update_subscription(self, event: str, enabled: bool) -> None:
|
|
142
|
+
protocol_event = self._event_to_subscription_mapping.get(event)
|
|
143
|
+
if protocol_event:
|
|
144
|
+
self._connection.wrap_api_call_sync(
|
|
145
|
+
lambda: self._channel.send_no_reply(
|
|
146
|
+
"updateSubscription", {"event": protocol_event, "enabled": enabled}
|
|
147
|
+
),
|
|
148
|
+
True,
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
def _add_event_handler(self, event: str, k: Any, v: Any) -> None:
|
|
152
|
+
if not self.listeners(event):
|
|
153
|
+
self._update_subscription(event, True)
|
|
154
|
+
super()._add_event_handler(event, k, v)
|
|
155
|
+
|
|
156
|
+
def remove_listener(self, event: str, f: Any) -> None:
|
|
157
|
+
super().remove_listener(event, f)
|
|
158
|
+
if not self.listeners(event):
|
|
159
|
+
self._update_subscription(event, False)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class ProtocolCallback:
|
|
163
|
+
|
|
164
|
+
def __init__(self, loop: asyncio.AbstractEventLoop) -> None:
|
|
165
|
+
self.stack_trace: traceback.StackSummary
|
|
166
|
+
self.no_reply: bool
|
|
167
|
+
self.future = loop.create_future()
|
|
168
|
+
current_task = asyncio.current_task()
|
|
169
|
+
|
|
170
|
+
def cb(task: asyncio.Task) -> None:
|
|
171
|
+
if current_task:
|
|
172
|
+
current_task.remove_done_callback(cb)
|
|
173
|
+
if task.cancelled():
|
|
174
|
+
self.future.cancel()
|
|
175
|
+
|
|
176
|
+
if current_task:
|
|
177
|
+
current_task.add_done_callback(cb)
|
|
178
|
+
self.future.add_done_callback(
|
|
179
|
+
lambda _: (
|
|
180
|
+
current_task.remove_done_callback(cb) if current_task else None
|
|
181
|
+
)
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
class RootChannelOwner(ChannelOwner):
|
|
186
|
+
|
|
187
|
+
def __init__(self, connection: "Connection") -> None:
|
|
188
|
+
super().__init__(connection, "Root", "", {})
|
|
189
|
+
|
|
190
|
+
async def initialize(self) -> "Playwright":
|
|
191
|
+
return from_channel(
|
|
192
|
+
await self._channel.send("initialize", {"sdkLanguage": "python"})
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
class Connection(EventEmitter):
|
|
197
|
+
|
|
198
|
+
def __init__(
|
|
199
|
+
self,
|
|
200
|
+
dispatcher_fiber: Any,
|
|
201
|
+
object_factory: Callable[[ChannelOwner, str, str, Dict], ChannelOwner],
|
|
202
|
+
transport: Transport,
|
|
203
|
+
loop: asyncio.AbstractEventLoop,
|
|
204
|
+
local_utils: Optional["LocalUtils"] = None,
|
|
205
|
+
) -> None:
|
|
206
|
+
super().__init__()
|
|
207
|
+
self._dispatcher_fiber = dispatcher_fiber
|
|
208
|
+
self._transport = transport
|
|
209
|
+
self._transport.on_message = lambda msg: self.dispatch(msg)
|
|
210
|
+
self._waiting_for_object: Dict[str, Callable[[ChannelOwner], None]] = {}
|
|
211
|
+
self._last_id = 0
|
|
212
|
+
self._objects: Dict[str, ChannelOwner] = {}
|
|
213
|
+
self._callbacks: Dict[int, ProtocolCallback] = {}
|
|
214
|
+
self._object_factory = object_factory
|
|
215
|
+
self._is_sync = False
|
|
216
|
+
self._child_ws_connections: List["Connection"] = []
|
|
217
|
+
self._loop = loop
|
|
218
|
+
self.playwright_future: asyncio.Future["Playwright"] = loop.create_future()
|
|
219
|
+
self._error: Optional[BaseException] = None
|
|
220
|
+
self.is_remote = False
|
|
221
|
+
self._init_task: Optional[asyncio.Task] = None
|
|
222
|
+
self._api_zone: contextvars.ContextVar[Optional[ParsedStackTrace]] = (
|
|
223
|
+
contextvars.ContextVar("ApiZone", default=None)
|
|
224
|
+
)
|
|
225
|
+
self._local_utils: Optional["LocalUtils"] = local_utils
|
|
226
|
+
self._tracing_count = 0
|
|
227
|
+
self._closed_error: Optional[Exception] = None
|
|
228
|
+
|
|
229
|
+
@property
|
|
230
|
+
def local_utils(self) -> "LocalUtils":
|
|
231
|
+
assert self._local_utils
|
|
232
|
+
return self._local_utils
|
|
233
|
+
|
|
234
|
+
def mark_as_remote(self) -> None:
|
|
235
|
+
self.is_remote = True
|
|
236
|
+
|
|
237
|
+
async def run_as_sync(self) -> None:
|
|
238
|
+
self._is_sync = True
|
|
239
|
+
await self.run()
|
|
240
|
+
|
|
241
|
+
async def run(self) -> None:
|
|
242
|
+
self._loop = asyncio.get_running_loop()
|
|
243
|
+
self._root_object = RootChannelOwner(self)
|
|
244
|
+
|
|
245
|
+
async def init() -> None:
|
|
246
|
+
self.playwright_future.set_result(await self._root_object.initialize())
|
|
247
|
+
|
|
248
|
+
await self._transport.connect()
|
|
249
|
+
self._init_task = self._loop.create_task(init())
|
|
250
|
+
await self._transport.run()
|
|
251
|
+
|
|
252
|
+
def stop_sync(self) -> None:
|
|
253
|
+
self._transport.request_stop()
|
|
254
|
+
self._dispatcher_fiber.switch()
|
|
255
|
+
self._loop.run_until_complete(self._transport.wait_until_stopped())
|
|
256
|
+
self.cleanup()
|
|
257
|
+
|
|
258
|
+
async def stop_async(self) -> None:
|
|
259
|
+
self._transport.request_stop()
|
|
260
|
+
await self._transport.wait_until_stopped()
|
|
261
|
+
self.cleanup()
|
|
262
|
+
|
|
263
|
+
def cleanup(self, cause: str = None) -> None:
|
|
264
|
+
self._closed_error = TargetClosedError(cause) if cause else TargetClosedError()
|
|
265
|
+
if self._init_task and (not self._init_task.done()):
|
|
266
|
+
self._init_task.cancel()
|
|
267
|
+
for ws_connection in self._child_ws_connections:
|
|
268
|
+
ws_connection._transport.dispose()
|
|
269
|
+
for callback in self._callbacks.values():
|
|
270
|
+
if callback.no_reply:
|
|
271
|
+
continue
|
|
272
|
+
if callback.future.cancelled():
|
|
273
|
+
continue
|
|
274
|
+
callback.future.set_exception(self._closed_error)
|
|
275
|
+
self._callbacks.clear()
|
|
276
|
+
self.emit("close")
|
|
277
|
+
|
|
278
|
+
def call_on_object_with_known_name(
|
|
279
|
+
self, guid: str, callback: Callable[[ChannelOwner], None]
|
|
280
|
+
) -> None:
|
|
281
|
+
self._waiting_for_object[guid] = callback
|
|
282
|
+
|
|
283
|
+
def set_is_tracing(self, is_tracing: bool) -> None:
|
|
284
|
+
if is_tracing:
|
|
285
|
+
self._tracing_count += 1
|
|
286
|
+
else:
|
|
287
|
+
self._tracing_count -= 1
|
|
288
|
+
|
|
289
|
+
def _send_message_to_server(
|
|
290
|
+
self, object: ChannelOwner, method: str, params: Dict, no_reply: bool = False
|
|
291
|
+
) -> ProtocolCallback:
|
|
292
|
+
if self._closed_error:
|
|
293
|
+
raise self._closed_error
|
|
294
|
+
if object._was_collected:
|
|
295
|
+
raise Error(
|
|
296
|
+
"The object has been collected to prevent unbounded heap growth."
|
|
297
|
+
)
|
|
298
|
+
self._last_id += 1
|
|
299
|
+
id = self._last_id
|
|
300
|
+
callback = ProtocolCallback(self._loop)
|
|
301
|
+
task = asyncio.current_task(self._loop)
|
|
302
|
+
callback.stack_trace = cast(
|
|
303
|
+
traceback.StackSummary,
|
|
304
|
+
getattr(task, "__pw_stack_trace__", traceback.extract_stack()),
|
|
305
|
+
)
|
|
306
|
+
callback.no_reply = no_reply
|
|
307
|
+
self._callbacks[id] = callback
|
|
308
|
+
stack_trace_information = cast(ParsedStackTrace, self._api_zone.get())
|
|
309
|
+
frames = stack_trace_information.get("frames", [])
|
|
310
|
+
location = (
|
|
311
|
+
{
|
|
312
|
+
"file": frames[0]["file"],
|
|
313
|
+
"line": frames[0]["line"],
|
|
314
|
+
"column": frames[0]["column"],
|
|
315
|
+
}
|
|
316
|
+
if frames
|
|
317
|
+
else None
|
|
318
|
+
)
|
|
319
|
+
metadata = {
|
|
320
|
+
"wallTime": int(datetime.datetime.now().timestamp() * 1000),
|
|
321
|
+
"apiName": stack_trace_information["apiName"],
|
|
322
|
+
"internal": not stack_trace_information["apiName"],
|
|
323
|
+
}
|
|
324
|
+
if location:
|
|
325
|
+
metadata["location"] = location
|
|
326
|
+
message = {
|
|
327
|
+
"id": id,
|
|
328
|
+
"guid": object._guid,
|
|
329
|
+
"method": method,
|
|
330
|
+
"params": self._replace_channels_with_guids(params),
|
|
331
|
+
"metadata": metadata,
|
|
332
|
+
}
|
|
333
|
+
if self._tracing_count > 0 and frames and (not object._is_internal_type):
|
|
334
|
+
self.local_utils.add_stack_to_tracing_no_reply(id, frames)
|
|
335
|
+
self._transport.send(message)
|
|
336
|
+
self._callbacks[id] = callback
|
|
337
|
+
return callback
|
|
338
|
+
|
|
339
|
+
def dispatch(self, msg: ParsedMessagePayload) -> None:
|
|
340
|
+
if self._closed_error:
|
|
341
|
+
return
|
|
342
|
+
id = msg.get("id")
|
|
343
|
+
if id:
|
|
344
|
+
callback = self._callbacks.pop(id)
|
|
345
|
+
if callback.future.cancelled():
|
|
346
|
+
return
|
|
347
|
+
if callback.no_reply:
|
|
348
|
+
return
|
|
349
|
+
error = msg.get("error")
|
|
350
|
+
if error and (not msg.get("result")):
|
|
351
|
+
parsed_error = parse_error(
|
|
352
|
+
error["error"], format_call_log(msg.get("log"))
|
|
353
|
+
)
|
|
354
|
+
parsed_error._stack = "".join(
|
|
355
|
+
traceback.format_list(callback.stack_trace)[-10:]
|
|
356
|
+
)
|
|
357
|
+
callback.future.set_exception(parsed_error)
|
|
358
|
+
else:
|
|
359
|
+
result = self._replace_guids_with_channels(msg.get("result"))
|
|
360
|
+
callback.future.set_result(result)
|
|
361
|
+
return
|
|
362
|
+
guid = msg["guid"]
|
|
363
|
+
method = msg["method"]
|
|
364
|
+
params = msg.get("params")
|
|
365
|
+
if method == "__create__":
|
|
366
|
+
assert params
|
|
367
|
+
parent = self._objects[guid]
|
|
368
|
+
self._create_remote_object(
|
|
369
|
+
parent, params["type"], params["guid"], params["initializer"]
|
|
370
|
+
)
|
|
371
|
+
return
|
|
372
|
+
object = self._objects.get(guid)
|
|
373
|
+
if not object:
|
|
374
|
+
raise Exception(f'Cannot find object to "{method}": {guid}')
|
|
375
|
+
if method == "__adopt__":
|
|
376
|
+
child_guid = cast(Dict[str, str], params)["guid"]
|
|
377
|
+
child = self._objects.get(child_guid)
|
|
378
|
+
if not child:
|
|
379
|
+
raise Exception(f"Unknown new child: {child_guid}")
|
|
380
|
+
object._adopt(child)
|
|
381
|
+
return
|
|
382
|
+
if method == "__dispose__":
|
|
383
|
+
assert isinstance(params, dict)
|
|
384
|
+
self._objects[guid]._dispose(cast(Optional[str], params.get("reason")))
|
|
385
|
+
return
|
|
386
|
+
object = self._objects[guid]
|
|
387
|
+
should_replace_guids_with_channels = "jsonPipe@" not in guid
|
|
388
|
+
try:
|
|
389
|
+
if self._is_sync:
|
|
390
|
+
for listener in object._channel.listeners(method):
|
|
391
|
+
|
|
392
|
+
def _done_callback(future: asyncio.Future) -> None:
|
|
393
|
+
exc = future.exception()
|
|
394
|
+
if exc:
|
|
395
|
+
self._on_event_listener_error(exc)
|
|
396
|
+
|
|
397
|
+
def _listener_with_error_handler_attached(params: Any) -> None:
|
|
398
|
+
potential_future = listener(params)
|
|
399
|
+
if asyncio.isfuture(potential_future):
|
|
400
|
+
potential_future.add_done_callback(_done_callback)
|
|
401
|
+
|
|
402
|
+
g = EventGreenlet(_listener_with_error_handler_attached)
|
|
403
|
+
if should_replace_guids_with_channels:
|
|
404
|
+
g.switch(self._replace_guids_with_channels(params))
|
|
405
|
+
else:
|
|
406
|
+
g.switch(params)
|
|
407
|
+
elif should_replace_guids_with_channels:
|
|
408
|
+
object._channel.emit(method, self._replace_guids_with_channels(params))
|
|
409
|
+
else:
|
|
410
|
+
object._channel.emit(method, params)
|
|
411
|
+
except BaseException as exc:
|
|
412
|
+
self._on_event_listener_error(exc)
|
|
413
|
+
|
|
414
|
+
def _on_event_listener_error(self, exc: BaseException) -> None:
|
|
415
|
+
print("Error occurred in event listener", file=sys.stderr)
|
|
416
|
+
traceback.print_exception(type(exc), exc, exc.__traceback__, file=sys.stderr)
|
|
417
|
+
self._error = exc
|
|
418
|
+
|
|
419
|
+
def _create_remote_object(
|
|
420
|
+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
|
|
421
|
+
) -> ChannelOwner:
|
|
422
|
+
initializer = self._replace_guids_with_channels(initializer)
|
|
423
|
+
result = self._object_factory(parent, type, guid, initializer)
|
|
424
|
+
if guid in self._waiting_for_object:
|
|
425
|
+
self._waiting_for_object.pop(guid)(result)
|
|
426
|
+
return result
|
|
427
|
+
|
|
428
|
+
def _replace_channels_with_guids(self, payload: Any) -> Any:
|
|
429
|
+
if payload is None:
|
|
430
|
+
return payload
|
|
431
|
+
if isinstance(payload, Path):
|
|
432
|
+
return str(payload)
|
|
433
|
+
if isinstance(payload, collections.abc.Sequence) and (
|
|
434
|
+
not isinstance(payload, str)
|
|
435
|
+
):
|
|
436
|
+
return list(map(self._replace_channels_with_guids, payload))
|
|
437
|
+
if isinstance(payload, Channel):
|
|
438
|
+
return dict(guid=payload._guid)
|
|
439
|
+
if isinstance(payload, dict):
|
|
440
|
+
result = {}
|
|
441
|
+
for key, value in payload.items():
|
|
442
|
+
result[key] = self._replace_channels_with_guids(value)
|
|
443
|
+
return result
|
|
444
|
+
return payload
|
|
445
|
+
|
|
446
|
+
def _replace_guids_with_channels(self, payload: Any) -> Any:
|
|
447
|
+
if payload is None:
|
|
448
|
+
return payload
|
|
449
|
+
if isinstance(payload, list):
|
|
450
|
+
return list(map(self._replace_guids_with_channels, payload))
|
|
451
|
+
if isinstance(payload, dict):
|
|
452
|
+
if payload.get("guid") in self._objects:
|
|
453
|
+
return self._objects[payload["guid"]]._channel
|
|
454
|
+
result = {}
|
|
455
|
+
for key, value in payload.items():
|
|
456
|
+
result[key] = self._replace_guids_with_channels(value)
|
|
457
|
+
return result
|
|
458
|
+
return payload
|
|
459
|
+
|
|
460
|
+
async def wrap_api_call(
|
|
461
|
+
self, cb: Callable[[], Any], is_internal: bool = False
|
|
462
|
+
) -> Any:
|
|
463
|
+
if self._api_zone.get():
|
|
464
|
+
return await cb()
|
|
465
|
+
task = asyncio.current_task(self._loop)
|
|
466
|
+
st: List[inspect.FrameInfo] = getattr(task, "__pw_stack__", inspect.stack())
|
|
467
|
+
parsed_st = _extract_stack_trace_information_from_stack(st, is_internal)
|
|
468
|
+
self._api_zone.set(parsed_st)
|
|
469
|
+
try:
|
|
470
|
+
return await cb()
|
|
471
|
+
except Exception as error:
|
|
472
|
+
raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
|
|
473
|
+
finally:
|
|
474
|
+
self._api_zone.set(None)
|
|
475
|
+
|
|
476
|
+
def wrap_api_call_sync(
|
|
477
|
+
self, cb: Callable[[], Any], is_internal: bool = False
|
|
478
|
+
) -> Any:
|
|
479
|
+
if self._api_zone.get():
|
|
480
|
+
return cb()
|
|
481
|
+
task = asyncio.current_task(self._loop)
|
|
482
|
+
st: List[inspect.FrameInfo] = getattr(task, "__pw_stack__", inspect.stack())
|
|
483
|
+
parsed_st = _extract_stack_trace_information_from_stack(st, is_internal)
|
|
484
|
+
self._api_zone.set(parsed_st)
|
|
485
|
+
try:
|
|
486
|
+
return cb()
|
|
487
|
+
except Exception as error:
|
|
488
|
+
raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
|
|
489
|
+
finally:
|
|
490
|
+
self._api_zone.set(None)
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
def from_channel(channel: Channel) -> Any:
|
|
494
|
+
return channel._object
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
def from_nullable_channel(channel: Optional[Channel]) -> Optional[Any]:
|
|
498
|
+
return channel._object if channel else None
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
class StackFrame(TypedDict):
|
|
502
|
+
file: str
|
|
503
|
+
line: int
|
|
504
|
+
column: int
|
|
505
|
+
function: Optional[str]
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
class ParsedStackTrace(TypedDict):
|
|
509
|
+
frames: List[StackFrame]
|
|
510
|
+
apiName: Optional[str]
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
def _extract_stack_trace_information_from_stack(
|
|
514
|
+
st: List[inspect.FrameInfo], is_internal: bool
|
|
515
|
+
) -> ParsedStackTrace:
|
|
516
|
+
playwright_module_path = str(Path(patchright.__file__).parents[0])
|
|
517
|
+
last_internal_api_name = ""
|
|
518
|
+
api_name = ""
|
|
519
|
+
parsed_frames: List[StackFrame] = []
|
|
520
|
+
for frame in st:
|
|
521
|
+
is_playwright_internal = frame.filename.startswith(playwright_module_path)
|
|
522
|
+
method_name = ""
|
|
523
|
+
if "self" in frame[0].f_locals:
|
|
524
|
+
method_name = frame[0].f_locals["self"].__class__.__name__ + "."
|
|
525
|
+
method_name += frame[0].f_code.co_name
|
|
526
|
+
if not is_playwright_internal:
|
|
527
|
+
parsed_frames.append(
|
|
528
|
+
{
|
|
529
|
+
"file": frame.filename,
|
|
530
|
+
"line": frame.lineno,
|
|
531
|
+
"column": 0,
|
|
532
|
+
"function": method_name,
|
|
533
|
+
}
|
|
534
|
+
)
|
|
535
|
+
if is_playwright_internal:
|
|
536
|
+
last_internal_api_name = method_name
|
|
537
|
+
elif last_internal_api_name:
|
|
538
|
+
api_name = last_internal_api_name
|
|
539
|
+
last_internal_api_name = ""
|
|
540
|
+
if not api_name:
|
|
541
|
+
api_name = last_internal_api_name
|
|
542
|
+
return {"frames": parsed_frames, "apiName": "" if is_internal else api_name}
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
def _filter_none(d: Mapping) -> Dict:
|
|
546
|
+
return {k: v for k, v in d.items() if v is not None}
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
def format_call_log(log: Optional[List[str]]) -> str:
|
|
550
|
+
if not log:
|
|
551
|
+
return ""
|
|
552
|
+
if len(list(filter(lambda x: x.strip(), log))) == 0:
|
|
553
|
+
return ""
|
|
554
|
+
return "\nCall log:\n" + "\n - ".join(log) + "\n"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from asyncio import AbstractEventLoop
|
|
2
|
+
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
|
3
|
+
from patchright._impl._api_structures import SourceLocation
|
|
4
|
+
from patchright._impl._connection import from_channel, from_nullable_channel
|
|
5
|
+
from patchright._impl._js_handle import JSHandle
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from patchright._impl._page import Page
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ConsoleMessage:
|
|
12
|
+
|
|
13
|
+
def __init__(
|
|
14
|
+
self, event: Dict, loop: AbstractEventLoop, dispatcher_fiber: Any
|
|
15
|
+
) -> None:
|
|
16
|
+
self._event = event
|
|
17
|
+
self._loop = loop
|
|
18
|
+
self._dispatcher_fiber = dispatcher_fiber
|
|
19
|
+
self._page: Optional["Page"] = from_nullable_channel(event.get("page"))
|
|
20
|
+
|
|
21
|
+
def __repr__(self) -> str:
|
|
22
|
+
return f"<ConsoleMessage type={self.type} text={self.text}>"
|
|
23
|
+
|
|
24
|
+
def __str__(self) -> str:
|
|
25
|
+
return self.text
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def type(self) -> str:
|
|
29
|
+
return self._event["type"]
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def text(self) -> str:
|
|
33
|
+
return self._event["text"]
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def args(self) -> List[JSHandle]:
|
|
37
|
+
return list(map(from_channel, self._event["args"]))
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def location(self) -> SourceLocation:
|
|
41
|
+
return self._event["location"]
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def page(self) -> Optional["Page"]:
|
|
45
|
+
return self._page
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING, Dict, Optional
|
|
2
|
+
from patchright._impl._connection import ChannelOwner, from_nullable_channel
|
|
3
|
+
from patchright._impl._helper import locals_to_params
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from patchright._impl._page import Page
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Dialog(ChannelOwner):
|
|
10
|
+
|
|
11
|
+
def __init__(
|
|
12
|
+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
|
|
13
|
+
) -> None:
|
|
14
|
+
super().__init__(parent, type, guid, initializer)
|
|
15
|
+
self._page: Optional["Page"] = from_nullable_channel(initializer.get("page"))
|
|
16
|
+
|
|
17
|
+
def __repr__(self) -> str:
|
|
18
|
+
return f"<Dialog type={self.type} message={self.message} default_value={self.default_value}>"
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def type(self) -> str:
|
|
22
|
+
return self._initializer["type"]
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def message(self) -> str:
|
|
26
|
+
return self._initializer["message"]
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def default_value(self) -> str:
|
|
30
|
+
return self._initializer["defaultValue"]
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def page(self) -> Optional["Page"]:
|
|
34
|
+
return self._page
|
|
35
|
+
|
|
36
|
+
async def accept(self, promptText: str = None) -> None:
|
|
37
|
+
await self._channel.send("accept", locals_to_params(locals()))
|
|
38
|
+
|
|
39
|
+
async def dismiss(self) -> None:
|
|
40
|
+
await self._channel.send("dismiss")
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import TYPE_CHECKING, Optional, Union
|
|
4
|
+
from patchright._impl._artifact import Artifact
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from patchright._impl._page import Page
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Download:
|
|
11
|
+
|
|
12
|
+
def __init__(
|
|
13
|
+
self, page: "Page", url: str, suggested_filename: str, artifact: Artifact
|
|
14
|
+
) -> None:
|
|
15
|
+
self._page = page
|
|
16
|
+
self._loop = page._loop
|
|
17
|
+
self._dispatcher_fiber = page._dispatcher_fiber
|
|
18
|
+
self._url = url
|
|
19
|
+
self._suggested_filename = suggested_filename
|
|
20
|
+
self._artifact = artifact
|
|
21
|
+
|
|
22
|
+
def __repr__(self) -> str:
|
|
23
|
+
return f"<Download url={self.url!r} suggested_filename={self.suggested_filename!r}>"
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def page(self) -> "Page":
|
|
27
|
+
return self._page
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def url(self) -> str:
|
|
31
|
+
return self._url
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def suggested_filename(self) -> str:
|
|
35
|
+
return self._suggested_filename
|
|
36
|
+
|
|
37
|
+
async def delete(self) -> None:
|
|
38
|
+
await self._artifact.delete()
|
|
39
|
+
|
|
40
|
+
async def failure(self) -> Optional[str]:
|
|
41
|
+
return await self._artifact.failure()
|
|
42
|
+
|
|
43
|
+
async def path(self) -> pathlib.Path:
|
|
44
|
+
return await self._artifact.path_after_finished()
|
|
45
|
+
|
|
46
|
+
async def save_as(self, path: Union[str, Path]) -> None:
|
|
47
|
+
await self._artifact.save_as(path)
|
|
48
|
+
|
|
49
|
+
async def cancel(self) -> None:
|
|
50
|
+
return await self._artifact.cancel()
|