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,51 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
escaped_chars = {"$", "^", "+", ".", "*", "(", ")", "|", "\\", "?", "{", "}", "[", "]"}
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def glob_to_regex(glob: str) -> "re.Pattern[str]":
|
|
7
|
+
tokens = ["^"]
|
|
8
|
+
in_group = False
|
|
9
|
+
i = 0
|
|
10
|
+
while i < len(glob):
|
|
11
|
+
c = glob[i]
|
|
12
|
+
if c == "\\" and i + 1 < len(glob):
|
|
13
|
+
char = glob[i + 1]
|
|
14
|
+
tokens.append("\\" + char if char in escaped_chars else char)
|
|
15
|
+
i += 1
|
|
16
|
+
elif c == "*":
|
|
17
|
+
before_deep = glob[i - 1] if i > 0 else None
|
|
18
|
+
star_count = 1
|
|
19
|
+
while i + 1 < len(glob) and glob[i + 1] == "*":
|
|
20
|
+
star_count += 1
|
|
21
|
+
i += 1
|
|
22
|
+
after_deep = glob[i + 1] if i + 1 < len(glob) else None
|
|
23
|
+
is_deep = (
|
|
24
|
+
star_count > 1
|
|
25
|
+
and (before_deep == "/" or before_deep is None)
|
|
26
|
+
and (after_deep == "/" or after_deep is None)
|
|
27
|
+
)
|
|
28
|
+
if is_deep:
|
|
29
|
+
tokens.append("((?:[^/]*(?:/|$))*)")
|
|
30
|
+
i += 1
|
|
31
|
+
else:
|
|
32
|
+
tokens.append("([^/]*)")
|
|
33
|
+
elif c == "?":
|
|
34
|
+
tokens.append(".")
|
|
35
|
+
elif c == "[":
|
|
36
|
+
tokens.append("[")
|
|
37
|
+
elif c == "]":
|
|
38
|
+
tokens.append("]")
|
|
39
|
+
elif c == "{":
|
|
40
|
+
in_group = True
|
|
41
|
+
tokens.append("(")
|
|
42
|
+
elif c == "}":
|
|
43
|
+
in_group = False
|
|
44
|
+
tokens.append(")")
|
|
45
|
+
elif c == "," and in_group:
|
|
46
|
+
tokens.append("|")
|
|
47
|
+
else:
|
|
48
|
+
tokens.append("\\" + c if c in escaped_chars else c)
|
|
49
|
+
i += 1
|
|
50
|
+
tokens.append("$")
|
|
51
|
+
return re.compile("".join(tokens))
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Tuple
|
|
3
|
+
import greenlet
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _greenlet_trace_callback(
|
|
7
|
+
event: str, args: Tuple[greenlet.greenlet, greenlet.greenlet]
|
|
8
|
+
) -> None:
|
|
9
|
+
if event in ("switch", "throw"):
|
|
10
|
+
origin, target = args
|
|
11
|
+
print(f"Transfer from {origin} to {target} with {event}")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
if os.environ.get("INTERNAL_PW_GREENLET_DEBUG"):
|
|
15
|
+
greenlet.settrace(_greenlet_trace_callback)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class MainGreenlet(greenlet.greenlet):
|
|
19
|
+
|
|
20
|
+
def __str__(self) -> str:
|
|
21
|
+
return "<MainGreenlet>"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class RouteGreenlet(greenlet.greenlet):
|
|
25
|
+
|
|
26
|
+
def __str__(self) -> str:
|
|
27
|
+
return "<RouteGreenlet>"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class LocatorHandlerGreenlet(greenlet.greenlet):
|
|
31
|
+
|
|
32
|
+
def __str__(self) -> str:
|
|
33
|
+
return "<LocatorHandlerGreenlet>"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class EventGreenlet(greenlet.greenlet):
|
|
37
|
+
|
|
38
|
+
def __str__(self) -> str:
|
|
39
|
+
return "<EventGreenlet>"
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import base64
|
|
3
|
+
from typing import TYPE_CHECKING, Optional, cast
|
|
4
|
+
from patchright._impl._api_structures import HeadersArray
|
|
5
|
+
from patchright._impl._helper import (
|
|
6
|
+
HarLookupResult,
|
|
7
|
+
RouteFromHarNotFoundPolicy,
|
|
8
|
+
URLMatch,
|
|
9
|
+
)
|
|
10
|
+
from patchright._impl._local_utils import LocalUtils
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from patchright._impl._browser_context import BrowserContext
|
|
14
|
+
from patchright._impl._network import Route
|
|
15
|
+
from patchright._impl._page import Page
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class HarRouter:
|
|
19
|
+
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
local_utils: LocalUtils,
|
|
23
|
+
har_id: str,
|
|
24
|
+
not_found_action: RouteFromHarNotFoundPolicy,
|
|
25
|
+
url_matcher: Optional[URLMatch] = None,
|
|
26
|
+
) -> None:
|
|
27
|
+
self._local_utils: LocalUtils = local_utils
|
|
28
|
+
self._har_id: str = har_id
|
|
29
|
+
self._not_found_action: RouteFromHarNotFoundPolicy = not_found_action
|
|
30
|
+
self._options_url_match: Optional[URLMatch] = url_matcher
|
|
31
|
+
|
|
32
|
+
@staticmethod
|
|
33
|
+
async def create(
|
|
34
|
+
local_utils: LocalUtils,
|
|
35
|
+
file: str,
|
|
36
|
+
not_found_action: RouteFromHarNotFoundPolicy,
|
|
37
|
+
url_matcher: Optional[URLMatch] = None,
|
|
38
|
+
) -> "HarRouter":
|
|
39
|
+
har_id = await local_utils._channel.send("harOpen", {"file": file})
|
|
40
|
+
return HarRouter(
|
|
41
|
+
local_utils=local_utils,
|
|
42
|
+
har_id=har_id,
|
|
43
|
+
not_found_action=not_found_action,
|
|
44
|
+
url_matcher=url_matcher,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
async def _handle(self, route: "Route") -> None:
|
|
48
|
+
request = route.request
|
|
49
|
+
response: HarLookupResult = await self._local_utils.har_lookup(
|
|
50
|
+
harId=self._har_id,
|
|
51
|
+
url=request.url,
|
|
52
|
+
method=request.method,
|
|
53
|
+
headers=await request.headers_array(),
|
|
54
|
+
postData=request.post_data_buffer,
|
|
55
|
+
isNavigationRequest=request.is_navigation_request(),
|
|
56
|
+
)
|
|
57
|
+
action = response["action"]
|
|
58
|
+
if action == "redirect":
|
|
59
|
+
redirect_url = response["redirectURL"]
|
|
60
|
+
assert redirect_url
|
|
61
|
+
await route._redirected_navigation_request(redirect_url)
|
|
62
|
+
return
|
|
63
|
+
if action == "fulfill":
|
|
64
|
+
if response.get("status") == -1:
|
|
65
|
+
return
|
|
66
|
+
body = response["body"]
|
|
67
|
+
assert body is not None
|
|
68
|
+
await route.fulfill(
|
|
69
|
+
status=response.get("status"),
|
|
70
|
+
headers={
|
|
71
|
+
v["name"]: v["value"]
|
|
72
|
+
for v in cast(HeadersArray, response.get("headers", []))
|
|
73
|
+
},
|
|
74
|
+
body=base64.b64decode(body),
|
|
75
|
+
)
|
|
76
|
+
return
|
|
77
|
+
if action == "error":
|
|
78
|
+
pass
|
|
79
|
+
if self._not_found_action == "abort":
|
|
80
|
+
await route.abort()
|
|
81
|
+
return
|
|
82
|
+
await route.fallback()
|
|
83
|
+
|
|
84
|
+
async def add_context_route(self, context: "BrowserContext") -> None:
|
|
85
|
+
await context.route(
|
|
86
|
+
url=self._options_url_match or "**/*",
|
|
87
|
+
handler=lambda route, _: asyncio.create_task(self._handle(route)),
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
async def add_page_route(self, page: "Page") -> None:
|
|
91
|
+
await page.route(
|
|
92
|
+
url=self._options_url_match or "**/*",
|
|
93
|
+
handler=lambda route, _: asyncio.create_task(self._handle(route)),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
def dispose(self) -> None:
|
|
97
|
+
asyncio.create_task(
|
|
98
|
+
self._local_utils._channel.send("harClose", {"harId": self._har_id})
|
|
99
|
+
)
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import math
|
|
3
|
+
import os
|
|
4
|
+
import re
|
|
5
|
+
import time
|
|
6
|
+
import traceback
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from types import TracebackType
|
|
9
|
+
from typing import (
|
|
10
|
+
TYPE_CHECKING,
|
|
11
|
+
Any,
|
|
12
|
+
Callable,
|
|
13
|
+
Dict,
|
|
14
|
+
List,
|
|
15
|
+
Literal,
|
|
16
|
+
Optional,
|
|
17
|
+
Pattern,
|
|
18
|
+
Set,
|
|
19
|
+
TypedDict,
|
|
20
|
+
TypeVar,
|
|
21
|
+
Union,
|
|
22
|
+
cast,
|
|
23
|
+
)
|
|
24
|
+
from urllib.parse import urljoin
|
|
25
|
+
from patchright._impl._api_structures import NameValue
|
|
26
|
+
from patchright._impl._errors import (
|
|
27
|
+
Error,
|
|
28
|
+
TargetClosedError,
|
|
29
|
+
TimeoutError,
|
|
30
|
+
is_target_closed_error,
|
|
31
|
+
rewrite_error,
|
|
32
|
+
)
|
|
33
|
+
from patchright._impl._glob import glob_to_regex
|
|
34
|
+
from patchright._impl._greenlets import RouteGreenlet
|
|
35
|
+
from patchright._impl._str_utils import escape_regex_flags
|
|
36
|
+
|
|
37
|
+
if TYPE_CHECKING:
|
|
38
|
+
from patchright._impl._api_structures import HeadersArray
|
|
39
|
+
from patchright._impl._network import Request, Response, Route, WebSocketRoute
|
|
40
|
+
URLMatch = Union[str, Pattern[str], Callable[[str], bool]]
|
|
41
|
+
URLMatchRequest = Union[str, Pattern[str], Callable[["Request"], bool]]
|
|
42
|
+
URLMatchResponse = Union[str, Pattern[str], Callable[["Response"], bool]]
|
|
43
|
+
RouteHandlerCallback = Union[
|
|
44
|
+
Callable[["Route"], Any], Callable[["Route", "Request"], Any]
|
|
45
|
+
]
|
|
46
|
+
WebSocketRouteHandlerCallback = Callable[["WebSocketRoute"], Any]
|
|
47
|
+
ColorScheme = Literal["dark", "light", "no-preference", "null"]
|
|
48
|
+
ForcedColors = Literal["active", "none", "null"]
|
|
49
|
+
ReducedMotion = Literal["no-preference", "null", "reduce"]
|
|
50
|
+
DocumentLoadState = Literal["commit", "domcontentloaded", "load", "networkidle"]
|
|
51
|
+
KeyboardModifier = Literal["Alt", "Control", "ControlOrMeta", "Meta", "Shift"]
|
|
52
|
+
MouseButton = Literal["left", "middle", "right"]
|
|
53
|
+
ServiceWorkersPolicy = Literal["allow", "block"]
|
|
54
|
+
HarMode = Literal["full", "minimal"]
|
|
55
|
+
HarContentPolicy = Literal["attach", "embed", "omit"]
|
|
56
|
+
RouteFromHarNotFoundPolicy = Literal["abort", "fallback"]
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class ErrorPayload(TypedDict, total=False):
|
|
60
|
+
message: str
|
|
61
|
+
name: str
|
|
62
|
+
stack: str
|
|
63
|
+
value: Optional[Any]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class HarRecordingMetadata(TypedDict, total=False):
|
|
67
|
+
path: str
|
|
68
|
+
content: Optional[HarContentPolicy]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def prepare_record_har_options(params: Dict) -> Dict[str, Any]:
|
|
72
|
+
out_params: Dict[str, Any] = {"path": str(params["recordHarPath"])}
|
|
73
|
+
if "recordHarUrlFilter" in params:
|
|
74
|
+
opt = params["recordHarUrlFilter"]
|
|
75
|
+
if isinstance(opt, str):
|
|
76
|
+
out_params["urlGlob"] = opt
|
|
77
|
+
if isinstance(opt, Pattern):
|
|
78
|
+
out_params["urlRegexSource"] = opt.pattern
|
|
79
|
+
out_params["urlRegexFlags"] = escape_regex_flags(opt)
|
|
80
|
+
del params["recordHarUrlFilter"]
|
|
81
|
+
if "recordHarMode" in params:
|
|
82
|
+
out_params["mode"] = params["recordHarMode"]
|
|
83
|
+
del params["recordHarMode"]
|
|
84
|
+
new_content_api = None
|
|
85
|
+
old_content_api = None
|
|
86
|
+
if "recordHarContent" in params:
|
|
87
|
+
new_content_api = params["recordHarContent"]
|
|
88
|
+
del params["recordHarContent"]
|
|
89
|
+
if "recordHarOmitContent" in params:
|
|
90
|
+
old_content_api = params["recordHarOmitContent"]
|
|
91
|
+
del params["recordHarOmitContent"]
|
|
92
|
+
content = new_content_api or ("omit" if old_content_api else None)
|
|
93
|
+
if content:
|
|
94
|
+
out_params["content"] = content
|
|
95
|
+
return out_params
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class ParsedMessageParams(TypedDict):
|
|
99
|
+
type: str
|
|
100
|
+
guid: str
|
|
101
|
+
initializer: Dict
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class ParsedMessagePayload(TypedDict, total=False):
|
|
105
|
+
id: int
|
|
106
|
+
guid: str
|
|
107
|
+
method: str
|
|
108
|
+
params: ParsedMessageParams
|
|
109
|
+
result: Any
|
|
110
|
+
error: ErrorPayload
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class Document(TypedDict):
|
|
114
|
+
request: Optional[Any]
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class FrameNavigatedEvent(TypedDict):
|
|
118
|
+
url: str
|
|
119
|
+
name: str
|
|
120
|
+
newDocument: Optional[Document]
|
|
121
|
+
error: Optional[str]
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
Env = Dict[str, Union[str, float, bool]]
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class URLMatcher:
|
|
128
|
+
|
|
129
|
+
def __init__(self, base_url: Union[str, None], match: URLMatch) -> None:
|
|
130
|
+
self._callback: Optional[Callable[[str], bool]] = None
|
|
131
|
+
self._regex_obj: Optional[Pattern[str]] = None
|
|
132
|
+
if isinstance(match, str):
|
|
133
|
+
if base_url and (not match.startswith("*")):
|
|
134
|
+
match = urljoin(base_url, match)
|
|
135
|
+
regex = glob_to_regex(match)
|
|
136
|
+
self._regex_obj = re.compile(regex)
|
|
137
|
+
elif isinstance(match, Pattern):
|
|
138
|
+
self._regex_obj = match
|
|
139
|
+
else:
|
|
140
|
+
self._callback = match
|
|
141
|
+
self.match = match
|
|
142
|
+
|
|
143
|
+
def matches(self, url: str) -> bool:
|
|
144
|
+
if self._callback:
|
|
145
|
+
return self._callback(url)
|
|
146
|
+
if self._regex_obj:
|
|
147
|
+
return cast(bool, self._regex_obj.search(url))
|
|
148
|
+
return False
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class HarLookupResult(TypedDict, total=False):
|
|
152
|
+
action: Literal["error", "redirect", "fulfill", "noentry"]
|
|
153
|
+
message: Optional[str]
|
|
154
|
+
redirectURL: Optional[str]
|
|
155
|
+
status: Optional[int]
|
|
156
|
+
headers: Optional["HeadersArray"]
|
|
157
|
+
body: Optional[str]
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class TimeoutSettings:
|
|
161
|
+
|
|
162
|
+
def __init__(self, parent: Optional["TimeoutSettings"]) -> None:
|
|
163
|
+
self._parent = parent
|
|
164
|
+
self._default_timeout: Optional[float] = None
|
|
165
|
+
self._default_navigation_timeout: Optional[float] = None
|
|
166
|
+
|
|
167
|
+
def set_default_timeout(self, timeout: Optional[float]) -> None:
|
|
168
|
+
self._default_timeout = timeout
|
|
169
|
+
|
|
170
|
+
def timeout(self, timeout: float = None) -> float:
|
|
171
|
+
if timeout is not None:
|
|
172
|
+
return timeout
|
|
173
|
+
if self._default_timeout is not None:
|
|
174
|
+
return self._default_timeout
|
|
175
|
+
if self._parent:
|
|
176
|
+
return self._parent.timeout()
|
|
177
|
+
return 30000
|
|
178
|
+
|
|
179
|
+
def set_default_navigation_timeout(
|
|
180
|
+
self, navigation_timeout: Optional[float]
|
|
181
|
+
) -> None:
|
|
182
|
+
self._default_navigation_timeout = navigation_timeout
|
|
183
|
+
|
|
184
|
+
def default_navigation_timeout(self) -> Optional[float]:
|
|
185
|
+
return self._default_navigation_timeout
|
|
186
|
+
|
|
187
|
+
def default_timeout(self) -> Optional[float]:
|
|
188
|
+
return self._default_timeout
|
|
189
|
+
|
|
190
|
+
def navigation_timeout(self) -> float:
|
|
191
|
+
if self._default_navigation_timeout is not None:
|
|
192
|
+
return self._default_navigation_timeout
|
|
193
|
+
if self._parent:
|
|
194
|
+
return self._parent.navigation_timeout()
|
|
195
|
+
return 30000
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def serialize_error(ex: Exception, tb: Optional[TracebackType]) -> ErrorPayload:
|
|
199
|
+
return ErrorPayload(
|
|
200
|
+
message=str(ex), name="Error", stack="".join(traceback.format_tb(tb))
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def parse_error(error: ErrorPayload, log: Optional[str] = None) -> Error:
|
|
205
|
+
base_error_class = Error
|
|
206
|
+
if error.get("name") == "TimeoutError":
|
|
207
|
+
base_error_class = TimeoutError
|
|
208
|
+
if error.get("name") == "TargetClosedError":
|
|
209
|
+
base_error_class = TargetClosedError
|
|
210
|
+
if not log:
|
|
211
|
+
log = ""
|
|
212
|
+
exc = base_error_class(patch_error_message(error["message"]) + log)
|
|
213
|
+
exc._name = error["name"]
|
|
214
|
+
exc._stack = error["stack"]
|
|
215
|
+
return exc
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def patch_error_message(message: str) -> str:
|
|
219
|
+
match = re.match("(\\w+)(: expected .*)", message)
|
|
220
|
+
if match:
|
|
221
|
+
message = to_snake_case(match.group(1)) + match.group(2)
|
|
222
|
+
message = message.replace(
|
|
223
|
+
"Pass { acceptDownloads: true }", "Pass 'accept_downloads=True'"
|
|
224
|
+
)
|
|
225
|
+
return message
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def locals_to_params(args: Dict) -> Dict:
|
|
229
|
+
copy = {}
|
|
230
|
+
for key in args:
|
|
231
|
+
if key == "self":
|
|
232
|
+
continue
|
|
233
|
+
if args[key] is not None:
|
|
234
|
+
copy[key] = (
|
|
235
|
+
args[key]
|
|
236
|
+
if not isinstance(args[key], Dict)
|
|
237
|
+
else locals_to_params(args[key])
|
|
238
|
+
)
|
|
239
|
+
return copy
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def monotonic_time() -> int:
|
|
243
|
+
return math.floor(time.monotonic() * 1000)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
class RouteHandlerInvocation:
|
|
247
|
+
complete: "asyncio.Future"
|
|
248
|
+
route: "Route"
|
|
249
|
+
|
|
250
|
+
def __init__(self, complete: "asyncio.Future", route: "Route") -> None:
|
|
251
|
+
self.complete = complete
|
|
252
|
+
self.route = route
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
class RouteHandler:
|
|
256
|
+
|
|
257
|
+
def __init__(
|
|
258
|
+
self,
|
|
259
|
+
matcher: URLMatcher,
|
|
260
|
+
handler: RouteHandlerCallback,
|
|
261
|
+
is_sync: bool,
|
|
262
|
+
times: Optional[int] = None,
|
|
263
|
+
):
|
|
264
|
+
self.matcher = matcher
|
|
265
|
+
self.handler = handler
|
|
266
|
+
self._times = times if times else math.inf
|
|
267
|
+
self._handled_count = 0
|
|
268
|
+
self._is_sync = is_sync
|
|
269
|
+
self._ignore_exception = False
|
|
270
|
+
self._active_invocations: Set[RouteHandlerInvocation] = set()
|
|
271
|
+
|
|
272
|
+
def matches(self, request_url: str) -> bool:
|
|
273
|
+
return self.matcher.matches(request_url)
|
|
274
|
+
|
|
275
|
+
async def handle(self, route: "Route") -> bool:
|
|
276
|
+
handler_invocation = RouteHandlerInvocation(
|
|
277
|
+
asyncio.get_running_loop().create_future(), route
|
|
278
|
+
)
|
|
279
|
+
self._active_invocations.add(handler_invocation)
|
|
280
|
+
try:
|
|
281
|
+
return await self._handle_internal(route)
|
|
282
|
+
except Exception as e:
|
|
283
|
+
if self._ignore_exception:
|
|
284
|
+
return False
|
|
285
|
+
if is_target_closed_error(e):
|
|
286
|
+
optional_async_prefix = "await " if not self._is_sync else ""
|
|
287
|
+
raise rewrite_error(
|
|
288
|
+
e,
|
|
289
|
+
f""""{str(e)}" while running route callback.\nConsider awaiting `{optional_async_prefix}page.unroute_all(behavior='ignoreErrors')`\nbefore the end of the test to ignore remaining routes in flight.""",
|
|
290
|
+
)
|
|
291
|
+
raise e
|
|
292
|
+
finally:
|
|
293
|
+
handler_invocation.complete.set_result(None)
|
|
294
|
+
self._active_invocations.remove(handler_invocation)
|
|
295
|
+
|
|
296
|
+
async def _handle_internal(self, route: "Route") -> bool:
|
|
297
|
+
handled_future = route._start_handling()
|
|
298
|
+
self._handled_count += 1
|
|
299
|
+
if self._is_sync:
|
|
300
|
+
handler_finished_future = route._loop.create_future()
|
|
301
|
+
|
|
302
|
+
def _handler() -> None:
|
|
303
|
+
try:
|
|
304
|
+
self.handler(route, route.request)
|
|
305
|
+
handler_finished_future.set_result(None)
|
|
306
|
+
except Exception as e:
|
|
307
|
+
handler_finished_future.set_exception(e)
|
|
308
|
+
|
|
309
|
+
g = RouteGreenlet(_handler)
|
|
310
|
+
g.switch()
|
|
311
|
+
await handler_finished_future
|
|
312
|
+
else:
|
|
313
|
+
coro_or_future = self.handler(route, route.request)
|
|
314
|
+
if coro_or_future:
|
|
315
|
+
await asyncio.ensure_future(coro_or_future)
|
|
316
|
+
return await handled_future
|
|
317
|
+
|
|
318
|
+
async def stop(self, behavior: Literal["ignoreErrors", "wait"]) -> None:
|
|
319
|
+
if behavior == "ignoreErrors":
|
|
320
|
+
self._ignore_exception = True
|
|
321
|
+
else:
|
|
322
|
+
tasks = []
|
|
323
|
+
for activation in self._active_invocations:
|
|
324
|
+
if not activation.route._did_throw:
|
|
325
|
+
tasks.append(activation.complete)
|
|
326
|
+
await asyncio.gather(*tasks)
|
|
327
|
+
|
|
328
|
+
@property
|
|
329
|
+
def will_expire(self) -> bool:
|
|
330
|
+
return self._handled_count + 1 >= self._times
|
|
331
|
+
|
|
332
|
+
@staticmethod
|
|
333
|
+
def prepare_interception_patterns(
|
|
334
|
+
handlers: List["RouteHandler"],
|
|
335
|
+
) -> List[Dict[str, str]]:
|
|
336
|
+
patterns = []
|
|
337
|
+
all = False
|
|
338
|
+
for handler in handlers:
|
|
339
|
+
if isinstance(handler.matcher.match, str):
|
|
340
|
+
patterns.append({"glob": handler.matcher.match})
|
|
341
|
+
elif isinstance(handler.matcher._regex_obj, re.Pattern):
|
|
342
|
+
patterns.append(
|
|
343
|
+
{
|
|
344
|
+
"regexSource": handler.matcher._regex_obj.pattern,
|
|
345
|
+
"regexFlags": escape_regex_flags(handler.matcher._regex_obj),
|
|
346
|
+
}
|
|
347
|
+
)
|
|
348
|
+
else:
|
|
349
|
+
all = True
|
|
350
|
+
if all:
|
|
351
|
+
return [{"glob": "**/*"}]
|
|
352
|
+
return patterns
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
to_snake_case_regex = re.compile("((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))")
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def to_snake_case(name: str) -> str:
|
|
359
|
+
return to_snake_case_regex.sub("_\\1", name).lower()
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def make_dirs_for_file(path: Union[Path, str]) -> None:
|
|
363
|
+
if not os.path.isabs(path):
|
|
364
|
+
path = Path.cwd() / path
|
|
365
|
+
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
async def async_writefile(file: Union[str, Path], data: Union[str, bytes]) -> None:
|
|
369
|
+
|
|
370
|
+
def inner() -> None:
|
|
371
|
+
with open(file, "w" if isinstance(data, str) else "wb") as fh:
|
|
372
|
+
fh.write(data)
|
|
373
|
+
|
|
374
|
+
loop = asyncio.get_running_loop()
|
|
375
|
+
await loop.run_in_executor(None, inner)
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
async def async_readfile(file: Union[str, Path]) -> bytes:
|
|
379
|
+
|
|
380
|
+
def inner() -> bytes:
|
|
381
|
+
with open(file, "rb") as fh:
|
|
382
|
+
return fh.read()
|
|
383
|
+
|
|
384
|
+
loop = asyncio.get_running_loop()
|
|
385
|
+
return await loop.run_in_executor(None, inner)
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
T = TypeVar("T")
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
def to_impl(obj: T) -> T:
|
|
392
|
+
if hasattr(obj, "_impl_obj"):
|
|
393
|
+
return cast(Any, obj)._impl_obj
|
|
394
|
+
return obj
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def object_to_array(obj: Optional[Dict]) -> Optional[List[NameValue]]:
|
|
398
|
+
if not obj:
|
|
399
|
+
return None
|
|
400
|
+
result = []
|
|
401
|
+
for key, value in obj.items():
|
|
402
|
+
result.append(NameValue(name=key, value=str(value)))
|
|
403
|
+
return result
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
def is_file_payload(value: Optional[Any]) -> bool:
|
|
407
|
+
return (
|
|
408
|
+
isinstance(value, dict)
|
|
409
|
+
and "name" in value
|
|
410
|
+
and ("mimeType" in value)
|
|
411
|
+
and ("buffer" in value)
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
TEXTUAL_MIME_TYPE = re.compile(
|
|
416
|
+
"^(text\\/.*?|application\\/(json|(x-)?javascript|xml.*?|ecmascript|graphql|x-www-form-urlencoded)|image\\/svg(\\+xml)?|application\\/.*?(\\+json|\\+xml))(;\\s*charset=.*)?$"
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
def is_textual_mime_type(mime_type: str) -> bool:
|
|
421
|
+
return bool(TEXTUAL_MIME_TYPE.match(mime_type))
|