patchright-core 1.51.3 → 1.52.1
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 +56 -71
- 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 +371 -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 +284 -404
- 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 +221 -112
- package/lib/server/frames.js +731 -894
- 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 +326 -423
- 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 +86 -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-CXVeovup.js} +1 -1
- package/lib/vite/recorder/assets/index-BsWQsSGl.js +184 -0
- package/lib/vite/recorder/index.html +1 -1
- package/lib/vite/traceViewer/assets/{codeMirrorModule-1DiydmYA.js → codeMirrorModule-_GLjJL-7.js} +1 -1
- package/lib/vite/traceViewer/assets/defaultSettingsView-DtCQiGHe.js +265 -0
- package/lib/vite/traceViewer/{defaultSettingsView.5fN5lw10.css → defaultSettingsView.QdHITyLI.css} +1 -1
- package/lib/vite/traceViewer/index.cFZzK9RN.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.XVPIqBeS.js +5 -0
- package/lib/vite/traceViewer/uiMode.html +3 -3
- 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-l0TyP_G8.js +0 -259
- package/lib/vite/traceViewer/index.BqUZLSro.js +0 -2
- package/lib/vite/traceViewer/uiMode.C1d2m5sF.js +0 -5
package/lib/server/page.js
CHANGED
|
@@ -1,90 +1,85 @@
|
|
|
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 page_exports = {};
|
|
30
|
+
__export(page_exports, {
|
|
31
|
+
InitScript: () => InitScript,
|
|
32
|
+
Page: () => Page,
|
|
33
|
+
PageBinding: () => PageBinding,
|
|
34
|
+
Worker: () => Worker,
|
|
35
|
+
kBuiltinsScript: () => kBuiltinsScript
|
|
5
36
|
});
|
|
6
|
-
|
|
7
|
-
var accessibility =
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var frames =
|
|
13
|
-
var
|
|
14
|
-
var input =
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* Copyright 2017 Google Inc. All rights reserved.
|
|
32
|
-
* Modifications copyright (c) Microsoft Corporation.
|
|
33
|
-
*
|
|
34
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
35
|
-
* you may not use this file except in compliance with the License.
|
|
36
|
-
* You may obtain a copy of the License at
|
|
37
|
-
*
|
|
38
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
39
|
-
*
|
|
40
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
41
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
42
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
43
|
-
* See the License for the specific language governing permissions and
|
|
44
|
-
* limitations under the License.
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
class Page extends _instrumentation.SdkObject {
|
|
37
|
+
module.exports = __toCommonJS(page_exports);
|
|
38
|
+
var accessibility = __toESM(require("./accessibility"));
|
|
39
|
+
var import_browserContext = require("./browserContext");
|
|
40
|
+
var import_console = require("./console");
|
|
41
|
+
var import_errors = require("./errors");
|
|
42
|
+
var import_fileChooser = require("./fileChooser");
|
|
43
|
+
var frames = __toESM(require("./frames"));
|
|
44
|
+
var import_helper = require("./helper");
|
|
45
|
+
var input = __toESM(require("./input"));
|
|
46
|
+
var import_instrumentation = require("./instrumentation");
|
|
47
|
+
var import_builtins = require("../utils/isomorphic/builtins");
|
|
48
|
+
var import_pageBinding = require("./pageBinding");
|
|
49
|
+
var js = __toESM(require("./javascript"));
|
|
50
|
+
var import_progress = require("./progress");
|
|
51
|
+
var import_screenshotter = require("./screenshotter");
|
|
52
|
+
var import_timeoutSettings = require("./timeoutSettings");
|
|
53
|
+
var import_utils = require("../utils");
|
|
54
|
+
var import_crypto = require("./utils/crypto");
|
|
55
|
+
var import_utils2 = require("../utils");
|
|
56
|
+
var import_comparators = require("./utils/comparators");
|
|
57
|
+
var import_debugLogger = require("./utils/debugLogger");
|
|
58
|
+
var import_selectorParser = require("../utils/isomorphic/selectorParser");
|
|
59
|
+
var import_manualPromise = require("../utils/isomorphic/manualPromise");
|
|
60
|
+
var import_callLog = require("./callLog");
|
|
61
|
+
class Page extends import_instrumentation.SdkObject {
|
|
48
62
|
constructor(delegate, browserContext) {
|
|
49
|
-
super(browserContext,
|
|
50
|
-
this._closedState =
|
|
51
|
-
this._closedPromise = new
|
|
52
|
-
this.
|
|
53
|
-
this._initializedPromise = new _manualPromise.ManualPromise();
|
|
63
|
+
super(browserContext, "page");
|
|
64
|
+
this._closedState = "open";
|
|
65
|
+
this._closedPromise = new import_manualPromise.ManualPromise();
|
|
66
|
+
this._initializedPromise = new import_manualPromise.ManualPromise();
|
|
54
67
|
this._eventsToEmitAfterInitialized = [];
|
|
55
68
|
this._crashed = false;
|
|
56
|
-
this.openScope = new
|
|
57
|
-
this._browserContext = void 0;
|
|
58
|
-
this.keyboard = void 0;
|
|
59
|
-
this.mouse = void 0;
|
|
60
|
-
this.touchscreen = void 0;
|
|
61
|
-
this._timeoutSettings = void 0;
|
|
62
|
-
this._delegate = void 0;
|
|
63
|
-
this._emulatedSize = void 0;
|
|
64
|
-
this._extraHTTPHeaders = void 0;
|
|
69
|
+
this.openScope = new import_utils.LongStandingScope();
|
|
65
70
|
this._emulatedMedia = {};
|
|
66
71
|
this._interceptFileChooser = false;
|
|
67
|
-
this._pageBindings = new Map();
|
|
72
|
+
this._pageBindings = /* @__PURE__ */ new Map();
|
|
68
73
|
this.initScripts = [];
|
|
69
|
-
this.
|
|
70
|
-
this._frameManager = void 0;
|
|
71
|
-
this.accessibility = void 0;
|
|
72
|
-
this._workers = new Map();
|
|
73
|
-
this.pdf = void 0;
|
|
74
|
-
this.coverage = void 0;
|
|
75
|
-
this._clientRequestInterceptor = void 0;
|
|
76
|
-
this._serverRequestInterceptor = void 0;
|
|
77
|
-
this._ownedContext = void 0;
|
|
74
|
+
this._workers = /* @__PURE__ */ new Map();
|
|
78
75
|
this._video = null;
|
|
79
|
-
this._opener = void 0;
|
|
80
76
|
this._isServerSideOnly = false;
|
|
81
|
-
this._locatorHandlers = new Map();
|
|
77
|
+
this._locatorHandlers = /* @__PURE__ */ new Map();
|
|
82
78
|
this._lastLocatorHandlerUid = 0;
|
|
83
79
|
this._locatorHandlerRunningCounter = 0;
|
|
84
80
|
// Aiming at 25 fps by default - each frame is 40ms, but we give some slack with 35ms.
|
|
85
81
|
// When throttling for tracing, 200ms between frames, except for 10 frames around the action.
|
|
86
82
|
this._frameThrottler = new FrameThrottler(10, 35, 200);
|
|
87
|
-
this._closeReason = void 0;
|
|
88
83
|
this.attribution.page = this;
|
|
89
84
|
this._delegate = delegate;
|
|
90
85
|
this._browserContext = browserContext;
|
|
@@ -92,91 +87,103 @@ class Page extends _instrumentation.SdkObject {
|
|
|
92
87
|
this.keyboard = new input.Keyboard(delegate.rawKeyboard);
|
|
93
88
|
this.mouse = new input.Mouse(delegate.rawMouse, this);
|
|
94
89
|
this.touchscreen = new input.Touchscreen(delegate.rawTouchscreen, this);
|
|
95
|
-
this._timeoutSettings = new
|
|
96
|
-
this._screenshotter = new
|
|
90
|
+
this._timeoutSettings = new import_timeoutSettings.TimeoutSettings(browserContext._timeoutSettings);
|
|
91
|
+
this._screenshotter = new import_screenshotter.Screenshotter(this);
|
|
97
92
|
this._frameManager = new frames.FrameManager(this);
|
|
98
|
-
if (delegate.pdf)
|
|
93
|
+
if (delegate.pdf)
|
|
94
|
+
this.pdf = delegate.pdf.bind(delegate);
|
|
99
95
|
this.coverage = delegate.coverage ? delegate.coverage() : null;
|
|
100
96
|
}
|
|
101
|
-
|
|
97
|
+
static {
|
|
98
|
+
this.Events = {
|
|
99
|
+
Close: "close",
|
|
100
|
+
Crash: "crash",
|
|
101
|
+
Download: "download",
|
|
102
|
+
FileChooser: "filechooser",
|
|
103
|
+
FrameAttached: "frameattached",
|
|
104
|
+
FrameDetached: "framedetached",
|
|
105
|
+
InternalFrameNavigatedToNewDocument: "internalframenavigatedtonewdocument",
|
|
106
|
+
LocatorHandlerTriggered: "locatorhandlertriggered",
|
|
107
|
+
ScreencastFrame: "screencastframe",
|
|
108
|
+
Video: "video",
|
|
109
|
+
WebSocket: "websocket",
|
|
110
|
+
Worker: "worker"
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
async reportAsNew(opener, error = void 0, contextEvent = import_browserContext.BrowserContext.Events.Page) {
|
|
102
114
|
if (opener) {
|
|
103
115
|
const openerPageOrError = await opener.waitForInitializedOrError();
|
|
104
|
-
if (openerPageOrError instanceof Page && !openerPageOrError.isClosed())
|
|
116
|
+
if (openerPageOrError instanceof Page && !openerPageOrError.isClosed())
|
|
117
|
+
this._opener = openerPageOrError;
|
|
105
118
|
}
|
|
106
119
|
this._markInitialized(error, contextEvent);
|
|
107
120
|
}
|
|
108
|
-
_markInitialized(error =
|
|
121
|
+
_markInitialized(error = void 0, contextEvent = import_browserContext.BrowserContext.Events.Page) {
|
|
109
122
|
if (error) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (this._browserContext.isClosingOrClosed()) return;
|
|
123
|
+
if (this._browserContext.isClosingOrClosed())
|
|
124
|
+
return;
|
|
113
125
|
this._frameManager.createDummyMainFrameIfNeeded();
|
|
114
126
|
}
|
|
115
127
|
this._initialized = error || this;
|
|
116
128
|
this.emitOnContext(contextEvent, this);
|
|
117
|
-
for (const {
|
|
118
|
-
event,
|
|
119
|
-
args
|
|
120
|
-
} of this._eventsToEmitAfterInitialized) this._browserContext.emit(event, ...args);
|
|
129
|
+
for (const { event, args } of this._eventsToEmitAfterInitialized)
|
|
130
|
+
this._browserContext.emit(event, ...args);
|
|
121
131
|
this._eventsToEmitAfterInitialized = [];
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (this.isClosed()) this.emit(Page.Events.Close);else this.instrumentation.onPageOpen(this);
|
|
127
|
-
|
|
128
|
-
// Note: it is important to resolve _initializedPromise at the end,
|
|
129
|
-
// so that anyone who awaits waitForInitializedOrError got a ready and reported page.
|
|
132
|
+
if (this.isClosed())
|
|
133
|
+
this.emit(Page.Events.Close);
|
|
134
|
+
else
|
|
135
|
+
this.instrumentation.onPageOpen(this);
|
|
130
136
|
this._initializedPromise.resolve(this._initialized);
|
|
131
137
|
}
|
|
132
138
|
initializedOrUndefined() {
|
|
133
|
-
return this._initialized ? this :
|
|
139
|
+
return this._initialized ? this : void 0;
|
|
134
140
|
}
|
|
135
141
|
waitForInitializedOrError() {
|
|
136
142
|
return this._initializedPromise;
|
|
137
143
|
}
|
|
138
144
|
emitOnContext(event, ...args) {
|
|
139
|
-
if (this._isServerSideOnly)
|
|
145
|
+
if (this._isServerSideOnly)
|
|
146
|
+
return;
|
|
140
147
|
this._browserContext.emit(event, ...args);
|
|
141
148
|
}
|
|
142
149
|
emitOnContextOnceInitialized(event, ...args) {
|
|
143
|
-
if (this._isServerSideOnly)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
event,
|
|
150
|
-
args
|
|
151
|
-
});
|
|
150
|
+
if (this._isServerSideOnly)
|
|
151
|
+
return;
|
|
152
|
+
if (this._initialized)
|
|
153
|
+
this._browserContext.emit(event, ...args);
|
|
154
|
+
else
|
|
155
|
+
this._eventsToEmitAfterInitialized.push({ event, args });
|
|
152
156
|
}
|
|
153
157
|
async resetForReuse(metadata) {
|
|
154
|
-
this.setDefaultNavigationTimeout(
|
|
155
|
-
this.setDefaultTimeout(
|
|
158
|
+
this.setDefaultNavigationTimeout(void 0);
|
|
159
|
+
this.setDefaultTimeout(void 0);
|
|
156
160
|
this._locatorHandlers.clear();
|
|
157
161
|
await this._removeExposedBindings();
|
|
158
162
|
await this._removeInitScripts();
|
|
159
|
-
await this.setClientRequestInterceptor(
|
|
160
|
-
await this._setServerRequestInterceptor(
|
|
163
|
+
await this.setClientRequestInterceptor(void 0);
|
|
164
|
+
await this._setServerRequestInterceptor(void 0);
|
|
161
165
|
await this.setFileChooserIntercepted(false);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
this._emulatedSize = undefined;
|
|
166
|
+
await this.mainFrame().goto(metadata, "about:blank");
|
|
167
|
+
this._emulatedSize = void 0;
|
|
165
168
|
this._emulatedMedia = {};
|
|
166
|
-
this._extraHTTPHeaders =
|
|
169
|
+
this._extraHTTPHeaders = void 0;
|
|
167
170
|
this._interceptFileChooser = false;
|
|
168
|
-
await Promise.all([
|
|
171
|
+
await Promise.all([
|
|
172
|
+
this._delegate.updateEmulatedViewportSize(),
|
|
173
|
+
this._delegate.updateEmulateMedia(),
|
|
174
|
+
this._delegate.updateFileChooserInterception()
|
|
175
|
+
]);
|
|
169
176
|
await this._delegate.resetForReuse();
|
|
170
177
|
}
|
|
171
178
|
_didClose() {
|
|
172
179
|
this._frameManager.dispose();
|
|
173
180
|
this._frameThrottler.dispose();
|
|
174
|
-
(0,
|
|
175
|
-
this._closedState =
|
|
181
|
+
(0, import_utils.assert)(this._closedState !== "closed", "Page closed twice");
|
|
182
|
+
this._closedState = "closed";
|
|
176
183
|
this.emit(Page.Events.Close);
|
|
177
184
|
this._closedPromise.resolve();
|
|
178
185
|
this.instrumentation.onPageClose(this);
|
|
179
|
-
this.openScope.close(new
|
|
186
|
+
this.openScope.close(new import_errors.TargetClosedError());
|
|
180
187
|
}
|
|
181
188
|
_didCrash() {
|
|
182
189
|
this._frameManager.dispose();
|
|
@@ -184,21 +191,20 @@ class Page extends _instrumentation.SdkObject {
|
|
|
184
191
|
this.emit(Page.Events.Crash);
|
|
185
192
|
this._crashed = true;
|
|
186
193
|
this.instrumentation.onPageClose(this);
|
|
187
|
-
this.openScope.close(new Error(
|
|
194
|
+
this.openScope.close(new Error("Page crashed"));
|
|
188
195
|
}
|
|
189
196
|
async _onFileChooserOpened(handle) {
|
|
190
197
|
let multiple;
|
|
191
198
|
try {
|
|
192
|
-
multiple = await handle.evaluate(element => !!element.multiple);
|
|
199
|
+
multiple = await handle.evaluate((element) => !!element.multiple);
|
|
193
200
|
} catch (e) {
|
|
194
|
-
// Frame/context may be gone during async processing. Do not throw.
|
|
195
201
|
return;
|
|
196
202
|
}
|
|
197
203
|
if (!this.listenerCount(Page.Events.FileChooser)) {
|
|
198
204
|
handle.dispose();
|
|
199
205
|
return;
|
|
200
206
|
}
|
|
201
|
-
const fileChooser = new
|
|
207
|
+
const fileChooser = new import_fileChooser.FileChooser(this, handle, multiple);
|
|
202
208
|
this.emit(Page.Events.FileChooser, fileChooser);
|
|
203
209
|
}
|
|
204
210
|
context() {
|
|
@@ -220,15 +226,18 @@ class Page extends _instrumentation.SdkObject {
|
|
|
220
226
|
this._timeoutSettings.setDefaultTimeout(timeout);
|
|
221
227
|
}
|
|
222
228
|
async exposeBinding(name, needsHandle, playwrightBinding) {
|
|
223
|
-
if (this._pageBindings.has(name))
|
|
224
|
-
|
|
229
|
+
if (this._pageBindings.has(name))
|
|
230
|
+
throw new Error(`Function "${name}" has been already registered`);
|
|
231
|
+
if (this._browserContext._pageBindings.has(name))
|
|
232
|
+
throw new Error(`Function "${name}" has been already registered in the browser context`);
|
|
225
233
|
const binding = new PageBinding(name, playwrightBinding, needsHandle);
|
|
226
234
|
this._pageBindings.set(name, binding);
|
|
227
235
|
await this._delegate.exposeBinding(binding);
|
|
228
236
|
}
|
|
229
237
|
async _removeExposedBindings() {
|
|
230
238
|
for (const key of this._pageBindings.keys()) {
|
|
231
|
-
if (!key.startsWith(
|
|
239
|
+
if (!key.startsWith("__pw"))
|
|
240
|
+
this._pageBindings.delete(key);
|
|
232
241
|
}
|
|
233
242
|
await this._delegate.removeExposedBindings();
|
|
234
243
|
}
|
|
@@ -240,60 +249,61 @@ class Page extends _instrumentation.SdkObject {
|
|
|
240
249
|
return this._extraHTTPHeaders;
|
|
241
250
|
}
|
|
242
251
|
async _onBindingCalled(payload, context) {
|
|
243
|
-
if (this._closedState ===
|
|
252
|
+
if (this._closedState === "closed")
|
|
253
|
+
return;
|
|
244
254
|
await PageBinding.dispatch(this, payload, context);
|
|
245
255
|
}
|
|
246
256
|
_addConsoleMessage(type, args, location, text) {
|
|
247
|
-
const message = new
|
|
257
|
+
const message = new import_console.ConsoleMessage(this, type, text, args, location);
|
|
248
258
|
const intercepted = this._frameManager.interceptConsoleMessage(message);
|
|
249
259
|
if (intercepted) {
|
|
250
|
-
args.forEach(arg => arg.dispose());
|
|
260
|
+
args.forEach((arg) => arg.dispose());
|
|
251
261
|
return;
|
|
252
262
|
}
|
|
253
|
-
this.emitOnContextOnceInitialized(
|
|
263
|
+
this.emitOnContextOnceInitialized(import_browserContext.BrowserContext.Events.Console, message);
|
|
254
264
|
}
|
|
255
265
|
async reload(metadata, options) {
|
|
256
|
-
const controller = new
|
|
257
|
-
return controller.run(progress => this.mainFrame().raceNavigationAction(progress, options, async () => {
|
|
258
|
-
// Note: waitForNavigation may fail before we get response to reload(),
|
|
259
|
-
// so we should await it immediately.
|
|
266
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
267
|
+
return controller.run((progress) => this.mainFrame().raceNavigationAction(progress, options, async () => {
|
|
260
268
|
const [response] = await Promise.all([
|
|
261
|
-
|
|
262
|
-
|
|
269
|
+
// Reload must be a new document, and should not be confused with a stray pushState.
|
|
270
|
+
this.mainFrame()._waitForNavigation(progress, true, options),
|
|
271
|
+
this._delegate.reload()
|
|
272
|
+
]);
|
|
263
273
|
return response;
|
|
264
274
|
}), this._timeoutSettings.navigationTimeout(options));
|
|
265
275
|
}
|
|
266
276
|
async goBack(metadata, options) {
|
|
267
|
-
const controller = new
|
|
268
|
-
return controller.run(progress => this.mainFrame().raceNavigationAction(progress, options, async () => {
|
|
269
|
-
// Note: waitForNavigation may fail before we get response to goBack,
|
|
270
|
-
// so we should catch it immediately.
|
|
277
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
278
|
+
return controller.run((progress) => this.mainFrame().raceNavigationAction(progress, options, async () => {
|
|
271
279
|
let error;
|
|
272
|
-
const waitPromise = this.mainFrame()._waitForNavigation(progress, false
|
|
280
|
+
const waitPromise = this.mainFrame()._waitForNavigation(progress, false, options).catch((e) => {
|
|
273
281
|
error = e;
|
|
274
282
|
return null;
|
|
275
283
|
});
|
|
276
284
|
const result = await this._delegate.goBack();
|
|
277
|
-
if (!result)
|
|
285
|
+
if (!result)
|
|
286
|
+
return null;
|
|
278
287
|
const response = await waitPromise;
|
|
279
|
-
if (error)
|
|
288
|
+
if (error)
|
|
289
|
+
throw error;
|
|
280
290
|
return response;
|
|
281
291
|
}), this._timeoutSettings.navigationTimeout(options));
|
|
282
292
|
}
|
|
283
293
|
async goForward(metadata, options) {
|
|
284
|
-
const controller = new
|
|
285
|
-
return controller.run(progress => this.mainFrame().raceNavigationAction(progress, options, async () => {
|
|
286
|
-
// Note: waitForNavigation may fail before we get response to goForward,
|
|
287
|
-
// so we should catch it immediately.
|
|
294
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
295
|
+
return controller.run((progress) => this.mainFrame().raceNavigationAction(progress, options, async () => {
|
|
288
296
|
let error;
|
|
289
|
-
const waitPromise = this.mainFrame()._waitForNavigation(progress, false
|
|
297
|
+
const waitPromise = this.mainFrame()._waitForNavigation(progress, false, options).catch((e) => {
|
|
290
298
|
error = e;
|
|
291
299
|
return null;
|
|
292
300
|
});
|
|
293
301
|
const result = await this._delegate.goForward();
|
|
294
|
-
if (!result)
|
|
302
|
+
if (!result)
|
|
303
|
+
return null;
|
|
295
304
|
const response = await waitPromise;
|
|
296
|
-
if (error)
|
|
305
|
+
if (error)
|
|
306
|
+
throw error;
|
|
297
307
|
return response;
|
|
298
308
|
}), this._timeoutSettings.navigationTimeout(options));
|
|
299
309
|
}
|
|
@@ -302,19 +312,16 @@ class Page extends _instrumentation.SdkObject {
|
|
|
302
312
|
}
|
|
303
313
|
registerLocatorHandler(selector, noWaitAfter) {
|
|
304
314
|
const uid = ++this._lastLocatorHandlerUid;
|
|
305
|
-
this._locatorHandlers.set(uid, {
|
|
306
|
-
selector,
|
|
307
|
-
noWaitAfter
|
|
308
|
-
});
|
|
315
|
+
this._locatorHandlers.set(uid, { selector, noWaitAfter });
|
|
309
316
|
return uid;
|
|
310
317
|
}
|
|
311
318
|
resolveLocatorHandler(uid, remove) {
|
|
312
319
|
const handler = this._locatorHandlers.get(uid);
|
|
313
|
-
if (remove)
|
|
320
|
+
if (remove)
|
|
321
|
+
this._locatorHandlers.delete(uid);
|
|
314
322
|
if (handler) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
handler.resolved = undefined;
|
|
323
|
+
handler.resolved?.resolve();
|
|
324
|
+
handler.resolved = void 0;
|
|
318
325
|
}
|
|
319
326
|
}
|
|
320
327
|
unregisterLocatorHandler(uid) {
|
|
@@ -325,103 +332,94 @@ class Page extends _instrumentation.SdkObject {
|
|
|
325
332
|
progress.throwIfAborted();
|
|
326
333
|
await this._performLocatorHandlersCheckpoint(progress);
|
|
327
334
|
progress.throwIfAborted();
|
|
328
|
-
// Wait once again, just in case a locator handler caused a navigation.
|
|
329
335
|
await this._performWaitForNavigationCheck(progress);
|
|
330
336
|
}
|
|
331
337
|
async _performWaitForNavigationCheck(progress) {
|
|
332
|
-
|
|
333
|
-
|
|
338
|
+
if (process.env.PLAYWRIGHT_SKIP_NAVIGATION_CHECK)
|
|
339
|
+
return;
|
|
334
340
|
const mainFrame = this._frameManager.mainFrame();
|
|
335
|
-
if (!mainFrame || !mainFrame.pendingDocument())
|
|
336
|
-
|
|
337
|
-
const
|
|
341
|
+
if (!mainFrame || !mainFrame.pendingDocument())
|
|
342
|
+
return;
|
|
343
|
+
const url = mainFrame.pendingDocument()?.request?.url();
|
|
344
|
+
const toUrl = url ? `" ${(0, import_utils.trimStringWithEllipsis)(url, 200)}"` : "";
|
|
338
345
|
progress.log(` waiting for${toUrl} navigation to finish...`);
|
|
339
|
-
await
|
|
340
|
-
if (!e.isPublic)
|
|
341
|
-
|
|
346
|
+
await import_helper.helper.waitForEvent(progress, mainFrame, frames.Frame.Events.InternalNavigation, (e) => {
|
|
347
|
+
if (!e.isPublic)
|
|
348
|
+
return false;
|
|
349
|
+
if (!e.error)
|
|
350
|
+
progress.log(` navigated to "${(0, import_utils.trimStringWithEllipsis)(mainFrame.url(), 200)}"`);
|
|
342
351
|
return true;
|
|
343
352
|
}).promise;
|
|
344
353
|
}
|
|
345
354
|
async _performLocatorHandlersCheckpoint(progress) {
|
|
346
|
-
|
|
347
|
-
|
|
355
|
+
if (this._locatorHandlerRunningCounter)
|
|
356
|
+
return;
|
|
348
357
|
for (const [uid, handler] of this._locatorHandlers) {
|
|
349
358
|
if (!handler.resolved) {
|
|
350
|
-
if (await this.mainFrame().isVisibleInternal(handler.selector, {
|
|
351
|
-
|
|
352
|
-
})) {
|
|
353
|
-
handler.resolved = new _manualPromise.ManualPromise();
|
|
359
|
+
if (await this.mainFrame().isVisibleInternal(handler.selector, { strict: true })) {
|
|
360
|
+
handler.resolved = new import_manualPromise.ManualPromise();
|
|
354
361
|
this.emit(Page.Events.LocatorHandlerTriggered, uid);
|
|
355
362
|
}
|
|
356
363
|
}
|
|
357
364
|
if (handler.resolved) {
|
|
358
365
|
++this._locatorHandlerRunningCounter;
|
|
359
|
-
progress.log(` found ${(0,
|
|
366
|
+
progress.log(` found ${(0, import_utils2.asLocator)(this.attribution.playwright.options.sdkLanguage, handler.selector)}, intercepting action to run the handler`);
|
|
360
367
|
const promise = handler.resolved.then(async () => {
|
|
361
368
|
progress.throwIfAborted();
|
|
362
369
|
if (!handler.noWaitAfter) {
|
|
363
|
-
progress.log(` locator handler has finished, waiting for ${(0,
|
|
364
|
-
await this.mainFrame().waitForSelectorInternal(progress, handler.selector, false, {
|
|
365
|
-
state: 'hidden'
|
|
366
|
-
});
|
|
370
|
+
progress.log(` locator handler has finished, waiting for ${(0, import_utils2.asLocator)(this.attribution.playwright.options.sdkLanguage, handler.selector)} to be hidden`);
|
|
371
|
+
await this.mainFrame().waitForSelectorInternal(progress, handler.selector, false, { state: "hidden" });
|
|
367
372
|
} else {
|
|
368
373
|
progress.log(` locator handler has finished`);
|
|
369
374
|
}
|
|
370
375
|
});
|
|
371
376
|
await this.openScope.race(promise).finally(() => --this._locatorHandlerRunningCounter);
|
|
372
|
-
// Avoid side-effects after long-running operation.
|
|
373
377
|
progress.throwIfAborted();
|
|
374
378
|
progress.log(` interception handler has finished, continuing`);
|
|
375
379
|
}
|
|
376
380
|
}
|
|
377
381
|
}
|
|
378
382
|
async emulateMedia(options) {
|
|
379
|
-
if (options.media !==
|
|
380
|
-
|
|
381
|
-
if (options.
|
|
382
|
-
|
|
383
|
-
if (options.
|
|
383
|
+
if (options.media !== void 0)
|
|
384
|
+
this._emulatedMedia.media = options.media;
|
|
385
|
+
if (options.colorScheme !== void 0)
|
|
386
|
+
this._emulatedMedia.colorScheme = options.colorScheme;
|
|
387
|
+
if (options.reducedMotion !== void 0)
|
|
388
|
+
this._emulatedMedia.reducedMotion = options.reducedMotion;
|
|
389
|
+
if (options.forcedColors !== void 0)
|
|
390
|
+
this._emulatedMedia.forcedColors = options.forcedColors;
|
|
391
|
+
if (options.contrast !== void 0)
|
|
392
|
+
this._emulatedMedia.contrast = options.contrast;
|
|
384
393
|
await this._delegate.updateEmulateMedia();
|
|
385
394
|
}
|
|
386
395
|
emulatedMedia() {
|
|
387
|
-
var _contextOptions$color, _contextOptions$reduc, _contextOptions$force, _contextOptions$contr;
|
|
388
396
|
const contextOptions = this._browserContext._options;
|
|
389
397
|
return {
|
|
390
|
-
media: this._emulatedMedia.media ||
|
|
391
|
-
colorScheme: this._emulatedMedia.colorScheme !==
|
|
392
|
-
reducedMotion: this._emulatedMedia.reducedMotion !==
|
|
393
|
-
forcedColors: this._emulatedMedia.forcedColors !==
|
|
394
|
-
contrast: this._emulatedMedia.contrast !==
|
|
398
|
+
media: this._emulatedMedia.media || "no-override",
|
|
399
|
+
colorScheme: this._emulatedMedia.colorScheme !== void 0 ? this._emulatedMedia.colorScheme : contextOptions.colorScheme ?? "light",
|
|
400
|
+
reducedMotion: this._emulatedMedia.reducedMotion !== void 0 ? this._emulatedMedia.reducedMotion : contextOptions.reducedMotion ?? "no-preference",
|
|
401
|
+
forcedColors: this._emulatedMedia.forcedColors !== void 0 ? this._emulatedMedia.forcedColors : contextOptions.forcedColors ?? "none",
|
|
402
|
+
contrast: this._emulatedMedia.contrast !== void 0 ? this._emulatedMedia.contrast : contextOptions.contrast ?? "no-preference"
|
|
395
403
|
};
|
|
396
404
|
}
|
|
397
405
|
async setViewportSize(viewportSize) {
|
|
398
|
-
this._emulatedSize = {
|
|
399
|
-
viewport: {
|
|
400
|
-
...viewportSize
|
|
401
|
-
},
|
|
402
|
-
screen: {
|
|
403
|
-
...viewportSize
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
+
this._emulatedSize = { viewport: { ...viewportSize }, screen: { ...viewportSize } };
|
|
406
407
|
await this._delegate.updateEmulatedViewportSize();
|
|
407
408
|
}
|
|
408
409
|
viewportSize() {
|
|
409
|
-
|
|
410
|
-
return ((_this$emulatedSize = this.emulatedSize()) === null || _this$emulatedSize === void 0 ? void 0 : _this$emulatedSize.viewport) || null;
|
|
410
|
+
return this.emulatedSize()?.viewport || null;
|
|
411
411
|
}
|
|
412
412
|
emulatedSize() {
|
|
413
|
-
if (this._emulatedSize)
|
|
413
|
+
if (this._emulatedSize)
|
|
414
|
+
return this._emulatedSize;
|
|
414
415
|
const contextOptions = this._browserContext._options;
|
|
415
|
-
return contextOptions.viewport ? {
|
|
416
|
-
viewport: contextOptions.viewport,
|
|
417
|
-
screen: contextOptions.screen || contextOptions.viewport
|
|
418
|
-
} : null;
|
|
416
|
+
return contextOptions.viewport ? { viewport: contextOptions.viewport, screen: contextOptions.screen || contextOptions.viewport } : null;
|
|
419
417
|
}
|
|
420
418
|
async bringToFront() {
|
|
421
419
|
await this._delegate.bringToFront();
|
|
422
420
|
}
|
|
423
421
|
async addInitScript(source, name) {
|
|
424
|
-
const initScript = new InitScript(source, false
|
|
422
|
+
const initScript = new InitScript(source, false, name);
|
|
425
423
|
this.initScripts.push(initScript);
|
|
426
424
|
await this._delegate.addInitScript(initScript);
|
|
427
425
|
}
|
|
@@ -449,110 +447,115 @@ class Page extends _instrumentation.SdkObject {
|
|
|
449
447
|
await this.mainFrame().rafrafTimeout(timeout);
|
|
450
448
|
return await this._screenshotter.screenshotPage(progress, options || {});
|
|
451
449
|
};
|
|
452
|
-
const comparator = (0,
|
|
453
|
-
const controller = new
|
|
454
|
-
if (!options.expected && options.isNot)
|
|
455
|
-
errorMessage: '"not" matcher requires expected result'
|
|
456
|
-
};
|
|
450
|
+
const comparator = (0, import_comparators.getComparator)("image/png");
|
|
451
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
452
|
+
if (!options.expected && options.isNot)
|
|
453
|
+
return { errorMessage: '"not" matcher requires expected result' };
|
|
457
454
|
try {
|
|
458
|
-
const format = (0,
|
|
459
|
-
if (format !==
|
|
455
|
+
const format = (0, import_screenshotter.validateScreenshotOptions)(options || {});
|
|
456
|
+
if (format !== "png")
|
|
457
|
+
throw new Error("Only PNG screenshots are supported");
|
|
460
458
|
} catch (error) {
|
|
461
|
-
return {
|
|
462
|
-
errorMessage: error.message
|
|
463
|
-
};
|
|
459
|
+
return { errorMessage: error.message };
|
|
464
460
|
}
|
|
465
|
-
let intermediateResult =
|
|
461
|
+
let intermediateResult = void 0;
|
|
466
462
|
const areEqualScreenshots = (actual, expected, previous) => {
|
|
467
|
-
const comparatorResult = actual && expected ? comparator(actual, expected, options) :
|
|
468
|
-
if (comparatorResult !==
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
diff: comparatorResult.diff,
|
|
472
|
-
actual,
|
|
473
|
-
previous
|
|
474
|
-
};
|
|
463
|
+
const comparatorResult = actual && expected ? comparator(actual, expected, options) : void 0;
|
|
464
|
+
if (comparatorResult !== void 0 && !!comparatorResult === !!options.isNot)
|
|
465
|
+
return true;
|
|
466
|
+
if (comparatorResult)
|
|
467
|
+
intermediateResult = { errorMessage: comparatorResult.errorMessage, diff: comparatorResult.diff, actual, previous };
|
|
475
468
|
return false;
|
|
476
469
|
};
|
|
477
470
|
const callTimeout = this._timeoutSettings.timeout(options);
|
|
478
|
-
return controller.run(async progress => {
|
|
471
|
+
return controller.run(async (progress) => {
|
|
479
472
|
let actual;
|
|
480
473
|
let previous;
|
|
481
474
|
const pollIntervals = [0, 100, 250, 500];
|
|
482
|
-
progress.log(`${metadata.apiName}${callTimeout ? ` with timeout ${callTimeout}ms` :
|
|
483
|
-
if (options.expected)
|
|
475
|
+
progress.log(`${metadata.apiName}${callTimeout ? ` with timeout ${callTimeout}ms` : ""}`);
|
|
476
|
+
if (options.expected)
|
|
477
|
+
progress.log(` verifying given screenshot expectation`);
|
|
478
|
+
else
|
|
479
|
+
progress.log(` generating new stable screenshot expectation`);
|
|
484
480
|
let isFirstIteration = true;
|
|
485
481
|
while (true) {
|
|
486
|
-
var _pollIntervals$shift;
|
|
487
482
|
progress.throwIfAborted();
|
|
488
|
-
if (this.isClosed())
|
|
489
|
-
|
|
490
|
-
|
|
483
|
+
if (this.isClosed())
|
|
484
|
+
throw new Error("The page has closed");
|
|
485
|
+
const screenshotTimeout = pollIntervals.shift() ?? 1e3;
|
|
486
|
+
if (screenshotTimeout)
|
|
487
|
+
progress.log(`waiting ${screenshotTimeout}ms before taking screenshot`);
|
|
491
488
|
previous = actual;
|
|
492
|
-
actual = await rafrafScreenshot(progress, screenshotTimeout).catch(e => {
|
|
489
|
+
actual = await rafrafScreenshot(progress, screenshotTimeout).catch((e) => {
|
|
493
490
|
progress.log(`failed to take screenshot - ` + e.message);
|
|
494
|
-
return
|
|
491
|
+
return void 0;
|
|
495
492
|
});
|
|
496
|
-
if (!actual)
|
|
497
|
-
|
|
493
|
+
if (!actual)
|
|
494
|
+
continue;
|
|
498
495
|
const expectation = options.expected && isFirstIteration ? options.expected : previous;
|
|
499
|
-
if (areEqualScreenshots(actual, expectation, previous))
|
|
500
|
-
|
|
496
|
+
if (areEqualScreenshots(actual, expectation, previous))
|
|
497
|
+
break;
|
|
498
|
+
if (intermediateResult)
|
|
499
|
+
progress.log(intermediateResult.errorMessage);
|
|
501
500
|
isFirstIteration = false;
|
|
502
501
|
}
|
|
503
|
-
if (!isFirstIteration)
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
502
|
+
if (!isFirstIteration)
|
|
503
|
+
progress.log(`captured a stable screenshot`);
|
|
504
|
+
if (!options.expected)
|
|
505
|
+
return { actual };
|
|
507
506
|
if (isFirstIteration) {
|
|
508
507
|
progress.log(`screenshot matched expectation`);
|
|
509
508
|
return {};
|
|
510
509
|
}
|
|
511
|
-
if (areEqualScreenshots(actual, options.expected,
|
|
510
|
+
if (areEqualScreenshots(actual, options.expected, void 0)) {
|
|
512
511
|
progress.log(`screenshot matched expectation`);
|
|
513
512
|
return {};
|
|
514
513
|
}
|
|
515
514
|
throw new Error(intermediateResult.errorMessage);
|
|
516
|
-
}, callTimeout).catch(e => {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
// A: We want user to receive a friendly diff between actual and expected/previous.
|
|
520
|
-
if (js.isJavaScriptErrorInEvaluate(e) || (0, _selectorParser.isInvalidSelectorError)(e)) throw e;
|
|
515
|
+
}, callTimeout).catch((e) => {
|
|
516
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_selectorParser.isInvalidSelectorError)(e))
|
|
517
|
+
throw e;
|
|
521
518
|
let errorMessage = e.message;
|
|
522
|
-
if (e instanceof
|
|
519
|
+
if (e instanceof import_errors.TimeoutError && intermediateResult?.previous)
|
|
520
|
+
errorMessage = `Failed to take two consecutive stable screenshots.`;
|
|
523
521
|
return {
|
|
524
|
-
log: (0,
|
|
522
|
+
log: (0, import_callLog.compressCallLog)(e.message ? [...metadata.log, e.message] : metadata.log),
|
|
525
523
|
...intermediateResult,
|
|
526
524
|
errorMessage,
|
|
527
|
-
timedOut: e instanceof
|
|
525
|
+
timedOut: e instanceof import_errors.TimeoutError
|
|
528
526
|
};
|
|
529
527
|
});
|
|
530
528
|
}
|
|
531
529
|
async screenshot(metadata, options = {}) {
|
|
532
|
-
const controller = new
|
|
533
|
-
return controller.run(
|
|
530
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
531
|
+
return controller.run(
|
|
532
|
+
(progress) => this._screenshotter.screenshotPage(progress, options),
|
|
533
|
+
this._timeoutSettings.timeout(options)
|
|
534
|
+
);
|
|
534
535
|
}
|
|
535
536
|
async close(metadata, options = {}) {
|
|
536
|
-
if (this._closedState ===
|
|
537
|
-
|
|
537
|
+
if (this._closedState === "closed")
|
|
538
|
+
return;
|
|
539
|
+
if (options.reason)
|
|
540
|
+
this._closeReason = options.reason;
|
|
538
541
|
const runBeforeUnload = !!options.runBeforeUnload;
|
|
539
|
-
if (this._closedState !==
|
|
540
|
-
this._closedState =
|
|
541
|
-
|
|
542
|
-
// while we are trying to close the page.
|
|
543
|
-
await this._delegate.closePage(runBeforeUnload).catch(e => _debugLogger.debugLogger.log('error', e));
|
|
542
|
+
if (this._closedState !== "closing") {
|
|
543
|
+
this._closedState = "closing";
|
|
544
|
+
await this._delegate.closePage(runBeforeUnload).catch((e) => import_debugLogger.debugLogger.log("error", e));
|
|
544
545
|
}
|
|
545
|
-
if (!runBeforeUnload)
|
|
546
|
-
|
|
546
|
+
if (!runBeforeUnload)
|
|
547
|
+
await this._closedPromise;
|
|
548
|
+
if (this._ownedContext)
|
|
549
|
+
await this._ownedContext.close(options);
|
|
547
550
|
}
|
|
548
551
|
isClosed() {
|
|
549
|
-
return this._closedState ===
|
|
552
|
+
return this._closedState === "closed";
|
|
550
553
|
}
|
|
551
554
|
hasCrashed() {
|
|
552
555
|
return this._crashed;
|
|
553
556
|
}
|
|
554
557
|
isClosedOrClosingOrCrashed() {
|
|
555
|
-
return this._closedState !==
|
|
558
|
+
return this._closedState !== "open" || this._crashed;
|
|
556
559
|
}
|
|
557
560
|
_addWorker(workerId, worker) {
|
|
558
561
|
this._workers.set(workerId, worker);
|
|
@@ -560,7 +563,8 @@ class Page extends _instrumentation.SdkObject {
|
|
|
560
563
|
}
|
|
561
564
|
_removeWorker(workerId) {
|
|
562
565
|
const worker = this._workers.get(workerId);
|
|
563
|
-
if (!worker)
|
|
566
|
+
if (!worker)
|
|
567
|
+
return;
|
|
564
568
|
worker.didClose();
|
|
565
569
|
this._workers.delete(workerId);
|
|
566
570
|
}
|
|
@@ -580,33 +584,35 @@ class Page extends _instrumentation.SdkObject {
|
|
|
580
584
|
frameNavigatedToNewDocument(frame) {
|
|
581
585
|
this.emit(Page.Events.InternalFrameNavigatedToNewDocument, frame);
|
|
582
586
|
const origin = frame.origin();
|
|
583
|
-
if (origin)
|
|
587
|
+
if (origin)
|
|
588
|
+
this._browserContext.addVisitedOrigin(origin);
|
|
584
589
|
}
|
|
585
590
|
getBinding(name) {
|
|
586
591
|
return this._pageBindings.get(name) || this._browserContext._pageBindings.get(name);
|
|
587
592
|
}
|
|
588
593
|
setScreencastOptions(options) {
|
|
589
|
-
this._delegate.setScreencastOptions(options).catch(e =>
|
|
594
|
+
this._delegate.setScreencastOptions(options).catch((e) => import_debugLogger.debugLogger.log("error", e));
|
|
590
595
|
this._frameThrottler.setThrottlingEnabled(!!options);
|
|
591
596
|
}
|
|
592
597
|
throttleScreencastFrameAck(ack) {
|
|
593
|
-
// Don't ack immediately, tracing has smart throttling logic that is implemented here.
|
|
594
598
|
this._frameThrottler.ack(ack);
|
|
595
599
|
}
|
|
596
600
|
temporarilyDisableTracingScreencastThrottling() {
|
|
597
601
|
this._frameThrottler.recharge();
|
|
598
602
|
}
|
|
599
603
|
async safeNonStallingEvaluateInAllFrames(expression, world, options = {}) {
|
|
600
|
-
await Promise.all(this.frames().map(async frame => {
|
|
604
|
+
await Promise.all(this.frames().map(async (frame) => {
|
|
601
605
|
try {
|
|
602
606
|
await frame.nonStallingEvaluateInExistingContext(expression, world);
|
|
603
607
|
} catch (e) {
|
|
604
|
-
if (options.throwOnJSErrors && js.isJavaScriptErrorInEvaluate(e))
|
|
608
|
+
if (options.throwOnJSErrors && js.isJavaScriptErrorInEvaluate(e))
|
|
609
|
+
throw e;
|
|
605
610
|
}
|
|
606
611
|
}));
|
|
607
612
|
}
|
|
608
613
|
async hideHighlight() {
|
|
609
|
-
await Promise.all(this.frames().map(frame => frame.hideHighlight().catch(() => {
|
|
614
|
+
await Promise.all(this.frames().map((frame) => frame.hideHighlight().catch(() => {
|
|
615
|
+
})));
|
|
610
616
|
}
|
|
611
617
|
markAsServerSideOnly() {
|
|
612
618
|
this._isServerSideOnly = true;
|
|
@@ -615,35 +621,23 @@ class Page extends _instrumentation.SdkObject {
|
|
|
615
621
|
return [...this._browserContext._pageBindings.values(), ...this._pageBindings.values()];
|
|
616
622
|
}
|
|
617
623
|
}
|
|
618
|
-
|
|
619
|
-
Page.Events = {
|
|
620
|
-
Close: 'close',
|
|
621
|
-
Crash: 'crash',
|
|
622
|
-
Download: 'download',
|
|
623
|
-
FileChooser: 'filechooser',
|
|
624
|
-
FrameAttached: 'frameattached',
|
|
625
|
-
FrameDetached: 'framedetached',
|
|
626
|
-
InternalFrameNavigatedToNewDocument: 'internalframenavigatedtonewdocument',
|
|
627
|
-
LocatorHandlerTriggered: 'locatorhandlertriggered',
|
|
628
|
-
ScreencastFrame: 'screencastframe',
|
|
629
|
-
Video: 'video',
|
|
630
|
-
WebSocket: 'websocket',
|
|
631
|
-
Worker: 'worker'
|
|
632
|
-
};
|
|
633
|
-
class Worker extends _instrumentation.SdkObject {
|
|
624
|
+
class Worker extends import_instrumentation.SdkObject {
|
|
634
625
|
constructor(parent, url) {
|
|
635
|
-
super(parent,
|
|
636
|
-
this._url = void 0;
|
|
637
|
-
this._executionContextPromise = void 0;
|
|
638
|
-
this._executionContextCallback = void 0;
|
|
626
|
+
super(parent, "worker");
|
|
639
627
|
this._existingExecutionContext = null;
|
|
640
|
-
this.openScope = new
|
|
628
|
+
this.openScope = new import_utils.LongStandingScope();
|
|
641
629
|
this._url = url;
|
|
642
|
-
this._executionContextCallback = () => {
|
|
643
|
-
|
|
630
|
+
this._executionContextCallback = () => {
|
|
631
|
+
};
|
|
632
|
+
this._executionContextPromise = new Promise((x) => this._executionContextCallback = x);
|
|
633
|
+
}
|
|
634
|
+
static {
|
|
635
|
+
this.Events = {
|
|
636
|
+
Close: "close"
|
|
637
|
+
};
|
|
644
638
|
}
|
|
645
639
|
_createExecutionContext(delegate) {
|
|
646
|
-
this._existingExecutionContext = new js.ExecutionContext(this, delegate,
|
|
640
|
+
this._existingExecutionContext = new js.ExecutionContext(this, delegate, "worker");
|
|
647
641
|
this._executionContextCallback(this._existingExecutionContext);
|
|
648
642
|
return this._existingExecutionContext;
|
|
649
643
|
}
|
|
@@ -651,177 +645,81 @@ class Worker extends _instrumentation.SdkObject {
|
|
|
651
645
|
return this._url;
|
|
652
646
|
}
|
|
653
647
|
didClose() {
|
|
654
|
-
if (this._existingExecutionContext)
|
|
648
|
+
if (this._existingExecutionContext)
|
|
649
|
+
this._existingExecutionContext.contextDestroyed("Worker was closed");
|
|
655
650
|
this.emit(Worker.Events.Close, this);
|
|
656
|
-
this.openScope.close(new Error(
|
|
651
|
+
this.openScope.close(new Error("Worker closed"));
|
|
657
652
|
}
|
|
658
653
|
async evaluateExpression(expression, isFunction, arg, isolatedContext) {
|
|
659
654
|
let context = await this._executionContextPromise;
|
|
660
655
|
if (context.constructor.name === "FrameExecutionContext") {
|
|
661
656
|
const frame = context.frame;
|
|
662
657
|
if (frame) {
|
|
663
|
-
if (isolatedContext) context = await frame._utilityContext();
|
|
658
|
+
if (isolatedContext) context = await frame._utilityContext();
|
|
659
|
+
else if (!isolatedContext) context = await frame._mainContext();
|
|
664
660
|
}
|
|
665
661
|
}
|
|
666
|
-
return js.evaluateExpression(context, expression, {
|
|
667
|
-
returnByValue: true,
|
|
668
|
-
isFunction
|
|
669
|
-
}, arg);
|
|
662
|
+
return js.evaluateExpression(context, expression, { returnByValue: true, isFunction }, arg);
|
|
670
663
|
}
|
|
671
664
|
async evaluateExpressionHandle(expression, isFunction, arg, isolatedContext) {
|
|
672
665
|
let context = await this._executionContextPromise;
|
|
673
666
|
if (this._context.constructor.name === "FrameExecutionContext") {
|
|
674
667
|
const frame = this._context.frame;
|
|
675
668
|
if (frame) {
|
|
676
|
-
if (isolatedContext) context = await frame._utilityContext();
|
|
669
|
+
if (isolatedContext) context = await frame._utilityContext();
|
|
670
|
+
else if (!isolatedContext) context = await frame._mainContext();
|
|
677
671
|
}
|
|
678
672
|
}
|
|
679
|
-
return js.evaluateExpression(context, expression, {
|
|
680
|
-
returnByValue: false,
|
|
681
|
-
isFunction
|
|
682
|
-
}, arg);
|
|
673
|
+
return js.evaluateExpression(context, expression, { returnByValue: false, isFunction }, arg);
|
|
683
674
|
}
|
|
684
675
|
}
|
|
685
|
-
exports.Worker = Worker;
|
|
686
|
-
Worker.Events = {
|
|
687
|
-
Close: 'close'
|
|
688
|
-
};
|
|
689
676
|
class PageBinding {
|
|
690
677
|
constructor(name, playwrightFunction, needsHandle) {
|
|
691
|
-
this.name = void 0;
|
|
692
|
-
this.playwrightFunction = void 0;
|
|
693
|
-
this.needsHandle = void 0;
|
|
694
|
-
this.internal = void 0;
|
|
695
|
-
this.source = void 0;
|
|
696
678
|
this.name = name;
|
|
697
679
|
this.playwrightFunction = playwrightFunction;
|
|
698
|
-
this.source =
|
|
680
|
+
this.source = (0, import_pageBinding.createPageBindingScript)(name, needsHandle);
|
|
699
681
|
this.needsHandle = needsHandle;
|
|
700
682
|
}
|
|
701
683
|
static async dispatch(page, payload, context) {
|
|
702
|
-
const {
|
|
703
|
-
name,
|
|
704
|
-
seq,
|
|
705
|
-
serializedArgs
|
|
706
|
-
} = JSON.parse(payload);
|
|
684
|
+
const { name, seq, serializedArgs } = JSON.parse(payload);
|
|
707
685
|
try {
|
|
708
|
-
(0,
|
|
686
|
+
(0, import_utils.assert)(context.world);
|
|
709
687
|
const binding = page.getBinding(name);
|
|
710
|
-
if (!binding)
|
|
688
|
+
if (!binding)
|
|
689
|
+
throw new Error(`Function "${name}" is not exposed`);
|
|
711
690
|
let result;
|
|
712
691
|
if (binding.needsHandle) {
|
|
713
|
-
const handle = await context.evaluateHandle(
|
|
714
|
-
|
|
715
|
-
seq
|
|
716
|
-
}).catch(e => null);
|
|
717
|
-
result = await binding.playwrightFunction({
|
|
718
|
-
frame: context.frame,
|
|
719
|
-
page,
|
|
720
|
-
context: page._browserContext
|
|
721
|
-
}, handle);
|
|
692
|
+
const handle = await context.evaluateHandle(import_pageBinding.takeBindingHandle, { name, seq }).catch((e) => null);
|
|
693
|
+
result = await binding.playwrightFunction({ frame: context.frame, page, context: page._browserContext }, handle);
|
|
722
694
|
} else {
|
|
723
|
-
if (!Array.isArray(serializedArgs))
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
page,
|
|
728
|
-
context: page._browserContext
|
|
729
|
-
}, ...args);
|
|
695
|
+
if (!Array.isArray(serializedArgs))
|
|
696
|
+
throw new Error(`serializedArgs is not an array. This can happen when Array.prototype.toJSON is defined incorrectly`);
|
|
697
|
+
const args = serializedArgs.map((a) => js.parseEvaluationResultValue(a));
|
|
698
|
+
result = await binding.playwrightFunction({ frame: context.frame, page, context: page._browserContext }, ...args);
|
|
730
699
|
}
|
|
731
|
-
context.evaluate(
|
|
732
|
-
name,
|
|
733
|
-
seq,
|
|
734
|
-
result
|
|
735
|
-
}).catch(e => _debugLogger.debugLogger.log('error', e));
|
|
700
|
+
context.evaluate(import_pageBinding.deliverBindingResult, { name, seq, result }).catch((e) => import_debugLogger.debugLogger.log("error", e));
|
|
736
701
|
} catch (error) {
|
|
737
|
-
context.evaluate(
|
|
738
|
-
name,
|
|
739
|
-
seq,
|
|
740
|
-
error
|
|
741
|
-
}).catch(e => _debugLogger.debugLogger.log('error', e));
|
|
742
|
-
}
|
|
743
|
-
function takeHandle(arg) {
|
|
744
|
-
const handle = globalThis[arg.name]['handles'].get(arg.seq);
|
|
745
|
-
globalThis[arg.name]['handles'].delete(arg.seq);
|
|
746
|
-
return handle;
|
|
747
|
-
}
|
|
748
|
-
function deliverResult(arg) {
|
|
749
|
-
const callbacks = globalThis[arg.name]['callbacks'];
|
|
750
|
-
if ('error' in arg) callbacks.get(arg.seq).reject(arg.error);else callbacks.get(arg.seq).resolve(arg.result);
|
|
751
|
-
callbacks.delete(arg.seq);
|
|
702
|
+
context.evaluate(import_pageBinding.deliverBindingResult, { name, seq, error }).catch((e) => import_debugLogger.debugLogger.log("error", e));
|
|
752
703
|
}
|
|
753
704
|
}
|
|
754
705
|
}
|
|
755
|
-
exports.PageBinding = PageBinding;
|
|
756
|
-
function addPageBinding(bindingName, needsHandle, utilityScriptSerializers) {
|
|
757
|
-
const binding = globalThis[bindingName];
|
|
758
|
-
if (binding && binding.toString().startsWith("(...args) => {")) return;
|
|
759
|
-
globalThis[bindingName] = (...args) => {
|
|
760
|
-
const me = globalThis[bindingName];
|
|
761
|
-
if (needsHandle && args.slice(1).some(arg => arg !== undefined)) throw new Error(`exposeBindingHandle supports a single argument, ${args.length} received`);
|
|
762
|
-
let callbacks = me['callbacks'];
|
|
763
|
-
if (!callbacks) {
|
|
764
|
-
callbacks = new Map();
|
|
765
|
-
me['callbacks'] = callbacks;
|
|
766
|
-
}
|
|
767
|
-
const seq = (me['lastSeq'] || 0) + 1;
|
|
768
|
-
me['lastSeq'] = seq;
|
|
769
|
-
let handles = me['handles'];
|
|
770
|
-
if (!handles) {
|
|
771
|
-
handles = new Map();
|
|
772
|
-
me['handles'] = handles;
|
|
773
|
-
}
|
|
774
|
-
const promise = new Promise((resolve, reject) => callbacks.set(seq, {
|
|
775
|
-
resolve,
|
|
776
|
-
reject
|
|
777
|
-
}));
|
|
778
|
-
let payload;
|
|
779
|
-
if (needsHandle) {
|
|
780
|
-
handles.set(seq, args[0]);
|
|
781
|
-
payload = {
|
|
782
|
-
name: bindingName,
|
|
783
|
-
seq
|
|
784
|
-
};
|
|
785
|
-
} else {
|
|
786
|
-
const serializedArgs = [];
|
|
787
|
-
for (let i = 0; i < args.length; i++) {
|
|
788
|
-
serializedArgs[i] = utilityScriptSerializers.serializeAsCallArgument(args[i], v => {
|
|
789
|
-
return {
|
|
790
|
-
fallThrough: v
|
|
791
|
-
};
|
|
792
|
-
});
|
|
793
|
-
}
|
|
794
|
-
payload = {
|
|
795
|
-
name: bindingName,
|
|
796
|
-
seq,
|
|
797
|
-
serializedArgs
|
|
798
|
-
};
|
|
799
|
-
}
|
|
800
|
-
binding(JSON.stringify(payload));
|
|
801
|
-
return promise;
|
|
802
|
-
};
|
|
803
|
-
}
|
|
804
706
|
class InitScript {
|
|
805
707
|
constructor(source, internal, name) {
|
|
806
|
-
|
|
807
|
-
this.internal = void 0;
|
|
808
|
-
this.name = void 0;
|
|
809
|
-
const guid = (0, _crypto.createGuid)();
|
|
708
|
+
const guid = (0, import_crypto.createGuid)();
|
|
810
709
|
this.source = `(() => { ${source} })();`;
|
|
811
710
|
this.internal = !!internal;
|
|
812
711
|
this.name = name;
|
|
813
712
|
}
|
|
814
713
|
}
|
|
815
|
-
|
|
714
|
+
const kBuiltinsScript = new InitScript(
|
|
715
|
+
`(${import_builtins.builtins})()`,
|
|
716
|
+
true
|
|
717
|
+
/* internal */
|
|
718
|
+
);
|
|
816
719
|
class FrameThrottler {
|
|
817
720
|
constructor(nonThrottledFrames, defaultInterval, throttlingInterval) {
|
|
818
721
|
this._acks = [];
|
|
819
|
-
this._defaultInterval = void 0;
|
|
820
|
-
this._throttlingInterval = void 0;
|
|
821
|
-
this._nonThrottledFrames = void 0;
|
|
822
|
-
this._budget = void 0;
|
|
823
722
|
this._throttlingEnabled = false;
|
|
824
|
-
this._timeoutId = void 0;
|
|
825
723
|
this._nonThrottledFrames = nonThrottledFrames;
|
|
826
724
|
this._budget = nonThrottledFrames;
|
|
827
725
|
this._defaultInterval = defaultInterval;
|
|
@@ -831,15 +729,15 @@ class FrameThrottler {
|
|
|
831
729
|
dispose() {
|
|
832
730
|
if (this._timeoutId) {
|
|
833
731
|
clearTimeout(this._timeoutId);
|
|
834
|
-
this._timeoutId =
|
|
732
|
+
this._timeoutId = void 0;
|
|
835
733
|
}
|
|
836
734
|
}
|
|
837
735
|
setThrottlingEnabled(enabled) {
|
|
838
736
|
this._throttlingEnabled = enabled;
|
|
839
737
|
}
|
|
840
738
|
recharge() {
|
|
841
|
-
|
|
842
|
-
|
|
739
|
+
for (const ack of this._acks)
|
|
740
|
+
ack();
|
|
843
741
|
this._acks = [];
|
|
844
742
|
this._budget = this._nonThrottledFrames;
|
|
845
743
|
if (this._timeoutId) {
|
|
@@ -849,7 +747,6 @@ class FrameThrottler {
|
|
|
849
747
|
}
|
|
850
748
|
ack(ack) {
|
|
851
749
|
if (!this._timeoutId) {
|
|
852
|
-
// Already disposed.
|
|
853
750
|
ack();
|
|
854
751
|
return;
|
|
855
752
|
}
|
|
@@ -862,11 +759,17 @@ class FrameThrottler {
|
|
|
862
759
|
ack();
|
|
863
760
|
}
|
|
864
761
|
if (this._throttlingEnabled && this._budget <= 0) {
|
|
865
|
-
// Non-throttled frame budget is exceeded. Next ack will be throttled.
|
|
866
762
|
this._timeoutId = setTimeout(() => this._tick(), this._throttlingInterval);
|
|
867
763
|
} else {
|
|
868
|
-
// Either not throttling, or still under budget. Next ack will be after the default timeout.
|
|
869
764
|
this._timeoutId = setTimeout(() => this._tick(), this._defaultInterval);
|
|
870
765
|
}
|
|
871
766
|
}
|
|
872
|
-
}
|
|
767
|
+
}
|
|
768
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
769
|
+
0 && (module.exports = {
|
|
770
|
+
InitScript,
|
|
771
|
+
Page,
|
|
772
|
+
PageBinding,
|
|
773
|
+
Worker,
|
|
774
|
+
kBuiltinsScript
|
|
775
|
+
});
|