@stablyai/internal-playwright-core 0.1.0
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.
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +3 -0
- package/ThirdPartyNotices.txt +1134 -0
- package/bin/install_media_pack.ps1 +5 -0
- package/bin/install_webkit_wsl.ps1 +35 -0
- package/bin/reinstall_chrome_beta_linux.sh +42 -0
- package/bin/reinstall_chrome_beta_mac.sh +13 -0
- package/bin/reinstall_chrome_beta_win.ps1 +24 -0
- package/bin/reinstall_chrome_stable_linux.sh +42 -0
- package/bin/reinstall_chrome_stable_mac.sh +12 -0
- package/bin/reinstall_chrome_stable_win.ps1 +24 -0
- package/bin/reinstall_msedge_beta_linux.sh +48 -0
- package/bin/reinstall_msedge_beta_mac.sh +11 -0
- package/bin/reinstall_msedge_beta_win.ps1 +23 -0
- package/bin/reinstall_msedge_dev_linux.sh +48 -0
- package/bin/reinstall_msedge_dev_mac.sh +11 -0
- package/bin/reinstall_msedge_dev_win.ps1 +23 -0
- package/bin/reinstall_msedge_stable_linux.sh +48 -0
- package/bin/reinstall_msedge_stable_mac.sh +11 -0
- package/bin/reinstall_msedge_stable_win.ps1 +24 -0
- package/browsers.json +80 -0
- package/cli.js +18 -0
- package/index.d.ts +17 -0
- package/index.js +32 -0
- package/index.mjs +28 -0
- package/lib/androidServerImpl.js +65 -0
- package/lib/browserServerImpl.js +120 -0
- package/lib/cli/cli.js +58 -0
- package/lib/cli/driver.js +97 -0
- package/lib/cli/program.js +634 -0
- package/lib/cli/programWithTestStub.js +74 -0
- package/lib/client/accessibility.js +49 -0
- package/lib/client/android.js +361 -0
- package/lib/client/api.js +137 -0
- package/lib/client/artifact.js +79 -0
- package/lib/client/browser.js +163 -0
- package/lib/client/browserContext.js +529 -0
- package/lib/client/browserType.js +184 -0
- package/lib/client/cdpSession.js +51 -0
- package/lib/client/channelOwner.js +194 -0
- package/lib/client/clientHelper.js +64 -0
- package/lib/client/clientInstrumentation.js +55 -0
- package/lib/client/clientStackTrace.js +69 -0
- package/lib/client/clock.js +68 -0
- package/lib/client/connection.js +314 -0
- package/lib/client/consoleMessage.js +54 -0
- package/lib/client/coverage.js +44 -0
- package/lib/client/dialog.js +56 -0
- package/lib/client/download.js +62 -0
- package/lib/client/electron.js +138 -0
- package/lib/client/elementHandle.js +281 -0
- package/lib/client/errors.js +77 -0
- package/lib/client/eventEmitter.js +314 -0
- package/lib/client/events.js +99 -0
- package/lib/client/fetch.js +369 -0
- package/lib/client/fileChooser.js +46 -0
- package/lib/client/fileUtils.js +34 -0
- package/lib/client/frame.js +408 -0
- package/lib/client/harRouter.js +87 -0
- package/lib/client/input.js +84 -0
- package/lib/client/jsHandle.js +109 -0
- package/lib/client/jsonPipe.js +39 -0
- package/lib/client/localUtils.js +60 -0
- package/lib/client/locator.js +368 -0
- package/lib/client/network.js +747 -0
- package/lib/client/page.js +721 -0
- package/lib/client/platform.js +74 -0
- package/lib/client/playwright.js +71 -0
- package/lib/client/selectors.js +55 -0
- package/lib/client/stream.js +39 -0
- package/lib/client/timeoutSettings.js +79 -0
- package/lib/client/tracing.js +117 -0
- package/lib/client/types.js +28 -0
- package/lib/client/video.js +59 -0
- package/lib/client/waiter.js +142 -0
- package/lib/client/webError.js +39 -0
- package/lib/client/webSocket.js +93 -0
- package/lib/client/worker.js +63 -0
- package/lib/client/writableStream.js +39 -0
- package/lib/common/debugLogger.js +90 -0
- package/lib/common/socksProxy.js +569 -0
- package/lib/common/timeoutSettings.js +73 -0
- package/lib/common/types.js +5 -0
- package/lib/generated/bindingsControllerSource.js +28 -0
- package/lib/generated/clockSource.js +28 -0
- package/lib/generated/consoleApiSource.js +28 -0
- package/lib/generated/injectedScriptSource.js +28 -0
- package/lib/generated/pollingRecorderSource.js +28 -0
- package/lib/generated/recorderSource.js +28 -0
- package/lib/generated/storageScriptSource.js +28 -0
- package/lib/generated/utilityScriptSource.js +28 -0
- package/lib/generated/webSocketMockSource.js +336 -0
- package/lib/image_tools/colorUtils.js +98 -0
- package/lib/image_tools/compare.js +108 -0
- package/lib/image_tools/imageChannel.js +70 -0
- package/lib/image_tools/stats.js +102 -0
- package/lib/inProcessFactory.js +60 -0
- package/lib/index.js +19 -0
- package/lib/inprocess.js +3 -0
- package/lib/outofprocess.js +76 -0
- package/lib/protocol/debug.js +27 -0
- package/lib/protocol/serializers.js +192 -0
- package/lib/protocol/transport.js +82 -0
- package/lib/protocol/validator.js +2919 -0
- package/lib/protocol/validatorPrimitives.js +193 -0
- package/lib/remote/playwrightConnection.js +129 -0
- package/lib/remote/playwrightServer.js +335 -0
- package/lib/server/accessibility.js +69 -0
- package/lib/server/android/android.js +465 -0
- package/lib/server/android/backendAdb.js +177 -0
- package/lib/server/artifact.js +127 -0
- package/lib/server/bidi/bidiBrowser.js +490 -0
- package/lib/server/bidi/bidiChromium.js +153 -0
- package/lib/server/bidi/bidiConnection.js +212 -0
- package/lib/server/bidi/bidiExecutionContext.js +221 -0
- package/lib/server/bidi/bidiFirefox.js +130 -0
- package/lib/server/bidi/bidiInput.js +146 -0
- package/lib/server/bidi/bidiNetworkManager.js +383 -0
- package/lib/server/bidi/bidiOverCdp.js +102 -0
- package/lib/server/bidi/bidiPage.js +552 -0
- package/lib/server/bidi/bidiPdf.js +106 -0
- package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
- package/lib/server/bidi/third_party/bidiDeserializer.js +98 -0
- package/lib/server/bidi/third_party/bidiKeyboard.js +256 -0
- package/lib/server/bidi/third_party/bidiProtocol.js +24 -0
- package/lib/server/bidi/third_party/bidiProtocolCore.js +179 -0
- package/lib/server/bidi/third_party/bidiProtocolPermissions.js +42 -0
- package/lib/server/bidi/third_party/bidiSerializer.js +148 -0
- package/lib/server/bidi/third_party/firefoxPrefs.js +259 -0
- package/lib/server/browser.js +149 -0
- package/lib/server/browserContext.js +695 -0
- package/lib/server/browserType.js +328 -0
- package/lib/server/callLog.js +82 -0
- package/lib/server/chromium/appIcon.png +0 -0
- package/lib/server/chromium/chromium.js +402 -0
- package/lib/server/chromium/chromiumSwitches.js +95 -0
- package/lib/server/chromium/crAccessibility.js +263 -0
- package/lib/server/chromium/crBrowser.js +501 -0
- package/lib/server/chromium/crConnection.js +202 -0
- package/lib/server/chromium/crCoverage.js +235 -0
- package/lib/server/chromium/crDevTools.js +113 -0
- package/lib/server/chromium/crDragDrop.js +131 -0
- package/lib/server/chromium/crExecutionContext.js +146 -0
- package/lib/server/chromium/crInput.js +187 -0
- package/lib/server/chromium/crNetworkManager.js +666 -0
- package/lib/server/chromium/crPage.js +1069 -0
- package/lib/server/chromium/crPdf.js +121 -0
- package/lib/server/chromium/crProtocolHelper.js +145 -0
- package/lib/server/chromium/crServiceWorker.js +123 -0
- package/lib/server/chromium/defaultFontFamilies.js +162 -0
- package/lib/server/chromium/protocol.d.js +16 -0
- package/lib/server/chromium/videoRecorder.js +113 -0
- package/lib/server/clock.js +149 -0
- package/lib/server/codegen/csharp.js +327 -0
- package/lib/server/codegen/java.js +274 -0
- package/lib/server/codegen/javascript.js +270 -0
- package/lib/server/codegen/jsonl.js +52 -0
- package/lib/server/codegen/language.js +132 -0
- package/lib/server/codegen/languages.js +68 -0
- package/lib/server/codegen/python.js +279 -0
- package/lib/server/codegen/types.js +16 -0
- package/lib/server/console.js +53 -0
- package/lib/server/cookieStore.js +206 -0
- package/lib/server/debugController.js +191 -0
- package/lib/server/debugger.js +119 -0
- package/lib/server/deviceDescriptors.js +39 -0
- package/lib/server/deviceDescriptorsSource.json +1779 -0
- package/lib/server/dialog.js +116 -0
- package/lib/server/dispatchers/androidDispatcher.js +325 -0
- package/lib/server/dispatchers/artifactDispatcher.js +118 -0
- package/lib/server/dispatchers/browserContextDispatcher.js +364 -0
- package/lib/server/dispatchers/browserDispatcher.js +118 -0
- package/lib/server/dispatchers/browserTypeDispatcher.js +64 -0
- package/lib/server/dispatchers/cdpSessionDispatcher.js +44 -0
- package/lib/server/dispatchers/debugControllerDispatcher.js +78 -0
- package/lib/server/dispatchers/dialogDispatcher.js +47 -0
- package/lib/server/dispatchers/dispatcher.js +371 -0
- package/lib/server/dispatchers/electronDispatcher.js +89 -0
- package/lib/server/dispatchers/elementHandlerDispatcher.js +181 -0
- package/lib/server/dispatchers/frameDispatcher.js +227 -0
- package/lib/server/dispatchers/jsHandleDispatcher.js +85 -0
- package/lib/server/dispatchers/jsonPipeDispatcher.js +58 -0
- package/lib/server/dispatchers/localUtilsDispatcher.js +149 -0
- package/lib/server/dispatchers/networkDispatchers.js +213 -0
- package/lib/server/dispatchers/pageDispatcher.js +401 -0
- package/lib/server/dispatchers/playwrightDispatcher.js +108 -0
- package/lib/server/dispatchers/selectorsDispatcher.js +36 -0
- package/lib/server/dispatchers/streamDispatcher.js +67 -0
- package/lib/server/dispatchers/tracingDispatcher.js +68 -0
- package/lib/server/dispatchers/webSocketRouteDispatcher.js +165 -0
- package/lib/server/dispatchers/writableStreamDispatcher.js +79 -0
- package/lib/server/dom.js +806 -0
- package/lib/server/download.js +70 -0
- package/lib/server/electron/electron.js +270 -0
- package/lib/server/electron/loader.js +29 -0
- package/lib/server/errors.js +69 -0
- package/lib/server/fetch.js +621 -0
- package/lib/server/fileChooser.js +43 -0
- package/lib/server/fileUploadUtils.js +84 -0
- package/lib/server/firefox/ffAccessibility.js +238 -0
- package/lib/server/firefox/ffBrowser.js +428 -0
- package/lib/server/firefox/ffConnection.js +147 -0
- package/lib/server/firefox/ffExecutionContext.js +150 -0
- package/lib/server/firefox/ffInput.js +159 -0
- package/lib/server/firefox/ffNetworkManager.js +256 -0
- package/lib/server/firefox/ffPage.js +503 -0
- package/lib/server/firefox/firefox.js +116 -0
- package/lib/server/firefox/protocol.d.js +16 -0
- package/lib/server/formData.js +147 -0
- package/lib/server/frameSelectors.js +156 -0
- package/lib/server/frames.js +1502 -0
- package/lib/server/har/harRecorder.js +147 -0
- package/lib/server/har/harTracer.js +607 -0
- package/lib/server/harBackend.js +157 -0
- package/lib/server/helper.js +96 -0
- package/lib/server/index.js +58 -0
- package/lib/server/input.js +273 -0
- package/lib/server/instrumentation.js +69 -0
- package/lib/server/isomorphic/utilityScriptSerializers.js +212 -0
- package/lib/server/javascript.js +291 -0
- package/lib/server/launchApp.js +128 -0
- package/lib/server/localUtils.js +218 -0
- package/lib/server/macEditingCommands.js +143 -0
- package/lib/server/network.js +629 -0
- package/lib/server/page.js +871 -0
- package/lib/server/pipeTransport.js +89 -0
- package/lib/server/playwright.js +69 -0
- package/lib/server/progress.js +112 -0
- package/lib/server/protocolError.js +52 -0
- package/lib/server/recorder/chat.js +161 -0
- package/lib/server/recorder/codeGenerator.js +153 -0
- package/lib/server/recorder/csharp.js +310 -0
- package/lib/server/recorder/java.js +248 -0
- package/lib/server/recorder/javascript.js +229 -0
- package/lib/server/recorder/jsonl.js +47 -0
- package/lib/server/recorder/language.js +44 -0
- package/lib/server/recorder/python.js +276 -0
- package/lib/server/recorder/recorderActions.js +5 -0
- package/lib/server/recorder/recorderApp.js +387 -0
- package/lib/server/recorder/recorderRunner.js +138 -0
- package/lib/server/recorder/recorderSignalProcessor.js +83 -0
- package/lib/server/recorder/recorderUtils.js +157 -0
- package/lib/server/recorder/throttledFile.js +57 -0
- package/lib/server/recorder/utils.js +45 -0
- package/lib/server/recorder.js +499 -0
- package/lib/server/registry/browserFetcher.js +175 -0
- package/lib/server/registry/dependencies.js +371 -0
- package/lib/server/registry/index.js +1331 -0
- package/lib/server/registry/nativeDeps.js +1280 -0
- package/lib/server/registry/oopDownloadBrowserMain.js +120 -0
- package/lib/server/screenshotter.js +333 -0
- package/lib/server/selectors.js +112 -0
- package/lib/server/socksClientCertificatesInterceptor.js +383 -0
- package/lib/server/socksInterceptor.js +95 -0
- package/lib/server/stably/ai-tools/http-request.js +70 -0
- package/lib/server/stably/ai-tools/stablyApiCaller.js +137 -0
- package/lib/server/stably/autohealing/elementHandleFromCoordinates.js +64 -0
- package/lib/server/stably/autohealing/healingService.js +228 -0
- package/lib/server/stably/autohealing/screenshotFrame.js +41 -0
- package/lib/server/stably/constants.js +31 -0
- package/lib/server/trace/recorder/snapshotter.js +147 -0
- package/lib/server/trace/recorder/snapshotterInjected.js +541 -0
- package/lib/server/trace/recorder/tracing.js +602 -0
- package/lib/server/trace/test/inMemorySnapshotter.js +87 -0
- package/lib/server/trace/viewer/traceViewer.js +240 -0
- package/lib/server/transport.js +181 -0
- package/lib/server/types.js +28 -0
- package/lib/server/usKeyboardLayout.js +145 -0
- package/lib/server/utils/ascii.js +44 -0
- package/lib/server/utils/comparators.js +161 -0
- package/lib/server/utils/crypto.js +216 -0
- package/lib/server/utils/debug.js +42 -0
- package/lib/server/utils/debugLogger.js +122 -0
- package/lib/server/utils/env.js +73 -0
- package/lib/server/utils/eventsHelper.js +39 -0
- package/lib/server/utils/expectUtils.js +38 -0
- package/lib/server/utils/fileUtils.js +191 -0
- package/lib/server/utils/happyEyeballs.js +207 -0
- package/lib/server/utils/hostPlatform.js +111 -0
- package/lib/server/utils/httpServer.js +218 -0
- package/lib/server/utils/image_tools/colorUtils.js +89 -0
- package/lib/server/utils/image_tools/compare.js +109 -0
- package/lib/server/utils/image_tools/imageChannel.js +78 -0
- package/lib/server/utils/image_tools/stats.js +102 -0
- package/lib/server/utils/linuxUtils.js +71 -0
- package/lib/server/utils/network.js +233 -0
- package/lib/server/utils/nodePlatform.js +148 -0
- package/lib/server/utils/pipeTransport.js +84 -0
- package/lib/server/utils/processLauncher.js +241 -0
- package/lib/server/utils/profiler.js +65 -0
- package/lib/server/utils/socksProxy.js +511 -0
- package/lib/server/utils/spawnAsync.js +41 -0
- package/lib/server/utils/task.js +51 -0
- package/lib/server/utils/userAgent.js +98 -0
- package/lib/server/utils/wsServer.js +121 -0
- package/lib/server/utils/zipFile.js +74 -0
- package/lib/server/utils/zones.js +57 -0
- package/lib/server/webkit/protocol.d.js +16 -0
- package/lib/server/webkit/webkit.js +119 -0
- package/lib/server/webkit/wkAccessibility.js +237 -0
- package/lib/server/webkit/wkBrowser.js +339 -0
- package/lib/server/webkit/wkConnection.js +149 -0
- package/lib/server/webkit/wkExecutionContext.js +154 -0
- package/lib/server/webkit/wkInput.js +181 -0
- package/lib/server/webkit/wkInterceptableRequest.js +169 -0
- package/lib/server/webkit/wkPage.js +1134 -0
- package/lib/server/webkit/wkProvisionalPage.js +83 -0
- package/lib/server/webkit/wkWorkers.js +104 -0
- package/lib/server/webkit/wsl/webkit-wsl-transport-client.js +74 -0
- package/lib/server/webkit/wsl/webkit-wsl-transport-server.js +113 -0
- package/lib/third_party/diff_match_patch.js +2222 -0
- package/lib/third_party/pixelmatch.js +255 -0
- package/lib/utils/ascii.js +31 -0
- package/lib/utils/comparators.js +171 -0
- package/lib/utils/crypto.js +33 -0
- package/lib/utils/debug.js +46 -0
- package/lib/utils/debugLogger.js +89 -0
- package/lib/utils/env.js +49 -0
- package/lib/utils/eventsHelper.js +38 -0
- package/lib/utils/fileUtils.js +205 -0
- package/lib/utils/glob.js +83 -0
- package/lib/utils/happy-eyeballs.js +160 -0
- package/lib/utils/headers.js +52 -0
- package/lib/utils/hostPlatform.js +128 -0
- package/lib/utils/httpServer.js +236 -0
- package/lib/utils/index.js +346 -0
- package/lib/utils/isomorphic/ariaSnapshot.js +392 -0
- package/lib/utils/isomorphic/assert.js +31 -0
- package/lib/utils/isomorphic/colors.js +72 -0
- package/lib/utils/isomorphic/cssParser.js +245 -0
- package/lib/utils/isomorphic/cssTokenizer.js +1051 -0
- package/lib/utils/isomorphic/headers.js +53 -0
- package/lib/utils/isomorphic/locatorGenerators.js +673 -0
- package/lib/utils/isomorphic/locatorParser.js +176 -0
- package/lib/utils/isomorphic/locatorUtils.js +81 -0
- package/lib/utils/isomorphic/manualPromise.js +114 -0
- package/lib/utils/isomorphic/mimeType.js +459 -0
- package/lib/utils/isomorphic/multimap.js +80 -0
- package/lib/utils/isomorphic/protocolFormatter.js +78 -0
- package/lib/utils/isomorphic/protocolMetainfo.js +321 -0
- package/lib/utils/isomorphic/rtti.js +43 -0
- package/lib/utils/isomorphic/selectorParser.js +386 -0
- package/lib/utils/isomorphic/semaphore.js +54 -0
- package/lib/utils/isomorphic/stackTrace.js +158 -0
- package/lib/utils/isomorphic/stringUtils.js +155 -0
- package/lib/utils/isomorphic/time.js +49 -0
- package/lib/utils/isomorphic/timeoutRunner.js +66 -0
- package/lib/utils/isomorphic/traceUtils.js +58 -0
- package/lib/utils/isomorphic/types.js +16 -0
- package/lib/utils/isomorphic/urlMatch.js +176 -0
- package/lib/utils/isomorphic/utilityScriptSerializers.js +251 -0
- package/lib/utils/linuxUtils.js +78 -0
- package/lib/utils/manualPromise.js +109 -0
- package/lib/utils/mimeType.js +29 -0
- package/lib/utils/multimap.js +75 -0
- package/lib/utils/network.js +188 -0
- package/lib/utils/processLauncher.js +248 -0
- package/lib/utils/profiler.js +53 -0
- package/lib/utils/rtti.js +44 -0
- package/lib/utils/semaphore.js +51 -0
- package/lib/utils/spawnAsync.js +45 -0
- package/lib/utils/stackTrace.js +121 -0
- package/lib/utils/task.js +58 -0
- package/lib/utils/time.js +37 -0
- package/lib/utils/timeoutRunner.js +66 -0
- package/lib/utils/traceUtils.js +44 -0
- package/lib/utils/userAgent.js +105 -0
- package/lib/utils/wsServer.js +127 -0
- package/lib/utils/zipFile.js +75 -0
- package/lib/utils/zones.js +62 -0
- package/lib/utils.js +107 -0
- package/lib/utilsBundle.js +109 -0
- package/lib/utilsBundleImpl/index.js +218 -0
- package/lib/utilsBundleImpl/xdg-open +1066 -0
- package/lib/vite/htmlReport/index.html +84 -0
- package/lib/vite/recorder/assets/codeMirrorModule-C3UTv-Ge.css +1 -0
- package/lib/vite/recorder/assets/codeMirrorModule-RJCXzfmE.js +24 -0
- package/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
- package/lib/vite/recorder/assets/index-Ri0uHF7I.css +1 -0
- package/lib/vite/recorder/assets/index-Y-X2TGJv.js +193 -0
- package/lib/vite/recorder/index.html +29 -0
- package/lib/vite/recorder/playwright-logo.svg +9 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-Bhnc5o2x.js +24 -0
- package/lib/vite/traceViewer/assets/defaultSettingsView-ClwvkA2N.js +265 -0
- package/lib/vite/traceViewer/assets/xtermModule-CsJ4vdCR.js +9 -0
- package/lib/vite/traceViewer/codeMirrorModule.C3UTv-Ge.css +1 -0
- package/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
- package/lib/vite/traceViewer/defaultSettingsView.TQ8_7ybu.css +1 -0
- package/lib/vite/traceViewer/index.DFO9NNF5.js +2 -0
- package/lib/vite/traceViewer/index.I8N9v4jT.css +1 -0
- package/lib/vite/traceViewer/index.html +43 -0
- package/lib/vite/traceViewer/playwright-logo.svg +9 -0
- package/lib/vite/traceViewer/snapshot.html +21 -0
- package/lib/vite/traceViewer/sw.bundle.js +3 -0
- package/lib/vite/traceViewer/uiMode.Btcz36p_.css +1 -0
- package/lib/vite/traceViewer/uiMode.Shu3QS-1.js +5 -0
- package/lib/vite/traceViewer/uiMode.html +17 -0
- package/lib/vite/traceViewer/xtermModule.DYP7pi_n.css +32 -0
- package/lib/zipBundle.js +34 -0
- package/lib/zipBundleImpl.js +5 -0
- package/package.json +43 -0
- package/types/protocol.d.ts +23130 -0
- package/types/structs.d.ts +45 -0
- package/types/types.d.ts +22857 -0
@@ -0,0 +1,871 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var page_exports = {};
|
30
|
+
__export(page_exports, {
|
31
|
+
InitScript: () => InitScript,
|
32
|
+
Page: () => Page,
|
33
|
+
PageBinding: () => PageBinding,
|
34
|
+
Worker: () => Worker
|
35
|
+
});
|
36
|
+
module.exports = __toCommonJS(page_exports);
|
37
|
+
var accessibility = __toESM(require("./accessibility"));
|
38
|
+
var import_browserContext = require("./browserContext");
|
39
|
+
var import_console = require("./console");
|
40
|
+
var import_errors = require("./errors");
|
41
|
+
var import_fileChooser = require("./fileChooser");
|
42
|
+
var frames = __toESM(require("./frames"));
|
43
|
+
var import_helper = require("./helper");
|
44
|
+
var input = __toESM(require("./input"));
|
45
|
+
var import_instrumentation = require("./instrumentation");
|
46
|
+
var js = __toESM(require("./javascript"));
|
47
|
+
var import_screenshotter = require("./screenshotter");
|
48
|
+
var import_utils = require("../utils");
|
49
|
+
var import_utils2 = require("../utils");
|
50
|
+
var import_comparators = require("./utils/comparators");
|
51
|
+
var import_debugLogger = require("./utils/debugLogger");
|
52
|
+
var import_selectorParser = require("../utils/isomorphic/selectorParser");
|
53
|
+
var import_manualPromise = require("../utils/isomorphic/manualPromise");
|
54
|
+
var import_utilityScriptSerializers = require("../utils/isomorphic/utilityScriptSerializers");
|
55
|
+
var import_callLog = require("./callLog");
|
56
|
+
var rawBindingsControllerSource = __toESM(require("../generated/bindingsControllerSource"));
|
57
|
+
class Page extends import_instrumentation.SdkObject {
|
58
|
+
constructor(delegate, browserContext) {
|
59
|
+
super(browserContext, "page");
|
60
|
+
this._closedState = "open";
|
61
|
+
this._closedPromise = new import_manualPromise.ManualPromise();
|
62
|
+
this._initializedPromise = new import_manualPromise.ManualPromise();
|
63
|
+
this._consoleMessages = [];
|
64
|
+
this._pageErrors = [];
|
65
|
+
this._crashed = false;
|
66
|
+
this.openScope = new import_utils.LongStandingScope();
|
67
|
+
this._emulatedMedia = {};
|
68
|
+
this._fileChooserInterceptedBy = /* @__PURE__ */ new Set();
|
69
|
+
this._pageBindings = /* @__PURE__ */ new Map();
|
70
|
+
this.initScripts = [];
|
71
|
+
this._workers = /* @__PURE__ */ new Map();
|
72
|
+
this.requestInterceptors = [];
|
73
|
+
this.video = null;
|
74
|
+
this._locatorHandlers = /* @__PURE__ */ new Map();
|
75
|
+
this._lastLocatorHandlerUid = 0;
|
76
|
+
this._locatorHandlerRunningCounter = 0;
|
77
|
+
this._networkRequests = [];
|
78
|
+
// Aiming at 25 fps by default - each frame is 40ms, but we give some slack with 35ms.
|
79
|
+
// When throttling for tracing, 200ms between frames, except for 10 frames around the action.
|
80
|
+
this._frameThrottler = new FrameThrottler(10, 35, 200);
|
81
|
+
this.lastSnapshotFrameIds = [];
|
82
|
+
this.attribution.page = this;
|
83
|
+
this.delegate = delegate;
|
84
|
+
this.browserContext = browserContext;
|
85
|
+
this.accessibility = new accessibility.Accessibility(delegate.getAccessibilityTree.bind(delegate));
|
86
|
+
this.keyboard = new input.Keyboard(delegate.rawKeyboard, this);
|
87
|
+
this.mouse = new input.Mouse(delegate.rawMouse, this);
|
88
|
+
this.touchscreen = new input.Touchscreen(delegate.rawTouchscreen, this);
|
89
|
+
this.screenshotter = new import_screenshotter.Screenshotter(this);
|
90
|
+
this.frameManager = new frames.FrameManager(this);
|
91
|
+
if (delegate.pdf)
|
92
|
+
this.pdf = delegate.pdf.bind(delegate);
|
93
|
+
this.coverage = delegate.coverage ? delegate.coverage() : null;
|
94
|
+
this.isStorageStatePage = browserContext.isCreatingStorageStatePage();
|
95
|
+
}
|
96
|
+
static {
|
97
|
+
this.Events = {
|
98
|
+
Close: "close",
|
99
|
+
Crash: "crash",
|
100
|
+
Download: "download",
|
101
|
+
EmulatedSizeChanged: "emulatedsizechanged",
|
102
|
+
FileChooser: "filechooser",
|
103
|
+
FrameAttached: "frameattached",
|
104
|
+
FrameDetached: "framedetached",
|
105
|
+
InternalFrameNavigatedToNewDocument: "internalframenavigatedtonewdocument",
|
106
|
+
LocatorHandlerTriggered: "locatorhandlertriggered",
|
107
|
+
ScreencastFrame: "screencastframe",
|
108
|
+
Video: "video",
|
109
|
+
WebSocket: "websocket",
|
110
|
+
Worker: "worker"
|
111
|
+
};
|
112
|
+
}
|
113
|
+
async reportAsNew(opener, error) {
|
114
|
+
if (opener) {
|
115
|
+
const openerPageOrError = await opener.waitForInitializedOrError();
|
116
|
+
if (openerPageOrError instanceof Page && !openerPageOrError.isClosed())
|
117
|
+
this._opener = openerPageOrError;
|
118
|
+
}
|
119
|
+
this._markInitialized(error);
|
120
|
+
}
|
121
|
+
_markInitialized(error = void 0) {
|
122
|
+
if (error) {
|
123
|
+
if (this.browserContext.isClosingOrClosed())
|
124
|
+
return;
|
125
|
+
this.frameManager.createDummyMainFrameIfNeeded();
|
126
|
+
}
|
127
|
+
this._initialized = error || this;
|
128
|
+
this.emitOnContext(import_browserContext.BrowserContext.Events.Page, this);
|
129
|
+
for (const pageError of this._pageErrors)
|
130
|
+
this.emitOnContext(import_browserContext.BrowserContext.Events.PageError, pageError, this);
|
131
|
+
for (const message of this._consoleMessages)
|
132
|
+
this.emitOnContext(import_browserContext.BrowserContext.Events.Console, message);
|
133
|
+
if (this.isClosed())
|
134
|
+
this.emit(Page.Events.Close);
|
135
|
+
else
|
136
|
+
this.instrumentation.onPageOpen(this);
|
137
|
+
this._initializedPromise.resolve(this._initialized);
|
138
|
+
}
|
139
|
+
initializedOrUndefined() {
|
140
|
+
return this._initialized ? this : void 0;
|
141
|
+
}
|
142
|
+
waitForInitializedOrError() {
|
143
|
+
return this._initializedPromise;
|
144
|
+
}
|
145
|
+
emitOnContext(event, ...args) {
|
146
|
+
if (this.isStorageStatePage)
|
147
|
+
return;
|
148
|
+
this.browserContext.emit(event, ...args);
|
149
|
+
}
|
150
|
+
async resetForReuse(progress) {
|
151
|
+
await this.mainFrame().gotoImpl(progress, "about:blank", {});
|
152
|
+
this._emulatedSize = void 0;
|
153
|
+
this._emulatedMedia = {};
|
154
|
+
this._extraHTTPHeaders = void 0;
|
155
|
+
await Promise.all([
|
156
|
+
this.delegate.updateEmulatedViewportSize(),
|
157
|
+
this.delegate.updateEmulateMedia(),
|
158
|
+
this.delegate.updateExtraHTTPHeaders()
|
159
|
+
]);
|
160
|
+
await this.delegate.resetForReuse(progress);
|
161
|
+
}
|
162
|
+
_didClose() {
|
163
|
+
this.frameManager.dispose();
|
164
|
+
this._frameThrottler.dispose();
|
165
|
+
(0, import_utils.assert)(this._closedState !== "closed", "Page closed twice");
|
166
|
+
this._closedState = "closed";
|
167
|
+
this.emit(Page.Events.Close);
|
168
|
+
this._closedPromise.resolve();
|
169
|
+
this.instrumentation.onPageClose(this);
|
170
|
+
this.openScope.close(new import_errors.TargetClosedError());
|
171
|
+
}
|
172
|
+
_didCrash() {
|
173
|
+
this.frameManager.dispose();
|
174
|
+
this._frameThrottler.dispose();
|
175
|
+
this.emit(Page.Events.Crash);
|
176
|
+
this._crashed = true;
|
177
|
+
this.instrumentation.onPageClose(this);
|
178
|
+
this.openScope.close(new Error("Page crashed"));
|
179
|
+
}
|
180
|
+
async _onFileChooserOpened(handle) {
|
181
|
+
let multiple;
|
182
|
+
try {
|
183
|
+
multiple = await handle.evaluate((element) => !!element.multiple);
|
184
|
+
} catch (e) {
|
185
|
+
return;
|
186
|
+
}
|
187
|
+
if (!this.listenerCount(Page.Events.FileChooser)) {
|
188
|
+
handle.dispose();
|
189
|
+
return;
|
190
|
+
}
|
191
|
+
const fileChooser = new import_fileChooser.FileChooser(this, handle, multiple);
|
192
|
+
this.emit(Page.Events.FileChooser, fileChooser);
|
193
|
+
}
|
194
|
+
opener() {
|
195
|
+
return this._opener;
|
196
|
+
}
|
197
|
+
mainFrame() {
|
198
|
+
return this.frameManager.mainFrame();
|
199
|
+
}
|
200
|
+
frames() {
|
201
|
+
return this.frameManager.frames();
|
202
|
+
}
|
203
|
+
async exposeBinding(progress, name, needsHandle, playwrightBinding) {
|
204
|
+
if (this._pageBindings.has(name))
|
205
|
+
throw new Error(`Function "${name}" has been already registered`);
|
206
|
+
if (this.browserContext._pageBindings.has(name))
|
207
|
+
throw new Error(`Function "${name}" has been already registered in the browser context`);
|
208
|
+
await progress.race(this.browserContext.exposePlaywrightBindingIfNeeded());
|
209
|
+
const binding = new PageBinding(name, playwrightBinding, needsHandle);
|
210
|
+
this._pageBindings.set(name, binding);
|
211
|
+
try {
|
212
|
+
await progress.race(this.delegate.addInitScript(binding.initScript));
|
213
|
+
await progress.race(this.safeNonStallingEvaluateInAllFrames(binding.initScript.source, "main"));
|
214
|
+
return binding;
|
215
|
+
} catch (error) {
|
216
|
+
this._pageBindings.delete(name);
|
217
|
+
throw error;
|
218
|
+
}
|
219
|
+
}
|
220
|
+
async removeExposedBindings(bindings) {
|
221
|
+
bindings = bindings.filter((binding) => this._pageBindings.get(binding.name) === binding);
|
222
|
+
for (const binding of bindings)
|
223
|
+
this._pageBindings.delete(binding.name);
|
224
|
+
await this.delegate.removeInitScripts(bindings.map((binding) => binding.initScript));
|
225
|
+
const cleanup = bindings.map((binding) => `{ ${binding.cleanupScript} };
|
226
|
+
`).join("");
|
227
|
+
await this.safeNonStallingEvaluateInAllFrames(cleanup, "main");
|
228
|
+
}
|
229
|
+
async setExtraHTTPHeaders(progress, headers) {
|
230
|
+
const oldHeaders = this._extraHTTPHeaders;
|
231
|
+
try {
|
232
|
+
this._extraHTTPHeaders = headers;
|
233
|
+
await progress.race(this.delegate.updateExtraHTTPHeaders());
|
234
|
+
} catch (error) {
|
235
|
+
this._extraHTTPHeaders = oldHeaders;
|
236
|
+
this.delegate.updateExtraHTTPHeaders().catch(() => {
|
237
|
+
});
|
238
|
+
throw error;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
extraHTTPHeaders() {
|
242
|
+
return this._extraHTTPHeaders;
|
243
|
+
}
|
244
|
+
addNetworkRequest(request) {
|
245
|
+
this._networkRequests.push(request);
|
246
|
+
ensureArrayLimit(this._networkRequests, 100);
|
247
|
+
}
|
248
|
+
networkRequests() {
|
249
|
+
return this._networkRequests;
|
250
|
+
}
|
251
|
+
async onBindingCalled(payload, context) {
|
252
|
+
if (this._closedState === "closed")
|
253
|
+
return;
|
254
|
+
await PageBinding.dispatch(this, payload, context);
|
255
|
+
}
|
256
|
+
addConsoleMessage(type, args, location, text) {
|
257
|
+
const message = new import_console.ConsoleMessage(this, type, text, args, location);
|
258
|
+
const intercepted = this.frameManager.interceptConsoleMessage(message);
|
259
|
+
if (intercepted) {
|
260
|
+
args.forEach((arg) => arg.dispose());
|
261
|
+
return;
|
262
|
+
}
|
263
|
+
this._consoleMessages.push(message);
|
264
|
+
ensureArrayLimit(this._consoleMessages, 200);
|
265
|
+
if (this._initialized)
|
266
|
+
this.emitOnContext(import_browserContext.BrowserContext.Events.Console, message);
|
267
|
+
}
|
268
|
+
consoleMessages() {
|
269
|
+
return this._consoleMessages;
|
270
|
+
}
|
271
|
+
addPageError(pageError) {
|
272
|
+
this._pageErrors.push(pageError);
|
273
|
+
ensureArrayLimit(this._pageErrors, 200);
|
274
|
+
if (this._initialized)
|
275
|
+
this.emitOnContext(import_browserContext.BrowserContext.Events.PageError, pageError, this);
|
276
|
+
}
|
277
|
+
pageErrors() {
|
278
|
+
return this._pageErrors;
|
279
|
+
}
|
280
|
+
async reload(progress, options) {
|
281
|
+
return this.mainFrame().raceNavigationAction(progress, async () => {
|
282
|
+
const [response] = await Promise.all([
|
283
|
+
// Reload must be a new document, and should not be confused with a stray pushState.
|
284
|
+
this.mainFrame()._waitForNavigation(progress, true, options),
|
285
|
+
progress.race(this.delegate.reload())
|
286
|
+
]);
|
287
|
+
return response;
|
288
|
+
});
|
289
|
+
}
|
290
|
+
async goBack(progress, options) {
|
291
|
+
return this.mainFrame().raceNavigationAction(progress, async () => {
|
292
|
+
let error;
|
293
|
+
const waitPromise = this.mainFrame()._waitForNavigation(progress, false, options).catch((e) => {
|
294
|
+
error = e;
|
295
|
+
return null;
|
296
|
+
});
|
297
|
+
const result = await progress.race(this.delegate.goBack());
|
298
|
+
if (!result) {
|
299
|
+
waitPromise.catch(() => {
|
300
|
+
});
|
301
|
+
return null;
|
302
|
+
}
|
303
|
+
const response = await waitPromise;
|
304
|
+
if (error)
|
305
|
+
throw error;
|
306
|
+
return response;
|
307
|
+
});
|
308
|
+
}
|
309
|
+
async goForward(progress, options) {
|
310
|
+
return this.mainFrame().raceNavigationAction(progress, async () => {
|
311
|
+
let error;
|
312
|
+
const waitPromise = this.mainFrame()._waitForNavigation(progress, false, options).catch((e) => {
|
313
|
+
error = e;
|
314
|
+
return null;
|
315
|
+
});
|
316
|
+
const result = await progress.race(this.delegate.goForward());
|
317
|
+
if (!result) {
|
318
|
+
waitPromise.catch(() => {
|
319
|
+
});
|
320
|
+
return null;
|
321
|
+
}
|
322
|
+
const response = await waitPromise;
|
323
|
+
if (error)
|
324
|
+
throw error;
|
325
|
+
return response;
|
326
|
+
});
|
327
|
+
}
|
328
|
+
requestGC() {
|
329
|
+
return this.delegate.requestGC();
|
330
|
+
}
|
331
|
+
registerLocatorHandler(selector, noWaitAfter) {
|
332
|
+
const uid = ++this._lastLocatorHandlerUid;
|
333
|
+
this._locatorHandlers.set(uid, { selector, noWaitAfter });
|
334
|
+
return uid;
|
335
|
+
}
|
336
|
+
resolveLocatorHandler(uid, remove) {
|
337
|
+
const handler = this._locatorHandlers.get(uid);
|
338
|
+
if (remove)
|
339
|
+
this._locatorHandlers.delete(uid);
|
340
|
+
if (handler) {
|
341
|
+
handler.resolved?.resolve();
|
342
|
+
handler.resolved = void 0;
|
343
|
+
}
|
344
|
+
}
|
345
|
+
unregisterLocatorHandler(uid) {
|
346
|
+
this._locatorHandlers.delete(uid);
|
347
|
+
}
|
348
|
+
async performActionPreChecks(progress) {
|
349
|
+
await this._performWaitForNavigationCheck(progress);
|
350
|
+
await this._performLocatorHandlersCheckpoint(progress);
|
351
|
+
await this._performWaitForNavigationCheck(progress);
|
352
|
+
}
|
353
|
+
async _performWaitForNavigationCheck(progress) {
|
354
|
+
const mainFrame = this.frameManager.mainFrame();
|
355
|
+
if (!mainFrame || !mainFrame.pendingDocument())
|
356
|
+
return;
|
357
|
+
const url = mainFrame.pendingDocument()?.request?.url();
|
358
|
+
const toUrl = url ? `" ${(0, import_utils.trimStringWithEllipsis)(url, 200)}"` : "";
|
359
|
+
progress.log(` waiting for${toUrl} navigation to finish...`);
|
360
|
+
await import_helper.helper.waitForEvent(progress, mainFrame, frames.Frame.Events.InternalNavigation, (e) => {
|
361
|
+
if (!e.isPublic)
|
362
|
+
return false;
|
363
|
+
if (!e.error)
|
364
|
+
progress.log(` navigated to "${(0, import_utils.trimStringWithEllipsis)(mainFrame.url(), 200)}"`);
|
365
|
+
return true;
|
366
|
+
}).promise;
|
367
|
+
}
|
368
|
+
async _performLocatorHandlersCheckpoint(progress) {
|
369
|
+
if (this._locatorHandlerRunningCounter)
|
370
|
+
return;
|
371
|
+
for (const [uid, handler] of this._locatorHandlers) {
|
372
|
+
if (!handler.resolved) {
|
373
|
+
if (await this.mainFrame().isVisibleInternal(progress, handler.selector, { strict: true })) {
|
374
|
+
handler.resolved = new import_manualPromise.ManualPromise();
|
375
|
+
this.emit(Page.Events.LocatorHandlerTriggered, uid);
|
376
|
+
}
|
377
|
+
}
|
378
|
+
if (handler.resolved) {
|
379
|
+
++this._locatorHandlerRunningCounter;
|
380
|
+
progress.log(` found ${(0, import_utils2.asLocator)(this.browserContext._browser.sdkLanguage(), handler.selector)}, intercepting action to run the handler`);
|
381
|
+
const promise = handler.resolved.then(async () => {
|
382
|
+
if (!handler.noWaitAfter) {
|
383
|
+
progress.log(` locator handler has finished, waiting for ${(0, import_utils2.asLocator)(this.browserContext._browser.sdkLanguage(), handler.selector)} to be hidden`);
|
384
|
+
await this.mainFrame().waitForSelector(progress, handler.selector, false, { state: "hidden" });
|
385
|
+
} else {
|
386
|
+
progress.log(` locator handler has finished`);
|
387
|
+
}
|
388
|
+
});
|
389
|
+
await progress.race(this.openScope.race(promise)).finally(() => --this._locatorHandlerRunningCounter);
|
390
|
+
progress.log(` interception handler has finished, continuing`);
|
391
|
+
}
|
392
|
+
}
|
393
|
+
}
|
394
|
+
async emulateMedia(progress, options) {
|
395
|
+
const oldEmulatedMedia = { ...this._emulatedMedia };
|
396
|
+
if (options.media !== void 0)
|
397
|
+
this._emulatedMedia.media = options.media;
|
398
|
+
if (options.colorScheme !== void 0)
|
399
|
+
this._emulatedMedia.colorScheme = options.colorScheme;
|
400
|
+
if (options.reducedMotion !== void 0)
|
401
|
+
this._emulatedMedia.reducedMotion = options.reducedMotion;
|
402
|
+
if (options.forcedColors !== void 0)
|
403
|
+
this._emulatedMedia.forcedColors = options.forcedColors;
|
404
|
+
if (options.contrast !== void 0)
|
405
|
+
this._emulatedMedia.contrast = options.contrast;
|
406
|
+
try {
|
407
|
+
await progress.race(this.delegate.updateEmulateMedia());
|
408
|
+
} catch (error) {
|
409
|
+
this._emulatedMedia = oldEmulatedMedia;
|
410
|
+
this.delegate.updateEmulateMedia().catch(() => {
|
411
|
+
});
|
412
|
+
throw error;
|
413
|
+
}
|
414
|
+
}
|
415
|
+
emulatedMedia() {
|
416
|
+
const contextOptions = this.browserContext._options;
|
417
|
+
return {
|
418
|
+
media: this._emulatedMedia.media || "no-override",
|
419
|
+
colorScheme: this._emulatedMedia.colorScheme !== void 0 ? this._emulatedMedia.colorScheme : contextOptions.colorScheme ?? "light",
|
420
|
+
reducedMotion: this._emulatedMedia.reducedMotion !== void 0 ? this._emulatedMedia.reducedMotion : contextOptions.reducedMotion ?? "no-preference",
|
421
|
+
forcedColors: this._emulatedMedia.forcedColors !== void 0 ? this._emulatedMedia.forcedColors : contextOptions.forcedColors ?? "none",
|
422
|
+
contrast: this._emulatedMedia.contrast !== void 0 ? this._emulatedMedia.contrast : contextOptions.contrast ?? "no-preference"
|
423
|
+
};
|
424
|
+
}
|
425
|
+
async setViewportSize(progress, viewportSize) {
|
426
|
+
const oldEmulatedSize = this._emulatedSize;
|
427
|
+
try {
|
428
|
+
this._setEmulatedSize({ viewport: { ...viewportSize }, screen: { ...viewportSize } });
|
429
|
+
await progress.race(this.delegate.updateEmulatedViewportSize());
|
430
|
+
} catch (error) {
|
431
|
+
this._emulatedSize = oldEmulatedSize;
|
432
|
+
this.delegate.updateEmulatedViewportSize().catch(() => {
|
433
|
+
});
|
434
|
+
throw error;
|
435
|
+
}
|
436
|
+
}
|
437
|
+
setEmulatedSizeFromWindowOpen(emulatedSize) {
|
438
|
+
this._setEmulatedSize(emulatedSize);
|
439
|
+
}
|
440
|
+
_setEmulatedSize(emulatedSize) {
|
441
|
+
this._emulatedSize = emulatedSize;
|
442
|
+
this.emit(Page.Events.EmulatedSizeChanged);
|
443
|
+
}
|
444
|
+
emulatedSize() {
|
445
|
+
if (this._emulatedSize)
|
446
|
+
return this._emulatedSize;
|
447
|
+
const contextOptions = this.browserContext._options;
|
448
|
+
return contextOptions.viewport ? { viewport: contextOptions.viewport, screen: contextOptions.screen || contextOptions.viewport } : void 0;
|
449
|
+
}
|
450
|
+
async bringToFront() {
|
451
|
+
await this.delegate.bringToFront();
|
452
|
+
}
|
453
|
+
async addInitScript(progress, source) {
|
454
|
+
const initScript = new InitScript(source);
|
455
|
+
this.initScripts.push(initScript);
|
456
|
+
try {
|
457
|
+
await progress.race(this.delegate.addInitScript(initScript));
|
458
|
+
} catch (error) {
|
459
|
+
this.removeInitScripts([initScript]).catch(() => {
|
460
|
+
});
|
461
|
+
throw error;
|
462
|
+
}
|
463
|
+
return initScript;
|
464
|
+
}
|
465
|
+
async removeInitScripts(initScripts) {
|
466
|
+
const set = new Set(initScripts);
|
467
|
+
this.initScripts = this.initScripts.filter((script) => !set.has(script));
|
468
|
+
await this.delegate.removeInitScripts(initScripts);
|
469
|
+
}
|
470
|
+
needsRequestInterception() {
|
471
|
+
return this.requestInterceptors.length > 0 || this.browserContext.requestInterceptors.length > 0;
|
472
|
+
}
|
473
|
+
async addRequestInterceptor(progress, handler, prepend) {
|
474
|
+
if (prepend)
|
475
|
+
this.requestInterceptors.unshift(handler);
|
476
|
+
else
|
477
|
+
this.requestInterceptors.push(handler);
|
478
|
+
await this.delegate.updateRequestInterception();
|
479
|
+
}
|
480
|
+
async removeRequestInterceptor(handler) {
|
481
|
+
const index = this.requestInterceptors.indexOf(handler);
|
482
|
+
if (index === -1)
|
483
|
+
return;
|
484
|
+
this.requestInterceptors.splice(index, 1);
|
485
|
+
await this.browserContext.notifyRoutesInFlightAboutRemovedHandler(handler);
|
486
|
+
await this.delegate.updateRequestInterception();
|
487
|
+
}
|
488
|
+
async expectScreenshot(progress, options) {
|
489
|
+
const locator = options.locator;
|
490
|
+
const rafrafScreenshot = locator ? async (timeout) => {
|
491
|
+
return await locator.frame.rafrafTimeoutScreenshotElementWithProgress(progress, locator.selector, timeout, options || {});
|
492
|
+
} : async (timeout) => {
|
493
|
+
await this.performActionPreChecks(progress);
|
494
|
+
await this.mainFrame().rafrafTimeout(progress, timeout);
|
495
|
+
return await this.screenshotter.screenshotPage(progress, options || {});
|
496
|
+
};
|
497
|
+
const comparator = (0, import_comparators.getComparator)("image/png");
|
498
|
+
if (!options.expected && options.isNot)
|
499
|
+
return { errorMessage: '"not" matcher requires expected result' };
|
500
|
+
try {
|
501
|
+
const format = (0, import_screenshotter.validateScreenshotOptions)(options || {});
|
502
|
+
if (format !== "png")
|
503
|
+
throw new Error("Only PNG screenshots are supported");
|
504
|
+
} catch (error) {
|
505
|
+
return { errorMessage: error.message };
|
506
|
+
}
|
507
|
+
let intermediateResult;
|
508
|
+
const areEqualScreenshots = (actual, expected, previous) => {
|
509
|
+
const comparatorResult = actual && expected ? comparator(actual, expected, options) : void 0;
|
510
|
+
if (comparatorResult !== void 0 && !!comparatorResult === !!options.isNot)
|
511
|
+
return true;
|
512
|
+
if (comparatorResult)
|
513
|
+
intermediateResult = { errorMessage: comparatorResult.errorMessage, diff: comparatorResult.diff, actual, previous };
|
514
|
+
return false;
|
515
|
+
};
|
516
|
+
try {
|
517
|
+
let actual;
|
518
|
+
let previous;
|
519
|
+
const pollIntervals = [0, 100, 250, 500];
|
520
|
+
progress.log(`${(0, import_utils.renderTitleForCall)(progress.metadata)}${options.timeout ? ` with timeout ${options.timeout}ms` : ""}`);
|
521
|
+
if (options.expected)
|
522
|
+
progress.log(` verifying given screenshot expectation`);
|
523
|
+
else
|
524
|
+
progress.log(` generating new stable screenshot expectation`);
|
525
|
+
let isFirstIteration = true;
|
526
|
+
while (true) {
|
527
|
+
if (this.isClosed())
|
528
|
+
throw new Error("The page has closed");
|
529
|
+
const screenshotTimeout = pollIntervals.shift() ?? 1e3;
|
530
|
+
if (screenshotTimeout)
|
531
|
+
progress.log(`waiting ${screenshotTimeout}ms before taking screenshot`);
|
532
|
+
previous = actual;
|
533
|
+
actual = await rafrafScreenshot(screenshotTimeout).catch((e) => {
|
534
|
+
if (this.mainFrame().isNonRetriableError(e))
|
535
|
+
throw e;
|
536
|
+
progress.log(`failed to take screenshot - ` + e.message);
|
537
|
+
return void 0;
|
538
|
+
});
|
539
|
+
if (!actual)
|
540
|
+
continue;
|
541
|
+
const expectation = options.expected && isFirstIteration ? options.expected : previous;
|
542
|
+
if (areEqualScreenshots(actual, expectation, previous))
|
543
|
+
break;
|
544
|
+
if (intermediateResult)
|
545
|
+
progress.log(intermediateResult.errorMessage);
|
546
|
+
isFirstIteration = false;
|
547
|
+
}
|
548
|
+
if (!isFirstIteration)
|
549
|
+
progress.log(`captured a stable screenshot`);
|
550
|
+
if (!options.expected)
|
551
|
+
return { actual };
|
552
|
+
if (isFirstIteration) {
|
553
|
+
progress.log(`screenshot matched expectation`);
|
554
|
+
return {};
|
555
|
+
}
|
556
|
+
if (areEqualScreenshots(actual, options.expected, void 0)) {
|
557
|
+
progress.log(`screenshot matched expectation`);
|
558
|
+
return {};
|
559
|
+
}
|
560
|
+
throw new Error(intermediateResult.errorMessage);
|
561
|
+
} catch (e) {
|
562
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_selectorParser.isInvalidSelectorError)(e))
|
563
|
+
throw e;
|
564
|
+
let errorMessage = e.message;
|
565
|
+
if (e instanceof import_errors.TimeoutError && intermediateResult?.previous)
|
566
|
+
errorMessage = `Failed to take two consecutive stable screenshots.`;
|
567
|
+
return {
|
568
|
+
log: (0, import_callLog.compressCallLog)(e.message ? [...progress.metadata.log, e.message] : progress.metadata.log),
|
569
|
+
...intermediateResult,
|
570
|
+
errorMessage,
|
571
|
+
timedOut: e instanceof import_errors.TimeoutError
|
572
|
+
};
|
573
|
+
}
|
574
|
+
}
|
575
|
+
async screenshot(progress, options) {
|
576
|
+
return await this.screenshotter.screenshotPage(progress, options);
|
577
|
+
}
|
578
|
+
async close(options = {}) {
|
579
|
+
if (this._closedState === "closed")
|
580
|
+
return;
|
581
|
+
if (options.reason)
|
582
|
+
this.closeReason = options.reason;
|
583
|
+
const runBeforeUnload = !!options.runBeforeUnload;
|
584
|
+
if (this._closedState !== "closing") {
|
585
|
+
if (!runBeforeUnload)
|
586
|
+
this._closedState = "closing";
|
587
|
+
await this.delegate.closePage(runBeforeUnload).catch((e) => import_debugLogger.debugLogger.log("error", e));
|
588
|
+
}
|
589
|
+
if (!runBeforeUnload)
|
590
|
+
await this._closedPromise;
|
591
|
+
}
|
592
|
+
isClosed() {
|
593
|
+
return this._closedState === "closed";
|
594
|
+
}
|
595
|
+
hasCrashed() {
|
596
|
+
return this._crashed;
|
597
|
+
}
|
598
|
+
isClosedOrClosingOrCrashed() {
|
599
|
+
return this._closedState !== "open" || this._crashed;
|
600
|
+
}
|
601
|
+
addWorker(workerId, worker) {
|
602
|
+
this._workers.set(workerId, worker);
|
603
|
+
this.emit(Page.Events.Worker, worker);
|
604
|
+
}
|
605
|
+
removeWorker(workerId) {
|
606
|
+
const worker = this._workers.get(workerId);
|
607
|
+
if (!worker)
|
608
|
+
return;
|
609
|
+
worker.didClose();
|
610
|
+
this._workers.delete(workerId);
|
611
|
+
}
|
612
|
+
clearWorkers() {
|
613
|
+
for (const [workerId, worker] of this._workers) {
|
614
|
+
worker.didClose();
|
615
|
+
this._workers.delete(workerId);
|
616
|
+
}
|
617
|
+
}
|
618
|
+
async setFileChooserInterceptedBy(enabled, by) {
|
619
|
+
const wasIntercepted = this.fileChooserIntercepted();
|
620
|
+
if (enabled)
|
621
|
+
this._fileChooserInterceptedBy.add(by);
|
622
|
+
else
|
623
|
+
this._fileChooserInterceptedBy.delete(by);
|
624
|
+
if (wasIntercepted !== this.fileChooserIntercepted())
|
625
|
+
await this.delegate.updateFileChooserInterception();
|
626
|
+
}
|
627
|
+
fileChooserIntercepted() {
|
628
|
+
return this._fileChooserInterceptedBy.size > 0;
|
629
|
+
}
|
630
|
+
frameNavigatedToNewDocument(frame) {
|
631
|
+
this.emit(Page.Events.InternalFrameNavigatedToNewDocument, frame);
|
632
|
+
const origin = frame.origin();
|
633
|
+
if (origin)
|
634
|
+
this.browserContext.addVisitedOrigin(origin);
|
635
|
+
}
|
636
|
+
allInitScripts() {
|
637
|
+
const bindings = [...this.browserContext._pageBindings.values(), ...this._pageBindings.values()].map((binding) => binding.initScript);
|
638
|
+
if (this.browserContext.bindingsInitScript)
|
639
|
+
bindings.unshift(this.browserContext.bindingsInitScript);
|
640
|
+
return [...bindings, ...this.browserContext.initScripts, ...this.initScripts];
|
641
|
+
}
|
642
|
+
getBinding(name) {
|
643
|
+
return this._pageBindings.get(name) || this.browserContext._pageBindings.get(name);
|
644
|
+
}
|
645
|
+
setScreencastOptions(options) {
|
646
|
+
this.delegate.setScreencastOptions(options).catch((e) => import_debugLogger.debugLogger.log("error", e));
|
647
|
+
this._frameThrottler.setThrottlingEnabled(!!options);
|
648
|
+
}
|
649
|
+
throttleScreencastFrameAck(ack) {
|
650
|
+
this._frameThrottler.ack(ack);
|
651
|
+
}
|
652
|
+
temporarilyDisableTracingScreencastThrottling() {
|
653
|
+
this._frameThrottler.recharge();
|
654
|
+
}
|
655
|
+
async safeNonStallingEvaluateInAllFrames(expression, world, options = {}) {
|
656
|
+
await Promise.all(this.frames().map(async (frame) => {
|
657
|
+
try {
|
658
|
+
await frame.nonStallingEvaluateInExistingContext(expression, world);
|
659
|
+
} catch (e) {
|
660
|
+
if (options.throwOnJSErrors && js.isJavaScriptErrorInEvaluate(e))
|
661
|
+
throw e;
|
662
|
+
}
|
663
|
+
}));
|
664
|
+
}
|
665
|
+
async hideHighlight() {
|
666
|
+
await Promise.all(this.frames().map((frame) => frame.hideHighlight().catch(() => {
|
667
|
+
})));
|
668
|
+
}
|
669
|
+
async snapshotForAI(progress) {
|
670
|
+
this.lastSnapshotFrameIds = [];
|
671
|
+
const snapshot = await snapshotFrameForAI(progress, this.mainFrame(), 0, this.lastSnapshotFrameIds);
|
672
|
+
return snapshot.join("\n");
|
673
|
+
}
|
674
|
+
}
|
675
|
+
class Worker extends import_instrumentation.SdkObject {
|
676
|
+
constructor(parent, url) {
|
677
|
+
super(parent, "worker");
|
678
|
+
this.existingExecutionContext = null;
|
679
|
+
this.openScope = new import_utils.LongStandingScope();
|
680
|
+
this.url = url;
|
681
|
+
this._executionContextCallback = () => {
|
682
|
+
};
|
683
|
+
this._executionContextPromise = new Promise((x) => this._executionContextCallback = x);
|
684
|
+
}
|
685
|
+
static {
|
686
|
+
this.Events = {
|
687
|
+
Close: "close"
|
688
|
+
};
|
689
|
+
}
|
690
|
+
createExecutionContext(delegate) {
|
691
|
+
this.existingExecutionContext = new js.ExecutionContext(this, delegate, "worker");
|
692
|
+
this._executionContextCallback(this.existingExecutionContext);
|
693
|
+
return this.existingExecutionContext;
|
694
|
+
}
|
695
|
+
didClose() {
|
696
|
+
if (this.existingExecutionContext)
|
697
|
+
this.existingExecutionContext.contextDestroyed("Worker was closed");
|
698
|
+
this.emit(Worker.Events.Close, this);
|
699
|
+
this.openScope.close(new Error("Worker closed"));
|
700
|
+
}
|
701
|
+
async evaluateExpression(expression, isFunction, arg) {
|
702
|
+
return js.evaluateExpression(await this._executionContextPromise, expression, { returnByValue: true, isFunction }, arg);
|
703
|
+
}
|
704
|
+
async evaluateExpressionHandle(expression, isFunction, arg) {
|
705
|
+
return js.evaluateExpression(await this._executionContextPromise, expression, { returnByValue: false, isFunction }, arg);
|
706
|
+
}
|
707
|
+
}
|
708
|
+
class PageBinding {
|
709
|
+
static {
|
710
|
+
this.kController = "__playwright__binding__controller__";
|
711
|
+
}
|
712
|
+
static {
|
713
|
+
this.kBindingName = "__playwright__binding__";
|
714
|
+
}
|
715
|
+
static createInitScript() {
|
716
|
+
return new InitScript(`
|
717
|
+
(() => {
|
718
|
+
const module = {};
|
719
|
+
${rawBindingsControllerSource.source}
|
720
|
+
const property = '${PageBinding.kController}';
|
721
|
+
if (!globalThis[property])
|
722
|
+
globalThis[property] = new (module.exports.BindingsController())(globalThis, '${PageBinding.kBindingName}');
|
723
|
+
})();
|
724
|
+
`);
|
725
|
+
}
|
726
|
+
constructor(name, playwrightFunction, needsHandle) {
|
727
|
+
this.name = name;
|
728
|
+
this.playwrightFunction = playwrightFunction;
|
729
|
+
this.initScript = new InitScript(`globalThis['${PageBinding.kController}'].addBinding(${JSON.stringify(name)}, ${needsHandle})`);
|
730
|
+
this.needsHandle = needsHandle;
|
731
|
+
this.cleanupScript = `globalThis['${PageBinding.kController}'].removeBinding(${JSON.stringify(name)})`;
|
732
|
+
}
|
733
|
+
static async dispatch(page, payload, context) {
|
734
|
+
const { name, seq, serializedArgs } = JSON.parse(payload);
|
735
|
+
try {
|
736
|
+
(0, import_utils.assert)(context.world);
|
737
|
+
const binding = page.getBinding(name);
|
738
|
+
if (!binding)
|
739
|
+
throw new Error(`Function "${name}" is not exposed`);
|
740
|
+
let result;
|
741
|
+
if (binding.needsHandle) {
|
742
|
+
const handle = await context.evaluateExpressionHandle(`arg => globalThis['${PageBinding.kController}'].takeBindingHandle(arg)`, { isFunction: true }, { name, seq }).catch((e) => null);
|
743
|
+
result = await binding.playwrightFunction({ frame: context.frame, page, context: page.browserContext }, handle);
|
744
|
+
} else {
|
745
|
+
if (!Array.isArray(serializedArgs))
|
746
|
+
throw new Error(`serializedArgs is not an array. This can happen when Array.prototype.toJSON is defined incorrectly`);
|
747
|
+
const args = serializedArgs.map((a) => (0, import_utilityScriptSerializers.parseEvaluationResultValue)(a));
|
748
|
+
result = await binding.playwrightFunction({ frame: context.frame, page, context: page.browserContext }, ...args);
|
749
|
+
}
|
750
|
+
context.evaluateExpressionHandle(`arg => globalThis['${PageBinding.kController}'].deliverBindingResult(arg)`, { isFunction: true }, { name, seq, result }).catch((e) => import_debugLogger.debugLogger.log("error", e));
|
751
|
+
} catch (error) {
|
752
|
+
context.evaluateExpressionHandle(`arg => globalThis['${PageBinding.kController}'].deliverBindingResult(arg)`, { isFunction: true }, { name, seq, error }).catch((e) => import_debugLogger.debugLogger.log("error", e));
|
753
|
+
}
|
754
|
+
}
|
755
|
+
}
|
756
|
+
class InitScript {
|
757
|
+
constructor(source) {
|
758
|
+
this.source = `(() => {
|
759
|
+
${source}
|
760
|
+
})();`;
|
761
|
+
}
|
762
|
+
}
|
763
|
+
class FrameThrottler {
|
764
|
+
constructor(nonThrottledFrames, defaultInterval, throttlingInterval) {
|
765
|
+
this._acks = [];
|
766
|
+
this._throttlingEnabled = false;
|
767
|
+
this._nonThrottledFrames = nonThrottledFrames;
|
768
|
+
this._budget = nonThrottledFrames;
|
769
|
+
this._defaultInterval = defaultInterval;
|
770
|
+
this._throttlingInterval = throttlingInterval;
|
771
|
+
this._tick();
|
772
|
+
}
|
773
|
+
dispose() {
|
774
|
+
if (this._timeoutId) {
|
775
|
+
clearTimeout(this._timeoutId);
|
776
|
+
this._timeoutId = void 0;
|
777
|
+
}
|
778
|
+
}
|
779
|
+
setThrottlingEnabled(enabled) {
|
780
|
+
this._throttlingEnabled = enabled;
|
781
|
+
}
|
782
|
+
recharge() {
|
783
|
+
for (const ack of this._acks)
|
784
|
+
ack();
|
785
|
+
this._acks = [];
|
786
|
+
this._budget = this._nonThrottledFrames;
|
787
|
+
if (this._timeoutId) {
|
788
|
+
clearTimeout(this._timeoutId);
|
789
|
+
this._tick();
|
790
|
+
}
|
791
|
+
}
|
792
|
+
ack(ack) {
|
793
|
+
if (!this._timeoutId) {
|
794
|
+
ack();
|
795
|
+
return;
|
796
|
+
}
|
797
|
+
this._acks.push(ack);
|
798
|
+
}
|
799
|
+
_tick() {
|
800
|
+
const ack = this._acks.shift();
|
801
|
+
if (ack) {
|
802
|
+
--this._budget;
|
803
|
+
ack();
|
804
|
+
}
|
805
|
+
if (this._throttlingEnabled && this._budget <= 0) {
|
806
|
+
this._timeoutId = setTimeout(() => this._tick(), this._throttlingInterval);
|
807
|
+
} else {
|
808
|
+
this._timeoutId = setTimeout(() => this._tick(), this._defaultInterval);
|
809
|
+
}
|
810
|
+
}
|
811
|
+
}
|
812
|
+
async function snapshotFrameForAI(progress, frame, frameOrdinal, frameIds) {
|
813
|
+
const snapshot = await frame.retryWithProgressAndTimeouts(progress, [1e3, 2e3, 4e3, 8e3], async (continuePolling) => {
|
814
|
+
try {
|
815
|
+
const context = await progress.race(frame._utilityContext());
|
816
|
+
const injectedScript = await progress.race(context.injectedScript());
|
817
|
+
const snapshotOrRetry = await progress.race(injectedScript.evaluate((injected, refPrefix) => {
|
818
|
+
const node = injected.document.body;
|
819
|
+
if (!node)
|
820
|
+
return true;
|
821
|
+
return injected.ariaSnapshot(node, { mode: "ai", refPrefix });
|
822
|
+
}, frameOrdinal ? "f" + frameOrdinal : ""));
|
823
|
+
if (snapshotOrRetry === true)
|
824
|
+
return continuePolling;
|
825
|
+
return snapshotOrRetry;
|
826
|
+
} catch (e) {
|
827
|
+
if (frame.isNonRetriableError(e))
|
828
|
+
throw e;
|
829
|
+
return continuePolling;
|
830
|
+
}
|
831
|
+
});
|
832
|
+
const lines = snapshot.split("\n");
|
833
|
+
const result = [];
|
834
|
+
for (const line of lines) {
|
835
|
+
const match = line.match(/^(\s*)- iframe (?:\[active\] )?\[ref=([^\]]*)\]/);
|
836
|
+
if (!match) {
|
837
|
+
result.push(line);
|
838
|
+
continue;
|
839
|
+
}
|
840
|
+
const leadingSpace = match[1];
|
841
|
+
const ref = match[2];
|
842
|
+
const frameSelector = `aria-ref=${ref} >> internal:control=enter-frame`;
|
843
|
+
const frameBodySelector = `${frameSelector} >> body`;
|
844
|
+
const child = await progress.race(frame.selectors.resolveFrameForSelector(frameBodySelector, { strict: true }));
|
845
|
+
if (!child) {
|
846
|
+
result.push(line);
|
847
|
+
continue;
|
848
|
+
}
|
849
|
+
const frameOrdinal2 = frameIds.length + 1;
|
850
|
+
frameIds.push(child.frame._id);
|
851
|
+
try {
|
852
|
+
const childSnapshot = await snapshotFrameForAI(progress, child.frame, frameOrdinal2, frameIds);
|
853
|
+
result.push(line + ":", ...childSnapshot.map((l) => leadingSpace + " " + l));
|
854
|
+
} catch {
|
855
|
+
result.push(line);
|
856
|
+
}
|
857
|
+
}
|
858
|
+
return result;
|
859
|
+
}
|
860
|
+
function ensureArrayLimit(array, limit) {
|
861
|
+
if (array.length > limit)
|
862
|
+
return array.splice(0, limit / 10);
|
863
|
+
return [];
|
864
|
+
}
|
865
|
+
// Annotate the CommonJS export names for ESM import in node:
|
866
|
+
0 && (module.exports = {
|
867
|
+
InitScript,
|
868
|
+
Page,
|
869
|
+
PageBinding,
|
870
|
+
Worker
|
871
|
+
});
|