@checkly/playwright-core 1.51.17-beta.2 → 1.54.2-beta.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/ThirdPartyNotices.txt +65 -123
- package/browsers.json +16 -14
- package/index.js +1 -1
- package/lib/androidServerImpl.js +47 -50
- package/lib/browserServerImpl.js +89 -69
- package/lib/checkly/escapeRegExp.js +23 -27
- package/lib/checkly/fetch.js +64 -46
- package/lib/checkly/secretsFilter.js +49 -35
- package/lib/cli/driver.js +71 -69
- package/lib/cli/program.js +400 -359
- package/lib/cli/programWithTestStub.js +51 -45
- package/lib/client/accessibility.js +31 -32
- package/lib/client/android.js +151 -242
- package/lib/client/api.js +135 -283
- package/lib/client/artifact.js +39 -36
- package/lib/client/browser.js +96 -71
- package/lib/client/browserContext.js +314 -345
- package/lib/client/browserType.js +103 -127
- package/lib/client/cdpSession.js +29 -31
- package/lib/client/channelOwner.js +90 -113
- package/lib/client/clientHelper.js +48 -39
- package/lib/client/clientInstrumentation.js +40 -37
- package/lib/client/clientStackTrace.js +41 -37
- package/lib/client/clock.js +36 -36
- package/lib/client/connection.js +188 -214
- package/lib/client/consoleMessage.js +31 -28
- package/lib/client/coverage.js +25 -22
- package/lib/client/dialog.js +30 -31
- package/lib/client/download.js +25 -25
- package/lib/client/electron.js +80 -77
- package/lib/client/elementHandle.js +120 -159
- package/lib/client/errors.js +53 -53
- package/lib/client/eventEmitter.js +124 -121
- package/lib/client/events.js +72 -68
- package/lib/client/fetch.js +166 -190
- package/lib/client/fileChooser.js +25 -24
- package/lib/client/fileUtils.js +31 -28
- package/lib/client/frame.js +207 -306
- package/lib/client/harRouter.js +42 -52
- package/lib/client/input.js +42 -69
- package/lib/client/jsHandle.js +54 -69
- package/lib/client/jsonPipe.js +27 -23
- package/lib/client/localUtils.js +29 -29
- package/lib/client/locator.js +145 -237
- package/lib/client/network.js +282 -307
- package/lib/client/page.js +269 -318
- package/lib/client/platform.js +46 -43
- package/lib/client/playwright.js +51 -76
- package/lib/client/selectors.js +45 -63
- package/lib/client/stream.js +29 -25
- package/lib/client/timeoutSettings.js +55 -41
- package/lib/client/tracing.js +49 -96
- package/lib/client/types.js +26 -22
- package/lib/client/video.js +35 -27
- package/lib/client/waiter.js +69 -88
- package/lib/client/webError.js +25 -23
- package/lib/client/webSocket.js +43 -56
- package/lib/client/worker.js +48 -56
- package/lib/client/writableStream.js +27 -23
- package/lib/generated/bindingsControllerSource.js +28 -0
- package/lib/generated/clockSource.js +26 -6
- package/lib/generated/consoleApiSource.js +26 -6
- package/lib/generated/injectedScriptSource.js +26 -6
- package/lib/generated/pollingRecorderSource.js +26 -6
- package/lib/generated/storageScriptSource.js +28 -0
- package/lib/generated/utilityScriptSource.js +26 -6
- package/lib/generated/webSocketMockSource.js +333 -5
- package/lib/inProcessFactory.js +51 -53
- package/lib/inprocess.js +2 -19
- package/lib/outofprocess.js +51 -46
- package/lib/protocol/serializers.js +153 -134
- package/lib/protocol/validator.js +2807 -2739
- package/lib/protocol/validatorPrimitives.js +114 -73
- package/lib/remote/playwrightConnection.js +88 -242
- package/lib/remote/playwrightServer.js +305 -92
- package/lib/server/accessibility.js +44 -37
- package/lib/server/android/android.js +251 -241
- package/lib/server/android/backendAdb.js +87 -82
- package/lib/server/artifact.js +78 -55
- package/lib/server/bidi/bidiBrowser.js +297 -158
- package/lib/server/bidi/bidiChromium.js +119 -89
- package/lib/server/bidi/bidiConnection.js +66 -83
- package/lib/server/bidi/bidiExecutionContext.js +129 -113
- package/lib/server/bidi/bidiFirefox.js +86 -76
- package/lib/server/bidi/bidiInput.js +106 -117
- package/lib/server/bidi/bidiNetworkManager.js +142 -159
- package/lib/server/bidi/bidiOverCdp.js +57 -58
- package/lib/server/bidi/bidiPage.js +260 -260
- package/lib/server/bidi/bidiPdf.js +52 -86
- package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
- package/lib/server/bidi/third_party/bidiDeserializer.js +55 -50
- package/lib/server/bidi/third_party/bidiKeyboard.js +236 -220
- package/lib/server/bidi/third_party/bidiProtocol.js +22 -137
- package/lib/server/bidi/third_party/bidiProtocolCore.js +152 -0
- package/lib/server/bidi/third_party/bidiProtocolPermissions.js +42 -0
- package/lib/server/bidi/third_party/bidiSerializer.js +67 -63
- package/lib/server/bidi/third_party/firefoxPrefs.js +141 -119
- package/lib/server/browser.js +93 -95
- package/lib/server/browserContext.js +419 -429
- package/lib/server/browserType.js +186 -216
- package/lib/server/callLog.js +47 -44
- package/lib/server/chromium/chromium.js +235 -203
- package/lib/server/chromium/chromiumSwitches.js +100 -67
- package/lib/server/chromium/crAccessibility.js +157 -131
- package/lib/server/chromium/crBrowser.js +310 -292
- package/lib/server/chromium/crConnection.js +95 -121
- package/lib/server/chromium/crCoverage.js +121 -131
- package/lib/server/chromium/crDevTools.js +60 -51
- package/lib/server/chromium/crDragDrop.js +68 -84
- package/lib/server/chromium/crExecutionContext.js +89 -83
- package/lib/server/chromium/crInput.js +118 -113
- package/lib/server/chromium/crNetworkManager.js +274 -375
- package/lib/server/chromium/crPage.js +536 -593
- package/lib/server/chromium/crPdf.js +54 -86
- package/lib/server/chromium/crProtocolHelper.js +92 -80
- package/lib/server/chromium/crServiceWorker.js +84 -73
- package/lib/server/chromium/defaultFontFamilies.js +152 -135
- package/lib/server/chromium/protocol.d.js +16 -0
- package/lib/server/chromium/videoRecorder.js +66 -99
- package/lib/server/clock.js +107 -83
- package/lib/server/codegen/csharp.js +192 -162
- package/lib/server/codegen/java.js +156 -129
- package/lib/server/codegen/javascript.js +163 -148
- package/lib/server/codegen/jsonl.js +32 -28
- package/lib/server/codegen/language.js +75 -52
- package/lib/server/codegen/languages.js +65 -27
- package/lib/server/codegen/python.js +141 -126
- package/lib/server/codegen/types.js +15 -4
- package/lib/server/console.js +28 -32
- package/lib/server/cookieStore.js +108 -86
- package/lib/server/debugController.js +147 -151
- package/lib/server/debugger.js +86 -78
- package/lib/server/deviceDescriptors.js +37 -24
- package/lib/server/deviceDescriptorsSource.json +238 -128
- package/lib/server/dialog.js +84 -39
- package/lib/server/dispatchers/androidDispatcher.js +257 -148
- package/lib/server/dispatchers/artifactDispatcher.js +79 -79
- package/lib/server/dispatchers/browserContextDispatcher.js +289 -259
- package/lib/server/dispatchers/browserDispatcher.js +96 -148
- package/lib/server/dispatchers/browserTypeDispatcher.js +50 -41
- package/lib/server/dispatchers/cdpSessionDispatcher.js +35 -39
- package/lib/server/dispatchers/debugControllerDispatcher.js +65 -83
- package/lib/server/dispatchers/dialogDispatcher.js +34 -31
- package/lib/server/dispatchers/dispatcher.js +208 -248
- package/lib/server/dispatchers/electronDispatcher.js +66 -70
- package/lib/server/dispatchers/elementHandlerDispatcher.js +164 -216
- package/lib/server/dispatchers/frameDispatcher.js +211 -272
- package/lib/server/dispatchers/jsHandleDispatcher.js +63 -75
- package/lib/server/dispatchers/jsonPipeDispatcher.js +37 -38
- package/lib/server/dispatchers/localUtilsDispatcher.js +121 -119
- package/lib/server/dispatchers/networkDispatchers.js +117 -128
- package/lib/server/dispatchers/pageDispatcher.js +256 -248
- package/lib/server/dispatchers/playwrightDispatcher.js +92 -87
- package/lib/server/dispatchers/streamDispatcher.js +52 -48
- package/lib/server/dispatchers/tracingDispatcher.js +47 -52
- package/lib/server/dispatchers/webSocketRouteDispatcher.js +126 -150
- package/lib/server/dispatchers/writableStreamDispatcher.js +65 -43
- package/lib/server/dom.js +485 -582
- package/lib/server/download.js +47 -37
- package/lib/server/electron/electron.js +216 -243
- package/lib/server/electron/loader.js +9 -37
- package/lib/server/errors.js +47 -46
- package/lib/server/fetch.js +317 -360
- package/lib/server/fileChooser.js +25 -24
- package/lib/server/fileUploadUtils.js +66 -60
- package/lib/server/firefox/ffAccessibility.js +153 -131
- package/lib/server/firefox/ffBrowser.js +268 -305
- package/lib/server/firefox/ffConnection.js +63 -84
- package/lib/server/firefox/ffExecutionContext.js +92 -73
- package/lib/server/firefox/ffInput.js +82 -84
- package/lib/server/firefox/ffNetworkManager.js +137 -114
- package/lib/server/firefox/ffPage.js +261 -293
- package/lib/server/firefox/firefox.js +80 -72
- package/lib/server/firefox/protocol.d.js +16 -0
- package/lib/server/formData.js +107 -35
- package/lib/server/frameSelectors.js +98 -114
- package/lib/server/frames.js +845 -1055
- package/lib/server/har/harRecorder.js +85 -77
- package/lib/server/har/harTracer.js +290 -223
- package/lib/server/harBackend.js +80 -80
- package/lib/server/helper.js +55 -59
- package/lib/server/index.js +59 -99
- package/lib/server/input.js +151 -189
- package/lib/server/instrumentation.js +57 -44
- package/lib/server/javascript.js +133 -134
- package/lib/server/launchApp.js +113 -75
- package/lib/server/localUtils.js +150 -142
- package/lib/server/macEditingCommands.js +141 -137
- package/lib/server/network.js +299 -303
- package/lib/server/page.js +513 -544
- package/lib/server/pipeTransport.js +49 -45
- package/lib/server/playwright.js +58 -67
- package/lib/server/progress.js +137 -68
- package/lib/server/protocolError.js +34 -31
- package/lib/server/recorder/chat.js +70 -86
- package/lib/server/recorder/recorderApp.js +341 -176
- package/lib/server/recorder/recorderInTraceViewer.js +65 -94
- package/lib/server/recorder/recorderRunner.js +93 -116
- package/lib/server/recorder/recorderSignalProcessor.js +83 -0
- package/lib/server/recorder/recorderUtils.js +104 -47
- package/lib/server/recorder/throttledFile.js +42 -30
- package/lib/server/recorder.js +395 -275
- package/lib/server/registry/browserFetcher.js +106 -101
- package/lib/server/registry/dependencies.js +245 -196
- package/lib/server/registry/index.js +930 -803
- package/lib/server/registry/nativeDeps.js +1073 -464
- package/lib/server/registry/oopDownloadBrowserMain.js +57 -75
- package/lib/server/screenshotter.js +160 -191
- package/lib/server/selectors.js +90 -51
- package/lib/server/socksClientCertificatesInterceptor.js +171 -186
- package/lib/server/socksInterceptor.js +62 -70
- package/lib/server/trace/recorder/snapshotter.js +76 -102
- package/lib/server/trace/recorder/snapshotterInjected.js +238 -217
- package/lib/server/trace/recorder/tracing.js +354 -362
- package/lib/server/trace/test/inMemorySnapshotter.js +46 -52
- package/lib/server/trace/viewer/traceViewer.js +160 -147
- package/lib/server/transport.js +119 -134
- package/lib/server/types.js +26 -22
- package/lib/server/usKeyboardLayout.js +135 -545
- package/lib/server/utils/ascii.js +39 -26
- package/lib/server/utils/comparators.js +105 -103
- package/lib/server/utils/crypto.js +157 -112
- package/lib/server/utils/debug.js +36 -32
- package/lib/server/utils/debugLogger.js +77 -48
- package/lib/server/utils/env.js +52 -37
- package/lib/server/utils/eventsHelper.js +29 -28
- package/lib/server/utils/expectUtils.js +31 -26
- package/lib/server/utils/fileUtils.js +123 -136
- package/lib/server/utils/happyEyeballs.js +141 -126
- package/lib/server/utils/hostPlatform.js +84 -120
- package/lib/server/utils/httpServer.js +106 -121
- package/lib/server/utils/image_tools/colorUtils.js +42 -51
- package/lib/server/utils/image_tools/compare.js +44 -43
- package/lib/server/utils/image_tools/imageChannel.js +38 -30
- package/lib/server/utils/image_tools/stats.js +40 -40
- package/lib/server/utils/linuxUtils.js +50 -37
- package/lib/server/utils/network.js +152 -96
- package/lib/server/utils/nodePlatform.js +87 -79
- package/lib/server/utils/pipeTransport.js +44 -42
- package/lib/server/utils/processLauncher.js +111 -121
- package/lib/server/utils/profiler.js +52 -39
- package/lib/server/utils/socksProxy.js +280 -339
- package/lib/server/utils/spawnAsync.js +37 -41
- package/lib/server/utils/task.js +31 -38
- package/lib/server/utils/userAgent.js +73 -66
- package/lib/server/utils/wsServer.js +68 -75
- package/lib/server/utils/zipFile.js +36 -37
- package/lib/server/utils/zones.js +37 -34
- package/lib/server/webkit/protocol.d.js +16 -0
- package/lib/server/webkit/webkit.js +77 -61
- package/lib/server/webkit/wkAccessibility.js +161 -118
- package/lib/server/webkit/wkBrowser.js +193 -184
- package/lib/server/webkit/wkConnection.js +59 -83
- package/lib/server/webkit/wkExecutionContext.js +85 -70
- package/lib/server/webkit/wkInput.js +97 -95
- package/lib/server/webkit/wkInterceptableRequest.js +102 -95
- package/lib/server/webkit/wkPage.js +568 -667
- package/lib/server/webkit/wkProvisionalPage.js +45 -56
- package/lib/server/webkit/wkWorkers.js +79 -79
- package/lib/utils/expectUtils.js +31 -26
- package/lib/utils/isomorphic/ariaSnapshot.js +149 -152
- package/lib/utils/isomorphic/assert.js +28 -22
- package/lib/utils/isomorphic/colors.js +66 -59
- package/lib/utils/isomorphic/cssParser.js +120 -125
- package/lib/utils/isomorphic/cssTokenizer.js +436 -364
- package/lib/utils/isomorphic/headers.js +38 -37
- package/lib/utils/isomorphic/locatorGenerators.js +358 -357
- package/lib/utils/isomorphic/locatorParser.js +96 -105
- package/lib/utils/isomorphic/locatorUtils.js +63 -44
- package/lib/utils/isomorphic/manualPromise.js +46 -39
- package/lib/utils/isomorphic/mimeType.js +447 -25
- package/lib/utils/isomorphic/multimap.js +34 -27
- package/lib/utils/isomorphic/protocolFormatter.js +68 -0
- package/lib/utils/isomorphic/protocolMetainfo.js +321 -0
- package/lib/utils/isomorphic/recorderUtils.js +140 -181
- package/lib/utils/isomorphic/rtti.js +35 -33
- package/lib/utils/isomorphic/selectorParser.js +182 -193
- package/lib/utils/isomorphic/semaphore.js +27 -24
- package/lib/utils/isomorphic/stackTrace.js +87 -98
- package/lib/utils/isomorphic/stringUtils.js +98 -112
- package/lib/utils/isomorphic/time.js +46 -22
- package/lib/utils/isomorphic/timeoutRunner.js +53 -53
- package/lib/utils/isomorphic/traceUtils.js +37 -41
- package/lib/utils/isomorphic/types.js +15 -4
- package/lib/utils/isomorphic/urlMatch.js +113 -67
- package/lib/utils/isomorphic/utilityScriptSerializers.js +251 -0
- package/lib/utils.js +101 -443
- package/lib/utilsBundle.js +101 -52
- package/lib/utilsBundleImpl/index.js +160 -150
- package/lib/zipBundle.js +32 -23
- package/lib/zipBundleImpl.js +4 -4
- package/package.json +1 -1
- package/types/protocol.d.ts +1267 -1057
- package/types/types.d.ts +131 -29
- package/lib/common/socksProxy.js +0 -569
- package/lib/common/timeoutSettings.js +0 -73
- package/lib/common/types.js +0 -5
- package/lib/image_tools/colorUtils.js +0 -98
- package/lib/image_tools/compare.js +0 -108
- package/lib/image_tools/imageChannel.js +0 -70
- package/lib/image_tools/stats.js +0 -102
- package/lib/protocol/debug.js +0 -27
- package/lib/protocol/transport.js +0 -82
- package/lib/server/dispatchers/selectorsDispatcher.js +0 -36
- package/lib/server/isomorphic/utilityScriptSerializers.js +0 -229
- package/lib/server/recorder/contextRecorder.js +0 -290
- package/lib/server/recorder/recorderCollection.js +0 -104
- package/lib/server/recorder/recorderFrontend.js +0 -5
- package/lib/server/storageScript.js +0 -160
- package/lib/server/timeoutSettings.js +0 -74
- package/lib/third_party/diff_match_patch.js +0 -2222
- package/lib/utils/ascii.js +0 -31
- package/lib/utils/comparators.js +0 -171
- package/lib/utils/crypto.js +0 -174
- package/lib/utils/debug.js +0 -46
- package/lib/utils/debugLogger.js +0 -91
- package/lib/utils/env.js +0 -49
- package/lib/utils/eventsHelper.js +0 -38
- package/lib/utils/fileUtils.js +0 -205
- package/lib/utils/happy-eyeballs.js +0 -210
- package/lib/utils/headers.js +0 -52
- package/lib/utils/hostPlatform.js +0 -133
- package/lib/utils/httpServer.js +0 -237
- package/lib/utils/index.js +0 -368
- package/lib/utils/linuxUtils.js +0 -78
- package/lib/utils/manualPromise.js +0 -109
- package/lib/utils/multimap.js +0 -75
- package/lib/utils/network.js +0 -160
- package/lib/utils/processLauncher.js +0 -248
- package/lib/utils/profiler.js +0 -53
- package/lib/utils/rtti.js +0 -44
- package/lib/utils/semaphore.js +0 -51
- package/lib/utils/spawnAsync.js +0 -45
- package/lib/utils/stackTrace.js +0 -121
- package/lib/utils/task.js +0 -58
- package/lib/utils/time.js +0 -37
- package/lib/utils/timeoutRunner.js +0 -66
- package/lib/utils/traceUtils.js +0 -44
- package/lib/utils/userAgent.js +0 -105
- package/lib/utils/wsServer.js +0 -127
- package/lib/utils/zipFile.js +0 -75
- package/lib/utils/zones.js +0 -62
- package/lib/vite/htmlReport/index.html +0 -69
- package/lib/vite/recorder/assets/codeMirrorModule-B9YMkrwa.js +0 -24
- package/lib/vite/recorder/assets/codeMirrorModule-C3UTv-Ge.css +0 -1
- package/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
- package/lib/vite/recorder/assets/index-ELPgmkwA.js +0 -184
- package/lib/vite/recorder/assets/index-eHBmevrY.css +0 -1
- package/lib/vite/recorder/index.html +0 -29
- package/lib/vite/recorder/playwright-logo.svg +0 -9
- package/lib/vite/traceViewer/assets/codeMirrorModule-gU1OOCQO.js +0 -24
- package/lib/vite/traceViewer/assets/defaultSettingsView-B5n_FjMx.js +0 -1
- package/lib/vite/traceViewer/assets/inspectorTab-6Tru8Mn_.js +0 -235
- package/lib/vite/traceViewer/assets/workbench-B_Nj4NA2.js +0 -25
- package/lib/vite/traceViewer/assets/xtermModule-BoAIEibi.js +0 -9
- package/lib/vite/traceViewer/codeMirrorModule.C3UTv-Ge.css +0 -1
- package/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
- package/lib/vite/traceViewer/defaultSettingsView.CO3FR0CX.css +0 -1
- package/lib/vite/traceViewer/embedded.DpNPH6mk.js +0 -2
- package/lib/vite/traceViewer/embedded.html +0 -18
- package/lib/vite/traceViewer/embedded.mLhjB5IF.css +0 -1
- package/lib/vite/traceViewer/index.CFOW-Ezb.css +0 -1
- package/lib/vite/traceViewer/index.CuE3SYGw.js +0 -2
- package/lib/vite/traceViewer/index.html +0 -47
- package/lib/vite/traceViewer/inspectorTab.CXDulcFG.css +0 -1
- package/lib/vite/traceViewer/playwright-logo.svg +0 -9
- package/lib/vite/traceViewer/recorder.BD-uZJs7.js +0 -2
- package/lib/vite/traceViewer/recorder.html +0 -17
- package/lib/vite/traceViewer/recorder.tn0RQdqM.css +0 -0
- package/lib/vite/traceViewer/snapshot.html +0 -21
- package/lib/vite/traceViewer/sw.bundle.js +0 -3
- package/lib/vite/traceViewer/uiMode.BatfzHMG.css +0 -1
- package/lib/vite/traceViewer/uiMode.DHrNgddz.js +0 -5
- package/lib/vite/traceViewer/uiMode.html +0 -21
- package/lib/vite/traceViewer/workbench.B9vIAzH9.css +0 -1
- package/lib/vite/traceViewer/xtermModule.Beg8tuEN.css +0 -32
|
@@ -1,75 +1,65 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty
|
|
4
|
-
|
|
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 crPage_exports = {};
|
|
30
|
+
__export(crPage_exports, {
|
|
31
|
+
CRPage: () => CRPage
|
|
5
32
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var dialog =
|
|
13
|
-
var dom =
|
|
14
|
-
var frames =
|
|
15
|
-
var
|
|
16
|
-
var network =
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
34
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
35
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
36
|
-
/**
|
|
37
|
-
* Copyright 2017 Google Inc. All rights reserved.
|
|
38
|
-
* Modifications copyright (c) Microsoft Corporation.
|
|
39
|
-
*
|
|
40
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
41
|
-
* you may not use this file except in compliance with the License.
|
|
42
|
-
* You may obtain a copy of the License at
|
|
43
|
-
*
|
|
44
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
45
|
-
*
|
|
46
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
47
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
48
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
49
|
-
* See the License for the specific language governing permissions and
|
|
50
|
-
* limitations under the License.
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
const UTILITY_WORLD_NAME = '__playwright_utility_world__';
|
|
33
|
+
module.exports = __toCommonJS(crPage_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_assert = require("../../utils/isomorphic/assert");
|
|
36
|
+
var import_crypto = require("../utils/crypto");
|
|
37
|
+
var import_eventsHelper = require("../utils/eventsHelper");
|
|
38
|
+
var import_stackTrace = require("../../utils/isomorphic/stackTrace");
|
|
39
|
+
var dialog = __toESM(require("../dialog"));
|
|
40
|
+
var dom = __toESM(require("../dom"));
|
|
41
|
+
var frames = __toESM(require("../frames"));
|
|
42
|
+
var import_helper = require("../helper");
|
|
43
|
+
var network = __toESM(require("../network"));
|
|
44
|
+
var import_page = require("../page");
|
|
45
|
+
var import_registry = require("../registry");
|
|
46
|
+
var import_crAccessibility = require("./crAccessibility");
|
|
47
|
+
var import_crBrowser = require("./crBrowser");
|
|
48
|
+
var import_crCoverage = require("./crCoverage");
|
|
49
|
+
var import_crDragDrop = require("./crDragDrop");
|
|
50
|
+
var import_crExecutionContext = require("./crExecutionContext");
|
|
51
|
+
var import_crInput = require("./crInput");
|
|
52
|
+
var import_crNetworkManager = require("./crNetworkManager");
|
|
53
|
+
var import_crPdf = require("./crPdf");
|
|
54
|
+
var import_crProtocolHelper = require("./crProtocolHelper");
|
|
55
|
+
var import_defaultFontFamilies = require("./defaultFontFamilies");
|
|
56
|
+
var import_videoRecorder = require("./videoRecorder");
|
|
57
|
+
var import_browserContext = require("../browserContext");
|
|
58
|
+
var import_errors = require("../errors");
|
|
59
|
+
var import_protocolError = require("../protocolError");
|
|
54
60
|
class CRPage {
|
|
55
|
-
static mainFrameSession(page) {
|
|
56
|
-
const crPage = page._delegate;
|
|
57
|
-
return crPage._mainFrameSession;
|
|
58
|
-
}
|
|
59
61
|
constructor(client, targetId, browserContext, opener, bits) {
|
|
60
|
-
this.
|
|
61
|
-
this._sessions = new Map();
|
|
62
|
-
this._page = void 0;
|
|
63
|
-
this.rawMouse = void 0;
|
|
64
|
-
this.rawKeyboard = void 0;
|
|
65
|
-
this.rawTouchscreen = void 0;
|
|
66
|
-
this._targetId = void 0;
|
|
67
|
-
this._opener = void 0;
|
|
68
|
-
this._networkManager = void 0;
|
|
69
|
-
this._pdf = void 0;
|
|
70
|
-
this._coverage = void 0;
|
|
71
|
-
this._browserContext = void 0;
|
|
72
|
-
this._isBackgroundPage = void 0;
|
|
62
|
+
this._sessions = /* @__PURE__ */ new Map();
|
|
73
63
|
// Holds window features for the next popup being opened via window.open,
|
|
74
64
|
// until the popup target arrives. This could be racy if two oopifs
|
|
75
65
|
// simultaneously call window.open with window features: the order
|
|
@@ -79,17 +69,16 @@ class CRPage {
|
|
|
79
69
|
this._targetId = targetId;
|
|
80
70
|
this._opener = opener;
|
|
81
71
|
this._isBackgroundPage = bits.isBackgroundPage;
|
|
82
|
-
const dragManager = new
|
|
83
|
-
this.rawKeyboard = new
|
|
84
|
-
this.rawMouse = new
|
|
85
|
-
this.rawTouchscreen = new
|
|
86
|
-
this._pdf = new
|
|
87
|
-
this._coverage = new
|
|
72
|
+
const dragManager = new import_crDragDrop.DragManager(this);
|
|
73
|
+
this.rawKeyboard = new import_crInput.RawKeyboardImpl(client, browserContext._browser._platform() === "mac", dragManager);
|
|
74
|
+
this.rawMouse = new import_crInput.RawMouseImpl(this, client, dragManager);
|
|
75
|
+
this.rawTouchscreen = new import_crInput.RawTouchscreenImpl(client);
|
|
76
|
+
this._pdf = new import_crPdf.CRPDF(client);
|
|
77
|
+
this._coverage = new import_crCoverage.CRCoverage(client);
|
|
88
78
|
this._browserContext = browserContext;
|
|
89
|
-
this._page = new
|
|
90
|
-
this.
|
|
91
|
-
|
|
92
|
-
// we have not connected any sessions to the network manager yet.
|
|
79
|
+
this._page = new import_page.Page(this, browserContext);
|
|
80
|
+
this.utilityWorldName = `__playwright_utility_world_${this._page.guid}`;
|
|
81
|
+
this._networkManager = new import_crNetworkManager.CRNetworkManager(this._page, null);
|
|
93
82
|
this.updateOffline();
|
|
94
83
|
this.updateExtraHTTPHeaders();
|
|
95
84
|
this.updateHttpCredentials();
|
|
@@ -98,37 +87,37 @@ class CRPage {
|
|
|
98
87
|
this._sessions.set(targetId, this._mainFrameSession);
|
|
99
88
|
if (opener && !browserContext._options.noDefaultViewport) {
|
|
100
89
|
const features = opener._nextWindowOpenPopupFeatures.shift() || [];
|
|
101
|
-
const viewportSize =
|
|
102
|
-
if (viewportSize)
|
|
103
|
-
viewport: viewportSize,
|
|
104
|
-
screen: viewportSize
|
|
105
|
-
};
|
|
90
|
+
const viewportSize = import_helper.helper.getViewportSizeFromWindowFeatures(features);
|
|
91
|
+
if (viewportSize)
|
|
92
|
+
this._page.setEmulatedSizeFromWindowOpen({ viewport: viewportSize, screen: viewportSize });
|
|
106
93
|
}
|
|
107
|
-
const createdEvent = this._isBackgroundPage ?
|
|
108
|
-
this._mainFrameSession._initialize(bits.hasUIWindow).then(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
94
|
+
const createdEvent = this._isBackgroundPage ? import_crBrowser.CRBrowserContext.CREvents.BackgroundPage : import_browserContext.BrowserContext.Events.Page;
|
|
95
|
+
this._mainFrameSession._initialize(bits.hasUIWindow).then(
|
|
96
|
+
() => this._page.reportAsNew(this._opener?._page, void 0, createdEvent),
|
|
97
|
+
(error) => this._page.reportAsNew(this._opener?._page, error, createdEvent)
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
static mainFrameSession(page) {
|
|
101
|
+
const crPage = page.delegate;
|
|
102
|
+
return crPage._mainFrameSession;
|
|
115
103
|
}
|
|
116
104
|
async _forAllFrameSessions(cb) {
|
|
117
105
|
const frameSessions = Array.from(this._sessions.values());
|
|
118
|
-
await Promise.all(frameSessions.map(frameSession => {
|
|
119
|
-
if (frameSession._isMainFrame())
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if ((0,
|
|
106
|
+
await Promise.all(frameSessions.map((frameSession) => {
|
|
107
|
+
if (frameSession._isMainFrame())
|
|
108
|
+
return cb(frameSession);
|
|
109
|
+
return cb(frameSession).catch((e) => {
|
|
110
|
+
if ((0, import_protocolError.isSessionClosedError)(e))
|
|
111
|
+
return;
|
|
123
112
|
throw e;
|
|
124
113
|
});
|
|
125
114
|
}));
|
|
126
115
|
}
|
|
127
116
|
_sessionForFrame(frame) {
|
|
128
|
-
// Frame id equals target id.
|
|
129
117
|
while (!this._sessions.has(frame._id)) {
|
|
130
118
|
const parent = frame.parentFrame();
|
|
131
|
-
if (!parent)
|
|
119
|
+
if (!parent)
|
|
120
|
+
throw new Error(`Frame has been detached.`);
|
|
132
121
|
frame = parent;
|
|
133
122
|
}
|
|
134
123
|
return this._sessions.get(frame._id);
|
|
@@ -141,18 +130,22 @@ class CRPage {
|
|
|
141
130
|
this._mainFrameSession._willBeginDownload();
|
|
142
131
|
}
|
|
143
132
|
didClose() {
|
|
144
|
-
for (const session of this._sessions.values())
|
|
133
|
+
for (const session of this._sessions.values())
|
|
134
|
+
session.dispose();
|
|
145
135
|
this._page._didClose();
|
|
146
136
|
}
|
|
147
137
|
async navigateFrame(frame, url, referrer) {
|
|
148
138
|
return this._sessionForFrame(frame)._navigate(frame, url, referrer);
|
|
149
139
|
}
|
|
150
140
|
async updateExtraHTTPHeaders() {
|
|
151
|
-
const headers = network.mergeHeaders([
|
|
141
|
+
const headers = network.mergeHeaders([
|
|
142
|
+
this._browserContext._options.extraHTTPHeaders,
|
|
143
|
+
this._page.extraHTTPHeaders()
|
|
144
|
+
]);
|
|
152
145
|
await this._networkManager.setExtraHTTPHeaders(headers);
|
|
153
146
|
}
|
|
154
147
|
async updateGeolocation() {
|
|
155
|
-
await this._forAllFrameSessions(frame => frame._updateGeolocation(false));
|
|
148
|
+
await this._forAllFrameSessions((frame) => frame._updateGeolocation(false));
|
|
156
149
|
}
|
|
157
150
|
async updateOffline() {
|
|
158
151
|
await this._networkManager.setOffline(!!this._browserContext._options.offline);
|
|
@@ -164,87 +157,77 @@ class CRPage {
|
|
|
164
157
|
await this._mainFrameSession._updateViewport(preserveWindowBoundaries);
|
|
165
158
|
}
|
|
166
159
|
async bringToFront() {
|
|
167
|
-
await this._mainFrameSession._client.send(
|
|
160
|
+
await this._mainFrameSession._client.send("Page.bringToFront");
|
|
168
161
|
}
|
|
169
162
|
async updateEmulateMedia() {
|
|
170
|
-
await this._forAllFrameSessions(frame => frame._updateEmulateMedia());
|
|
163
|
+
await this._forAllFrameSessions((frame) => frame._updateEmulateMedia());
|
|
171
164
|
}
|
|
172
165
|
async updateUserAgent() {
|
|
173
|
-
await this._forAllFrameSessions(frame => frame._updateUserAgent());
|
|
166
|
+
await this._forAllFrameSessions((frame) => frame._updateUserAgent());
|
|
174
167
|
}
|
|
175
168
|
async updateRequestInterception() {
|
|
176
169
|
await this._networkManager.setRequestInterception(this._page.needsRequestInterception());
|
|
177
170
|
}
|
|
178
171
|
async updateFileChooserInterception() {
|
|
179
|
-
await this._forAllFrameSessions(frame => frame._updateFileChooserInterception(false));
|
|
172
|
+
await this._forAllFrameSessions((frame) => frame._updateFileChooserInterception(false));
|
|
180
173
|
}
|
|
181
174
|
async reload() {
|
|
182
|
-
await this._mainFrameSession._client.send(
|
|
175
|
+
await this._mainFrameSession._client.send("Page.reload");
|
|
183
176
|
}
|
|
184
177
|
async _go(delta) {
|
|
185
|
-
const history = await this._mainFrameSession._client.send(
|
|
178
|
+
const history = await this._mainFrameSession._client.send("Page.getNavigationHistory");
|
|
186
179
|
const entry = history.entries[history.currentIndex + delta];
|
|
187
|
-
if (!entry)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
});
|
|
180
|
+
if (!entry)
|
|
181
|
+
return false;
|
|
182
|
+
await this._mainFrameSession._client.send("Page.navigateToHistoryEntry", { entryId: entry.id });
|
|
191
183
|
return true;
|
|
192
184
|
}
|
|
193
185
|
goBack() {
|
|
194
186
|
return this._go(-1);
|
|
195
187
|
}
|
|
196
188
|
goForward() {
|
|
197
|
-
return this._go(
|
|
189
|
+
return this._go(1);
|
|
198
190
|
}
|
|
199
191
|
async requestGC() {
|
|
200
|
-
await this._mainFrameSession._client.send(
|
|
192
|
+
await this._mainFrameSession._client.send("HeapProfiler.collectGarbage");
|
|
201
193
|
}
|
|
202
|
-
async addInitScript(initScript, world =
|
|
203
|
-
await this._forAllFrameSessions(frame => frame._evaluateOnNewDocument(initScript, world));
|
|
194
|
+
async addInitScript(initScript, world = "main") {
|
|
195
|
+
await this._forAllFrameSessions((frame) => frame._evaluateOnNewDocument(initScript, world));
|
|
204
196
|
}
|
|
205
|
-
async
|
|
206
|
-
await this._forAllFrameSessions(frame => frame.
|
|
197
|
+
async exposePlaywrightBinding() {
|
|
198
|
+
await this._forAllFrameSessions((frame) => frame.exposePlaywrightBinding());
|
|
199
|
+
}
|
|
200
|
+
async removeInitScripts(initScripts) {
|
|
201
|
+
await this._forAllFrameSessions((frame) => frame._removeEvaluatesOnNewDocument(initScripts));
|
|
207
202
|
}
|
|
208
203
|
async closePage(runBeforeUnload) {
|
|
209
|
-
if (runBeforeUnload)
|
|
204
|
+
if (runBeforeUnload)
|
|
205
|
+
await this._mainFrameSession._client.send("Page.close");
|
|
206
|
+
else
|
|
207
|
+
await this._browserContext._browser._closePage(this);
|
|
210
208
|
}
|
|
211
209
|
async setBackgroundColor(color) {
|
|
212
|
-
await this._mainFrameSession._client.send(
|
|
213
|
-
color
|
|
214
|
-
});
|
|
210
|
+
await this._mainFrameSession._client.send("Emulation.setDefaultBackgroundColorOverride", { color });
|
|
215
211
|
}
|
|
216
212
|
async takeScreenshot(progress, format, documentRect, viewportRect, quality, fitsViewport, scale) {
|
|
217
|
-
const {
|
|
218
|
-
visualViewport
|
|
219
|
-
} = await this._mainFrameSession._client.send('Page.getLayoutMetrics');
|
|
213
|
+
const { visualViewport } = await progress.race(this._mainFrameSession._client.send("Page.getLayoutMetrics"));
|
|
220
214
|
if (!documentRect) {
|
|
221
215
|
documentRect = {
|
|
222
216
|
x: visualViewport.pageX + viewportRect.x,
|
|
223
217
|
y: visualViewport.pageY + viewportRect.y,
|
|
224
|
-
...
|
|
218
|
+
...import_helper.helper.enclosingIntSize({
|
|
225
219
|
width: viewportRect.width / visualViewport.scale,
|
|
226
220
|
height: viewportRect.height / visualViewport.scale
|
|
227
221
|
})
|
|
228
222
|
};
|
|
229
223
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const clip = {
|
|
233
|
-
...documentRect,
|
|
234
|
-
scale: viewportRect ? visualViewport.scale : 1
|
|
235
|
-
};
|
|
236
|
-
if (scale === 'css') {
|
|
224
|
+
const clip = { ...documentRect, scale: viewportRect ? visualViewport.scale : 1 };
|
|
225
|
+
if (scale === "css") {
|
|
237
226
|
const deviceScaleFactor = this._browserContext._options.deviceScaleFactor || 1;
|
|
238
227
|
clip.scale /= deviceScaleFactor;
|
|
239
228
|
}
|
|
240
|
-
progress.
|
|
241
|
-
|
|
242
|
-
format,
|
|
243
|
-
quality,
|
|
244
|
-
clip,
|
|
245
|
-
captureBeyondViewport: !fitsViewport
|
|
246
|
-
});
|
|
247
|
-
return Buffer.from(result.data, 'base64');
|
|
229
|
+
const result = await progress.race(this._mainFrameSession._client.send("Page.captureScreenshot", { format, quality, clip, captureBeyondViewport: !fitsViewport }));
|
|
230
|
+
return Buffer.from(result.data, "base64");
|
|
248
231
|
}
|
|
249
232
|
async getContentFrame(handle) {
|
|
250
233
|
return this._sessionForHandle(handle)._getContentFrame(handle);
|
|
@@ -261,7 +244,7 @@ class CRPage {
|
|
|
261
244
|
async setScreencastOptions(options) {
|
|
262
245
|
if (options) {
|
|
263
246
|
await this._mainFrameSession._startScreencast(this, {
|
|
264
|
-
format:
|
|
247
|
+
format: "jpeg",
|
|
265
248
|
quality: options.quality,
|
|
266
249
|
maxWidth: options.width,
|
|
267
250
|
maxHeight: options.height
|
|
@@ -278,9 +261,10 @@ class CRPage {
|
|
|
278
261
|
}
|
|
279
262
|
async setInputFilePaths(handle, files) {
|
|
280
263
|
const frame = await handle.ownerFrame();
|
|
281
|
-
if (!frame)
|
|
264
|
+
if (!frame)
|
|
265
|
+
throw new Error("Cannot set input files to detached input element");
|
|
282
266
|
const parentSession = this._sessionForFrame(frame);
|
|
283
|
-
await parentSession._client.send(
|
|
267
|
+
await parentSession._client.send("DOM.setFileInputFiles", {
|
|
284
268
|
objectId: handle._objectId,
|
|
285
269
|
files
|
|
286
270
|
});
|
|
@@ -289,14 +273,14 @@ class CRPage {
|
|
|
289
273
|
return this._sessionForHandle(handle)._adoptElementHandle(handle, to);
|
|
290
274
|
}
|
|
291
275
|
async getAccessibilityTree(needle) {
|
|
292
|
-
return (0,
|
|
276
|
+
return (0, import_crAccessibility.getAccessibilityTree)(this._mainFrameSession._client, needle);
|
|
293
277
|
}
|
|
294
278
|
async inputActionEpilogue() {
|
|
295
|
-
await this._mainFrameSession._client.send(
|
|
279
|
+
await this._mainFrameSession._client.send("Page.enable").catch((e) => {
|
|
280
|
+
});
|
|
296
281
|
}
|
|
297
|
-
async resetForReuse() {
|
|
298
|
-
|
|
299
|
-
await this.rawMouse.move(-1, -1, 'none', new Set(), new Set(), true);
|
|
282
|
+
async resetForReuse(progress) {
|
|
283
|
+
await this.rawMouse.move(progress, -1, -1, "none", /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set(), true);
|
|
300
284
|
}
|
|
301
285
|
async pdf(options) {
|
|
302
286
|
return this._pdf.generate(options);
|
|
@@ -306,356 +290,359 @@ class CRPage {
|
|
|
306
290
|
}
|
|
307
291
|
async getFrameElement(frame) {
|
|
308
292
|
let parent = frame.parentFrame();
|
|
309
|
-
if (!parent)
|
|
293
|
+
if (!parent)
|
|
294
|
+
throw new Error("Frame has been detached.");
|
|
310
295
|
const parentSession = this._sessionForFrame(parent);
|
|
311
|
-
const {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
frameId: frame._id
|
|
315
|
-
}).catch(e => {
|
|
316
|
-
if (e instanceof Error && e.message.includes('Frame with the given id was not found.')) (0, _stackTrace.rewriteErrorMessage)(e, 'Frame has been detached.');
|
|
296
|
+
const { backendNodeId } = await parentSession._client.send("DOM.getFrameOwner", { frameId: frame._id }).catch((e) => {
|
|
297
|
+
if (e instanceof Error && e.message.includes("Frame with the given id was not found."))
|
|
298
|
+
(0, import_stackTrace.rewriteErrorMessage)(e, "Frame has been detached.");
|
|
317
299
|
throw e;
|
|
318
300
|
});
|
|
319
301
|
parent = frame.parentFrame();
|
|
320
|
-
if (!parent)
|
|
302
|
+
if (!parent)
|
|
303
|
+
throw new Error("Frame has been detached.");
|
|
321
304
|
return parentSession._adoptBackendNodeId(backendNodeId, await parent._mainContext());
|
|
322
305
|
}
|
|
323
306
|
shouldToggleStyleSheetToSyncAnimations() {
|
|
324
307
|
return false;
|
|
325
308
|
}
|
|
326
309
|
}
|
|
327
|
-
exports.CRPage = CRPage;
|
|
328
310
|
class FrameSession {
|
|
329
311
|
constructor(crPage, client, targetId, parentSession) {
|
|
330
|
-
this.
|
|
331
|
-
this.
|
|
332
|
-
this._page = void 0;
|
|
333
|
-
this._parentSession = void 0;
|
|
334
|
-
this._childSessions = new Set();
|
|
335
|
-
this._contextIdToContext = new Map();
|
|
312
|
+
this._childSessions = /* @__PURE__ */ new Set();
|
|
313
|
+
this._contextIdToContext = /* @__PURE__ */ new Map();
|
|
336
314
|
this._eventListeners = [];
|
|
337
|
-
this.
|
|
338
|
-
|
|
339
|
-
this.
|
|
340
|
-
|
|
341
|
-
this._windowId = void 0;
|
|
315
|
+
this._firstNonInitialNavigationCommittedFulfill = () => {
|
|
316
|
+
};
|
|
317
|
+
this._firstNonInitialNavigationCommittedReject = (e) => {
|
|
318
|
+
};
|
|
342
319
|
// Marks the oopif session that remote -> local transition has happened in the parent.
|
|
343
320
|
// See Target.detachedFromTarget handler for details.
|
|
344
321
|
this._swappedIn = false;
|
|
345
322
|
this._videoRecorder = null;
|
|
346
323
|
this._screencastId = null;
|
|
347
|
-
this._screencastClients = new Set();
|
|
348
|
-
this.
|
|
349
|
-
this.
|
|
350
|
-
this._workerSessions = new Map();
|
|
324
|
+
this._screencastClients = /* @__PURE__ */ new Set();
|
|
325
|
+
this._workerSessions = /* @__PURE__ */ new Map();
|
|
326
|
+
this._initScriptIds = /* @__PURE__ */ new Map();
|
|
351
327
|
this._client = client;
|
|
352
328
|
this._crPage = crPage;
|
|
353
329
|
this._page = crPage._page;
|
|
354
330
|
this._targetId = targetId;
|
|
355
331
|
this._parentSession = parentSession;
|
|
356
|
-
if (parentSession)
|
|
332
|
+
if (parentSession)
|
|
333
|
+
parentSession._childSessions.add(this);
|
|
357
334
|
this._firstNonInitialNavigationCommittedPromise = new Promise((f, r) => {
|
|
358
335
|
this._firstNonInitialNavigationCommittedFulfill = f;
|
|
359
336
|
this._firstNonInitialNavigationCommittedReject = r;
|
|
360
337
|
});
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
this._firstNonInitialNavigationCommittedPromise.catch(() => {});
|
|
338
|
+
this._firstNonInitialNavigationCommittedPromise.catch(() => {
|
|
339
|
+
});
|
|
364
340
|
}
|
|
365
341
|
_isMainFrame() {
|
|
366
342
|
return this._targetId === this._crPage._targetId;
|
|
367
343
|
}
|
|
368
344
|
_addRendererListeners() {
|
|
369
|
-
this._eventListeners.push(...[
|
|
345
|
+
this._eventListeners.push(...[
|
|
346
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Log.entryAdded", (event) => this._onLogEntryAdded(event)),
|
|
347
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.fileChooserOpened", (event) => this._onFileChooserOpened(event)),
|
|
348
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.frameAttached", (event) => this._onFrameAttached(event.frameId, event.parentFrameId)),
|
|
349
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.frameDetached", (event) => this._onFrameDetached(event.frameId, event.reason)),
|
|
350
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.frameNavigated", (event) => this._onFrameNavigated(event.frame, false)),
|
|
351
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.frameRequestedNavigation", (event) => this._onFrameRequestedNavigation(event)),
|
|
352
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.javascriptDialogOpening", (event) => this._onDialog(event)),
|
|
353
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.navigatedWithinDocument", (event) => this._onFrameNavigatedWithinDocument(event.frameId, event.url)),
|
|
354
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Runtime.bindingCalled", (event) => this._onBindingCalled(event)),
|
|
355
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Runtime.consoleAPICalled", (event) => this._onConsoleAPI(event)),
|
|
356
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Runtime.exceptionThrown", (exception) => this._handleException(exception.exceptionDetails)),
|
|
357
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Runtime.executionContextCreated", (event) => this._onExecutionContextCreated(event.context)),
|
|
358
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Runtime.executionContextDestroyed", (event) => this._onExecutionContextDestroyed(event.executionContextId)),
|
|
359
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Runtime.executionContextsCleared", (event) => this._onExecutionContextsCleared()),
|
|
360
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Target.attachedToTarget", (event) => this._onAttachedToTarget(event)),
|
|
361
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Target.detachedFromTarget", (event) => this._onDetachedFromTarget(event))
|
|
362
|
+
]);
|
|
370
363
|
}
|
|
371
364
|
_addBrowserListeners() {
|
|
372
|
-
this._eventListeners.push(...[
|
|
365
|
+
this._eventListeners.push(...[
|
|
366
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Inspector.targetCrashed", (event) => this._onTargetCrashed()),
|
|
367
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.screencastFrame", (event) => this._onScreencastFrame(event)),
|
|
368
|
+
import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.windowOpen", (event) => this._onWindowOpen(event))
|
|
369
|
+
]);
|
|
373
370
|
}
|
|
374
371
|
async _initialize(hasUIWindow) {
|
|
375
|
-
const isSettingStorageState = this._page.
|
|
372
|
+
const isSettingStorageState = this._page.browserContext.isSettingStorageState();
|
|
376
373
|
if (!isSettingStorageState && hasUIWindow && !this._crPage._browserContext._browser.isClank() && !this._crPage._browserContext._options.noDefaultViewport) {
|
|
377
|
-
const {
|
|
378
|
-
windowId
|
|
379
|
-
} = await this._client.send('Browser.getWindowForTarget');
|
|
374
|
+
const { windowId } = await this._client.send("Browser.getWindowForTarget");
|
|
380
375
|
this._windowId = windowId;
|
|
381
376
|
}
|
|
382
377
|
let screencastOptions;
|
|
383
378
|
if (!isSettingStorageState && this._isMainFrame() && this._crPage._browserContext._options.recordVideo && hasUIWindow) {
|
|
384
|
-
const screencastId = (0,
|
|
385
|
-
const outputFile =
|
|
379
|
+
const screencastId = (0, import_crypto.createGuid)();
|
|
380
|
+
const outputFile = import_path.default.join(this._crPage._browserContext._options.recordVideo.dir, screencastId + ".webm");
|
|
386
381
|
screencastOptions = {
|
|
387
382
|
// validateBrowserContextOptions ensures correct video size.
|
|
388
383
|
...this._crPage._browserContext._options.recordVideo.size,
|
|
389
384
|
outputFile
|
|
390
385
|
};
|
|
391
386
|
await this._crPage._browserContext._ensureVideosPath();
|
|
392
|
-
// Note: it is important to start video recorder before sending Page.startScreencast,
|
|
393
|
-
// and it is equally important to send Page.startScreencast before sending Runtime.runIfWaitingForDebugger.
|
|
394
387
|
await this._createVideoRecorder(screencastId, screencastOptions);
|
|
395
|
-
this._crPage._page.waitForInitializedOrError().then(p => {
|
|
396
|
-
if (p instanceof Error)
|
|
388
|
+
this._crPage._page.waitForInitializedOrError().then((p) => {
|
|
389
|
+
if (p instanceof Error)
|
|
390
|
+
this._stopVideoRecording().catch(() => {
|
|
391
|
+
});
|
|
397
392
|
});
|
|
398
393
|
}
|
|
399
394
|
let lifecycleEventsEnabled;
|
|
400
|
-
if (!this._isMainFrame())
|
|
395
|
+
if (!this._isMainFrame())
|
|
396
|
+
this._addRendererListeners();
|
|
401
397
|
this._addBrowserListeners();
|
|
402
|
-
const promises = [
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
this._eventListeners.push(
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}), this._crPage._networkManager.addSession(this._client, undefined, this._isMainFrame()), this._client.send('Target.setAutoAttach', {
|
|
439
|
-
autoAttach: true,
|
|
440
|
-
waitForDebuggerOnStart: true,
|
|
441
|
-
flatten: true
|
|
442
|
-
})];
|
|
398
|
+
const promises = [
|
|
399
|
+
this._client.send("Page.enable"),
|
|
400
|
+
this._client.send("Page.getFrameTree").then(({ frameTree }) => {
|
|
401
|
+
if (this._isMainFrame()) {
|
|
402
|
+
this._handleFrameTree(frameTree);
|
|
403
|
+
this._addRendererListeners();
|
|
404
|
+
}
|
|
405
|
+
const localFrames = this._isMainFrame() ? this._page.frames() : [this._page.frameManager.frame(this._targetId)];
|
|
406
|
+
for (const frame of localFrames) {
|
|
407
|
+
this._client._sendMayFail("Page.createIsolatedWorld", {
|
|
408
|
+
frameId: frame._id,
|
|
409
|
+
grantUniveralAccess: true,
|
|
410
|
+
worldName: this._crPage.utilityWorldName
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
const isInitialEmptyPage = this._isMainFrame() && this._page.mainFrame().url() === ":";
|
|
414
|
+
if (isInitialEmptyPage) {
|
|
415
|
+
lifecycleEventsEnabled.catch((e) => {
|
|
416
|
+
}).then(() => {
|
|
417
|
+
this._eventListeners.push(import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.lifecycleEvent", (event) => this._onLifecycleEvent(event)));
|
|
418
|
+
});
|
|
419
|
+
} else {
|
|
420
|
+
this._firstNonInitialNavigationCommittedFulfill();
|
|
421
|
+
this._eventListeners.push(import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.lifecycleEvent", (event) => this._onLifecycleEvent(event)));
|
|
422
|
+
}
|
|
423
|
+
}),
|
|
424
|
+
this._client.send("Log.enable", {}),
|
|
425
|
+
lifecycleEventsEnabled = this._client.send("Page.setLifecycleEventsEnabled", { enabled: true }),
|
|
426
|
+
this._client.send("Runtime.enable", {}),
|
|
427
|
+
this._client.send("Page.addScriptToEvaluateOnNewDocument", {
|
|
428
|
+
source: "",
|
|
429
|
+
worldName: this._crPage.utilityWorldName
|
|
430
|
+
}),
|
|
431
|
+
this._crPage._networkManager.addSession(this._client, void 0, this._isMainFrame()),
|
|
432
|
+
this._client.send("Target.setAutoAttach", { autoAttach: true, waitForDebuggerOnStart: true, flatten: true })
|
|
433
|
+
];
|
|
443
434
|
if (!isSettingStorageState) {
|
|
444
|
-
if (this.
|
|
445
|
-
|
|
446
|
-
|
|
435
|
+
if (this._crPage._browserContext.needsPlaywrightBinding())
|
|
436
|
+
promises.push(this.exposePlaywrightBinding());
|
|
437
|
+
if (this._isMainFrame())
|
|
438
|
+
promises.push(this._client.send("Emulation.setFocusEmulationEnabled", { enabled: true }));
|
|
447
439
|
const options = this._crPage._browserContext._options;
|
|
448
|
-
if (options.bypassCSP)
|
|
449
|
-
enabled: true
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
if (
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
if (options.
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
if (options.
|
|
463
|
-
|
|
464
|
-
if (!this._crPage._browserContext._browser.options.headful)
|
|
440
|
+
if (options.bypassCSP)
|
|
441
|
+
promises.push(this._client.send("Page.setBypassCSP", { enabled: true }));
|
|
442
|
+
if (options.ignoreHTTPSErrors || options.internalIgnoreHTTPSErrors)
|
|
443
|
+
promises.push(this._client.send("Security.setIgnoreCertificateErrors", { ignore: true }));
|
|
444
|
+
if (this._isMainFrame())
|
|
445
|
+
promises.push(this._updateViewport());
|
|
446
|
+
if (options.hasTouch)
|
|
447
|
+
promises.push(this._client.send("Emulation.setTouchEmulationEnabled", { enabled: true }));
|
|
448
|
+
if (options.javaScriptEnabled === false)
|
|
449
|
+
promises.push(this._client.send("Emulation.setScriptExecutionDisabled", { value: true }));
|
|
450
|
+
if (options.userAgent || options.locale)
|
|
451
|
+
promises.push(this._updateUserAgent());
|
|
452
|
+
if (options.locale)
|
|
453
|
+
promises.push(emulateLocale(this._client, options.locale));
|
|
454
|
+
if (options.timezoneId)
|
|
455
|
+
promises.push(emulateTimezone(this._client, options.timezoneId));
|
|
456
|
+
if (!this._crPage._browserContext._browser.options.headful)
|
|
457
|
+
promises.push(this._setDefaultFontFamilies(this._client));
|
|
465
458
|
promises.push(this._updateGeolocation(true));
|
|
466
459
|
promises.push(this._updateEmulateMedia());
|
|
467
460
|
promises.push(this._updateFileChooserInterception(true));
|
|
468
|
-
for (const initScript of this._crPage._page.allInitScripts())
|
|
469
|
-
|
|
461
|
+
for (const initScript of this._crPage._page.allInitScripts())
|
|
462
|
+
promises.push(this._evaluateOnNewDocument(
|
|
463
|
+
initScript,
|
|
464
|
+
"main",
|
|
465
|
+
true
|
|
466
|
+
/* runImmediately */
|
|
467
|
+
));
|
|
468
|
+
if (screencastOptions)
|
|
469
|
+
promises.push(this._startVideoRecording(screencastOptions));
|
|
470
470
|
}
|
|
471
|
-
promises.push(this._client.send(
|
|
471
|
+
promises.push(this._client.send("Runtime.runIfWaitingForDebugger"));
|
|
472
472
|
promises.push(this._firstNonInitialNavigationCommittedPromise);
|
|
473
473
|
await Promise.all(promises);
|
|
474
474
|
}
|
|
475
475
|
dispose() {
|
|
476
|
-
this._firstNonInitialNavigationCommittedReject(new
|
|
477
|
-
for (const childSession of this._childSessions)
|
|
478
|
-
|
|
479
|
-
|
|
476
|
+
this._firstNonInitialNavigationCommittedReject(new import_errors.TargetClosedError());
|
|
477
|
+
for (const childSession of this._childSessions)
|
|
478
|
+
childSession.dispose();
|
|
479
|
+
if (this._parentSession)
|
|
480
|
+
this._parentSession._childSessions.delete(this);
|
|
481
|
+
import_eventsHelper.eventsHelper.removeEventListeners(this._eventListeners);
|
|
480
482
|
this._crPage._networkManager.removeSession(this._client);
|
|
481
483
|
this._crPage._sessions.delete(this._targetId);
|
|
482
484
|
this._client.dispose();
|
|
483
485
|
}
|
|
484
486
|
async _navigate(frame, url, referrer) {
|
|
485
|
-
const response = await this._client.send(
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
referrerPolicy: 'unsafeUrl'
|
|
490
|
-
});
|
|
491
|
-
if (response.errorText) throw new frames.NavigationAbortedError(response.loaderId, `${response.errorText} at ${url}`);
|
|
492
|
-
return {
|
|
493
|
-
newDocumentId: response.loaderId
|
|
494
|
-
};
|
|
487
|
+
const response = await this._client.send("Page.navigate", { url, referrer, frameId: frame._id, referrerPolicy: "unsafeUrl" });
|
|
488
|
+
if (response.errorText)
|
|
489
|
+
throw new frames.NavigationAbortedError(response.loaderId, `${response.errorText} at ${url}`);
|
|
490
|
+
return { newDocumentId: response.loaderId };
|
|
495
491
|
}
|
|
496
492
|
_onLifecycleEvent(event) {
|
|
497
|
-
if (this._eventBelongsToStaleFrame(event.frameId))
|
|
498
|
-
|
|
493
|
+
if (this._eventBelongsToStaleFrame(event.frameId))
|
|
494
|
+
return;
|
|
495
|
+
if (event.name === "load")
|
|
496
|
+
this._page.frameManager.frameLifecycleEvent(event.frameId, "load");
|
|
497
|
+
else if (event.name === "DOMContentLoaded")
|
|
498
|
+
this._page.frameManager.frameLifecycleEvent(event.frameId, "domcontentloaded");
|
|
499
499
|
}
|
|
500
500
|
_handleFrameTree(frameTree) {
|
|
501
501
|
this._onFrameAttached(frameTree.frame.id, frameTree.frame.parentId || null);
|
|
502
502
|
this._onFrameNavigated(frameTree.frame, true);
|
|
503
|
-
if (!frameTree.childFrames)
|
|
504
|
-
|
|
503
|
+
if (!frameTree.childFrames)
|
|
504
|
+
return;
|
|
505
|
+
for (const child of frameTree.childFrames)
|
|
506
|
+
this._handleFrameTree(child);
|
|
505
507
|
}
|
|
506
508
|
_eventBelongsToStaleFrame(frameId) {
|
|
507
|
-
const frame = this._page.
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
// When frame goes remote, parent process may still send some events
|
|
511
|
-
// related to the local frame before it sends frameDetached.
|
|
512
|
-
// In this case, we already have a new session for this frame, so events
|
|
513
|
-
// in the old session should be ignored.
|
|
509
|
+
const frame = this._page.frameManager.frame(frameId);
|
|
510
|
+
if (!frame)
|
|
511
|
+
return true;
|
|
514
512
|
const session = this._crPage._sessionForFrame(frame);
|
|
515
513
|
return session && session !== this && !session._swappedIn;
|
|
516
514
|
}
|
|
517
515
|
_onFrameAttached(frameId, parentFrameId) {
|
|
518
516
|
const frameSession = this._crPage._sessions.get(frameId);
|
|
519
517
|
if (frameSession && frameId !== this._targetId) {
|
|
520
|
-
// This is a remote -> local frame transition.
|
|
521
518
|
frameSession._swappedIn = true;
|
|
522
|
-
const frame = this._page.
|
|
523
|
-
|
|
524
|
-
|
|
519
|
+
const frame = this._page.frameManager.frame(frameId);
|
|
520
|
+
if (frame)
|
|
521
|
+
this._page.frameManager.removeChildFramesRecursively(frame);
|
|
525
522
|
return;
|
|
526
523
|
}
|
|
527
|
-
if (parentFrameId && !this._page.
|
|
528
|
-
// Parent frame may be gone already because some ancestor frame navigated and
|
|
529
|
-
// destroyed the whole subtree of some oopif, while oopif's process is still sending us events.
|
|
530
|
-
// Be careful to not confuse this with "main frame navigated cross-process" scenario
|
|
531
|
-
// where parentFrameId is null.
|
|
524
|
+
if (parentFrameId && !this._page.frameManager.frame(parentFrameId)) {
|
|
532
525
|
return;
|
|
533
526
|
}
|
|
534
|
-
this._page.
|
|
527
|
+
this._page.frameManager.frameAttached(frameId, parentFrameId);
|
|
535
528
|
}
|
|
536
529
|
_onFrameNavigated(framePayload, initial) {
|
|
537
|
-
if (this._eventBelongsToStaleFrame(framePayload.id))
|
|
538
|
-
|
|
539
|
-
|
|
530
|
+
if (this._eventBelongsToStaleFrame(framePayload.id))
|
|
531
|
+
return;
|
|
532
|
+
this._page.frameManager.frameCommittedNewDocumentNavigation(framePayload.id, framePayload.url + (framePayload.urlFragment || ""), framePayload.name || "", framePayload.loaderId, initial);
|
|
533
|
+
if (!initial)
|
|
534
|
+
this._firstNonInitialNavigationCommittedFulfill();
|
|
540
535
|
}
|
|
541
536
|
_onFrameRequestedNavigation(payload) {
|
|
542
|
-
if (this._eventBelongsToStaleFrame(payload.frameId))
|
|
543
|
-
|
|
537
|
+
if (this._eventBelongsToStaleFrame(payload.frameId))
|
|
538
|
+
return;
|
|
539
|
+
if (payload.disposition === "currentTab")
|
|
540
|
+
this._page.frameManager.frameRequestedNavigation(payload.frameId);
|
|
544
541
|
}
|
|
545
542
|
_onFrameNavigatedWithinDocument(frameId, url) {
|
|
546
|
-
if (this._eventBelongsToStaleFrame(frameId))
|
|
547
|
-
|
|
543
|
+
if (this._eventBelongsToStaleFrame(frameId))
|
|
544
|
+
return;
|
|
545
|
+
this._page.frameManager.frameCommittedSameDocumentNavigation(frameId, url);
|
|
548
546
|
}
|
|
549
547
|
_onFrameDetached(frameId, reason) {
|
|
550
548
|
if (this._crPage._sessions.has(frameId)) {
|
|
551
|
-
// This is a local -> remote frame transition, where
|
|
552
|
-
// Page.frameDetached arrives after Target.attachedToTarget.
|
|
553
|
-
// We've already handled the new target and frame reattach - nothing to do here.
|
|
554
549
|
return;
|
|
555
550
|
}
|
|
556
|
-
if (reason ===
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
const frame = this._page._frameManager.frame(frameId);
|
|
561
|
-
if (frame) this._page._frameManager.removeChildFramesRecursively(frame);
|
|
551
|
+
if (reason === "swap") {
|
|
552
|
+
const frame = this._page.frameManager.frame(frameId);
|
|
553
|
+
if (frame)
|
|
554
|
+
this._page.frameManager.removeChildFramesRecursively(frame);
|
|
562
555
|
return;
|
|
563
556
|
}
|
|
564
|
-
|
|
565
|
-
this._page._frameManager.frameDetached(frameId);
|
|
557
|
+
this._page.frameManager.frameDetached(frameId);
|
|
566
558
|
}
|
|
567
559
|
_onExecutionContextCreated(contextPayload) {
|
|
568
|
-
const frame = contextPayload.auxData ? this._page.
|
|
569
|
-
if (!frame || this._eventBelongsToStaleFrame(frame._id))
|
|
570
|
-
|
|
560
|
+
const frame = contextPayload.auxData ? this._page.frameManager.frame(contextPayload.auxData.frameId) : null;
|
|
561
|
+
if (!frame || this._eventBelongsToStaleFrame(frame._id))
|
|
562
|
+
return;
|
|
563
|
+
const delegate = new import_crExecutionContext.CRExecutionContext(this._client, contextPayload);
|
|
571
564
|
let worldName;
|
|
572
|
-
if (contextPayload.auxData && !!contextPayload.auxData.isDefault)
|
|
565
|
+
if (contextPayload.auxData && !!contextPayload.auxData.isDefault)
|
|
566
|
+
worldName = "main";
|
|
567
|
+
else if (contextPayload.name === this._crPage.utilityWorldName)
|
|
568
|
+
worldName = "utility";
|
|
569
|
+
else
|
|
570
|
+
return;
|
|
573
571
|
const context = new dom.FrameExecutionContext(delegate, frame, worldName);
|
|
574
|
-
if (worldName)
|
|
572
|
+
if (worldName)
|
|
573
|
+
frame._contextCreated(worldName, context);
|
|
575
574
|
this._contextIdToContext.set(contextPayload.id, context);
|
|
576
575
|
}
|
|
577
576
|
_onExecutionContextDestroyed(executionContextId) {
|
|
578
577
|
const context = this._contextIdToContext.get(executionContextId);
|
|
579
|
-
if (!context)
|
|
578
|
+
if (!context)
|
|
579
|
+
return;
|
|
580
580
|
this._contextIdToContext.delete(executionContextId);
|
|
581
581
|
context.frame._contextDestroyed(context);
|
|
582
582
|
}
|
|
583
583
|
_onExecutionContextsCleared() {
|
|
584
|
-
for (const contextId of Array.from(this._contextIdToContext.keys()))
|
|
584
|
+
for (const contextId of Array.from(this._contextIdToContext.keys()))
|
|
585
|
+
this._onExecutionContextDestroyed(contextId);
|
|
585
586
|
}
|
|
586
587
|
_onAttachedToTarget(event) {
|
|
587
|
-
var _this$_page$_frameMan;
|
|
588
588
|
const session = this._client.createChildSession(event.sessionId);
|
|
589
|
-
if (event.targetInfo.type ===
|
|
590
|
-
// Frame id equals target id.
|
|
589
|
+
if (event.targetInfo.type === "iframe") {
|
|
591
590
|
const targetId = event.targetInfo.targetId;
|
|
592
|
-
const frame = this._page.
|
|
593
|
-
if (!frame)
|
|
594
|
-
|
|
591
|
+
const frame = this._page.frameManager.frame(targetId);
|
|
592
|
+
if (!frame)
|
|
593
|
+
return;
|
|
594
|
+
this._page.frameManager.removeChildFramesRecursively(frame);
|
|
595
595
|
for (const [contextId, context] of this._contextIdToContext) {
|
|
596
|
-
if (context.frame === frame)
|
|
596
|
+
if (context.frame === frame)
|
|
597
|
+
this._onExecutionContextDestroyed(contextId);
|
|
597
598
|
}
|
|
598
599
|
const frameSession = new FrameSession(this._crPage, session, targetId, this);
|
|
599
600
|
this._crPage._sessions.set(targetId, frameSession);
|
|
600
|
-
frameSession._initialize(false).catch(e => e);
|
|
601
|
+
frameSession._initialize(false).catch((e) => e);
|
|
601
602
|
return;
|
|
602
603
|
}
|
|
603
|
-
if (event.targetInfo.type !==
|
|
604
|
-
session.detach().catch(() => {
|
|
604
|
+
if (event.targetInfo.type !== "worker") {
|
|
605
|
+
session.detach().catch(() => {
|
|
606
|
+
});
|
|
605
607
|
return;
|
|
606
608
|
}
|
|
607
609
|
const url = event.targetInfo.url;
|
|
608
|
-
const worker = new
|
|
609
|
-
this._page.
|
|
610
|
+
const worker = new import_page.Worker(this._page, url);
|
|
611
|
+
this._page.addWorker(event.sessionId, worker);
|
|
610
612
|
this._workerSessions.set(event.sessionId, session);
|
|
611
|
-
session.once(
|
|
612
|
-
worker.
|
|
613
|
+
session.once("Runtime.executionContextCreated", async (event2) => {
|
|
614
|
+
worker.createExecutionContext(new import_crExecutionContext.CRExecutionContext(session, event2.context));
|
|
613
615
|
});
|
|
614
|
-
|
|
615
|
-
session.
|
|
616
|
-
// TODO: attribute workers to the right frame.
|
|
617
|
-
this._crPage._networkManager.addSession(session, (_this$_page$_frameMan = this._page._frameManager.frame(this._targetId)) !== null && _this$_page$_frameMan !== void 0 ? _this$_page$_frameMan : undefined).catch(() => {});
|
|
618
|
-
session._sendMayFail('Runtime.runIfWaitingForDebugger');
|
|
619
|
-
session._sendMayFail('Target.setAutoAttach', {
|
|
620
|
-
autoAttach: true,
|
|
621
|
-
waitForDebuggerOnStart: true,
|
|
622
|
-
flatten: true
|
|
616
|
+
session._sendMayFail("Runtime.enable");
|
|
617
|
+
this._crPage._networkManager.addSession(session, this._page.frameManager.frame(this._targetId) ?? void 0).catch(() => {
|
|
623
618
|
});
|
|
624
|
-
session.
|
|
625
|
-
session.
|
|
626
|
-
session.on(
|
|
627
|
-
|
|
628
|
-
|
|
619
|
+
session._sendMayFail("Runtime.runIfWaitingForDebugger");
|
|
620
|
+
session._sendMayFail("Target.setAutoAttach", { autoAttach: true, waitForDebuggerOnStart: true, flatten: true });
|
|
621
|
+
session.on("Target.attachedToTarget", (event2) => this._onAttachedToTarget(event2));
|
|
622
|
+
session.on("Target.detachedFromTarget", (event2) => this._onDetachedFromTarget(event2));
|
|
623
|
+
session.on("Runtime.consoleAPICalled", (event2) => {
|
|
624
|
+
const args = event2.args.map((o) => (0, import_crExecutionContext.createHandle)(worker.existingExecutionContext, o));
|
|
625
|
+
this._page.addConsoleMessage(event2.type, args, (0, import_crProtocolHelper.toConsoleMessageLocation)(event2.stackTrace));
|
|
629
626
|
});
|
|
630
|
-
session.on(
|
|
627
|
+
session.on("Runtime.exceptionThrown", (exception) => this._page.emitOnContextOnceInitialized(import_browserContext.BrowserContext.Events.PageError, (0, import_crProtocolHelper.exceptionToError)(exception.exceptionDetails), this._page));
|
|
631
628
|
}
|
|
632
629
|
_onDetachedFromTarget(event) {
|
|
633
|
-
// This might be a worker...
|
|
634
630
|
const workerSession = this._workerSessions.get(event.sessionId);
|
|
635
631
|
if (workerSession) {
|
|
636
632
|
workerSession.dispose();
|
|
637
|
-
this._page.
|
|
633
|
+
this._page.removeWorker(event.sessionId);
|
|
638
634
|
return;
|
|
639
635
|
}
|
|
640
|
-
|
|
641
|
-
// ... or an oopif.
|
|
642
636
|
const childFrameSession = this._crPage._sessions.get(event.targetId);
|
|
643
|
-
if (!childFrameSession)
|
|
644
|
-
|
|
645
|
-
// Usually, we get frameAttached in this session first and mark child as swappedIn.
|
|
637
|
+
if (!childFrameSession)
|
|
638
|
+
return;
|
|
646
639
|
if (childFrameSession._swappedIn) {
|
|
647
640
|
childFrameSession.dispose();
|
|
648
641
|
return;
|
|
649
642
|
}
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
// or just a remote -> local transition. In the latter case, frameAttached
|
|
654
|
-
// is already inflight, so let's make a safe roundtrip to ensure it arrives.
|
|
655
|
-
this._client.send('Page.enable').catch(e => null).then(() => {
|
|
656
|
-
// Child was not swapped in - that means frameAttached did not happen and
|
|
657
|
-
// this is remote detach rather than remote -> local swap.
|
|
658
|
-
if (!childFrameSession._swappedIn) this._page._frameManager.frameDetached(event.targetId);
|
|
643
|
+
this._client.send("Page.enable").catch((e) => null).then(() => {
|
|
644
|
+
if (!childFrameSession._swappedIn)
|
|
645
|
+
this._page.frameManager.frameDetached(event.targetId);
|
|
659
646
|
childFrameSession.dispose();
|
|
660
647
|
});
|
|
661
648
|
}
|
|
@@ -664,158 +651,148 @@ class FrameSession {
|
|
|
664
651
|
}
|
|
665
652
|
async _onConsoleAPI(event) {
|
|
666
653
|
if (event.executionContextId === 0) {
|
|
667
|
-
// DevTools protocol stores the last 1000 console messages. These
|
|
668
|
-
// messages are always reported even for removed execution contexts. In
|
|
669
|
-
// this case, they are marked with executionContextId = 0 and are
|
|
670
|
-
// reported upon enabling Runtime agent.
|
|
671
|
-
//
|
|
672
|
-
// Ignore these messages since:
|
|
673
|
-
// - there's no execution context we can use to operate with message
|
|
674
|
-
// arguments
|
|
675
|
-
// - these messages are reported before Playwright clients can subscribe
|
|
676
|
-
// to the 'console'
|
|
677
|
-
// page event.
|
|
678
|
-
//
|
|
679
|
-
// @see https://github.com/GoogleChrome/puppeteer/issues/3865
|
|
680
654
|
return;
|
|
681
655
|
}
|
|
682
656
|
const context = this._contextIdToContext.get(event.executionContextId);
|
|
683
|
-
if (!context)
|
|
684
|
-
|
|
685
|
-
|
|
657
|
+
if (!context)
|
|
658
|
+
return;
|
|
659
|
+
const values = event.args.map((arg) => (0, import_crExecutionContext.createHandle)(context, arg));
|
|
660
|
+
this._page.addConsoleMessage(event.type, values, (0, import_crProtocolHelper.toConsoleMessageLocation)(event.stackTrace));
|
|
686
661
|
}
|
|
687
662
|
async _onBindingCalled(event) {
|
|
688
663
|
const pageOrError = await this._crPage._page.waitForInitializedOrError();
|
|
689
664
|
if (!(pageOrError instanceof Error)) {
|
|
690
665
|
const context = this._contextIdToContext.get(event.executionContextId);
|
|
691
|
-
if (context)
|
|
666
|
+
if (context)
|
|
667
|
+
await this._page.onBindingCalled(event.payload, context);
|
|
692
668
|
}
|
|
693
669
|
}
|
|
694
670
|
_onDialog(event) {
|
|
695
|
-
if (!this._page.
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
671
|
+
if (!this._page.frameManager.frame(this._targetId))
|
|
672
|
+
return;
|
|
673
|
+
this._page.browserContext.dialogManager.dialogDidOpen(new dialog.Dialog(
|
|
674
|
+
this._page,
|
|
675
|
+
event.type,
|
|
676
|
+
event.message,
|
|
677
|
+
async (accept, promptText) => {
|
|
678
|
+
if (this._isMainFrame() && event.type === "beforeunload" && !accept)
|
|
679
|
+
this._page.frameManager.frameAbortedNavigation(this._page.mainFrame()._id, "navigation cancelled by beforeunload dialog");
|
|
680
|
+
await this._client.send("Page.handleJavaScriptDialog", { accept, promptText });
|
|
681
|
+
},
|
|
682
|
+
event.defaultPrompt
|
|
683
|
+
));
|
|
704
684
|
}
|
|
705
685
|
_handleException(exceptionDetails) {
|
|
706
|
-
this._page.emitOnContextOnceInitialized(
|
|
686
|
+
this._page.emitOnContextOnceInitialized(import_browserContext.BrowserContext.Events.PageError, (0, import_crProtocolHelper.exceptionToError)(exceptionDetails), this._page);
|
|
707
687
|
}
|
|
708
688
|
async _onTargetCrashed() {
|
|
709
689
|
this._client._markAsCrashed();
|
|
710
690
|
this._page._didCrash();
|
|
711
691
|
}
|
|
712
692
|
_onLogEntryAdded(event) {
|
|
713
|
-
const {
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
source,
|
|
718
|
-
url,
|
|
719
|
-
lineNumber
|
|
720
|
-
} = event.entry;
|
|
721
|
-
if (args) args.map(arg => (0, _crProtocolHelper.releaseObject)(this._client, arg.objectId));
|
|
722
|
-
if (source !== 'worker') {
|
|
693
|
+
const { level, text, args, source, url, lineNumber } = event.entry;
|
|
694
|
+
if (args)
|
|
695
|
+
args.map((arg) => (0, import_crProtocolHelper.releaseObject)(this._client, arg.objectId));
|
|
696
|
+
if (source !== "worker") {
|
|
723
697
|
const location = {
|
|
724
|
-
url: url ||
|
|
698
|
+
url: url || "",
|
|
725
699
|
lineNumber: lineNumber || 0,
|
|
726
700
|
columnNumber: 0
|
|
727
701
|
};
|
|
728
|
-
this._page.
|
|
702
|
+
this._page.addConsoleMessage(level, [], location, text);
|
|
729
703
|
}
|
|
730
704
|
}
|
|
731
705
|
async _onFileChooserOpened(event) {
|
|
732
|
-
if (!event.backendNodeId)
|
|
733
|
-
|
|
734
|
-
|
|
706
|
+
if (!event.backendNodeId)
|
|
707
|
+
return;
|
|
708
|
+
const frame = this._page.frameManager.frame(event.frameId);
|
|
709
|
+
if (!frame)
|
|
710
|
+
return;
|
|
735
711
|
let handle;
|
|
736
712
|
try {
|
|
737
713
|
const utilityContext = await frame._utilityContext();
|
|
738
714
|
handle = await this._adoptBackendNodeId(event.backendNodeId, utilityContext);
|
|
739
715
|
} catch (e) {
|
|
740
|
-
// During async processing, frame/context may go away. We should not throw.
|
|
741
716
|
return;
|
|
742
717
|
}
|
|
743
718
|
await this._page._onFileChooserOpened(handle);
|
|
744
719
|
}
|
|
745
720
|
_willBeginDownload() {
|
|
746
721
|
if (!this._crPage._page.initializedOrUndefined()) {
|
|
747
|
-
|
|
748
|
-
// after the download begins.
|
|
749
|
-
this._firstNonInitialNavigationCommittedReject(new Error('Starting new page download'));
|
|
722
|
+
this._firstNonInitialNavigationCommittedReject(new Error("Starting new page download"));
|
|
750
723
|
}
|
|
751
724
|
}
|
|
752
725
|
_onScreencastFrame(payload) {
|
|
753
726
|
this._page.throttleScreencastFrameAck(() => {
|
|
754
|
-
this._client.send(
|
|
755
|
-
|
|
756
|
-
}).catch(() => {});
|
|
727
|
+
this._client.send("Page.screencastFrameAck", { sessionId: payload.sessionId }).catch(() => {
|
|
728
|
+
});
|
|
757
729
|
});
|
|
758
|
-
const buffer = Buffer.from(payload.data,
|
|
759
|
-
this._page.emit(
|
|
730
|
+
const buffer = Buffer.from(payload.data, "base64");
|
|
731
|
+
this._page.emit(import_page.Page.Events.ScreencastFrame, {
|
|
760
732
|
buffer,
|
|
761
|
-
frameSwapWallTime: payload.metadata.timestamp ? payload.metadata.timestamp *
|
|
733
|
+
frameSwapWallTime: payload.metadata.timestamp ? payload.metadata.timestamp * 1e3 : void 0,
|
|
762
734
|
width: payload.metadata.deviceWidth,
|
|
763
735
|
height: payload.metadata.deviceHeight
|
|
764
736
|
});
|
|
765
737
|
}
|
|
766
738
|
async _createVideoRecorder(screencastId, options) {
|
|
767
|
-
(0,
|
|
768
|
-
const ffmpegPath =
|
|
769
|
-
this._videoRecorder = await
|
|
739
|
+
(0, import_assert.assert)(!this._screencastId);
|
|
740
|
+
const ffmpegPath = import_registry.registry.findExecutable("ffmpeg").executablePathOrDie(this._page.browserContext._browser.sdkLanguage());
|
|
741
|
+
this._videoRecorder = await import_videoRecorder.VideoRecorder.launch(this._crPage._page, ffmpegPath, options);
|
|
770
742
|
this._screencastId = screencastId;
|
|
771
743
|
}
|
|
772
744
|
async _startVideoRecording(options) {
|
|
773
745
|
const screencastId = this._screencastId;
|
|
774
|
-
(0,
|
|
775
|
-
this._page.once(
|
|
776
|
-
|
|
746
|
+
(0, import_assert.assert)(screencastId);
|
|
747
|
+
this._page.once(import_page.Page.Events.Close, () => this._stopVideoRecording().catch(() => {
|
|
748
|
+
}));
|
|
749
|
+
const gotFirstFrame = new Promise((f) => this._client.once("Page.screencastFrame", f));
|
|
777
750
|
await this._startScreencast(this._videoRecorder, {
|
|
778
|
-
format:
|
|
751
|
+
format: "jpeg",
|
|
779
752
|
quality: 90,
|
|
780
753
|
maxWidth: options.width,
|
|
781
754
|
maxHeight: options.height
|
|
782
755
|
});
|
|
783
|
-
// Wait for the first frame before reporting video to the client.
|
|
784
756
|
gotFirstFrame.then(() => {
|
|
785
757
|
this._crPage._browserContext._browser._videoStarted(this._crPage._browserContext, screencastId, options.outputFile, this._crPage._page.waitForInitializedOrError());
|
|
786
758
|
});
|
|
787
759
|
}
|
|
788
760
|
async _stopVideoRecording() {
|
|
789
|
-
if (!this._screencastId)
|
|
761
|
+
if (!this._screencastId)
|
|
762
|
+
return;
|
|
790
763
|
const screencastId = this._screencastId;
|
|
791
764
|
this._screencastId = null;
|
|
792
765
|
const recorder = this._videoRecorder;
|
|
793
766
|
this._videoRecorder = null;
|
|
794
767
|
await this._stopScreencast(recorder);
|
|
795
|
-
await recorder.stop().catch(() => {
|
|
796
|
-
|
|
797
|
-
// starts closing before the video is fully written to disk it will wait for it.
|
|
768
|
+
await recorder.stop().catch(() => {
|
|
769
|
+
});
|
|
798
770
|
const video = this._crPage._browserContext._browser._takeVideo(screencastId);
|
|
799
|
-
video
|
|
771
|
+
video?.reportFinished();
|
|
800
772
|
}
|
|
801
773
|
async _startScreencast(client, options = {}) {
|
|
802
774
|
this._screencastClients.add(client);
|
|
803
|
-
if (this._screencastClients.size === 1)
|
|
775
|
+
if (this._screencastClients.size === 1)
|
|
776
|
+
await this._client.send("Page.startScreencast", options);
|
|
804
777
|
}
|
|
805
778
|
async _stopScreencast(client) {
|
|
806
779
|
this._screencastClients.delete(client);
|
|
807
|
-
if (!this._screencastClients.size)
|
|
780
|
+
if (!this._screencastClients.size)
|
|
781
|
+
await this._client._sendMayFail("Page.stopScreencast");
|
|
808
782
|
}
|
|
809
783
|
async _updateGeolocation(initial) {
|
|
810
784
|
const geolocation = this._crPage._browserContext._options.geolocation;
|
|
811
|
-
if (!initial || geolocation)
|
|
785
|
+
if (!initial || geolocation)
|
|
786
|
+
await this._client.send("Emulation.setGeolocationOverride", geolocation || {});
|
|
812
787
|
}
|
|
813
788
|
async _updateViewport(preserveWindowBoundaries) {
|
|
814
|
-
if (this._crPage._browserContext._browser.isClank())
|
|
815
|
-
|
|
789
|
+
if (this._crPage._browserContext._browser.isClank())
|
|
790
|
+
return;
|
|
791
|
+
(0, import_assert.assert)(this._isMainFrame());
|
|
816
792
|
const options = this._crPage._browserContext._options;
|
|
817
793
|
const emulatedSize = this._page.emulatedSize();
|
|
818
|
-
if (emulatedSize
|
|
794
|
+
if (!emulatedSize)
|
|
795
|
+
return;
|
|
819
796
|
const viewportSize = emulatedSize.viewport;
|
|
820
797
|
const screenSize = emulatedSize.screen;
|
|
821
798
|
const isLandscape = screenSize.width > screenSize.height;
|
|
@@ -826,45 +803,23 @@ class FrameSession {
|
|
|
826
803
|
screenWidth: screenSize.width,
|
|
827
804
|
screenHeight: screenSize.height,
|
|
828
805
|
deviceScaleFactor: options.deviceScaleFactor || 1,
|
|
829
|
-
screenOrientation: !!options.isMobile ? isLandscape ? {
|
|
830
|
-
angle: 90,
|
|
831
|
-
type: 'landscapePrimary'
|
|
832
|
-
} : {
|
|
833
|
-
angle: 0,
|
|
834
|
-
type: 'portraitPrimary'
|
|
835
|
-
} : {
|
|
836
|
-
angle: 0,
|
|
837
|
-
type: 'landscapePrimary'
|
|
838
|
-
},
|
|
806
|
+
screenOrientation: !!options.isMobile ? isLandscape ? { angle: 90, type: "landscapePrimary" } : { angle: 0, type: "portraitPrimary" } : { angle: 0, type: "landscapePrimary" },
|
|
839
807
|
dontSetVisibleSize: preserveWindowBoundaries
|
|
840
808
|
};
|
|
841
|
-
if (JSON.stringify(this._metricsOverride) === JSON.stringify(metricsOverride))
|
|
842
|
-
|
|
809
|
+
if (JSON.stringify(this._metricsOverride) === JSON.stringify(metricsOverride))
|
|
810
|
+
return;
|
|
811
|
+
const promises = [];
|
|
843
812
|
if (!preserveWindowBoundaries && this._windowId) {
|
|
844
|
-
let insets = {
|
|
845
|
-
width: 0,
|
|
846
|
-
height: 0
|
|
847
|
-
};
|
|
813
|
+
let insets = { width: 0, height: 0 };
|
|
848
814
|
if (this._crPage._browserContext._browser.options.headful) {
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
width:
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
if (process.platform ===
|
|
855
|
-
width:
|
|
856
|
-
height: 88
|
|
857
|
-
};else if (process.platform === 'linux') insets = {
|
|
858
|
-
width: 8,
|
|
859
|
-
height: 85
|
|
860
|
-
};else if (process.platform === 'darwin') insets = {
|
|
861
|
-
width: 2,
|
|
862
|
-
height: 80
|
|
863
|
-
};
|
|
815
|
+
insets = { width: 24, height: 88 };
|
|
816
|
+
if (process.platform === "win32")
|
|
817
|
+
insets = { width: 16, height: 88 };
|
|
818
|
+
else if (process.platform === "linux")
|
|
819
|
+
insets = { width: 8, height: 85 };
|
|
820
|
+
else if (process.platform === "darwin")
|
|
821
|
+
insets = { width: 2, height: 80 };
|
|
864
822
|
if (this._crPage._browserContext.isPersistentContext()) {
|
|
865
|
-
// FIXME: Chrome bug: OOPIF router is confused when hit target is
|
|
866
|
-
// outside browser window.
|
|
867
|
-
// Account for the infobar here to work around the bug.
|
|
868
823
|
insets.height += 46;
|
|
869
824
|
}
|
|
870
825
|
}
|
|
@@ -873,219 +828,201 @@ class FrameSession {
|
|
|
873
828
|
height: viewportSize.height + insets.height
|
|
874
829
|
}));
|
|
875
830
|
}
|
|
831
|
+
promises.push(this._client.send("Emulation.setDeviceMetricsOverride", metricsOverride));
|
|
876
832
|
await Promise.all(promises);
|
|
877
833
|
this._metricsOverride = metricsOverride;
|
|
878
834
|
}
|
|
879
835
|
async windowBounds() {
|
|
880
|
-
const {
|
|
881
|
-
bounds
|
|
882
|
-
} = await this._client.send('Browser.getWindowBounds', {
|
|
836
|
+
const { bounds } = await this._client.send("Browser.getWindowBounds", {
|
|
883
837
|
windowId: this._windowId
|
|
884
838
|
});
|
|
885
839
|
return bounds;
|
|
886
840
|
}
|
|
887
841
|
async setWindowBounds(bounds) {
|
|
888
|
-
return await this._client.send(
|
|
842
|
+
return await this._client.send("Browser.setWindowBounds", {
|
|
889
843
|
windowId: this._windowId,
|
|
890
844
|
bounds
|
|
891
845
|
});
|
|
892
846
|
}
|
|
893
847
|
async _updateEmulateMedia() {
|
|
894
848
|
const emulatedMedia = this._page.emulatedMedia();
|
|
895
|
-
|
|
896
|
-
const
|
|
897
|
-
const
|
|
898
|
-
const
|
|
899
|
-
const
|
|
900
|
-
const
|
|
901
|
-
|
|
902
|
-
name:
|
|
903
|
-
value:
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
}, {
|
|
908
|
-
name: 'forced-colors',
|
|
909
|
-
value: forcedColors
|
|
910
|
-
}, {
|
|
911
|
-
name: 'prefers-contrast',
|
|
912
|
-
value: contrast
|
|
913
|
-
}];
|
|
914
|
-
await this._client.send('Emulation.setEmulatedMedia', {
|
|
915
|
-
media,
|
|
916
|
-
features
|
|
917
|
-
});
|
|
849
|
+
const media = emulatedMedia.media === "no-override" ? "" : emulatedMedia.media;
|
|
850
|
+
const colorScheme = emulatedMedia.colorScheme === "no-override" ? "" : emulatedMedia.colorScheme;
|
|
851
|
+
const reducedMotion = emulatedMedia.reducedMotion === "no-override" ? "" : emulatedMedia.reducedMotion;
|
|
852
|
+
const forcedColors = emulatedMedia.forcedColors === "no-override" ? "" : emulatedMedia.forcedColors;
|
|
853
|
+
const contrast = emulatedMedia.contrast === "no-override" ? "" : emulatedMedia.contrast;
|
|
854
|
+
const features = [
|
|
855
|
+
{ name: "prefers-color-scheme", value: colorScheme },
|
|
856
|
+
{ name: "prefers-reduced-motion", value: reducedMotion },
|
|
857
|
+
{ name: "forced-colors", value: forcedColors },
|
|
858
|
+
{ name: "prefers-contrast", value: contrast }
|
|
859
|
+
];
|
|
860
|
+
await this._client.send("Emulation.setEmulatedMedia", { media, features });
|
|
918
861
|
}
|
|
919
862
|
async _updateUserAgent() {
|
|
920
863
|
const options = this._crPage._browserContext._options;
|
|
921
|
-
await this._client.send(
|
|
922
|
-
userAgent: options.userAgent ||
|
|
864
|
+
await this._client.send("Emulation.setUserAgentOverride", {
|
|
865
|
+
userAgent: options.userAgent || "",
|
|
923
866
|
acceptLanguage: options.locale,
|
|
924
867
|
userAgentMetadata: calculateUserAgentMetadata(options)
|
|
925
868
|
});
|
|
926
869
|
}
|
|
927
870
|
async _setDefaultFontFamilies(session) {
|
|
928
|
-
const fontFamilies =
|
|
929
|
-
await session.send(
|
|
871
|
+
const fontFamilies = import_defaultFontFamilies.platformToFontFamilies[this._crPage._browserContext._browser._platform()];
|
|
872
|
+
await session.send("Page.setFontFamilies", fontFamilies);
|
|
930
873
|
}
|
|
931
874
|
async _updateFileChooserInterception(initial) {
|
|
932
875
|
const enabled = this._page.fileChooserIntercepted();
|
|
933
|
-
if (initial && !enabled)
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
}).catch(() => {}); // target can be closed.
|
|
937
|
-
}
|
|
938
|
-
async _evaluateOnNewDocument(initScript, world) {
|
|
939
|
-
const worldName = world === 'utility' ? UTILITY_WORLD_NAME : undefined;
|
|
940
|
-
const {
|
|
941
|
-
identifier
|
|
942
|
-
} = await this._client.send('Page.addScriptToEvaluateOnNewDocument', {
|
|
943
|
-
source: initScript.source,
|
|
944
|
-
worldName
|
|
876
|
+
if (initial && !enabled)
|
|
877
|
+
return;
|
|
878
|
+
await this._client.send("Page.setInterceptFileChooserDialog", { enabled }).catch(() => {
|
|
945
879
|
});
|
|
946
|
-
if (!initScript.internal) this._evaluateOnNewDocumentIdentifiers.push(identifier);
|
|
947
880
|
}
|
|
948
|
-
async
|
|
949
|
-
const
|
|
950
|
-
this.
|
|
951
|
-
|
|
952
|
-
|
|
881
|
+
async _evaluateOnNewDocument(initScript, world, runImmediately) {
|
|
882
|
+
const worldName = world === "utility" ? this._crPage.utilityWorldName : void 0;
|
|
883
|
+
const { identifier } = await this._client.send("Page.addScriptToEvaluateOnNewDocument", { source: initScript.source, worldName, runImmediately });
|
|
884
|
+
this._initScriptIds.set(initScript, identifier);
|
|
885
|
+
}
|
|
886
|
+
async _removeEvaluatesOnNewDocument(initScripts) {
|
|
887
|
+
const ids = [];
|
|
888
|
+
for (const script of initScripts) {
|
|
889
|
+
const id = this._initScriptIds.get(script);
|
|
890
|
+
if (id)
|
|
891
|
+
ids.push(id);
|
|
892
|
+
this._initScriptIds.delete(script);
|
|
893
|
+
}
|
|
894
|
+
await Promise.all(ids.map((identifier) => this._client.send("Page.removeScriptToEvaluateOnNewDocument", { identifier }).catch(() => {
|
|
953
895
|
})));
|
|
954
896
|
}
|
|
897
|
+
async exposePlaywrightBinding() {
|
|
898
|
+
await this._client.send("Runtime.addBinding", { name: import_page.PageBinding.kBindingName });
|
|
899
|
+
}
|
|
955
900
|
async _getContentFrame(handle) {
|
|
956
|
-
const nodeInfo = await this._client.send(
|
|
901
|
+
const nodeInfo = await this._client.send("DOM.describeNode", {
|
|
957
902
|
objectId: handle._objectId
|
|
958
903
|
});
|
|
959
|
-
if (!nodeInfo || typeof nodeInfo.node.frameId !==
|
|
960
|
-
|
|
904
|
+
if (!nodeInfo || typeof nodeInfo.node.frameId !== "string")
|
|
905
|
+
return null;
|
|
906
|
+
return this._page.frameManager.frame(nodeInfo.node.frameId);
|
|
961
907
|
}
|
|
962
908
|
async _getOwnerFrame(handle) {
|
|
963
|
-
|
|
964
|
-
const documentElement = await handle.evaluateHandle(node => {
|
|
909
|
+
const documentElement = await handle.evaluateHandle((node) => {
|
|
965
910
|
const doc = node;
|
|
966
|
-
if (doc.documentElement && doc.documentElement.ownerDocument === doc)
|
|
911
|
+
if (doc.documentElement && doc.documentElement.ownerDocument === doc)
|
|
912
|
+
return doc.documentElement;
|
|
967
913
|
return node.ownerDocument ? node.ownerDocument.documentElement : null;
|
|
968
914
|
});
|
|
969
|
-
if (!documentElement)
|
|
970
|
-
|
|
971
|
-
|
|
915
|
+
if (!documentElement)
|
|
916
|
+
return null;
|
|
917
|
+
if (!documentElement._objectId)
|
|
918
|
+
return null;
|
|
919
|
+
const nodeInfo = await this._client.send("DOM.describeNode", {
|
|
972
920
|
objectId: documentElement._objectId
|
|
973
921
|
});
|
|
974
|
-
const frameId = nodeInfo && typeof nodeInfo.node.frameId ===
|
|
922
|
+
const frameId = nodeInfo && typeof nodeInfo.node.frameId === "string" ? nodeInfo.node.frameId : null;
|
|
975
923
|
documentElement.dispose();
|
|
976
924
|
return frameId;
|
|
977
925
|
}
|
|
978
926
|
async _getBoundingBox(handle) {
|
|
979
|
-
const result = await this._client._sendMayFail(
|
|
927
|
+
const result = await this._client._sendMayFail("DOM.getBoxModel", {
|
|
980
928
|
objectId: handle._objectId
|
|
981
929
|
});
|
|
982
|
-
if (!result)
|
|
930
|
+
if (!result)
|
|
931
|
+
return null;
|
|
983
932
|
const quad = result.model.border;
|
|
984
933
|
const x = Math.min(quad[0], quad[2], quad[4], quad[6]);
|
|
985
934
|
const y = Math.min(quad[1], quad[3], quad[5], quad[7]);
|
|
986
935
|
const width = Math.max(quad[0], quad[2], quad[4], quad[6]) - x;
|
|
987
936
|
const height = Math.max(quad[1], quad[3], quad[5], quad[7]) - y;
|
|
988
937
|
const position = await this._framePosition();
|
|
989
|
-
if (!position)
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
y: y + position.y,
|
|
993
|
-
width,
|
|
994
|
-
height
|
|
995
|
-
};
|
|
938
|
+
if (!position)
|
|
939
|
+
return null;
|
|
940
|
+
return { x: x + position.x, y: y + position.y, width, height };
|
|
996
941
|
}
|
|
997
942
|
async _framePosition() {
|
|
998
|
-
const frame = this._page.
|
|
999
|
-
if (!frame)
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
y: 0
|
|
1003
|
-
};
|
|
943
|
+
const frame = this._page.frameManager.frame(this._targetId);
|
|
944
|
+
if (!frame)
|
|
945
|
+
return null;
|
|
946
|
+
if (frame === this._page.mainFrame())
|
|
947
|
+
return { x: 0, y: 0 };
|
|
1004
948
|
const element = await frame.frameElement();
|
|
1005
949
|
const box = await element.boundingBox();
|
|
1006
950
|
return box;
|
|
1007
951
|
}
|
|
1008
952
|
async _scrollRectIntoViewIfNeeded(handle, rect) {
|
|
1009
|
-
return await this._client.send(
|
|
953
|
+
return await this._client.send("DOM.scrollIntoViewIfNeeded", {
|
|
1010
954
|
objectId: handle._objectId,
|
|
1011
955
|
rect
|
|
1012
|
-
}).then(() =>
|
|
1013
|
-
if (e instanceof Error && e.message.includes(
|
|
1014
|
-
|
|
956
|
+
}).then(() => "done").catch((e) => {
|
|
957
|
+
if (e instanceof Error && e.message.includes("Node does not have a layout object"))
|
|
958
|
+
return "error:notvisible";
|
|
959
|
+
if (e instanceof Error && e.message.includes("Node is detached from document"))
|
|
960
|
+
return "error:notconnected";
|
|
1015
961
|
throw e;
|
|
1016
962
|
});
|
|
1017
963
|
}
|
|
1018
964
|
async _getContentQuads(handle) {
|
|
1019
|
-
const result = await this._client._sendMayFail(
|
|
965
|
+
const result = await this._client._sendMayFail("DOM.getContentQuads", {
|
|
1020
966
|
objectId: handle._objectId
|
|
1021
967
|
});
|
|
1022
|
-
if (!result)
|
|
968
|
+
if (!result)
|
|
969
|
+
return null;
|
|
1023
970
|
const position = await this._framePosition();
|
|
1024
|
-
if (!position)
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
y: quad[1] + position.y
|
|
1028
|
-
|
|
1029
|
-
x: quad[
|
|
1030
|
-
y: quad[
|
|
1031
|
-
|
|
1032
|
-
x: quad[4] + position.x,
|
|
1033
|
-
y: quad[5] + position.y
|
|
1034
|
-
}, {
|
|
1035
|
-
x: quad[6] + position.x,
|
|
1036
|
-
y: quad[7] + position.y
|
|
1037
|
-
}]);
|
|
971
|
+
if (!position)
|
|
972
|
+
return null;
|
|
973
|
+
return result.quads.map((quad) => [
|
|
974
|
+
{ x: quad[0] + position.x, y: quad[1] + position.y },
|
|
975
|
+
{ x: quad[2] + position.x, y: quad[3] + position.y },
|
|
976
|
+
{ x: quad[4] + position.x, y: quad[5] + position.y },
|
|
977
|
+
{ x: quad[6] + position.x, y: quad[7] + position.y }
|
|
978
|
+
]);
|
|
1038
979
|
}
|
|
1039
980
|
async _adoptElementHandle(handle, to) {
|
|
1040
|
-
const nodeInfo = await this._client.send(
|
|
981
|
+
const nodeInfo = await this._client.send("DOM.describeNode", {
|
|
1041
982
|
objectId: handle._objectId
|
|
1042
983
|
});
|
|
1043
984
|
return this._adoptBackendNodeId(nodeInfo.node.backendNodeId, to);
|
|
1044
985
|
}
|
|
1045
986
|
async _adoptBackendNodeId(backendNodeId, to) {
|
|
1046
|
-
const result = await this._client._sendMayFail(
|
|
987
|
+
const result = await this._client._sendMayFail("DOM.resolveNode", {
|
|
1047
988
|
backendNodeId,
|
|
1048
989
|
executionContextId: to.delegate._contextId
|
|
1049
990
|
});
|
|
1050
|
-
if (!result || result.object.subtype ===
|
|
1051
|
-
|
|
991
|
+
if (!result || result.object.subtype === "null")
|
|
992
|
+
throw new Error(dom.kUnableToAdoptErrorMessage);
|
|
993
|
+
return (0, import_crExecutionContext.createHandle)(to, result.object).asElement();
|
|
1052
994
|
}
|
|
1053
995
|
}
|
|
1054
996
|
async function emulateLocale(session, locale) {
|
|
1055
997
|
try {
|
|
1056
|
-
await session.send(
|
|
1057
|
-
locale
|
|
1058
|
-
});
|
|
998
|
+
await session.send("Emulation.setLocaleOverride", { locale });
|
|
1059
999
|
} catch (exception) {
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
// we are trying to set so it's not a problem.
|
|
1063
|
-
if (exception.message.includes('Another locale override is already in effect')) return;
|
|
1000
|
+
if (exception.message.includes("Another locale override is already in effect"))
|
|
1001
|
+
return;
|
|
1064
1002
|
throw exception;
|
|
1065
1003
|
}
|
|
1066
1004
|
}
|
|
1067
1005
|
async function emulateTimezone(session, timezoneId) {
|
|
1068
1006
|
try {
|
|
1069
|
-
await session.send(
|
|
1070
|
-
timezoneId: timezoneId
|
|
1071
|
-
});
|
|
1007
|
+
await session.send("Emulation.setTimezoneOverride", { timezoneId });
|
|
1072
1008
|
} catch (exception) {
|
|
1073
|
-
if (exception.message.includes(
|
|
1074
|
-
|
|
1009
|
+
if (exception.message.includes("Timezone override is already in effect"))
|
|
1010
|
+
return;
|
|
1011
|
+
if (exception.message.includes("Invalid timezone"))
|
|
1012
|
+
throw new Error(`Invalid timezone ID: ${timezoneId}`);
|
|
1075
1013
|
throw exception;
|
|
1076
1014
|
}
|
|
1077
1015
|
}
|
|
1078
|
-
|
|
1079
|
-
// Chromium reference: https://source.chromium.org/chromium/chromium/src/+/main:components/embedder_support/user_agent_utils.cc;l=434;drc=70a6711e08e9f9e0d8e4c48e9ba5cab62eb010c2
|
|
1080
1016
|
function calculateUserAgentMetadata(options) {
|
|
1081
1017
|
const ua = options.userAgent;
|
|
1082
|
-
if (!ua)
|
|
1018
|
+
if (!ua)
|
|
1019
|
+
return void 0;
|
|
1083
1020
|
const metadata = {
|
|
1084
1021
|
mobile: !!options.isMobile,
|
|
1085
|
-
model:
|
|
1086
|
-
architecture:
|
|
1087
|
-
platform:
|
|
1088
|
-
platformVersion:
|
|
1022
|
+
model: "",
|
|
1023
|
+
architecture: "x86",
|
|
1024
|
+
platform: "Windows",
|
|
1025
|
+
platformVersion: ""
|
|
1089
1026
|
};
|
|
1090
1027
|
const androidMatch = ua.match(/Android (\d+(\.\d+)?(\.\d+)?)/);
|
|
1091
1028
|
const iPhoneMatch = ua.match(/iPhone OS (\d+(_\d+)?)/);
|
|
@@ -1093,27 +1030,33 @@ function calculateUserAgentMetadata(options) {
|
|
|
1093
1030
|
const macOSMatch = ua.match(/Mac OS X (\d+(_\d+)?(_\d+)?)/);
|
|
1094
1031
|
const windowsMatch = ua.match(/Windows\D+(\d+(\.\d+)?(\.\d+)?)/);
|
|
1095
1032
|
if (androidMatch) {
|
|
1096
|
-
metadata.platform =
|
|
1033
|
+
metadata.platform = "Android";
|
|
1097
1034
|
metadata.platformVersion = androidMatch[1];
|
|
1098
|
-
metadata.architecture =
|
|
1035
|
+
metadata.architecture = "arm";
|
|
1099
1036
|
} else if (iPhoneMatch) {
|
|
1100
|
-
metadata.platform =
|
|
1037
|
+
metadata.platform = "iOS";
|
|
1101
1038
|
metadata.platformVersion = iPhoneMatch[1];
|
|
1102
|
-
metadata.architecture =
|
|
1039
|
+
metadata.architecture = "arm";
|
|
1103
1040
|
} else if (iPadMatch) {
|
|
1104
|
-
metadata.platform =
|
|
1041
|
+
metadata.platform = "iOS";
|
|
1105
1042
|
metadata.platformVersion = iPadMatch[1];
|
|
1106
|
-
metadata.architecture =
|
|
1043
|
+
metadata.architecture = "arm";
|
|
1107
1044
|
} else if (macOSMatch) {
|
|
1108
|
-
metadata.platform =
|
|
1045
|
+
metadata.platform = "macOS";
|
|
1109
1046
|
metadata.platformVersion = macOSMatch[1];
|
|
1110
|
-
if (!ua.includes(
|
|
1047
|
+
if (!ua.includes("Intel"))
|
|
1048
|
+
metadata.architecture = "arm";
|
|
1111
1049
|
} else if (windowsMatch) {
|
|
1112
|
-
metadata.platform =
|
|
1050
|
+
metadata.platform = "Windows";
|
|
1113
1051
|
metadata.platformVersion = windowsMatch[1];
|
|
1114
|
-
} else if (ua.toLowerCase().includes(
|
|
1115
|
-
metadata.platform =
|
|
1052
|
+
} else if (ua.toLowerCase().includes("linux")) {
|
|
1053
|
+
metadata.platform = "Linux";
|
|
1116
1054
|
}
|
|
1117
|
-
if (ua.includes(
|
|
1055
|
+
if (ua.includes("ARM"))
|
|
1056
|
+
metadata.architecture = "arm";
|
|
1118
1057
|
return metadata;
|
|
1119
|
-
}
|
|
1058
|
+
}
|
|
1059
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1060
|
+
0 && (module.exports = {
|
|
1061
|
+
CRPage
|
|
1062
|
+
});
|