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