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
|
@@ -1,251 +1,245 @@
|
|
|
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
|
+
prepareBrowserContextParams: () => prepareBrowserContextParams,
|
|
33
|
+
toClientCertificatesProtocol: () => toClientCertificatesProtocol
|
|
5
34
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
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
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
var _stackTrace = require("../utils/isomorphic/stackTrace");
|
|
34
|
-
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); }
|
|
35
|
-
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; }
|
|
36
|
-
/**
|
|
37
|
-
* Copyright 2017 Google Inc. All rights reserved.
|
|
38
|
-
* Modifications copyright (c) Microsoft Corporation.
|
|
39
|
-
*
|
|
40
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
41
|
-
* you may not use this file except in compliance with the License.
|
|
42
|
-
* You may obtain a copy of the License at
|
|
43
|
-
*
|
|
44
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
45
|
-
*
|
|
46
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
47
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
48
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
49
|
-
* See the License for the specific language governing permissions and
|
|
50
|
-
* limitations under the License.
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
class BrowserContext extends _channelOwner.ChannelOwner {
|
|
54
|
-
static from(context) {
|
|
55
|
-
return context._object;
|
|
56
|
-
}
|
|
57
|
-
static fromNullable(context) {
|
|
58
|
-
return context ? BrowserContext.from(context) : null;
|
|
59
|
-
}
|
|
35
|
+
module.exports = __toCommonJS(browserContext_exports);
|
|
36
|
+
var import_artifact = require("./artifact");
|
|
37
|
+
var import_browser = require("./browser");
|
|
38
|
+
var import_cdpSession = require("./cdpSession");
|
|
39
|
+
var import_channelOwner = require("./channelOwner");
|
|
40
|
+
var import_clientHelper = require("./clientHelper");
|
|
41
|
+
var import_clock = require("./clock");
|
|
42
|
+
var import_consoleMessage = require("./consoleMessage");
|
|
43
|
+
var import_dialog = require("./dialog");
|
|
44
|
+
var import_errors = require("./errors");
|
|
45
|
+
var import_events = require("./events");
|
|
46
|
+
var import_fetch = require("./fetch");
|
|
47
|
+
var import_frame = require("./frame");
|
|
48
|
+
var import_harRouter = require("./harRouter");
|
|
49
|
+
var network = __toESM(require("./network"));
|
|
50
|
+
var import_page = require("./page");
|
|
51
|
+
var import_tracing = require("./tracing");
|
|
52
|
+
var import_waiter = require("./waiter");
|
|
53
|
+
var import_webError = require("./webError");
|
|
54
|
+
var import_worker = require("./worker");
|
|
55
|
+
var import_timeoutSettings = require("./timeoutSettings");
|
|
56
|
+
var import_fileUtils = require("./fileUtils");
|
|
57
|
+
var import_headers = require("../utils/isomorphic/headers");
|
|
58
|
+
var import_urlMatch = require("../utils/isomorphic/urlMatch");
|
|
59
|
+
var import_rtti = require("../utils/isomorphic/rtti");
|
|
60
|
+
var import_stackTrace = require("../utils/isomorphic/stackTrace");
|
|
61
|
+
class BrowserContext extends import_channelOwner.ChannelOwner {
|
|
60
62
|
constructor(parent, type, guid, initializer) {
|
|
61
|
-
var _this$_browser, _this$_browser2;
|
|
62
63
|
super(parent, type, guid, initializer);
|
|
63
|
-
this._pages = new Set();
|
|
64
|
+
this._pages = /* @__PURE__ */ new Set();
|
|
64
65
|
this._routes = [];
|
|
65
66
|
this._webSocketRoutes = [];
|
|
66
67
|
this._browser = null;
|
|
67
|
-
this.
|
|
68
|
-
this._bindings = new Map();
|
|
69
|
-
this._timeoutSettings = void 0;
|
|
70
|
-
this._ownerPage = void 0;
|
|
71
|
-
this._closedPromise = void 0;
|
|
68
|
+
this._bindings = /* @__PURE__ */ new Map();
|
|
72
69
|
this._options = {};
|
|
73
|
-
this.
|
|
74
|
-
this.
|
|
75
|
-
this.
|
|
76
|
-
this._backgroundPages = new Set();
|
|
77
|
-
this._serviceWorkers = new Set();
|
|
78
|
-
this._isChromium = void 0;
|
|
79
|
-
this._harRecorders = new Map();
|
|
70
|
+
this._backgroundPages = /* @__PURE__ */ new Set();
|
|
71
|
+
this._serviceWorkers = /* @__PURE__ */ new Set();
|
|
72
|
+
this._harRecorders = /* @__PURE__ */ new Map();
|
|
80
73
|
this._closeWasCalled = false;
|
|
81
|
-
this._closeReason = void 0;
|
|
82
74
|
this._harRouters = [];
|
|
83
75
|
this.routeInjecting = false;
|
|
84
|
-
this._timeoutSettings = new
|
|
85
|
-
if (parent instanceof
|
|
86
|
-
|
|
87
|
-
this.
|
|
88
|
-
this.
|
|
89
|
-
this.
|
|
90
|
-
this.
|
|
91
|
-
this.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this._channel.on(
|
|
95
|
-
this._channel.on(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
route
|
|
100
|
-
}) => this._onRoute(network.Route.from(route)));
|
|
101
|
-
this._channel.on('webSocketRoute', ({
|
|
102
|
-
webSocketRoute
|
|
103
|
-
}) => this._onWebSocketRoute(network.WebSocketRoute.from(webSocketRoute)));
|
|
104
|
-
this._channel.on('backgroundPage', ({
|
|
105
|
-
page
|
|
106
|
-
}) => {
|
|
107
|
-
const backgroundPage = _page.Page.from(page);
|
|
76
|
+
this._timeoutSettings = new import_timeoutSettings.TimeoutSettings(this._platform);
|
|
77
|
+
if (parent instanceof import_browser.Browser)
|
|
78
|
+
this._browser = parent;
|
|
79
|
+
this._browser?._contexts.add(this);
|
|
80
|
+
this._isChromium = this._browser?._name === "chromium";
|
|
81
|
+
this.tracing = import_tracing.Tracing.from(initializer.tracing);
|
|
82
|
+
this.request = import_fetch.APIRequestContext.from(initializer.requestContext);
|
|
83
|
+
this.clock = new import_clock.Clock(this);
|
|
84
|
+
this._channel.on("bindingCall", ({ binding }) => this._onBinding(import_page.BindingCall.from(binding)));
|
|
85
|
+
this._channel.on("close", () => this._onClose());
|
|
86
|
+
this._channel.on("page", ({ page }) => this._onPage(import_page.Page.from(page)));
|
|
87
|
+
this._channel.on("route", ({ route }) => this._onRoute(network.Route.from(route)));
|
|
88
|
+
this._channel.on("webSocketRoute", ({ webSocketRoute }) => this._onWebSocketRoute(network.WebSocketRoute.from(webSocketRoute)));
|
|
89
|
+
this._channel.on("backgroundPage", ({ page }) => {
|
|
90
|
+
const backgroundPage = import_page.Page.from(page);
|
|
108
91
|
this._backgroundPages.add(backgroundPage);
|
|
109
|
-
this.emit(
|
|
92
|
+
this.emit(import_events.Events.BrowserContext.BackgroundPage, backgroundPage);
|
|
110
93
|
});
|
|
111
|
-
this._channel.on(
|
|
112
|
-
worker
|
|
113
|
-
}) => {
|
|
114
|
-
const serviceWorker = _worker.Worker.from(worker);
|
|
94
|
+
this._channel.on("serviceWorker", ({ worker }) => {
|
|
95
|
+
const serviceWorker = import_worker.Worker.from(worker);
|
|
115
96
|
serviceWorker._context = this;
|
|
116
97
|
this._serviceWorkers.add(serviceWorker);
|
|
117
|
-
this.emit(
|
|
98
|
+
this.emit(import_events.Events.BrowserContext.ServiceWorker, serviceWorker);
|
|
118
99
|
});
|
|
119
|
-
this._channel.on(
|
|
120
|
-
const consoleMessage = new
|
|
121
|
-
this.emit(
|
|
100
|
+
this._channel.on("console", (event) => {
|
|
101
|
+
const consoleMessage = new import_consoleMessage.ConsoleMessage(this._platform, event);
|
|
102
|
+
this.emit(import_events.Events.BrowserContext.Console, consoleMessage);
|
|
122
103
|
const page = consoleMessage.page();
|
|
123
|
-
if (page)
|
|
104
|
+
if (page)
|
|
105
|
+
page.emit(import_events.Events.Page.Console, consoleMessage);
|
|
124
106
|
});
|
|
125
|
-
this._channel.on(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
this.emit(_events.Events.BrowserContext.WebError, new _webError.WebError(pageObject, parsedError));
|
|
132
|
-
if (pageObject) pageObject.emit(_events.Events.Page.PageError, parsedError);
|
|
107
|
+
this._channel.on("pageError", ({ error, page }) => {
|
|
108
|
+
const pageObject = import_page.Page.from(page);
|
|
109
|
+
const parsedError = (0, import_errors.parseError)(error);
|
|
110
|
+
this.emit(import_events.Events.BrowserContext.WebError, new import_webError.WebError(pageObject, parsedError));
|
|
111
|
+
if (pageObject)
|
|
112
|
+
pageObject.emit(import_events.Events.Page.PageError, parsedError);
|
|
133
113
|
});
|
|
134
|
-
this._channel.on(
|
|
135
|
-
dialog
|
|
136
|
-
|
|
137
|
-
const dialogObject = _dialog.Dialog.from(dialog);
|
|
138
|
-
let hasListeners = this.emit(_events.Events.BrowserContext.Dialog, dialogObject);
|
|
114
|
+
this._channel.on("dialog", ({ dialog }) => {
|
|
115
|
+
const dialogObject = import_dialog.Dialog.from(dialog);
|
|
116
|
+
let hasListeners = this.emit(import_events.Events.BrowserContext.Dialog, dialogObject);
|
|
139
117
|
const page = dialogObject.page();
|
|
140
|
-
if (page)
|
|
118
|
+
if (page)
|
|
119
|
+
hasListeners = page.emit(import_events.Events.Page.Dialog, dialogObject) || hasListeners;
|
|
141
120
|
if (!hasListeners) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
121
|
+
if (dialogObject.type() === "beforeunload")
|
|
122
|
+
dialog.accept({}).catch(() => {
|
|
123
|
+
});
|
|
124
|
+
else
|
|
125
|
+
dialog.dismiss().catch(() => {
|
|
126
|
+
});
|
|
147
127
|
}
|
|
148
128
|
});
|
|
149
|
-
this._channel.on(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}) => this.
|
|
153
|
-
this.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
129
|
+
this._channel.on("request", ({ request, page }) => this._onRequest(network.Request.from(request), import_page.Page.fromNullable(page)));
|
|
130
|
+
this._channel.on("requestFailed", ({ request, failureText, responseEndTiming, page }) => this._onRequestFailed(network.Request.from(request), responseEndTiming, failureText, import_page.Page.fromNullable(page)));
|
|
131
|
+
this._channel.on("requestFinished", (params) => this._onRequestFinished(params));
|
|
132
|
+
this._channel.on("response", ({ response, page }) => this._onResponse(network.Response.from(response), import_page.Page.fromNullable(page)));
|
|
133
|
+
this._closedPromise = new Promise((f) => this.once(import_events.Events.BrowserContext.Close, f));
|
|
134
|
+
this._setEventToSubscriptionMapping(/* @__PURE__ */ new Map([
|
|
135
|
+
[import_events.Events.BrowserContext.Console, "console"],
|
|
136
|
+
[import_events.Events.BrowserContext.Dialog, "dialog"],
|
|
137
|
+
[import_events.Events.BrowserContext.Request, "request"],
|
|
138
|
+
[import_events.Events.BrowserContext.Response, "response"],
|
|
139
|
+
[import_events.Events.BrowserContext.RequestFinished, "requestFinished"],
|
|
140
|
+
[import_events.Events.BrowserContext.RequestFailed, "requestFailed"]
|
|
141
|
+
]));
|
|
142
|
+
}
|
|
143
|
+
static from(context) {
|
|
144
|
+
return context._object;
|
|
145
|
+
}
|
|
146
|
+
static fromNullable(context) {
|
|
147
|
+
return context ? BrowserContext.from(context) : null;
|
|
166
148
|
}
|
|
167
149
|
_setOptions(contextOptions, browserOptions) {
|
|
168
150
|
this._options = contextOptions;
|
|
169
|
-
if (this._options.recordHar)
|
|
170
|
-
path: this._options.recordHar.path,
|
|
171
|
-
content: this._options.recordHar.content
|
|
172
|
-
});
|
|
151
|
+
if (this._options.recordHar)
|
|
152
|
+
this._harRecorders.set("", { path: this._options.recordHar.path, content: this._options.recordHar.content });
|
|
173
153
|
this.tracing._tracesDir = browserOptions.tracesDir;
|
|
174
154
|
}
|
|
175
155
|
_onPage(page) {
|
|
176
156
|
this._pages.add(page);
|
|
177
|
-
this.emit(
|
|
178
|
-
if (page._opener && !page._opener.isClosed())
|
|
157
|
+
this.emit(import_events.Events.BrowserContext.Page, page);
|
|
158
|
+
if (page._opener && !page._opener.isClosed())
|
|
159
|
+
page._opener.emit(import_events.Events.Page.Popup, page);
|
|
179
160
|
}
|
|
180
161
|
_onRequest(request, page) {
|
|
181
|
-
this.emit(
|
|
182
|
-
if (page)
|
|
162
|
+
this.emit(import_events.Events.BrowserContext.Request, request);
|
|
163
|
+
if (page)
|
|
164
|
+
page.emit(import_events.Events.Page.Request, request);
|
|
183
165
|
}
|
|
184
166
|
_onResponse(response, page) {
|
|
185
|
-
this.emit(
|
|
186
|
-
if (page)
|
|
167
|
+
this.emit(import_events.Events.BrowserContext.Response, response);
|
|
168
|
+
if (page)
|
|
169
|
+
page.emit(import_events.Events.Page.Response, response);
|
|
187
170
|
}
|
|
188
171
|
_onRequestFailed(request, responseEndTiming, failureText, page) {
|
|
189
172
|
request._failureText = failureText || null;
|
|
190
173
|
request._setResponseEndTiming(responseEndTiming);
|
|
191
|
-
this.emit(
|
|
192
|
-
if (page)
|
|
174
|
+
this.emit(import_events.Events.BrowserContext.RequestFailed, request);
|
|
175
|
+
if (page)
|
|
176
|
+
page.emit(import_events.Events.Page.RequestFailed, request);
|
|
193
177
|
}
|
|
194
178
|
_onRequestFinished(params) {
|
|
195
|
-
const {
|
|
196
|
-
responseEndTiming
|
|
197
|
-
} = params;
|
|
179
|
+
const { responseEndTiming } = params;
|
|
198
180
|
const request = network.Request.from(params.request);
|
|
199
181
|
const response = network.Response.fromNullable(params.response);
|
|
200
|
-
const page =
|
|
182
|
+
const page = import_page.Page.fromNullable(params.page);
|
|
201
183
|
request._setResponseEndTiming(responseEndTiming);
|
|
202
|
-
this.emit(
|
|
203
|
-
if (page)
|
|
204
|
-
|
|
184
|
+
this.emit(import_events.Events.BrowserContext.RequestFinished, request);
|
|
185
|
+
if (page)
|
|
186
|
+
page.emit(import_events.Events.Page.RequestFinished, request);
|
|
187
|
+
if (response)
|
|
188
|
+
response._finishedPromise.resolve(null);
|
|
205
189
|
}
|
|
206
190
|
async _onRoute(route) {
|
|
207
191
|
route._context = this;
|
|
208
192
|
const page = route.request()._safePage();
|
|
209
193
|
const routeHandlers = this._routes.slice();
|
|
210
194
|
for (const routeHandler of routeHandlers) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (!routeHandler.matches(route.request().url()))
|
|
195
|
+
if (page?._closeWasCalled || this._closeWasCalled)
|
|
196
|
+
return;
|
|
197
|
+
if (!routeHandler.matches(route.request().url()))
|
|
198
|
+
continue;
|
|
214
199
|
const index = this._routes.indexOf(routeHandler);
|
|
215
|
-
if (index === -1)
|
|
216
|
-
|
|
200
|
+
if (index === -1)
|
|
201
|
+
continue;
|
|
202
|
+
if (routeHandler.willExpire())
|
|
203
|
+
this._routes.splice(index, 1);
|
|
217
204
|
const handled = await routeHandler.handle(route);
|
|
218
|
-
if (!this._routes.length)
|
|
219
|
-
|
|
205
|
+
if (!this._routes.length)
|
|
206
|
+
this._wrapApiCall(() => this._updateInterceptionPatterns(), true).catch(() => {
|
|
207
|
+
});
|
|
208
|
+
if (handled)
|
|
209
|
+
return;
|
|
220
210
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
211
|
+
await route._innerContinue(
|
|
212
|
+
true
|
|
213
|
+
/* isFallback */
|
|
214
|
+
).catch(() => {
|
|
215
|
+
});
|
|
224
216
|
}
|
|
225
217
|
async _onWebSocketRoute(webSocketRoute) {
|
|
226
|
-
const routeHandler = this._webSocketRoutes.find(route => route.matches(webSocketRoute.url()));
|
|
227
|
-
if (routeHandler)
|
|
218
|
+
const routeHandler = this._webSocketRoutes.find((route) => route.matches(webSocketRoute.url()));
|
|
219
|
+
if (routeHandler)
|
|
220
|
+
await routeHandler.handle(webSocketRoute);
|
|
221
|
+
else
|
|
222
|
+
webSocketRoute.connectToServer();
|
|
228
223
|
}
|
|
229
224
|
async _onBinding(bindingCall) {
|
|
230
225
|
const func = this._bindings.get(bindingCall._initializer.name);
|
|
231
|
-
if (!func)
|
|
226
|
+
if (!func)
|
|
227
|
+
return;
|
|
232
228
|
await bindingCall.call(func);
|
|
233
229
|
}
|
|
234
230
|
setDefaultNavigationTimeout(timeout) {
|
|
235
231
|
this._timeoutSettings.setDefaultNavigationTimeout(timeout);
|
|
236
232
|
this._wrapApiCall(async () => {
|
|
237
|
-
await this._channel.setDefaultNavigationTimeoutNoReply({
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}, true).catch(() => {});
|
|
233
|
+
await this._channel.setDefaultNavigationTimeoutNoReply({ timeout });
|
|
234
|
+
}, true).catch(() => {
|
|
235
|
+
});
|
|
241
236
|
}
|
|
242
237
|
setDefaultTimeout(timeout) {
|
|
243
238
|
this._timeoutSettings.setDefaultTimeout(timeout);
|
|
244
239
|
this._wrapApiCall(async () => {
|
|
245
|
-
await this._channel.setDefaultTimeoutNoReply({
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}, true).catch(() => {});
|
|
240
|
+
await this._channel.setDefaultTimeoutNoReply({ timeout });
|
|
241
|
+
}, true).catch(() => {
|
|
242
|
+
});
|
|
249
243
|
}
|
|
250
244
|
browser() {
|
|
251
245
|
return this._browser;
|
|
@@ -254,84 +248,65 @@ class BrowserContext extends _channelOwner.ChannelOwner {
|
|
|
254
248
|
return [...this._pages];
|
|
255
249
|
}
|
|
256
250
|
async newPage() {
|
|
257
|
-
if (this._ownerPage)
|
|
258
|
-
|
|
251
|
+
if (this._ownerPage)
|
|
252
|
+
throw new Error("Please use browser.newContext()");
|
|
253
|
+
return import_page.Page.from((await this._channel.newPage()).page);
|
|
259
254
|
}
|
|
260
255
|
async cookies(urls) {
|
|
261
|
-
if (!urls)
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
urls
|
|
265
|
-
})).cookies;
|
|
256
|
+
if (!urls)
|
|
257
|
+
urls = [];
|
|
258
|
+
if (urls && typeof urls === "string")
|
|
259
|
+
urls = [urls];
|
|
260
|
+
return (await this._channel.cookies({ urls })).cookies;
|
|
266
261
|
}
|
|
267
262
|
async addCookies(cookies) {
|
|
268
|
-
await this._channel.addCookies({
|
|
269
|
-
cookies
|
|
270
|
-
});
|
|
263
|
+
await this._channel.addCookies({ cookies });
|
|
271
264
|
}
|
|
272
265
|
async clearCookies(options = {}) {
|
|
273
266
|
await this._channel.clearCookies({
|
|
274
|
-
name: (0,
|
|
275
|
-
nameRegexSource: (0,
|
|
276
|
-
nameRegexFlags: (0,
|
|
277
|
-
domain: (0,
|
|
278
|
-
domainRegexSource: (0,
|
|
279
|
-
domainRegexFlags: (0,
|
|
280
|
-
path: (0,
|
|
281
|
-
pathRegexSource: (0,
|
|
282
|
-
pathRegexFlags: (0,
|
|
267
|
+
name: (0, import_rtti.isString)(options.name) ? options.name : void 0,
|
|
268
|
+
nameRegexSource: (0, import_rtti.isRegExp)(options.name) ? options.name.source : void 0,
|
|
269
|
+
nameRegexFlags: (0, import_rtti.isRegExp)(options.name) ? options.name.flags : void 0,
|
|
270
|
+
domain: (0, import_rtti.isString)(options.domain) ? options.domain : void 0,
|
|
271
|
+
domainRegexSource: (0, import_rtti.isRegExp)(options.domain) ? options.domain.source : void 0,
|
|
272
|
+
domainRegexFlags: (0, import_rtti.isRegExp)(options.domain) ? options.domain.flags : void 0,
|
|
273
|
+
path: (0, import_rtti.isString)(options.path) ? options.path : void 0,
|
|
274
|
+
pathRegexSource: (0, import_rtti.isRegExp)(options.path) ? options.path.source : void 0,
|
|
275
|
+
pathRegexFlags: (0, import_rtti.isRegExp)(options.path) ? options.path.flags : void 0
|
|
283
276
|
});
|
|
284
277
|
}
|
|
285
278
|
async grantPermissions(permissions, options) {
|
|
286
|
-
await this._channel.grantPermissions({
|
|
287
|
-
permissions,
|
|
288
|
-
...options
|
|
289
|
-
});
|
|
279
|
+
await this._channel.grantPermissions({ permissions, ...options });
|
|
290
280
|
}
|
|
291
281
|
async clearPermissions() {
|
|
292
282
|
await this._channel.clearPermissions();
|
|
293
283
|
}
|
|
294
284
|
async setGeolocation(geolocation) {
|
|
295
|
-
await this._channel.setGeolocation({
|
|
296
|
-
geolocation: geolocation || undefined
|
|
297
|
-
});
|
|
285
|
+
await this._channel.setGeolocation({ geolocation: geolocation || void 0 });
|
|
298
286
|
}
|
|
299
287
|
async setExtraHTTPHeaders(headers) {
|
|
300
288
|
network.validateHeaders(headers);
|
|
301
|
-
await this._channel.setExtraHTTPHeaders({
|
|
302
|
-
headers: (0, _headers.headersObjectToArray)(headers)
|
|
303
|
-
});
|
|
289
|
+
await this._channel.setExtraHTTPHeaders({ headers: (0, import_headers.headersObjectToArray)(headers) });
|
|
304
290
|
}
|
|
305
291
|
async setOffline(offline) {
|
|
306
|
-
await this._channel.setOffline({
|
|
307
|
-
offline
|
|
308
|
-
});
|
|
292
|
+
await this._channel.setOffline({ offline });
|
|
309
293
|
}
|
|
310
294
|
async setHTTPCredentials(httpCredentials) {
|
|
311
|
-
await this._channel.setHTTPCredentials({
|
|
312
|
-
httpCredentials: httpCredentials || undefined
|
|
313
|
-
});
|
|
295
|
+
await this._channel.setHTTPCredentials({ httpCredentials: httpCredentials || void 0 });
|
|
314
296
|
}
|
|
315
297
|
async addInitScript(script, arg) {
|
|
316
298
|
await this.installInjectRoute();
|
|
317
|
-
const source = await (0,
|
|
318
|
-
await this._channel.addInitScript({
|
|
319
|
-
source
|
|
320
|
-
});
|
|
299
|
+
const source = await (0, import_clientHelper.evaluationScript)(this._platform, script, arg);
|
|
300
|
+
await this._channel.addInitScript({ source });
|
|
321
301
|
}
|
|
322
302
|
async exposeBinding(name, callback, options = {}) {
|
|
323
303
|
await this.installInjectRoute();
|
|
324
|
-
await this._channel.exposeBinding({
|
|
325
|
-
name,
|
|
326
|
-
needsHandle: options.handle
|
|
327
|
-
});
|
|
304
|
+
await this._channel.exposeBinding({ name, needsHandle: options.handle });
|
|
328
305
|
this._bindings.set(name, callback);
|
|
329
306
|
}
|
|
330
307
|
async exposeFunction(name, callback) {
|
|
331
308
|
await this.installInjectRoute();
|
|
332
|
-
await this._channel.exposeBinding({
|
|
333
|
-
name
|
|
334
|
-
});
|
|
309
|
+
await this._channel.exposeBinding({ name });
|
|
335
310
|
const binding = (source, ...args) => callback(...args);
|
|
336
311
|
this._bindings.set(name, binding);
|
|
337
312
|
}
|
|
@@ -344,94 +319,85 @@ class BrowserContext extends _channelOwner.ChannelOwner {
|
|
|
344
319
|
await this._updateWebSocketInterceptionPatterns();
|
|
345
320
|
}
|
|
346
321
|
async _recordIntoHAR(har, page, options = {}) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
harId
|
|
350
|
-
} = await this._channel.harStart({
|
|
351
|
-
page: page === null || page === void 0 ? void 0 : page._channel,
|
|
322
|
+
const { harId } = await this._channel.harStart({
|
|
323
|
+
page: page?._channel,
|
|
352
324
|
options: prepareRecordHarOptions({
|
|
353
325
|
path: har,
|
|
354
|
-
content:
|
|
355
|
-
mode:
|
|
326
|
+
content: options.updateContent ?? "attach",
|
|
327
|
+
mode: options.updateMode ?? "minimal",
|
|
356
328
|
urlFilter: options.url
|
|
357
329
|
})
|
|
358
330
|
});
|
|
359
|
-
this._harRecorders.set(harId, {
|
|
360
|
-
path: har,
|
|
361
|
-
content: (_options$updateConten2 = options.updateContent) !== null && _options$updateConten2 !== void 0 ? _options$updateConten2 : 'attach'
|
|
362
|
-
});
|
|
331
|
+
this._harRecorders.set(harId, { path: har, content: options.updateContent ?? "attach" });
|
|
363
332
|
}
|
|
364
333
|
async routeFromHAR(har, options = {}) {
|
|
365
334
|
const localUtils = this._connection.localUtils();
|
|
366
|
-
if (!localUtils)
|
|
335
|
+
if (!localUtils)
|
|
336
|
+
throw new Error("Route from har is not supported in thin clients");
|
|
367
337
|
if (options.update) {
|
|
368
338
|
await this._recordIntoHAR(har, null, options);
|
|
369
339
|
return;
|
|
370
340
|
}
|
|
371
|
-
const harRouter = await
|
|
372
|
-
urlMatch: options.url
|
|
373
|
-
});
|
|
341
|
+
const harRouter = await import_harRouter.HarRouter.create(localUtils, har, options.notFound || "abort", { urlMatch: options.url });
|
|
374
342
|
this._harRouters.push(harRouter);
|
|
375
343
|
await harRouter.addContextRoute(this);
|
|
376
344
|
}
|
|
377
345
|
_disposeHarRouters() {
|
|
378
|
-
this._harRouters.forEach(router => router.dispose());
|
|
346
|
+
this._harRouters.forEach((router) => router.dispose());
|
|
379
347
|
this._harRouters = [];
|
|
380
348
|
}
|
|
381
349
|
async unrouteAll(options) {
|
|
382
|
-
await this._unrouteInternal(this._routes, [], options
|
|
350
|
+
await this._unrouteInternal(this._routes, [], options?.behavior);
|
|
383
351
|
this._disposeHarRouters();
|
|
384
352
|
}
|
|
385
353
|
async unroute(url, handler) {
|
|
386
354
|
const removed = [];
|
|
387
355
|
const remaining = [];
|
|
388
356
|
for (const route of this._routes) {
|
|
389
|
-
if ((0,
|
|
357
|
+
if ((0, import_urlMatch.urlMatchesEqual)(route.url, url) && (!handler || route.handler === handler))
|
|
358
|
+
removed.push(route);
|
|
359
|
+
else
|
|
360
|
+
remaining.push(route);
|
|
390
361
|
}
|
|
391
|
-
await this._unrouteInternal(removed, remaining,
|
|
362
|
+
await this._unrouteInternal(removed, remaining, "default");
|
|
392
363
|
}
|
|
393
364
|
async _unrouteInternal(removed, remaining, behavior) {
|
|
394
365
|
this._routes = remaining;
|
|
395
366
|
await this._updateInterceptionPatterns();
|
|
396
|
-
if (!behavior || behavior ===
|
|
397
|
-
|
|
367
|
+
if (!behavior || behavior === "default")
|
|
368
|
+
return;
|
|
369
|
+
const promises = removed.map((routeHandler) => routeHandler.stop(behavior));
|
|
398
370
|
await Promise.all(promises);
|
|
399
371
|
}
|
|
400
372
|
async _updateInterceptionPatterns() {
|
|
401
373
|
const patterns = network.RouteHandler.prepareInterceptionPatterns(this._routes);
|
|
402
|
-
await this._channel.setNetworkInterceptionPatterns({
|
|
403
|
-
patterns
|
|
404
|
-
});
|
|
374
|
+
await this._channel.setNetworkInterceptionPatterns({ patterns });
|
|
405
375
|
}
|
|
406
376
|
async _updateWebSocketInterceptionPatterns() {
|
|
407
377
|
const patterns = network.WebSocketRouteHandler.prepareInterceptionPatterns(this._webSocketRoutes);
|
|
408
|
-
await this._channel.setWebSocketInterceptionPatterns({
|
|
409
|
-
patterns
|
|
410
|
-
});
|
|
378
|
+
await this._channel.setWebSocketInterceptionPatterns({ patterns });
|
|
411
379
|
}
|
|
412
380
|
_effectiveCloseReason() {
|
|
413
|
-
|
|
414
|
-
return this._closeReason || ((_this$_browser3 = this._browser) === null || _this$_browser3 === void 0 ? void 0 : _this$_browser3._closeReason);
|
|
381
|
+
return this._closeReason || this._browser?._closeReason;
|
|
415
382
|
}
|
|
416
383
|
async waitForEvent(event, optionsOrPredicate = {}) {
|
|
417
384
|
return await this._wrapApiCall(async () => {
|
|
418
|
-
const timeout = this._timeoutSettings.timeout(typeof optionsOrPredicate ===
|
|
419
|
-
const predicate = typeof optionsOrPredicate ===
|
|
420
|
-
const waiter =
|
|
385
|
+
const timeout = this._timeoutSettings.timeout(typeof optionsOrPredicate === "function" ? {} : optionsOrPredicate);
|
|
386
|
+
const predicate = typeof optionsOrPredicate === "function" ? optionsOrPredicate : optionsOrPredicate.predicate;
|
|
387
|
+
const waiter = import_waiter.Waiter.createForEvent(this, event);
|
|
421
388
|
waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded while waiting for event "${event}"`);
|
|
422
|
-
if (event !==
|
|
389
|
+
if (event !== import_events.Events.BrowserContext.Close)
|
|
390
|
+
waiter.rejectOnEvent(this, import_events.Events.BrowserContext.Close, () => new import_errors.TargetClosedError(this._effectiveCloseReason()));
|
|
423
391
|
const result = await waiter.waitForEvent(this, event, predicate);
|
|
424
392
|
waiter.dispose();
|
|
425
393
|
return result;
|
|
426
394
|
});
|
|
427
395
|
}
|
|
428
396
|
async storageState(options = {}) {
|
|
429
|
-
const state = await this._channel.storageState({
|
|
430
|
-
indexedDB: options.indexedDB
|
|
431
|
-
});
|
|
397
|
+
const state = await this._channel.storageState({ indexedDB: options.indexedDB });
|
|
432
398
|
if (options.path) {
|
|
433
|
-
await (0,
|
|
434
|
-
await this._platform.fs().promises.writeFile(options.path, JSON.stringify(state,
|
|
399
|
+
await (0, import_fileUtils.mkdirIfNeeded)(this._platform, options.path);
|
|
400
|
+
await this._platform.fs().promises.writeFile(options.path, JSON.stringify(state, void 0, 2), "utf8");
|
|
435
401
|
}
|
|
436
402
|
return state;
|
|
437
403
|
}
|
|
@@ -442,52 +408,43 @@ class BrowserContext extends _channelOwner.ChannelOwner {
|
|
|
442
408
|
return [...this._serviceWorkers];
|
|
443
409
|
}
|
|
444
410
|
async newCDPSession(page) {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
const result = await this._channel.newCDPSession(page instanceof
|
|
448
|
-
|
|
449
|
-
} : {
|
|
450
|
-
frame: page._channel
|
|
451
|
-
});
|
|
452
|
-
return _cdpSession.CDPSession.from(result.session);
|
|
411
|
+
if (!(page instanceof import_page.Page) && !(page instanceof import_frame.Frame))
|
|
412
|
+
throw new Error("page: expected Page or Frame");
|
|
413
|
+
const result = await this._channel.newCDPSession(page instanceof import_page.Page ? { page: page._channel } : { frame: page._channel });
|
|
414
|
+
return import_cdpSession.CDPSession.from(result.session);
|
|
453
415
|
}
|
|
454
416
|
_onClose() {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
417
|
+
if (this._browser)
|
|
418
|
+
this._browser._contexts.delete(this);
|
|
419
|
+
this._browserType?._contexts?.delete(this);
|
|
458
420
|
this._disposeHarRouters();
|
|
459
421
|
this.tracing._resetStackCounter();
|
|
460
|
-
this.emit(
|
|
422
|
+
this.emit(import_events.Events.BrowserContext.Close, this);
|
|
461
423
|
}
|
|
462
424
|
async [Symbol.asyncDispose]() {
|
|
463
425
|
await this.close();
|
|
464
426
|
}
|
|
465
427
|
async close(options = {}) {
|
|
466
|
-
if (this._closeWasCalled)
|
|
428
|
+
if (this._closeWasCalled)
|
|
429
|
+
return;
|
|
467
430
|
this._closeReason = options.reason;
|
|
468
431
|
this._closeWasCalled = true;
|
|
469
432
|
await this._wrapApiCall(async () => {
|
|
470
433
|
await this.request.dispose(options);
|
|
471
434
|
}, true);
|
|
472
435
|
await this._wrapApiCall(async () => {
|
|
473
|
-
|
|
474
|
-
await ((_this$_browserType2 = this._browserType) === null || _this$_browserType2 === void 0 ? void 0 : _this$_browserType2._willCloseContext(this));
|
|
436
|
+
await this._browserType?._willCloseContext(this);
|
|
475
437
|
for (const [harId, harParams] of this._harRecorders) {
|
|
476
|
-
const har = await this._channel.harExport({
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
const
|
|
480
|
-
// Server side will compress artifact if content is attach or if file is .zip.
|
|
481
|
-
const isCompressed = harParams.content === 'attach' || harParams.path.endsWith('.zip');
|
|
482
|
-
const needCompressed = harParams.path.endsWith('.zip');
|
|
438
|
+
const har = await this._channel.harExport({ harId });
|
|
439
|
+
const artifact = import_artifact.Artifact.from(har.artifact);
|
|
440
|
+
const isCompressed = harParams.content === "attach" || harParams.path.endsWith(".zip");
|
|
441
|
+
const needCompressed = harParams.path.endsWith(".zip");
|
|
483
442
|
if (isCompressed && !needCompressed) {
|
|
484
443
|
const localUtils = this._connection.localUtils();
|
|
485
|
-
if (!localUtils)
|
|
486
|
-
|
|
487
|
-
await
|
|
488
|
-
|
|
489
|
-
harFile: harParams.path
|
|
490
|
-
});
|
|
444
|
+
if (!localUtils)
|
|
445
|
+
throw new Error("Uncompressed har is not supported in thin clients");
|
|
446
|
+
await artifact.saveAs(harParams.path + ".tmp");
|
|
447
|
+
await localUtils.harUnzip({ zipFile: harParams.path + ".tmp", harFile: harParams.path });
|
|
491
448
|
} else {
|
|
492
449
|
await artifact.saveAs(harParams.path);
|
|
493
450
|
}
|
|
@@ -502,13 +459,11 @@ class BrowserContext extends _channelOwner.ChannelOwner {
|
|
|
502
459
|
}
|
|
503
460
|
async installInjectRoute() {
|
|
504
461
|
if (this.routeInjecting) return;
|
|
505
|
-
await this.route(
|
|
462
|
+
await this.route("**/*", async (route) => {
|
|
506
463
|
try {
|
|
507
|
-
if (route.request().resourceType() ===
|
|
508
|
-
const protocol = route.request().url().split(
|
|
509
|
-
await route.continue({
|
|
510
|
-
url: protocol + '://patchright-init-script-inject.internal/'
|
|
511
|
-
});
|
|
464
|
+
if (route.request().resourceType() === "document" && route.request().url().startsWith("http")) {
|
|
465
|
+
const protocol = route.request().url().split(":")[0];
|
|
466
|
+
await route.continue({ url: protocol + "://patchright-init-script-inject.internal/" });
|
|
512
467
|
} else {
|
|
513
468
|
await route.continue();
|
|
514
469
|
}
|
|
@@ -518,42 +473,46 @@ class BrowserContext extends _channelOwner.ChannelOwner {
|
|
|
518
473
|
});
|
|
519
474
|
}
|
|
520
475
|
}
|
|
521
|
-
exports.BrowserContext = BrowserContext;
|
|
522
476
|
async function prepareStorageState(platform, options) {
|
|
523
|
-
if (typeof options.storageState !==
|
|
477
|
+
if (typeof options.storageState !== "string")
|
|
478
|
+
return options.storageState;
|
|
524
479
|
try {
|
|
525
|
-
return JSON.parse(await platform.fs().promises.readFile(options.storageState,
|
|
480
|
+
return JSON.parse(await platform.fs().promises.readFile(options.storageState, "utf8"));
|
|
526
481
|
} catch (e) {
|
|
527
|
-
(0,
|
|
482
|
+
(0, import_stackTrace.rewriteErrorMessage)(e, `Error reading storage state from ${options.storageState}:
|
|
483
|
+
` + e.message);
|
|
528
484
|
throw e;
|
|
529
485
|
}
|
|
530
486
|
}
|
|
531
487
|
function prepareRecordHarOptions(options) {
|
|
532
|
-
if (!options)
|
|
488
|
+
if (!options)
|
|
489
|
+
return;
|
|
533
490
|
return {
|
|
534
491
|
path: options.path,
|
|
535
|
-
content: options.content || (options.omitContent ?
|
|
536
|
-
urlGlob: (0,
|
|
537
|
-
urlRegexSource: (0,
|
|
538
|
-
urlRegexFlags: (0,
|
|
492
|
+
content: options.content || (options.omitContent ? "omit" : void 0),
|
|
493
|
+
urlGlob: (0, import_rtti.isString)(options.urlFilter) ? options.urlFilter : void 0,
|
|
494
|
+
urlRegexSource: (0, import_rtti.isRegExp)(options.urlFilter) ? options.urlFilter.source : void 0,
|
|
495
|
+
urlRegexFlags: (0, import_rtti.isRegExp)(options.urlFilter) ? options.urlFilter.flags : void 0,
|
|
539
496
|
mode: options.mode
|
|
540
497
|
};
|
|
541
498
|
}
|
|
542
499
|
async function prepareBrowserContextParams(platform, options) {
|
|
543
|
-
if (options.videoSize && !options.videosPath)
|
|
544
|
-
|
|
500
|
+
if (options.videoSize && !options.videosPath)
|
|
501
|
+
throw new Error(`"videoSize" option requires "videosPath" to be specified`);
|
|
502
|
+
if (options.extraHTTPHeaders)
|
|
503
|
+
network.validateHeaders(options.extraHTTPHeaders);
|
|
545
504
|
const contextParams = {
|
|
546
505
|
...options,
|
|
547
|
-
viewport: options.viewport === null ?
|
|
506
|
+
viewport: options.viewport === null ? void 0 : options.viewport,
|
|
548
507
|
noDefaultViewport: options.viewport === null,
|
|
549
|
-
extraHTTPHeaders: options.extraHTTPHeaders ? (0,
|
|
508
|
+
extraHTTPHeaders: options.extraHTTPHeaders ? (0, import_headers.headersObjectToArray)(options.extraHTTPHeaders) : void 0,
|
|
550
509
|
storageState: await prepareStorageState(platform, options),
|
|
551
510
|
serviceWorkers: options.serviceWorkers,
|
|
552
511
|
recordHar: prepareRecordHarOptions(options.recordHar),
|
|
553
|
-
colorScheme: options.colorScheme === null ?
|
|
554
|
-
reducedMotion: options.reducedMotion === null ?
|
|
555
|
-
forcedColors: options.forcedColors === null ?
|
|
556
|
-
contrast: options.contrast === null ?
|
|
512
|
+
colorScheme: options.colorScheme === null ? "no-override" : options.colorScheme,
|
|
513
|
+
reducedMotion: options.reducedMotion === null ? "no-override" : options.reducedMotion,
|
|
514
|
+
forcedColors: options.forcedColors === null ? "no-override" : options.forcedColors,
|
|
515
|
+
contrast: options.contrast === null ? "no-override" : options.contrast,
|
|
557
516
|
acceptDownloads: toAcceptDownloadsProtocol(options.acceptDownloads),
|
|
558
517
|
clientCertificates: await toClientCertificatesProtocol(platform, options.clientCertificates)
|
|
559
518
|
};
|
|
@@ -563,25 +522,37 @@ async function prepareBrowserContextParams(platform, options) {
|
|
|
563
522
|
size: options.videoSize
|
|
564
523
|
};
|
|
565
524
|
}
|
|
566
|
-
if (contextParams.recordVideo && contextParams.recordVideo.dir)
|
|
525
|
+
if (contextParams.recordVideo && contextParams.recordVideo.dir)
|
|
526
|
+
contextParams.recordVideo.dir = platform.path().resolve(contextParams.recordVideo.dir);
|
|
567
527
|
return contextParams;
|
|
568
528
|
}
|
|
569
529
|
function toAcceptDownloadsProtocol(acceptDownloads) {
|
|
570
|
-
if (acceptDownloads ===
|
|
571
|
-
|
|
572
|
-
|
|
530
|
+
if (acceptDownloads === void 0)
|
|
531
|
+
return void 0;
|
|
532
|
+
if (acceptDownloads)
|
|
533
|
+
return "accept";
|
|
534
|
+
return "deny";
|
|
573
535
|
}
|
|
574
536
|
async function toClientCertificatesProtocol(platform, certs) {
|
|
575
|
-
if (!certs)
|
|
537
|
+
if (!certs)
|
|
538
|
+
return void 0;
|
|
576
539
|
const bufferizeContent = async (value, path) => {
|
|
577
|
-
if (value)
|
|
578
|
-
|
|
540
|
+
if (value)
|
|
541
|
+
return value;
|
|
542
|
+
if (path)
|
|
543
|
+
return await platform.fs().promises.readFile(path);
|
|
579
544
|
};
|
|
580
|
-
return await Promise.all(certs.map(async cert => ({
|
|
545
|
+
return await Promise.all(certs.map(async (cert) => ({
|
|
581
546
|
origin: cert.origin,
|
|
582
547
|
cert: await bufferizeContent(cert.cert, cert.certPath),
|
|
583
548
|
key: await bufferizeContent(cert.key, cert.keyPath),
|
|
584
549
|
pfx: await bufferizeContent(cert.pfx, cert.pfxPath),
|
|
585
550
|
passphrase: cert.passphrase
|
|
586
551
|
})));
|
|
587
|
-
}
|
|
552
|
+
}
|
|
553
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
554
|
+
0 && (module.exports = {
|
|
555
|
+
BrowserContext,
|
|
556
|
+
prepareBrowserContextParams,
|
|
557
|
+
toClientCertificatesProtocol
|
|
558
|
+
});
|