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/frames.js
CHANGED
|
@@ -1,82 +1,86 @@
|
|
|
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 frames_exports = {};
|
|
30
|
+
__export(frames_exports, {
|
|
31
|
+
Frame: () => Frame,
|
|
32
|
+
FrameManager: () => FrameManager,
|
|
33
|
+
NavigationAbortedError: () => NavigationAbortedError
|
|
5
34
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var js =
|
|
18
|
-
var network =
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var types =
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
30
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
31
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
32
|
-
// undetected-undetected_playwright-patch - custom imports
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Copyright 2017 Google Inc. All rights reserved.
|
|
36
|
-
* Modifications copyright (c) Microsoft Corporation.
|
|
37
|
-
*
|
|
38
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
39
|
-
* you may not use this file except in compliance with the License.
|
|
40
|
-
* You may obtain a copy of the License at
|
|
41
|
-
*
|
|
42
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
43
|
-
*
|
|
44
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
45
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
46
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
47
|
-
* See the License for the specific language governing permissions and
|
|
48
|
-
* limitations under the License.
|
|
49
|
-
*/
|
|
50
|
-
|
|
35
|
+
module.exports = __toCommonJS(frames_exports);
|
|
36
|
+
var import_crExecutionContext = require("./chromium/crExecutionContext");
|
|
37
|
+
var import_dom = require("./dom");
|
|
38
|
+
var import_crypto = __toESM(require("crypto"));
|
|
39
|
+
var import_browserContext = require("./browserContext");
|
|
40
|
+
var dom = __toESM(require("./dom"));
|
|
41
|
+
var import_errors = require("./errors");
|
|
42
|
+
var import_fileUploadUtils = require("./fileUploadUtils");
|
|
43
|
+
var import_frameSelectors = require("./frameSelectors");
|
|
44
|
+
var import_helper = require("./helper");
|
|
45
|
+
var import_instrumentation = require("./instrumentation");
|
|
46
|
+
var js = __toESM(require("./javascript"));
|
|
47
|
+
var network = __toESM(require("./network"));
|
|
48
|
+
var import_page = require("./page");
|
|
49
|
+
var import_progress = require("./progress");
|
|
50
|
+
var types = __toESM(require("./types"));
|
|
51
|
+
var import_utils = require("../utils");
|
|
52
|
+
var import_protocolError = require("./protocolError");
|
|
53
|
+
var import_debugLogger = require("./utils/debugLogger");
|
|
54
|
+
var import_eventsHelper = require("./utils/eventsHelper");
|
|
55
|
+
var import_selectorParser = require("../utils/isomorphic/selectorParser");
|
|
56
|
+
var import_manualPromise = require("../utils/isomorphic/manualPromise");
|
|
57
|
+
var import_callLog = require("./callLog");
|
|
51
58
|
class NavigationAbortedError extends Error {
|
|
52
59
|
constructor(documentId, message) {
|
|
53
60
|
super(message);
|
|
54
|
-
this.documentId = void 0;
|
|
55
61
|
this.documentId = documentId;
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
|
-
|
|
59
|
-
const kDummyFrameId = '<dummy>';
|
|
64
|
+
const kDummyFrameId = "<dummy>";
|
|
60
65
|
class FrameManager {
|
|
61
66
|
constructor(page) {
|
|
62
|
-
this.
|
|
63
|
-
this.
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
66
|
-
this.
|
|
67
|
-
this._webSockets = new Map();
|
|
68
|
-
this._openedDialogs = new Set();
|
|
67
|
+
this._frames = /* @__PURE__ */ new Map();
|
|
68
|
+
this._consoleMessageTags = /* @__PURE__ */ new Map();
|
|
69
|
+
this._signalBarriers = /* @__PURE__ */ new Set();
|
|
70
|
+
this._webSockets = /* @__PURE__ */ new Map();
|
|
71
|
+
this._openedDialogs = /* @__PURE__ */ new Set();
|
|
69
72
|
this._closeAllOpeningDialogs = false;
|
|
70
73
|
this._page = page;
|
|
71
|
-
this._mainFrame =
|
|
74
|
+
this._mainFrame = void 0;
|
|
72
75
|
}
|
|
73
76
|
createDummyMainFrameIfNeeded() {
|
|
74
|
-
if (!this._mainFrame)
|
|
77
|
+
if (!this._mainFrame)
|
|
78
|
+
this.frameAttached(kDummyFrameId, null);
|
|
75
79
|
}
|
|
76
80
|
dispose() {
|
|
77
81
|
for (const frame of this._frames.values()) {
|
|
78
82
|
frame._stopNetworkIdleTimer();
|
|
79
|
-
frame._invalidateNonStallingEvaluations(
|
|
83
|
+
frame._invalidateNonStallingEvaluations("Target crashed");
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
86
|
mainFrame() {
|
|
@@ -88,7 +92,8 @@ class FrameManager {
|
|
|
88
92
|
return frames;
|
|
89
93
|
function collect(frame) {
|
|
90
94
|
frames.push(frame);
|
|
91
|
-
for (const subframe of frame.childFrames())
|
|
95
|
+
for (const subframe of frame.childFrames())
|
|
96
|
+
collect(subframe);
|
|
92
97
|
}
|
|
93
98
|
}
|
|
94
99
|
frame(frameId) {
|
|
@@ -98,55 +103,55 @@ class FrameManager {
|
|
|
98
103
|
const parentFrame = parentFrameId ? this._frames.get(parentFrameId) : null;
|
|
99
104
|
if (!parentFrame) {
|
|
100
105
|
if (this._mainFrame) {
|
|
101
|
-
// Update frame id to retain frame identity on cross-process navigation.
|
|
102
106
|
this._frames.delete(this._mainFrame._id);
|
|
103
107
|
this._mainFrame._id = frameId;
|
|
104
108
|
} else {
|
|
105
|
-
(0,
|
|
109
|
+
(0, import_utils.assert)(!this._frames.has(frameId));
|
|
106
110
|
this._mainFrame = new Frame(this._page, frameId, parentFrame);
|
|
107
111
|
}
|
|
108
112
|
this._frames.set(frameId, this._mainFrame);
|
|
109
113
|
return this._mainFrame;
|
|
110
114
|
} else {
|
|
111
|
-
(0,
|
|
115
|
+
(0, import_utils.assert)(!this._frames.has(frameId));
|
|
112
116
|
const frame = new Frame(this._page, frameId, parentFrame);
|
|
113
117
|
this._frames.set(frameId, frame);
|
|
114
|
-
this._page.emit(
|
|
118
|
+
this._page.emit(import_page.Page.Events.FrameAttached, frame);
|
|
115
119
|
return frame;
|
|
116
120
|
}
|
|
117
121
|
}
|
|
118
122
|
async waitForSignalsCreatedBy(progress, waitAfter, action) {
|
|
119
|
-
if (!waitAfter)
|
|
123
|
+
if (!waitAfter)
|
|
124
|
+
return action();
|
|
120
125
|
const barrier = new SignalBarrier(progress);
|
|
121
126
|
this._signalBarriers.add(barrier);
|
|
122
|
-
if (progress)
|
|
127
|
+
if (progress)
|
|
128
|
+
progress.cleanupWhenAborted(() => this._signalBarriers.delete(barrier));
|
|
123
129
|
const result = await action();
|
|
124
130
|
await this._page._delegate.inputActionEpilogue();
|
|
125
131
|
await barrier.waitFor();
|
|
126
132
|
this._signalBarriers.delete(barrier);
|
|
127
|
-
|
|
128
|
-
await new Promise((0, _utils.makeWaitForNextTask)());
|
|
133
|
+
await new Promise((0, import_utils.makeWaitForNextTask)());
|
|
129
134
|
return result;
|
|
130
135
|
}
|
|
131
136
|
frameWillPotentiallyRequestNavigation() {
|
|
132
|
-
for (const barrier of this._signalBarriers)
|
|
137
|
+
for (const barrier of this._signalBarriers)
|
|
138
|
+
barrier.retain();
|
|
133
139
|
}
|
|
134
140
|
frameDidPotentiallyRequestNavigation() {
|
|
135
|
-
for (const barrier of this._signalBarriers)
|
|
141
|
+
for (const barrier of this._signalBarriers)
|
|
142
|
+
barrier.release();
|
|
136
143
|
}
|
|
137
144
|
frameRequestedNavigation(frameId, documentId) {
|
|
138
145
|
const frame = this._frames.get(frameId);
|
|
139
|
-
if (!frame)
|
|
140
|
-
|
|
146
|
+
if (!frame)
|
|
147
|
+
return;
|
|
148
|
+
for (const barrier of this._signalBarriers)
|
|
149
|
+
barrier.addFrameNavigation(frame);
|
|
141
150
|
if (frame.pendingDocument() && frame.pendingDocument().documentId === documentId) {
|
|
142
|
-
// Do not override request with undefined.
|
|
143
151
|
return;
|
|
144
152
|
}
|
|
145
|
-
const request = documentId ? Array.from(frame._inflightRequests).find(
|
|
146
|
-
frame.setPendingDocument({
|
|
147
|
-
documentId,
|
|
148
|
-
request
|
|
149
|
-
});
|
|
153
|
+
const request = documentId ? Array.from(frame._inflightRequests).find((request2) => request2._documentId === documentId) : void 0;
|
|
154
|
+
frame.setPendingDocument({ documentId, request });
|
|
150
155
|
}
|
|
151
156
|
frameCommittedNewDocumentNavigation(frameId, url, name, documentId, initial) {
|
|
152
157
|
const frame = this._frames.get(frameId);
|
|
@@ -157,69 +162,47 @@ class FrameManager {
|
|
|
157
162
|
let keepPending;
|
|
158
163
|
const pendingDocument = frame.pendingDocument();
|
|
159
164
|
if (pendingDocument) {
|
|
160
|
-
if (pendingDocument.documentId ===
|
|
161
|
-
// Pending with unknown documentId - assume it is the one being committed.
|
|
165
|
+
if (pendingDocument.documentId === void 0) {
|
|
162
166
|
pendingDocument.documentId = documentId;
|
|
163
167
|
}
|
|
164
168
|
if (pendingDocument.documentId === documentId) {
|
|
165
|
-
// Committing a pending document.
|
|
166
169
|
frame._currentDocument = pendingDocument;
|
|
167
170
|
} else {
|
|
168
|
-
// Sometimes, we already have a new pending when the old one commits.
|
|
169
|
-
// An example would be Chromium error page followed by a new navigation request,
|
|
170
|
-
// where the error page commit arrives after Network.requestWillBeSent for the
|
|
171
|
-
// new navigation.
|
|
172
|
-
// We commit, but keep the pending request since it's not done yet.
|
|
173
171
|
keepPending = pendingDocument;
|
|
174
|
-
frame._currentDocument = {
|
|
175
|
-
documentId,
|
|
176
|
-
request: undefined
|
|
177
|
-
};
|
|
172
|
+
frame._currentDocument = { documentId, request: void 0 };
|
|
178
173
|
}
|
|
179
|
-
frame.setPendingDocument(
|
|
174
|
+
frame.setPendingDocument(void 0);
|
|
180
175
|
} else {
|
|
181
|
-
|
|
182
|
-
frame._currentDocument = {
|
|
183
|
-
documentId,
|
|
184
|
-
request: undefined
|
|
185
|
-
};
|
|
176
|
+
frame._currentDocument = { documentId, request: void 0 };
|
|
186
177
|
}
|
|
187
178
|
frame._onClearLifecycle();
|
|
188
|
-
const navigationEvent = {
|
|
189
|
-
url,
|
|
190
|
-
name,
|
|
191
|
-
newDocument: frame._currentDocument,
|
|
192
|
-
isPublic: true
|
|
193
|
-
};
|
|
179
|
+
const navigationEvent = { url, name, newDocument: frame._currentDocument, isPublic: true };
|
|
194
180
|
this._fireInternalFrameNavigation(frame, navigationEvent);
|
|
195
181
|
if (!initial) {
|
|
196
|
-
|
|
182
|
+
import_debugLogger.debugLogger.log("api", ` navigated to "${url}"`);
|
|
197
183
|
this._page.frameNavigatedToNewDocument(frame);
|
|
198
184
|
}
|
|
199
|
-
// Restore pending if any - see comments above about keepPending.
|
|
200
185
|
frame.setPendingDocument(keepPending);
|
|
201
186
|
}
|
|
202
187
|
frameCommittedSameDocumentNavigation(frameId, url) {
|
|
203
188
|
const frame = this._frames.get(frameId);
|
|
204
|
-
if (!frame)
|
|
189
|
+
if (!frame)
|
|
190
|
+
return;
|
|
205
191
|
const pending = frame.pendingDocument();
|
|
206
|
-
if (pending && pending.documentId ===
|
|
207
|
-
|
|
208
|
-
frame.setPendingDocument(undefined);
|
|
192
|
+
if (pending && pending.documentId === void 0 && pending.request === void 0) {
|
|
193
|
+
frame.setPendingDocument(void 0);
|
|
209
194
|
}
|
|
210
195
|
frame._url = url;
|
|
211
|
-
const navigationEvent = {
|
|
212
|
-
url,
|
|
213
|
-
name: frame._name,
|
|
214
|
-
isPublic: true
|
|
215
|
-
};
|
|
196
|
+
const navigationEvent = { url, name: frame._name, isPublic: true };
|
|
216
197
|
this._fireInternalFrameNavigation(frame, navigationEvent);
|
|
217
|
-
|
|
198
|
+
import_debugLogger.debugLogger.log("api", ` navigated to "${url}"`);
|
|
218
199
|
}
|
|
219
200
|
frameAbortedNavigation(frameId, errorText, documentId) {
|
|
220
201
|
const frame = this._frames.get(frameId);
|
|
221
|
-
if (!frame || !frame.pendingDocument())
|
|
222
|
-
|
|
202
|
+
if (!frame || !frame.pendingDocument())
|
|
203
|
+
return;
|
|
204
|
+
if (documentId !== void 0 && frame.pendingDocument().documentId !== documentId)
|
|
205
|
+
return;
|
|
223
206
|
const navigationEvent = {
|
|
224
207
|
url: frame._url,
|
|
225
208
|
name: frame._name,
|
|
@@ -227,7 +210,7 @@ class FrameManager {
|
|
|
227
210
|
error: new NavigationAbortedError(documentId, errorText),
|
|
228
211
|
isPublic: !(documentId && frame._redirectedNavigations.has(documentId))
|
|
229
212
|
};
|
|
230
|
-
frame.setPendingDocument(
|
|
213
|
+
frame.setPendingDocument(void 0);
|
|
231
214
|
this._fireInternalFrameNavigation(frame, navigationEvent);
|
|
232
215
|
}
|
|
233
216
|
frameDetached(frameId) {
|
|
@@ -239,104 +222,119 @@ class FrameManager {
|
|
|
239
222
|
}
|
|
240
223
|
frameLifecycleEvent(frameId, event) {
|
|
241
224
|
const frame = this._frames.get(frameId);
|
|
242
|
-
if (frame)
|
|
225
|
+
if (frame)
|
|
226
|
+
frame._onLifecycleEvent(event);
|
|
243
227
|
}
|
|
244
228
|
requestStarted(request, route) {
|
|
245
229
|
const frame = request.frame();
|
|
246
230
|
this._inflightRequestStarted(request);
|
|
247
|
-
if (request._documentId)
|
|
248
|
-
documentId: request._documentId,
|
|
249
|
-
request
|
|
250
|
-
});
|
|
231
|
+
if (request._documentId)
|
|
232
|
+
frame.setPendingDocument({ documentId: request._documentId, request });
|
|
251
233
|
if (request._isFavicon) {
|
|
252
|
-
|
|
253
|
-
|
|
234
|
+
route?.abort("aborted").catch(() => {
|
|
235
|
+
});
|
|
254
236
|
return;
|
|
255
237
|
}
|
|
256
|
-
this._page.emitOnContext(
|
|
238
|
+
this._page.emitOnContext(import_browserContext.BrowserContext.Events.Request, request);
|
|
257
239
|
if (route) {
|
|
258
|
-
var _this$_page$_serverRe, _this$_page, _this$_page$_clientRe, _this$_page2, _this$_page$_browserC, _this$_page$_browserC2;
|
|
259
240
|
const r = new network.Route(request, route);
|
|
260
|
-
if (
|
|
261
|
-
|
|
262
|
-
if (
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
241
|
+
if (this._page._serverRequestInterceptor?.(r, request))
|
|
242
|
+
return;
|
|
243
|
+
if (this._page._clientRequestInterceptor?.(r, request))
|
|
244
|
+
return;
|
|
245
|
+
if (this._page._browserContext._requestInterceptor?.(r, request))
|
|
246
|
+
return;
|
|
247
|
+
r.continue({ isFallback: true }).catch(() => {
|
|
248
|
+
});
|
|
266
249
|
}
|
|
267
250
|
}
|
|
268
251
|
requestReceivedResponse(response) {
|
|
269
|
-
if (response.request()._isFavicon)
|
|
270
|
-
|
|
252
|
+
if (response.request()._isFavicon)
|
|
253
|
+
return;
|
|
254
|
+
this._page.emitOnContext(import_browserContext.BrowserContext.Events.Response, response);
|
|
271
255
|
}
|
|
272
256
|
reportRequestFinished(request, response) {
|
|
273
257
|
this._inflightRequestFinished(request);
|
|
274
|
-
if (request._isFavicon)
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
response
|
|
278
|
-
});
|
|
258
|
+
if (request._isFavicon)
|
|
259
|
+
return;
|
|
260
|
+
this._page.emitOnContext(import_browserContext.BrowserContext.Events.RequestFinished, { request, response });
|
|
279
261
|
}
|
|
280
262
|
requestFailed(request, canceled) {
|
|
281
263
|
const frame = request.frame();
|
|
282
264
|
this._inflightRequestFinished(request);
|
|
283
265
|
if (frame.pendingDocument() && frame.pendingDocument().request === request) {
|
|
284
266
|
let errorText = request.failure().errorText;
|
|
285
|
-
if (canceled)
|
|
267
|
+
if (canceled)
|
|
268
|
+
errorText += "; maybe frame was detached?";
|
|
286
269
|
this.frameAbortedNavigation(frame._id, errorText, frame.pendingDocument().documentId);
|
|
287
270
|
}
|
|
288
|
-
if (request._isFavicon)
|
|
289
|
-
|
|
271
|
+
if (request._isFavicon)
|
|
272
|
+
return;
|
|
273
|
+
this._page.emitOnContext(import_browserContext.BrowserContext.Events.RequestFailed, request);
|
|
290
274
|
}
|
|
291
275
|
dialogDidOpen(dialog) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
if (this._closeAllOpeningDialogs)
|
|
276
|
+
for (const frame of this._frames.values())
|
|
277
|
+
frame._invalidateNonStallingEvaluations("JavaScript dialog interrupted evaluation");
|
|
278
|
+
if (this._closeAllOpeningDialogs)
|
|
279
|
+
dialog.close().then(() => {
|
|
280
|
+
});
|
|
281
|
+
else
|
|
282
|
+
this._openedDialogs.add(dialog);
|
|
295
283
|
}
|
|
296
284
|
dialogWillClose(dialog) {
|
|
297
285
|
this._openedDialogs.delete(dialog);
|
|
298
286
|
}
|
|
299
287
|
async closeOpenDialogs() {
|
|
300
|
-
await Promise.all([...this._openedDialogs].map(dialog => dialog.close())).catch(() => {
|
|
288
|
+
await Promise.all([...this._openedDialogs].map((dialog) => dialog.close())).catch(() => {
|
|
289
|
+
});
|
|
301
290
|
this._openedDialogs.clear();
|
|
302
291
|
}
|
|
303
292
|
setCloseAllOpeningDialogs(closeDialogs) {
|
|
304
293
|
this._closeAllOpeningDialogs = closeDialogs;
|
|
305
294
|
}
|
|
306
295
|
removeChildFramesRecursively(frame) {
|
|
307
|
-
for (const child of frame.childFrames())
|
|
296
|
+
for (const child of frame.childFrames())
|
|
297
|
+
this._removeFramesRecursively(child);
|
|
308
298
|
}
|
|
309
299
|
_removeFramesRecursively(frame) {
|
|
310
300
|
this.removeChildFramesRecursively(frame);
|
|
311
301
|
frame._onDetached();
|
|
312
302
|
this._frames.delete(frame._id);
|
|
313
|
-
if (!this._page.isClosed())
|
|
303
|
+
if (!this._page.isClosed())
|
|
304
|
+
this._page.emit(import_page.Page.Events.FrameDetached, frame);
|
|
314
305
|
}
|
|
315
306
|
_inflightRequestFinished(request) {
|
|
316
307
|
const frame = request.frame();
|
|
317
|
-
if (request._isFavicon)
|
|
318
|
-
|
|
308
|
+
if (request._isFavicon)
|
|
309
|
+
return;
|
|
310
|
+
if (!frame._inflightRequests.has(request))
|
|
311
|
+
return;
|
|
319
312
|
frame._inflightRequests.delete(request);
|
|
320
|
-
if (frame._inflightRequests.size === 0)
|
|
313
|
+
if (frame._inflightRequests.size === 0)
|
|
314
|
+
frame._startNetworkIdleTimer();
|
|
321
315
|
}
|
|
322
316
|
_inflightRequestStarted(request) {
|
|
323
317
|
const frame = request.frame();
|
|
324
|
-
if (request._isFavicon)
|
|
318
|
+
if (request._isFavicon)
|
|
319
|
+
return;
|
|
325
320
|
frame._inflightRequests.add(request);
|
|
326
|
-
if (frame._inflightRequests.size === 1)
|
|
321
|
+
if (frame._inflightRequests.size === 1)
|
|
322
|
+
frame._stopNetworkIdleTimer();
|
|
327
323
|
}
|
|
328
324
|
interceptConsoleMessage(message) {
|
|
329
|
-
if (message.type() !==
|
|
325
|
+
if (message.type() !== "debug")
|
|
326
|
+
return false;
|
|
330
327
|
const tag = message.text();
|
|
331
328
|
const handler = this._consoleMessageTags.get(tag);
|
|
332
|
-
if (!handler)
|
|
329
|
+
if (!handler)
|
|
330
|
+
return false;
|
|
333
331
|
this._consoleMessageTags.delete(tag);
|
|
334
332
|
handler();
|
|
335
333
|
return true;
|
|
336
334
|
}
|
|
337
335
|
clearWebSockets(frame) {
|
|
338
|
-
|
|
339
|
-
|
|
336
|
+
if (frame.parentFrame())
|
|
337
|
+
return;
|
|
340
338
|
this._webSockets.clear();
|
|
341
339
|
}
|
|
342
340
|
onWebSocketCreated(requestId, url) {
|
|
@@ -345,125 +343,131 @@ class FrameManager {
|
|
|
345
343
|
}
|
|
346
344
|
onWebSocketRequest(requestId) {
|
|
347
345
|
const ws = this._webSockets.get(requestId);
|
|
348
|
-
if (ws && ws.markAsNotified())
|
|
346
|
+
if (ws && ws.markAsNotified())
|
|
347
|
+
this._page.emit(import_page.Page.Events.WebSocket, ws);
|
|
349
348
|
}
|
|
350
349
|
onWebSocketResponse(requestId, status, statusText) {
|
|
351
350
|
const ws = this._webSockets.get(requestId);
|
|
352
|
-
if (status < 400)
|
|
353
|
-
|
|
351
|
+
if (status < 400)
|
|
352
|
+
return;
|
|
353
|
+
if (ws)
|
|
354
|
+
ws.error(`${statusText}: ${status}`);
|
|
354
355
|
}
|
|
355
356
|
onWebSocketFrameSent(requestId, opcode, data) {
|
|
356
357
|
const ws = this._webSockets.get(requestId);
|
|
357
|
-
if (ws)
|
|
358
|
+
if (ws)
|
|
359
|
+
ws.frameSent(opcode, data);
|
|
358
360
|
}
|
|
359
361
|
webSocketFrameReceived(requestId, opcode, data) {
|
|
360
362
|
const ws = this._webSockets.get(requestId);
|
|
361
|
-
if (ws)
|
|
363
|
+
if (ws)
|
|
364
|
+
ws.frameReceived(opcode, data);
|
|
362
365
|
}
|
|
363
366
|
webSocketClosed(requestId) {
|
|
364
367
|
const ws = this._webSockets.get(requestId);
|
|
365
|
-
if (ws)
|
|
368
|
+
if (ws)
|
|
369
|
+
ws.closed();
|
|
366
370
|
this._webSockets.delete(requestId);
|
|
367
371
|
}
|
|
368
372
|
webSocketError(requestId, errorMessage) {
|
|
369
373
|
const ws = this._webSockets.get(requestId);
|
|
370
|
-
if (ws)
|
|
374
|
+
if (ws)
|
|
375
|
+
ws.error(errorMessage);
|
|
371
376
|
}
|
|
372
377
|
_fireInternalFrameNavigation(frame, event) {
|
|
373
378
|
frame.emit(Frame.Events.InternalNavigation, event);
|
|
374
379
|
}
|
|
375
380
|
}
|
|
376
|
-
|
|
377
|
-
class Frame extends _instrumentation.SdkObject {
|
|
381
|
+
class Frame extends import_instrumentation.SdkObject {
|
|
378
382
|
constructor(page, id, parentFrame) {
|
|
379
|
-
super(page,
|
|
380
|
-
this.
|
|
381
|
-
this._firedLifecycleEvents = new Set();
|
|
383
|
+
super(page, "frame");
|
|
384
|
+
this._firedLifecycleEvents = /* @__PURE__ */ new Set();
|
|
382
385
|
this._firedNetworkIdleSelf = false;
|
|
383
|
-
this.
|
|
384
|
-
this.
|
|
385
|
-
this.
|
|
386
|
-
this.
|
|
387
|
-
this.
|
|
388
|
-
this._contextData = new Map();
|
|
389
|
-
this._childFrames = new Set();
|
|
390
|
-
this._name = '';
|
|
391
|
-
this._inflightRequests = new Set();
|
|
392
|
-
this._networkIdleTimer = void 0;
|
|
386
|
+
this._url = "";
|
|
387
|
+
this._contextData = /* @__PURE__ */ new Map();
|
|
388
|
+
this._childFrames = /* @__PURE__ */ new Set();
|
|
389
|
+
this._name = "";
|
|
390
|
+
this._inflightRequests = /* @__PURE__ */ new Set();
|
|
393
391
|
this._setContentCounter = 0;
|
|
394
|
-
this._detachedScope = new
|
|
395
|
-
this._raceAgainstEvaluationStallingEventsPromises = new Set();
|
|
396
|
-
this._redirectedNavigations = new Map();
|
|
397
|
-
// documentId -> data
|
|
398
|
-
this.selectors = void 0;
|
|
399
|
-
this._isolatedWorld = void 0;
|
|
400
|
-
this._mainWorld = void 0;
|
|
401
|
-
this._iframeWorld = void 0;
|
|
392
|
+
this._detachedScope = new import_utils.LongStandingScope();
|
|
393
|
+
this._raceAgainstEvaluationStallingEventsPromises = /* @__PURE__ */ new Set();
|
|
394
|
+
this._redirectedNavigations = /* @__PURE__ */ new Map();
|
|
402
395
|
this.attribution.frame = this;
|
|
403
396
|
this._id = id;
|
|
404
397
|
this._page = page;
|
|
405
398
|
this._parentFrame = parentFrame;
|
|
406
|
-
this._currentDocument = {
|
|
407
|
-
|
|
408
|
-
|
|
399
|
+
this._currentDocument = { documentId: void 0, request: void 0 };
|
|
400
|
+
this.selectors = new import_frameSelectors.FrameSelectors(this);
|
|
401
|
+
this._contextData.set("main", { contextPromise: new import_manualPromise.ManualPromise(), context: null });
|
|
402
|
+
this._contextData.set("utility", { contextPromise: new import_manualPromise.ManualPromise(), context: null });
|
|
403
|
+
this._setContext("main", null);
|
|
404
|
+
this._setContext("utility", null);
|
|
405
|
+
if (this._parentFrame)
|
|
406
|
+
this._parentFrame._childFrames.add(this);
|
|
407
|
+
this._firedLifecycleEvents.add("commit");
|
|
408
|
+
if (id !== kDummyFrameId)
|
|
409
|
+
this._startNetworkIdleTimer();
|
|
410
|
+
}
|
|
411
|
+
static {
|
|
412
|
+
this.Events = {
|
|
413
|
+
InternalNavigation: "internalnavigation",
|
|
414
|
+
AddLifecycle: "addlifecycle",
|
|
415
|
+
RemoveLifecycle: "removelifecycle"
|
|
409
416
|
};
|
|
410
|
-
this.selectors = new _frameSelectors.FrameSelectors(this);
|
|
411
|
-
this._contextData.set('main', {
|
|
412
|
-
contextPromise: new _manualPromise.ManualPromise(),
|
|
413
|
-
context: null
|
|
414
|
-
});
|
|
415
|
-
this._contextData.set('utility', {
|
|
416
|
-
contextPromise: new _manualPromise.ManualPromise(),
|
|
417
|
-
context: null
|
|
418
|
-
});
|
|
419
|
-
this._setContext('main', null);
|
|
420
|
-
this._setContext('utility', null);
|
|
421
|
-
if (this._parentFrame) this._parentFrame._childFrames.add(this);
|
|
422
|
-
this._firedLifecycleEvents.add('commit');
|
|
423
|
-
if (id !== kDummyFrameId) this._startNetworkIdleTimer();
|
|
424
417
|
}
|
|
425
418
|
isDetached() {
|
|
426
419
|
return this._detachedScope.isClosed();
|
|
427
420
|
}
|
|
428
421
|
_onLifecycleEvent(event) {
|
|
429
|
-
if (this._firedLifecycleEvents.has(event))
|
|
422
|
+
if (this._firedLifecycleEvents.has(event))
|
|
423
|
+
return;
|
|
430
424
|
this._firedLifecycleEvents.add(event);
|
|
431
425
|
this.emit(Frame.Events.AddLifecycle, event);
|
|
432
|
-
if (this === this._page.mainFrame() && this._url !==
|
|
426
|
+
if (this === this._page.mainFrame() && this._url !== "about:blank")
|
|
427
|
+
import_debugLogger.debugLogger.log("api", ` "${event}" event fired`);
|
|
433
428
|
this._page.mainFrame()._recalculateNetworkIdle();
|
|
434
429
|
}
|
|
435
430
|
_onClearLifecycle() {
|
|
436
|
-
this._isolatedWorld =
|
|
437
|
-
this._mainWorld =
|
|
438
|
-
this._iframeWorld =
|
|
439
|
-
for (const event of this._firedLifecycleEvents)
|
|
431
|
+
this._isolatedWorld = void 0;
|
|
432
|
+
this._mainWorld = void 0;
|
|
433
|
+
this._iframeWorld = void 0;
|
|
434
|
+
for (const event of this._firedLifecycleEvents)
|
|
435
|
+
this.emit(Frame.Events.RemoveLifecycle, event);
|
|
440
436
|
this._firedLifecycleEvents.clear();
|
|
441
|
-
|
|
442
|
-
this._inflightRequests = new Set(Array.from(this._inflightRequests).filter(request => request === this._currentDocument.request));
|
|
437
|
+
this._inflightRequests = new Set(Array.from(this._inflightRequests).filter((request) => request === this._currentDocument.request));
|
|
443
438
|
this._stopNetworkIdleTimer();
|
|
444
|
-
if (this._inflightRequests.size === 0)
|
|
439
|
+
if (this._inflightRequests.size === 0)
|
|
440
|
+
this._startNetworkIdleTimer();
|
|
445
441
|
this._page.mainFrame()._recalculateNetworkIdle(this);
|
|
446
|
-
this._onLifecycleEvent(
|
|
442
|
+
this._onLifecycleEvent("commit");
|
|
447
443
|
}
|
|
448
444
|
setPendingDocument(documentInfo) {
|
|
449
445
|
this._pendingDocument = documentInfo;
|
|
450
|
-
if (documentInfo)
|
|
446
|
+
if (documentInfo)
|
|
447
|
+
this._invalidateNonStallingEvaluations("Navigation interrupted the evaluation");
|
|
451
448
|
}
|
|
452
449
|
pendingDocument() {
|
|
453
450
|
return this._pendingDocument;
|
|
454
451
|
}
|
|
455
452
|
_invalidateNonStallingEvaluations(message) {
|
|
456
|
-
if (!this._raceAgainstEvaluationStallingEventsPromises.size)
|
|
453
|
+
if (!this._raceAgainstEvaluationStallingEventsPromises.size)
|
|
454
|
+
return;
|
|
457
455
|
const error = new Error(message);
|
|
458
|
-
for (const promise of this._raceAgainstEvaluationStallingEventsPromises)
|
|
456
|
+
for (const promise of this._raceAgainstEvaluationStallingEventsPromises)
|
|
457
|
+
promise.reject(error);
|
|
459
458
|
}
|
|
460
459
|
async raceAgainstEvaluationStallingEvents(cb) {
|
|
461
|
-
if (this._pendingDocument)
|
|
462
|
-
|
|
463
|
-
|
|
460
|
+
if (this._pendingDocument)
|
|
461
|
+
throw new Error("Frame is currently attempting a navigation");
|
|
462
|
+
if (this._page._frameManager._openedDialogs.size)
|
|
463
|
+
throw new Error("Open JavaScript dialog prevents evaluation");
|
|
464
|
+
const promise = new import_manualPromise.ManualPromise();
|
|
464
465
|
this._raceAgainstEvaluationStallingEventsPromises.add(promise);
|
|
465
466
|
try {
|
|
466
|
-
return await Promise.race([
|
|
467
|
+
return await Promise.race([
|
|
468
|
+
cb(),
|
|
469
|
+
promise
|
|
470
|
+
]);
|
|
467
471
|
} finally {
|
|
468
472
|
this._raceAgainstEvaluationStallingEventsPromises.delete(promise);
|
|
469
473
|
}
|
|
@@ -471,41 +475,42 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
471
475
|
nonStallingRawEvaluateInExistingMainContext(expression) {
|
|
472
476
|
return this.raceAgainstEvaluationStallingEvents(() => {
|
|
473
477
|
const context = this._existingMainContext();
|
|
474
|
-
if (!context)
|
|
478
|
+
if (!context)
|
|
479
|
+
throw new Error("Frame does not yet have a main execution context");
|
|
475
480
|
return context.rawEvaluateJSON(expression);
|
|
476
481
|
});
|
|
477
482
|
}
|
|
478
483
|
nonStallingEvaluateInExistingContext(expression, world) {
|
|
479
484
|
return this.raceAgainstEvaluationStallingEvents(() => {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
return context.evaluateExpression(expression, {
|
|
484
|
-
isFunction: false
|
|
485
|
-
});
|
|
485
|
+
const context = this._contextData.get(world)?.context;
|
|
486
|
+
if (!context)
|
|
487
|
+
throw new Error("Frame does not yet have the execution context");
|
|
488
|
+
return context.evaluateExpression(expression, { isFunction: false });
|
|
486
489
|
});
|
|
487
490
|
}
|
|
488
491
|
_recalculateNetworkIdle(frameThatAllowsRemovingNetworkIdle) {
|
|
489
492
|
let isNetworkIdle = this._firedNetworkIdleSelf;
|
|
490
493
|
for (const child of this._childFrames) {
|
|
491
494
|
child._recalculateNetworkIdle(frameThatAllowsRemovingNetworkIdle);
|
|
492
|
-
|
|
493
|
-
|
|
495
|
+
if (!child._firedLifecycleEvents.has("networkidle"))
|
|
496
|
+
isNetworkIdle = false;
|
|
494
497
|
}
|
|
495
|
-
if (isNetworkIdle && !this._firedLifecycleEvents.has(
|
|
496
|
-
this._firedLifecycleEvents.add(
|
|
497
|
-
this.emit(Frame.Events.AddLifecycle,
|
|
498
|
-
if (this === this._page.mainFrame() && this._url !==
|
|
498
|
+
if (isNetworkIdle && !this._firedLifecycleEvents.has("networkidle")) {
|
|
499
|
+
this._firedLifecycleEvents.add("networkidle");
|
|
500
|
+
this.emit(Frame.Events.AddLifecycle, "networkidle");
|
|
501
|
+
if (this === this._page.mainFrame() && this._url !== "about:blank")
|
|
502
|
+
import_debugLogger.debugLogger.log("api", ` "networkidle" event fired`);
|
|
499
503
|
}
|
|
500
|
-
if (frameThatAllowsRemovingNetworkIdle !== this && this._firedLifecycleEvents.has(
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
this._firedLifecycleEvents.delete('networkidle');
|
|
504
|
-
this.emit(Frame.Events.RemoveLifecycle, 'networkidle');
|
|
504
|
+
if (frameThatAllowsRemovingNetworkIdle !== this && this._firedLifecycleEvents.has("networkidle") && !isNetworkIdle) {
|
|
505
|
+
this._firedLifecycleEvents.delete("networkidle");
|
|
506
|
+
this.emit(Frame.Events.RemoveLifecycle, "networkidle");
|
|
505
507
|
}
|
|
506
508
|
}
|
|
507
509
|
async raceNavigationAction(progress, options, action) {
|
|
508
|
-
return
|
|
510
|
+
return import_utils.LongStandingScope.raceMultiple([
|
|
511
|
+
this._detachedScope,
|
|
512
|
+
this._page.openScope
|
|
513
|
+
], action().catch((e) => {
|
|
509
514
|
if (e instanceof NavigationAbortedError && e.documentId) {
|
|
510
515
|
const data = this._redirectedNavigations.get(e.documentId);
|
|
511
516
|
if (data) {
|
|
@@ -517,95 +522,96 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
517
522
|
}));
|
|
518
523
|
}
|
|
519
524
|
redirectNavigation(url, documentId, referer) {
|
|
520
|
-
const controller = new
|
|
525
|
+
const controller = new import_progress.ProgressController((0, import_instrumentation.serverSideCallMetadata)(), this);
|
|
521
526
|
const data = {
|
|
522
527
|
url,
|
|
523
|
-
gotoPromise: controller.run(progress => this._gotoAction(progress, url, {
|
|
524
|
-
referer
|
|
525
|
-
}), 0)
|
|
528
|
+
gotoPromise: controller.run((progress) => this._gotoAction(progress, url, { referer }), 0)
|
|
526
529
|
};
|
|
527
530
|
this._redirectedNavigations.set(documentId, data);
|
|
528
531
|
data.gotoPromise.finally(() => this._redirectedNavigations.delete(documentId));
|
|
529
532
|
}
|
|
530
533
|
async goto(metadata, url, options = {}) {
|
|
531
|
-
const constructedNavigationURL = (0,
|
|
532
|
-
const controller = new
|
|
533
|
-
return controller.run(progress => this._goto(progress, constructedNavigationURL, options), this._page._timeoutSettings.navigationTimeout(options));
|
|
534
|
+
const constructedNavigationURL = (0, import_utils.constructURLBasedOnBaseURL)(this._page._browserContext._options.baseURL, url);
|
|
535
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
536
|
+
return controller.run((progress) => this._goto(progress, constructedNavigationURL, options), this._page._timeoutSettings.navigationTimeout(options));
|
|
534
537
|
}
|
|
535
538
|
async _goto(progress, url, options) {
|
|
536
539
|
return this.raceNavigationAction(progress, options, async () => this._gotoAction(progress, url, options));
|
|
537
540
|
}
|
|
538
541
|
async _gotoAction(progress, url, options) {
|
|
539
|
-
const waitUntil = verifyLifecycle(
|
|
542
|
+
const waitUntil = verifyLifecycle("waitUntil", options.waitUntil === void 0 ? "load" : options.waitUntil);
|
|
540
543
|
progress.log(`navigating to "${url}", waiting until "${waitUntil}"`);
|
|
541
544
|
const headers = this._page.extraHTTPHeaders() || [];
|
|
542
|
-
const refererHeader = headers.find(h => h.name.toLowerCase() ===
|
|
543
|
-
let referer = refererHeader ? refererHeader.value :
|
|
544
|
-
if (options.referer !==
|
|
545
|
-
if (referer !==
|
|
545
|
+
const refererHeader = headers.find((h) => h.name.toLowerCase() === "referer");
|
|
546
|
+
let referer = refererHeader ? refererHeader.value : void 0;
|
|
547
|
+
if (options.referer !== void 0) {
|
|
548
|
+
if (referer !== void 0 && referer !== options.referer)
|
|
549
|
+
throw new Error('"referer" is already specified as extra HTTP header');
|
|
546
550
|
referer = options.referer;
|
|
547
551
|
}
|
|
548
|
-
url =
|
|
552
|
+
url = import_helper.helper.completeUserURL(url);
|
|
549
553
|
const navigationEvents = [];
|
|
550
|
-
const collectNavigations = arg => navigationEvents.push(arg);
|
|
554
|
+
const collectNavigations = (arg) => navigationEvents.push(arg);
|
|
551
555
|
this.on(Frame.Events.InternalNavigation, collectNavigations);
|
|
552
|
-
const navigateResult = await this._page._delegate.navigateFrame(this, url, referer).finally(
|
|
556
|
+
const navigateResult = await this._page._delegate.navigateFrame(this, url, referer).finally(
|
|
557
|
+
() => this.off(Frame.Events.InternalNavigation, collectNavigations)
|
|
558
|
+
);
|
|
553
559
|
let event;
|
|
554
560
|
if (navigateResult.newDocumentId) {
|
|
555
|
-
const predicate =
|
|
556
|
-
|
|
557
|
-
// did commit and replaced the expected document.
|
|
558
|
-
return event.newDocument && (event.newDocument.documentId === navigateResult.newDocumentId || !event.error);
|
|
561
|
+
const predicate = (event2) => {
|
|
562
|
+
return event2.newDocument && (event2.newDocument.documentId === navigateResult.newDocumentId || !event2.error);
|
|
559
563
|
};
|
|
560
564
|
const events = navigationEvents.filter(predicate);
|
|
561
|
-
if (events.length)
|
|
565
|
+
if (events.length)
|
|
566
|
+
event = events[0];
|
|
567
|
+
else
|
|
568
|
+
event = await import_helper.helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, predicate).promise;
|
|
562
569
|
if (event.newDocument.documentId !== navigateResult.newDocumentId) {
|
|
563
|
-
// This is just a sanity check. In practice, new navigation should
|
|
564
|
-
// cancel the previous one and report "request cancelled"-like error.
|
|
565
570
|
throw new NavigationAbortedError(navigateResult.newDocumentId, `Navigation to "${url}" is interrupted by another navigation to "${event.url}"`);
|
|
566
571
|
}
|
|
567
|
-
if (event.error)
|
|
572
|
+
if (event.error)
|
|
573
|
+
throw event.error;
|
|
568
574
|
} else {
|
|
569
|
-
|
|
570
|
-
const predicate = e => !e.newDocument;
|
|
575
|
+
const predicate = (e) => !e.newDocument;
|
|
571
576
|
const events = navigationEvents.filter(predicate);
|
|
572
|
-
if (events.length)
|
|
577
|
+
if (events.length)
|
|
578
|
+
event = events[0];
|
|
579
|
+
else
|
|
580
|
+
event = await import_helper.helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, predicate).promise;
|
|
573
581
|
}
|
|
574
|
-
if (!this._firedLifecycleEvents.has(waitUntil))
|
|
575
|
-
|
|
582
|
+
if (!this._firedLifecycleEvents.has(waitUntil))
|
|
583
|
+
await import_helper.helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, (e) => e === waitUntil).promise;
|
|
584
|
+
const request = event.newDocument ? event.newDocument.request : void 0;
|
|
576
585
|
const response = request ? request._finalRequest().response() : null;
|
|
577
586
|
return response;
|
|
578
587
|
}
|
|
579
588
|
async _waitForNavigation(progress, requiresNewDocument, options) {
|
|
580
|
-
const waitUntil = verifyLifecycle(
|
|
589
|
+
const waitUntil = verifyLifecycle("waitUntil", options.waitUntil === void 0 ? "load" : options.waitUntil);
|
|
581
590
|
progress.log(`waiting for navigation until "${waitUntil}"`);
|
|
582
|
-
const navigationEvent = await
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
if (requiresNewDocument && !event.newDocument)
|
|
591
|
+
const navigationEvent = await import_helper.helper.waitForEvent(progress, this, Frame.Events.InternalNavigation, (event) => {
|
|
592
|
+
if (event.error)
|
|
593
|
+
return true;
|
|
594
|
+
if (requiresNewDocument && !event.newDocument)
|
|
595
|
+
return false;
|
|
586
596
|
progress.log(` navigated to "${this._url}"`);
|
|
587
597
|
return true;
|
|
588
598
|
}).promise;
|
|
589
|
-
if (navigationEvent.error)
|
|
590
|
-
|
|
591
|
-
|
|
599
|
+
if (navigationEvent.error)
|
|
600
|
+
throw navigationEvent.error;
|
|
601
|
+
if (!this._firedLifecycleEvents.has(waitUntil))
|
|
602
|
+
await import_helper.helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, (e) => e === waitUntil).promise;
|
|
603
|
+
const request = navigationEvent.newDocument ? navigationEvent.newDocument.request : void 0;
|
|
592
604
|
return request ? request._finalRequest().response() : null;
|
|
593
605
|
}
|
|
594
606
|
async _waitForLoadState(progress, state) {
|
|
595
|
-
const waitUntil = verifyLifecycle(
|
|
596
|
-
if (!this._firedLifecycleEvents.has(waitUntil))
|
|
607
|
+
const waitUntil = verifyLifecycle("state", state);
|
|
608
|
+
if (!this._firedLifecycleEvents.has(waitUntil))
|
|
609
|
+
await import_helper.helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, (e) => e === waitUntil).promise;
|
|
597
610
|
}
|
|
598
611
|
async frameElement() {
|
|
599
612
|
return this._page._delegate.getFrameElement(this);
|
|
600
613
|
}
|
|
601
614
|
async _context(world) {
|
|
602
|
-
/* await this._page._delegate._mainFrameSession._client._sendMayFail('DOM.enable');
|
|
603
|
-
var globalDoc = await this._page._delegate._mainFrameSession._client._sendMayFail('DOM.getFrameOwner', { frameId: this._id });
|
|
604
|
-
if (globalDoc) {
|
|
605
|
-
await this._page._delegate._mainFrameSession._client._sendMayFail("DOM.resolveNode", { nodeId: globalDoc.nodeId })
|
|
606
|
-
} */
|
|
607
|
-
|
|
608
|
-
// if (this.isDetached()) throw new Error('Frame was detached');
|
|
609
615
|
try {
|
|
610
616
|
var client = this._page._delegate._sessionForFrame(this)._client;
|
|
611
617
|
} catch (e) {
|
|
@@ -613,76 +619,54 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
613
619
|
}
|
|
614
620
|
var iframeExecutionContextId = await this._getFrameMainFrameContextId(client);
|
|
615
621
|
if (world == "main") {
|
|
616
|
-
|
|
617
|
-
if (this != this._page.mainFrame() && iframeExecutionContextId && this._iframeWorld == undefined) {
|
|
622
|
+
if (this != this._page.mainFrame() && iframeExecutionContextId && this._iframeWorld == void 0) {
|
|
618
623
|
var executionContextId = iframeExecutionContextId;
|
|
619
|
-
var crContext = new
|
|
620
|
-
|
|
621
|
-
}, this._id);
|
|
622
|
-
this._iframeWorld = new _dom.FrameExecutionContext(crContext, this, world);
|
|
624
|
+
var crContext = new import_crExecutionContext.CRExecutionContext(client, { id: executionContextId }, this._id);
|
|
625
|
+
this._iframeWorld = new import_dom.FrameExecutionContext(crContext, this, world);
|
|
623
626
|
this._page._delegate._mainFrameSession._onExecutionContextCreated({
|
|
624
627
|
id: executionContextId,
|
|
625
628
|
origin: world,
|
|
626
629
|
name: world,
|
|
627
|
-
auxData: {
|
|
628
|
-
isDefault: this === this._page.mainFrame(),
|
|
629
|
-
type: 'isolated',
|
|
630
|
-
frameId: this._id
|
|
631
|
-
}
|
|
630
|
+
auxData: { isDefault: this === this._page.mainFrame(), type: "isolated", frameId: this._id }
|
|
632
631
|
});
|
|
633
|
-
} else if (this._mainWorld ==
|
|
634
|
-
var
|
|
632
|
+
} else if (this._mainWorld == void 0) {
|
|
633
|
+
var globalThis2 = await client._sendMayFail("Runtime.evaluate", {
|
|
635
634
|
expression: "globalThis",
|
|
636
|
-
serializationOptions: {
|
|
637
|
-
serialization: "idOnly"
|
|
638
|
-
}
|
|
635
|
+
serializationOptions: { serialization: "idOnly" }
|
|
639
636
|
});
|
|
640
|
-
if (!
|
|
637
|
+
if (!globalThis2) {
|
|
641
638
|
return;
|
|
642
639
|
}
|
|
643
|
-
var globalThisObjId =
|
|
644
|
-
var executionContextId = parseInt(globalThisObjId.split(
|
|
645
|
-
var crContext = new
|
|
646
|
-
|
|
647
|
-
}, this._id);
|
|
648
|
-
this._mainWorld = new _dom.FrameExecutionContext(crContext, this, world);
|
|
640
|
+
var globalThisObjId = globalThis2["result"]["objectId"];
|
|
641
|
+
var executionContextId = parseInt(globalThisObjId.split(".")[1], 10);
|
|
642
|
+
var crContext = new import_crExecutionContext.CRExecutionContext(client, { id: executionContextId }, this._id);
|
|
643
|
+
this._mainWorld = new import_dom.FrameExecutionContext(crContext, this, world);
|
|
649
644
|
this._page._delegate._mainFrameSession._onExecutionContextCreated({
|
|
650
645
|
id: executionContextId,
|
|
651
646
|
origin: world,
|
|
652
647
|
name: world,
|
|
653
|
-
auxData: {
|
|
654
|
-
isDefault: this === this._page.mainFrame(),
|
|
655
|
-
type: 'isolated',
|
|
656
|
-
frameId: this._id
|
|
657
|
-
}
|
|
648
|
+
auxData: { isDefault: this === this._page.mainFrame(), type: "isolated", frameId: this._id }
|
|
658
649
|
});
|
|
659
650
|
}
|
|
660
651
|
}
|
|
661
|
-
if (world != "main" && this._isolatedWorld ==
|
|
652
|
+
if (world != "main" && this._isolatedWorld == void 0) {
|
|
662
653
|
world = "utility";
|
|
663
|
-
var result = await client._sendMayFail(
|
|
654
|
+
var result = await client._sendMayFail("Page.createIsolatedWorld", {
|
|
664
655
|
frameId: this._id,
|
|
665
656
|
grantUniveralAccess: true,
|
|
666
657
|
worldName: world
|
|
667
658
|
});
|
|
668
659
|
if (!result) {
|
|
669
|
-
// if (this.isDetached()) throw new Error("Frame was detached");
|
|
670
660
|
return;
|
|
671
661
|
}
|
|
672
662
|
var executionContextId = result.executionContextId;
|
|
673
|
-
var crContext = new
|
|
674
|
-
|
|
675
|
-
}, this._id);
|
|
676
|
-
this._isolatedWorld = new _dom.FrameExecutionContext(crContext, this, world);
|
|
663
|
+
var crContext = new import_crExecutionContext.CRExecutionContext(client, { id: executionContextId }, this._id);
|
|
664
|
+
this._isolatedWorld = new import_dom.FrameExecutionContext(crContext, this, world);
|
|
677
665
|
this._page._delegate._mainFrameSession._onExecutionContextCreated({
|
|
678
666
|
id: executionContextId,
|
|
679
667
|
origin: world,
|
|
680
668
|
name: world,
|
|
681
|
-
auxData: {
|
|
682
|
-
isDefault: this === this._page.mainFrame(),
|
|
683
|
-
type: 'isolated',
|
|
684
|
-
frameId: this._id
|
|
685
|
-
}
|
|
669
|
+
auxData: { isDefault: this === this._page.mainFrame(), type: "isolated", frameId: this._id }
|
|
686
670
|
});
|
|
687
671
|
}
|
|
688
672
|
if (world != "main") {
|
|
@@ -694,65 +678,59 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
694
678
|
}
|
|
695
679
|
}
|
|
696
680
|
_mainContext() {
|
|
697
|
-
return this._context(
|
|
681
|
+
return this._context("main");
|
|
698
682
|
}
|
|
699
683
|
_existingMainContext() {
|
|
700
|
-
|
|
701
|
-
return ((_this$_contextData$ge2 = this._contextData.get('main')) === null || _this$_contextData$ge2 === void 0 ? void 0 : _this$_contextData$ge2.context) || null;
|
|
684
|
+
return this._contextData.get("main")?.context || null;
|
|
702
685
|
}
|
|
703
686
|
_utilityContext() {
|
|
704
|
-
return this._context(
|
|
687
|
+
return this._context("utility");
|
|
705
688
|
}
|
|
706
689
|
async evaluateExpression(expression, options = {}, arg) {
|
|
707
|
-
|
|
708
|
-
const context = await this._context((_options$world = options.world) !== null && _options$world !== void 0 ? _options$world : 'main');
|
|
690
|
+
const context = await this._context(options.world ?? "main");
|
|
709
691
|
const value = await context.evaluateExpression(expression, options, arg);
|
|
710
692
|
return value;
|
|
711
693
|
}
|
|
712
694
|
async evaluateExpressionHandle(expression, options = {}, arg) {
|
|
713
|
-
|
|
714
|
-
const context = await this._context((_options$world2 = options.world) !== null && _options$world2 !== void 0 ? _options$world2 : 'main');
|
|
695
|
+
const context = await this._context(options.world ?? "main");
|
|
715
696
|
const value = await context.evaluateExpressionHandle(expression, options, arg);
|
|
716
697
|
return value;
|
|
717
698
|
}
|
|
718
699
|
async querySelector(selector, options) {
|
|
719
|
-
|
|
700
|
+
import_debugLogger.debugLogger.log("api", ` finding element using the selector "${selector}"`);
|
|
720
701
|
return this.selectors.query(selector, options);
|
|
721
702
|
}
|
|
722
703
|
async waitForSelector(metadata, selector, options, scope) {
|
|
723
|
-
const controller = new
|
|
724
|
-
if (options.visibility)
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
} = options;
|
|
729
|
-
if (![
|
|
730
|
-
|
|
731
|
-
|
|
704
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
705
|
+
if (options.visibility)
|
|
706
|
+
throw new Error("options.visibility is not supported, did you mean options.state?");
|
|
707
|
+
if (options.waitFor && options.waitFor !== "visible")
|
|
708
|
+
throw new Error("options.waitFor is not supported, did you mean options.state?");
|
|
709
|
+
const { state = "visible" } = options;
|
|
710
|
+
if (!["attached", "detached", "visible", "hidden"].includes(state))
|
|
711
|
+
throw new Error(`state: expected one of (attached|detached|visible|hidden)`);
|
|
712
|
+
return controller.run(async (progress) => {
|
|
713
|
+
progress.log(`waiting for ${this._asLocator(selector)}${state === "attached" ? "" : " to be " + state}`);
|
|
732
714
|
return await this.waitForSelectorInternal(progress, selector, true, options, scope);
|
|
733
715
|
}, this._page._timeoutSettings.timeout(options));
|
|
734
716
|
}
|
|
735
717
|
async waitForSelectorInternal(progress, selector, performActionPreChecks, options, scope) {
|
|
736
718
|
const {
|
|
737
|
-
state =
|
|
719
|
+
state = "visible"
|
|
738
720
|
} = options;
|
|
739
|
-
const promise = this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, async handle => {
|
|
721
|
+
const promise = this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, async (handle) => {
|
|
740
722
|
const attached = !!handle;
|
|
741
723
|
var visible = false;
|
|
742
724
|
if (attached) {
|
|
743
725
|
if (handle.parentNode.constructor.name == "ElementHandle") {
|
|
744
|
-
visible = await handle.parentNode.evaluateInUtility(([injected, node, {
|
|
745
|
-
|
|
746
|
-
}]) => {
|
|
747
|
-
return handle ? injected.utils.isElementVisible(handle) : false;
|
|
726
|
+
visible = await handle.parentNode.evaluateInUtility(([injected, node, { handle: handle2 }]) => {
|
|
727
|
+
return handle2 ? injected.utils.isElementVisible(handle2) : false;
|
|
748
728
|
}, {
|
|
749
729
|
handle
|
|
750
730
|
});
|
|
751
731
|
} else {
|
|
752
|
-
visible = await handle.parentNode.evaluate((injected, {
|
|
753
|
-
|
|
754
|
-
}) => {
|
|
755
|
-
return handle ? injected.utils.isElementVisible(handle) : false;
|
|
732
|
+
visible = await handle.parentNode.evaluate((injected, { handle: handle2 }) => {
|
|
733
|
+
return handle2 ? injected.utils.isElementVisible(handle2) : false;
|
|
756
734
|
}, {
|
|
757
735
|
handle
|
|
758
736
|
});
|
|
@@ -770,7 +748,7 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
770
748
|
if (options.omitReturnValue) {
|
|
771
749
|
return null;
|
|
772
750
|
}
|
|
773
|
-
const element = state ===
|
|
751
|
+
const element = state === "attached" || state === "visible" ? handle : null;
|
|
774
752
|
if (!element) return null;
|
|
775
753
|
if (options.__testHookBeforeAdoptNode) await options.__testHookBeforeAdoptNode();
|
|
776
754
|
try {
|
|
@@ -778,51 +756,34 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
778
756
|
} catch (e) {
|
|
779
757
|
return "internal:continuepolling";
|
|
780
758
|
}
|
|
781
|
-
}
|
|
759
|
+
});
|
|
782
760
|
return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
|
|
783
761
|
}
|
|
784
762
|
async dispatchEvent(metadata, selector, type, eventInit = {}, options = {}, scope) {
|
|
785
763
|
await this._callOnElementOnceMatches(metadata, selector, (injectedScript, element, data) => {
|
|
786
764
|
injectedScript.dispatchEvent(element, data.type, data.eventInit);
|
|
787
|
-
}, {
|
|
788
|
-
type,
|
|
789
|
-
eventInit
|
|
790
|
-
}, {
|
|
791
|
-
mainWorld: true,
|
|
792
|
-
...options
|
|
793
|
-
}, scope);
|
|
765
|
+
}, { type, eventInit }, { mainWorld: true, ...options }, scope);
|
|
794
766
|
}
|
|
795
767
|
async evalOnSelector(selector, strict, expression, isFunction, arg, scope) {
|
|
796
|
-
const handle = await this.selectors.query(selector, {
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
const result = await handle.evaluateExpression(expression, {
|
|
801
|
-
isFunction
|
|
802
|
-
}, arg);
|
|
768
|
+
const handle = await this.selectors.query(selector, { strict }, scope);
|
|
769
|
+
if (!handle)
|
|
770
|
+
throw new Error(`Failed to find element matching selector "${selector}"`);
|
|
771
|
+
const result = await handle.evaluateExpression(expression, { isFunction }, arg);
|
|
803
772
|
handle.dispose();
|
|
804
773
|
return result;
|
|
805
774
|
}
|
|
806
775
|
async evalOnSelectorAll(selector, expression, isFunction, arg, scope) {
|
|
807
776
|
const arrayHandle = await this.selectors.queryArrayInMainWorld(selector, scope);
|
|
808
|
-
const result = await arrayHandle.evaluateExpression(expression, {
|
|
809
|
-
isFunction
|
|
810
|
-
}, arg);
|
|
777
|
+
const result = await arrayHandle.evaluateExpression(expression, { isFunction }, arg);
|
|
811
778
|
arrayHandle.dispose();
|
|
812
779
|
return result;
|
|
813
780
|
}
|
|
814
781
|
async maskSelectors(selectors, color) {
|
|
815
782
|
const context = await this._utilityContext();
|
|
816
783
|
const injectedScript = await context.injectedScript();
|
|
817
|
-
await injectedScript.evaluate((injected, {
|
|
818
|
-
parsed,
|
|
819
|
-
|
|
820
|
-
}) => {
|
|
821
|
-
injected.maskSelectors(parsed, color);
|
|
822
|
-
}, {
|
|
823
|
-
parsed: selectors,
|
|
824
|
-
color: color
|
|
825
|
-
});
|
|
784
|
+
await injectedScript.evaluate((injected, { parsed, color: color2 }) => {
|
|
785
|
+
injected.maskSelectors(parsed, color2);
|
|
786
|
+
}, { parsed: selectors, color });
|
|
826
787
|
}
|
|
827
788
|
async querySelectorAll(selector) {
|
|
828
789
|
return this.selectors.queryAll(selector);
|
|
@@ -832,60 +793,58 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
832
793
|
"internal": false,
|
|
833
794
|
"log": []
|
|
834
795
|
};
|
|
835
|
-
const controller = new
|
|
836
|
-
|
|
796
|
+
const controller = new import_progress.ProgressController(custom_metadata, this);
|
|
797
|
+
const resultPromise = await controller.run(async (progress) => {
|
|
837
798
|
progress.log("waiting for " + this._asLocator(selector));
|
|
838
|
-
const promise = await this._retryWithProgressIfNotConnected(progress, selector, false, false, async result => {
|
|
799
|
+
const promise = await this._retryWithProgressIfNotConnected(progress, selector, false, false, async (result) => {
|
|
839
800
|
const handle = result[0];
|
|
840
801
|
const handles = result[1];
|
|
841
802
|
return handle ? handles.length : 0;
|
|
842
|
-
},
|
|
803
|
+
}, "returnAll");
|
|
843
804
|
return promise;
|
|
844
|
-
}, 100);
|
|
805
|
+
}, 100);
|
|
806
|
+
return resultPromise ? resultPromise : 0;
|
|
845
807
|
}
|
|
846
808
|
async content() {
|
|
847
809
|
try {
|
|
848
810
|
const context = await this._utilityContext();
|
|
849
811
|
return await context.evaluate(() => {
|
|
850
|
-
let retVal =
|
|
851
|
-
if (document.doctype)
|
|
852
|
-
|
|
812
|
+
let retVal = "";
|
|
813
|
+
if (document.doctype)
|
|
814
|
+
retVal = new XMLSerializer().serializeToString(document.doctype);
|
|
815
|
+
if (document.documentElement)
|
|
816
|
+
retVal += document.documentElement.outerHTML;
|
|
853
817
|
return retVal;
|
|
854
818
|
});
|
|
855
819
|
} catch (e) {
|
|
856
|
-
if (js.isJavaScriptErrorInEvaluate(e) || (0,
|
|
820
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_protocolError.isSessionClosedError)(e))
|
|
821
|
+
throw e;
|
|
857
822
|
throw new Error(`Unable to retrieve content because the page is navigating and changing the content.`);
|
|
858
823
|
}
|
|
859
824
|
}
|
|
860
825
|
async setContent(metadata, html, options = {}) {
|
|
861
|
-
const controller = new
|
|
862
|
-
return controller.run(async progress => {
|
|
826
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
827
|
+
return controller.run(async (progress) => {
|
|
863
828
|
await this.raceNavigationAction(progress, options, async () => {
|
|
864
|
-
const waitUntil = options.waitUntil ===
|
|
829
|
+
const waitUntil = options.waitUntil === void 0 ? "load" : options.waitUntil;
|
|
865
830
|
progress.log(`setting frame content, waiting until "${waitUntil}"`);
|
|
866
831
|
const tag = `--playwright--set--content--${this._id}--${++this._setContentCounter}--`;
|
|
867
|
-
const bindingName = "_tagDebug" +
|
|
832
|
+
const bindingName = "_tagDebug" + import_crypto.default.randomBytes(20).toString("hex");
|
|
868
833
|
const context = await this._utilityContext();
|
|
869
|
-
await this._page._delegate._mainFrameSession._client.send(
|
|
870
|
-
name: bindingName
|
|
871
|
-
});
|
|
834
|
+
await this._page._delegate._mainFrameSession._client.send("Runtime.addBinding", { name: bindingName });
|
|
872
835
|
const lifecyclePromise = new Promise(async (resolve, reject) => {
|
|
873
|
-
await this._page.exposeBinding(bindingName, false,
|
|
836
|
+
await this._page.exposeBinding(bindingName, false, (tag2) => {
|
|
874
837
|
this._onClearLifecycle();
|
|
875
838
|
this._waitForLoadState(progress, waitUntil).then(resolve).catch(reject);
|
|
876
839
|
});
|
|
877
840
|
});
|
|
878
|
-
const contentPromise = context.evaluate(({
|
|
879
|
-
html,
|
|
880
|
-
tag,
|
|
881
|
-
bindingName
|
|
882
|
-
}) => {
|
|
841
|
+
const contentPromise = context.evaluate(({ html: html2, tag: tag2, bindingName: bindingName2 }) => {
|
|
883
842
|
document.open();
|
|
884
|
-
var _tagDebug = window[
|
|
885
|
-
delete window[
|
|
886
|
-
_tagDebug('{ "name": "' +
|
|
887
|
-
console.debug(
|
|
888
|
-
document.write(
|
|
843
|
+
var _tagDebug = window[bindingName2].bind({});
|
|
844
|
+
delete window[bindingName2];
|
|
845
|
+
_tagDebug('{ "name": "' + bindingName2 + '", "seq": 1, "serializedArgs": ["' + tag2 + '"] }');
|
|
846
|
+
console.debug(tag2);
|
|
847
|
+
document.write(html2);
|
|
889
848
|
document.close();
|
|
890
849
|
}, {
|
|
891
850
|
html,
|
|
@@ -898,15 +857,15 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
898
857
|
}, this._page._timeoutSettings.navigationTimeout(options));
|
|
899
858
|
}
|
|
900
859
|
name() {
|
|
901
|
-
return this._name ||
|
|
860
|
+
return this._name || "";
|
|
902
861
|
}
|
|
903
862
|
url() {
|
|
904
863
|
return this._url;
|
|
905
864
|
}
|
|
906
865
|
origin() {
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
return
|
|
866
|
+
if (!this._url.startsWith("http"))
|
|
867
|
+
return;
|
|
868
|
+
return network.parseURL(this._url)?.origin;
|
|
910
869
|
}
|
|
911
870
|
parentFrame() {
|
|
912
871
|
return this._parentFrame;
|
|
@@ -918,44 +877,41 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
918
877
|
const {
|
|
919
878
|
url = null,
|
|
920
879
|
content = null,
|
|
921
|
-
type =
|
|
880
|
+
type = ""
|
|
922
881
|
} = params;
|
|
923
|
-
if (!url && !content)
|
|
882
|
+
if (!url && !content)
|
|
883
|
+
throw new Error("Provide an object with a `url`, `path` or `content` property");
|
|
924
884
|
const context = await this._mainContext();
|
|
925
885
|
return this._raceWithCSPError(async () => {
|
|
926
|
-
if (url !== null)
|
|
927
|
-
url,
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
content: content,
|
|
932
|
-
type
|
|
933
|
-
})).asElement();
|
|
934
|
-
// Another round trip to the browser to ensure that we receive CSP error messages
|
|
935
|
-
// (if any) logged asynchronously in a separate task on the content main thread.
|
|
936
|
-
if (this._page._delegate.cspErrorsAsynchronousForInlineScripts) await context.evaluate(() => true);
|
|
886
|
+
if (url !== null)
|
|
887
|
+
return (await context.evaluateHandle(addScriptUrl, { url, type })).asElement();
|
|
888
|
+
const result = (await context.evaluateHandle(addScriptContent, { content, type })).asElement();
|
|
889
|
+
if (this._page._delegate.cspErrorsAsynchronousForInlineScripts)
|
|
890
|
+
await context.evaluate(() => true);
|
|
937
891
|
return result;
|
|
938
892
|
});
|
|
939
|
-
async function addScriptUrl(
|
|
940
|
-
const script = document.createElement(
|
|
941
|
-
script.src =
|
|
942
|
-
if (
|
|
893
|
+
async function addScriptUrl(params2) {
|
|
894
|
+
const script = document.createElement("script");
|
|
895
|
+
script.src = params2.url;
|
|
896
|
+
if (params2.type)
|
|
897
|
+
script.type = params2.type;
|
|
943
898
|
const promise = new Promise((res, rej) => {
|
|
944
899
|
script.onload = res;
|
|
945
|
-
script.onerror = e => rej(typeof e ===
|
|
900
|
+
script.onerror = (e) => rej(typeof e === "string" ? new Error(e) : new Error(`Failed to load script at ${script.src}`));
|
|
946
901
|
});
|
|
947
902
|
document.head.appendChild(script);
|
|
948
903
|
await promise;
|
|
949
904
|
return script;
|
|
950
905
|
}
|
|
951
|
-
function addScriptContent(
|
|
952
|
-
const script = document.createElement(
|
|
953
|
-
script.type =
|
|
954
|
-
script.text =
|
|
906
|
+
function addScriptContent(params2) {
|
|
907
|
+
const script = document.createElement("script");
|
|
908
|
+
script.type = params2.type || "text/javascript";
|
|
909
|
+
script.text = params2.content;
|
|
955
910
|
let error = null;
|
|
956
|
-
script.onerror = e => error = e;
|
|
911
|
+
script.onerror = (e) => error = e;
|
|
957
912
|
document.head.appendChild(script);
|
|
958
|
-
if (error)
|
|
913
|
+
if (error)
|
|
914
|
+
throw error;
|
|
959
915
|
return script;
|
|
960
916
|
}
|
|
961
917
|
}
|
|
@@ -964,16 +920,18 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
964
920
|
url = null,
|
|
965
921
|
content = null
|
|
966
922
|
} = params;
|
|
967
|
-
if (!url && !content)
|
|
923
|
+
if (!url && !content)
|
|
924
|
+
throw new Error("Provide an object with a `url`, `path` or `content` property");
|
|
968
925
|
const context = await this._mainContext();
|
|
969
926
|
return this._raceWithCSPError(async () => {
|
|
970
|
-
if (url !== null)
|
|
927
|
+
if (url !== null)
|
|
928
|
+
return (await context.evaluateHandle(addStyleUrl, url)).asElement();
|
|
971
929
|
return (await context.evaluateHandle(addStyleContent, content)).asElement();
|
|
972
930
|
});
|
|
973
|
-
async function addStyleUrl(
|
|
974
|
-
const link = document.createElement(
|
|
975
|
-
link.rel =
|
|
976
|
-
link.href =
|
|
931
|
+
async function addStyleUrl(url2) {
|
|
932
|
+
const link = document.createElement("link");
|
|
933
|
+
link.rel = "stylesheet";
|
|
934
|
+
link.href = url2;
|
|
977
935
|
const promise = new Promise((res, rej) => {
|
|
978
936
|
link.onload = res;
|
|
979
937
|
link.onerror = rej;
|
|
@@ -982,10 +940,10 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
982
940
|
await promise;
|
|
983
941
|
return link;
|
|
984
942
|
}
|
|
985
|
-
async function addStyleContent(
|
|
986
|
-
const style = document.createElement(
|
|
987
|
-
style.type =
|
|
988
|
-
style.appendChild(document.createTextNode(
|
|
943
|
+
async function addStyleContent(content2) {
|
|
944
|
+
const style = document.createElement("style");
|
|
945
|
+
style.type = "text/css";
|
|
946
|
+
style.appendChild(document.createTextNode(content2));
|
|
989
947
|
const promise = new Promise((res, rej) => {
|
|
990
948
|
style.onload = res;
|
|
991
949
|
style.onerror = rej;
|
|
@@ -1000,68 +958,73 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1000
958
|
let result;
|
|
1001
959
|
let error;
|
|
1002
960
|
let cspMessage;
|
|
1003
|
-
const actionPromise = func().then(r => result = r).catch(e => error = e);
|
|
1004
|
-
const errorPromise = new Promise(resolve => {
|
|
1005
|
-
listeners.push(
|
|
1006
|
-
if (message.page() !== this._page || message.type() !==
|
|
1007
|
-
|
|
961
|
+
const actionPromise = func().then((r) => result = r).catch((e) => error = e);
|
|
962
|
+
const errorPromise = new Promise((resolve) => {
|
|
963
|
+
listeners.push(import_eventsHelper.eventsHelper.addEventListener(this._page._browserContext, import_browserContext.BrowserContext.Events.Console, (message) => {
|
|
964
|
+
if (message.page() !== this._page || message.type() !== "error")
|
|
965
|
+
return;
|
|
966
|
+
if (message.text().includes("Content-Security-Policy") || message.text().includes("Content Security Policy")) {
|
|
1008
967
|
cspMessage = message;
|
|
1009
968
|
resolve();
|
|
1010
969
|
}
|
|
1011
970
|
}));
|
|
1012
971
|
});
|
|
1013
972
|
await Promise.race([actionPromise, errorPromise]);
|
|
1014
|
-
|
|
1015
|
-
if (cspMessage)
|
|
1016
|
-
|
|
973
|
+
import_eventsHelper.eventsHelper.removeEventListeners(listeners);
|
|
974
|
+
if (cspMessage)
|
|
975
|
+
throw new Error(cspMessage.text());
|
|
976
|
+
if (error)
|
|
977
|
+
throw error;
|
|
1017
978
|
return result;
|
|
1018
979
|
}
|
|
1019
980
|
async retryWithProgressAndTimeouts(progress, timeouts, action) {
|
|
1020
|
-
const
|
|
981
|
+
const continuePolling2 = Symbol("continuePolling");
|
|
1021
982
|
timeouts = [0, ...timeouts];
|
|
1022
983
|
let timeoutIndex = 0;
|
|
1023
984
|
while (progress.isRunning()) {
|
|
1024
985
|
const timeout = timeouts[Math.min(timeoutIndex++, timeouts.length - 1)];
|
|
1025
986
|
if (timeout) {
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
987
|
+
const actionPromise = new Promise((f) => setTimeout(f, timeout));
|
|
988
|
+
await import_utils.LongStandingScope.raceMultiple([
|
|
989
|
+
this._page.openScope,
|
|
990
|
+
this._detachedScope
|
|
991
|
+
], actionPromise);
|
|
1030
992
|
}
|
|
1031
993
|
progress.throwIfAborted();
|
|
1032
994
|
try {
|
|
1033
|
-
const result = await action(
|
|
1034
|
-
if (result ===
|
|
995
|
+
const result = await action(continuePolling2);
|
|
996
|
+
if (result === continuePolling2)
|
|
997
|
+
continue;
|
|
1035
998
|
return result;
|
|
1036
999
|
} catch (e) {
|
|
1037
|
-
if (this._isErrorThatCannotBeRetried(e))
|
|
1000
|
+
if (this._isErrorThatCannotBeRetried(e))
|
|
1001
|
+
throw e;
|
|
1038
1002
|
continue;
|
|
1039
1003
|
}
|
|
1040
1004
|
}
|
|
1041
1005
|
progress.throwIfAborted();
|
|
1042
|
-
return
|
|
1006
|
+
return void 0;
|
|
1043
1007
|
}
|
|
1044
1008
|
_isErrorThatCannotBeRetried(e) {
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
// Retry upon all other errors.
|
|
1009
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_protocolError.isSessionClosedError)(e))
|
|
1010
|
+
return true;
|
|
1011
|
+
if (dom.isNonRecoverableDOMError(e) || (0, import_selectorParser.isInvalidSelectorError)(e))
|
|
1012
|
+
return true;
|
|
1013
|
+
if (this.isDetached())
|
|
1014
|
+
return true;
|
|
1052
1015
|
return false;
|
|
1053
1016
|
}
|
|
1054
1017
|
async _retryWithProgressIfNotConnected(progress, selector, strict, performActionPreChecks, action, returnAction) {
|
|
1055
1018
|
progress.log("waiting for " + this._asLocator(selector));
|
|
1056
|
-
return this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async
|
|
1019
|
+
return this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async (continuePolling2) => {
|
|
1057
1020
|
if (performActionPreChecks) await this._page.performActionPreChecks(progress);
|
|
1058
1021
|
const resolved = await this.selectors.resolveInjectedForSelector(selector, {
|
|
1059
1022
|
strict
|
|
1060
1023
|
});
|
|
1061
1024
|
progress.throwIfAborted();
|
|
1062
1025
|
if (!resolved) {
|
|
1063
|
-
if (returnAction ===
|
|
1064
|
-
return
|
|
1026
|
+
if (returnAction === "returnOnNotResolved" || returnAction === "returnAll") return null;
|
|
1027
|
+
return continuePolling2;
|
|
1065
1028
|
}
|
|
1066
1029
|
try {
|
|
1067
1030
|
var client = this._page._delegate._sessionForFrame(resolved.frame)._client;
|
|
@@ -1069,7 +1032,7 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1069
1032
|
var client = this._page._delegate._mainFrameSession._client;
|
|
1070
1033
|
}
|
|
1071
1034
|
var context = await resolved.frame._context("main");
|
|
1072
|
-
const documentNode = await client.send(
|
|
1035
|
+
const documentNode = await client.send("Runtime.evaluate", {
|
|
1073
1036
|
expression: "document",
|
|
1074
1037
|
serializationOptions: {
|
|
1075
1038
|
serialization: "idOnly"
|
|
@@ -1079,9 +1042,8 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1079
1042
|
const documentScope = new dom.ElementHandle(context, documentNode.result.objectId);
|
|
1080
1043
|
const currentScopingElements = await this._customFindElementsByParsed(resolved, client, context, documentScope, progress, resolved.info.parsed);
|
|
1081
1044
|
if (currentScopingElements.length == 0) {
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
return continuePolling;
|
|
1045
|
+
if (returnAction === "returnOnNotResolved" || returnAction === "returnAll") return null;
|
|
1046
|
+
return continuePolling2;
|
|
1085
1047
|
}
|
|
1086
1048
|
const resultElement = currentScopingElements[0];
|
|
1087
1049
|
if (currentScopingElements.length > 1) {
|
|
@@ -1102,64 +1064,61 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1102
1064
|
}
|
|
1103
1065
|
try {
|
|
1104
1066
|
var result = null;
|
|
1105
|
-
if (returnAction ===
|
|
1067
|
+
if (returnAction === "returnAll") {
|
|
1106
1068
|
result = await action([resultElement, currentScopingElements]);
|
|
1107
1069
|
} else {
|
|
1108
1070
|
result = await action(resultElement);
|
|
1109
1071
|
}
|
|
1110
|
-
if (result ===
|
|
1111
|
-
progress.log(
|
|
1112
|
-
return
|
|
1113
|
-
} else if (result ===
|
|
1114
|
-
return
|
|
1072
|
+
if (result === "error:notconnected") {
|
|
1073
|
+
progress.log("element was detached from the DOM, retrying");
|
|
1074
|
+
return continuePolling2;
|
|
1075
|
+
} else if (result === "internal:continuepolling") {
|
|
1076
|
+
return continuePolling2;
|
|
1115
1077
|
}
|
|
1116
1078
|
return result;
|
|
1117
|
-
} finally {
|
|
1079
|
+
} finally {
|
|
1080
|
+
}
|
|
1118
1081
|
});
|
|
1119
1082
|
}
|
|
1120
1083
|
async rafrafTimeoutScreenshotElementWithProgress(progress, selector, timeout, options) {
|
|
1121
|
-
return await this._retryWithProgressIfNotConnected(progress, selector, true
|
|
1084
|
+
return await this._retryWithProgressIfNotConnected(progress, selector, true, true, async (handle) => {
|
|
1122
1085
|
await handle._frame.rafrafTimeout(timeout);
|
|
1123
1086
|
return await this._page._screenshotter.screenshotElement(progress, handle, options);
|
|
1124
1087
|
});
|
|
1125
1088
|
}
|
|
1126
1089
|
async click(metadata, selector, options) {
|
|
1127
|
-
const controller = new
|
|
1128
|
-
return controller.run(async progress => {
|
|
1129
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force
|
|
1130
|
-
...options,
|
|
1131
|
-
waitAfter: !options.noWaitAfter
|
|
1132
|
-
})));
|
|
1090
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1091
|
+
return controller.run(async (progress) => {
|
|
1092
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._click(progress, { ...options, waitAfter: !options.noWaitAfter })));
|
|
1133
1093
|
}, this._page._timeoutSettings.timeout(options));
|
|
1134
1094
|
}
|
|
1135
1095
|
async dblclick(metadata, selector, options = {}) {
|
|
1136
|
-
const controller = new
|
|
1137
|
-
return controller.run(async progress => {
|
|
1138
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force
|
|
1096
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1097
|
+
return controller.run(async (progress) => {
|
|
1098
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._dblclick(progress, options)));
|
|
1139
1099
|
}, this._page._timeoutSettings.timeout(options));
|
|
1140
1100
|
}
|
|
1141
1101
|
async dragAndDrop(metadata, source, target, options = {}) {
|
|
1142
|
-
const controller = new
|
|
1143
|
-
await controller.run(async progress => {
|
|
1144
|
-
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, source, options.strict, !options.force
|
|
1145
|
-
return handle._retryPointerAction(progress,
|
|
1102
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1103
|
+
await controller.run(async (progress) => {
|
|
1104
|
+
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, source, options.strict, !options.force, async (handle) => {
|
|
1105
|
+
return handle._retryPointerAction(progress, "move and down", false, async (point) => {
|
|
1146
1106
|
await this._page.mouse.move(point.x, point.y);
|
|
1147
1107
|
await this._page.mouse.down();
|
|
1148
1108
|
}, {
|
|
1149
1109
|
...options,
|
|
1150
|
-
waitAfter:
|
|
1110
|
+
waitAfter: "disabled",
|
|
1151
1111
|
position: options.sourcePosition,
|
|
1152
1112
|
timeout: progress.timeUntilDeadline()
|
|
1153
1113
|
});
|
|
1154
1114
|
}));
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
return handle._retryPointerAction(progress, 'move and up', false, async point => {
|
|
1115
|
+
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, target, options.strict, false, async (handle) => {
|
|
1116
|
+
return handle._retryPointerAction(progress, "move and up", false, async (point) => {
|
|
1158
1117
|
await this._page.mouse.move(point.x, point.y);
|
|
1159
1118
|
await this._page.mouse.up();
|
|
1160
1119
|
}, {
|
|
1161
1120
|
...options,
|
|
1162
|
-
waitAfter:
|
|
1121
|
+
waitAfter: "disabled",
|
|
1163
1122
|
position: options.targetPosition,
|
|
1164
1123
|
timeout: progress.timeUntilDeadline()
|
|
1165
1124
|
});
|
|
@@ -1167,70 +1126,68 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1167
1126
|
}, this._page._timeoutSettings.timeout(options));
|
|
1168
1127
|
}
|
|
1169
1128
|
async tap(metadata, selector, options) {
|
|
1170
|
-
if (!this._page._browserContext._options.hasTouch)
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1129
|
+
if (!this._page._browserContext._options.hasTouch)
|
|
1130
|
+
throw new Error("The page does not support tap. Use hasTouch context option to enable touch support.");
|
|
1131
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1132
|
+
return controller.run(async (progress) => {
|
|
1133
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._tap(progress, options)));
|
|
1174
1134
|
}, this._page._timeoutSettings.timeout(options));
|
|
1175
1135
|
}
|
|
1176
1136
|
async fill(metadata, selector, value, options) {
|
|
1177
|
-
const controller = new
|
|
1178
|
-
return controller.run(async progress => {
|
|
1179
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force
|
|
1137
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1138
|
+
return controller.run(async (progress) => {
|
|
1139
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._fill(progress, value, options)));
|
|
1180
1140
|
}, this._page._timeoutSettings.timeout(options));
|
|
1181
1141
|
}
|
|
1182
1142
|
async focus(metadata, selector, options = {}) {
|
|
1183
|
-
const controller = new
|
|
1184
|
-
await controller.run(async progress => {
|
|
1185
|
-
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true
|
|
1143
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1144
|
+
await controller.run(async (progress) => {
|
|
1145
|
+
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle) => handle._focus(progress)));
|
|
1186
1146
|
}, this._page._timeoutSettings.timeout(options));
|
|
1187
1147
|
}
|
|
1188
1148
|
async blur(metadata, selector, options = {}) {
|
|
1189
|
-
const controller = new
|
|
1190
|
-
await controller.run(async progress => {
|
|
1191
|
-
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true
|
|
1149
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1150
|
+
await controller.run(async (progress) => {
|
|
1151
|
+
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle) => handle._blur(progress)));
|
|
1192
1152
|
}, this._page._timeoutSettings.timeout(options));
|
|
1193
1153
|
}
|
|
1194
1154
|
async textContent(metadata, selector, options = {}, scope) {
|
|
1195
|
-
return this._callOnElementOnceMatches(metadata, selector, (injected, element) => element.textContent,
|
|
1155
|
+
return this._callOnElementOnceMatches(metadata, selector, (injected, element) => element.textContent, void 0, options, scope);
|
|
1196
1156
|
}
|
|
1197
1157
|
async innerText(metadata, selector, options = {}, scope) {
|
|
1198
1158
|
return this._callOnElementOnceMatches(metadata, selector, (injectedScript, element) => {
|
|
1199
|
-
if (element.namespaceURI !==
|
|
1159
|
+
if (element.namespaceURI !== "http://www.w3.org/1999/xhtml")
|
|
1160
|
+
throw injectedScript.createStacklessError("Node is not an HTMLElement");
|
|
1200
1161
|
return element.innerText;
|
|
1201
|
-
},
|
|
1162
|
+
}, void 0, options, scope);
|
|
1202
1163
|
}
|
|
1203
1164
|
async innerHTML(metadata, selector, options = {}, scope) {
|
|
1204
|
-
return this._callOnElementOnceMatches(metadata, selector, (injected, element) => element.innerHTML,
|
|
1165
|
+
return this._callOnElementOnceMatches(metadata, selector, (injected, element) => element.innerHTML, void 0, options, scope);
|
|
1205
1166
|
}
|
|
1206
1167
|
async getAttribute(metadata, selector, name, options = {}, scope) {
|
|
1207
|
-
return this._callOnElementOnceMatches(metadata, selector, (injected, element, data) => element.getAttribute(data.name), {
|
|
1208
|
-
name
|
|
1209
|
-
}, options, scope);
|
|
1168
|
+
return this._callOnElementOnceMatches(metadata, selector, (injected, element, data) => element.getAttribute(data.name), { name }, options, scope);
|
|
1210
1169
|
}
|
|
1211
1170
|
async inputValue(metadata, selector, options = {}, scope) {
|
|
1212
1171
|
return this._callOnElementOnceMatches(metadata, selector, (injectedScript, node) => {
|
|
1213
|
-
const element = injectedScript.retarget(node,
|
|
1214
|
-
if (!element || element.nodeName !==
|
|
1172
|
+
const element = injectedScript.retarget(node, "follow-label");
|
|
1173
|
+
if (!element || element.nodeName !== "INPUT" && element.nodeName !== "TEXTAREA" && element.nodeName !== "SELECT")
|
|
1174
|
+
throw injectedScript.createStacklessError("Node is not an <input>, <textarea> or <select> element");
|
|
1215
1175
|
return element.value;
|
|
1216
|
-
},
|
|
1176
|
+
}, void 0, options, scope);
|
|
1217
1177
|
}
|
|
1218
1178
|
async highlight(selector) {
|
|
1219
1179
|
const resolved = await this.selectors.resolveInjectedForSelector(selector);
|
|
1220
|
-
if (!resolved)
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
}) => {
|
|
1180
|
+
if (!resolved)
|
|
1181
|
+
return;
|
|
1182
|
+
return await resolved.injected.evaluate((injected, { info }) => {
|
|
1224
1183
|
return injected.highlight(info.parsed);
|
|
1225
|
-
}, {
|
|
1226
|
-
info: resolved.info
|
|
1227
|
-
});
|
|
1184
|
+
}, { info: resolved.info });
|
|
1228
1185
|
}
|
|
1229
1186
|
async hideHighlight() {
|
|
1230
1187
|
return this.raceAgainstEvaluationStallingEvents(async () => {
|
|
1231
1188
|
const context = await this._utilityContext();
|
|
1232
1189
|
const injectedScript = await context.injectedScript();
|
|
1233
|
-
return await injectedScript.evaluate(injected => {
|
|
1190
|
+
return await injectedScript.evaluate((injected) => {
|
|
1234
1191
|
return injected.hideHighlight();
|
|
1235
1192
|
});
|
|
1236
1193
|
});
|
|
@@ -1238,248 +1195,189 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1238
1195
|
async _elementState(metadata, selector, state, options = {}, scope) {
|
|
1239
1196
|
const result = await this._callOnElementOnceMatches(metadata, selector, (injected, element, data) => {
|
|
1240
1197
|
return injected.elementState(element, data.state);
|
|
1241
|
-
}, {
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
if (result.received === 'error:notconnected') dom.throwElementIsNotAttached();
|
|
1198
|
+
}, { state }, options, scope);
|
|
1199
|
+
if (result.received === "error:notconnected")
|
|
1200
|
+
dom.throwElementIsNotAttached();
|
|
1245
1201
|
return result.matches;
|
|
1246
1202
|
}
|
|
1247
1203
|
async isVisible(metadata, selector, options = {}, scope) {
|
|
1248
|
-
const controller = new
|
|
1249
|
-
return controller.run(async progress => {
|
|
1204
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1205
|
+
return controller.run(async (progress) => {
|
|
1250
1206
|
progress.log(` checking visibility of ${this._asLocator(selector)}`);
|
|
1251
1207
|
return await this.isVisibleInternal(selector, options, scope);
|
|
1252
1208
|
}, this._page._timeoutSettings.timeout({}));
|
|
1253
1209
|
}
|
|
1254
1210
|
async isVisibleInternal(selector, options = {}, scope) {
|
|
1255
1211
|
try {
|
|
1256
|
-
const custom_metadata = {
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
};
|
|
1260
|
-
const controller = new _progress2.ProgressController(custom_metadata, this);
|
|
1261
|
-
return await controller.run(async progress => {
|
|
1212
|
+
const custom_metadata = { "internal": false, "log": [] };
|
|
1213
|
+
const controller = new import_progress.ProgressController(custom_metadata, this);
|
|
1214
|
+
return await controller.run(async (progress) => {
|
|
1262
1215
|
progress.log("waiting for " + this._asLocator(selector));
|
|
1263
|
-
const promise = this._retryWithProgressIfNotConnected(progress, selector, options.strict, false, async handle => {
|
|
1216
|
+
const promise = this._retryWithProgressIfNotConnected(progress, selector, options.strict, false, async (handle) => {
|
|
1264
1217
|
if (handle.parentNode.constructor.name == "ElementHandle") {
|
|
1265
|
-
return await handle.parentNode.evaluateInUtility(([injected, node, {
|
|
1266
|
-
|
|
1267
|
-
}]) => {
|
|
1268
|
-
const state = handle ? injected.elementState(handle, 'visible') : {
|
|
1218
|
+
return await handle.parentNode.evaluateInUtility(([injected, node, { handle: handle2 }]) => {
|
|
1219
|
+
const state = handle2 ? injected.elementState(handle2, "visible") : {
|
|
1269
1220
|
matches: false,
|
|
1270
|
-
received:
|
|
1221
|
+
received: "error:notconnected"
|
|
1271
1222
|
};
|
|
1272
1223
|
return state.matches;
|
|
1273
|
-
}, {
|
|
1274
|
-
handle
|
|
1275
|
-
});
|
|
1224
|
+
}, { handle });
|
|
1276
1225
|
} else {
|
|
1277
|
-
return await handle.parentNode.evaluate((injected, {
|
|
1278
|
-
|
|
1279
|
-
}) => {
|
|
1280
|
-
const state = handle ? injected.elementState(handle, 'visible') : {
|
|
1226
|
+
return await handle.parentNode.evaluate((injected, { handle: handle2 }) => {
|
|
1227
|
+
const state = handle2 ? injected.elementState(handle2, "visible") : {
|
|
1281
1228
|
matches: false,
|
|
1282
|
-
received:
|
|
1229
|
+
received: "error:notconnected"
|
|
1283
1230
|
};
|
|
1284
1231
|
return state.matches;
|
|
1285
|
-
}, {
|
|
1286
|
-
handle
|
|
1287
|
-
});
|
|
1232
|
+
}, { handle });
|
|
1288
1233
|
}
|
|
1289
1234
|
});
|
|
1290
1235
|
return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;
|
|
1291
|
-
}, 100);
|
|
1236
|
+
}, 100);
|
|
1292
1237
|
} catch (e) {
|
|
1293
|
-
if (js.isJavaScriptErrorInEvaluate(e) || (0,
|
|
1238
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_selectorParser.isInvalidSelectorError)(e) || (0, import_protocolError.isSessionClosedError)(e)) throw e;
|
|
1294
1239
|
return false;
|
|
1295
1240
|
}
|
|
1296
1241
|
}
|
|
1297
1242
|
async isHidden(metadata, selector, options = {}, scope) {
|
|
1298
|
-
return !
|
|
1243
|
+
return !await this.isVisible(metadata, selector, options, scope);
|
|
1299
1244
|
}
|
|
1300
1245
|
async isDisabled(metadata, selector, options = {}, scope) {
|
|
1301
|
-
return this._elementState(metadata, selector,
|
|
1246
|
+
return this._elementState(metadata, selector, "disabled", options, scope);
|
|
1302
1247
|
}
|
|
1303
1248
|
async isEnabled(metadata, selector, options = {}, scope) {
|
|
1304
|
-
return this._elementState(metadata, selector,
|
|
1249
|
+
return this._elementState(metadata, selector, "enabled", options, scope);
|
|
1305
1250
|
}
|
|
1306
1251
|
async isEditable(metadata, selector, options = {}, scope) {
|
|
1307
|
-
return this._elementState(metadata, selector,
|
|
1252
|
+
return this._elementState(metadata, selector, "editable", options, scope);
|
|
1308
1253
|
}
|
|
1309
1254
|
async isChecked(metadata, selector, options = {}, scope) {
|
|
1310
|
-
return this._elementState(metadata, selector,
|
|
1255
|
+
return this._elementState(metadata, selector, "checked", options, scope);
|
|
1311
1256
|
}
|
|
1312
1257
|
async hover(metadata, selector, options = {}) {
|
|
1313
|
-
const controller = new
|
|
1314
|
-
return controller.run(async progress => {
|
|
1315
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force
|
|
1258
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1259
|
+
return controller.run(async (progress) => {
|
|
1260
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._hover(progress, options)));
|
|
1316
1261
|
}, this._page._timeoutSettings.timeout(options));
|
|
1317
1262
|
}
|
|
1318
1263
|
async selectOption(metadata, selector, elements, values, options = {}) {
|
|
1319
|
-
const controller = new
|
|
1320
|
-
return controller.run(async progress => {
|
|
1321
|
-
return await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force
|
|
1264
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1265
|
+
return controller.run(async (progress) => {
|
|
1266
|
+
return await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._selectOption(progress, elements, values, options));
|
|
1322
1267
|
}, this._page._timeoutSettings.timeout(options));
|
|
1323
1268
|
}
|
|
1324
1269
|
async setInputFiles(metadata, selector, params) {
|
|
1325
|
-
const inputFileItems = await (0,
|
|
1326
|
-
const controller = new
|
|
1327
|
-
return controller.run(async progress => {
|
|
1328
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, params.strict, true
|
|
1270
|
+
const inputFileItems = await (0, import_fileUploadUtils.prepareFilesForUpload)(this, params);
|
|
1271
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1272
|
+
return controller.run(async (progress) => {
|
|
1273
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, params.strict, true, (handle) => handle._setInputFiles(progress, inputFileItems)));
|
|
1329
1274
|
}, this._page._timeoutSettings.timeout(params));
|
|
1330
1275
|
}
|
|
1331
1276
|
async type(metadata, selector, text, options = {}) {
|
|
1332
|
-
const controller = new
|
|
1333
|
-
return controller.run(async progress => {
|
|
1334
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true
|
|
1277
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1278
|
+
return controller.run(async (progress) => {
|
|
1279
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle) => handle._type(progress, text, options)));
|
|
1335
1280
|
}, this._page._timeoutSettings.timeout(options));
|
|
1336
1281
|
}
|
|
1337
1282
|
async press(metadata, selector, key, options = {}) {
|
|
1338
|
-
const controller = new
|
|
1339
|
-
return controller.run(async progress => {
|
|
1340
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true
|
|
1283
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1284
|
+
return controller.run(async (progress) => {
|
|
1285
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true, (handle) => handle._press(progress, key, options)));
|
|
1341
1286
|
}, this._page._timeoutSettings.timeout(options));
|
|
1342
1287
|
}
|
|
1343
1288
|
async check(metadata, selector, options = {}) {
|
|
1344
|
-
const controller = new
|
|
1345
|
-
return controller.run(async progress => {
|
|
1346
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force
|
|
1289
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1290
|
+
return controller.run(async (progress) => {
|
|
1291
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._setChecked(progress, true, options)));
|
|
1347
1292
|
}, this._page._timeoutSettings.timeout(options));
|
|
1348
1293
|
}
|
|
1349
1294
|
async uncheck(metadata, selector, options = {}) {
|
|
1350
|
-
const controller = new
|
|
1351
|
-
return controller.run(async progress => {
|
|
1352
|
-
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force
|
|
1295
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1296
|
+
return controller.run(async (progress) => {
|
|
1297
|
+
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force, (handle) => handle._setChecked(progress, false, options)));
|
|
1353
1298
|
}, this._page._timeoutSettings.timeout(options));
|
|
1354
1299
|
}
|
|
1355
1300
|
async waitForTimeout(metadata, timeout) {
|
|
1356
|
-
const controller = new
|
|
1301
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1357
1302
|
return controller.run(async () => {
|
|
1358
|
-
await new Promise(resolve => setTimeout(resolve, timeout));
|
|
1303
|
+
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
1359
1304
|
});
|
|
1360
1305
|
}
|
|
1361
1306
|
async ariaSnapshot(metadata, selector, options = {}) {
|
|
1362
|
-
const controller = new
|
|
1363
|
-
return controller.run(async progress => {
|
|
1364
|
-
return await this._retryWithProgressIfNotConnected(progress, selector, true
|
|
1307
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1308
|
+
return controller.run(async (progress) => {
|
|
1309
|
+
return await this._retryWithProgressIfNotConnected(progress, selector, true, true, (handle) => handle.ariaSnapshot(options));
|
|
1365
1310
|
}, this._page._timeoutSettings.timeout(options));
|
|
1366
1311
|
}
|
|
1367
1312
|
async expect(metadata, selector, options) {
|
|
1368
1313
|
const result = await this._expectImpl(metadata, selector, options);
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
error: {
|
|
1372
|
-
name: 'Expect',
|
|
1373
|
-
message: 'Expect failed'
|
|
1374
|
-
}
|
|
1375
|
-
};
|
|
1314
|
+
if (result.matches === options.isNot)
|
|
1315
|
+
metadata.error = { error: { name: "Expect", message: "Expect failed" } };
|
|
1376
1316
|
return result;
|
|
1377
1317
|
}
|
|
1378
1318
|
async _expectImpl(metadata, selector, options) {
|
|
1379
|
-
const lastIntermediateResult = {
|
|
1380
|
-
isSet: false
|
|
1381
|
-
};
|
|
1319
|
+
const lastIntermediateResult = { isSet: false };
|
|
1382
1320
|
try {
|
|
1383
1321
|
let timeout = this._page._timeoutSettings.timeout(options);
|
|
1384
|
-
const start = timeout > 0 ? (0,
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
await new _progress2.ProgressController(metadata, this).run(async progress => {
|
|
1388
|
-
progress.log(`${metadata.apiName}${timeout ? ` with timeout ${timeout}ms` : ''}`);
|
|
1322
|
+
const start = timeout > 0 ? (0, import_utils.monotonicTime)() : 0;
|
|
1323
|
+
await new import_progress.ProgressController(metadata, this).run(async (progress) => {
|
|
1324
|
+
progress.log(`${metadata.apiName}${timeout ? ` with timeout ${timeout}ms` : ""}`);
|
|
1389
1325
|
progress.log(`waiting for ${this._asLocator(selector)}`);
|
|
1390
1326
|
await this._page.performActionPreChecks(progress);
|
|
1391
1327
|
}, timeout);
|
|
1392
|
-
|
|
1393
|
-
// Step 2: perform one-shot expect check without a timeout.
|
|
1394
|
-
// Supports the case of `expect(locator).toBeVisible({ timeout: 1 })`
|
|
1395
|
-
// that should succeed when the locator is already visible.
|
|
1396
1328
|
try {
|
|
1397
|
-
const resultOneShot = await new
|
|
1329
|
+
const resultOneShot = await new import_progress.ProgressController(metadata, this).run(async (progress) => {
|
|
1398
1330
|
return await this._expectInternal(progress, selector, options, lastIntermediateResult);
|
|
1399
1331
|
});
|
|
1400
|
-
if (resultOneShot.matches !== options.isNot)
|
|
1332
|
+
if (resultOneShot.matches !== options.isNot)
|
|
1333
|
+
return resultOneShot;
|
|
1401
1334
|
} catch (e) {
|
|
1402
|
-
if (js.isJavaScriptErrorInEvaluate(e) || (0,
|
|
1403
|
-
|
|
1335
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_selectorParser.isInvalidSelectorError)(e))
|
|
1336
|
+
throw e;
|
|
1404
1337
|
}
|
|
1405
1338
|
if (timeout > 0) {
|
|
1406
|
-
const elapsed = (0,
|
|
1339
|
+
const elapsed = (0, import_utils.monotonicTime)() - start;
|
|
1407
1340
|
timeout -= elapsed;
|
|
1408
1341
|
}
|
|
1409
|
-
if (timeout < 0)
|
|
1410
|
-
matches: options.isNot,
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
received: lastIntermediateResult.received
|
|
1414
|
-
};
|
|
1415
|
-
|
|
1416
|
-
// Step 3: auto-retry expect with increasing timeouts. Bounded by the total remaining time.
|
|
1417
|
-
return await new _progress2.ProgressController(metadata, this).run(async progress => {
|
|
1418
|
-
return await this.retryWithProgressAndTimeouts(progress, [100, 250, 500, 1000], async continuePolling => {
|
|
1342
|
+
if (timeout < 0)
|
|
1343
|
+
return { matches: options.isNot, log: (0, import_callLog.compressCallLog)(metadata.log), timedOut: true, received: lastIntermediateResult.received };
|
|
1344
|
+
return await new import_progress.ProgressController(metadata, this).run(async (progress) => {
|
|
1345
|
+
return await this.retryWithProgressAndTimeouts(progress, [100, 250, 500, 1e3], async (continuePolling2) => {
|
|
1419
1346
|
await this._page.performActionPreChecks(progress);
|
|
1420
|
-
const {
|
|
1421
|
-
matches,
|
|
1422
|
-
received
|
|
1423
|
-
} = await this._expectInternal(progress, selector, options, lastIntermediateResult);
|
|
1347
|
+
const { matches, received } = await this._expectInternal(progress, selector, options, lastIntermediateResult);
|
|
1424
1348
|
if (matches === options.isNot) {
|
|
1425
|
-
|
|
1426
|
-
// expect(locator).conditionThatDoesNotMatch
|
|
1427
|
-
// expect(locator).not.conditionThatDoesMatch
|
|
1428
|
-
return continuePolling;
|
|
1349
|
+
return continuePolling2;
|
|
1429
1350
|
}
|
|
1430
|
-
return {
|
|
1431
|
-
matches,
|
|
1432
|
-
received
|
|
1433
|
-
};
|
|
1351
|
+
return { matches, received };
|
|
1434
1352
|
});
|
|
1435
1353
|
}, timeout);
|
|
1436
1354
|
} catch (e) {
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
if (lastIntermediateResult.isSet) result.received = lastIntermediateResult.received;
|
|
1445
|
-
if (e instanceof _errors.TimeoutError) result.timedOut = true;
|
|
1355
|
+
if (js.isJavaScriptErrorInEvaluate(e) || (0, import_selectorParser.isInvalidSelectorError)(e))
|
|
1356
|
+
throw e;
|
|
1357
|
+
const result = { matches: options.isNot, log: (0, import_callLog.compressCallLog)(metadata.log) };
|
|
1358
|
+
if (lastIntermediateResult.isSet)
|
|
1359
|
+
result.received = lastIntermediateResult.received;
|
|
1360
|
+
if (e instanceof import_errors.TimeoutError)
|
|
1361
|
+
result.timedOut = true;
|
|
1446
1362
|
return result;
|
|
1447
1363
|
}
|
|
1448
1364
|
}
|
|
1449
1365
|
async _expectInternal(progress, selector, options, lastIntermediateResult) {
|
|
1450
1366
|
progress.log("waiting for " + this._asLocator(selector));
|
|
1451
|
-
const isArray = options.expression ===
|
|
1452
|
-
const promise = await this._retryWithProgressIfNotConnected(progress, selector, !isArray, false, async result => {
|
|
1367
|
+
const isArray = options.expression === "to.have.count" || options.expression.endsWith(".array");
|
|
1368
|
+
const promise = await this._retryWithProgressIfNotConnected(progress, selector, !isArray, false, async (result) => {
|
|
1453
1369
|
const handle = result[0];
|
|
1454
1370
|
const handles = result[1];
|
|
1455
1371
|
if (handle.parentNode.constructor.name == "ElementHandle") {
|
|
1456
|
-
return await handle.parentNode.evaluateInUtility(async ([injected, node, {
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
handles
|
|
1460
|
-
}]) => {
|
|
1461
|
-
return await injected.expect(handle, options, handles);
|
|
1462
|
-
}, {
|
|
1463
|
-
handle,
|
|
1464
|
-
options,
|
|
1465
|
-
handles
|
|
1466
|
-
});
|
|
1372
|
+
return await handle.parentNode.evaluateInUtility(async ([injected, node, { handle: handle2, options: options2, handles: handles2 }]) => {
|
|
1373
|
+
return await injected.expect(handle2, options2, handles2);
|
|
1374
|
+
}, { handle, options, handles });
|
|
1467
1375
|
} else {
|
|
1468
|
-
return await handle.parentNode.evaluate(async (injected, {
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
handles
|
|
1472
|
-
}) => {
|
|
1473
|
-
return await injected.expect(handle, options, handles);
|
|
1474
|
-
}, {
|
|
1475
|
-
handle,
|
|
1476
|
-
options,
|
|
1477
|
-
handles
|
|
1478
|
-
});
|
|
1376
|
+
return await handle.parentNode.evaluate(async (injected, { handle: handle2, options: options2, handles: handles2 }) => {
|
|
1377
|
+
return await injected.expect(handle2, options2, handles2);
|
|
1378
|
+
}, { handle, options, handles });
|
|
1479
1379
|
}
|
|
1480
|
-
},
|
|
1481
|
-
|
|
1482
|
-
// Default Values, if no Elements found
|
|
1380
|
+
}, "returnAll");
|
|
1483
1381
|
var matches = false;
|
|
1484
1382
|
var received = 0;
|
|
1485
1383
|
var missingReceived = null;
|
|
@@ -1490,10 +1388,8 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1490
1388
|
} else if (options.expectedNumber === 0) {
|
|
1491
1389
|
matches = true;
|
|
1492
1390
|
}
|
|
1493
|
-
|
|
1494
|
-
// Note: missingReceived avoids unexpected value "undefined" when element was not found.
|
|
1495
1391
|
if (matches === options.isNot) {
|
|
1496
|
-
lastIntermediateResult.received = missingReceived ?
|
|
1392
|
+
lastIntermediateResult.received = missingReceived ? "<element(s) not found>" : received;
|
|
1497
1393
|
lastIntermediateResult.isSet = true;
|
|
1498
1394
|
if (!missingReceived && !Array.isArray(received)) progress.log(' unexpected value "' + renderUnexpectedValue(options.expression, received) + '"');
|
|
1499
1395
|
}
|
|
@@ -1502,34 +1398,27 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1502
1398
|
received
|
|
1503
1399
|
};
|
|
1504
1400
|
}
|
|
1505
|
-
async _waitForFunctionExpression(metadata, expression, isFunction, arg, options, world =
|
|
1506
|
-
const controller = new
|
|
1507
|
-
if (typeof options.pollingInterval ===
|
|
1401
|
+
async _waitForFunctionExpression(metadata, expression, isFunction, arg, options, world = "main") {
|
|
1402
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1403
|
+
if (typeof options.pollingInterval === "number")
|
|
1404
|
+
(0, import_utils.assert)(options.pollingInterval > 0, "Cannot poll with non-positive interval: " + options.pollingInterval);
|
|
1508
1405
|
expression = js.normalizeEvaluationExpression(expression, isFunction);
|
|
1509
|
-
return controller.run(async progress => {
|
|
1406
|
+
return controller.run(async (progress) => {
|
|
1510
1407
|
return this.retryWithProgressAndTimeouts(progress, [100], async () => {
|
|
1511
|
-
const context = world ===
|
|
1408
|
+
const context = world === "main" ? await this._mainContext() : await this._utilityContext();
|
|
1512
1409
|
const injectedScript = await context.injectedScript();
|
|
1513
|
-
const handle = await injectedScript.evaluateHandle((injected, {
|
|
1514
|
-
expression,
|
|
1515
|
-
isFunction,
|
|
1516
|
-
polling,
|
|
1517
|
-
arg
|
|
1518
|
-
}) => {
|
|
1410
|
+
const handle = await injectedScript.evaluateHandle((injected, { expression: expression2, isFunction: isFunction2, polling, arg: arg2 }) => {
|
|
1519
1411
|
const predicate = () => {
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
result = result(arg);
|
|
1526
|
-
} else if (isFunction === false) {
|
|
1527
|
-
result = result;
|
|
1412
|
+
let result2 = globalThis.eval(expression2);
|
|
1413
|
+
if (isFunction2 === true) {
|
|
1414
|
+
result2 = result2(arg2);
|
|
1415
|
+
} else if (isFunction2 === false) {
|
|
1416
|
+
result2 = result2;
|
|
1528
1417
|
} else {
|
|
1529
|
-
|
|
1530
|
-
|
|
1418
|
+
if (typeof result2 === "function")
|
|
1419
|
+
result2 = result2(arg2);
|
|
1531
1420
|
}
|
|
1532
|
-
return
|
|
1421
|
+
return result2;
|
|
1533
1422
|
};
|
|
1534
1423
|
let fulfill;
|
|
1535
1424
|
let reject;
|
|
@@ -1539,31 +1428,28 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1539
1428
|
reject = r;
|
|
1540
1429
|
});
|
|
1541
1430
|
const next = () => {
|
|
1542
|
-
if (aborted)
|
|
1431
|
+
if (aborted)
|
|
1432
|
+
return;
|
|
1543
1433
|
try {
|
|
1544
1434
|
const success = predicate();
|
|
1545
1435
|
if (success) {
|
|
1546
1436
|
fulfill(success);
|
|
1547
1437
|
return;
|
|
1548
1438
|
}
|
|
1549
|
-
if (typeof polling !==
|
|
1439
|
+
if (typeof polling !== "number")
|
|
1440
|
+
injected.utils.builtins.requestAnimationFrame(next);
|
|
1441
|
+
else
|
|
1442
|
+
injected.utils.builtins.setTimeout(next, polling);
|
|
1550
1443
|
} catch (e) {
|
|
1551
1444
|
reject(e);
|
|
1552
1445
|
}
|
|
1553
1446
|
};
|
|
1554
1447
|
next();
|
|
1555
|
-
return {
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
expression,
|
|
1561
|
-
isFunction,
|
|
1562
|
-
polling: options.pollingInterval,
|
|
1563
|
-
arg
|
|
1564
|
-
});
|
|
1565
|
-
progress.cleanupWhenAborted(() => handle.evaluate(h => h.abort()).catch(() => {}));
|
|
1566
|
-
return handle.evaluateHandle(h => h.result);
|
|
1448
|
+
return { result, abort: () => aborted = true };
|
|
1449
|
+
}, { expression, isFunction, polling: options.pollingInterval, arg });
|
|
1450
|
+
progress.cleanupWhenAborted(() => handle.evaluate((h) => h.abort()).catch(() => {
|
|
1451
|
+
}));
|
|
1452
|
+
return handle.evaluateHandle((h) => h.result);
|
|
1567
1453
|
});
|
|
1568
1454
|
}, this._page._timeoutSettings.timeout(options));
|
|
1569
1455
|
}
|
|
@@ -1574,9 +1460,7 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1574
1460
|
return result;
|
|
1575
1461
|
return JSON.stringify(result);
|
|
1576
1462
|
}`;
|
|
1577
|
-
const handle = await this._waitForFunctionExpression((0,
|
|
1578
|
-
timeout: progress.timeUntilDeadline()
|
|
1579
|
-
}, 'utility');
|
|
1463
|
+
const handle = await this._waitForFunctionExpression((0, import_instrumentation.serverSideCallMetadata)(), expression, true, void 0, { timeout: progress.timeUntilDeadline() }, "utility");
|
|
1580
1464
|
return JSON.parse(handle.rawValue());
|
|
1581
1465
|
}
|
|
1582
1466
|
async title() {
|
|
@@ -1584,55 +1468,50 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1584
1468
|
return context.evaluate(() => document.title);
|
|
1585
1469
|
}
|
|
1586
1470
|
async rafrafTimeout(timeout) {
|
|
1587
|
-
if (timeout === 0)
|
|
1471
|
+
if (timeout === 0)
|
|
1472
|
+
return;
|
|
1588
1473
|
const context = await this._utilityContext();
|
|
1589
1474
|
await Promise.all([
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1475
|
+
// wait for double raf
|
|
1476
|
+
context.evaluate(() => new Promise((x) => {
|
|
1477
|
+
requestAnimationFrame(() => {
|
|
1478
|
+
requestAnimationFrame(x);
|
|
1479
|
+
});
|
|
1480
|
+
})),
|
|
1481
|
+
new Promise((fulfill) => setTimeout(fulfill, timeout))
|
|
1482
|
+
]);
|
|
1596
1483
|
}
|
|
1597
1484
|
_onDetached() {
|
|
1598
1485
|
this._stopNetworkIdleTimer();
|
|
1599
|
-
this._detachedScope.close(new Error(
|
|
1486
|
+
this._detachedScope.close(new Error("Frame was detached"));
|
|
1600
1487
|
for (const data of this._contextData.values()) {
|
|
1601
|
-
if (data.context)
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
});
|
|
1488
|
+
if (data.context)
|
|
1489
|
+
data.context.contextDestroyed("Frame was detached");
|
|
1490
|
+
data.contextPromise.resolve({ destroyedReason: "Frame was detached" });
|
|
1605
1491
|
}
|
|
1606
|
-
if (this._parentFrame)
|
|
1492
|
+
if (this._parentFrame)
|
|
1493
|
+
this._parentFrame._childFrames.delete(this);
|
|
1607
1494
|
this._parentFrame = null;
|
|
1608
1495
|
}
|
|
1609
1496
|
async _callOnElementOnceMatches(metadata, selector, body, taskData, options = {}, scope) {
|
|
1610
1497
|
const callbackText = body.toString();
|
|
1611
|
-
const controller = new
|
|
1612
|
-
return controller.run(async progress => {
|
|
1498
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
1499
|
+
return controller.run(async (progress) => {
|
|
1613
1500
|
progress.log("waiting for " + this._asLocator(selector));
|
|
1614
|
-
const promise = this._retryWithProgressIfNotConnected(progress, selector, false, false, async handle => {
|
|
1501
|
+
const promise = this._retryWithProgressIfNotConnected(progress, selector, false, false, async (handle) => {
|
|
1615
1502
|
if (handle.parentNode.constructor.name == "ElementHandle") {
|
|
1616
|
-
return await handle.parentNode.evaluateInUtility(([injected, node, {
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
taskData
|
|
1620
|
-
}]) => {
|
|
1621
|
-
const callback = injected.eval(callbackText);
|
|
1622
|
-
return callback(injected, handle, taskData);
|
|
1503
|
+
return await handle.parentNode.evaluateInUtility(([injected, node, { callbackText: callbackText2, handle: handle2, taskData: taskData2 }]) => {
|
|
1504
|
+
const callback = injected.eval(callbackText2);
|
|
1505
|
+
return callback(injected, handle2, taskData2);
|
|
1623
1506
|
}, {
|
|
1624
1507
|
callbackText,
|
|
1625
1508
|
handle,
|
|
1626
1509
|
taskData
|
|
1627
1510
|
});
|
|
1628
1511
|
} else {
|
|
1629
|
-
return await handle.parentNode.evaluate((injected, {
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
taskData
|
|
1633
|
-
}) => {
|
|
1634
|
-
const callback = injected.eval(callbackText);
|
|
1635
|
-
return callback(injected, handle, taskData);
|
|
1512
|
+
return await handle.parentNode.evaluate((injected, { callbackText: callbackText2, handle: handle2, taskData: taskData2 }) => {
|
|
1513
|
+
const callback = injected.eval(callbackText2);
|
|
1514
|
+
return callback(injected, handle2, taskData2);
|
|
1636
1515
|
}, {
|
|
1637
1516
|
callbackText,
|
|
1638
1517
|
handle,
|
|
@@ -1646,98 +1525,79 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1646
1525
|
_setContext(world, context) {
|
|
1647
1526
|
const data = this._contextData.get(world);
|
|
1648
1527
|
data.context = context;
|
|
1649
|
-
if (context)
|
|
1528
|
+
if (context)
|
|
1529
|
+
data.contextPromise.resolve(context);
|
|
1530
|
+
else
|
|
1531
|
+
data.contextPromise = new import_manualPromise.ManualPromise();
|
|
1650
1532
|
}
|
|
1651
1533
|
_contextCreated(world, context) {
|
|
1652
1534
|
const data = this._contextData.get(world);
|
|
1653
|
-
// In case of multiple sessions to the same target, there's a race between
|
|
1654
|
-
// connections so we might end up creating multiple isolated worlds.
|
|
1655
|
-
// We can use either.
|
|
1656
1535
|
if (data.context) {
|
|
1657
|
-
data.context.contextDestroyed(
|
|
1536
|
+
data.context.contextDestroyed("Execution context was destroyed, most likely because of a navigation");
|
|
1658
1537
|
this._setContext(world, null);
|
|
1659
1538
|
}
|
|
1660
1539
|
this._setContext(world, context);
|
|
1661
1540
|
}
|
|
1662
1541
|
_contextDestroyed(context) {
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
context.contextDestroyed('Execution context was destroyed, most likely because of a navigation');
|
|
1542
|
+
if (this._detachedScope.isClosed())
|
|
1543
|
+
return;
|
|
1544
|
+
context.contextDestroyed("Execution context was destroyed, most likely because of a navigation");
|
|
1667
1545
|
for (const [world, data] of this._contextData) {
|
|
1668
|
-
if (data.context === context)
|
|
1546
|
+
if (data.context === context)
|
|
1547
|
+
this._setContext(world, null);
|
|
1669
1548
|
}
|
|
1670
1549
|
}
|
|
1671
1550
|
_startNetworkIdleTimer() {
|
|
1672
|
-
(0,
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
// after the frame was detached - probably a race in the Firefox itself.
|
|
1676
|
-
if (this._firedLifecycleEvents.has('networkidle') || this._detachedScope.isClosed()) return;
|
|
1551
|
+
(0, import_utils.assert)(!this._networkIdleTimer);
|
|
1552
|
+
if (this._firedLifecycleEvents.has("networkidle") || this._detachedScope.isClosed())
|
|
1553
|
+
return;
|
|
1677
1554
|
this._networkIdleTimer = setTimeout(() => {
|
|
1678
1555
|
this._firedNetworkIdleSelf = true;
|
|
1679
1556
|
this._page.mainFrame()._recalculateNetworkIdle();
|
|
1680
1557
|
}, 500);
|
|
1681
1558
|
}
|
|
1682
1559
|
_stopNetworkIdleTimer() {
|
|
1683
|
-
if (this._networkIdleTimer)
|
|
1684
|
-
|
|
1560
|
+
if (this._networkIdleTimer)
|
|
1561
|
+
clearTimeout(this._networkIdleTimer);
|
|
1562
|
+
this._networkIdleTimer = void 0;
|
|
1685
1563
|
this._firedNetworkIdleSelf = false;
|
|
1686
1564
|
}
|
|
1687
1565
|
async extendInjectedScript(source, arg) {
|
|
1688
|
-
const context = await this._context(
|
|
1566
|
+
const context = await this._context("main");
|
|
1689
1567
|
const injectedScriptHandle = await context.injectedScript();
|
|
1690
|
-
return injectedScriptHandle.evaluateHandle((injectedScript, {
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
}) => {
|
|
1694
|
-
return injectedScript.extend(source, arg);
|
|
1695
|
-
}, {
|
|
1696
|
-
source,
|
|
1697
|
-
arg
|
|
1698
|
-
});
|
|
1568
|
+
return injectedScriptHandle.evaluateHandle((injectedScript, { source: source2, arg: arg2 }) => {
|
|
1569
|
+
return injectedScript.extend(source2, arg2);
|
|
1570
|
+
}, { source, arg });
|
|
1699
1571
|
}
|
|
1700
1572
|
async resetStorageForCurrentOriginBestEffort(newStorage) {
|
|
1701
1573
|
const context = await this._utilityContext();
|
|
1702
|
-
await context.evaluate(async ({
|
|
1703
|
-
ls
|
|
1704
|
-
}) => {
|
|
1705
|
-
// Clean DOMStorage.
|
|
1574
|
+
await context.evaluate(async ({ ls }) => {
|
|
1706
1575
|
sessionStorage.clear();
|
|
1707
1576
|
localStorage.clear();
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
for (const entry of ls || []) localStorage[entry.name] = entry.value;
|
|
1711
|
-
|
|
1712
|
-
// Clean Service Workers
|
|
1577
|
+
for (const entry of ls || [])
|
|
1578
|
+
localStorage[entry.name] = entry.value;
|
|
1713
1579
|
const registrations = navigator.serviceWorker ? await navigator.serviceWorker.getRegistrations() : [];
|
|
1714
|
-
await Promise.all(registrations.map(async r => {
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1580
|
+
await Promise.all(registrations.map(async (r) => {
|
|
1581
|
+
if (!r.installing && !r.waiting && !r.active)
|
|
1582
|
+
r.unregister().catch(() => {
|
|
1583
|
+
});
|
|
1584
|
+
else
|
|
1585
|
+
await r.unregister().catch(() => {
|
|
1586
|
+
});
|
|
1721
1587
|
}));
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
var _indexedDB$databases, _indexedDB;
|
|
1726
|
-
// Do not wait for the callback - it is called on timer in Chromium (slow).
|
|
1727
|
-
if (db.name) indexedDB.deleteDatabase(db.name);
|
|
1588
|
+
for (const db of await indexedDB.databases?.() || []) {
|
|
1589
|
+
if (db.name)
|
|
1590
|
+
indexedDB.deleteDatabase(db.name);
|
|
1728
1591
|
}
|
|
1729
|
-
}, {
|
|
1730
|
-
|
|
1731
|
-
}).catch(() => {});
|
|
1592
|
+
}, { ls: newStorage?.localStorage }).catch(() => {
|
|
1593
|
+
});
|
|
1732
1594
|
}
|
|
1733
1595
|
_asLocator(selector) {
|
|
1734
|
-
return (0,
|
|
1596
|
+
return (0, import_utils.asLocator)(this._page.attribution.playwright.options.sdkLanguage, selector);
|
|
1735
1597
|
}
|
|
1736
1598
|
async _getFrameMainFrameContextId(client) {
|
|
1737
1599
|
try {
|
|
1738
|
-
var globalDocument = await client._sendMayFail("DOM.getFrameOwner", {
|
|
1739
|
-
frameId: this._id
|
|
1740
|
-
});
|
|
1600
|
+
var globalDocument = await client._sendMayFail("DOM.getFrameOwner", { frameId: this._id });
|
|
1741
1601
|
if (globalDocument && globalDocument.nodeId) {
|
|
1742
1602
|
var describedNode = await client._sendMayFail("DOM.describeNode", {
|
|
1743
1603
|
backendNodeId: globalDocument.backendNodeId
|
|
@@ -1750,20 +1610,17 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1750
1610
|
return _executionContextId;
|
|
1751
1611
|
}
|
|
1752
1612
|
}
|
|
1753
|
-
} catch (e) {
|
|
1613
|
+
} catch (e) {
|
|
1614
|
+
}
|
|
1754
1615
|
return 0;
|
|
1755
1616
|
}
|
|
1756
1617
|
async _customFindElementsByParsed(resolved, client, context, documentScope, progress, parsed) {
|
|
1757
|
-
var parsedEdits = {
|
|
1758
|
-
...parsed
|
|
1759
|
-
};
|
|
1760
|
-
// Note: We start scoping at document level
|
|
1618
|
+
var parsedEdits = { ...parsed };
|
|
1761
1619
|
var currentScopingElements = [documentScope];
|
|
1762
1620
|
while (parsed.parts.length > 0) {
|
|
1763
1621
|
var part = parsed.parts.shift();
|
|
1764
1622
|
parsedEdits.parts = [part];
|
|
1765
1623
|
var isUsingXPath = false;
|
|
1766
|
-
// Getting All Elements
|
|
1767
1624
|
var elements = [];
|
|
1768
1625
|
var elementsIndexes = [];
|
|
1769
1626
|
if (part.name == "xpath") {
|
|
@@ -1782,53 +1639,49 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1782
1639
|
elements = currentScopingElements.concat(orredElements);
|
|
1783
1640
|
} else if (part.name == "internal:and") {
|
|
1784
1641
|
var andedElements = await this._customFindElementsByParsed(resolved, client, context, documentScope, progress, part.body.parsed);
|
|
1785
|
-
const backendNodeIds = new Set(andedElements.map(item => item.backendNodeId));
|
|
1786
|
-
elements = currentScopingElements.filter(item => backendNodeIds.has(item.backendNodeId));
|
|
1642
|
+
const backendNodeIds = new Set(andedElements.map((item) => item.backendNodeId));
|
|
1643
|
+
elements = currentScopingElements.filter((item) => backendNodeIds.has(item.backendNodeId));
|
|
1787
1644
|
} else {
|
|
1788
1645
|
for (const scope of currentScopingElements) {
|
|
1789
|
-
const describedScope = await client.send(
|
|
1646
|
+
const describedScope = await client.send("DOM.describeNode", {
|
|
1790
1647
|
objectId: scope._objectId,
|
|
1791
1648
|
depth: -1,
|
|
1792
1649
|
pierce: true
|
|
1793
1650
|
});
|
|
1794
|
-
|
|
1795
|
-
// Elements Queryed in the "current round"
|
|
1796
1651
|
var queryingElements = [];
|
|
1797
1652
|
if (!isUsingXPath) {
|
|
1798
|
-
function
|
|
1799
|
-
if (!node || typeof node !==
|
|
1653
|
+
let findClosedShadowRoots2 = function(node, results = []) {
|
|
1654
|
+
if (!node || typeof node !== "object") return results;
|
|
1800
1655
|
if (node.shadowRoots && Array.isArray(node.shadowRoots)) {
|
|
1801
|
-
for (const
|
|
1802
|
-
if (
|
|
1803
|
-
results.push(
|
|
1656
|
+
for (const shadowRoot2 of node.shadowRoots) {
|
|
1657
|
+
if (shadowRoot2.shadowRootType === "closed" && shadowRoot2.backendNodeId) {
|
|
1658
|
+
results.push(shadowRoot2.backendNodeId);
|
|
1804
1659
|
}
|
|
1805
|
-
|
|
1660
|
+
findClosedShadowRoots2(shadowRoot2, results);
|
|
1806
1661
|
}
|
|
1807
1662
|
}
|
|
1808
|
-
if (node.nodeName !==
|
|
1663
|
+
if (node.nodeName !== "IFRAME" && node.children && Array.isArray(node.children)) {
|
|
1809
1664
|
for (const child of node.children) {
|
|
1810
|
-
|
|
1665
|
+
findClosedShadowRoots2(child, results);
|
|
1811
1666
|
}
|
|
1812
1667
|
}
|
|
1813
1668
|
return results;
|
|
1814
|
-
}
|
|
1815
|
-
var
|
|
1669
|
+
};
|
|
1670
|
+
var findClosedShadowRoots = findClosedShadowRoots2;
|
|
1671
|
+
var shadowRootBackendIds = findClosedShadowRoots2(describedScope.node);
|
|
1816
1672
|
var shadowRoots = [];
|
|
1817
1673
|
for (var shadowRootBackendId of shadowRootBackendIds) {
|
|
1818
|
-
var resolvedShadowRoot = await client.send(
|
|
1674
|
+
var resolvedShadowRoot = await client.send("DOM.resolveNode", {
|
|
1819
1675
|
backendNodeId: shadowRootBackendId,
|
|
1820
1676
|
contextId: context.delegate._contextId
|
|
1821
1677
|
});
|
|
1822
1678
|
shadowRoots.push(new dom.ElementHandle(context, resolvedShadowRoot.object.objectId));
|
|
1823
1679
|
}
|
|
1824
1680
|
for (var shadowRoot of shadowRoots) {
|
|
1825
|
-
const shadowElements = await shadowRoot.evaluateHandleInUtility(([injected, node, {
|
|
1826
|
-
|
|
1827
|
-
callId
|
|
1828
|
-
|
|
1829
|
-
const elements = injected.querySelectorAll(parsed, node);
|
|
1830
|
-
if (callId) injected.markTargetElements(new Set(elements), callId);
|
|
1831
|
-
return elements;
|
|
1681
|
+
const shadowElements = await shadowRoot.evaluateHandleInUtility(([injected, node, { parsed: parsed2, callId }]) => {
|
|
1682
|
+
const elements2 = injected.querySelectorAll(parsed2, node);
|
|
1683
|
+
if (callId) injected.markTargetElements(new Set(elements2), callId);
|
|
1684
|
+
return elements2;
|
|
1832
1685
|
}, {
|
|
1833
1686
|
parsed: parsedEdits,
|
|
1834
1687
|
callId: progress.metadata.id
|
|
@@ -1837,70 +1690,45 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1837
1690
|
queryingElements.push([shadowElements, shadowElementsAmount, shadowRoot]);
|
|
1838
1691
|
}
|
|
1839
1692
|
}
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
callId
|
|
1845
|
-
}]) => {
|
|
1846
|
-
const elements = injected.querySelectorAll(parsed, node);
|
|
1847
|
-
if (callId) injected.markTargetElements(new Set(elements), callId);
|
|
1848
|
-
return elements;
|
|
1693
|
+
const rootElements = await scope.evaluateHandleInUtility(([injected, node, { parsed: parsed2, callId }]) => {
|
|
1694
|
+
const elements2 = injected.querySelectorAll(parsed2, node);
|
|
1695
|
+
if (callId) injected.markTargetElements(new Set(elements2), callId);
|
|
1696
|
+
return elements2;
|
|
1849
1697
|
}, {
|
|
1850
1698
|
parsed: parsedEdits,
|
|
1851
1699
|
callId: progress.metadata.id
|
|
1852
1700
|
});
|
|
1853
1701
|
const rootElementsAmount = await rootElements.getProperty("length");
|
|
1854
1702
|
queryingElements.push([rootElements, rootElementsAmount, resolved.injected]);
|
|
1855
|
-
|
|
1856
|
-
// Querying and Sorting the elements by their backendNodeId
|
|
1857
1703
|
for (var queryedElement of queryingElements) {
|
|
1858
1704
|
var elementsToCheck = queryedElement[0];
|
|
1859
1705
|
var elementsAmount = await queryedElement[1].jsonValue();
|
|
1860
1706
|
var parentNode = queryedElement[2];
|
|
1861
1707
|
for (var i = 0; i < elementsAmount; i++) {
|
|
1862
1708
|
if (parentNode.constructor.name == "ElementHandle") {
|
|
1863
|
-
var elementToCheck = await parentNode.evaluateHandleInUtility(([injected, node, {
|
|
1864
|
-
index
|
|
1865
|
-
|
|
1866
|
-
}]) => {
|
|
1867
|
-
return elementsToCheck[index];
|
|
1868
|
-
}, {
|
|
1869
|
-
index: i,
|
|
1870
|
-
elementsToCheck: elementsToCheck
|
|
1871
|
-
});
|
|
1709
|
+
var elementToCheck = await parentNode.evaluateHandleInUtility(([injected, node, { index, elementsToCheck: elementsToCheck2 }]) => {
|
|
1710
|
+
return elementsToCheck2[index];
|
|
1711
|
+
}, { index: i, elementsToCheck });
|
|
1872
1712
|
} else {
|
|
1873
|
-
var elementToCheck = await parentNode.evaluateHandle((injected, {
|
|
1874
|
-
index
|
|
1875
|
-
|
|
1876
|
-
}) => {
|
|
1877
|
-
return elementsToCheck[index];
|
|
1878
|
-
}, {
|
|
1879
|
-
index: i,
|
|
1880
|
-
elementsToCheck: elementsToCheck
|
|
1881
|
-
});
|
|
1713
|
+
var elementToCheck = await parentNode.evaluateHandle((injected, { index, elementsToCheck: elementsToCheck2 }) => {
|
|
1714
|
+
return elementsToCheck2[index];
|
|
1715
|
+
}, { index: i, elementsToCheck });
|
|
1882
1716
|
}
|
|
1883
|
-
// For other Functions/Utilities
|
|
1884
1717
|
elementToCheck.parentNode = parentNode;
|
|
1885
|
-
var resolvedElement = await client.send(
|
|
1718
|
+
var resolvedElement = await client.send("DOM.describeNode", {
|
|
1886
1719
|
objectId: elementToCheck._objectId,
|
|
1887
1720
|
depth: -1
|
|
1888
1721
|
});
|
|
1889
|
-
// Note: Possible Bug, Maybe well actually have to check the Documents Node Position instead of using the backendNodeId
|
|
1890
1722
|
elementToCheck.backendNodeId = resolvedElement.node.backendNodeId;
|
|
1891
1723
|
elements.push(elementToCheck);
|
|
1892
1724
|
}
|
|
1893
1725
|
}
|
|
1894
1726
|
}
|
|
1895
1727
|
}
|
|
1896
|
-
// Setting currentScopingElements to the elements we just queried
|
|
1897
1728
|
currentScopingElements = [];
|
|
1898
1729
|
for (var element of elements) {
|
|
1899
1730
|
var elemIndex = element.backendNodeId;
|
|
1900
|
-
|
|
1901
|
-
var elemPos = elementsIndexes.findIndex(index => index > elemIndex);
|
|
1902
|
-
|
|
1903
|
-
// Sort the elements by their backendNodeId
|
|
1731
|
+
var elemPos = elementsIndexes.findIndex((index) => index > elemIndex);
|
|
1904
1732
|
if (elemPos === -1) {
|
|
1905
1733
|
currentScopingElements.push(element);
|
|
1906
1734
|
elementsIndexes.push(elemIndex);
|
|
@@ -1913,17 +1741,10 @@ class Frame extends _instrumentation.SdkObject {
|
|
|
1913
1741
|
return currentScopingElements;
|
|
1914
1742
|
}
|
|
1915
1743
|
}
|
|
1916
|
-
exports.Frame = Frame;
|
|
1917
|
-
Frame.Events = {
|
|
1918
|
-
InternalNavigation: 'internalnavigation',
|
|
1919
|
-
AddLifecycle: 'addlifecycle',
|
|
1920
|
-
RemoveLifecycle: 'removelifecycle'
|
|
1921
|
-
};
|
|
1922
1744
|
class SignalBarrier {
|
|
1923
1745
|
constructor(progress) {
|
|
1924
|
-
this._progress = void 0;
|
|
1925
1746
|
this._protectCount = 0;
|
|
1926
|
-
this._promise = new
|
|
1747
|
+
this._promise = new import_manualPromise.ManualPromise();
|
|
1927
1748
|
this._progress = progress;
|
|
1928
1749
|
this.retain();
|
|
1929
1750
|
}
|
|
@@ -1932,15 +1753,21 @@ class SignalBarrier {
|
|
|
1932
1753
|
return this._promise;
|
|
1933
1754
|
}
|
|
1934
1755
|
async addFrameNavigation(frame) {
|
|
1935
|
-
|
|
1936
|
-
|
|
1756
|
+
if (frame.parentFrame())
|
|
1757
|
+
return;
|
|
1937
1758
|
this.retain();
|
|
1938
|
-
const waiter =
|
|
1939
|
-
if (!e.isPublic)
|
|
1940
|
-
|
|
1759
|
+
const waiter = import_helper.helper.waitForEvent(null, frame, Frame.Events.InternalNavigation, (e) => {
|
|
1760
|
+
if (!e.isPublic)
|
|
1761
|
+
return false;
|
|
1762
|
+
if (!e.error && this._progress)
|
|
1763
|
+
this._progress.log(` navigated to "${frame._url}"`);
|
|
1941
1764
|
return true;
|
|
1942
1765
|
});
|
|
1943
|
-
await
|
|
1766
|
+
await import_utils.LongStandingScope.raceMultiple([
|
|
1767
|
+
frame._page.openScope,
|
|
1768
|
+
frame._detachedScope
|
|
1769
|
+
], waiter.promise).catch(() => {
|
|
1770
|
+
});
|
|
1944
1771
|
waiter.dispose();
|
|
1945
1772
|
this.release();
|
|
1946
1773
|
}
|
|
@@ -1949,15 +1776,25 @@ class SignalBarrier {
|
|
|
1949
1776
|
}
|
|
1950
1777
|
release() {
|
|
1951
1778
|
--this._protectCount;
|
|
1952
|
-
if (!this._protectCount)
|
|
1779
|
+
if (!this._protectCount)
|
|
1780
|
+
this._promise.resolve();
|
|
1953
1781
|
}
|
|
1954
1782
|
}
|
|
1955
1783
|
function verifyLifecycle(name, waitUntil) {
|
|
1956
|
-
if (waitUntil ===
|
|
1957
|
-
|
|
1784
|
+
if (waitUntil === "networkidle0")
|
|
1785
|
+
waitUntil = "networkidle";
|
|
1786
|
+
if (!types.kLifecycleEvents.has(waitUntil))
|
|
1787
|
+
throw new Error(`${name}: expected one of (load|domcontentloaded|networkidle|commit)`);
|
|
1958
1788
|
return waitUntil;
|
|
1959
1789
|
}
|
|
1960
1790
|
function renderUnexpectedValue(expression, received) {
|
|
1961
|
-
if (expression ===
|
|
1791
|
+
if (expression === "to.match.aria")
|
|
1792
|
+
return received ? received.raw : received;
|
|
1962
1793
|
return received;
|
|
1963
|
-
}
|
|
1794
|
+
}
|
|
1795
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1796
|
+
0 && (module.exports = {
|
|
1797
|
+
Frame,
|
|
1798
|
+
FrameManager,
|
|
1799
|
+
NavigationAbortedError
|
|
1800
|
+
});
|