patchright-core 1.51.2 → 1.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browsers.json +15 -13
- package/lib/androidServerImpl.js +42 -48
- package/lib/browserServerImpl.js +54 -67
- package/lib/cli/driver.js +71 -69
- package/lib/cli/program.js +312 -328
- package/lib/cli/programWithTestStub.js +51 -45
- package/lib/client/accessibility.js +31 -32
- package/lib/client/android.js +141 -228
- package/lib/client/api.js +135 -283
- package/lib/client/artifact.js +39 -36
- package/lib/client/browser.js +57 -61
- package/lib/client/browserContext.js +297 -326
- package/lib/client/browserType.js +92 -106
- package/lib/client/cdpSession.js +29 -31
- package/lib/client/channelOwner.js +82 -95
- package/lib/client/clientHelper.js +46 -38
- package/lib/client/clientInstrumentation.js +40 -37
- package/lib/client/clientStackTrace.js +41 -37
- package/lib/client/clock.js +36 -36
- package/lib/client/connection.js +190 -212
- package/lib/client/consoleMessage.js +31 -28
- package/lib/client/coverage.js +25 -22
- package/lib/client/dialog.js +30 -31
- package/lib/client/download.js +25 -25
- package/lib/client/electron.js +73 -75
- package/lib/client/elementHandle.js +111 -147
- package/lib/client/errors.js +53 -53
- package/lib/client/eventEmitter.js +124 -121
- package/lib/client/events.js +72 -68
- package/lib/client/fetch.js +135 -158
- package/lib/client/fileChooser.js +25 -24
- package/lib/client/fileUtils.js +31 -28
- package/lib/client/frame.js +187 -306
- package/lib/client/harRouter.js +42 -52
- package/lib/client/input.js +40 -69
- package/lib/client/jsHandle.js +54 -69
- package/lib/client/jsonPipe.js +27 -23
- package/lib/client/localUtils.js +29 -28
- package/lib/client/locator.js +161 -245
- package/lib/client/network.js +277 -295
- package/lib/client/page.js +270 -318
- package/lib/client/platform.js +46 -43
- package/lib/client/playwright.js +51 -66
- package/lib/client/selectors.js +48 -46
- package/lib/client/stream.js +29 -25
- package/lib/client/timeoutSettings.js +49 -39
- package/lib/client/tracing.js +48 -84
- package/lib/client/types.js +26 -22
- package/lib/client/video.js +35 -27
- package/lib/client/waiter.js +69 -88
- package/lib/client/webError.js +25 -23
- package/lib/client/webSocket.js +61 -56
- package/lib/client/worker.js +48 -58
- package/lib/client/writableStream.js +27 -23
- package/lib/generated/clockSource.js +26 -5
- package/lib/generated/consoleApiSource.js +26 -5
- package/lib/generated/injectedScriptSource.js +26 -5
- package/lib/generated/pollingRecorderSource.js +26 -5
- package/lib/generated/utilityScriptSource.js +26 -5
- package/lib/generated/webSocketMockSource.js +375 -4
- package/lib/inProcessFactory.js +53 -53
- package/lib/inprocess.js +2 -19
- package/lib/outofprocess.js +53 -46
- package/lib/protocol/debug.js +209 -25
- package/lib/protocol/serializers.js +153 -134
- package/lib/protocol/validator.js +2714 -2714
- package/lib/protocol/validatorPrimitives.js +114 -73
- package/lib/remote/playwrightConnection.js +140 -157
- package/lib/remote/playwrightServer.js +99 -84
- package/lib/server/accessibility.js +44 -37
- package/lib/server/android/android.js +216 -209
- package/lib/server/android/backendAdb.js +89 -82
- package/lib/server/artifact.js +78 -55
- package/lib/server/bidi/bidiBrowser.js +221 -155
- package/lib/server/bidi/bidiChromium.js +106 -79
- package/lib/server/bidi/bidiConnection.js +66 -83
- package/lib/server/bidi/bidiExecutionContext.js +128 -113
- package/lib/server/bidi/bidiFirefox.js +76 -69
- package/lib/server/bidi/bidiInput.js +86 -97
- package/lib/server/bidi/bidiNetworkManager.js +137 -154
- package/lib/server/bidi/bidiOverCdp.js +57 -58
- package/lib/server/bidi/bidiPage.js +247 -219
- package/lib/server/bidi/bidiPdf.js +52 -86
- package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
- package/lib/server/bidi/third_party/bidiDeserializer.js +55 -50
- package/lib/server/bidi/third_party/bidiKeyboard.js +236 -220
- package/lib/server/bidi/third_party/bidiProtocol.js +144 -131
- package/lib/server/bidi/third_party/bidiSerializer.js +67 -63
- package/lib/server/bidi/third_party/firefoxPrefs.js +141 -119
- package/lib/server/browser.js +76 -84
- package/lib/server/browserContext.js +321 -346
- package/lib/server/browserType.js +169 -182
- package/lib/server/callLog.js +47 -44
- package/lib/server/chromium/chromium.js +212 -190
- package/lib/server/chromium/chromiumSwitches.js +86 -64
- package/lib/server/chromium/crAccessibility.js +157 -131
- package/lib/server/chromium/crBrowser.js +253 -273
- package/lib/server/chromium/crConnection.js +91 -116
- package/lib/server/chromium/crCoverage.js +113 -127
- package/lib/server/chromium/crDevTools.js +59 -51
- package/lib/server/chromium/crDragDrop.js +62 -79
- package/lib/server/chromium/crExecutionContext.js +88 -83
- package/lib/server/chromium/crInput.js +97 -95
- package/lib/server/chromium/crNetworkManager.js +288 -403
- package/lib/server/chromium/crPage.js +522 -608
- package/lib/server/chromium/crPdf.js +54 -86
- package/lib/server/chromium/crProtocolHelper.js +92 -80
- package/lib/server/chromium/crServiceWorker.js +82 -67
- package/lib/server/chromium/defaultFontFamilies.js +152 -135
- package/lib/server/chromium/protocol.d.js +16 -0
- package/lib/server/chromium/videoRecorder.js +65 -99
- package/lib/server/clock.js +62 -50
- package/lib/server/codegen/csharp.js +185 -160
- package/lib/server/codegen/java.js +155 -128
- package/lib/server/codegen/javascript.js +163 -148
- package/lib/server/codegen/jsonl.js +32 -28
- package/lib/server/codegen/language.js +75 -52
- package/lib/server/codegen/languages.js +65 -27
- package/lib/server/codegen/python.js +140 -125
- package/lib/server/codegen/types.js +15 -4
- package/lib/server/console.js +28 -32
- package/lib/server/cookieStore.js +105 -86
- package/lib/server/debugController.js +97 -124
- package/lib/server/debugger.js +82 -78
- package/lib/server/deviceDescriptors.js +37 -24
- package/lib/server/deviceDescriptorsSource.json +50 -50
- package/lib/server/dialog.js +36 -35
- package/lib/server/dispatchers/androidDispatcher.js +196 -107
- package/lib/server/dispatchers/artifactDispatcher.js +62 -62
- package/lib/server/dispatchers/browserContextDispatcher.js +176 -205
- package/lib/server/dispatchers/browserDispatcher.js +78 -97
- package/lib/server/dispatchers/browserTypeDispatcher.js +35 -35
- package/lib/server/dispatchers/cdpSessionDispatcher.js +32 -36
- package/lib/server/dispatchers/debugControllerDispatcher.js +48 -66
- package/lib/server/dispatchers/dialogDispatcher.js +30 -27
- package/lib/server/dispatchers/dispatcher.js +169 -220
- package/lib/server/dispatchers/electronDispatcher.js +54 -57
- package/lib/server/dispatchers/elementHandlerDispatcher.js +77 -119
- package/lib/server/dispatchers/frameDispatcher.js +99 -163
- package/lib/server/dispatchers/jsHandleDispatcher.js +49 -66
- package/lib/server/dispatchers/jsonPipeDispatcher.js +35 -36
- package/lib/server/dispatchers/localUtilsDispatcher.js +95 -80
- package/lib/server/dispatchers/networkDispatchers.js +90 -107
- package/lib/server/dispatchers/pageDispatcher.js +128 -169
- package/lib/server/dispatchers/playwrightDispatcher.js +69 -76
- package/lib/server/dispatchers/selectorsDispatcher.js +28 -24
- package/lib/server/dispatchers/streamDispatcher.js +42 -45
- package/lib/server/dispatchers/tracingDispatcher.js +36 -41
- package/lib/server/dispatchers/webSocketRouteDispatcher.js +96 -131
- package/lib/server/dispatchers/writableStreamDispatcher.js +54 -38
- package/lib/server/dom.js +413 -443
- package/lib/server/download.js +45 -35
- package/lib/server/electron/electron.js +156 -176
- package/lib/server/electron/loader.js +8 -36
- package/lib/server/errors.js +47 -46
- package/lib/server/fetch.js +289 -323
- package/lib/server/fileChooser.js +25 -24
- package/lib/server/fileUploadUtils.js +65 -59
- package/lib/server/firefox/ffAccessibility.js +153 -131
- package/lib/server/firefox/ffBrowser.js +213 -277
- package/lib/server/firefox/ffConnection.js +63 -84
- package/lib/server/firefox/ffExecutionContext.js +91 -73
- package/lib/server/firefox/ffInput.js +67 -69
- package/lib/server/firefox/ffNetworkManager.js +131 -110
- package/lib/server/firefox/ffPage.js +236 -273
- package/lib/server/firefox/firefox.js +76 -67
- package/lib/server/firefox/protocol.d.js +16 -0
- package/lib/server/formData.js +107 -35
- package/lib/server/frameSelectors.js +77 -111
- package/lib/server/frames.js +741 -891
- package/lib/server/har/harRecorder.js +85 -77
- package/lib/server/har/harTracer.js +287 -222
- package/lib/server/harBackend.js +80 -80
- package/lib/server/helper.js +56 -59
- package/lib/server/index.js +59 -99
- package/lib/server/input.js +134 -163
- package/lib/server/instrumentation.js +49 -44
- package/lib/server/javascript.js +143 -134
- package/lib/server/launchApp.js +92 -73
- package/lib/server/localUtils.js +130 -122
- package/lib/server/macEditingCommands.js +141 -137
- package/lib/server/network.js +262 -296
- package/lib/server/page.js +329 -426
- package/lib/server/pageBinding.js +88 -0
- package/lib/server/pipeTransport.js +49 -45
- package/lib/server/playwright.js +60 -67
- package/lib/server/progress.js +56 -51
- package/lib/server/protocolError.js +34 -31
- package/lib/server/recorder/chat.js +70 -86
- package/lib/server/recorder/contextRecorder.js +134 -138
- package/lib/server/recorder/recorderApp.js +127 -136
- package/lib/server/recorder/recorderCollection.js +56 -44
- package/lib/server/recorder/recorderFrontend.js +15 -4
- package/lib/server/recorder/recorderRunner.js +79 -103
- package/lib/server/recorder/recorderUtils.js +56 -45
- package/lib/server/recorder/throttledFile.js +42 -30
- package/lib/server/recorder.js +177 -186
- package/lib/server/registry/browserFetcher.js +106 -101
- package/lib/server/registry/dependencies.js +245 -196
- package/lib/server/registry/index.js +904 -792
- package/lib/server/registry/nativeDeps.js +1073 -464
- package/lib/server/registry/oopDownloadBrowserMain.js +57 -75
- package/lib/server/screenshotter.js +166 -182
- package/lib/server/selectors.js +85 -46
- package/lib/server/socksClientCertificatesInterceptor.js +166 -185
- package/lib/server/socksInterceptor.js +62 -70
- package/lib/server/storageScript.js +94 -100
- package/lib/server/timeoutSettings.js +58 -43
- package/lib/server/trace/recorder/snapshotter.js +70 -89
- package/lib/server/trace/recorder/snapshotterInjected.js +238 -217
- package/lib/server/trace/recorder/tracing.js +321 -333
- package/lib/server/trace/test/inMemorySnapshotter.js +46 -52
- package/lib/server/trace/viewer/traceViewer.js +168 -146
- package/lib/server/transport.js +124 -133
- package/lib/server/types.js +26 -22
- package/lib/server/usKeyboardLayout.js +135 -545
- package/lib/server/utils/ascii.js +39 -26
- package/lib/server/utils/comparators.js +105 -103
- package/lib/server/utils/crypto.js +157 -112
- package/lib/server/utils/debug.js +37 -28
- package/lib/server/utils/debugLogger.js +69 -48
- package/lib/server/utils/env.js +52 -37
- package/lib/server/utils/eventsHelper.js +29 -28
- package/lib/server/utils/expectUtils.js +31 -26
- package/lib/server/utils/fileUtils.js +123 -136
- package/lib/server/utils/happyEyeballs.js +138 -123
- package/lib/server/utils/hostPlatform.js +84 -120
- package/lib/server/utils/httpServer.js +106 -121
- package/lib/server/utils/image_tools/colorUtils.js +42 -51
- package/lib/server/utils/image_tools/compare.js +44 -43
- package/lib/server/utils/image_tools/imageChannel.js +38 -30
- package/lib/server/utils/image_tools/stats.js +40 -40
- package/lib/server/utils/linuxUtils.js +50 -37
- package/lib/server/utils/network.js +143 -86
- package/lib/server/utils/nodePlatform.js +87 -79
- package/lib/server/utils/pipeTransport.js +44 -42
- package/lib/server/utils/processLauncher.js +111 -121
- package/lib/server/utils/profiler.js +52 -39
- package/lib/server/utils/socksProxy.js +280 -339
- package/lib/server/utils/spawnAsync.js +37 -41
- package/lib/server/utils/task.js +31 -38
- package/lib/server/utils/userAgent.js +73 -66
- package/lib/server/utils/wsServer.js +73 -69
- package/lib/server/utils/zipFile.js +36 -37
- package/lib/server/utils/zones.js +37 -34
- package/lib/server/webkit/protocol.d.js +16 -0
- package/lib/server/webkit/webkit.js +76 -63
- package/lib/server/webkit/wkAccessibility.js +161 -118
- package/lib/server/webkit/wkBrowser.js +159 -176
- package/lib/server/webkit/wkConnection.js +59 -83
- package/lib/server/webkit/wkExecutionContext.js +84 -70
- package/lib/server/webkit/wkInput.js +82 -80
- package/lib/server/webkit/wkInterceptableRequest.js +102 -95
- package/lib/server/webkit/wkPage.js +525 -619
- package/lib/server/webkit/wkProvisionalPage.js +45 -56
- package/lib/server/webkit/wkWorkers.js +77 -77
- package/lib/utils/isomorphic/ariaSnapshot.js +144 -152
- package/lib/utils/isomorphic/assert.js +28 -22
- package/lib/utils/isomorphic/builtins.js +90 -0
- package/lib/utils/isomorphic/colors.js +66 -59
- package/lib/utils/isomorphic/cssParser.js +121 -125
- package/lib/utils/isomorphic/cssTokenizer.js +436 -364
- package/lib/utils/isomorphic/headers.js +38 -37
- package/lib/utils/isomorphic/locatorGenerators.js +340 -357
- package/lib/utils/isomorphic/locatorParser.js +96 -105
- package/lib/utils/isomorphic/locatorUtils.js +63 -44
- package/lib/utils/isomorphic/manualPromise.js +47 -39
- package/lib/utils/isomorphic/mimeType.js +448 -25
- package/lib/utils/isomorphic/multimap.js +35 -27
- package/lib/utils/isomorphic/rtti.js +35 -33
- package/lib/utils/isomorphic/selectorParser.js +183 -193
- package/lib/utils/isomorphic/semaphore.js +27 -24
- package/lib/utils/isomorphic/stackTrace.js +87 -98
- package/lib/utils/isomorphic/stringUtils.js +113 -106
- package/lib/utils/isomorphic/time.js +41 -22
- package/lib/utils/isomorphic/timeoutRunner.js +55 -54
- package/lib/utils/isomorphic/traceUtils.js +38 -41
- package/lib/utils/isomorphic/types.js +15 -4
- package/lib/utils/isomorphic/urlMatch.js +112 -67
- package/lib/utils/isomorphic/utilityScriptSerializers.js +248 -0
- package/lib/utils.js +97 -443
- package/lib/utilsBundle.js +101 -52
- package/lib/vite/htmlReport/index.html +21 -15
- package/lib/vite/recorder/assets/{codeMirrorModule-B9YMkrwa.js → codeMirrorModule-DVQi6prl.js} +1 -1
- package/lib/vite/recorder/assets/index-97EUAAbk.js +184 -0
- package/lib/vite/recorder/index.html +1 -1
- package/lib/vite/traceViewer/assets/{codeMirrorModule-DpJ-EmBQ.js → codeMirrorModule-dvXVzLxY.js} +1 -1
- package/lib/vite/traceViewer/assets/defaultSettingsView-BjymbO6M.js +265 -0
- package/lib/vite/traceViewer/{defaultSettingsView.5fN5lw10.css → defaultSettingsView.QdHITyLI.css} +1 -1
- package/lib/vite/traceViewer/index.ChIUCJnj.js +2 -0
- package/lib/vite/traceViewer/index.html +3 -3
- package/lib/vite/traceViewer/sw.bundle.js +3 -3
- package/lib/vite/traceViewer/uiMode.html +3 -3
- package/lib/vite/traceViewer/uiMode.jUCiCtdp.js +5 -0
- package/lib/zipBundle.js +32 -23
- package/package.json +1 -1
- package/types/protocol.d.ts +436 -17
- package/types/types.d.ts +35 -16
- package/lib/server/isomorphic/utilityScriptSerializers.js +0 -229
- package/lib/vite/recorder/assets/index-ELPgmkwA.js +0 -184
- package/lib/vite/traceViewer/assets/defaultSettingsView-DTenqiGw.js +0 -259
- package/lib/vite/traceViewer/index.CUq7VgrV.js +0 -2
- package/lib/vite/traceViewer/uiMode.CHJSAD7F.js +0 -5
|
@@ -1,94 +1,109 @@
|
|
|
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 browserContext_exports = {};
|
|
30
|
+
__export(browserContext_exports, {
|
|
31
|
+
BrowserContext: () => BrowserContext,
|
|
32
|
+
assertBrowserContextIsNotOwned: () => assertBrowserContextIsNotOwned,
|
|
33
|
+
normalizeProxySettings: () => normalizeProxySettings,
|
|
34
|
+
validateBrowserContextOptions: () => validateBrowserContextOptions,
|
|
35
|
+
verifyClientCertificates: () => verifyClientCertificates,
|
|
36
|
+
verifyGeolocation: () => verifyGeolocation
|
|
5
37
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
var consoleApiSource = _interopRequireWildcard(require("../generated/consoleApiSource"));
|
|
31
|
-
var _tracing = require("./trace/recorder/tracing");
|
|
32
|
-
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); }
|
|
33
|
-
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; }
|
|
34
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
35
|
-
/**
|
|
36
|
-
* Copyright 2017 Google Inc. All rights reserved.
|
|
37
|
-
* Modifications copyright (c) Microsoft Corporation.
|
|
38
|
-
*
|
|
39
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
40
|
-
* you may not use this file except in compliance with the License.
|
|
41
|
-
* You may obtain a copy of the License at
|
|
42
|
-
*
|
|
43
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
44
|
-
*
|
|
45
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
46
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
47
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
48
|
-
* See the License for the specific language governing permissions and
|
|
49
|
-
* limitations under the License.
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
class BrowserContext extends _instrumentation.SdkObject {
|
|
38
|
+
module.exports = __toCommonJS(browserContext_exports);
|
|
39
|
+
var import_fs = __toESM(require("fs"));
|
|
40
|
+
var import_path = __toESM(require("path"));
|
|
41
|
+
var import_timeoutSettings = require("./timeoutSettings");
|
|
42
|
+
var import_crypto = require("./utils/crypto");
|
|
43
|
+
var import_debug = require("./utils/debug");
|
|
44
|
+
var import_clock = require("./clock");
|
|
45
|
+
var import_debugger = require("./debugger");
|
|
46
|
+
var import_fetch = require("./fetch");
|
|
47
|
+
var import_fileUtils = require("./utils/fileUtils");
|
|
48
|
+
var import_harRecorder = require("./har/harRecorder");
|
|
49
|
+
var import_helper = require("./helper");
|
|
50
|
+
var import_instrumentation = require("./instrumentation");
|
|
51
|
+
var import_builtins = require("../utils/isomorphic/builtins");
|
|
52
|
+
var utilityScriptSerializers = __toESM(require("../utils/isomorphic/utilityScriptSerializers"));
|
|
53
|
+
var network = __toESM(require("./network"));
|
|
54
|
+
var import_page = require("./page");
|
|
55
|
+
var import_page2 = require("./page");
|
|
56
|
+
var import_recorder = require("./recorder");
|
|
57
|
+
var import_recorderApp = require("./recorder/recorderApp");
|
|
58
|
+
var storageScript = __toESM(require("./storageScript"));
|
|
59
|
+
var consoleApiSource = __toESM(require("../generated/consoleApiSource"));
|
|
60
|
+
var import_tracing = require("./trace/recorder/tracing");
|
|
61
|
+
class BrowserContext extends import_instrumentation.SdkObject {
|
|
53
62
|
constructor(browser, options, browserContextId) {
|
|
54
|
-
super(browser,
|
|
55
|
-
this._timeoutSettings = new
|
|
56
|
-
this._pageBindings = new Map();
|
|
57
|
-
this._activeProgressControllers = new Set();
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
61
|
-
this.
|
|
62
|
-
this.
|
|
63
|
-
this._closePromiseFulfill = void 0;
|
|
64
|
-
this._permissions = new Map();
|
|
65
|
-
this._downloads = new Set();
|
|
66
|
-
this._browser = void 0;
|
|
67
|
-
this._browserContextId = void 0;
|
|
68
|
-
this._selectors = void 0;
|
|
69
|
-
this._origins = new Set();
|
|
70
|
-
this._harRecorders = new Map();
|
|
71
|
-
this.tracing = void 0;
|
|
72
|
-
this.fetchRequest = void 0;
|
|
73
|
-
this._customCloseHandler = void 0;
|
|
63
|
+
super(browser, "browser-context");
|
|
64
|
+
this._timeoutSettings = new import_timeoutSettings.TimeoutSettings();
|
|
65
|
+
this._pageBindings = /* @__PURE__ */ new Map();
|
|
66
|
+
this._activeProgressControllers = /* @__PURE__ */ new Set();
|
|
67
|
+
this._closedStatus = "open";
|
|
68
|
+
this._permissions = /* @__PURE__ */ new Map();
|
|
69
|
+
this._downloads = /* @__PURE__ */ new Set();
|
|
70
|
+
this._origins = /* @__PURE__ */ new Set();
|
|
71
|
+
this._harRecorders = /* @__PURE__ */ new Map();
|
|
74
72
|
this._tempDirs = [];
|
|
75
73
|
this._settingStorageState = false;
|
|
76
74
|
this.initScripts = [];
|
|
77
|
-
this._routesInFlight = new Set();
|
|
78
|
-
this._debugger = void 0;
|
|
79
|
-
this._closeReason = void 0;
|
|
80
|
-
this.clock = void 0;
|
|
81
|
-
this._clientCertificatesProxy = void 0;
|
|
75
|
+
this._routesInFlight = /* @__PURE__ */ new Set();
|
|
82
76
|
this.attribution.context = this;
|
|
83
77
|
this._browser = browser;
|
|
84
78
|
this._options = options;
|
|
85
79
|
this._browserContextId = browserContextId;
|
|
86
80
|
this._isPersistentContext = !browserContextId;
|
|
87
|
-
this._closePromise = new Promise(fulfill => this._closePromiseFulfill = fulfill);
|
|
88
|
-
this.fetchRequest = new
|
|
89
|
-
if (this._options.recordHar)
|
|
90
|
-
|
|
91
|
-
this.
|
|
81
|
+
this._closePromise = new Promise((fulfill) => this._closePromiseFulfill = fulfill);
|
|
82
|
+
this.fetchRequest = new import_fetch.BrowserContextAPIRequestContext(this);
|
|
83
|
+
if (this._options.recordHar)
|
|
84
|
+
this._harRecorders.set("", new import_harRecorder.HarRecorder(this, null, this._options.recordHar));
|
|
85
|
+
this.tracing = new import_tracing.Tracing(this, browser.options.tracesDir);
|
|
86
|
+
this.clock = new import_clock.Clock(this);
|
|
87
|
+
}
|
|
88
|
+
static {
|
|
89
|
+
this.Events = {
|
|
90
|
+
Console: "console",
|
|
91
|
+
Close: "close",
|
|
92
|
+
Dialog: "dialog",
|
|
93
|
+
Page: "page",
|
|
94
|
+
// Can't use just 'error' due to node.js special treatment of error events.
|
|
95
|
+
// @see https://nodejs.org/api/events.html#events_error_events
|
|
96
|
+
PageError: "pageerror",
|
|
97
|
+
Request: "request",
|
|
98
|
+
Response: "response",
|
|
99
|
+
RequestFailed: "requestfailed",
|
|
100
|
+
RequestFinished: "requestfinished",
|
|
101
|
+
RequestAborted: "requestaborted",
|
|
102
|
+
RequestFulfilled: "requestfulfilled",
|
|
103
|
+
RequestContinued: "requestcontinued",
|
|
104
|
+
BeforeClose: "beforeclose",
|
|
105
|
+
VideoStarted: "videostarted"
|
|
106
|
+
};
|
|
92
107
|
}
|
|
93
108
|
isPersistentContext() {
|
|
94
109
|
return this._isPersistentContext;
|
|
@@ -100,133 +115,128 @@ class BrowserContext extends _instrumentation.SdkObject {
|
|
|
100
115
|
return this._selectors || this.attribution.playwright.selectors;
|
|
101
116
|
}
|
|
102
117
|
async _initialize() {
|
|
103
|
-
if (this.attribution.playwright.options.isInternalPlaywright)
|
|
104
|
-
|
|
105
|
-
this._debugger = new
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (this._debugger.isPaused()) _recorder.Recorder.showInspectorNoReply(this, _recorderApp.RecorderApp.factory(this));
|
|
114
|
-
this._debugger.on(_debugger.Debugger.Events.PausedStateChanged, () => {
|
|
115
|
-
if (this._debugger.isPaused()) _recorder.Recorder.showInspectorNoReply(this, _recorderApp.RecorderApp.factory(this));
|
|
118
|
+
if (this.attribution.playwright.options.isInternalPlaywright)
|
|
119
|
+
return;
|
|
120
|
+
this._debugger = new import_debugger.Debugger(this);
|
|
121
|
+
if ((0, import_debug.debugMode)() === "inspector")
|
|
122
|
+
await import_recorder.Recorder.show(this, import_recorderApp.RecorderApp.factory(this), { pauseOnNextStatement: true });
|
|
123
|
+
if (this._debugger.isPaused())
|
|
124
|
+
import_recorder.Recorder.showInspectorNoReply(this, import_recorderApp.RecorderApp.factory(this));
|
|
125
|
+
this._debugger.on(import_debugger.Debugger.Events.PausedStateChanged, () => {
|
|
126
|
+
if (this._debugger.isPaused())
|
|
127
|
+
import_recorder.Recorder.showInspectorNoReply(this, import_recorderApp.RecorderApp.factory(this));
|
|
116
128
|
});
|
|
117
|
-
if ((0,
|
|
118
|
-
|
|
119
|
-
if (this._options.
|
|
129
|
+
if ((0, import_debug.debugMode)() === "console")
|
|
130
|
+
await this.extendInjectedScript(consoleApiSource.source);
|
|
131
|
+
if (this._options.serviceWorkers === "block")
|
|
132
|
+
await this.addInitScript(`navigator.serviceWorker.register = async () => { };`);
|
|
133
|
+
if (this._options.permissions)
|
|
134
|
+
await this.grantPermissions(this._options.permissions);
|
|
120
135
|
}
|
|
121
136
|
debugger() {
|
|
122
137
|
return this._debugger;
|
|
123
138
|
}
|
|
124
139
|
async _ensureVideosPath() {
|
|
125
|
-
if (this._options.recordVideo)
|
|
140
|
+
if (this._options.recordVideo)
|
|
141
|
+
await (0, import_fileUtils.mkdirIfNeeded)(import_path.default.join(this._options.recordVideo.dir, "dummy"));
|
|
126
142
|
}
|
|
127
143
|
canResetForReuse() {
|
|
128
|
-
if (this._closedStatus !==
|
|
144
|
+
if (this._closedStatus !== "open")
|
|
145
|
+
return false;
|
|
129
146
|
return true;
|
|
130
147
|
}
|
|
131
148
|
async stopPendingOperations(reason) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// Let rejections in microtask generate events before returning.
|
|
136
|
-
await new Promise(f => setTimeout(f, 0));
|
|
149
|
+
for (const controller of this._activeProgressControllers)
|
|
150
|
+
controller.abort(new Error(reason));
|
|
151
|
+
await new Promise((f) => setTimeout(f, 0));
|
|
137
152
|
}
|
|
138
153
|
static reusableContextHash(params) {
|
|
139
|
-
const paramsCopy = {
|
|
140
|
-
...params
|
|
141
|
-
};
|
|
154
|
+
const paramsCopy = { ...params };
|
|
142
155
|
for (const k of Object.keys(paramsCopy)) {
|
|
143
156
|
const key = k;
|
|
144
|
-
if (paramsCopy[key] === defaultNewContextParamValues[key])
|
|
157
|
+
if (paramsCopy[key] === defaultNewContextParamValues[key])
|
|
158
|
+
delete paramsCopy[key];
|
|
145
159
|
}
|
|
146
|
-
for (const key of paramsThatAllowContextReuse)
|
|
160
|
+
for (const key of paramsThatAllowContextReuse)
|
|
161
|
+
delete paramsCopy[key];
|
|
147
162
|
return JSON.stringify(paramsCopy);
|
|
148
163
|
}
|
|
149
164
|
async resetForReuse(metadata, params) {
|
|
150
|
-
|
|
151
|
-
this.
|
|
152
|
-
this.setDefaultTimeout(undefined);
|
|
165
|
+
this.setDefaultNavigationTimeout(void 0);
|
|
166
|
+
this.setDefaultTimeout(void 0);
|
|
153
167
|
this.tracing.resetForReuse();
|
|
154
168
|
if (params) {
|
|
155
|
-
for (const key of paramsThatAllowContextReuse)
|
|
169
|
+
for (const key of paramsThatAllowContextReuse)
|
|
170
|
+
this._options[key] = params[key];
|
|
156
171
|
}
|
|
157
172
|
await this._cancelAllRoutesInFlight();
|
|
158
|
-
|
|
159
|
-
// Close extra pages early.
|
|
160
173
|
let page = this.pages()[0];
|
|
161
174
|
const [, ...otherPages] = this.pages();
|
|
162
|
-
for (const p of otherPages)
|
|
175
|
+
for (const p of otherPages)
|
|
176
|
+
await p.close(metadata);
|
|
163
177
|
if (page && page.hasCrashed()) {
|
|
164
178
|
await page.close(metadata);
|
|
165
|
-
page =
|
|
179
|
+
page = void 0;
|
|
166
180
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
// Navigate to about:blank first to ensure no page scripts are running after this point.
|
|
172
|
-
await ((_page3 = page) === null || _page3 === void 0 ? void 0 : _page3.mainFrame().goto(metadata, 'about:blank', {
|
|
173
|
-
timeout: 0
|
|
174
|
-
}));
|
|
175
|
-
(_page4 = page) === null || _page4 === void 0 || _page4._frameManager.setCloseAllOpeningDialogs(false);
|
|
181
|
+
page?._frameManager.setCloseAllOpeningDialogs(true);
|
|
182
|
+
await page?._frameManager.closeOpenDialogs();
|
|
183
|
+
await page?.mainFrame().goto(metadata, "about:blank", { timeout: 0 });
|
|
184
|
+
page?._frameManager.setCloseAllOpeningDialogs(false);
|
|
176
185
|
await this._resetStorage();
|
|
177
186
|
await this._removeExposedBindings();
|
|
178
187
|
await this._removeInitScripts();
|
|
179
188
|
this.clock.markAsUninstalled();
|
|
180
|
-
|
|
181
|
-
|
|
189
|
+
if (this._options.permissions)
|
|
190
|
+
await this.grantPermissions(this._options.permissions);
|
|
191
|
+
else
|
|
192
|
+
await this.clearPermissions();
|
|
182
193
|
await this.setExtraHTTPHeaders(this._options.extraHTTPHeaders || []);
|
|
183
194
|
await this.setGeolocation(this._options.geolocation);
|
|
184
195
|
await this.setOffline(!!this._options.offline);
|
|
185
196
|
await this.setUserAgent(this._options.userAgent);
|
|
186
197
|
await this.clearCache();
|
|
187
198
|
await this._resetCookies();
|
|
188
|
-
await
|
|
199
|
+
await page?.resetForReuse(metadata);
|
|
189
200
|
}
|
|
190
201
|
_browserClosed() {
|
|
191
|
-
for (const page of this.pages())
|
|
202
|
+
for (const page of this.pages())
|
|
203
|
+
page._didClose();
|
|
192
204
|
this._didCloseInternal();
|
|
193
205
|
}
|
|
194
206
|
_didCloseInternal() {
|
|
195
|
-
|
|
196
|
-
if (this._closedStatus === 'closed') {
|
|
197
|
-
// We can come here twice if we close browser context and browser
|
|
198
|
-
// at the same time.
|
|
207
|
+
if (this._closedStatus === "closed") {
|
|
199
208
|
return;
|
|
200
209
|
}
|
|
201
|
-
|
|
210
|
+
this._clientCertificatesProxy?.close().catch(() => {
|
|
211
|
+
});
|
|
202
212
|
this.tracing.abort();
|
|
203
|
-
if (this._isPersistentContext)
|
|
204
|
-
|
|
213
|
+
if (this._isPersistentContext)
|
|
214
|
+
this.onClosePersistent();
|
|
215
|
+
this._closePromiseFulfill(new Error("Context closed"));
|
|
205
216
|
this.emit(BrowserContext.Events.Close);
|
|
206
217
|
}
|
|
207
218
|
pages() {
|
|
208
|
-
return this.possiblyUninitializedPages().filter(page => page.initializedOrUndefined());
|
|
219
|
+
return this.possiblyUninitializedPages().filter((page) => page.initializedOrUndefined());
|
|
209
220
|
}
|
|
210
|
-
|
|
211
|
-
// BrowserContext methods.
|
|
212
|
-
|
|
213
221
|
async cookies(urls = []) {
|
|
214
|
-
if (urls && !Array.isArray(urls))
|
|
222
|
+
if (urls && !Array.isArray(urls))
|
|
223
|
+
urls = [urls];
|
|
215
224
|
return await this.doGetCookies(urls);
|
|
216
225
|
}
|
|
217
226
|
async clearCookies(options) {
|
|
218
227
|
const currentCookies = await this.cookies();
|
|
219
228
|
await this.doClearCookies();
|
|
220
229
|
const matches = (cookie, prop, value) => {
|
|
221
|
-
if (!value)
|
|
230
|
+
if (!value)
|
|
231
|
+
return true;
|
|
222
232
|
if (value instanceof RegExp) {
|
|
223
233
|
value.lastIndex = 0;
|
|
224
234
|
return value.test(cookie[prop]);
|
|
225
235
|
}
|
|
226
236
|
return cookie[prop] === value;
|
|
227
237
|
};
|
|
228
|
-
const cookiesToReadd = currentCookies.filter(cookie => {
|
|
229
|
-
return !matches(cookie,
|
|
238
|
+
const cookiesToReadd = currentCookies.filter((cookie) => {
|
|
239
|
+
return !matches(cookie, "name", options.name) || !matches(cookie, "domain", options.domain) || !matches(cookie, "path", options.path);
|
|
230
240
|
});
|
|
231
241
|
await this.addCookies(cookiesToReadd);
|
|
232
242
|
}
|
|
@@ -237,28 +247,31 @@ class BrowserContext extends _instrumentation.SdkObject {
|
|
|
237
247
|
return this._pageBindings.has(name);
|
|
238
248
|
}
|
|
239
249
|
async exposeBinding(name, needsHandle, playwrightBinding) {
|
|
240
|
-
if (this._pageBindings.has(name))
|
|
250
|
+
if (this._pageBindings.has(name))
|
|
251
|
+
throw new Error(`Function "${name}" has been already registered`);
|
|
241
252
|
for (const page of this.pages()) {
|
|
242
|
-
if (page.getBinding(name))
|
|
253
|
+
if (page.getBinding(name))
|
|
254
|
+
throw new Error(`Function "${name}" has been already registered in one of the pages`);
|
|
243
255
|
}
|
|
244
|
-
const binding = new
|
|
256
|
+
const binding = new import_page2.PageBinding(name, playwrightBinding, needsHandle);
|
|
245
257
|
this._pageBindings.set(name, binding);
|
|
246
258
|
await this.doExposeBinding(binding);
|
|
247
259
|
}
|
|
248
260
|
async _removeExposedBindings() {
|
|
249
261
|
for (const key of this._pageBindings.keys()) {
|
|
250
|
-
if (!key.startsWith(
|
|
262
|
+
if (!key.startsWith("__pw"))
|
|
263
|
+
this._pageBindings.delete(key);
|
|
251
264
|
}
|
|
252
265
|
await this.doRemoveExposedBindings();
|
|
253
266
|
}
|
|
254
267
|
async grantPermissions(permissions, origin) {
|
|
255
|
-
let resolvedOrigin =
|
|
268
|
+
let resolvedOrigin = "*";
|
|
256
269
|
if (origin) {
|
|
257
270
|
const url = new URL(origin);
|
|
258
271
|
resolvedOrigin = url.origin;
|
|
259
272
|
}
|
|
260
273
|
const existing = new Set(this._permissions.get(resolvedOrigin) || []);
|
|
261
|
-
permissions.forEach(p => existing.add(p));
|
|
274
|
+
permissions.forEach((p) => existing.add(p));
|
|
262
275
|
const list = [...existing.values()];
|
|
263
276
|
this._permissions.set(resolvedOrigin, list);
|
|
264
277
|
await this.doGrantPermissions(resolvedOrigin, list);
|
|
@@ -275,62 +288,51 @@ class BrowserContext extends _instrumentation.SdkObject {
|
|
|
275
288
|
}
|
|
276
289
|
async _loadDefaultContextAsIs(progress) {
|
|
277
290
|
if (!this.possiblyUninitializedPages().length) {
|
|
278
|
-
const waitForEvent =
|
|
291
|
+
const waitForEvent = import_helper.helper.waitForEvent(progress, this, BrowserContext.Events.Page);
|
|
279
292
|
progress.cleanupWhenAborted(() => waitForEvent.dispose);
|
|
280
|
-
// Race against BrowserContext.close
|
|
281
293
|
await Promise.race([waitForEvent.promise, this._closePromise]);
|
|
282
294
|
}
|
|
283
295
|
const page = this.possiblyUninitializedPages()[0];
|
|
284
|
-
if (!page)
|
|
296
|
+
if (!page)
|
|
297
|
+
return;
|
|
285
298
|
const pageOrError = await page.waitForInitializedOrError();
|
|
286
|
-
if (pageOrError instanceof Error)
|
|
287
|
-
|
|
299
|
+
if (pageOrError instanceof Error)
|
|
300
|
+
throw pageOrError;
|
|
301
|
+
await page.mainFrame()._waitForLoadState(progress, "load");
|
|
288
302
|
return page;
|
|
289
303
|
}
|
|
290
304
|
async _loadDefaultContext(progress) {
|
|
291
305
|
const defaultPage = await this._loadDefaultContextAsIs(progress);
|
|
292
|
-
if (!defaultPage)
|
|
306
|
+
if (!defaultPage)
|
|
307
|
+
return;
|
|
293
308
|
const browserName = this._browser.options.name;
|
|
294
|
-
if (this._options.isMobile && browserName ===
|
|
295
|
-
// Workaround for:
|
|
296
|
-
// - chromium fails to change isMobile for existing page;
|
|
297
|
-
// - webkit fails to change locale for existing page.
|
|
309
|
+
if (this._options.isMobile && browserName === "chromium" || this._options.locale && browserName === "webkit") {
|
|
298
310
|
await this.newPage(progress.metadata);
|
|
299
311
|
await defaultPage.close(progress.metadata);
|
|
300
312
|
}
|
|
301
313
|
}
|
|
302
314
|
_authenticateProxyViaHeader() {
|
|
303
|
-
const proxy = this._options.proxy || this._browser.options.proxy || {
|
|
304
|
-
|
|
305
|
-
password: undefined
|
|
306
|
-
};
|
|
307
|
-
const {
|
|
308
|
-
username,
|
|
309
|
-
password
|
|
310
|
-
} = proxy;
|
|
315
|
+
const proxy = this._options.proxy || this._browser.options.proxy || { username: void 0, password: void 0 };
|
|
316
|
+
const { username, password } = proxy;
|
|
311
317
|
if (username) {
|
|
312
|
-
this._options.httpCredentials = {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
+
this._options.httpCredentials = { username, password };
|
|
319
|
+
const token = Buffer.from(`${username}:${password}`).toString("base64");
|
|
320
|
+
this._options.extraHTTPHeaders = network.mergeHeaders([
|
|
321
|
+
this._options.extraHTTPHeaders,
|
|
322
|
+
network.singleHeader("Proxy-Authorization", `Basic ${token}`)
|
|
323
|
+
]);
|
|
318
324
|
}
|
|
319
325
|
}
|
|
320
326
|
_authenticateProxyViaCredentials() {
|
|
321
327
|
const proxy = this._options.proxy || this._browser.options.proxy;
|
|
322
|
-
if (!proxy)
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (username) this._options.httpCredentials = {
|
|
328
|
-
username,
|
|
329
|
-
password: password || ''
|
|
330
|
-
};
|
|
328
|
+
if (!proxy)
|
|
329
|
+
return;
|
|
330
|
+
const { username, password } = proxy;
|
|
331
|
+
if (username)
|
|
332
|
+
this._options.httpCredentials = { username, password: password || "" };
|
|
331
333
|
}
|
|
332
334
|
async addInitScript(source, name) {
|
|
333
|
-
const initScript = new
|
|
335
|
+
const initScript = new import_page.InitScript(source, false, name);
|
|
334
336
|
this.initScripts.push(initScript);
|
|
335
337
|
await this.doAddInitScript(initScript);
|
|
336
338
|
}
|
|
@@ -343,58 +345,53 @@ class BrowserContext extends _instrumentation.SdkObject {
|
|
|
343
345
|
await this.doUpdateRequestInterception();
|
|
344
346
|
}
|
|
345
347
|
isClosingOrClosed() {
|
|
346
|
-
return this._closedStatus !==
|
|
348
|
+
return this._closedStatus !== "open";
|
|
347
349
|
}
|
|
348
350
|
async _deleteAllDownloads() {
|
|
349
|
-
await Promise.all(Array.from(this._downloads).map(download => download.artifact.deleteOnContextClose()));
|
|
351
|
+
await Promise.all(Array.from(this._downloads).map((download) => download.artifact.deleteOnContextClose()));
|
|
350
352
|
}
|
|
351
353
|
async _deleteAllTempDirs() {
|
|
352
|
-
await Promise.all(this._tempDirs.map(async dir => await
|
|
354
|
+
await Promise.all(this._tempDirs.map(async (dir) => await import_fs.default.promises.unlink(dir).catch((e) => {
|
|
355
|
+
})));
|
|
353
356
|
}
|
|
354
357
|
setCustomCloseHandler(handler) {
|
|
355
358
|
this._customCloseHandler = handler;
|
|
356
359
|
}
|
|
357
360
|
async close(options) {
|
|
358
|
-
if (this._closedStatus ===
|
|
359
|
-
if (options.reason)
|
|
361
|
+
if (this._closedStatus === "open") {
|
|
362
|
+
if (options.reason)
|
|
363
|
+
this._closeReason = options.reason;
|
|
360
364
|
this.emit(BrowserContext.Events.BeforeClose);
|
|
361
|
-
this._closedStatus =
|
|
362
|
-
for (const harRecorder of this._harRecorders.values())
|
|
365
|
+
this._closedStatus = "closing";
|
|
366
|
+
for (const harRecorder of this._harRecorders.values())
|
|
367
|
+
await harRecorder.flush();
|
|
363
368
|
await this.tracing.flush();
|
|
364
|
-
|
|
365
|
-
// Cleanup.
|
|
366
369
|
const promises = [];
|
|
367
|
-
for (const {
|
|
368
|
-
context
|
|
369
|
-
|
|
370
|
-
} of this._browser._idToVideo.values()) {
|
|
371
|
-
// Wait for the videos to finish.
|
|
372
|
-
if (context === this) promises.push(artifact.finishedPromise());
|
|
370
|
+
for (const { context, artifact } of this._browser._idToVideo.values()) {
|
|
371
|
+
if (context === this)
|
|
372
|
+
promises.push(artifact.finishedPromise());
|
|
373
373
|
}
|
|
374
374
|
if (this._customCloseHandler) {
|
|
375
375
|
await this._customCloseHandler();
|
|
376
376
|
} else {
|
|
377
|
-
// Close the context.
|
|
378
377
|
await this.doClose(options.reason);
|
|
379
378
|
}
|
|
380
|
-
|
|
381
|
-
// We delete downloads after context closure
|
|
382
|
-
// so that browser does not write to the download file anymore.
|
|
383
379
|
promises.push(this._deleteAllDownloads());
|
|
384
380
|
promises.push(this._deleteAllTempDirs());
|
|
385
381
|
await Promise.all(promises);
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
if (!this._customCloseHandler) this._didCloseInternal();
|
|
382
|
+
if (!this._customCloseHandler)
|
|
383
|
+
this._didCloseInternal();
|
|
389
384
|
}
|
|
390
385
|
await this._closePromise;
|
|
391
386
|
}
|
|
392
387
|
async newPage(metadata) {
|
|
393
388
|
const page = await this.doCreateNewPage();
|
|
394
|
-
if (metadata.isServerSide)
|
|
389
|
+
if (metadata.isServerSide)
|
|
390
|
+
page.markAsServerSideOnly();
|
|
395
391
|
const pageOrError = await page.waitForInitializedOrError();
|
|
396
|
-
if (pageOrError instanceof
|
|
397
|
-
if (pageOrError.isClosed())
|
|
392
|
+
if (pageOrError instanceof import_page2.Page) {
|
|
393
|
+
if (pageOrError.isClosed())
|
|
394
|
+
throw new Error("Page has been closed.");
|
|
398
395
|
return pageOrError;
|
|
399
396
|
}
|
|
400
397
|
throw pageOrError;
|
|
@@ -408,85 +405,68 @@ class BrowserContext extends _instrumentation.SdkObject {
|
|
|
408
405
|
origins: []
|
|
409
406
|
};
|
|
410
407
|
const originsToSave = new Set(this._origins);
|
|
411
|
-
const collectScript = `(${storageScript.collect})(
|
|
412
|
-
|
|
413
|
-
// First try collecting storage stage from existing pages.
|
|
408
|
+
const collectScript = `(${storageScript.collect})(${utilityScriptSerializers.source}, (${import_builtins.builtins})(), ${this._browser.options.name === "firefox"}, ${indexedDB})`;
|
|
414
409
|
for (const page of this.pages()) {
|
|
415
410
|
const origin = page.mainFrame().origin();
|
|
416
|
-
if (!origin || !originsToSave.has(origin))
|
|
411
|
+
if (!origin || !originsToSave.has(origin))
|
|
412
|
+
continue;
|
|
417
413
|
try {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
origin,
|
|
422
|
-
localStorage: storage.localStorage,
|
|
423
|
-
indexedDB: storage.indexedDB
|
|
424
|
-
});
|
|
414
|
+
const storage = await page.mainFrame().nonStallingEvaluateInExistingContext(collectScript, "utility");
|
|
415
|
+
if (storage.localStorage.length || storage.indexedDB?.length)
|
|
416
|
+
result.origins.push({ origin, localStorage: storage.localStorage, indexedDB: storage.indexedDB });
|
|
425
417
|
originsToSave.delete(origin);
|
|
426
418
|
} catch {
|
|
427
|
-
// When failed on the live page, we'll retry on the blank page below.
|
|
428
419
|
}
|
|
429
420
|
}
|
|
430
|
-
|
|
431
|
-
// If there are still origins to save, create a blank page to iterate over origins.
|
|
432
421
|
if (originsToSave.size) {
|
|
433
|
-
const internalMetadata = (0,
|
|
422
|
+
const internalMetadata = (0, import_instrumentation.serverSideCallMetadata)();
|
|
434
423
|
const page = await this.newPage(internalMetadata);
|
|
435
|
-
await page._setServerRequestInterceptor(handler => {
|
|
436
|
-
handler.fulfill({
|
|
437
|
-
|
|
438
|
-
}).catch(() => {});
|
|
424
|
+
await page._setServerRequestInterceptor((handler) => {
|
|
425
|
+
handler.fulfill({ body: "<html></html>" }).catch(() => {
|
|
426
|
+
});
|
|
439
427
|
return true;
|
|
440
428
|
});
|
|
441
429
|
for (const origin of originsToSave) {
|
|
442
|
-
var _storage$indexedDB2;
|
|
443
430
|
const frame = page.mainFrame();
|
|
444
431
|
await frame.goto(internalMetadata, origin);
|
|
445
|
-
const storage = await frame.evaluateExpression(collectScript, {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
if (storage.localStorage.length || (_storage$indexedDB2 = storage.indexedDB) !== null && _storage$indexedDB2 !== void 0 && _storage$indexedDB2.length) result.origins.push({
|
|
449
|
-
origin,
|
|
450
|
-
localStorage: storage.localStorage,
|
|
451
|
-
indexedDB: storage.indexedDB
|
|
452
|
-
});
|
|
432
|
+
const storage = await frame.evaluateExpression(collectScript, { world: "utility" });
|
|
433
|
+
if (storage.localStorage.length || storage.indexedDB?.length)
|
|
434
|
+
result.origins.push({ origin, localStorage: storage.localStorage, indexedDB: storage.indexedDB });
|
|
453
435
|
}
|
|
454
436
|
await page.close(internalMetadata);
|
|
455
437
|
}
|
|
456
438
|
return result;
|
|
457
439
|
}
|
|
458
440
|
async _resetStorage() {
|
|
459
|
-
var _this$_options$storag;
|
|
460
441
|
const oldOrigins = this._origins;
|
|
461
|
-
const newOrigins = new Map(
|
|
462
|
-
if (!oldOrigins.size && !newOrigins.size)
|
|
442
|
+
const newOrigins = new Map(this._options.storageState?.origins?.map((p) => [p.origin, p]) || []);
|
|
443
|
+
if (!oldOrigins.size && !newOrigins.size)
|
|
444
|
+
return;
|
|
463
445
|
let page = this.pages()[0];
|
|
464
|
-
const internalMetadata = (0,
|
|
465
|
-
page = page ||
|
|
446
|
+
const internalMetadata = (0, import_instrumentation.serverSideCallMetadata)();
|
|
447
|
+
page = page || await this.newPage({
|
|
466
448
|
...internalMetadata,
|
|
467
449
|
// Do not mark this page as internal, because we will leave it for later reuse
|
|
468
450
|
// as a user-visible page.
|
|
469
451
|
isServerSide: false
|
|
470
|
-
})
|
|
471
|
-
await page._setServerRequestInterceptor(handler => {
|
|
472
|
-
handler.fulfill({
|
|
473
|
-
|
|
474
|
-
}).catch(() => {});
|
|
452
|
+
});
|
|
453
|
+
await page._setServerRequestInterceptor((handler) => {
|
|
454
|
+
handler.fulfill({ body: "<html></html>" }).catch(() => {
|
|
455
|
+
});
|
|
475
456
|
return true;
|
|
476
457
|
});
|
|
477
|
-
for (const origin of new Set([...oldOrigins, ...newOrigins.keys()])) {
|
|
458
|
+
for (const origin of /* @__PURE__ */ new Set([...oldOrigins, ...newOrigins.keys()])) {
|
|
478
459
|
const frame = page.mainFrame();
|
|
479
460
|
await frame.goto(internalMetadata, origin);
|
|
480
461
|
await frame.resetStorageForCurrentOriginBestEffort(newOrigins.get(origin));
|
|
481
462
|
}
|
|
482
|
-
await page._setServerRequestInterceptor(
|
|
483
|
-
this._origins = new Set([...newOrigins.keys()]);
|
|
484
|
-
// It is safe to not restore the URL to about:blank since we are doing it in Page::resetForReuse.
|
|
463
|
+
await page._setServerRequestInterceptor(void 0);
|
|
464
|
+
this._origins = /* @__PURE__ */ new Set([...newOrigins.keys()]);
|
|
485
465
|
}
|
|
486
466
|
async _resetCookies() {
|
|
487
|
-
var _this$_options$storag2, _this$_options$storag3;
|
|
488
467
|
await this.doClearCookies();
|
|
489
|
-
if (
|
|
468
|
+
if (this._options.storageState?.cookies)
|
|
469
|
+
await this.addCookies(this._options.storageState?.cookies);
|
|
490
470
|
}
|
|
491
471
|
isSettingStorageState() {
|
|
492
472
|
return this._settingStorageState;
|
|
@@ -494,22 +474,20 @@ class BrowserContext extends _instrumentation.SdkObject {
|
|
|
494
474
|
async setStorageState(metadata, state) {
|
|
495
475
|
this._settingStorageState = true;
|
|
496
476
|
try {
|
|
497
|
-
if (state.cookies)
|
|
477
|
+
if (state.cookies)
|
|
478
|
+
await this.addCookies(state.cookies);
|
|
498
479
|
if (state.origins && state.origins.length) {
|
|
499
|
-
const internalMetadata = (0,
|
|
480
|
+
const internalMetadata = (0, import_instrumentation.serverSideCallMetadata)();
|
|
500
481
|
const page = await this.newPage(internalMetadata);
|
|
501
|
-
await page._setServerRequestInterceptor(handler => {
|
|
502
|
-
handler.fulfill({
|
|
503
|
-
|
|
504
|
-
}).catch(() => {});
|
|
482
|
+
await page._setServerRequestInterceptor((handler) => {
|
|
483
|
+
handler.fulfill({ body: "<html></html>" }).catch(() => {
|
|
484
|
+
});
|
|
505
485
|
return true;
|
|
506
486
|
});
|
|
507
487
|
for (const originState of state.origins) {
|
|
508
488
|
const frame = page.mainFrame();
|
|
509
489
|
await frame.goto(metadata, originState.origin);
|
|
510
|
-
await frame.evaluateExpression(`(${storageScript.restore})(${
|
|
511
|
-
world: 'utility'
|
|
512
|
-
});
|
|
490
|
+
await frame.evaluateExpression(`(${storageScript.restore})(${utilityScriptSerializers.source}, (${import_builtins.builtins})(), ${JSON.stringify(originState)})`, { world: "utility" });
|
|
513
491
|
}
|
|
514
492
|
await page.close(internalMetadata);
|
|
515
493
|
}
|
|
@@ -518,24 +496,25 @@ class BrowserContext extends _instrumentation.SdkObject {
|
|
|
518
496
|
}
|
|
519
497
|
}
|
|
520
498
|
async extendInjectedScript(source, arg) {
|
|
521
|
-
const installInFrame = frame => frame.extendInjectedScript(source, arg).catch(() => {
|
|
522
|
-
|
|
523
|
-
|
|
499
|
+
const installInFrame = (frame) => frame.extendInjectedScript(source, arg).catch(() => {
|
|
500
|
+
});
|
|
501
|
+
const installInPage = (page) => {
|
|
502
|
+
page.on(import_page2.Page.Events.InternalFrameNavigatedToNewDocument, installInFrame);
|
|
524
503
|
return Promise.all(page.frames().map(installInFrame));
|
|
525
504
|
};
|
|
526
505
|
this.on(BrowserContext.Events.Page, installInPage);
|
|
527
506
|
return Promise.all(this.pages().map(installInPage));
|
|
528
507
|
}
|
|
529
508
|
async safeNonStallingEvaluateInAllFrames(expression, world, options = {}) {
|
|
530
|
-
await Promise.all(this.pages().map(page => page.safeNonStallingEvaluateInAllFrames(expression, world, options)));
|
|
509
|
+
await Promise.all(this.pages().map((page) => page.safeNonStallingEvaluateInAllFrames(expression, world, options)));
|
|
531
510
|
}
|
|
532
511
|
async _harStart(page, options) {
|
|
533
|
-
const harId = (0,
|
|
534
|
-
this._harRecorders.set(harId, new
|
|
512
|
+
const harId = (0, import_crypto.createGuid)();
|
|
513
|
+
this._harRecorders.set(harId, new import_harRecorder.HarRecorder(this, page, options));
|
|
535
514
|
return harId;
|
|
536
515
|
}
|
|
537
516
|
async _harExport(harId) {
|
|
538
|
-
const recorder = this._harRecorders.get(harId ||
|
|
517
|
+
const recorder = this._harRecorders.get(harId || "");
|
|
539
518
|
return recorder.export();
|
|
540
519
|
}
|
|
541
520
|
addRouteInFlight(route) {
|
|
@@ -545,53 +524,32 @@ class BrowserContext extends _instrumentation.SdkObject {
|
|
|
545
524
|
this._routesInFlight.delete(route);
|
|
546
525
|
}
|
|
547
526
|
async _cancelAllRoutesInFlight() {
|
|
548
|
-
await Promise.all([...this._routesInFlight].map(r => r.abort())).catch(() => {
|
|
527
|
+
await Promise.all([...this._routesInFlight].map((r) => r.abort())).catch(() => {
|
|
528
|
+
});
|
|
549
529
|
this._routesInFlight.clear();
|
|
550
530
|
}
|
|
551
531
|
}
|
|
552
|
-
exports.BrowserContext = BrowserContext;
|
|
553
|
-
BrowserContext.Events = {
|
|
554
|
-
Console: 'console',
|
|
555
|
-
Close: 'close',
|
|
556
|
-
Dialog: 'dialog',
|
|
557
|
-
Page: 'page',
|
|
558
|
-
// Can't use just 'error' due to node.js special treatment of error events.
|
|
559
|
-
// @see https://nodejs.org/api/events.html#events_error_events
|
|
560
|
-
PageError: 'pageerror',
|
|
561
|
-
Request: 'request',
|
|
562
|
-
Response: 'response',
|
|
563
|
-
RequestFailed: 'requestfailed',
|
|
564
|
-
RequestFinished: 'requestfinished',
|
|
565
|
-
RequestAborted: 'requestaborted',
|
|
566
|
-
RequestFulfilled: 'requestfulfilled',
|
|
567
|
-
RequestContinued: 'requestcontinued',
|
|
568
|
-
BeforeClose: 'beforeclose',
|
|
569
|
-
VideoStarted: 'videostarted'
|
|
570
|
-
};
|
|
571
532
|
function assertBrowserContextIsNotOwned(context) {
|
|
572
533
|
for (const page of context.pages()) {
|
|
573
|
-
if (page._ownedContext)
|
|
534
|
+
if (page._ownedContext)
|
|
535
|
+
throw new Error("Please use browser.newContext() for multi-page scripts that share the context.");
|
|
574
536
|
}
|
|
575
537
|
}
|
|
576
538
|
function validateBrowserContextOptions(options, browserOptions) {
|
|
577
|
-
if (options.noDefaultViewport && options.deviceScaleFactor !==
|
|
578
|
-
|
|
579
|
-
if (options.
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
else if (options.acceptDownloads ===
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
height: 720
|
|
587
|
-
};
|
|
539
|
+
if (options.noDefaultViewport && options.deviceScaleFactor !== void 0)
|
|
540
|
+
throw new Error(`"deviceScaleFactor" option is not supported with null "viewport"`);
|
|
541
|
+
if (options.noDefaultViewport && !!options.isMobile)
|
|
542
|
+
throw new Error(`"isMobile" option is not supported with null "viewport"`);
|
|
543
|
+
if (options.acceptDownloads === void 0 && browserOptions.name !== "electron")
|
|
544
|
+
options.acceptDownloads = "accept";
|
|
545
|
+
else if (options.acceptDownloads === void 0 && browserOptions.name === "electron")
|
|
546
|
+
options.acceptDownloads = "internal-browser-default";
|
|
547
|
+
if (!options.viewport && !options.noDefaultViewport)
|
|
548
|
+
options.viewport = { width: 1280, height: 720 };
|
|
588
549
|
if (options.recordVideo) {
|
|
589
550
|
if (!options.recordVideo.size) {
|
|
590
551
|
if (options.noDefaultViewport) {
|
|
591
|
-
options.recordVideo.size = {
|
|
592
|
-
width: 800,
|
|
593
|
-
height: 600
|
|
594
|
-
};
|
|
552
|
+
options.recordVideo.size = { width: 800, height: 600 };
|
|
595
553
|
} else {
|
|
596
554
|
const size = options.viewport;
|
|
597
555
|
const scale = Math.min(1, 800 / Math.max(size.width, size.height));
|
|
@@ -601,61 +559,69 @@ function validateBrowserContextOptions(options, browserOptions) {
|
|
|
601
559
|
};
|
|
602
560
|
}
|
|
603
561
|
}
|
|
604
|
-
// Make sure both dimensions are odd, this is required for vp8
|
|
605
562
|
options.recordVideo.size.width &= ~1;
|
|
606
563
|
options.recordVideo.size.height &= ~1;
|
|
607
564
|
}
|
|
608
|
-
if (options.proxy)
|
|
565
|
+
if (options.proxy)
|
|
566
|
+
options.proxy = normalizeProxySettings(options.proxy);
|
|
609
567
|
verifyGeolocation(options.geolocation);
|
|
610
568
|
}
|
|
611
569
|
function verifyGeolocation(geolocation) {
|
|
612
|
-
if (!geolocation)
|
|
570
|
+
if (!geolocation)
|
|
571
|
+
return;
|
|
613
572
|
geolocation.accuracy = geolocation.accuracy || 0;
|
|
614
|
-
const {
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
if (
|
|
620
|
-
|
|
621
|
-
if (accuracy < 0) throw new Error(`geolocation.accuracy: precondition 0 <= ACCURACY failed.`);
|
|
573
|
+
const { longitude, latitude, accuracy } = geolocation;
|
|
574
|
+
if (longitude < -180 || longitude > 180)
|
|
575
|
+
throw new Error(`geolocation.longitude: precondition -180 <= LONGITUDE <= 180 failed.`);
|
|
576
|
+
if (latitude < -90 || latitude > 90)
|
|
577
|
+
throw new Error(`geolocation.latitude: precondition -90 <= LATITUDE <= 90 failed.`);
|
|
578
|
+
if (accuracy < 0)
|
|
579
|
+
throw new Error(`geolocation.accuracy: precondition 0 <= ACCURACY failed.`);
|
|
622
580
|
}
|
|
623
581
|
function verifyClientCertificates(clientCertificates) {
|
|
624
|
-
if (!clientCertificates)
|
|
582
|
+
if (!clientCertificates)
|
|
583
|
+
return;
|
|
625
584
|
for (const cert of clientCertificates) {
|
|
626
|
-
if (!cert.origin)
|
|
627
|
-
|
|
628
|
-
if (cert.cert && !cert.key
|
|
629
|
-
|
|
630
|
-
if (cert.
|
|
585
|
+
if (!cert.origin)
|
|
586
|
+
throw new Error(`clientCertificates.origin is required`);
|
|
587
|
+
if (!cert.cert && !cert.key && !cert.passphrase && !cert.pfx)
|
|
588
|
+
throw new Error("None of cert, key, passphrase or pfx is specified");
|
|
589
|
+
if (cert.cert && !cert.key)
|
|
590
|
+
throw new Error("cert is specified without key");
|
|
591
|
+
if (!cert.cert && cert.key)
|
|
592
|
+
throw new Error("key is specified without cert");
|
|
593
|
+
if (cert.pfx && (cert.cert || cert.key))
|
|
594
|
+
throw new Error("pfx is specified together with cert, key or passphrase");
|
|
631
595
|
}
|
|
632
596
|
}
|
|
633
597
|
function normalizeProxySettings(proxy) {
|
|
634
|
-
let {
|
|
635
|
-
server,
|
|
636
|
-
bypass
|
|
637
|
-
} = proxy;
|
|
598
|
+
let { server, bypass } = proxy;
|
|
638
599
|
let url;
|
|
639
600
|
try {
|
|
640
|
-
// new URL('127.0.0.1:8080') throws
|
|
641
|
-
// new URL('localhost:8080') fails to parse host or protocol
|
|
642
|
-
// In both of these cases, we need to try re-parse URL with `http://` prefix.
|
|
643
601
|
url = new URL(server);
|
|
644
|
-
if (!url.host || !url.protocol)
|
|
602
|
+
if (!url.host || !url.protocol)
|
|
603
|
+
url = new URL("http://" + server);
|
|
645
604
|
} catch (e) {
|
|
646
|
-
url = new URL(
|
|
647
|
-
}
|
|
648
|
-
if (url.protocol ===
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
};
|
|
605
|
+
url = new URL("http://" + server);
|
|
606
|
+
}
|
|
607
|
+
if (url.protocol === "socks4:" && (proxy.username || proxy.password))
|
|
608
|
+
throw new Error(`Socks4 proxy protocol does not support authentication`);
|
|
609
|
+
if (url.protocol === "socks5:" && (proxy.username || proxy.password))
|
|
610
|
+
throw new Error(`Browser does not support socks5 proxy authentication`);
|
|
611
|
+
server = url.protocol + "//" + url.host;
|
|
612
|
+
if (bypass)
|
|
613
|
+
bypass = bypass.split(",").map((t) => t.trim()).join(",");
|
|
614
|
+
return { ...proxy, server, bypass };
|
|
657
615
|
}
|
|
658
|
-
const paramsThatAllowContextReuse = [
|
|
616
|
+
const paramsThatAllowContextReuse = [
|
|
617
|
+
"colorScheme",
|
|
618
|
+
"forcedColors",
|
|
619
|
+
"reducedMotion",
|
|
620
|
+
"contrast",
|
|
621
|
+
"screen",
|
|
622
|
+
"userAgent",
|
|
623
|
+
"viewport"
|
|
624
|
+
];
|
|
659
625
|
const defaultNewContextParamValues = {
|
|
660
626
|
noDefaultViewport: false,
|
|
661
627
|
ignoreHTTPSErrors: false,
|
|
@@ -664,8 +630,17 @@ const defaultNewContextParamValues = {
|
|
|
664
630
|
offline: false,
|
|
665
631
|
isMobile: false,
|
|
666
632
|
hasTouch: false,
|
|
667
|
-
acceptDownloads:
|
|
633
|
+
acceptDownloads: "accept",
|
|
668
634
|
strictSelectors: false,
|
|
669
|
-
serviceWorkers:
|
|
670
|
-
locale:
|
|
671
|
-
};
|
|
635
|
+
serviceWorkers: "allow",
|
|
636
|
+
locale: "en-US"
|
|
637
|
+
};
|
|
638
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
639
|
+
0 && (module.exports = {
|
|
640
|
+
BrowserContext,
|
|
641
|
+
assertBrowserContextIsNotOwned,
|
|
642
|
+
normalizeProxySettings,
|
|
643
|
+
validateBrowserContextOptions,
|
|
644
|
+
verifyClientCertificates,
|
|
645
|
+
verifyGeolocation
|
|
646
|
+
});
|