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