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,11 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def get_file_dirname() -> Path:
|
|
6
|
+
"""Returns the callee (`__file__`) directory name"""
|
|
7
|
+
frame = inspect.stack()[1]
|
|
8
|
+
module = inspect.getmodule(frame[0])
|
|
9
|
+
assert module
|
|
10
|
+
assert module.__file__
|
|
11
|
+
return Path(module.__file__).parent.absolute()
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from typing import Dict
|
|
2
|
+
from patchright._impl._browser_type import BrowserType
|
|
3
|
+
from patchright._impl._connection import ChannelOwner, from_channel
|
|
4
|
+
from patchright._impl._fetch import APIRequest
|
|
5
|
+
from patchright._impl._selectors import Selectors, SelectorsOwner
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Playwright(ChannelOwner):
|
|
9
|
+
devices: Dict
|
|
10
|
+
selectors: Selectors
|
|
11
|
+
chromium: BrowserType
|
|
12
|
+
firefox: BrowserType
|
|
13
|
+
webkit: BrowserType
|
|
14
|
+
request: APIRequest
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
|
|
18
|
+
) -> None:
|
|
19
|
+
super().__init__(parent, type, guid, initializer)
|
|
20
|
+
self.request = APIRequest(self)
|
|
21
|
+
self.chromium = from_channel(initializer["chromium"])
|
|
22
|
+
self.chromium._playwright = self
|
|
23
|
+
self.firefox = from_channel(initializer["firefox"])
|
|
24
|
+
self.firefox._playwright = self
|
|
25
|
+
self.webkit = from_channel(initializer["webkit"])
|
|
26
|
+
self.webkit._playwright = self
|
|
27
|
+
self.selectors = Selectors(self._loop, self._dispatcher_fiber)
|
|
28
|
+
selectors_owner: SelectorsOwner = from_channel(initializer["selectors"])
|
|
29
|
+
self.selectors._add_channel(selectors_owner)
|
|
30
|
+
self._connection.on(
|
|
31
|
+
"close", lambda: self.selectors._remove_channel(selectors_owner)
|
|
32
|
+
)
|
|
33
|
+
self.devices = self._connection.local_utils.devices
|
|
34
|
+
|
|
35
|
+
def __getitem__(self, value: str) -> "BrowserType":
|
|
36
|
+
if value == "chromium":
|
|
37
|
+
return self.chromium
|
|
38
|
+
elif value == "firefox":
|
|
39
|
+
return self.firefox
|
|
40
|
+
elif value == "webkit":
|
|
41
|
+
return self.webkit
|
|
42
|
+
raise ValueError("Invalid browser " + value)
|
|
43
|
+
|
|
44
|
+
def _set_selectors(self, selectors: Selectors) -> None:
|
|
45
|
+
selectors_owner = from_channel(self._initializer["selectors"])
|
|
46
|
+
self.selectors._remove_channel(selectors_owner)
|
|
47
|
+
self.selectors = selectors
|
|
48
|
+
self.selectors._add_channel(selectors_owner)
|
|
49
|
+
|
|
50
|
+
async def stop(self) -> None:
|
|
51
|
+
pass
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import Any, Dict, List, Set, Union
|
|
4
|
+
from patchright._impl._connection import ChannelOwner
|
|
5
|
+
from patchright._impl._errors import Error
|
|
6
|
+
from patchright._impl._helper import async_readfile
|
|
7
|
+
from patchright._impl._locator import set_test_id_attribute_name, test_id_attribute_name
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Selectors:
|
|
11
|
+
|
|
12
|
+
def __init__(self, loop: asyncio.AbstractEventLoop, dispatcher_fiber: Any) -> None:
|
|
13
|
+
self._loop = loop
|
|
14
|
+
self._channels: Set[SelectorsOwner] = set()
|
|
15
|
+
self._registrations: List[Dict] = []
|
|
16
|
+
self._dispatcher_fiber = dispatcher_fiber
|
|
17
|
+
|
|
18
|
+
async def register(
|
|
19
|
+
self,
|
|
20
|
+
name: str,
|
|
21
|
+
script: str = None,
|
|
22
|
+
path: Union[str, Path] = None,
|
|
23
|
+
contentScript: bool = None,
|
|
24
|
+
) -> None:
|
|
25
|
+
if not script and (not path):
|
|
26
|
+
raise Error("Either source or path should be specified")
|
|
27
|
+
if path:
|
|
28
|
+
script = (await async_readfile(path)).decode()
|
|
29
|
+
params: Dict[str, Any] = dict(name=name, source=script)
|
|
30
|
+
if contentScript:
|
|
31
|
+
params["contentScript"] = True
|
|
32
|
+
for channel in self._channels:
|
|
33
|
+
await channel._channel.send("register", params)
|
|
34
|
+
self._registrations.append(params)
|
|
35
|
+
|
|
36
|
+
def set_test_id_attribute(self, attributeName: str) -> None:
|
|
37
|
+
set_test_id_attribute_name(attributeName)
|
|
38
|
+
for channel in self._channels:
|
|
39
|
+
channel._channel.send_no_reply(
|
|
40
|
+
"setTestIdAttributeName", {"testIdAttributeName": attributeName}
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
def _add_channel(self, channel: "SelectorsOwner") -> None:
|
|
44
|
+
self._channels.add(channel)
|
|
45
|
+
for params in self._registrations:
|
|
46
|
+
channel._channel.send_no_reply("register", params)
|
|
47
|
+
channel._channel.send_no_reply(
|
|
48
|
+
"setTestIdAttributeName",
|
|
49
|
+
{"testIdAttributeName": test_id_attribute_name()},
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
def _remove_channel(self, channel: "SelectorsOwner") -> None:
|
|
53
|
+
if channel in self._channels:
|
|
54
|
+
self._channels.remove(channel)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class SelectorsOwner(ChannelOwner):
|
|
58
|
+
|
|
59
|
+
def __init__(
|
|
60
|
+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
|
|
61
|
+
) -> None:
|
|
62
|
+
super().__init__(parent, type, guid, initializer)
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import collections.abc
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import (
|
|
6
|
+
TYPE_CHECKING,
|
|
7
|
+
Dict,
|
|
8
|
+
List,
|
|
9
|
+
Optional,
|
|
10
|
+
Sequence,
|
|
11
|
+
Tuple,
|
|
12
|
+
TypedDict,
|
|
13
|
+
Union,
|
|
14
|
+
cast,
|
|
15
|
+
)
|
|
16
|
+
from patchright._impl._connection import Channel, from_channel
|
|
17
|
+
from patchright._impl._helper import Error
|
|
18
|
+
from patchright._impl._writable_stream import WritableStream
|
|
19
|
+
|
|
20
|
+
if TYPE_CHECKING:
|
|
21
|
+
from patchright._impl._browser_context import BrowserContext
|
|
22
|
+
from patchright._impl._api_structures import FilePayload
|
|
23
|
+
|
|
24
|
+
SIZE_LIMIT_IN_BYTES = 50 * 1024 * 1024
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class InputFilesList(TypedDict, total=False):
|
|
28
|
+
streams: Optional[List[Channel]]
|
|
29
|
+
directoryStream: Optional[Channel]
|
|
30
|
+
localDirectory: Optional[str]
|
|
31
|
+
localPaths: Optional[List[str]]
|
|
32
|
+
payloads: Optional[List[Dict[str, Union[str, bytes]]]]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _list_files(directory: str) -> List[str]:
|
|
36
|
+
files = []
|
|
37
|
+
for root, _, filenames in os.walk(directory):
|
|
38
|
+
for filename in filenames:
|
|
39
|
+
files.append(os.path.join(root, filename))
|
|
40
|
+
return files
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
async def convert_input_files(
|
|
44
|
+
files: Union[
|
|
45
|
+
str, Path, FilePayload, Sequence[Union[str, Path]], Sequence[FilePayload]
|
|
46
|
+
],
|
|
47
|
+
context: "BrowserContext",
|
|
48
|
+
) -> InputFilesList:
|
|
49
|
+
items = (
|
|
50
|
+
files
|
|
51
|
+
if isinstance(files, collections.abc.Sequence) and (not isinstance(files, str))
|
|
52
|
+
else [files]
|
|
53
|
+
)
|
|
54
|
+
if any([isinstance(item, (str, Path)) for item in items]):
|
|
55
|
+
if not all([isinstance(item, (str, Path)) for item in items]):
|
|
56
|
+
raise Error("File paths cannot be mixed with buffers")
|
|
57
|
+
local_paths, local_directory = resolve_paths_and_directory_for_input_files(
|
|
58
|
+
cast(Sequence[Union[str, Path]], items)
|
|
59
|
+
)
|
|
60
|
+
if context._channel._connection.is_remote:
|
|
61
|
+
files_to_stream = cast(
|
|
62
|
+
List[str],
|
|
63
|
+
_list_files(local_directory) if local_directory else local_paths,
|
|
64
|
+
)
|
|
65
|
+
streams = []
|
|
66
|
+
result = await context._connection.wrap_api_call(
|
|
67
|
+
lambda: context._channel.send_return_as_dict(
|
|
68
|
+
"createTempFiles",
|
|
69
|
+
{
|
|
70
|
+
"rootDirName": (
|
|
71
|
+
os.path.basename(local_directory)
|
|
72
|
+
if local_directory
|
|
73
|
+
else None
|
|
74
|
+
),
|
|
75
|
+
"items": list(
|
|
76
|
+
map(
|
|
77
|
+
lambda file: dict(
|
|
78
|
+
name=(
|
|
79
|
+
os.path.relpath(file, local_directory)
|
|
80
|
+
if local_directory
|
|
81
|
+
else os.path.basename(file)
|
|
82
|
+
),
|
|
83
|
+
lastModifiedMs=int(os.path.getmtime(file) * 1000),
|
|
84
|
+
),
|
|
85
|
+
files_to_stream,
|
|
86
|
+
)
|
|
87
|
+
),
|
|
88
|
+
},
|
|
89
|
+
)
|
|
90
|
+
)
|
|
91
|
+
for i, file in enumerate(result["writableStreams"]):
|
|
92
|
+
stream: WritableStream = from_channel(file)
|
|
93
|
+
await stream.copy(files_to_stream[i])
|
|
94
|
+
streams.append(stream._channel)
|
|
95
|
+
return InputFilesList(
|
|
96
|
+
streams=None if local_directory else streams,
|
|
97
|
+
directoryStream=result.get("rootDir"),
|
|
98
|
+
)
|
|
99
|
+
return InputFilesList(localPaths=local_paths, localDirectory=local_directory)
|
|
100
|
+
file_payload_exceeds_size_limit = (
|
|
101
|
+
sum([len(f.get("buffer", "")) for f in items if not isinstance(f, (str, Path))])
|
|
102
|
+
> SIZE_LIMIT_IN_BYTES
|
|
103
|
+
)
|
|
104
|
+
if file_payload_exceeds_size_limit:
|
|
105
|
+
raise Error(
|
|
106
|
+
"Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead."
|
|
107
|
+
)
|
|
108
|
+
return InputFilesList(
|
|
109
|
+
payloads=[
|
|
110
|
+
{
|
|
111
|
+
"name": item["name"],
|
|
112
|
+
"mimeType": item["mimeType"],
|
|
113
|
+
"buffer": base64.b64encode(item["buffer"]).decode(),
|
|
114
|
+
}
|
|
115
|
+
for item in cast(List[FilePayload], items)
|
|
116
|
+
]
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def resolve_paths_and_directory_for_input_files(
|
|
121
|
+
items: Sequence[Union[str, Path]]
|
|
122
|
+
) -> Tuple[Optional[List[str]], Optional[str]]:
|
|
123
|
+
local_paths: Optional[List[str]] = None
|
|
124
|
+
local_directory: Optional[str] = None
|
|
125
|
+
for item in items:
|
|
126
|
+
if os.path.isdir(item):
|
|
127
|
+
if local_directory:
|
|
128
|
+
raise Error("Multiple directories are not supported")
|
|
129
|
+
local_directory = str(Path(item).resolve())
|
|
130
|
+
else:
|
|
131
|
+
local_paths = local_paths or []
|
|
132
|
+
local_paths.append(str(Path(item).resolve()))
|
|
133
|
+
if local_paths and local_directory:
|
|
134
|
+
raise Error("File paths must be all files or a single directory")
|
|
135
|
+
return (local_paths, local_directory)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import re
|
|
3
|
+
from typing import Pattern, Union
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def escape_regex_flags(pattern: Pattern) -> str:
|
|
7
|
+
flags = ""
|
|
8
|
+
if pattern.flags != 0:
|
|
9
|
+
flags = ""
|
|
10
|
+
if pattern.flags & int(re.IGNORECASE) != 0:
|
|
11
|
+
flags += "i"
|
|
12
|
+
if pattern.flags & int(re.DOTALL) != 0:
|
|
13
|
+
flags += "s"
|
|
14
|
+
if pattern.flags & int(re.MULTILINE) != 0:
|
|
15
|
+
flags += "m"
|
|
16
|
+
assert (
|
|
17
|
+
pattern.flags
|
|
18
|
+
& ~(int(re.MULTILINE) | int(re.IGNORECASE) | int(re.DOTALL) | int(re.UNICODE))
|
|
19
|
+
== 0
|
|
20
|
+
), "Unexpected re.Pattern flag, only MULTILINE, IGNORECASE and DOTALL are supported."
|
|
21
|
+
return flags
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def escape_for_regex(text: str) -> str:
|
|
25
|
+
return re.sub("[.*+?^>${}()|[\\]\\\\]", "\\$&", text)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def escape_regex_for_selector(text: Pattern) -> str:
|
|
29
|
+
return (
|
|
30
|
+
"/"
|
|
31
|
+
+ re.sub(
|
|
32
|
+
"(^|[^\\\\])(\\\\\\\\)*([\"\\'`])", "\\1\\2\\\\\\3", text.pattern
|
|
33
|
+
).replace(">>", "\\>\\>")
|
|
34
|
+
+ "/"
|
|
35
|
+
+ escape_regex_flags(text)
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def escape_for_text_selector(
|
|
40
|
+
text: Union[str, Pattern[str]], exact: bool = None, case_sensitive: bool = None
|
|
41
|
+
) -> str:
|
|
42
|
+
if isinstance(text, Pattern):
|
|
43
|
+
return escape_regex_for_selector(text)
|
|
44
|
+
return json.dumps(text) + ("s" if exact else "i")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def escape_for_attribute_selector(
|
|
48
|
+
value: Union[str, Pattern], exact: bool = None
|
|
49
|
+
) -> str:
|
|
50
|
+
if isinstance(value, Pattern):
|
|
51
|
+
return escape_regex_for_selector(value)
|
|
52
|
+
return (
|
|
53
|
+
'"'
|
|
54
|
+
+ value.replace("\\", "\\\\").replace('"', '\\"')
|
|
55
|
+
+ '"'
|
|
56
|
+
+ ("s" if exact else "i")
|
|
57
|
+
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import Dict, Union
|
|
4
|
+
from patchright._impl._connection import ChannelOwner
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Stream(ChannelOwner):
|
|
8
|
+
|
|
9
|
+
def __init__(
|
|
10
|
+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
|
|
11
|
+
) -> None:
|
|
12
|
+
super().__init__(parent, type, guid, initializer)
|
|
13
|
+
|
|
14
|
+
async def save_as(self, path: Union[str, Path]) -> None:
|
|
15
|
+
file = await self._loop.run_in_executor(None, lambda: open(path, "wb"))
|
|
16
|
+
while True:
|
|
17
|
+
binary = await self._channel.send("read", {"size": 1024 * 1024})
|
|
18
|
+
if not binary:
|
|
19
|
+
break
|
|
20
|
+
await self._loop.run_in_executor(
|
|
21
|
+
None, lambda: file.write(base64.b64decode(binary))
|
|
22
|
+
)
|
|
23
|
+
await self._loop.run_in_executor(None, lambda: file.close())
|
|
24
|
+
|
|
25
|
+
async def read_all(self) -> bytes:
|
|
26
|
+
binary = b""
|
|
27
|
+
while True:
|
|
28
|
+
chunk = await self._channel.send("read", {"size": 1024 * 1024})
|
|
29
|
+
if not chunk:
|
|
30
|
+
break
|
|
31
|
+
binary += base64.b64decode(chunk)
|
|
32
|
+
return binary
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import inspect
|
|
3
|
+
import traceback
|
|
4
|
+
from contextlib import AbstractContextManager
|
|
5
|
+
from types import TracebackType
|
|
6
|
+
from typing import (
|
|
7
|
+
Any,
|
|
8
|
+
Callable,
|
|
9
|
+
Coroutine,
|
|
10
|
+
Generator,
|
|
11
|
+
Generic,
|
|
12
|
+
Optional,
|
|
13
|
+
Type,
|
|
14
|
+
TypeVar,
|
|
15
|
+
Union,
|
|
16
|
+
cast,
|
|
17
|
+
)
|
|
18
|
+
import greenlet
|
|
19
|
+
from patchright._impl._helper import Error
|
|
20
|
+
from patchright._impl._impl_to_api_mapping import ImplToApiMapping, ImplWrapper
|
|
21
|
+
|
|
22
|
+
mapping = ImplToApiMapping()
|
|
23
|
+
T = TypeVar("T")
|
|
24
|
+
Self = TypeVar("Self", bound="SyncContextManager")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class EventInfo(Generic[T]):
|
|
28
|
+
|
|
29
|
+
def __init__(self, sync_base: "SyncBase", future: "asyncio.Future[T]") -> None:
|
|
30
|
+
self._sync_base = sync_base
|
|
31
|
+
self._future = future
|
|
32
|
+
g_self = greenlet.getcurrent()
|
|
33
|
+
self._future.add_done_callback(lambda _: g_self.switch())
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def value(self) -> T:
|
|
37
|
+
while not self._future.done():
|
|
38
|
+
self._sync_base._dispatcher_fiber.switch()
|
|
39
|
+
asyncio._set_running_loop(self._sync_base._loop)
|
|
40
|
+
exception = self._future.exception()
|
|
41
|
+
if exception:
|
|
42
|
+
raise exception
|
|
43
|
+
return cast(T, mapping.from_maybe_impl(self._future.result()))
|
|
44
|
+
|
|
45
|
+
def _cancel(self) -> None:
|
|
46
|
+
self._future.cancel()
|
|
47
|
+
|
|
48
|
+
def is_done(self) -> bool:
|
|
49
|
+
return self._future.done()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class EventContextManager(Generic[T], AbstractContextManager):
|
|
53
|
+
|
|
54
|
+
def __init__(self, sync_base: "SyncBase", future: "asyncio.Future[T]") -> None:
|
|
55
|
+
self._event = EventInfo[T](sync_base, future)
|
|
56
|
+
|
|
57
|
+
def __enter__(self) -> EventInfo[T]:
|
|
58
|
+
return self._event
|
|
59
|
+
|
|
60
|
+
def __exit__(
|
|
61
|
+
self,
|
|
62
|
+
exc_type: Optional[Type[BaseException]],
|
|
63
|
+
exc_val: Optional[BaseException],
|
|
64
|
+
exc_tb: Optional[TracebackType],
|
|
65
|
+
) -> None:
|
|
66
|
+
if exc_val:
|
|
67
|
+
self._event._cancel()
|
|
68
|
+
else:
|
|
69
|
+
self._event.value
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class SyncBase(ImplWrapper):
|
|
73
|
+
|
|
74
|
+
def __init__(self, impl_obj: Any) -> None:
|
|
75
|
+
super().__init__(impl_obj)
|
|
76
|
+
self._loop: asyncio.AbstractEventLoop = impl_obj._loop
|
|
77
|
+
self._dispatcher_fiber = impl_obj._dispatcher_fiber
|
|
78
|
+
|
|
79
|
+
def __str__(self) -> str:
|
|
80
|
+
return self._impl_obj.__str__()
|
|
81
|
+
|
|
82
|
+
def _sync(
|
|
83
|
+
self, coro: Union[Coroutine[Any, Any, Any], Generator[Any, Any, Any]]
|
|
84
|
+
) -> Any:
|
|
85
|
+
__tracebackhide__ = True
|
|
86
|
+
if self._loop.is_closed():
|
|
87
|
+
coro.close()
|
|
88
|
+
raise Error("Event loop is closed! Is Playwright already stopped?")
|
|
89
|
+
g_self = greenlet.getcurrent()
|
|
90
|
+
task: asyncio.tasks.Task[Any] = self._loop.create_task(coro)
|
|
91
|
+
setattr(task, "__pw_stack__", inspect.stack())
|
|
92
|
+
setattr(task, "__pw_stack_trace__", traceback.extract_stack())
|
|
93
|
+
task.add_done_callback(lambda _: g_self.switch())
|
|
94
|
+
while not task.done():
|
|
95
|
+
self._dispatcher_fiber.switch()
|
|
96
|
+
asyncio._set_running_loop(self._loop)
|
|
97
|
+
return task.result()
|
|
98
|
+
|
|
99
|
+
def _wrap_handler(
|
|
100
|
+
self, handler: Union[Callable[..., Any], Any]
|
|
101
|
+
) -> Callable[..., None]:
|
|
102
|
+
if callable(handler):
|
|
103
|
+
return mapping.wrap_handler(handler)
|
|
104
|
+
return handler
|
|
105
|
+
|
|
106
|
+
def on(self, event: Any, f: Any) -> None:
|
|
107
|
+
"""Registers the function ``f`` to the event name ``event``."""
|
|
108
|
+
self._impl_obj.on(event, self._wrap_handler(f))
|
|
109
|
+
|
|
110
|
+
def once(self, event: Any, f: Any) -> None:
|
|
111
|
+
"""The same as ``self.on``, except that the listener is automatically
|
|
112
|
+
removed after being called.
|
|
113
|
+
"""
|
|
114
|
+
self._impl_obj.once(event, self._wrap_handler(f))
|
|
115
|
+
|
|
116
|
+
def remove_listener(self, event: Any, f: Any) -> None:
|
|
117
|
+
"""Removes the function ``f`` from ``event``."""
|
|
118
|
+
self._impl_obj.remove_listener(event, self._wrap_handler(f))
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class SyncContextManager(SyncBase):
|
|
122
|
+
|
|
123
|
+
def __enter__(self: Self) -> Self:
|
|
124
|
+
return self
|
|
125
|
+
|
|
126
|
+
def __exit__(
|
|
127
|
+
self,
|
|
128
|
+
exc_type: Type[BaseException],
|
|
129
|
+
exc_val: BaseException,
|
|
130
|
+
_traceback: TracebackType,
|
|
131
|
+
) -> None:
|
|
132
|
+
self.close()
|
|
133
|
+
|
|
134
|
+
def close(self) -> None: ...
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
from typing import Dict, Optional, Union, cast
|
|
3
|
+
from patchright._impl._artifact import Artifact
|
|
4
|
+
from patchright._impl._connection import ChannelOwner, from_nullable_channel
|
|
5
|
+
from patchright._impl._helper import locals_to_params
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Tracing(ChannelOwner):
|
|
9
|
+
|
|
10
|
+
def __init__(
|
|
11
|
+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
|
|
12
|
+
) -> None:
|
|
13
|
+
super().__init__(parent, type, guid, initializer)
|
|
14
|
+
self.mark_as_internal_type()
|
|
15
|
+
self._include_sources: bool = False
|
|
16
|
+
self._stacks_id: Optional[str] = None
|
|
17
|
+
self._is_tracing: bool = False
|
|
18
|
+
self._traces_dir: Optional[str] = None
|
|
19
|
+
|
|
20
|
+
async def start(
|
|
21
|
+
self,
|
|
22
|
+
name: str = None,
|
|
23
|
+
title: str = None,
|
|
24
|
+
snapshots: bool = None,
|
|
25
|
+
screenshots: bool = None,
|
|
26
|
+
sources: bool = None,
|
|
27
|
+
) -> None:
|
|
28
|
+
params = locals_to_params(locals())
|
|
29
|
+
self._include_sources = bool(sources)
|
|
30
|
+
await self._channel.send("tracingStart", params)
|
|
31
|
+
trace_name = await self._channel.send(
|
|
32
|
+
"tracingStartChunk", {"title": title, "name": name}
|
|
33
|
+
)
|
|
34
|
+
await self._start_collecting_stacks(trace_name)
|
|
35
|
+
|
|
36
|
+
async def start_chunk(self, title: str = None, name: str = None) -> None:
|
|
37
|
+
params = locals_to_params(locals())
|
|
38
|
+
trace_name = await self._channel.send("tracingStartChunk", params)
|
|
39
|
+
await self._start_collecting_stacks(trace_name)
|
|
40
|
+
|
|
41
|
+
async def _start_collecting_stacks(self, trace_name: str) -> None:
|
|
42
|
+
if not self._is_tracing:
|
|
43
|
+
self._is_tracing = True
|
|
44
|
+
self._connection.set_is_tracing(True)
|
|
45
|
+
self._stacks_id = await self._connection.local_utils.tracing_started(
|
|
46
|
+
self._traces_dir, trace_name
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
async def stop_chunk(self, path: Union[pathlib.Path, str] = None) -> None:
|
|
50
|
+
await self._do_stop_chunk(path)
|
|
51
|
+
|
|
52
|
+
async def stop(self, path: Union[pathlib.Path, str] = None) -> None:
|
|
53
|
+
await self._do_stop_chunk(path)
|
|
54
|
+
await self._channel.send("tracingStop")
|
|
55
|
+
|
|
56
|
+
async def _do_stop_chunk(self, file_path: Union[pathlib.Path, str] = None) -> None:
|
|
57
|
+
self._reset_stack_counter()
|
|
58
|
+
if not file_path:
|
|
59
|
+
await self._channel.send("tracingStopChunk", {"mode": "discard"})
|
|
60
|
+
if self._stacks_id:
|
|
61
|
+
await self._connection.local_utils.trace_discarded(self._stacks_id)
|
|
62
|
+
return
|
|
63
|
+
is_local = not self._connection.is_remote
|
|
64
|
+
if is_local:
|
|
65
|
+
result = await self._channel.send_return_as_dict(
|
|
66
|
+
"tracingStopChunk", {"mode": "entries"}
|
|
67
|
+
)
|
|
68
|
+
await self._connection.local_utils.zip(
|
|
69
|
+
{
|
|
70
|
+
"zipFile": str(file_path),
|
|
71
|
+
"entries": result["entries"],
|
|
72
|
+
"stacksId": self._stacks_id,
|
|
73
|
+
"mode": "write",
|
|
74
|
+
"includeSources": self._include_sources,
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
return
|
|
78
|
+
result = await self._channel.send_return_as_dict(
|
|
79
|
+
"tracingStopChunk", {"mode": "archive"}
|
|
80
|
+
)
|
|
81
|
+
artifact = cast(
|
|
82
|
+
Optional[Artifact], from_nullable_channel(result.get("artifact"))
|
|
83
|
+
)
|
|
84
|
+
if not artifact:
|
|
85
|
+
if self._stacks_id:
|
|
86
|
+
await self._connection.local_utils.trace_discarded(self._stacks_id)
|
|
87
|
+
return
|
|
88
|
+
await artifact.save_as(file_path)
|
|
89
|
+
await artifact.delete()
|
|
90
|
+
await self._connection.local_utils.zip(
|
|
91
|
+
{
|
|
92
|
+
"zipFile": str(file_path),
|
|
93
|
+
"entries": [],
|
|
94
|
+
"stacksId": self._stacks_id,
|
|
95
|
+
"mode": "append",
|
|
96
|
+
"includeSources": self._include_sources,
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
def _reset_stack_counter(self) -> None:
|
|
101
|
+
if self._is_tracing:
|
|
102
|
+
self._is_tracing = False
|
|
103
|
+
self._connection.set_is_tracing(False)
|