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