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,122 +1,123 @@
|
|
|
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 wkPage_exports = {};
|
|
30
|
+
__export(wkPage_exports, {
|
|
31
|
+
WKPage: () => WKPage
|
|
5
32
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var dialog =
|
|
17
|
-
var dom =
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var network =
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
33
|
-
/**
|
|
34
|
-
* Copyright 2017 Google Inc. All rights reserved.
|
|
35
|
-
* Modifications copyright (c) Microsoft Corporation.
|
|
36
|
-
*
|
|
37
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
38
|
-
* you may not use this file except in compliance with the License.
|
|
39
|
-
* You may obtain a copy of the License at
|
|
40
|
-
*
|
|
41
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
42
|
-
*
|
|
43
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
44
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
45
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
46
|
-
* See the License for the specific language governing permissions and
|
|
47
|
-
* limitations under the License.
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
const UTILITY_WORLD_NAME = '__playwright_utility_world__';
|
|
33
|
+
module.exports = __toCommonJS(wkPage_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_utils = require("../../utils");
|
|
36
|
+
var import_headers = require("../../utils/isomorphic/headers");
|
|
37
|
+
var import_crypto = require("../utils/crypto");
|
|
38
|
+
var import_eventsHelper = require("../utils/eventsHelper");
|
|
39
|
+
var import_hostPlatform = require("../utils/hostPlatform");
|
|
40
|
+
var import_stackTrace = require("../../utils/isomorphic/stackTrace");
|
|
41
|
+
var import_utilsBundle = require("../../utilsBundle");
|
|
42
|
+
var import_browserContext = require("../browserContext");
|
|
43
|
+
var dialog = __toESM(require("../dialog"));
|
|
44
|
+
var dom = __toESM(require("../dom"));
|
|
45
|
+
var import_errors = require("../errors");
|
|
46
|
+
var import_helper = require("../helper");
|
|
47
|
+
var network = __toESM(require("../network"));
|
|
48
|
+
var import_page = require("../page");
|
|
49
|
+
var import_page2 = require("../page");
|
|
50
|
+
var import_wkAccessibility = require("./wkAccessibility");
|
|
51
|
+
var import_wkConnection = require("./wkConnection");
|
|
52
|
+
var import_wkExecutionContext = require("./wkExecutionContext");
|
|
53
|
+
var import_wkInput = require("./wkInput");
|
|
54
|
+
var import_wkInterceptableRequest = require("./wkInterceptableRequest");
|
|
55
|
+
var import_wkProvisionalPage = require("./wkProvisionalPage");
|
|
56
|
+
var import_wkWorkers = require("./wkWorkers");
|
|
57
|
+
var import_debugLogger = require("../utils/debugLogger");
|
|
58
|
+
const UTILITY_WORLD_NAME = "__playwright_utility_world__";
|
|
51
59
|
class WKPage {
|
|
52
60
|
constructor(browserContext, pageProxySession, opener) {
|
|
53
|
-
this.rawMouse = void 0;
|
|
54
|
-
this.rawKeyboard = void 0;
|
|
55
|
-
this.rawTouchscreen = void 0;
|
|
56
|
-
this._session = void 0;
|
|
57
61
|
this._provisionalPage = null;
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
60
|
-
this._opener = void 0;
|
|
61
|
-
this._requestIdToRequest = new Map();
|
|
62
|
-
this._requestIdToRequestWillBeSentEvent = new Map();
|
|
63
|
-
this._workers = void 0;
|
|
64
|
-
this._contextIdToContext = void 0;
|
|
62
|
+
this._requestIdToRequest = /* @__PURE__ */ new Map();
|
|
63
|
+
this._requestIdToRequestWillBeSentEvent = /* @__PURE__ */ new Map();
|
|
65
64
|
this._sessionListeners = [];
|
|
66
|
-
this.
|
|
67
|
-
|
|
68
|
-
this.
|
|
69
|
-
|
|
70
|
-
this._firstNonInitialNavigationCommittedReject = e => {};
|
|
65
|
+
this._firstNonInitialNavigationCommittedFulfill = () => {
|
|
66
|
+
};
|
|
67
|
+
this._firstNonInitialNavigationCommittedReject = (e) => {
|
|
68
|
+
};
|
|
71
69
|
this._lastConsoleMessage = null;
|
|
72
|
-
this._requestIdToResponseReceivedPayloadEvent = new Map();
|
|
73
|
-
// Holds window features for the next popup being opened via window.open,
|
|
74
|
-
// until the popup page proxy arrives.
|
|
75
|
-
this._nextWindowOpenPopupFeatures = void 0;
|
|
70
|
+
this._requestIdToResponseReceivedPayloadEvent = /* @__PURE__ */ new Map();
|
|
76
71
|
this._recordingVideoFile = null;
|
|
77
72
|
this._screencastGeneration = 0;
|
|
78
73
|
this._pageProxySession = pageProxySession;
|
|
79
74
|
this._opener = opener;
|
|
80
|
-
this.rawKeyboard = new
|
|
81
|
-
this.rawMouse = new
|
|
82
|
-
this.rawTouchscreen = new
|
|
83
|
-
this._contextIdToContext = new Map();
|
|
84
|
-
this._page = new
|
|
75
|
+
this.rawKeyboard = new import_wkInput.RawKeyboardImpl(pageProxySession);
|
|
76
|
+
this.rawMouse = new import_wkInput.RawMouseImpl(pageProxySession);
|
|
77
|
+
this.rawTouchscreen = new import_wkInput.RawTouchscreenImpl(pageProxySession);
|
|
78
|
+
this._contextIdToContext = /* @__PURE__ */ new Map();
|
|
79
|
+
this._page = new import_page2.Page(this, browserContext);
|
|
85
80
|
this.rawMouse.setPage(this._page);
|
|
86
|
-
this._workers = new
|
|
87
|
-
this._session =
|
|
81
|
+
this._workers = new import_wkWorkers.WKWorkers(this._page);
|
|
82
|
+
this._session = void 0;
|
|
88
83
|
this._browserContext = browserContext;
|
|
89
|
-
this._page.on(
|
|
90
|
-
this._eventListeners = [
|
|
84
|
+
this._page.on(import_page2.Page.Events.FrameDetached, (frame) => this._removeContextsForFrame(frame, false));
|
|
85
|
+
this._eventListeners = [
|
|
86
|
+
import_eventsHelper.eventsHelper.addEventListener(this._pageProxySession, "Target.targetCreated", this._onTargetCreated.bind(this)),
|
|
87
|
+
import_eventsHelper.eventsHelper.addEventListener(this._pageProxySession, "Target.targetDestroyed", this._onTargetDestroyed.bind(this)),
|
|
88
|
+
import_eventsHelper.eventsHelper.addEventListener(this._pageProxySession, "Target.dispatchMessageFromTarget", this._onDispatchMessageFromTarget.bind(this)),
|
|
89
|
+
import_eventsHelper.eventsHelper.addEventListener(this._pageProxySession, "Target.didCommitProvisionalTarget", this._onDidCommitProvisionalTarget.bind(this)),
|
|
90
|
+
import_eventsHelper.eventsHelper.addEventListener(this._pageProxySession, "Screencast.screencastFrame", this._onScreencastFrame.bind(this))
|
|
91
|
+
];
|
|
91
92
|
this._firstNonInitialNavigationCommittedPromise = new Promise((f, r) => {
|
|
92
93
|
this._firstNonInitialNavigationCommittedFulfill = f;
|
|
93
94
|
this._firstNonInitialNavigationCommittedReject = r;
|
|
94
95
|
});
|
|
95
96
|
if (opener && !browserContext._options.noDefaultViewport && opener._nextWindowOpenPopupFeatures) {
|
|
96
|
-
const viewportSize =
|
|
97
|
-
opener._nextWindowOpenPopupFeatures =
|
|
98
|
-
if (viewportSize)
|
|
99
|
-
viewport: viewportSize,
|
|
100
|
-
screen: viewportSize
|
|
101
|
-
};
|
|
97
|
+
const viewportSize = import_helper.helper.getViewportSizeFromWindowFeatures(opener._nextWindowOpenPopupFeatures);
|
|
98
|
+
opener._nextWindowOpenPopupFeatures = void 0;
|
|
99
|
+
if (viewportSize)
|
|
100
|
+
this._page._emulatedSize = { viewport: viewportSize, screen: viewportSize };
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
103
|
async _initializePageProxySession() {
|
|
105
|
-
if (this._page._browserContext.isSettingStorageState())
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
104
|
+
if (this._page._browserContext.isSettingStorageState())
|
|
105
|
+
return;
|
|
106
|
+
const promises = [
|
|
107
|
+
this._pageProxySession.send("Dialog.enable"),
|
|
108
|
+
this._pageProxySession.send("Emulation.setActiveAndFocused", { active: true })
|
|
109
|
+
];
|
|
109
110
|
const contextOptions = this._browserContext._options;
|
|
110
|
-
if (contextOptions.javaScriptEnabled === false)
|
|
111
|
-
enabled: false
|
|
112
|
-
}));
|
|
111
|
+
if (contextOptions.javaScriptEnabled === false)
|
|
112
|
+
promises.push(this._pageProxySession.send("Emulation.setJavaScriptEnabled", { enabled: false }));
|
|
113
113
|
promises.push(this._updateViewport());
|
|
114
114
|
promises.push(this.updateHttpCredentials());
|
|
115
115
|
if (this._browserContext._permissions.size) {
|
|
116
|
-
for (const [key, value] of this._browserContext._permissions)
|
|
116
|
+
for (const [key, value] of this._browserContext._permissions)
|
|
117
|
+
promises.push(this._grantPermissions(key, value));
|
|
117
118
|
}
|
|
118
119
|
if (this._browserContext._options.recordVideo) {
|
|
119
|
-
const outputFile =
|
|
120
|
+
const outputFile = import_path.default.join(this._browserContext._options.recordVideo.dir, (0, import_crypto.createGuid)() + ".webm");
|
|
120
121
|
promises.push(this._browserContext._ensureVideosPath().then(() => {
|
|
121
122
|
return this._startVideo({
|
|
122
123
|
// validateBrowserContextOptions ensures correct video size.
|
|
@@ -128,134 +129,100 @@ class WKPage {
|
|
|
128
129
|
await Promise.all(promises);
|
|
129
130
|
}
|
|
130
131
|
_setSession(session) {
|
|
131
|
-
|
|
132
|
+
import_eventsHelper.eventsHelper.removeEventListeners(this._sessionListeners);
|
|
132
133
|
this._session = session;
|
|
133
134
|
this.rawKeyboard.setSession(session);
|
|
134
135
|
this.rawMouse.setSession(session);
|
|
135
136
|
this._addSessionListeners();
|
|
136
137
|
this._workers.setSession(session);
|
|
137
138
|
}
|
|
138
|
-
|
|
139
139
|
// This method is called for provisional targets as well. The session passed as the parameter
|
|
140
140
|
// may be different from the current session and may be destroyed without becoming current.
|
|
141
141
|
async _initializeSession(session, provisional, resourceTreeHandler) {
|
|
142
|
-
await this._initializeSessionMayThrow(session, resourceTreeHandler).catch(e => {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if (
|
|
146
|
-
|
|
147
|
-
// since we will reinitialize again.
|
|
148
|
-
if (this._session === session) throw e;
|
|
142
|
+
await this._initializeSessionMayThrow(session, resourceTreeHandler).catch((e) => {
|
|
143
|
+
if (provisional && session.isDisposed())
|
|
144
|
+
return;
|
|
145
|
+
if (this._session === session)
|
|
146
|
+
throw e;
|
|
149
147
|
});
|
|
150
148
|
}
|
|
151
149
|
async _initializeSessionMayThrow(session, resourceTreeHandler) {
|
|
152
150
|
const [, frameTree] = await Promise.all([
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
// Page agent must be enabled before Runtime.
|
|
152
|
+
session.send("Page.enable"),
|
|
153
|
+
session.send("Page.getResourceTree")
|
|
154
|
+
]);
|
|
155
155
|
resourceTreeHandler(frameTree);
|
|
156
156
|
const promises = [
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
name:
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
157
|
+
// Resource tree should be received before first execution context.
|
|
158
|
+
session.send("Runtime.enable"),
|
|
159
|
+
session.send("Runtime.addBinding", { name: import_page.PageBinding.kPlaywrightBinding }),
|
|
160
|
+
session.send("Page.createUserWorld", { name: UTILITY_WORLD_NAME }).catch((_) => {
|
|
161
|
+
}),
|
|
162
|
+
// Worlds are per-process
|
|
163
|
+
session.send("Console.enable"),
|
|
164
|
+
session.send("Network.enable"),
|
|
165
|
+
this._workers.initializeSession(session)
|
|
166
|
+
];
|
|
165
167
|
if (this._page.needsRequestInterception()) {
|
|
166
|
-
promises.push(session.send(
|
|
167
|
-
|
|
168
|
-
}));
|
|
169
|
-
promises.push(session.send('Network.setResourceCachingDisabled', {
|
|
170
|
-
disabled: true
|
|
171
|
-
}));
|
|
172
|
-
promises.push(session.send('Network.addInterception', {
|
|
173
|
-
url: '.*',
|
|
174
|
-
stage: 'request',
|
|
175
|
-
isRegex: true
|
|
176
|
-
}));
|
|
168
|
+
promises.push(session.send("Network.setInterceptionEnabled", { enabled: true }));
|
|
169
|
+
promises.push(session.send("Network.setResourceCachingDisabled", { disabled: true }));
|
|
170
|
+
promises.push(session.send("Network.addInterception", { url: ".*", stage: "request", isRegex: true }));
|
|
177
171
|
}
|
|
178
172
|
if (this._page._browserContext.isSettingStorageState()) {
|
|
179
173
|
await Promise.all(promises);
|
|
180
174
|
return;
|
|
181
175
|
}
|
|
182
176
|
const contextOptions = this._browserContext._options;
|
|
183
|
-
if (contextOptions.userAgent)
|
|
177
|
+
if (contextOptions.userAgent)
|
|
178
|
+
promises.push(this.updateUserAgent());
|
|
184
179
|
const emulatedMedia = this._page.emulatedMedia();
|
|
185
|
-
if (emulatedMedia.media || emulatedMedia.colorScheme || emulatedMedia.reducedMotion || emulatedMedia.forcedColors || emulatedMedia.contrast)
|
|
180
|
+
if (emulatedMedia.media || emulatedMedia.colorScheme || emulatedMedia.reducedMotion || emulatedMedia.forcedColors || emulatedMedia.contrast)
|
|
181
|
+
promises.push(WKPage._setEmulateMedia(session, emulatedMedia.media, emulatedMedia.colorScheme, emulatedMedia.reducedMotion, emulatedMedia.forcedColors, emulatedMedia.contrast));
|
|
186
182
|
const bootstrapScript = this._calculateBootstrapScript();
|
|
187
|
-
if (bootstrapScript.length)
|
|
188
|
-
source: bootstrapScript
|
|
189
|
-
|
|
190
|
-
this._page.frames().map(frame => frame.evaluateExpression(bootstrapScript).catch(e => {}));
|
|
191
|
-
if (contextOptions.bypassCSP) promises.push(session.send('Page.setBypassCSP', {
|
|
192
|
-
enabled: true
|
|
183
|
+
if (bootstrapScript.length)
|
|
184
|
+
promises.push(session.send("Page.setBootstrapScript", { source: bootstrapScript }));
|
|
185
|
+
this._page.frames().map((frame) => frame.evaluateExpression(bootstrapScript).catch((e) => {
|
|
193
186
|
}));
|
|
187
|
+
if (contextOptions.bypassCSP)
|
|
188
|
+
promises.push(session.send("Page.setBypassCSP", { enabled: true }));
|
|
194
189
|
const emulatedSize = this._page.emulatedSize();
|
|
195
190
|
if (emulatedSize) {
|
|
196
|
-
promises.push(session.send(
|
|
191
|
+
promises.push(session.send("Page.setScreenSizeOverride", {
|
|
197
192
|
width: emulatedSize.screen.width,
|
|
198
193
|
height: emulatedSize.screen.height
|
|
199
194
|
}));
|
|
200
195
|
}
|
|
201
196
|
promises.push(this.updateEmulateMedia());
|
|
202
|
-
promises.push(session.send(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}));
|
|
197
|
+
promises.push(session.send("Network.setExtraHTTPHeaders", { headers: (0, import_headers.headersArrayToObject)(
|
|
198
|
+
this._calculateExtraHTTPHeaders(),
|
|
199
|
+
false
|
|
200
|
+
/* lowerCase */
|
|
201
|
+
) }));
|
|
202
|
+
if (contextOptions.offline)
|
|
203
|
+
promises.push(session.send("Network.setEmulateOfflineState", { offline: true }));
|
|
204
|
+
promises.push(session.send("Page.setTouchEmulationEnabled", { enabled: !!contextOptions.hasTouch }));
|
|
211
205
|
if (contextOptions.timezoneId) {
|
|
212
|
-
promises.push(session.send(
|
|
213
|
-
timeZone: contextOptions.timezoneId
|
|
214
|
-
}).catch(e => {
|
|
206
|
+
promises.push(session.send("Page.setTimeZone", { timeZone: contextOptions.timezoneId }).catch((e) => {
|
|
215
207
|
throw new Error(`Invalid timezone ID: ${contextOptions.timezoneId}`);
|
|
216
208
|
}));
|
|
217
209
|
}
|
|
218
|
-
if (this._page.fileChooserIntercepted())
|
|
219
|
-
enabled: true
|
|
220
|
-
}));
|
|
221
|
-
promises.push(session.send(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}));
|
|
225
|
-
promises.push(session.send(
|
|
226
|
-
|
|
227
|
-
value: !contextOptions.isMobile
|
|
228
|
-
}));
|
|
229
|
-
promises.push(session.send('Page.overrideSetting', {
|
|
230
|
-
setting: 'NotificationsEnabled',
|
|
231
|
-
value: !contextOptions.isMobile
|
|
232
|
-
}));
|
|
233
|
-
promises.push(session.send('Page.overrideSetting', {
|
|
234
|
-
setting: 'PointerLockEnabled',
|
|
235
|
-
value: !contextOptions.isMobile
|
|
236
|
-
}));
|
|
237
|
-
promises.push(session.send('Page.overrideSetting', {
|
|
238
|
-
setting: 'InputTypeMonthEnabled',
|
|
239
|
-
value: contextOptions.isMobile
|
|
240
|
-
}));
|
|
241
|
-
promises.push(session.send('Page.overrideSetting', {
|
|
242
|
-
setting: 'InputTypeWeekEnabled',
|
|
243
|
-
value: contextOptions.isMobile
|
|
244
|
-
}));
|
|
245
|
-
promises.push(session.send('Page.overrideSetting', {
|
|
246
|
-
setting: 'FixedBackgroundsPaintRelativeToDocument',
|
|
247
|
-
value: contextOptions.isMobile
|
|
248
|
-
}));
|
|
210
|
+
if (this._page.fileChooserIntercepted())
|
|
211
|
+
promises.push(session.send("Page.setInterceptFileChooserDialog", { enabled: true }));
|
|
212
|
+
promises.push(session.send("Page.overrideSetting", { setting: "DeviceOrientationEventEnabled", value: contextOptions.isMobile }));
|
|
213
|
+
promises.push(session.send("Page.overrideSetting", { setting: "FullScreenEnabled", value: !contextOptions.isMobile }));
|
|
214
|
+
promises.push(session.send("Page.overrideSetting", { setting: "NotificationsEnabled", value: !contextOptions.isMobile }));
|
|
215
|
+
promises.push(session.send("Page.overrideSetting", { setting: "PointerLockEnabled", value: !contextOptions.isMobile }));
|
|
216
|
+
promises.push(session.send("Page.overrideSetting", { setting: "InputTypeMonthEnabled", value: contextOptions.isMobile }));
|
|
217
|
+
promises.push(session.send("Page.overrideSetting", { setting: "InputTypeWeekEnabled", value: contextOptions.isMobile }));
|
|
218
|
+
promises.push(session.send("Page.overrideSetting", { setting: "FixedBackgroundsPaintRelativeToDocument", value: contextOptions.isMobile }));
|
|
249
219
|
await Promise.all(promises);
|
|
250
220
|
}
|
|
251
221
|
_onDidCommitProvisionalTarget(event) {
|
|
252
|
-
const {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
(0, _utils.assert)(this._provisionalPage);
|
|
257
|
-
(0, _utils.assert)(this._provisionalPage._session.sessionId === newTargetId, 'Unknown new target: ' + newTargetId);
|
|
258
|
-
(0, _utils.assert)(this._session.sessionId === oldTargetId, 'Unknown old target: ' + oldTargetId);
|
|
222
|
+
const { oldTargetId, newTargetId } = event;
|
|
223
|
+
(0, import_utils.assert)(this._provisionalPage);
|
|
224
|
+
(0, import_utils.assert)(this._provisionalPage._session.sessionId === newTargetId, "Unknown new target: " + newTargetId);
|
|
225
|
+
(0, import_utils.assert)(this._session.sessionId === oldTargetId, "Unknown old target: " + oldTargetId);
|
|
259
226
|
const newSession = this._provisionalPage._session;
|
|
260
227
|
this._provisionalPage.commit();
|
|
261
228
|
this._provisionalPage.dispose();
|
|
@@ -263,10 +230,7 @@ class WKPage {
|
|
|
263
230
|
this._setSession(newSession);
|
|
264
231
|
}
|
|
265
232
|
_onTargetDestroyed(event) {
|
|
266
|
-
const {
|
|
267
|
-
targetId,
|
|
268
|
-
crashed
|
|
269
|
-
} = event;
|
|
233
|
+
const { targetId, crashed } = event;
|
|
270
234
|
if (this._provisionalPage && this._provisionalPage._session.sessionId === targetId) {
|
|
271
235
|
this._maybeCancelCoopNavigationRequest(this._provisionalPage);
|
|
272
236
|
this._provisionalPage._session.dispose();
|
|
@@ -274,7 +238,7 @@ class WKPage {
|
|
|
274
238
|
this._provisionalPage = null;
|
|
275
239
|
} else if (this._session.sessionId === targetId) {
|
|
276
240
|
this._session.dispose();
|
|
277
|
-
|
|
241
|
+
import_eventsHelper.eventsHelper.removeEventListeners(this._sessionListeners);
|
|
278
242
|
if (crashed) {
|
|
279
243
|
this._session.markAsCrashed();
|
|
280
244
|
this._page._didCrash();
|
|
@@ -283,15 +247,16 @@ class WKPage {
|
|
|
283
247
|
}
|
|
284
248
|
didClose() {
|
|
285
249
|
this._pageProxySession.dispose();
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (this._session)
|
|
250
|
+
import_eventsHelper.eventsHelper.removeEventListeners(this._sessionListeners);
|
|
251
|
+
import_eventsHelper.eventsHelper.removeEventListeners(this._eventListeners);
|
|
252
|
+
if (this._session)
|
|
253
|
+
this._session.dispose();
|
|
289
254
|
if (this._provisionalPage) {
|
|
290
255
|
this._provisionalPage._session.dispose();
|
|
291
256
|
this._provisionalPage.dispose();
|
|
292
257
|
this._provisionalPage = null;
|
|
293
258
|
}
|
|
294
|
-
this._firstNonInitialNavigationCommittedReject(new
|
|
259
|
+
this._firstNonInitialNavigationCommittedReject(new import_errors.TargetClosedError());
|
|
295
260
|
this._page._didClose();
|
|
296
261
|
}
|
|
297
262
|
dispatchMessageToSession(message) {
|
|
@@ -299,139 +264,157 @@ class WKPage {
|
|
|
299
264
|
}
|
|
300
265
|
handleProvisionalLoadFailed(event) {
|
|
301
266
|
if (!this._page.initializedOrUndefined()) {
|
|
302
|
-
this._firstNonInitialNavigationCommittedReject(new Error(
|
|
267
|
+
this._firstNonInitialNavigationCommittedReject(new Error("Initial load failed"));
|
|
303
268
|
return;
|
|
304
269
|
}
|
|
305
|
-
if (!this._provisionalPage)
|
|
270
|
+
if (!this._provisionalPage)
|
|
271
|
+
return;
|
|
306
272
|
let errorText = event.error;
|
|
307
|
-
if (errorText.includes(
|
|
273
|
+
if (errorText.includes("cancelled"))
|
|
274
|
+
errorText += "; maybe frame was detached?";
|
|
308
275
|
this._page._frameManager.frameAbortedNavigation(this._page.mainFrame()._id, errorText, event.loaderId);
|
|
309
276
|
}
|
|
310
277
|
handleWindowOpen(event) {
|
|
311
278
|
this._nextWindowOpenPopupFeatures = event.windowFeatures;
|
|
312
279
|
}
|
|
313
280
|
async _onTargetCreated(event) {
|
|
314
|
-
const {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
const session = new _wkConnection.WKSession(this._pageProxySession.connection, targetInfo.targetId, message => {
|
|
318
|
-
this._pageProxySession.send('Target.sendMessageToTarget', {
|
|
281
|
+
const { targetInfo } = event;
|
|
282
|
+
const session = new import_wkConnection.WKSession(this._pageProxySession.connection, targetInfo.targetId, (message) => {
|
|
283
|
+
this._pageProxySession.send("Target.sendMessageToTarget", {
|
|
319
284
|
message: JSON.stringify(message),
|
|
320
285
|
targetId: targetInfo.targetId
|
|
321
|
-
}).catch(e => {
|
|
322
|
-
session.dispatchMessage({
|
|
323
|
-
id: message.id,
|
|
324
|
-
error: {
|
|
325
|
-
message: e.message
|
|
326
|
-
}
|
|
327
|
-
});
|
|
286
|
+
}).catch((e) => {
|
|
287
|
+
session.dispatchMessage({ id: message.id, error: { message: e.message } });
|
|
328
288
|
});
|
|
329
289
|
});
|
|
330
|
-
(0,
|
|
290
|
+
(0, import_utils.assert)(targetInfo.type === "page", "Only page targets are expected in WebKit, received: " + targetInfo.type);
|
|
331
291
|
if (!targetInfo.isProvisional) {
|
|
332
|
-
|
|
333
|
-
(0, _utils.assert)(!this._page.initializedOrUndefined());
|
|
292
|
+
(0, import_utils.assert)(!this._page.initializedOrUndefined());
|
|
334
293
|
let pageOrError;
|
|
335
294
|
try {
|
|
336
295
|
this._setSession(session);
|
|
337
|
-
await Promise.all([
|
|
338
|
-
|
|
339
|
-
|
|
296
|
+
await Promise.all([
|
|
297
|
+
this._initializePageProxySession(),
|
|
298
|
+
this._initializeSession(session, false, ({ frameTree }) => this._handleFrameTree(frameTree))
|
|
299
|
+
]);
|
|
340
300
|
pageOrError = this._page;
|
|
341
301
|
} catch (e) {
|
|
342
302
|
pageOrError = e;
|
|
343
303
|
}
|
|
344
|
-
if (targetInfo.isPaused)
|
|
345
|
-
targetId: targetInfo.targetId
|
|
346
|
-
|
|
347
|
-
if (pageOrError instanceof _page.Page && this._page.mainFrame().url() === '') {
|
|
304
|
+
if (targetInfo.isPaused)
|
|
305
|
+
this._pageProxySession.sendMayFail("Target.resume", { targetId: targetInfo.targetId });
|
|
306
|
+
if (pageOrError instanceof import_page2.Page && this._page.mainFrame().url() === "") {
|
|
348
307
|
try {
|
|
349
|
-
// Initial empty page has an empty url. We should wait until the first real url has been loaded,
|
|
350
|
-
// even if that url is about:blank. This is especially important for popups, where we need the
|
|
351
|
-
// actual url before interacting with it.
|
|
352
308
|
await this._firstNonInitialNavigationCommittedPromise;
|
|
353
309
|
} catch (e) {
|
|
354
310
|
pageOrError = e;
|
|
355
311
|
}
|
|
356
312
|
} else {
|
|
357
|
-
|
|
358
|
-
|
|
313
|
+
this._firstNonInitialNavigationCommittedPromise.catch(() => {
|
|
314
|
+
});
|
|
359
315
|
}
|
|
360
|
-
this._page.reportAsNew(
|
|
316
|
+
this._page.reportAsNew(this._opener?._page, pageOrError instanceof import_page2.Page ? void 0 : pageOrError);
|
|
361
317
|
} else {
|
|
362
|
-
(0,
|
|
363
|
-
(0,
|
|
364
|
-
this._provisionalPage = new
|
|
318
|
+
(0, import_utils.assert)(targetInfo.isProvisional);
|
|
319
|
+
(0, import_utils.assert)(!this._provisionalPage);
|
|
320
|
+
this._provisionalPage = new import_wkProvisionalPage.WKProvisionalPage(session, this);
|
|
365
321
|
if (targetInfo.isPaused) {
|
|
366
322
|
this._provisionalPage.initializationPromise.then(() => {
|
|
367
|
-
this._pageProxySession.sendMayFail(
|
|
368
|
-
targetId: targetInfo.targetId
|
|
369
|
-
});
|
|
323
|
+
this._pageProxySession.sendMayFail("Target.resume", { targetId: targetInfo.targetId });
|
|
370
324
|
});
|
|
371
325
|
}
|
|
372
326
|
}
|
|
373
327
|
}
|
|
374
328
|
_onDispatchMessageFromTarget(event) {
|
|
375
|
-
const {
|
|
376
|
-
|
|
377
|
-
message
|
|
378
|
-
|
|
379
|
-
|
|
329
|
+
const { targetId, message } = event;
|
|
330
|
+
if (this._provisionalPage && this._provisionalPage._session.sessionId === targetId)
|
|
331
|
+
this._provisionalPage._session.dispatchMessage(JSON.parse(message));
|
|
332
|
+
else if (this._session.sessionId === targetId)
|
|
333
|
+
this._session.dispatchMessage(JSON.parse(message));
|
|
334
|
+
else
|
|
335
|
+
throw new Error("Unknown target: " + targetId);
|
|
380
336
|
}
|
|
381
337
|
_addSessionListeners() {
|
|
382
|
-
this._sessionListeners = [
|
|
338
|
+
this._sessionListeners = [
|
|
339
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Page.frameNavigated", (event) => this._onFrameNavigated(event.frame, false)),
|
|
340
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Page.navigatedWithinDocument", (event) => this._onFrameNavigatedWithinDocument(event.frameId, event.url)),
|
|
341
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Page.frameAttached", (event) => this._onFrameAttached(event.frameId, event.parentFrameId)),
|
|
342
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Page.frameDetached", (event) => this._onFrameDetached(event.frameId)),
|
|
343
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Page.willCheckNavigationPolicy", (event) => this._onWillCheckNavigationPolicy(event.frameId)),
|
|
344
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Page.didCheckNavigationPolicy", (event) => this._onDidCheckNavigationPolicy(event.frameId, event.cancel)),
|
|
345
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Page.frameScheduledNavigation", (event) => this._onFrameScheduledNavigation(event.frameId, event.delay, event.targetIsCurrentFrame)),
|
|
346
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Page.loadEventFired", (event) => this._page._frameManager.frameLifecycleEvent(event.frameId, "load")),
|
|
347
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Page.domContentEventFired", (event) => this._page._frameManager.frameLifecycleEvent(event.frameId, "domcontentloaded")),
|
|
348
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Runtime.executionContextCreated", (event) => this._onExecutionContextCreated(event.context)),
|
|
349
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Runtime.bindingCalled", (event) => this._onBindingCalled(event.contextId, event.argument)),
|
|
350
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Console.messageAdded", (event) => this._onConsoleMessage(event)),
|
|
351
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Console.messageRepeatCountUpdated", (event) => this._onConsoleRepeatCountUpdated(event)),
|
|
352
|
+
import_eventsHelper.eventsHelper.addEventListener(this._pageProxySession, "Dialog.javascriptDialogOpening", (event) => this._onDialog(event)),
|
|
353
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Page.fileChooserOpened", (event) => this._onFileChooserOpened(event)),
|
|
354
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Network.requestWillBeSent", (e) => this._onRequestWillBeSent(this._session, e)),
|
|
355
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Network.requestIntercepted", (e) => this._onRequestIntercepted(this._session, e)),
|
|
356
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Network.responseReceived", (e) => this._onResponseReceived(this._session, e)),
|
|
357
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Network.loadingFinished", (e) => this._onLoadingFinished(e)),
|
|
358
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Network.loadingFailed", (e) => this._onLoadingFailed(this._session, e)),
|
|
359
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Network.webSocketCreated", (e) => this._page._frameManager.onWebSocketCreated(e.requestId, e.url)),
|
|
360
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Network.webSocketWillSendHandshakeRequest", (e) => this._page._frameManager.onWebSocketRequest(e.requestId)),
|
|
361
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Network.webSocketHandshakeResponseReceived", (e) => this._page._frameManager.onWebSocketResponse(e.requestId, e.response.status, e.response.statusText)),
|
|
362
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Network.webSocketFrameSent", (e) => e.response.payloadData && this._page._frameManager.onWebSocketFrameSent(e.requestId, e.response.opcode, e.response.payloadData)),
|
|
363
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Network.webSocketFrameReceived", (e) => e.response.payloadData && this._page._frameManager.webSocketFrameReceived(e.requestId, e.response.opcode, e.response.payloadData)),
|
|
364
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Network.webSocketClosed", (e) => this._page._frameManager.webSocketClosed(e.requestId)),
|
|
365
|
+
import_eventsHelper.eventsHelper.addEventListener(this._session, "Network.webSocketFrameError", (e) => this._page._frameManager.webSocketError(e.requestId, e.errorMessage))
|
|
366
|
+
];
|
|
383
367
|
}
|
|
384
368
|
async _updateState(method, params) {
|
|
385
|
-
await this._forAllSessions(session => session.send(method, params).then());
|
|
369
|
+
await this._forAllSessions((session) => session.send(method, params).then());
|
|
386
370
|
}
|
|
387
371
|
async _forAllSessions(callback) {
|
|
388
|
-
const sessions = [
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
if (this._provisionalPage)
|
|
392
|
-
|
|
372
|
+
const sessions = [
|
|
373
|
+
this._session
|
|
374
|
+
];
|
|
375
|
+
if (this._provisionalPage)
|
|
376
|
+
sessions.push(this._provisionalPage._session);
|
|
377
|
+
await Promise.all(sessions.map((session) => callback(session).catch((e) => {
|
|
378
|
+
})));
|
|
393
379
|
}
|
|
394
380
|
_onWillCheckNavigationPolicy(frameId) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
// either:
|
|
398
|
-
// - end up canceled, e.g. ctrl+click opening link in new tab, having no effect
|
|
399
|
-
// on this page
|
|
400
|
-
// - start new provisional load which we will miss in our signal trackers but
|
|
401
|
-
// we certainly won't hang waiting for it to finish and there is high chance
|
|
402
|
-
// that the current provisional page will commit navigation canceling the new
|
|
403
|
-
// one.
|
|
404
|
-
if (this._provisionalPage) return;
|
|
381
|
+
if (this._provisionalPage)
|
|
382
|
+
return;
|
|
405
383
|
this._page._frameManager.frameRequestedNavigation(frameId);
|
|
406
384
|
}
|
|
407
385
|
_onDidCheckNavigationPolicy(frameId, cancel) {
|
|
408
|
-
if (!cancel)
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
this._page._frameManager.frameAbortedNavigation(frameId,
|
|
386
|
+
if (!cancel)
|
|
387
|
+
return;
|
|
388
|
+
if (this._provisionalPage)
|
|
389
|
+
return;
|
|
390
|
+
this._page._frameManager.frameAbortedNavigation(frameId, "Navigation canceled by policy check");
|
|
413
391
|
}
|
|
414
392
|
_onFrameScheduledNavigation(frameId, delay, targetIsCurrentFrame) {
|
|
415
|
-
if (targetIsCurrentFrame)
|
|
393
|
+
if (targetIsCurrentFrame)
|
|
394
|
+
this._page._frameManager.frameRequestedNavigation(frameId);
|
|
416
395
|
}
|
|
417
396
|
_handleFrameTree(frameTree) {
|
|
418
397
|
this._onFrameAttached(frameTree.frame.id, frameTree.frame.parentId || null);
|
|
419
398
|
this._onFrameNavigated(frameTree.frame, true);
|
|
420
|
-
this._page._frameManager.frameLifecycleEvent(frameTree.frame.id,
|
|
421
|
-
this._page._frameManager.frameLifecycleEvent(frameTree.frame.id,
|
|
422
|
-
if (!frameTree.childFrames)
|
|
423
|
-
|
|
399
|
+
this._page._frameManager.frameLifecycleEvent(frameTree.frame.id, "domcontentloaded");
|
|
400
|
+
this._page._frameManager.frameLifecycleEvent(frameTree.frame.id, "load");
|
|
401
|
+
if (!frameTree.childFrames)
|
|
402
|
+
return;
|
|
403
|
+
for (const child of frameTree.childFrames)
|
|
404
|
+
this._handleFrameTree(child);
|
|
424
405
|
}
|
|
425
406
|
_onFrameAttached(frameId, parentFrameId) {
|
|
426
407
|
return this._page._frameManager.frameAttached(frameId, parentFrameId);
|
|
427
408
|
}
|
|
428
409
|
_onFrameNavigated(framePayload, initial) {
|
|
429
410
|
const frame = this._page._frameManager.frame(framePayload.id);
|
|
430
|
-
(0,
|
|
411
|
+
(0, import_utils.assert)(frame);
|
|
431
412
|
this._removeContextsForFrame(frame, true);
|
|
432
|
-
if (!framePayload.parentId)
|
|
433
|
-
|
|
434
|
-
|
|
413
|
+
if (!framePayload.parentId)
|
|
414
|
+
this._workers.clear();
|
|
415
|
+
this._page._frameManager.frameCommittedNewDocumentNavigation(framePayload.id, framePayload.url, framePayload.name || "", framePayload.loaderId, initial);
|
|
416
|
+
if (!initial)
|
|
417
|
+
this._firstNonInitialNavigationCommittedFulfill();
|
|
435
418
|
}
|
|
436
419
|
_onFrameNavigatedWithinDocument(frameId, url) {
|
|
437
420
|
this._page._frameManager.frameCommittedSameDocumentNavigation(frameId, url);
|
|
@@ -443,76 +426,67 @@ class WKPage {
|
|
|
443
426
|
for (const [contextId, context] of this._contextIdToContext) {
|
|
444
427
|
if (context.frame === frame) {
|
|
445
428
|
this._contextIdToContext.delete(contextId);
|
|
446
|
-
if (notifyFrame)
|
|
429
|
+
if (notifyFrame)
|
|
430
|
+
frame._contextDestroyed(context);
|
|
447
431
|
}
|
|
448
432
|
}
|
|
449
433
|
}
|
|
450
434
|
_onExecutionContextCreated(contextPayload) {
|
|
451
|
-
if (this._contextIdToContext.has(contextPayload.id))
|
|
435
|
+
if (this._contextIdToContext.has(contextPayload.id))
|
|
436
|
+
return;
|
|
452
437
|
const frame = this._page._frameManager.frame(contextPayload.frameId);
|
|
453
|
-
if (!frame)
|
|
454
|
-
|
|
438
|
+
if (!frame)
|
|
439
|
+
return;
|
|
440
|
+
const delegate = new import_wkExecutionContext.WKExecutionContext(this._session, contextPayload.id);
|
|
455
441
|
let worldName = null;
|
|
456
|
-
if (contextPayload.type ===
|
|
442
|
+
if (contextPayload.type === "normal")
|
|
443
|
+
worldName = "main";
|
|
444
|
+
else if (contextPayload.type === "user" && contextPayload.name === UTILITY_WORLD_NAME)
|
|
445
|
+
worldName = "utility";
|
|
457
446
|
const context = new dom.FrameExecutionContext(delegate, frame, worldName);
|
|
458
|
-
if (worldName)
|
|
447
|
+
if (worldName)
|
|
448
|
+
frame._contextCreated(worldName, context);
|
|
459
449
|
this._contextIdToContext.set(contextPayload.id, context);
|
|
460
450
|
}
|
|
461
451
|
async _onBindingCalled(contextId, argument) {
|
|
462
452
|
const pageOrError = await this._page.waitForInitializedOrError();
|
|
463
453
|
if (!(pageOrError instanceof Error)) {
|
|
464
454
|
const context = this._contextIdToContext.get(contextId);
|
|
465
|
-
if (context)
|
|
455
|
+
if (context)
|
|
456
|
+
await this._page._onBindingCalled(argument, context);
|
|
466
457
|
}
|
|
467
458
|
}
|
|
468
459
|
async navigateFrame(frame, url, referrer) {
|
|
469
|
-
if (this._pageProxySession.isDisposed())
|
|
460
|
+
if (this._pageProxySession.isDisposed())
|
|
461
|
+
throw new import_errors.TargetClosedError();
|
|
470
462
|
const pageProxyId = this._pageProxySession.sessionId;
|
|
471
|
-
const result = await this._pageProxySession.connection.browserSession.send(
|
|
472
|
-
|
|
473
|
-
pageProxyId,
|
|
474
|
-
frameId: frame._id,
|
|
475
|
-
referrer
|
|
476
|
-
});
|
|
477
|
-
return {
|
|
478
|
-
newDocumentId: result.loaderId
|
|
479
|
-
};
|
|
463
|
+
const result = await this._pageProxySession.connection.browserSession.send("Playwright.navigate", { url, pageProxyId, frameId: frame._id, referrer });
|
|
464
|
+
return { newDocumentId: result.loaderId };
|
|
480
465
|
}
|
|
481
466
|
_onConsoleMessage(event) {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
type,
|
|
486
|
-
level,
|
|
487
|
-
text,
|
|
488
|
-
parameters,
|
|
489
|
-
url,
|
|
490
|
-
line: lineNumber,
|
|
491
|
-
column: columnNumber,
|
|
492
|
-
source
|
|
493
|
-
} = event.message;
|
|
494
|
-
if (level === 'error' && source === 'javascript') {
|
|
495
|
-
const {
|
|
496
|
-
name,
|
|
497
|
-
message
|
|
498
|
-
} = (0, _stackTrace.splitErrorMessage)(text);
|
|
467
|
+
const { type, level, text, parameters, url, line: lineNumber, column: columnNumber, source } = event.message;
|
|
468
|
+
if (level === "error" && source === "javascript") {
|
|
469
|
+
const { name, message } = (0, import_stackTrace.splitErrorMessage)(text);
|
|
499
470
|
let stack;
|
|
500
471
|
if (event.message.stackTrace) {
|
|
501
|
-
stack = text +
|
|
502
|
-
return ` at ${callFrame.functionName ||
|
|
503
|
-
}).join(
|
|
472
|
+
stack = text + "\n" + event.message.stackTrace.callFrames.map((callFrame) => {
|
|
473
|
+
return ` at ${callFrame.functionName || "unknown"} (${callFrame.url}:${callFrame.lineNumber}:${callFrame.columnNumber})`;
|
|
474
|
+
}).join("\n");
|
|
504
475
|
} else {
|
|
505
|
-
stack =
|
|
476
|
+
stack = "";
|
|
506
477
|
}
|
|
507
478
|
this._lastConsoleMessage = null;
|
|
508
479
|
const error = new Error(message);
|
|
509
480
|
error.stack = stack;
|
|
510
481
|
error.name = name;
|
|
511
|
-
this._page.emitOnContextOnceInitialized(
|
|
482
|
+
this._page.emitOnContextOnceInitialized(import_browserContext.BrowserContext.Events.PageError, error, this._page);
|
|
512
483
|
return;
|
|
513
484
|
}
|
|
514
|
-
let derivedType = type ||
|
|
515
|
-
if (type ===
|
|
485
|
+
let derivedType = type || "";
|
|
486
|
+
if (type === "log")
|
|
487
|
+
derivedType = level;
|
|
488
|
+
else if (type === "timing")
|
|
489
|
+
derivedType = "timeEnd";
|
|
516
490
|
const handles = [];
|
|
517
491
|
for (const p of parameters || []) {
|
|
518
492
|
let context;
|
|
@@ -520,11 +494,11 @@ class WKPage {
|
|
|
520
494
|
const objectId = JSON.parse(p.objectId);
|
|
521
495
|
context = this._contextIdToContext.get(objectId.injectedScriptId);
|
|
522
496
|
} else {
|
|
523
|
-
|
|
524
|
-
context = [...this._contextIdToContext.values()].find(c => c.frame === this._page.mainFrame());
|
|
497
|
+
context = [...this._contextIdToContext.values()].find((c) => c.frame === this._page.mainFrame());
|
|
525
498
|
}
|
|
526
|
-
if (!context)
|
|
527
|
-
|
|
499
|
+
if (!context)
|
|
500
|
+
return;
|
|
501
|
+
handles.push((0, import_wkExecutionContext.createHandle)(context, p));
|
|
528
502
|
}
|
|
529
503
|
this._lastConsoleMessage = {
|
|
530
504
|
derivedType,
|
|
@@ -532,14 +506,12 @@ class WKPage {
|
|
|
532
506
|
handles,
|
|
533
507
|
count: 0,
|
|
534
508
|
location: {
|
|
535
|
-
url: url ||
|
|
509
|
+
url: url || "",
|
|
536
510
|
lineNumber: (lineNumber || 1) - 1,
|
|
537
511
|
columnNumber: (columnNumber || 1) - 1
|
|
538
512
|
}
|
|
539
513
|
};
|
|
540
|
-
this._onConsoleRepeatCountUpdated({
|
|
541
|
-
count: 1
|
|
542
|
-
});
|
|
514
|
+
this._onConsoleRepeatCountUpdated({ count: 1 });
|
|
543
515
|
}
|
|
544
516
|
_onConsoleRepeatCountUpdated(event) {
|
|
545
517
|
if (this._lastConsoleMessage) {
|
|
@@ -550,109 +522,105 @@ class WKPage {
|
|
|
550
522
|
count,
|
|
551
523
|
location
|
|
552
524
|
} = this._lastConsoleMessage;
|
|
553
|
-
for (let i = count; i < event.count; ++i)
|
|
525
|
+
for (let i = count; i < event.count; ++i)
|
|
526
|
+
this._page._addConsoleMessage(derivedType, handles, location, handles.length ? void 0 : text);
|
|
554
527
|
this._lastConsoleMessage.count = event.count;
|
|
555
528
|
}
|
|
556
529
|
}
|
|
557
530
|
_onDialog(event) {
|
|
558
|
-
this._page.emitOnContext(
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
531
|
+
this._page.emitOnContext(import_browserContext.BrowserContext.Events.Dialog, new dialog.Dialog(
|
|
532
|
+
this._page,
|
|
533
|
+
event.type,
|
|
534
|
+
event.message,
|
|
535
|
+
async (accept, promptText) => {
|
|
536
|
+
if (event.type === "beforeunload" && !accept)
|
|
537
|
+
this._page._frameManager.frameAbortedNavigation(this._page.mainFrame()._id, "navigation cancelled by beforeunload dialog");
|
|
538
|
+
await this._pageProxySession.send("Dialog.handleJavaScriptDialog", { accept, promptText });
|
|
539
|
+
},
|
|
540
|
+
event.defaultPrompt
|
|
541
|
+
));
|
|
566
542
|
}
|
|
567
543
|
async _onFileChooserOpened(event) {
|
|
568
544
|
let handle;
|
|
569
545
|
try {
|
|
570
546
|
const context = await this._page._frameManager.frame(event.frameId)._mainContext();
|
|
571
|
-
handle = (0,
|
|
547
|
+
handle = (0, import_wkExecutionContext.createHandle)(context, event.element).asElement();
|
|
572
548
|
} catch (e) {
|
|
573
|
-
// During async processing, frame/context may go away. We should not throw.
|
|
574
549
|
return;
|
|
575
550
|
}
|
|
576
551
|
await this._page._onFileChooserOpened(handle);
|
|
577
552
|
}
|
|
578
553
|
static async _setEmulateMedia(session, mediaType, colorScheme, reducedMotion, forcedColors, contrast) {
|
|
579
554
|
const promises = [];
|
|
580
|
-
promises.push(session.send(
|
|
581
|
-
|
|
582
|
-
}));
|
|
583
|
-
let appearance = undefined;
|
|
555
|
+
promises.push(session.send("Page.setEmulatedMedia", { media: mediaType === "no-override" ? "" : mediaType }));
|
|
556
|
+
let appearance = void 0;
|
|
584
557
|
switch (colorScheme) {
|
|
585
|
-
case
|
|
586
|
-
appearance =
|
|
558
|
+
case "light":
|
|
559
|
+
appearance = "Light";
|
|
587
560
|
break;
|
|
588
|
-
case
|
|
589
|
-
appearance =
|
|
561
|
+
case "dark":
|
|
562
|
+
appearance = "Dark";
|
|
590
563
|
break;
|
|
591
|
-
case
|
|
592
|
-
appearance =
|
|
564
|
+
case "no-override":
|
|
565
|
+
appearance = void 0;
|
|
593
566
|
break;
|
|
594
567
|
}
|
|
595
|
-
promises.push(session.send(
|
|
596
|
-
|
|
597
|
-
value: appearance
|
|
598
|
-
}));
|
|
599
|
-
let reducedMotionWk = undefined;
|
|
568
|
+
promises.push(session.send("Page.overrideUserPreference", { name: "PrefersColorScheme", value: appearance }));
|
|
569
|
+
let reducedMotionWk = void 0;
|
|
600
570
|
switch (reducedMotion) {
|
|
601
|
-
case
|
|
602
|
-
reducedMotionWk =
|
|
571
|
+
case "reduce":
|
|
572
|
+
reducedMotionWk = "Reduce";
|
|
603
573
|
break;
|
|
604
|
-
case
|
|
605
|
-
reducedMotionWk =
|
|
574
|
+
case "no-preference":
|
|
575
|
+
reducedMotionWk = "NoPreference";
|
|
606
576
|
break;
|
|
607
|
-
case
|
|
608
|
-
reducedMotionWk =
|
|
577
|
+
case "no-override":
|
|
578
|
+
reducedMotionWk = void 0;
|
|
609
579
|
break;
|
|
610
580
|
}
|
|
611
|
-
promises.push(session.send(
|
|
612
|
-
|
|
613
|
-
value: reducedMotionWk
|
|
614
|
-
}));
|
|
615
|
-
let forcedColorsWk = undefined;
|
|
581
|
+
promises.push(session.send("Page.overrideUserPreference", { name: "PrefersReducedMotion", value: reducedMotionWk }));
|
|
582
|
+
let forcedColorsWk = void 0;
|
|
616
583
|
switch (forcedColors) {
|
|
617
|
-
case
|
|
618
|
-
forcedColorsWk =
|
|
584
|
+
case "active":
|
|
585
|
+
forcedColorsWk = "Active";
|
|
619
586
|
break;
|
|
620
|
-
case
|
|
621
|
-
forcedColorsWk =
|
|
587
|
+
case "none":
|
|
588
|
+
forcedColorsWk = "None";
|
|
622
589
|
break;
|
|
623
|
-
case
|
|
624
|
-
forcedColorsWk =
|
|
590
|
+
case "no-override":
|
|
591
|
+
forcedColorsWk = void 0;
|
|
625
592
|
break;
|
|
626
593
|
}
|
|
627
|
-
promises.push(session.send(
|
|
628
|
-
|
|
629
|
-
}));
|
|
630
|
-
let contrastWk = undefined;
|
|
594
|
+
promises.push(session.send("Page.setForcedColors", { forcedColors: forcedColorsWk }));
|
|
595
|
+
let contrastWk = void 0;
|
|
631
596
|
switch (contrast) {
|
|
632
|
-
case
|
|
633
|
-
contrastWk =
|
|
597
|
+
case "more":
|
|
598
|
+
contrastWk = "More";
|
|
634
599
|
break;
|
|
635
|
-
case
|
|
636
|
-
contrastWk =
|
|
600
|
+
case "no-preference":
|
|
601
|
+
contrastWk = "NoPreference";
|
|
637
602
|
break;
|
|
638
|
-
case
|
|
639
|
-
contrastWk =
|
|
603
|
+
case "no-override":
|
|
604
|
+
contrastWk = void 0;
|
|
640
605
|
break;
|
|
641
606
|
}
|
|
642
|
-
promises.push(session.send(
|
|
643
|
-
name: 'PrefersContrast',
|
|
644
|
-
value: contrastWk
|
|
645
|
-
}));
|
|
607
|
+
promises.push(session.send("Page.overrideUserPreference", { name: "PrefersContrast", value: contrastWk }));
|
|
646
608
|
await Promise.all(promises);
|
|
647
609
|
}
|
|
648
610
|
async updateExtraHTTPHeaders() {
|
|
649
|
-
await this._updateState(
|
|
650
|
-
|
|
651
|
-
|
|
611
|
+
await this._updateState("Network.setExtraHTTPHeaders", { headers: (0, import_headers.headersArrayToObject)(
|
|
612
|
+
this._calculateExtraHTTPHeaders(),
|
|
613
|
+
false
|
|
614
|
+
/* lowerCase */
|
|
615
|
+
) });
|
|
652
616
|
}
|
|
653
617
|
_calculateExtraHTTPHeaders() {
|
|
654
618
|
const locale = this._browserContext._options.locale;
|
|
655
|
-
const headers = network.mergeHeaders([
|
|
619
|
+
const headers = network.mergeHeaders([
|
|
620
|
+
this._browserContext._options.extraHTTPHeaders,
|
|
621
|
+
this._page.extraHTTPHeaders(),
|
|
622
|
+
locale ? network.singleHeader("Accept-Language", locale) : void 0
|
|
623
|
+
]);
|
|
656
624
|
return headers;
|
|
657
625
|
}
|
|
658
626
|
async updateEmulateMedia() {
|
|
@@ -661,7 +629,7 @@ class WKPage {
|
|
|
661
629
|
const reducedMotion = emulatedMedia.reducedMotion;
|
|
662
630
|
const forcedColors = emulatedMedia.forcedColors;
|
|
663
631
|
const contrast = emulatedMedia.contrast;
|
|
664
|
-
await this._forAllSessions(session => WKPage._setEmulateMedia(session, emulatedMedia.media, colorScheme, reducedMotion, forcedColors, contrast));
|
|
632
|
+
await this._forAllSessions((session) => WKPage._setEmulateMedia(session, emulatedMedia.media, colorScheme, reducedMotion, forcedColors, contrast));
|
|
665
633
|
}
|
|
666
634
|
async updateEmulatedViewportSize() {
|
|
667
635
|
this._browserContext._validateEmulatedViewport(this._page.viewportSize());
|
|
@@ -669,90 +637,77 @@ class WKPage {
|
|
|
669
637
|
}
|
|
670
638
|
async updateUserAgent() {
|
|
671
639
|
const contextOptions = this._browserContext._options;
|
|
672
|
-
this._updateState(
|
|
673
|
-
value: contextOptions.userAgent
|
|
674
|
-
});
|
|
640
|
+
this._updateState("Page.overrideUserAgent", { value: contextOptions.userAgent });
|
|
675
641
|
}
|
|
676
642
|
async bringToFront() {
|
|
677
|
-
this._pageProxySession.send(
|
|
643
|
+
this._pageProxySession.send("Target.activate", {
|
|
678
644
|
targetId: this._session.sessionId
|
|
679
645
|
});
|
|
680
646
|
}
|
|
681
647
|
async _updateViewport() {
|
|
682
648
|
const options = this._browserContext._options;
|
|
683
649
|
const deviceSize = this._page.emulatedSize();
|
|
684
|
-
if (deviceSize === null)
|
|
650
|
+
if (deviceSize === null)
|
|
651
|
+
return;
|
|
685
652
|
const viewportSize = deviceSize.viewport;
|
|
686
653
|
const screenSize = deviceSize.screen;
|
|
687
|
-
const promises = [
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
654
|
+
const promises = [
|
|
655
|
+
this._pageProxySession.send("Emulation.setDeviceMetricsOverride", {
|
|
656
|
+
width: viewportSize.width,
|
|
657
|
+
height: viewportSize.height,
|
|
658
|
+
fixedLayout: !!options.isMobile,
|
|
659
|
+
deviceScaleFactor: options.deviceScaleFactor || 1
|
|
660
|
+
}),
|
|
661
|
+
this._session.send("Page.setScreenSizeOverride", {
|
|
662
|
+
width: screenSize.width,
|
|
663
|
+
height: screenSize.height
|
|
664
|
+
})
|
|
665
|
+
];
|
|
696
666
|
if (options.isMobile) {
|
|
697
667
|
const angle = viewportSize.width > viewportSize.height ? 90 : 0;
|
|
698
|
-
promises.push(this._pageProxySession.send(
|
|
699
|
-
angle
|
|
700
|
-
}));
|
|
668
|
+
promises.push(this._pageProxySession.send("Emulation.setOrientationOverride", { angle }));
|
|
701
669
|
}
|
|
702
670
|
await Promise.all(promises);
|
|
703
671
|
}
|
|
704
672
|
async updateRequestInterception() {
|
|
705
673
|
const enabled = this._page.needsRequestInterception();
|
|
706
|
-
await Promise.all([
|
|
707
|
-
enabled
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
url: '.*',
|
|
712
|
-
stage: 'request',
|
|
713
|
-
isRegex: true
|
|
714
|
-
})]);
|
|
674
|
+
await Promise.all([
|
|
675
|
+
this._updateState("Network.setInterceptionEnabled", { enabled }),
|
|
676
|
+
this._updateState("Network.setResourceCachingDisabled", { disabled: enabled }),
|
|
677
|
+
this._updateState("Network.addInterception", { url: ".*", stage: "request", isRegex: true })
|
|
678
|
+
]);
|
|
715
679
|
}
|
|
716
680
|
async updateOffline() {
|
|
717
|
-
await this._updateState(
|
|
718
|
-
offline: !!this._browserContext._options.offline
|
|
719
|
-
});
|
|
681
|
+
await this._updateState("Network.setEmulateOfflineState", { offline: !!this._browserContext._options.offline });
|
|
720
682
|
}
|
|
721
683
|
async updateHttpCredentials() {
|
|
722
|
-
const credentials = this._browserContext._options.httpCredentials || {
|
|
723
|
-
|
|
724
|
-
password: '',
|
|
725
|
-
origin: ''
|
|
726
|
-
};
|
|
727
|
-
await this._pageProxySession.send('Emulation.setAuthCredentials', {
|
|
728
|
-
username: credentials.username,
|
|
729
|
-
password: credentials.password,
|
|
730
|
-
origin: credentials.origin
|
|
731
|
-
});
|
|
684
|
+
const credentials = this._browserContext._options.httpCredentials || { username: "", password: "", origin: "" };
|
|
685
|
+
await this._pageProxySession.send("Emulation.setAuthCredentials", { username: credentials.username, password: credentials.password, origin: credentials.origin });
|
|
732
686
|
}
|
|
733
687
|
async updateFileChooserInterception() {
|
|
734
688
|
const enabled = this._page.fileChooserIntercepted();
|
|
735
|
-
await this._session.send(
|
|
736
|
-
|
|
737
|
-
}).catch(() => {}); // target can be closed.
|
|
689
|
+
await this._session.send("Page.setInterceptFileChooserDialog", { enabled }).catch(() => {
|
|
690
|
+
});
|
|
738
691
|
}
|
|
739
692
|
async reload() {
|
|
740
|
-
await this._session.send(
|
|
693
|
+
await this._session.send("Page.reload");
|
|
741
694
|
}
|
|
742
695
|
goBack() {
|
|
743
|
-
return this._session.send(
|
|
744
|
-
if (error instanceof Error && error.message.includes(`Protocol error (Page.goBack): Failed to go`))
|
|
696
|
+
return this._session.send("Page.goBack").then(() => true).catch((error) => {
|
|
697
|
+
if (error instanceof Error && error.message.includes(`Protocol error (Page.goBack): Failed to go`))
|
|
698
|
+
return false;
|
|
745
699
|
throw error;
|
|
746
700
|
});
|
|
747
701
|
}
|
|
748
702
|
goForward() {
|
|
749
|
-
return this._session.send(
|
|
750
|
-
if (error instanceof Error && error.message.includes(`Protocol error (Page.goForward): Failed to go`))
|
|
703
|
+
return this._session.send("Page.goForward").then(() => true).catch((error) => {
|
|
704
|
+
if (error instanceof Error && error.message.includes(`Protocol error (Page.goForward): Failed to go`))
|
|
705
|
+
return false;
|
|
751
706
|
throw error;
|
|
752
707
|
});
|
|
753
708
|
}
|
|
754
709
|
async requestGC() {
|
|
755
|
-
await this._session.send(
|
|
710
|
+
await this._session.send("Heap.gc");
|
|
756
711
|
}
|
|
757
712
|
async addInitScript(initScript) {
|
|
758
713
|
await this._updateBootstrapScript();
|
|
@@ -763,42 +718,36 @@ class WKPage {
|
|
|
763
718
|
_calculateBootstrapScript() {
|
|
764
719
|
const scripts = [];
|
|
765
720
|
if (!this._page.context()._options.isMobile) {
|
|
766
|
-
scripts.push(
|
|
767
|
-
scripts.push(
|
|
768
|
-
scripts.push(
|
|
721
|
+
scripts.push("delete window.orientation");
|
|
722
|
+
scripts.push("delete window.ondevicemotion");
|
|
723
|
+
scripts.push("delete window.ondeviceorientation");
|
|
769
724
|
}
|
|
770
725
|
scripts.push('if (!window.safari) window.safari = { pushNotification: { toString() { return "[object SafariRemoteNotification]"; } } };');
|
|
771
|
-
scripts.push(
|
|
772
|
-
scripts.push(...this._page.allInitScripts().map(script => script.source));
|
|
773
|
-
return scripts.join(
|
|
726
|
+
scripts.push("if (!window.GestureEvent) window.GestureEvent = function GestureEvent() {};");
|
|
727
|
+
scripts.push(...this._page.allInitScripts().map((script) => script.source));
|
|
728
|
+
return scripts.join(";\n");
|
|
774
729
|
}
|
|
775
730
|
async _updateBootstrapScript() {
|
|
776
|
-
await this._updateState(
|
|
777
|
-
source: this._calculateBootstrapScript()
|
|
778
|
-
});
|
|
731
|
+
await this._updateState("Page.setBootstrapScript", { source: this._calculateBootstrapScript() });
|
|
779
732
|
}
|
|
780
733
|
async closePage(runBeforeUnload) {
|
|
781
734
|
await this._stopVideo();
|
|
782
|
-
await this._pageProxySession.sendMayFail(
|
|
735
|
+
await this._pageProxySession.sendMayFail("Target.close", {
|
|
783
736
|
targetId: this._session.sessionId,
|
|
784
737
|
runBeforeUnload
|
|
785
738
|
});
|
|
786
739
|
}
|
|
787
740
|
async setBackgroundColor(color) {
|
|
788
|
-
await this._session.send(
|
|
789
|
-
color
|
|
790
|
-
});
|
|
741
|
+
await this._session.send("Page.setDefaultBackgroundColorOverride", { color });
|
|
791
742
|
}
|
|
792
743
|
_toolbarHeight() {
|
|
793
|
-
|
|
794
|
-
|
|
744
|
+
if (this._page._browserContext._browser?.options.headful)
|
|
745
|
+
return import_hostPlatform.hostPlatform === "mac10.15" ? 55 : 59;
|
|
795
746
|
return 0;
|
|
796
747
|
}
|
|
797
748
|
async _startVideo(options) {
|
|
798
|
-
(0,
|
|
799
|
-
const {
|
|
800
|
-
screencastId
|
|
801
|
-
} = await this._pageProxySession.send('Screencast.startVideo', {
|
|
749
|
+
(0, import_utils.assert)(!this._recordingVideoFile);
|
|
750
|
+
const { screencastId } = await this._pageProxySession.send("Screencast.startVideo", {
|
|
802
751
|
file: options.outputFile,
|
|
803
752
|
width: options.width,
|
|
804
753
|
height: options.height,
|
|
@@ -808,49 +757,51 @@ class WKPage {
|
|
|
808
757
|
this._browserContext._browser._videoStarted(this._browserContext, screencastId, options.outputFile, this._page.waitForInitializedOrError());
|
|
809
758
|
}
|
|
810
759
|
async _stopVideo() {
|
|
811
|
-
if (!this._recordingVideoFile)
|
|
812
|
-
|
|
760
|
+
if (!this._recordingVideoFile)
|
|
761
|
+
return;
|
|
762
|
+
await this._pageProxySession.sendMayFail("Screencast.stopVideo");
|
|
813
763
|
this._recordingVideoFile = null;
|
|
814
764
|
}
|
|
815
765
|
validateScreenshotDimension(side, omitDeviceScaleFactor) {
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
if (
|
|
819
|
-
|
|
820
|
-
if (side > 32767)
|
|
766
|
+
if (process.platform === "darwin")
|
|
767
|
+
return;
|
|
768
|
+
if (!omitDeviceScaleFactor && this._page._browserContext._options.deviceScaleFactor)
|
|
769
|
+
side = Math.ceil(side * this._page._browserContext._options.deviceScaleFactor);
|
|
770
|
+
if (side > 32767)
|
|
771
|
+
throw new Error("Cannot take screenshot larger than 32767 pixels on any dimension");
|
|
821
772
|
}
|
|
822
773
|
async takeScreenshot(progress, format, documentRect, viewportRect, quality, fitsViewport, scale) {
|
|
823
774
|
const rect = documentRect || viewportRect;
|
|
824
|
-
const omitDeviceScaleFactor = scale ===
|
|
775
|
+
const omitDeviceScaleFactor = scale === "css";
|
|
825
776
|
this.validateScreenshotDimension(rect.width, omitDeviceScaleFactor);
|
|
826
777
|
this.validateScreenshotDimension(rect.height, omitDeviceScaleFactor);
|
|
827
|
-
const result = await this._session.send(
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
const prefix = 'data:image/png;base64,';
|
|
833
|
-
let buffer = Buffer.from(result.dataURL.substr(prefix.length), 'base64');
|
|
834
|
-
if (format === 'jpeg') buffer = _utilsBundle.jpegjs.encode(_utilsBundle.PNG.sync.read(buffer), quality).data;
|
|
778
|
+
const result = await this._session.send("Page.snapshotRect", { ...rect, coordinateSystem: documentRect ? "Page" : "Viewport", omitDeviceScaleFactor });
|
|
779
|
+
const prefix = "data:image/png;base64,";
|
|
780
|
+
let buffer = Buffer.from(result.dataURL.substr(prefix.length), "base64");
|
|
781
|
+
if (format === "jpeg")
|
|
782
|
+
buffer = import_utilsBundle.jpegjs.encode(import_utilsBundle.PNG.sync.read(buffer), quality).data;
|
|
835
783
|
return buffer;
|
|
836
784
|
}
|
|
837
785
|
async getContentFrame(handle) {
|
|
838
|
-
const nodeInfo = await this._session.send(
|
|
786
|
+
const nodeInfo = await this._session.send("DOM.describeNode", {
|
|
839
787
|
objectId: handle._objectId
|
|
840
788
|
});
|
|
841
|
-
if (!nodeInfo.contentFrameId)
|
|
789
|
+
if (!nodeInfo.contentFrameId)
|
|
790
|
+
return null;
|
|
842
791
|
return this._page._frameManager.frame(nodeInfo.contentFrameId);
|
|
843
792
|
}
|
|
844
793
|
async getOwnerFrame(handle) {
|
|
845
|
-
if (!handle._objectId)
|
|
846
|
-
|
|
794
|
+
if (!handle._objectId)
|
|
795
|
+
return null;
|
|
796
|
+
const nodeInfo = await this._session.send("DOM.describeNode", {
|
|
847
797
|
objectId: handle._objectId
|
|
848
798
|
});
|
|
849
799
|
return nodeInfo.ownerFrameId || null;
|
|
850
800
|
}
|
|
851
801
|
async getBoundingBox(handle) {
|
|
852
802
|
const quads = await this.getContentQuads(handle);
|
|
853
|
-
if (!quads || !quads.length)
|
|
803
|
+
if (!quads || !quads.length)
|
|
804
|
+
return null;
|
|
854
805
|
let minX = Infinity;
|
|
855
806
|
let maxX = -Infinity;
|
|
856
807
|
let minY = Infinity;
|
|
@@ -863,116 +814,101 @@ class WKPage {
|
|
|
863
814
|
maxY = Math.max(maxY, point.y);
|
|
864
815
|
}
|
|
865
816
|
}
|
|
866
|
-
return {
|
|
867
|
-
x: minX,
|
|
868
|
-
y: minY,
|
|
869
|
-
width: maxX - minX,
|
|
870
|
-
height: maxY - minY
|
|
871
|
-
};
|
|
817
|
+
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
872
818
|
}
|
|
873
819
|
async scrollRectIntoViewIfNeeded(handle, rect) {
|
|
874
|
-
return await this._session.send(
|
|
820
|
+
return await this._session.send("DOM.scrollIntoViewIfNeeded", {
|
|
875
821
|
objectId: handle._objectId,
|
|
876
822
|
rect
|
|
877
|
-
}).then(() =>
|
|
878
|
-
if (e instanceof Error && e.message.includes(
|
|
879
|
-
|
|
823
|
+
}).then(() => "done").catch((e) => {
|
|
824
|
+
if (e instanceof Error && e.message.includes("Node does not have a layout object"))
|
|
825
|
+
return "error:notvisible";
|
|
826
|
+
if (e instanceof Error && e.message.includes("Node is detached from document"))
|
|
827
|
+
return "error:notconnected";
|
|
880
828
|
throw e;
|
|
881
829
|
});
|
|
882
830
|
}
|
|
883
831
|
async setScreencastOptions(options) {
|
|
884
832
|
if (options) {
|
|
885
|
-
const so = {
|
|
886
|
-
|
|
887
|
-
toolbarHeight: this._toolbarHeight()
|
|
888
|
-
};
|
|
889
|
-
const {
|
|
890
|
-
generation
|
|
891
|
-
} = await this._pageProxySession.send('Screencast.startScreencast', so);
|
|
833
|
+
const so = { ...options, toolbarHeight: this._toolbarHeight() };
|
|
834
|
+
const { generation } = await this._pageProxySession.send("Screencast.startScreencast", so);
|
|
892
835
|
this._screencastGeneration = generation;
|
|
893
836
|
} else {
|
|
894
|
-
await this._pageProxySession.send(
|
|
837
|
+
await this._pageProxySession.send("Screencast.stopScreencast");
|
|
895
838
|
}
|
|
896
839
|
}
|
|
897
840
|
_onScreencastFrame(event) {
|
|
898
841
|
const generation = this._screencastGeneration;
|
|
899
842
|
this._page.throttleScreencastFrameAck(() => {
|
|
900
|
-
this._pageProxySession.send(
|
|
901
|
-
generation
|
|
902
|
-
}).catch(e => _debugLogger.debugLogger.log('error', e));
|
|
843
|
+
this._pageProxySession.send("Screencast.screencastFrameAck", { generation }).catch((e) => import_debugLogger.debugLogger.log("error", e));
|
|
903
844
|
});
|
|
904
|
-
const buffer = Buffer.from(event.data,
|
|
905
|
-
this._page.emit(
|
|
845
|
+
const buffer = Buffer.from(event.data, "base64");
|
|
846
|
+
this._page.emit(import_page2.Page.Events.ScreencastFrame, {
|
|
906
847
|
buffer,
|
|
907
848
|
width: event.deviceWidth,
|
|
908
849
|
height: event.deviceHeight
|
|
909
850
|
});
|
|
910
851
|
}
|
|
911
852
|
rafCountForStablePosition() {
|
|
912
|
-
return process.platform ===
|
|
853
|
+
return process.platform === "win32" ? 5 : 1;
|
|
913
854
|
}
|
|
914
855
|
async getContentQuads(handle) {
|
|
915
|
-
const result = await this._session.sendMayFail(
|
|
856
|
+
const result = await this._session.sendMayFail("DOM.getContentQuads", {
|
|
916
857
|
objectId: handle._objectId
|
|
917
858
|
});
|
|
918
|
-
if (!result)
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
y: quad[1]
|
|
922
|
-
|
|
923
|
-
x: quad[
|
|
924
|
-
y: quad[
|
|
925
|
-
|
|
926
|
-
x: quad[4],
|
|
927
|
-
y: quad[5]
|
|
928
|
-
}, {
|
|
929
|
-
x: quad[6],
|
|
930
|
-
y: quad[7]
|
|
931
|
-
}]);
|
|
859
|
+
if (!result)
|
|
860
|
+
return null;
|
|
861
|
+
return result.quads.map((quad) => [
|
|
862
|
+
{ x: quad[0], y: quad[1] },
|
|
863
|
+
{ x: quad[2], y: quad[3] },
|
|
864
|
+
{ x: quad[4], y: quad[5] },
|
|
865
|
+
{ x: quad[6], y: quad[7] }
|
|
866
|
+
]);
|
|
932
867
|
}
|
|
933
868
|
async setInputFilePaths(handle, paths) {
|
|
934
869
|
const pageProxyId = this._pageProxySession.sessionId;
|
|
935
870
|
const objectId = handle._objectId;
|
|
936
|
-
await Promise.all([
|
|
937
|
-
pageProxyId,
|
|
938
|
-
paths
|
|
939
|
-
|
|
940
|
-
objectId,
|
|
941
|
-
paths
|
|
942
|
-
})]);
|
|
871
|
+
await Promise.all([
|
|
872
|
+
this._pageProxySession.connection.browserSession.send("Playwright.grantFileReadAccess", { pageProxyId, paths }),
|
|
873
|
+
this._session.send("DOM.setInputFiles", { objectId, paths })
|
|
874
|
+
]);
|
|
943
875
|
}
|
|
944
876
|
async adoptElementHandle(handle, to) {
|
|
945
|
-
const result = await this._session.sendMayFail(
|
|
877
|
+
const result = await this._session.sendMayFail("DOM.resolveNode", {
|
|
946
878
|
objectId: handle._objectId,
|
|
947
879
|
executionContextId: to.delegate._contextId
|
|
948
880
|
});
|
|
949
|
-
if (!result || result.object.subtype ===
|
|
950
|
-
|
|
881
|
+
if (!result || result.object.subtype === "null")
|
|
882
|
+
throw new Error(dom.kUnableToAdoptErrorMessage);
|
|
883
|
+
return (0, import_wkExecutionContext.createHandle)(to, result.object);
|
|
951
884
|
}
|
|
952
885
|
async getAccessibilityTree(needle) {
|
|
953
|
-
return (0,
|
|
886
|
+
return (0, import_wkAccessibility.getAccessibilityTree)(this._session, needle);
|
|
887
|
+
}
|
|
888
|
+
async inputActionEpilogue() {
|
|
889
|
+
}
|
|
890
|
+
async resetForReuse() {
|
|
954
891
|
}
|
|
955
|
-
async inputActionEpilogue() {}
|
|
956
|
-
async resetForReuse() {}
|
|
957
892
|
async getFrameElement(frame) {
|
|
958
893
|
const parent = frame.parentFrame();
|
|
959
|
-
if (!parent)
|
|
894
|
+
if (!parent)
|
|
895
|
+
throw new Error("Frame has been detached.");
|
|
960
896
|
const context = await parent._mainContext();
|
|
961
|
-
const result = await this._session.send(
|
|
897
|
+
const result = await this._session.send("DOM.resolveNode", {
|
|
962
898
|
frameId: frame._id,
|
|
963
899
|
executionContextId: context.delegate._contextId
|
|
964
900
|
});
|
|
965
|
-
if (!result || result.object.subtype ===
|
|
966
|
-
|
|
901
|
+
if (!result || result.object.subtype === "null")
|
|
902
|
+
throw new Error("Frame has been detached.");
|
|
903
|
+
return (0, import_wkExecutionContext.createHandle)(context, result.object);
|
|
967
904
|
}
|
|
968
905
|
_maybeCancelCoopNavigationRequest(provisionalPage) {
|
|
969
906
|
const navigationRequest = provisionalPage.coopNavigationRequest();
|
|
970
907
|
for (const [requestId, request] of this._requestIdToRequest) {
|
|
971
908
|
if (request.request === navigationRequest) {
|
|
972
|
-
// Make sure the request completes if the provisional navigation is canceled.
|
|
973
909
|
this._onLoadingFailed(provisionalPage._session, {
|
|
974
|
-
requestId
|
|
975
|
-
errorText:
|
|
910
|
+
requestId,
|
|
911
|
+
errorText: "Provisiolal navigation canceled.",
|
|
976
912
|
timestamp: request._timestamp,
|
|
977
913
|
canceled: true
|
|
978
914
|
});
|
|
@@ -991,35 +927,33 @@ class WKPage {
|
|
|
991
927
|
}
|
|
992
928
|
}
|
|
993
929
|
_onRequestWillBeSent(session, event) {
|
|
994
|
-
if (event.request.url.startsWith(
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
930
|
+
if (event.request.url.startsWith("data:"))
|
|
931
|
+
return;
|
|
932
|
+
if (event.request.url.startsWith("about:"))
|
|
933
|
+
return;
|
|
934
|
+
if (this._page.needsRequestInterception() && !event.redirectResponse)
|
|
935
|
+
this._requestIdToRequestWillBeSentEvent.set(event.requestId, event);
|
|
936
|
+
else
|
|
937
|
+
this._onRequest(session, event, false);
|
|
998
938
|
}
|
|
999
939
|
_onRequest(session, event, intercepted) {
|
|
1000
940
|
let redirectedFrom = null;
|
|
1001
941
|
if (event.redirectResponse) {
|
|
1002
|
-
const
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
redirectedFrom = request;
|
|
942
|
+
const request2 = this._requestIdToRequest.get(event.requestId);
|
|
943
|
+
if (request2) {
|
|
944
|
+
this._handleRequestRedirect(request2, event.requestId, event.redirectResponse, event.timestamp);
|
|
945
|
+
redirectedFrom = request2;
|
|
1007
946
|
}
|
|
1008
947
|
}
|
|
1009
948
|
const frame = redirectedFrom ? redirectedFrom.request.frame() : this._page._frameManager.frame(event.frameId);
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
const isNavigationRequest = event.type === 'Document';
|
|
1016
|
-
const documentId = isNavigationRequest ? event.loaderId : undefined;
|
|
1017
|
-
const request = new _wkInterceptableRequest.WKInterceptableRequest(session, frame, event, redirectedFrom, documentId);
|
|
949
|
+
if (!frame)
|
|
950
|
+
return;
|
|
951
|
+
const isNavigationRequest = event.type === "Document";
|
|
952
|
+
const documentId = isNavigationRequest ? event.loaderId : void 0;
|
|
953
|
+
const request = new import_wkInterceptableRequest.WKInterceptableRequest(session, frame, event, redirectedFrom, documentId);
|
|
1018
954
|
let route;
|
|
1019
955
|
if (intercepted) {
|
|
1020
|
-
route = new
|
|
1021
|
-
// There is no point in waiting for the raw headers in Network.responseReceived when intercepting.
|
|
1022
|
-
// Use provisional headers as raw headers, so that client can call allHeaders() from the route handler.
|
|
956
|
+
route = new import_wkInterceptableRequest.WKRouteImpl(session, event.requestId);
|
|
1023
957
|
request.request.setRawRequestHeaders(null);
|
|
1024
958
|
}
|
|
1025
959
|
this._requestIdToRequest.set(event.requestId, request);
|
|
@@ -1031,7 +965,7 @@ class WKPage {
|
|
|
1031
965
|
response._serverAddrFinished();
|
|
1032
966
|
response.setResponseHeadersSize(null);
|
|
1033
967
|
response.setEncodedBodySize(null);
|
|
1034
|
-
response._requestFinished(responsePayload.timing ?
|
|
968
|
+
response._requestFinished(responsePayload.timing ? import_helper.helper.secondsToRoundishMillis(timestamp - request._timestamp) : -1);
|
|
1035
969
|
this._requestIdToRequest.delete(requestId);
|
|
1036
970
|
this._page._frameManager.requestReceivedResponse(response);
|
|
1037
971
|
this._page._frameManager.reportRequestFinished(request.request, response);
|
|
@@ -1039,11 +973,7 @@ class WKPage {
|
|
|
1039
973
|
_onRequestIntercepted(session, event) {
|
|
1040
974
|
const requestWillBeSentEvent = this._requestIdToRequestWillBeSentEvent.get(event.requestId);
|
|
1041
975
|
if (!requestWillBeSentEvent) {
|
|
1042
|
-
|
|
1043
|
-
// Just continue.
|
|
1044
|
-
session.sendMayFail('Network.interceptWithRequest', {
|
|
1045
|
-
requestId: event.requestId
|
|
1046
|
-
});
|
|
976
|
+
session.sendMayFail("Network.interceptWithRequest", { requestId: event.requestId });
|
|
1047
977
|
return;
|
|
1048
978
|
}
|
|
1049
979
|
this._requestIdToRequestWillBeSentEvent.delete(event.requestId);
|
|
@@ -1053,49 +983,42 @@ class WKPage {
|
|
|
1053
983
|
const requestWillBeSentEvent = this._requestIdToRequestWillBeSentEvent.get(event.requestId);
|
|
1054
984
|
if (requestWillBeSentEvent) {
|
|
1055
985
|
this._requestIdToRequestWillBeSentEvent.delete(event.requestId);
|
|
1056
|
-
// We received a response, so the request won't be intercepted (e.g. it was handled by a
|
|
1057
|
-
// service worker and we don't intercept service workers).
|
|
1058
986
|
this._onRequest(session, requestWillBeSentEvent, false);
|
|
1059
987
|
}
|
|
1060
988
|
const request = this._requestIdToRequest.get(event.requestId);
|
|
1061
|
-
|
|
1062
|
-
|
|
989
|
+
if (!request)
|
|
990
|
+
return;
|
|
1063
991
|
this._requestIdToResponseReceivedPayloadEvent.set(event.requestId, event);
|
|
1064
992
|
const response = request.createResponse(event.response);
|
|
1065
993
|
this._page._frameManager.requestReceivedResponse(response);
|
|
1066
994
|
if (response.status() === 204 && request.request.isNavigationRequest()) {
|
|
1067
995
|
this._onLoadingFailed(session, {
|
|
1068
996
|
requestId: event.requestId,
|
|
1069
|
-
errorText:
|
|
997
|
+
errorText: "Aborted: 204 No Content",
|
|
1070
998
|
timestamp: event.timestamp
|
|
1071
999
|
});
|
|
1072
1000
|
}
|
|
1073
1001
|
}
|
|
1074
1002
|
_onLoadingFinished(event) {
|
|
1075
1003
|
const request = this._requestIdToRequest.get(event.requestId);
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
if (!request) return;
|
|
1079
|
-
|
|
1080
|
-
// Under certain conditions we never get the Network.responseReceived
|
|
1081
|
-
// event from protocol. @see https://crbug.com/883475
|
|
1004
|
+
if (!request)
|
|
1005
|
+
return;
|
|
1082
1006
|
const response = request.request._existingResponse();
|
|
1083
1007
|
if (response) {
|
|
1084
|
-
var _event$metrics, _event$metrics2, _responseReceivedPayl, _responseReceivedPayl2, _responseReceivedPayl3, _event$metrics3, _event$metrics$respon, _event$metrics4, _event$metrics$respon2, _event$metrics5;
|
|
1085
1008
|
const responseReceivedPayload = this._requestIdToResponseReceivedPayloadEvent.get(event.requestId);
|
|
1086
|
-
response._serverAddrFinished(parseRemoteAddress(event
|
|
1009
|
+
response._serverAddrFinished(parseRemoteAddress(event?.metrics?.remoteAddress));
|
|
1087
1010
|
response._securityDetailsFinished({
|
|
1088
|
-
protocol: isLoadedSecurely(response.url(), response.timing()) ?
|
|
1089
|
-
subjectName: responseReceivedPayload
|
|
1090
|
-
validFrom: responseReceivedPayload
|
|
1091
|
-
validTo: responseReceivedPayload
|
|
1011
|
+
protocol: isLoadedSecurely(response.url(), response.timing()) ? event.metrics?.securityConnection?.protocol : void 0,
|
|
1012
|
+
subjectName: responseReceivedPayload?.response.security?.certificate?.subject,
|
|
1013
|
+
validFrom: responseReceivedPayload?.response.security?.certificate?.validFrom,
|
|
1014
|
+
validTo: responseReceivedPayload?.response.security?.certificate?.validUntil
|
|
1092
1015
|
});
|
|
1093
|
-
if (
|
|
1094
|
-
|
|
1095
|
-
response.
|
|
1096
|
-
response.
|
|
1016
|
+
if (event.metrics?.protocol)
|
|
1017
|
+
response._setHttpVersion(event.metrics.protocol);
|
|
1018
|
+
response.setEncodedBodySize(event.metrics?.responseBodyBytesReceived ?? null);
|
|
1019
|
+
response.setResponseHeadersSize(event.metrics?.responseHeaderBytesReceived ?? null);
|
|
1020
|
+
response._requestFinished(import_helper.helper.secondsToRoundishMillis(event.timestamp - request._timestamp));
|
|
1097
1021
|
} else {
|
|
1098
|
-
// Use provisional headers if we didn't have the response with raw headers.
|
|
1099
1022
|
request.request.setRawRequestHeaders(null);
|
|
1100
1023
|
}
|
|
1101
1024
|
this._requestIdToResponseReceivedPayloadEvent.delete(event.requestId);
|
|
@@ -1106,103 +1029,86 @@ class WKPage {
|
|
|
1106
1029
|
const requestWillBeSentEvent = this._requestIdToRequestWillBeSentEvent.get(event.requestId);
|
|
1107
1030
|
if (requestWillBeSentEvent) {
|
|
1108
1031
|
this._requestIdToRequestWillBeSentEvent.delete(event.requestId);
|
|
1109
|
-
// If loading failed, the request won't be intercepted (e.g. it was handled by a
|
|
1110
|
-
// service worker and we don't intercept service workers).
|
|
1111
1032
|
this._onRequest(session, requestWillBeSentEvent, false);
|
|
1112
1033
|
}
|
|
1113
1034
|
const request = this._requestIdToRequest.get(event.requestId);
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
if (!request) return;
|
|
1035
|
+
if (!request)
|
|
1036
|
+
return;
|
|
1117
1037
|
const response = request.request._existingResponse();
|
|
1118
1038
|
if (response) {
|
|
1119
1039
|
response._serverAddrFinished();
|
|
1120
1040
|
response._securityDetailsFinished();
|
|
1121
1041
|
response.setResponseHeadersSize(null);
|
|
1122
1042
|
response.setEncodedBodySize(null);
|
|
1123
|
-
response._requestFinished(
|
|
1043
|
+
response._requestFinished(import_helper.helper.secondsToRoundishMillis(event.timestamp - request._timestamp));
|
|
1124
1044
|
} else {
|
|
1125
|
-
// Use provisional headers if we didn't have the response with raw headers.
|
|
1126
1045
|
request.request.setRawRequestHeaders(null);
|
|
1127
1046
|
}
|
|
1128
1047
|
this._requestIdToRequest.delete(event.requestId);
|
|
1129
1048
|
request.request._setFailureText(event.errorText);
|
|
1130
|
-
this._page._frameManager.requestFailed(request.request, event.errorText.includes(
|
|
1049
|
+
this._page._frameManager.requestFailed(request.request, event.errorText.includes("cancelled"));
|
|
1131
1050
|
}
|
|
1132
1051
|
async _grantPermissions(origin, permissions) {
|
|
1133
|
-
const webPermissionToProtocol = new Map([
|
|
1134
|
-
|
|
1052
|
+
const webPermissionToProtocol = /* @__PURE__ */ new Map([
|
|
1053
|
+
["geolocation", "geolocation"],
|
|
1054
|
+
["notifications", "notifications"],
|
|
1055
|
+
["clipboard-read", "clipboard-read"]
|
|
1056
|
+
]);
|
|
1057
|
+
const filtered = permissions.map((permission) => {
|
|
1135
1058
|
const protocolPermission = webPermissionToProtocol.get(permission);
|
|
1136
|
-
if (!protocolPermission)
|
|
1059
|
+
if (!protocolPermission)
|
|
1060
|
+
throw new Error("Unknown permission: " + permission);
|
|
1137
1061
|
return protocolPermission;
|
|
1138
1062
|
});
|
|
1139
|
-
await this._pageProxySession.send(
|
|
1140
|
-
origin,
|
|
1141
|
-
permissions: filtered
|
|
1142
|
-
});
|
|
1063
|
+
await this._pageProxySession.send("Emulation.grantPermissions", { origin, permissions: filtered });
|
|
1143
1064
|
}
|
|
1144
1065
|
async _clearPermissions() {
|
|
1145
|
-
await this._pageProxySession.send(
|
|
1066
|
+
await this._pageProxySession.send("Emulation.resetPermissions", {});
|
|
1146
1067
|
}
|
|
1147
1068
|
shouldToggleStyleSheetToSyncAnimations() {
|
|
1148
1069
|
return true;
|
|
1149
1070
|
}
|
|
1150
1071
|
}
|
|
1151
|
-
|
|
1152
|
-
/**
|
|
1153
|
-
* WebKit Remote Addresses look like:
|
|
1154
|
-
*
|
|
1155
|
-
* macOS:
|
|
1156
|
-
* ::1.8911
|
|
1157
|
-
* 2606:2800:220:1:248:1893:25c8:1946.443
|
|
1158
|
-
* 127.0.0.1:8000
|
|
1159
|
-
*
|
|
1160
|
-
* ubuntu:
|
|
1161
|
-
* ::1:8907
|
|
1162
|
-
* 127.0.0.1:8000
|
|
1163
|
-
*
|
|
1164
|
-
* NB: They look IPv4 and IPv6's with ports but use an alternative notation.
|
|
1165
|
-
*/
|
|
1166
|
-
exports.WKPage = WKPage;
|
|
1167
1072
|
function parseRemoteAddress(value) {
|
|
1168
|
-
if (!value)
|
|
1073
|
+
if (!value)
|
|
1074
|
+
return;
|
|
1169
1075
|
try {
|
|
1170
|
-
const colon = value.lastIndexOf(
|
|
1171
|
-
const dot = value.lastIndexOf(
|
|
1076
|
+
const colon = value.lastIndexOf(":");
|
|
1077
|
+
const dot = value.lastIndexOf(".");
|
|
1172
1078
|
if (dot < 0) {
|
|
1173
|
-
// IPv6ish:port
|
|
1174
1079
|
return {
|
|
1175
1080
|
ipAddress: `[${value.slice(0, colon)}]`,
|
|
1176
1081
|
port: +value.slice(colon + 1)
|
|
1177
1082
|
};
|
|
1178
1083
|
}
|
|
1179
1084
|
if (colon > dot) {
|
|
1180
|
-
|
|
1181
|
-
const [address, port] = value.split(':');
|
|
1085
|
+
const [address, port] = value.split(":");
|
|
1182
1086
|
return {
|
|
1183
1087
|
ipAddress: address,
|
|
1184
1088
|
port: +port
|
|
1185
1089
|
};
|
|
1186
1090
|
} else {
|
|
1187
|
-
|
|
1188
|
-
const [address, port] = value.split('.');
|
|
1091
|
+
const [address, port] = value.split(".");
|
|
1189
1092
|
return {
|
|
1190
1093
|
ipAddress: `[${address}]`,
|
|
1191
1094
|
port: +port
|
|
1192
1095
|
};
|
|
1193
1096
|
}
|
|
1194
|
-
} catch (_) {
|
|
1097
|
+
} catch (_) {
|
|
1098
|
+
}
|
|
1195
1099
|
}
|
|
1196
|
-
|
|
1197
|
-
/**
|
|
1198
|
-
* Adapted from Source/WebInspectorUI/UserInterface/Models/Resource.js in
|
|
1199
|
-
* WebKit codebase.
|
|
1200
|
-
*/
|
|
1201
1100
|
function isLoadedSecurely(url, timing) {
|
|
1202
1101
|
try {
|
|
1203
1102
|
const u = new URL(url);
|
|
1204
|
-
if (u.protocol !==
|
|
1205
|
-
|
|
1103
|
+
if (u.protocol !== "https:" && u.protocol !== "wss:" && u.protocol !== "sftp:")
|
|
1104
|
+
return false;
|
|
1105
|
+
if (timing.secureConnectionStart === -1 && timing.connectStart !== -1)
|
|
1106
|
+
return false;
|
|
1206
1107
|
return true;
|
|
1207
|
-
} catch (_) {
|
|
1208
|
-
}
|
|
1108
|
+
} catch (_) {
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1112
|
+
0 && (module.exports = {
|
|
1113
|
+
WKPage
|
|
1114
|
+
});
|