patchright-core 1.51.3 → 1.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browsers.json +15 -13
- package/lib/androidServerImpl.js +42 -48
- package/lib/browserServerImpl.js +54 -67
- package/lib/cli/driver.js +71 -69
- package/lib/cli/program.js +312 -328
- package/lib/cli/programWithTestStub.js +51 -45
- package/lib/client/accessibility.js +31 -32
- package/lib/client/android.js +141 -228
- package/lib/client/api.js +135 -283
- package/lib/client/artifact.js +39 -36
- package/lib/client/browser.js +57 -61
- package/lib/client/browserContext.js +297 -326
- package/lib/client/browserType.js +92 -106
- package/lib/client/cdpSession.js +29 -31
- package/lib/client/channelOwner.js +82 -95
- package/lib/client/clientHelper.js +46 -38
- package/lib/client/clientInstrumentation.js +40 -37
- package/lib/client/clientStackTrace.js +41 -37
- package/lib/client/clock.js +36 -36
- package/lib/client/connection.js +190 -212
- package/lib/client/consoleMessage.js +31 -28
- package/lib/client/coverage.js +25 -22
- package/lib/client/dialog.js +30 -31
- package/lib/client/download.js +25 -25
- package/lib/client/electron.js +73 -75
- package/lib/client/elementHandle.js +111 -147
- package/lib/client/errors.js +53 -53
- package/lib/client/eventEmitter.js +124 -121
- package/lib/client/events.js +72 -68
- package/lib/client/fetch.js +135 -158
- package/lib/client/fileChooser.js +25 -24
- package/lib/client/fileUtils.js +31 -28
- package/lib/client/frame.js +187 -306
- package/lib/client/harRouter.js +42 -52
- package/lib/client/input.js +40 -69
- package/lib/client/jsHandle.js +54 -69
- package/lib/client/jsonPipe.js +27 -23
- package/lib/client/localUtils.js +29 -28
- package/lib/client/locator.js +161 -245
- package/lib/client/network.js +277 -295
- package/lib/client/page.js +270 -318
- package/lib/client/platform.js +46 -43
- package/lib/client/playwright.js +51 -66
- package/lib/client/selectors.js +48 -46
- package/lib/client/stream.js +29 -25
- package/lib/client/timeoutSettings.js +49 -39
- package/lib/client/tracing.js +48 -84
- package/lib/client/types.js +26 -22
- package/lib/client/video.js +35 -27
- package/lib/client/waiter.js +69 -88
- package/lib/client/webError.js +25 -23
- package/lib/client/webSocket.js +61 -56
- package/lib/client/worker.js +48 -58
- package/lib/client/writableStream.js +27 -23
- package/lib/generated/clockSource.js +26 -5
- package/lib/generated/consoleApiSource.js +26 -5
- package/lib/generated/injectedScriptSource.js +26 -5
- package/lib/generated/pollingRecorderSource.js +26 -5
- package/lib/generated/utilityScriptSource.js +26 -5
- package/lib/generated/webSocketMockSource.js +375 -4
- package/lib/inProcessFactory.js +53 -53
- package/lib/inprocess.js +2 -19
- package/lib/outofprocess.js +53 -46
- package/lib/protocol/debug.js +209 -25
- package/lib/protocol/serializers.js +153 -134
- package/lib/protocol/validator.js +2714 -2714
- package/lib/protocol/validatorPrimitives.js +114 -73
- package/lib/remote/playwrightConnection.js +140 -157
- package/lib/remote/playwrightServer.js +99 -84
- package/lib/server/accessibility.js +44 -37
- package/lib/server/android/android.js +216 -209
- package/lib/server/android/backendAdb.js +89 -82
- package/lib/server/artifact.js +78 -55
- package/lib/server/bidi/bidiBrowser.js +221 -155
- package/lib/server/bidi/bidiChromium.js +106 -79
- package/lib/server/bidi/bidiConnection.js +66 -83
- package/lib/server/bidi/bidiExecutionContext.js +128 -113
- package/lib/server/bidi/bidiFirefox.js +76 -69
- package/lib/server/bidi/bidiInput.js +86 -97
- package/lib/server/bidi/bidiNetworkManager.js +137 -154
- package/lib/server/bidi/bidiOverCdp.js +57 -58
- package/lib/server/bidi/bidiPage.js +247 -219
- package/lib/server/bidi/bidiPdf.js +52 -86
- package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
- package/lib/server/bidi/third_party/bidiDeserializer.js +55 -50
- package/lib/server/bidi/third_party/bidiKeyboard.js +236 -220
- package/lib/server/bidi/third_party/bidiProtocol.js +144 -131
- package/lib/server/bidi/third_party/bidiSerializer.js +67 -63
- package/lib/server/bidi/third_party/firefoxPrefs.js +141 -119
- package/lib/server/browser.js +76 -84
- package/lib/server/browserContext.js +321 -346
- package/lib/server/browserType.js +169 -182
- package/lib/server/callLog.js +47 -44
- package/lib/server/chromium/chromium.js +212 -190
- package/lib/server/chromium/chromiumSwitches.js +86 -64
- package/lib/server/chromium/crAccessibility.js +157 -131
- package/lib/server/chromium/crBrowser.js +253 -273
- package/lib/server/chromium/crConnection.js +91 -116
- package/lib/server/chromium/crCoverage.js +113 -127
- package/lib/server/chromium/crDevTools.js +59 -51
- package/lib/server/chromium/crDragDrop.js +62 -79
- package/lib/server/chromium/crExecutionContext.js +88 -83
- package/lib/server/chromium/crInput.js +97 -95
- package/lib/server/chromium/crNetworkManager.js +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 +77 -111
- package/lib/server/frames.js +730 -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 +329 -426
- package/lib/server/pageBinding.js +88 -0
- package/lib/server/pipeTransport.js +49 -45
- package/lib/server/playwright.js +60 -67
- package/lib/server/progress.js +56 -51
- package/lib/server/protocolError.js +34 -31
- package/lib/server/recorder/chat.js +70 -86
- package/lib/server/recorder/contextRecorder.js +134 -138
- package/lib/server/recorder/recorderApp.js +127 -136
- package/lib/server/recorder/recorderCollection.js +56 -44
- package/lib/server/recorder/recorderFrontend.js +15 -4
- package/lib/server/recorder/recorderRunner.js +79 -103
- package/lib/server/recorder/recorderUtils.js +56 -45
- package/lib/server/recorder/throttledFile.js +42 -30
- package/lib/server/recorder.js +177 -186
- package/lib/server/registry/browserFetcher.js +106 -101
- package/lib/server/registry/dependencies.js +245 -196
- package/lib/server/registry/index.js +904 -792
- package/lib/server/registry/nativeDeps.js +1073 -464
- package/lib/server/registry/oopDownloadBrowserMain.js +57 -75
- package/lib/server/screenshotter.js +166 -182
- package/lib/server/selectors.js +85 -46
- package/lib/server/socksClientCertificatesInterceptor.js +166 -185
- package/lib/server/socksInterceptor.js +62 -70
- package/lib/server/storageScript.js +94 -100
- package/lib/server/timeoutSettings.js +58 -43
- package/lib/server/trace/recorder/snapshotter.js +70 -89
- package/lib/server/trace/recorder/snapshotterInjected.js +238 -217
- package/lib/server/trace/recorder/tracing.js +321 -333
- package/lib/server/trace/test/inMemorySnapshotter.js +46 -52
- package/lib/server/trace/viewer/traceViewer.js +168 -146
- package/lib/server/transport.js +124 -133
- package/lib/server/types.js +26 -22
- package/lib/server/usKeyboardLayout.js +135 -545
- package/lib/server/utils/ascii.js +39 -26
- package/lib/server/utils/comparators.js +105 -103
- package/lib/server/utils/crypto.js +157 -112
- package/lib/server/utils/debug.js +37 -28
- package/lib/server/utils/debugLogger.js +69 -48
- package/lib/server/utils/env.js +52 -37
- package/lib/server/utils/eventsHelper.js +29 -28
- package/lib/server/utils/expectUtils.js +31 -26
- package/lib/server/utils/fileUtils.js +123 -136
- package/lib/server/utils/happyEyeballs.js +138 -123
- package/lib/server/utils/hostPlatform.js +84 -120
- package/lib/server/utils/httpServer.js +106 -121
- package/lib/server/utils/image_tools/colorUtils.js +42 -51
- package/lib/server/utils/image_tools/compare.js +44 -43
- package/lib/server/utils/image_tools/imageChannel.js +38 -30
- package/lib/server/utils/image_tools/stats.js +40 -40
- package/lib/server/utils/linuxUtils.js +50 -37
- package/lib/server/utils/network.js +143 -86
- package/lib/server/utils/nodePlatform.js +87 -79
- package/lib/server/utils/pipeTransport.js +44 -42
- package/lib/server/utils/processLauncher.js +111 -121
- package/lib/server/utils/profiler.js +52 -39
- package/lib/server/utils/socksProxy.js +280 -339
- package/lib/server/utils/spawnAsync.js +37 -41
- package/lib/server/utils/task.js +31 -38
- package/lib/server/utils/userAgent.js +73 -66
- package/lib/server/utils/wsServer.js +73 -69
- package/lib/server/utils/zipFile.js +36 -37
- package/lib/server/utils/zones.js +37 -34
- package/lib/server/webkit/protocol.d.js +16 -0
- package/lib/server/webkit/webkit.js +76 -63
- package/lib/server/webkit/wkAccessibility.js +161 -118
- package/lib/server/webkit/wkBrowser.js +159 -176
- package/lib/server/webkit/wkConnection.js +59 -83
- package/lib/server/webkit/wkExecutionContext.js +84 -70
- package/lib/server/webkit/wkInput.js +82 -80
- package/lib/server/webkit/wkInterceptableRequest.js +102 -95
- package/lib/server/webkit/wkPage.js +525 -619
- package/lib/server/webkit/wkProvisionalPage.js +45 -56
- package/lib/server/webkit/wkWorkers.js +77 -77
- package/lib/utils/isomorphic/ariaSnapshot.js +144 -152
- package/lib/utils/isomorphic/assert.js +28 -22
- package/lib/utils/isomorphic/builtins.js +90 -0
- package/lib/utils/isomorphic/colors.js +66 -59
- package/lib/utils/isomorphic/cssParser.js +121 -125
- package/lib/utils/isomorphic/cssTokenizer.js +436 -364
- package/lib/utils/isomorphic/headers.js +38 -37
- package/lib/utils/isomorphic/locatorGenerators.js +340 -357
- package/lib/utils/isomorphic/locatorParser.js +96 -105
- package/lib/utils/isomorphic/locatorUtils.js +63 -44
- package/lib/utils/isomorphic/manualPromise.js +47 -39
- package/lib/utils/isomorphic/mimeType.js +448 -25
- package/lib/utils/isomorphic/multimap.js +35 -27
- package/lib/utils/isomorphic/rtti.js +35 -33
- package/lib/utils/isomorphic/selectorParser.js +183 -193
- package/lib/utils/isomorphic/semaphore.js +27 -24
- package/lib/utils/isomorphic/stackTrace.js +87 -98
- package/lib/utils/isomorphic/stringUtils.js +113 -106
- package/lib/utils/isomorphic/time.js +41 -22
- package/lib/utils/isomorphic/timeoutRunner.js +55 -54
- package/lib/utils/isomorphic/traceUtils.js +38 -41
- package/lib/utils/isomorphic/types.js +15 -4
- package/lib/utils/isomorphic/urlMatch.js +112 -67
- package/lib/utils/isomorphic/utilityScriptSerializers.js +248 -0
- package/lib/utils.js +97 -443
- package/lib/utilsBundle.js +101 -52
- package/lib/vite/htmlReport/index.html +21 -15
- package/lib/vite/recorder/assets/{codeMirrorModule-B9YMkrwa.js → codeMirrorModule-DVQi6prl.js} +1 -1
- package/lib/vite/recorder/assets/index-97EUAAbk.js +184 -0
- package/lib/vite/recorder/index.html +1 -1
- package/lib/vite/traceViewer/assets/{codeMirrorModule-1DiydmYA.js → codeMirrorModule-dvXVzLxY.js} +1 -1
- package/lib/vite/traceViewer/assets/defaultSettingsView-BjymbO6M.js +265 -0
- package/lib/vite/traceViewer/{defaultSettingsView.5fN5lw10.css → defaultSettingsView.QdHITyLI.css} +1 -1
- package/lib/vite/traceViewer/index.ChIUCJnj.js +2 -0
- package/lib/vite/traceViewer/index.html +3 -3
- package/lib/vite/traceViewer/sw.bundle.js +3 -3
- package/lib/vite/traceViewer/uiMode.html +3 -3
- package/lib/vite/traceViewer/uiMode.jUCiCtdp.js +5 -0
- package/lib/zipBundle.js +32 -23
- package/package.json +1 -1
- package/types/protocol.d.ts +436 -17
- package/types/types.d.ts +35 -16
- package/lib/server/isomorphic/utilityScriptSerializers.js +0 -229
- package/lib/vite/recorder/assets/index-ELPgmkwA.js +0 -184
- package/lib/vite/traceViewer/assets/defaultSettingsView-l0TyP_G8.js +0 -259
- package/lib/vite/traceViewer/index.BqUZLSro.js +0 -2
- package/lib/vite/traceViewer/uiMode.C1d2m5sF.js +0 -5
package/lib/client/network.js
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var network_exports = {};
|
|
20
|
+
__export(network_exports, {
|
|
21
|
+
RawHeaders: () => RawHeaders,
|
|
22
|
+
Request: () => Request,
|
|
23
|
+
Response: () => Response,
|
|
24
|
+
Route: () => Route,
|
|
25
|
+
RouteHandler: () => RouteHandler,
|
|
26
|
+
WebSocket: () => WebSocket,
|
|
27
|
+
WebSocketRoute: () => WebSocketRoute,
|
|
28
|
+
WebSocketRouteHandler: () => WebSocketRouteHandler,
|
|
29
|
+
validateHeaders: () => validateHeaders
|
|
5
30
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
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
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Copyright (c) Microsoft Corporation.
|
|
25
|
-
*
|
|
26
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
27
|
-
* you may not use this file except in compliance with the License.
|
|
28
|
-
* You may obtain a copy of the License at
|
|
29
|
-
*
|
|
30
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
31
|
-
*
|
|
32
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
33
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
34
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
35
|
-
* See the License for the specific language governing permissions and
|
|
36
|
-
* limitations under the License.
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
class Request extends _channelOwner.ChannelOwner {
|
|
40
|
-
static from(request) {
|
|
41
|
-
return request._object;
|
|
42
|
-
}
|
|
43
|
-
static fromNullable(request) {
|
|
44
|
-
return request ? Request.from(request) : null;
|
|
45
|
-
}
|
|
31
|
+
module.exports = __toCommonJS(network_exports);
|
|
32
|
+
var import_channelOwner = require("./channelOwner");
|
|
33
|
+
var import_errors = require("./errors");
|
|
34
|
+
var import_events = require("./events");
|
|
35
|
+
var import_fetch = require("./fetch");
|
|
36
|
+
var import_frame = require("./frame");
|
|
37
|
+
var import_waiter = require("./waiter");
|
|
38
|
+
var import_worker = require("./worker");
|
|
39
|
+
var import_assert = require("../utils/isomorphic/assert");
|
|
40
|
+
var import_headers = require("../utils/isomorphic/headers");
|
|
41
|
+
var import_urlMatch = require("../utils/isomorphic/urlMatch");
|
|
42
|
+
var import_manualPromise = require("../utils/isomorphic/manualPromise");
|
|
43
|
+
var import_multimap = require("../utils/isomorphic/multimap");
|
|
44
|
+
var import_rtti = require("../utils/isomorphic/rtti");
|
|
45
|
+
var import_stackTrace = require("../utils/isomorphic/stackTrace");
|
|
46
|
+
var import_mimeType = require("../utils/isomorphic/mimeType");
|
|
47
|
+
class Request extends import_channelOwner.ChannelOwner {
|
|
46
48
|
constructor(parent, type, guid, initializer) {
|
|
47
49
|
super(parent, type, guid, initializer);
|
|
48
50
|
this._redirectedFrom = null;
|
|
49
51
|
this._redirectedTo = null;
|
|
50
52
|
this._failureText = null;
|
|
51
|
-
this._provisionalHeaders = void 0;
|
|
52
|
-
this._actualHeadersPromise = void 0;
|
|
53
|
-
this._timing = void 0;
|
|
54
53
|
this._fallbackOverrides = {};
|
|
55
54
|
this.markAsInternalType();
|
|
56
55
|
this._redirectedFrom = Request.fromNullable(initializer.redirectedFrom);
|
|
57
|
-
if (this._redirectedFrom)
|
|
56
|
+
if (this._redirectedFrom)
|
|
57
|
+
this._redirectedFrom._redirectedTo = this;
|
|
58
58
|
this._provisionalHeaders = new RawHeaders(initializer.headers);
|
|
59
59
|
this._timing = {
|
|
60
60
|
startTime: 0,
|
|
@@ -68,6 +68,12 @@ class Request extends _channelOwner.ChannelOwner {
|
|
|
68
68
|
responseEnd: -1
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
+
static from(request) {
|
|
72
|
+
return request._object;
|
|
73
|
+
}
|
|
74
|
+
static fromNullable(request) {
|
|
75
|
+
return request ? Request.from(request) : null;
|
|
76
|
+
}
|
|
71
77
|
url() {
|
|
72
78
|
return this._fallbackOverrides.url || this._initializer.url;
|
|
73
79
|
}
|
|
@@ -78,38 +84,40 @@ class Request extends _channelOwner.ChannelOwner {
|
|
|
78
84
|
return this._fallbackOverrides.method || this._initializer.method;
|
|
79
85
|
}
|
|
80
86
|
postData() {
|
|
81
|
-
|
|
82
|
-
return ((_ref = this._fallbackOverrides.postDataBuffer || this._initializer.postData) === null || _ref === void 0 ? void 0 : _ref.toString('utf-8')) || null;
|
|
87
|
+
return (this._fallbackOverrides.postDataBuffer || this._initializer.postData)?.toString("utf-8") || null;
|
|
83
88
|
}
|
|
84
89
|
postDataBuffer() {
|
|
85
90
|
return this._fallbackOverrides.postDataBuffer || this._initializer.postData || null;
|
|
86
91
|
}
|
|
87
92
|
postDataJSON() {
|
|
88
93
|
const postData = this.postData();
|
|
89
|
-
if (!postData)
|
|
90
|
-
|
|
91
|
-
|
|
94
|
+
if (!postData)
|
|
95
|
+
return null;
|
|
96
|
+
const contentType = this.headers()["content-type"];
|
|
97
|
+
if (contentType?.includes("application/x-www-form-urlencoded")) {
|
|
92
98
|
const entries = {};
|
|
93
99
|
const parsed = new URLSearchParams(postData);
|
|
94
|
-
for (const [k, v] of parsed.entries())
|
|
100
|
+
for (const [k, v] of parsed.entries())
|
|
101
|
+
entries[k] = v;
|
|
95
102
|
return entries;
|
|
96
103
|
}
|
|
97
104
|
try {
|
|
98
105
|
return JSON.parse(postData);
|
|
99
106
|
} catch (e) {
|
|
100
|
-
throw new Error(
|
|
107
|
+
throw new Error("POST data is not a valid JSON object: " + postData);
|
|
101
108
|
}
|
|
102
109
|
}
|
|
103
|
-
|
|
104
110
|
/**
|
|
105
111
|
* @deprecated
|
|
106
112
|
*/
|
|
107
113
|
headers() {
|
|
108
|
-
if (this._fallbackOverrides.headers)
|
|
114
|
+
if (this._fallbackOverrides.headers)
|
|
115
|
+
return RawHeaders._fromHeadersObjectLossy(this._fallbackOverrides.headers).headers();
|
|
109
116
|
return this._provisionalHeaders.headers();
|
|
110
117
|
}
|
|
111
118
|
async _actualHeaders() {
|
|
112
|
-
if (this._fallbackOverrides.headers)
|
|
119
|
+
if (this._fallbackOverrides.headers)
|
|
120
|
+
return RawHeaders._fromHeadersObjectLossy(this._fallbackOverrides.headers);
|
|
113
121
|
if (!this._actualHeadersPromise) {
|
|
114
122
|
this._actualHeadersPromise = this._wrapApiCall(async () => {
|
|
115
123
|
return new RawHeaders((await this._channel.rawRequestHeaders()).headers);
|
|
@@ -136,21 +144,24 @@ class Request extends _channelOwner.ChannelOwner {
|
|
|
136
144
|
}
|
|
137
145
|
frame() {
|
|
138
146
|
if (!this._initializer.frame) {
|
|
139
|
-
(0,
|
|
140
|
-
throw new Error(
|
|
147
|
+
(0, import_assert.assert)(this.serviceWorker());
|
|
148
|
+
throw new Error("Service Worker requests do not have an associated frame.");
|
|
141
149
|
}
|
|
142
|
-
const frame =
|
|
150
|
+
const frame = import_frame.Frame.from(this._initializer.frame);
|
|
143
151
|
if (!frame._page) {
|
|
144
|
-
throw new Error([
|
|
152
|
+
throw new Error([
|
|
153
|
+
"Frame for this navigation request is not available, because the request",
|
|
154
|
+
"was issued before the frame is created. You can check whether the request",
|
|
155
|
+
"is a navigation request by calling isNavigationRequest() method."
|
|
156
|
+
].join("\n"));
|
|
145
157
|
}
|
|
146
158
|
return frame;
|
|
147
159
|
}
|
|
148
160
|
_safePage() {
|
|
149
|
-
|
|
150
|
-
return ((_Frame$fromNullable = _frame.Frame.fromNullable(this._initializer.frame)) === null || _Frame$fromNullable === void 0 ? void 0 : _Frame$fromNullable._page) || null;
|
|
161
|
+
return import_frame.Frame.fromNullable(this._initializer.frame)?._page || null;
|
|
151
162
|
}
|
|
152
163
|
serviceWorker() {
|
|
153
|
-
return this._initializer.serviceWorker ?
|
|
164
|
+
return this._initializer.serviceWorker ? import_worker.Worker.from(this._initializer.serviceWorker) : null;
|
|
154
165
|
}
|
|
155
166
|
isNavigationRequest() {
|
|
156
167
|
return this._initializer.isNavigationRequest;
|
|
@@ -162,7 +173,8 @@ class Request extends _channelOwner.ChannelOwner {
|
|
|
162
173
|
return this._redirectedTo;
|
|
163
174
|
}
|
|
164
175
|
failure() {
|
|
165
|
-
if (this._failureText === null)
|
|
176
|
+
if (this._failureText === null)
|
|
177
|
+
return null;
|
|
166
178
|
return {
|
|
167
179
|
errorText: this._failureText
|
|
168
180
|
};
|
|
@@ -172,53 +184,57 @@ class Request extends _channelOwner.ChannelOwner {
|
|
|
172
184
|
}
|
|
173
185
|
async sizes() {
|
|
174
186
|
const response = await this.response();
|
|
175
|
-
if (!response)
|
|
187
|
+
if (!response)
|
|
188
|
+
throw new Error("Unable to fetch sizes for failed request");
|
|
176
189
|
return (await response._channel.sizes()).sizes;
|
|
177
190
|
}
|
|
178
191
|
_setResponseEndTiming(responseEndTiming) {
|
|
179
192
|
this._timing.responseEnd = responseEndTiming;
|
|
180
|
-
if (this._timing.responseStart === -1)
|
|
193
|
+
if (this._timing.responseStart === -1)
|
|
194
|
+
this._timing.responseStart = responseEndTiming;
|
|
181
195
|
}
|
|
182
196
|
_finalRequest() {
|
|
183
197
|
return this._redirectedTo ? this._redirectedTo._finalRequest() : this;
|
|
184
198
|
}
|
|
185
199
|
_applyFallbackOverrides(overrides) {
|
|
186
|
-
if (overrides.url)
|
|
187
|
-
|
|
188
|
-
if (overrides.
|
|
189
|
-
|
|
200
|
+
if (overrides.url)
|
|
201
|
+
this._fallbackOverrides.url = overrides.url;
|
|
202
|
+
if (overrides.method)
|
|
203
|
+
this._fallbackOverrides.method = overrides.method;
|
|
204
|
+
if (overrides.headers)
|
|
205
|
+
this._fallbackOverrides.headers = overrides.headers;
|
|
206
|
+
if ((0, import_rtti.isString)(overrides.postData))
|
|
207
|
+
this._fallbackOverrides.postDataBuffer = Buffer.from(overrides.postData, "utf-8");
|
|
208
|
+
else if (overrides.postData instanceof Buffer)
|
|
209
|
+
this._fallbackOverrides.postDataBuffer = overrides.postData;
|
|
210
|
+
else if (overrides.postData)
|
|
211
|
+
this._fallbackOverrides.postDataBuffer = Buffer.from(JSON.stringify(overrides.postData), "utf-8");
|
|
190
212
|
}
|
|
191
213
|
_fallbackOverridesForContinue() {
|
|
192
214
|
return this._fallbackOverrides;
|
|
193
215
|
}
|
|
194
216
|
_targetClosedScope() {
|
|
195
|
-
|
|
196
|
-
return ((_this$serviceWorker = this.serviceWorker()) === null || _this$serviceWorker === void 0 ? void 0 : _this$serviceWorker._closedScope) || ((_this$_safePage = this._safePage()) === null || _this$_safePage === void 0 ? void 0 : _this$_safePage._closedOrCrashedScope) || new _manualPromise.LongStandingScope();
|
|
217
|
+
return this.serviceWorker()?._closedScope || this._safePage()?._closedOrCrashedScope || new import_manualPromise.LongStandingScope();
|
|
197
218
|
}
|
|
198
219
|
}
|
|
199
|
-
|
|
200
|
-
class Route extends _channelOwner.ChannelOwner {
|
|
201
|
-
static from(route) {
|
|
202
|
-
return route._object;
|
|
203
|
-
}
|
|
220
|
+
class Route extends import_channelOwner.ChannelOwner {
|
|
204
221
|
constructor(parent, type, guid, initializer) {
|
|
205
222
|
super(parent, type, guid, initializer);
|
|
206
223
|
this._handlingPromise = null;
|
|
207
|
-
this._context = void 0;
|
|
208
224
|
this._didThrow = false;
|
|
209
225
|
this.markAsInternalType();
|
|
210
226
|
}
|
|
227
|
+
static from(route) {
|
|
228
|
+
return route._object;
|
|
229
|
+
}
|
|
211
230
|
request() {
|
|
212
231
|
return Request.from(this._initializer.request);
|
|
213
232
|
}
|
|
214
233
|
async _raceWithTargetClose(promise) {
|
|
215
|
-
// When page closes or crashes, we catch any potential rejects from this Route.
|
|
216
|
-
// Note that page could be missing when routing popup's initial request that
|
|
217
|
-
// does not have a Page initialized just yet.
|
|
218
234
|
return await this.request()._targetClosedScope().safeRace(promise);
|
|
219
235
|
}
|
|
220
236
|
async _startHandling() {
|
|
221
|
-
this._handlingPromise = new
|
|
237
|
+
this._handlingPromise = new import_manualPromise.ManualPromise();
|
|
222
238
|
return await this._handlingPromise;
|
|
223
239
|
}
|
|
224
240
|
async fallback(options = {}) {
|
|
@@ -228,25 +244,17 @@ class Route extends _channelOwner.ChannelOwner {
|
|
|
228
244
|
}
|
|
229
245
|
async abort(errorCode) {
|
|
230
246
|
await this._handleRoute(async () => {
|
|
231
|
-
await this._raceWithTargetClose(this._channel.abort({
|
|
232
|
-
errorCode
|
|
233
|
-
}));
|
|
247
|
+
await this._raceWithTargetClose(this._channel.abort({ errorCode }));
|
|
234
248
|
});
|
|
235
249
|
}
|
|
236
250
|
async _redirectNavigationRequest(url) {
|
|
237
251
|
await this._handleRoute(async () => {
|
|
238
|
-
await this._raceWithTargetClose(this._channel.redirectNavigationRequest({
|
|
239
|
-
url
|
|
240
|
-
}));
|
|
252
|
+
await this._raceWithTargetClose(this._channel.redirectNavigationRequest({ url }));
|
|
241
253
|
});
|
|
242
254
|
}
|
|
243
255
|
async fetch(options = {}) {
|
|
244
256
|
return await this._wrapApiCall(async () => {
|
|
245
|
-
return await this._context.request._innerFetch({
|
|
246
|
-
request: this.request(),
|
|
247
|
-
data: options.postData,
|
|
248
|
-
...options
|
|
249
|
-
});
|
|
257
|
+
return await this._context.request._innerFetch({ request: this.request(), data: options.postData, ...options });
|
|
250
258
|
});
|
|
251
259
|
}
|
|
252
260
|
async fulfill(options = {}) {
|
|
@@ -268,44 +276,50 @@ class Route extends _channelOwner.ChannelOwner {
|
|
|
268
276
|
}
|
|
269
277
|
async _innerFulfill(options = {}) {
|
|
270
278
|
let fetchResponseUid;
|
|
271
|
-
let {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
body
|
|
275
|
-
} = options;
|
|
276
|
-
if (options.json !== undefined) {
|
|
277
|
-
(0, _assert.assert)(options.body === undefined, 'Can specify either body or json parameters');
|
|
279
|
+
let { status: statusOption, headers: headersOption, body } = options;
|
|
280
|
+
if (options.json !== void 0) {
|
|
281
|
+
(0, import_assert.assert)(options.body === void 0, "Can specify either body or json parameters");
|
|
278
282
|
body = JSON.stringify(options.json);
|
|
279
283
|
}
|
|
280
|
-
if (options.response instanceof
|
|
281
|
-
statusOption
|
|
282
|
-
headersOption
|
|
283
|
-
if (body ===
|
|
284
|
-
if (options.response._request._connection === this._connection)
|
|
284
|
+
if (options.response instanceof import_fetch.APIResponse) {
|
|
285
|
+
statusOption ??= options.response.status();
|
|
286
|
+
headersOption ??= options.response.headers();
|
|
287
|
+
if (body === void 0 && options.path === void 0) {
|
|
288
|
+
if (options.response._request._connection === this._connection)
|
|
289
|
+
fetchResponseUid = options.response._fetchUid();
|
|
290
|
+
else
|
|
291
|
+
body = await options.response.body();
|
|
285
292
|
}
|
|
286
293
|
}
|
|
287
294
|
let isBase64 = false;
|
|
288
295
|
let length = 0;
|
|
289
296
|
if (options.path) {
|
|
290
297
|
const buffer = await this._platform.fs().promises.readFile(options.path);
|
|
291
|
-
body = buffer.toString(
|
|
298
|
+
body = buffer.toString("base64");
|
|
292
299
|
isBase64 = true;
|
|
293
300
|
length = buffer.length;
|
|
294
|
-
} else if ((0,
|
|
301
|
+
} else if ((0, import_rtti.isString)(body)) {
|
|
295
302
|
isBase64 = false;
|
|
296
303
|
length = Buffer.byteLength(body);
|
|
297
304
|
} else if (body) {
|
|
298
305
|
length = body.length;
|
|
299
|
-
body = body.toString(
|
|
306
|
+
body = body.toString("base64");
|
|
300
307
|
isBase64 = true;
|
|
301
308
|
}
|
|
302
309
|
const headers = {};
|
|
303
|
-
for (const header of Object.keys(headersOption || {}))
|
|
304
|
-
|
|
305
|
-
if (
|
|
310
|
+
for (const header of Object.keys(headersOption || {}))
|
|
311
|
+
headers[header.toLowerCase()] = String(headersOption[header]);
|
|
312
|
+
if (options.contentType)
|
|
313
|
+
headers["content-type"] = String(options.contentType);
|
|
314
|
+
else if (options.json)
|
|
315
|
+
headers["content-type"] = "application/json";
|
|
316
|
+
else if (options.path)
|
|
317
|
+
headers["content-type"] = (0, import_mimeType.getMimeTypeForPath)(options.path) || "application/octet-stream";
|
|
318
|
+
if (length && !("content-length" in headers))
|
|
319
|
+
headers["content-length"] = String(length);
|
|
306
320
|
await this._raceWithTargetClose(this._channel.fulfill({
|
|
307
321
|
status: statusOption || 200,
|
|
308
|
-
headers: (0,
|
|
322
|
+
headers: (0, import_headers.headersObjectToArray)(headers),
|
|
309
323
|
body,
|
|
310
324
|
isBase64,
|
|
311
325
|
fetchResponseUid
|
|
@@ -314,11 +328,15 @@ class Route extends _channelOwner.ChannelOwner {
|
|
|
314
328
|
async continue(options = {}) {
|
|
315
329
|
await this._handleRoute(async () => {
|
|
316
330
|
this.request()._applyFallbackOverrides(options);
|
|
317
|
-
await this._innerContinue(
|
|
331
|
+
await this._innerContinue(
|
|
332
|
+
false
|
|
333
|
+
/* isFallback */
|
|
334
|
+
);
|
|
318
335
|
});
|
|
319
336
|
}
|
|
320
337
|
_checkNotHandled() {
|
|
321
|
-
if (!this._handlingPromise)
|
|
338
|
+
if (!this._handlingPromise)
|
|
339
|
+
throw new Error("Route is already handled!");
|
|
322
340
|
}
|
|
323
341
|
_reportHandled(done) {
|
|
324
342
|
const chain = this._handlingPromise;
|
|
@@ -330,31 +348,22 @@ class Route extends _channelOwner.ChannelOwner {
|
|
|
330
348
|
return await this._raceWithTargetClose(this._channel.continue({
|
|
331
349
|
url: options.url,
|
|
332
350
|
method: options.method,
|
|
333
|
-
headers: options.headers ? (0,
|
|
351
|
+
headers: options.headers ? (0, import_headers.headersObjectToArray)(options.headers) : void 0,
|
|
334
352
|
postData: options.postDataBuffer,
|
|
335
353
|
isFallback
|
|
336
354
|
}));
|
|
337
355
|
}
|
|
338
356
|
}
|
|
339
|
-
|
|
340
|
-
class WebSocketRoute extends _channelOwner.ChannelOwner {
|
|
341
|
-
static from(route) {
|
|
342
|
-
return route._object;
|
|
343
|
-
}
|
|
357
|
+
class WebSocketRoute extends import_channelOwner.ChannelOwner {
|
|
344
358
|
constructor(parent, type, guid, initializer) {
|
|
345
359
|
super(parent, type, guid, initializer);
|
|
346
|
-
this._onPageMessage = void 0;
|
|
347
|
-
this._onPageClose = void 0;
|
|
348
|
-
this._onServerMessage = void 0;
|
|
349
|
-
this._onServerClose = void 0;
|
|
350
|
-
this._server = void 0;
|
|
351
360
|
this._connected = false;
|
|
352
361
|
this.markAsInternalType();
|
|
353
362
|
this._server = {
|
|
354
|
-
onMessage: handler => {
|
|
363
|
+
onMessage: (handler) => {
|
|
355
364
|
this._onServerMessage = handler;
|
|
356
365
|
},
|
|
357
|
-
onClose: handler => {
|
|
366
|
+
onClose: (handler) => {
|
|
358
367
|
this._onServerClose = handler;
|
|
359
368
|
},
|
|
360
369
|
connectToServer: () => {
|
|
@@ -364,88 +373,75 @@ class WebSocketRoute extends _channelOwner.ChannelOwner {
|
|
|
364
373
|
return this._initializer.url;
|
|
365
374
|
},
|
|
366
375
|
close: async (options = {}) => {
|
|
367
|
-
await this._channel.closeServer({
|
|
368
|
-
|
|
369
|
-
wasClean: true
|
|
370
|
-
}).catch(() => {});
|
|
376
|
+
await this._channel.closeServer({ ...options, wasClean: true }).catch(() => {
|
|
377
|
+
});
|
|
371
378
|
},
|
|
372
|
-
send: message => {
|
|
373
|
-
if ((0,
|
|
374
|
-
message,
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
message: message.toString(
|
|
378
|
-
|
|
379
|
-
}).catch(() => {});
|
|
379
|
+
send: (message) => {
|
|
380
|
+
if ((0, import_rtti.isString)(message))
|
|
381
|
+
this._channel.sendToServer({ message, isBase64: false }).catch(() => {
|
|
382
|
+
});
|
|
383
|
+
else
|
|
384
|
+
this._channel.sendToServer({ message: message.toString("base64"), isBase64: true }).catch(() => {
|
|
385
|
+
});
|
|
380
386
|
},
|
|
381
387
|
async [Symbol.asyncDispose]() {
|
|
382
388
|
await this.close();
|
|
383
389
|
}
|
|
384
390
|
};
|
|
385
|
-
this._channel.on(
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
isBase64
|
|
392
|
-
}).catch(() => {});
|
|
391
|
+
this._channel.on("messageFromPage", ({ message, isBase64 }) => {
|
|
392
|
+
if (this._onPageMessage)
|
|
393
|
+
this._onPageMessage(isBase64 ? Buffer.from(message, "base64") : message);
|
|
394
|
+
else if (this._connected)
|
|
395
|
+
this._channel.sendToServer({ message, isBase64 }).catch(() => {
|
|
396
|
+
});
|
|
393
397
|
});
|
|
394
|
-
this._channel.on(
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
isBase64
|
|
401
|
-
}).catch(() => {});
|
|
398
|
+
this._channel.on("messageFromServer", ({ message, isBase64 }) => {
|
|
399
|
+
if (this._onServerMessage)
|
|
400
|
+
this._onServerMessage(isBase64 ? Buffer.from(message, "base64") : message);
|
|
401
|
+
else
|
|
402
|
+
this._channel.sendToPage({ message, isBase64 }).catch(() => {
|
|
403
|
+
});
|
|
402
404
|
});
|
|
403
|
-
this._channel.on(
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
code,
|
|
410
|
-
reason,
|
|
411
|
-
wasClean
|
|
412
|
-
}).catch(() => {});
|
|
405
|
+
this._channel.on("closePage", ({ code, reason, wasClean }) => {
|
|
406
|
+
if (this._onPageClose)
|
|
407
|
+
this._onPageClose(code, reason);
|
|
408
|
+
else
|
|
409
|
+
this._channel.closeServer({ code, reason, wasClean }).catch(() => {
|
|
410
|
+
});
|
|
413
411
|
});
|
|
414
|
-
this._channel.on(
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
code,
|
|
421
|
-
reason,
|
|
422
|
-
wasClean
|
|
423
|
-
}).catch(() => {});
|
|
412
|
+
this._channel.on("closeServer", ({ code, reason, wasClean }) => {
|
|
413
|
+
if (this._onServerClose)
|
|
414
|
+
this._onServerClose(code, reason);
|
|
415
|
+
else
|
|
416
|
+
this._channel.closePage({ code, reason, wasClean }).catch(() => {
|
|
417
|
+
});
|
|
424
418
|
});
|
|
425
419
|
}
|
|
420
|
+
static from(route) {
|
|
421
|
+
return route._object;
|
|
422
|
+
}
|
|
426
423
|
url() {
|
|
427
424
|
return this._initializer.url;
|
|
428
425
|
}
|
|
429
426
|
async close(options = {}) {
|
|
430
|
-
await this._channel.closePage({
|
|
431
|
-
|
|
432
|
-
wasClean: true
|
|
433
|
-
}).catch(() => {});
|
|
427
|
+
await this._channel.closePage({ ...options, wasClean: true }).catch(() => {
|
|
428
|
+
});
|
|
434
429
|
}
|
|
435
430
|
connectToServer() {
|
|
436
|
-
if (this._connected)
|
|
431
|
+
if (this._connected)
|
|
432
|
+
throw new Error("Already connected to the server");
|
|
437
433
|
this._connected = true;
|
|
438
|
-
this._channel.connect().catch(() => {
|
|
434
|
+
this._channel.connect().catch(() => {
|
|
435
|
+
});
|
|
439
436
|
return this._server;
|
|
440
437
|
}
|
|
441
438
|
send(message) {
|
|
442
|
-
if ((0,
|
|
443
|
-
message,
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
message: message.toString(
|
|
447
|
-
|
|
448
|
-
}).catch(() => {});
|
|
439
|
+
if ((0, import_rtti.isString)(message))
|
|
440
|
+
this._channel.sendToPage({ message, isBase64: false }).catch(() => {
|
|
441
|
+
});
|
|
442
|
+
else
|
|
443
|
+
this._channel.sendToPage({ message: message.toString("base64"), isBase64: true }).catch(() => {
|
|
444
|
+
});
|
|
449
445
|
}
|
|
450
446
|
onMessage(handler) {
|
|
451
447
|
this._onPageMessage = handler;
|
|
@@ -457,17 +453,13 @@ class WebSocketRoute extends _channelOwner.ChannelOwner {
|
|
|
457
453
|
await this.close();
|
|
458
454
|
}
|
|
459
455
|
async _afterHandle() {
|
|
460
|
-
if (this._connected)
|
|
461
|
-
|
|
456
|
+
if (this._connected)
|
|
457
|
+
return;
|
|
462
458
|
await this._channel.ensureOpened();
|
|
463
459
|
}
|
|
464
460
|
}
|
|
465
|
-
exports.WebSocketRoute = WebSocketRoute;
|
|
466
461
|
class WebSocketRouteHandler {
|
|
467
462
|
constructor(baseURL, url, handler) {
|
|
468
|
-
this._baseURL = void 0;
|
|
469
|
-
this.url = void 0;
|
|
470
|
-
this.handler = void 0;
|
|
471
463
|
this._baseURL = baseURL;
|
|
472
464
|
this.url = url;
|
|
473
465
|
this.handler = handler;
|
|
@@ -476,20 +468,19 @@ class WebSocketRouteHandler {
|
|
|
476
468
|
const patterns = [];
|
|
477
469
|
let all = false;
|
|
478
470
|
for (const handler of handlers) {
|
|
479
|
-
if ((0,
|
|
480
|
-
glob: handler.url
|
|
481
|
-
|
|
482
|
-
regexSource: handler.url.source,
|
|
483
|
-
|
|
484
|
-
|
|
471
|
+
if ((0, import_rtti.isString)(handler.url))
|
|
472
|
+
patterns.push({ glob: handler.url });
|
|
473
|
+
else if ((0, import_rtti.isRegExp)(handler.url))
|
|
474
|
+
patterns.push({ regexSource: handler.url.source, regexFlags: handler.url.flags });
|
|
475
|
+
else
|
|
476
|
+
all = true;
|
|
485
477
|
}
|
|
486
|
-
if (all)
|
|
487
|
-
glob:
|
|
488
|
-
}];
|
|
478
|
+
if (all)
|
|
479
|
+
return [{ glob: "**/*" }];
|
|
489
480
|
return patterns;
|
|
490
481
|
}
|
|
491
482
|
matches(wsURL) {
|
|
492
|
-
return (0,
|
|
483
|
+
return (0, import_urlMatch.urlMatches)(this._baseURL, wsURL, this.url, true);
|
|
493
484
|
}
|
|
494
485
|
async handle(webSocketRoute) {
|
|
495
486
|
const handler = this.handler;
|
|
@@ -497,30 +488,25 @@ class WebSocketRouteHandler {
|
|
|
497
488
|
await webSocketRoute._afterHandle();
|
|
498
489
|
}
|
|
499
490
|
}
|
|
500
|
-
|
|
501
|
-
class Response extends _channelOwner.ChannelOwner {
|
|
502
|
-
static from(response) {
|
|
503
|
-
return response._object;
|
|
504
|
-
}
|
|
505
|
-
static fromNullable(response) {
|
|
506
|
-
return response ? Response.from(response) : null;
|
|
507
|
-
}
|
|
491
|
+
class Response extends import_channelOwner.ChannelOwner {
|
|
508
492
|
constructor(parent, type, guid, initializer) {
|
|
509
493
|
super(parent, type, guid, initializer);
|
|
510
|
-
this.
|
|
511
|
-
this._actualHeadersPromise = void 0;
|
|
512
|
-
this._request = void 0;
|
|
513
|
-
this._finishedPromise = new _manualPromise.ManualPromise();
|
|
494
|
+
this._finishedPromise = new import_manualPromise.ManualPromise();
|
|
514
495
|
this.markAsInternalType();
|
|
515
496
|
this._provisionalHeaders = new RawHeaders(initializer.headers);
|
|
516
497
|
this._request = Request.from(this._initializer.request);
|
|
517
498
|
Object.assign(this._request._timing, this._initializer.timing);
|
|
518
499
|
}
|
|
500
|
+
static from(response) {
|
|
501
|
+
return response._object;
|
|
502
|
+
}
|
|
503
|
+
static fromNullable(response) {
|
|
504
|
+
return response ? Response.from(response) : null;
|
|
505
|
+
}
|
|
519
506
|
url() {
|
|
520
507
|
return this._initializer.url;
|
|
521
508
|
}
|
|
522
509
|
ok() {
|
|
523
|
-
// Status 0 is for file:// URLs
|
|
524
510
|
return this._initializer.status === 0 || this._initializer.status >= 200 && this._initializer.status <= 299;
|
|
525
511
|
}
|
|
526
512
|
status() {
|
|
@@ -532,7 +518,6 @@ class Response extends _channelOwner.ChannelOwner {
|
|
|
532
518
|
fromServiceWorker() {
|
|
533
519
|
return this._initializer.fromServiceWorker;
|
|
534
520
|
}
|
|
535
|
-
|
|
536
521
|
/**
|
|
537
522
|
* @deprecated
|
|
538
523
|
*/
|
|
@@ -567,7 +552,7 @@ class Response extends _channelOwner.ChannelOwner {
|
|
|
567
552
|
}
|
|
568
553
|
async text() {
|
|
569
554
|
const content = await this.body();
|
|
570
|
-
return content.toString(
|
|
555
|
+
return content.toString("utf8");
|
|
571
556
|
}
|
|
572
557
|
async json() {
|
|
573
558
|
const content = await this.text();
|
|
@@ -586,37 +571,30 @@ class Response extends _channelOwner.ChannelOwner {
|
|
|
586
571
|
return (await this._channel.securityDetails()).value || null;
|
|
587
572
|
}
|
|
588
573
|
}
|
|
589
|
-
|
|
590
|
-
class WebSocket extends _channelOwner.ChannelOwner {
|
|
574
|
+
class WebSocket extends import_channelOwner.ChannelOwner {
|
|
591
575
|
static from(webSocket) {
|
|
592
576
|
return webSocket._object;
|
|
593
577
|
}
|
|
594
578
|
constructor(parent, type, guid, initializer) {
|
|
595
579
|
super(parent, type, guid, initializer);
|
|
596
|
-
this._page = void 0;
|
|
597
|
-
this._isClosed = void 0;
|
|
598
580
|
this._isClosed = false;
|
|
599
581
|
this._page = parent;
|
|
600
|
-
this._channel.on(
|
|
601
|
-
if (event.opcode === 1)
|
|
602
|
-
payload: event.data
|
|
603
|
-
|
|
604
|
-
payload: Buffer.from(event.data,
|
|
605
|
-
});
|
|
582
|
+
this._channel.on("frameSent", (event) => {
|
|
583
|
+
if (event.opcode === 1)
|
|
584
|
+
this.emit(import_events.Events.WebSocket.FrameSent, { payload: event.data });
|
|
585
|
+
else if (event.opcode === 2)
|
|
586
|
+
this.emit(import_events.Events.WebSocket.FrameSent, { payload: Buffer.from(event.data, "base64") });
|
|
606
587
|
});
|
|
607
|
-
this._channel.on(
|
|
608
|
-
if (event.opcode === 1)
|
|
609
|
-
payload: event.data
|
|
610
|
-
|
|
611
|
-
payload: Buffer.from(event.data,
|
|
612
|
-
});
|
|
588
|
+
this._channel.on("frameReceived", (event) => {
|
|
589
|
+
if (event.opcode === 1)
|
|
590
|
+
this.emit(import_events.Events.WebSocket.FrameReceived, { payload: event.data });
|
|
591
|
+
else if (event.opcode === 2)
|
|
592
|
+
this.emit(import_events.Events.WebSocket.FrameReceived, { payload: Buffer.from(event.data, "base64") });
|
|
613
593
|
});
|
|
614
|
-
this._channel.on(
|
|
615
|
-
|
|
616
|
-
}) => this.emit(_events.Events.WebSocket.Error, error));
|
|
617
|
-
this._channel.on('close', () => {
|
|
594
|
+
this._channel.on("socketError", ({ error }) => this.emit(import_events.Events.WebSocket.Error, error));
|
|
595
|
+
this._channel.on("close", () => {
|
|
618
596
|
this._isClosed = true;
|
|
619
|
-
this.emit(
|
|
597
|
+
this.emit(import_events.Events.WebSocket.Close, this);
|
|
620
598
|
});
|
|
621
599
|
}
|
|
622
600
|
url() {
|
|
@@ -627,36 +605,33 @@ class WebSocket extends _channelOwner.ChannelOwner {
|
|
|
627
605
|
}
|
|
628
606
|
async waitForEvent(event, optionsOrPredicate = {}) {
|
|
629
607
|
return await this._wrapApiCall(async () => {
|
|
630
|
-
const timeout = this._page._timeoutSettings.timeout(typeof optionsOrPredicate ===
|
|
631
|
-
const predicate = typeof optionsOrPredicate ===
|
|
632
|
-
const waiter =
|
|
608
|
+
const timeout = this._page._timeoutSettings.timeout(typeof optionsOrPredicate === "function" ? {} : optionsOrPredicate);
|
|
609
|
+
const predicate = typeof optionsOrPredicate === "function" ? optionsOrPredicate : optionsOrPredicate.predicate;
|
|
610
|
+
const waiter = import_waiter.Waiter.createForEvent(this, event);
|
|
633
611
|
waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded while waiting for event "${event}"`);
|
|
634
|
-
if (event !==
|
|
635
|
-
|
|
636
|
-
|
|
612
|
+
if (event !== import_events.Events.WebSocket.Error)
|
|
613
|
+
waiter.rejectOnEvent(this, import_events.Events.WebSocket.Error, new Error("Socket error"));
|
|
614
|
+
if (event !== import_events.Events.WebSocket.Close)
|
|
615
|
+
waiter.rejectOnEvent(this, import_events.Events.WebSocket.Close, new Error("Socket closed"));
|
|
616
|
+
waiter.rejectOnEvent(this._page, import_events.Events.Page.Close, () => this._page._closeErrorWithReason());
|
|
637
617
|
const result = await waiter.waitForEvent(this, event, predicate);
|
|
638
618
|
waiter.dispose();
|
|
639
619
|
return result;
|
|
640
620
|
});
|
|
641
621
|
}
|
|
642
622
|
}
|
|
643
|
-
exports.WebSocket = WebSocket;
|
|
644
623
|
function validateHeaders(headers) {
|
|
645
624
|
for (const key of Object.keys(headers)) {
|
|
646
625
|
const value = headers[key];
|
|
647
|
-
if (!Object.is(value,
|
|
626
|
+
if (!Object.is(value, void 0) && !(0, import_rtti.isString)(value))
|
|
627
|
+
throw new Error(`Expected value of header "${key}" to be String, but "${typeof value}" is found.`);
|
|
648
628
|
}
|
|
649
629
|
}
|
|
650
630
|
class RouteHandler {
|
|
651
631
|
constructor(platform, baseURL, url, handler, times = Number.MAX_SAFE_INTEGER) {
|
|
652
632
|
this.handledCount = 0;
|
|
653
|
-
this._baseURL = void 0;
|
|
654
|
-
this._times = void 0;
|
|
655
|
-
this.url = void 0;
|
|
656
|
-
this.handler = void 0;
|
|
657
633
|
this._ignoreException = false;
|
|
658
|
-
this._activeInvocations = new Set();
|
|
659
|
-
this._savedZone = void 0;
|
|
634
|
+
this._activeInvocations = /* @__PURE__ */ new Set();
|
|
660
635
|
this._baseURL = baseURL;
|
|
661
636
|
this._times = times;
|
|
662
637
|
this.url = url;
|
|
@@ -667,39 +642,35 @@ class RouteHandler {
|
|
|
667
642
|
const patterns = [];
|
|
668
643
|
let all = false;
|
|
669
644
|
for (const handler of handlers) {
|
|
670
|
-
if ((0,
|
|
671
|
-
glob: handler.url
|
|
672
|
-
|
|
673
|
-
regexSource: handler.url.source,
|
|
674
|
-
|
|
675
|
-
|
|
645
|
+
if ((0, import_rtti.isString)(handler.url))
|
|
646
|
+
patterns.push({ glob: handler.url });
|
|
647
|
+
else if ((0, import_rtti.isRegExp)(handler.url))
|
|
648
|
+
patterns.push({ regexSource: handler.url.source, regexFlags: handler.url.flags });
|
|
649
|
+
else
|
|
650
|
+
all = true;
|
|
676
651
|
}
|
|
677
|
-
if (all)
|
|
678
|
-
glob:
|
|
679
|
-
}];
|
|
652
|
+
if (all)
|
|
653
|
+
return [{ glob: "**/*" }];
|
|
680
654
|
return patterns;
|
|
681
655
|
}
|
|
682
656
|
matches(requestURL) {
|
|
683
|
-
return (0,
|
|
657
|
+
return (0, import_urlMatch.urlMatches)(this._baseURL, requestURL, this.url);
|
|
684
658
|
}
|
|
685
659
|
async handle(route) {
|
|
686
660
|
return await this._savedZone.run(async () => this._handleImpl(route));
|
|
687
661
|
}
|
|
688
662
|
async _handleImpl(route) {
|
|
689
|
-
const handlerInvocation = {
|
|
690
|
-
complete: new _manualPromise.ManualPromise(),
|
|
691
|
-
route
|
|
692
|
-
};
|
|
663
|
+
const handlerInvocation = { complete: new import_manualPromise.ManualPromise(), route };
|
|
693
664
|
this._activeInvocations.add(handlerInvocation);
|
|
694
665
|
try {
|
|
695
666
|
return await this._handleInternal(route);
|
|
696
667
|
} catch (e) {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
if ((0,
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
668
|
+
if (this._ignoreException)
|
|
669
|
+
return false;
|
|
670
|
+
if ((0, import_errors.isTargetClosedError)(e)) {
|
|
671
|
+
(0, import_stackTrace.rewriteErrorMessage)(e, `"${e.message}" while running route callback.
|
|
672
|
+
Consider awaiting \`await page.unrouteAll({ behavior: 'ignoreErrors' })\`
|
|
673
|
+
before the end of the test to ignore remaining routes in flight.`);
|
|
703
674
|
}
|
|
704
675
|
throw e;
|
|
705
676
|
} finally {
|
|
@@ -708,16 +679,13 @@ class RouteHandler {
|
|
|
708
679
|
}
|
|
709
680
|
}
|
|
710
681
|
async stop(behavior) {
|
|
711
|
-
|
|
712
|
-
// - wait for the current handler invocations to finish
|
|
713
|
-
// - or do not wait, if the user opted out of it, but swallow all exceptions
|
|
714
|
-
// that happen after the unroute/close.
|
|
715
|
-
if (behavior === 'ignoreErrors') {
|
|
682
|
+
if (behavior === "ignoreErrors") {
|
|
716
683
|
this._ignoreException = true;
|
|
717
684
|
} else {
|
|
718
685
|
const promises = [];
|
|
719
686
|
for (const activation of this._activeInvocations) {
|
|
720
|
-
if (!activation.route._didThrow)
|
|
687
|
+
if (!activation.route._didThrow)
|
|
688
|
+
promises.push(activation.complete);
|
|
721
689
|
}
|
|
722
690
|
await Promise.all(promises);
|
|
723
691
|
}
|
|
@@ -725,45 +693,59 @@ class RouteHandler {
|
|
|
725
693
|
async _handleInternal(route) {
|
|
726
694
|
++this.handledCount;
|
|
727
695
|
const handledPromise = route._startHandling();
|
|
728
|
-
// Extract handler into a variable to avoid [RouteHandler.handler] in the stack.
|
|
729
696
|
const handler = this.handler;
|
|
730
|
-
const [handled] = await Promise.all([
|
|
697
|
+
const [handled] = await Promise.all([
|
|
698
|
+
handledPromise,
|
|
699
|
+
handler(route, route.request())
|
|
700
|
+
]);
|
|
731
701
|
return handled;
|
|
732
702
|
}
|
|
733
703
|
willExpire() {
|
|
734
704
|
return this.handledCount + 1 >= this._times;
|
|
735
705
|
}
|
|
736
706
|
}
|
|
737
|
-
exports.RouteHandler = RouteHandler;
|
|
738
707
|
class RawHeaders {
|
|
708
|
+
constructor(headers) {
|
|
709
|
+
this._headersMap = new import_multimap.MultiMap();
|
|
710
|
+
this._headersArray = headers;
|
|
711
|
+
for (const header of headers)
|
|
712
|
+
this._headersMap.set(header.name.toLowerCase(), header.value);
|
|
713
|
+
}
|
|
739
714
|
static _fromHeadersObjectLossy(headers) {
|
|
740
715
|
const headersArray = Object.entries(headers).map(([name, value]) => ({
|
|
741
716
|
name,
|
|
742
717
|
value
|
|
743
|
-
})).filter(header => header.value !==
|
|
718
|
+
})).filter((header) => header.value !== void 0);
|
|
744
719
|
return new RawHeaders(headersArray);
|
|
745
720
|
}
|
|
746
|
-
constructor(headers) {
|
|
747
|
-
this._headersArray = void 0;
|
|
748
|
-
this._headersMap = new _multimap.MultiMap();
|
|
749
|
-
this._headersArray = headers;
|
|
750
|
-
for (const header of headers) this._headersMap.set(header.name.toLowerCase(), header.value);
|
|
751
|
-
}
|
|
752
721
|
get(name) {
|
|
753
722
|
const values = this.getAll(name);
|
|
754
|
-
if (!values || !values.length)
|
|
755
|
-
|
|
723
|
+
if (!values || !values.length)
|
|
724
|
+
return null;
|
|
725
|
+
return values.join(name.toLowerCase() === "set-cookie" ? "\n" : ", ");
|
|
756
726
|
}
|
|
757
727
|
getAll(name) {
|
|
758
728
|
return [...this._headersMap.get(name.toLowerCase())];
|
|
759
729
|
}
|
|
760
730
|
headers() {
|
|
761
731
|
const result = {};
|
|
762
|
-
for (const name of this._headersMap.keys())
|
|
732
|
+
for (const name of this._headersMap.keys())
|
|
733
|
+
result[name] = this.get(name);
|
|
763
734
|
return result;
|
|
764
735
|
}
|
|
765
736
|
headersArray() {
|
|
766
737
|
return this._headersArray;
|
|
767
738
|
}
|
|
768
739
|
}
|
|
769
|
-
|
|
740
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
741
|
+
0 && (module.exports = {
|
|
742
|
+
RawHeaders,
|
|
743
|
+
Request,
|
|
744
|
+
Response,
|
|
745
|
+
Route,
|
|
746
|
+
RouteHandler,
|
|
747
|
+
WebSocket,
|
|
748
|
+
WebSocketRoute,
|
|
749
|
+
WebSocketRouteHandler,
|
|
750
|
+
validateHeaders
|
|
751
|
+
});
|