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/server/fetch.js
CHANGED
|
@@ -1,63 +1,80 @@
|
|
|
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 fetch_exports = {};
|
|
30
|
+
__export(fetch_exports, {
|
|
31
|
+
APIRequestContext: () => APIRequestContext,
|
|
32
|
+
BrowserContextAPIRequestContext: () => BrowserContextAPIRequestContext,
|
|
33
|
+
GlobalAPIRequestContext: () => GlobalAPIRequestContext
|
|
5
34
|
});
|
|
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
|
-
var
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* See the License for the specific language governing permissions and
|
|
43
|
-
* limitations under the License.
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
class APIRequestContext extends _instrumentation.SdkObject {
|
|
35
|
+
module.exports = __toCommonJS(fetch_exports);
|
|
36
|
+
var import_http = __toESM(require("http"));
|
|
37
|
+
var import_https = __toESM(require("https"));
|
|
38
|
+
var import_stream = require("stream");
|
|
39
|
+
var import_tls = require("tls");
|
|
40
|
+
var zlib = __toESM(require("zlib"));
|
|
41
|
+
var import_timeoutSettings = require("./timeoutSettings");
|
|
42
|
+
var import_utils = require("../utils");
|
|
43
|
+
var import_crypto = require("./utils/crypto");
|
|
44
|
+
var import_userAgent = require("./utils/userAgent");
|
|
45
|
+
var import_browserContext = require("./browserContext");
|
|
46
|
+
var import_cookieStore = require("./cookieStore");
|
|
47
|
+
var import_formData = require("./formData");
|
|
48
|
+
var import_instrumentation = require("./instrumentation");
|
|
49
|
+
var import_progress = require("./progress");
|
|
50
|
+
var import_socksClientCertificatesInterceptor = require("./socksClientCertificatesInterceptor");
|
|
51
|
+
var import_happyEyeballs = require("./utils/happyEyeballs");
|
|
52
|
+
var import_tracing = require("./trace/recorder/tracing");
|
|
53
|
+
class APIRequestContext extends import_instrumentation.SdkObject {
|
|
54
|
+
constructor(parent) {
|
|
55
|
+
super(parent, "request-context");
|
|
56
|
+
this.fetchResponses = /* @__PURE__ */ new Map();
|
|
57
|
+
this.fetchLog = /* @__PURE__ */ new Map();
|
|
58
|
+
this._activeProgressControllers = /* @__PURE__ */ new Set();
|
|
59
|
+
APIRequestContext.allInstances.add(this);
|
|
60
|
+
}
|
|
61
|
+
static {
|
|
62
|
+
this.Events = {
|
|
63
|
+
Dispose: "dispose",
|
|
64
|
+
Request: "request",
|
|
65
|
+
RequestFinished: "requestfinished"
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
static {
|
|
69
|
+
this.allInstances = /* @__PURE__ */ new Set();
|
|
70
|
+
}
|
|
47
71
|
static findResponseBody(guid) {
|
|
48
72
|
for (const request of APIRequestContext.allInstances) {
|
|
49
73
|
const body = request.fetchResponses.get(guid);
|
|
50
|
-
if (body)
|
|
74
|
+
if (body)
|
|
75
|
+
return body;
|
|
51
76
|
}
|
|
52
|
-
return
|
|
53
|
-
}
|
|
54
|
-
constructor(parent) {
|
|
55
|
-
super(parent, 'request-context');
|
|
56
|
-
this.fetchResponses = new Map();
|
|
57
|
-
this.fetchLog = new Map();
|
|
58
|
-
this._activeProgressControllers = new Set();
|
|
59
|
-
this._closeReason = void 0;
|
|
60
|
-
APIRequestContext.allInstances.add(this);
|
|
77
|
+
return void 0;
|
|
61
78
|
}
|
|
62
79
|
_disposeImpl() {
|
|
63
80
|
APIRequestContext.allInstances.delete(this);
|
|
@@ -70,140 +87,138 @@ class APIRequestContext extends _instrumentation.SdkObject {
|
|
|
70
87
|
this.fetchLog.delete(fetchUid);
|
|
71
88
|
}
|
|
72
89
|
_storeResponseBody(body) {
|
|
73
|
-
const uid = (0,
|
|
90
|
+
const uid = (0, import_crypto.createGuid)();
|
|
74
91
|
this.fetchResponses.set(uid, body);
|
|
75
92
|
return uid;
|
|
76
93
|
}
|
|
77
94
|
async fetch(params, metadata) {
|
|
78
|
-
var _params$method;
|
|
79
95
|
const defaults = this._defaultOptions();
|
|
80
96
|
const headers = {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
97
|
+
"user-agent": defaults.userAgent,
|
|
98
|
+
"accept": "*/*",
|
|
99
|
+
"accept-encoding": "gzip,deflate,br"
|
|
84
100
|
};
|
|
85
101
|
if (defaults.extraHTTPHeaders) {
|
|
86
|
-
for (const {
|
|
87
|
-
name,
|
|
88
|
-
value
|
|
89
|
-
} of defaults.extraHTTPHeaders) setHeader(headers, name, value);
|
|
102
|
+
for (const { name, value } of defaults.extraHTTPHeaders)
|
|
103
|
+
setHeader(headers, name, value);
|
|
90
104
|
}
|
|
91
105
|
if (params.headers) {
|
|
92
|
-
for (const {
|
|
93
|
-
name,
|
|
94
|
-
value
|
|
95
|
-
} of params.headers) setHeader(headers, name, value);
|
|
106
|
+
for (const { name, value } of params.headers)
|
|
107
|
+
setHeader(headers, name, value);
|
|
96
108
|
}
|
|
97
|
-
const requestUrl = new URL((0,
|
|
109
|
+
const requestUrl = new URL((0, import_utils.constructURLBasedOnBaseURL)(defaults.baseURL, params.url));
|
|
98
110
|
if (params.encodedParams) {
|
|
99
111
|
requestUrl.search = params.encodedParams;
|
|
100
112
|
} else if (params.params) {
|
|
101
|
-
for (const {
|
|
102
|
-
name,
|
|
103
|
-
value
|
|
104
|
-
} of params.params) requestUrl.searchParams.append(name, value);
|
|
113
|
+
for (const { name, value } of params.params)
|
|
114
|
+
requestUrl.searchParams.append(name, value);
|
|
105
115
|
}
|
|
106
116
|
const credentials = this._getHttpCredentials(requestUrl);
|
|
107
|
-
if (
|
|
108
|
-
|
|
117
|
+
if (credentials?.send === "always")
|
|
118
|
+
setBasicAuthorizationHeader(headers, credentials);
|
|
119
|
+
const method = params.method?.toUpperCase() || "GET";
|
|
109
120
|
const proxy = defaults.proxy;
|
|
110
121
|
let agent;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
if (proxy?.server !== "per-context")
|
|
123
|
+
agent = (0, import_utils.createProxyAgent)(proxy, requestUrl);
|
|
124
|
+
let maxRedirects = params.maxRedirects ?? (defaults.maxRedirects ?? 20);
|
|
125
|
+
maxRedirects = maxRedirects === 0 ? -1 : maxRedirects;
|
|
114
126
|
const timeout = defaults.timeoutSettings.timeout(params);
|
|
115
|
-
const deadline = timeout && (0,
|
|
127
|
+
const deadline = timeout && (0, import_utils.monotonicTime)() + timeout;
|
|
116
128
|
const options = {
|
|
117
129
|
method,
|
|
118
130
|
headers,
|
|
119
131
|
agent,
|
|
120
|
-
maxRedirects
|
|
132
|
+
maxRedirects,
|
|
121
133
|
timeout,
|
|
122
134
|
deadline,
|
|
123
|
-
...(0,
|
|
135
|
+
...(0, import_socksClientCertificatesInterceptor.getMatchingTLSOptionsForOrigin)(this._defaultOptions().clientCertificates, requestUrl.origin),
|
|
124
136
|
__testHookLookup: params.__testHookLookup
|
|
125
137
|
};
|
|
126
|
-
|
|
127
|
-
|
|
138
|
+
if (params.ignoreHTTPSErrors || defaults.ignoreHTTPSErrors)
|
|
139
|
+
options.rejectUnauthorized = false;
|
|
128
140
|
const postData = serializePostData(params, headers);
|
|
129
|
-
if (postData)
|
|
130
|
-
|
|
131
|
-
const
|
|
141
|
+
if (postData)
|
|
142
|
+
setHeader(headers, "content-length", String(postData.byteLength));
|
|
143
|
+
const controller = new import_progress.ProgressController(metadata, this);
|
|
144
|
+
const fetchResponse = await controller.run((progress) => {
|
|
132
145
|
return this._sendRequestWithRetries(progress, requestUrl, options, postData, params.maxRetries);
|
|
133
146
|
});
|
|
134
147
|
const fetchUid = this._storeResponseBody(fetchResponse.body);
|
|
135
148
|
this.fetchLog.set(fetchUid, controller.metadata.log);
|
|
136
|
-
const failOnStatusCode = params.failOnStatusCode !==
|
|
149
|
+
const failOnStatusCode = params.failOnStatusCode !== void 0 ? params.failOnStatusCode : !!defaults.failOnStatusCode;
|
|
137
150
|
if (failOnStatusCode && (fetchResponse.status < 200 || fetchResponse.status >= 400)) {
|
|
138
|
-
let responseText =
|
|
151
|
+
let responseText = "";
|
|
139
152
|
if (fetchResponse.body.byteLength) {
|
|
140
|
-
let text = fetchResponse.body.toString(
|
|
141
|
-
if (text.length >
|
|
142
|
-
|
|
153
|
+
let text = fetchResponse.body.toString("utf8");
|
|
154
|
+
if (text.length > 1e3)
|
|
155
|
+
text = text.substring(0, 997) + "...";
|
|
156
|
+
responseText = `
|
|
157
|
+
Response text:
|
|
158
|
+
${text}`;
|
|
143
159
|
}
|
|
144
160
|
throw new Error(`${fetchResponse.status} ${fetchResponse.statusText}${responseText}`);
|
|
145
161
|
}
|
|
146
|
-
return {
|
|
147
|
-
...fetchResponse,
|
|
148
|
-
fetchUid
|
|
149
|
-
};
|
|
162
|
+
return { ...fetchResponse, fetchUid };
|
|
150
163
|
}
|
|
151
164
|
_parseSetCookieHeader(responseUrl, setCookie) {
|
|
152
|
-
if (!setCookie)
|
|
165
|
+
if (!setCookie)
|
|
166
|
+
return [];
|
|
153
167
|
const url = new URL(responseUrl);
|
|
154
|
-
|
|
155
|
-
const defaultPath = '/' + url.pathname.substr(1).split('/').slice(0, -1).join('/');
|
|
168
|
+
const defaultPath = "/" + url.pathname.substr(1).split("/").slice(0, -1).join("/");
|
|
156
169
|
const cookies = [];
|
|
157
170
|
for (const header of setCookie) {
|
|
158
|
-
// Decode cookie value?
|
|
159
171
|
const cookie = parseCookie(header);
|
|
160
|
-
if (!cookie)
|
|
161
|
-
|
|
162
|
-
if (!cookie.domain)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
172
|
+
if (!cookie)
|
|
173
|
+
continue;
|
|
174
|
+
if (!cookie.domain)
|
|
175
|
+
cookie.domain = url.hostname;
|
|
176
|
+
else
|
|
177
|
+
(0, import_utils.assert)(cookie.domain.startsWith(".") || !cookie.domain.includes("."));
|
|
178
|
+
if (!(0, import_cookieStore.domainMatches)(url.hostname, cookie.domain))
|
|
179
|
+
continue;
|
|
180
|
+
if (!cookie.path || !cookie.path.startsWith("/"))
|
|
181
|
+
cookie.path = defaultPath;
|
|
166
182
|
cookies.push(cookie);
|
|
167
183
|
}
|
|
168
184
|
return cookies;
|
|
169
185
|
}
|
|
170
186
|
async _updateRequestCookieHeader(url, headers) {
|
|
171
|
-
if (getHeader(headers,
|
|
187
|
+
if (getHeader(headers, "cookie") !== void 0)
|
|
188
|
+
return;
|
|
172
189
|
const cookies = await this._cookies(url);
|
|
173
190
|
if (cookies.length) {
|
|
174
|
-
const valueArray = cookies.map(c => `${c.name}=${c.value}`);
|
|
175
|
-
setHeader(headers,
|
|
191
|
+
const valueArray = cookies.map((c) => `${c.name}=${c.value}`);
|
|
192
|
+
setHeader(headers, "cookie", valueArray.join("; "));
|
|
176
193
|
}
|
|
177
194
|
}
|
|
178
195
|
async _sendRequestWithRetries(progress, url, options, postData, maxRetries) {
|
|
179
|
-
maxRetries
|
|
196
|
+
maxRetries ??= 0;
|
|
180
197
|
let backoff = 250;
|
|
181
198
|
for (let i = 0; i <= maxRetries; i++) {
|
|
182
199
|
try {
|
|
183
200
|
return await this._sendRequest(progress, url, options, postData);
|
|
184
201
|
} catch (e) {
|
|
185
|
-
e = (0,
|
|
186
|
-
if (maxRetries === 0)
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
202
|
+
e = (0, import_socksClientCertificatesInterceptor.rewriteOpenSSLErrorIfNeeded)(e);
|
|
203
|
+
if (maxRetries === 0)
|
|
204
|
+
throw e;
|
|
205
|
+
if (i === maxRetries || options.deadline && (0, import_utils.monotonicTime)() + backoff > options.deadline)
|
|
206
|
+
throw new Error(`Failed after ${i + 1} attempt(s): ${e}`);
|
|
207
|
+
if (e.code !== "ECONNRESET")
|
|
208
|
+
throw e;
|
|
190
209
|
progress.log(` Received ECONNRESET, will retry after ${backoff}ms.`);
|
|
191
|
-
await new Promise(f => setTimeout(f, backoff));
|
|
210
|
+
await new Promise((f) => setTimeout(f, backoff));
|
|
192
211
|
backoff *= 2;
|
|
193
212
|
}
|
|
194
213
|
}
|
|
195
|
-
throw new Error(
|
|
214
|
+
throw new Error("Unreachable");
|
|
196
215
|
}
|
|
197
216
|
async _sendRequest(progress, url, options, postData) {
|
|
198
|
-
var _getHeader;
|
|
199
217
|
await this._updateRequestCookieHeader(url, options.headers);
|
|
200
|
-
const requestCookies =
|
|
201
|
-
const [name, value] = p.split(
|
|
202
|
-
return {
|
|
203
|
-
|
|
204
|
-
value
|
|
205
|
-
};
|
|
206
|
-
})) || [];
|
|
218
|
+
const requestCookies = getHeader(options.headers, "cookie")?.split(";").map((p) => {
|
|
219
|
+
const [name, value] = p.split("=").map((v) => v.trim());
|
|
220
|
+
return { name, value };
|
|
221
|
+
}) || [];
|
|
207
222
|
const requestEvent = {
|
|
208
223
|
url,
|
|
209
224
|
method: options.method,
|
|
@@ -213,14 +228,10 @@ class APIRequestContext extends _instrumentation.SdkObject {
|
|
|
213
228
|
};
|
|
214
229
|
this.emit(APIRequestContext.Events.Request, requestEvent);
|
|
215
230
|
return new Promise((fulfill, reject) => {
|
|
216
|
-
const requestConstructor = (url.protocol ===
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
const
|
|
220
|
-
...options,
|
|
221
|
-
agent
|
|
222
|
-
};
|
|
223
|
-
const startAt = (0, _utils.monotonicTime)();
|
|
231
|
+
const requestConstructor = (url.protocol === "https:" ? import_https.default : import_http.default).request;
|
|
232
|
+
const agent = options.agent || (url.protocol === "https:" ? import_happyEyeballs.httpsHappyEyeballsAgent : import_happyEyeballs.httpHappyEyeballsAgent);
|
|
233
|
+
const requestOptions = { ...options, agent };
|
|
234
|
+
const startAt = (0, import_utils.monotonicTime)();
|
|
224
235
|
let reusedSocketAt;
|
|
225
236
|
let dnsLookupAt;
|
|
226
237
|
let tcpConnectionAt;
|
|
@@ -230,12 +241,11 @@ class APIRequestContext extends _instrumentation.SdkObject {
|
|
|
230
241
|
let serverPort;
|
|
231
242
|
let securityDetails;
|
|
232
243
|
const listeners = [];
|
|
233
|
-
const request = requestConstructor(url, requestOptions, async response => {
|
|
234
|
-
const responseAt = (0,
|
|
235
|
-
const notifyRequestFinished =
|
|
236
|
-
const endAt = (0,
|
|
237
|
-
|
|
238
|
-
const connectEnd = tlsHandshakeAt !== null && tlsHandshakeAt !== void 0 ? tlsHandshakeAt : tcpConnectionAt;
|
|
244
|
+
const request = requestConstructor(url, requestOptions, async (response) => {
|
|
245
|
+
const responseAt = (0, import_utils.monotonicTime)();
|
|
246
|
+
const notifyRequestFinished = (body2) => {
|
|
247
|
+
const endAt = (0, import_utils.monotonicTime)();
|
|
248
|
+
const connectEnd = tlsHandshakeAt ?? tcpConnectionAt;
|
|
239
249
|
const timings = {
|
|
240
250
|
send: requestFinishAt - startAt,
|
|
241
251
|
wait: responseAt - requestFinishAt,
|
|
@@ -250,11 +260,11 @@ class APIRequestContext extends _instrumentation.SdkObject {
|
|
|
250
260
|
requestEvent,
|
|
251
261
|
httpVersion: response.httpVersion,
|
|
252
262
|
statusCode: response.statusCode || 0,
|
|
253
|
-
statusMessage: response.statusMessage ||
|
|
263
|
+
statusMessage: response.statusMessage || "",
|
|
254
264
|
headers: response.headers,
|
|
255
265
|
rawHeaders: response.rawHeaders,
|
|
256
266
|
cookies,
|
|
257
|
-
body,
|
|
267
|
+
body: body2,
|
|
258
268
|
timings,
|
|
259
269
|
serverIPAddress,
|
|
260
270
|
serverPort,
|
|
@@ -262,36 +272,31 @@ class APIRequestContext extends _instrumentation.SdkObject {
|
|
|
262
272
|
};
|
|
263
273
|
this.emit(APIRequestContext.Events.RequestFinished, requestFinishedEvent);
|
|
264
274
|
};
|
|
265
|
-
progress.log(
|
|
266
|
-
for (const [name, value] of Object.entries(response.headers))
|
|
267
|
-
|
|
275
|
+
progress.log(`\u2190 ${response.statusCode} ${response.statusMessage}`);
|
|
276
|
+
for (const [name, value] of Object.entries(response.headers))
|
|
277
|
+
progress.log(` ${name}: ${value}`);
|
|
278
|
+
const cookies = this._parseSetCookieHeader(response.url || url.toString(), response.headers["set-cookie"]);
|
|
268
279
|
if (cookies.length) {
|
|
269
280
|
try {
|
|
270
281
|
await this._addCookies(cookies);
|
|
271
282
|
} catch (e) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
await Promise.all(cookies.map(c => this._addCookies([c]).catch(() => {})));
|
|
283
|
+
await Promise.all(cookies.map((c) => this._addCookies([c]).catch(() => {
|
|
284
|
+
})));
|
|
275
285
|
}
|
|
276
286
|
}
|
|
277
287
|
if (redirectStatus.includes(response.statusCode) && options.maxRedirects >= 0) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
reject(new Error('Max redirect count exceeded'));
|
|
288
|
+
if (options.maxRedirects === 0) {
|
|
289
|
+
reject(new Error("Max redirect count exceeded"));
|
|
281
290
|
request.destroy();
|
|
282
291
|
return;
|
|
283
292
|
}
|
|
284
|
-
const headers = {
|
|
285
|
-
...options.headers
|
|
286
|
-
};
|
|
293
|
+
const headers = { ...options.headers };
|
|
287
294
|
removeHeader(headers, `cookie`);
|
|
288
|
-
|
|
289
|
-
// HTTP-redirect fetch step 13 (https://fetch.spec.whatwg.org/#http-redirect-fetch)
|
|
290
295
|
const status = response.statusCode;
|
|
291
296
|
let method = options.method;
|
|
292
|
-
if ((status === 301 || status === 302) && method ===
|
|
293
|
-
method =
|
|
294
|
-
postData =
|
|
297
|
+
if ((status === 301 || status === 302) && method === "POST" || status === 303 && !["GET", "HEAD"].includes(method)) {
|
|
298
|
+
method = "GET";
|
|
299
|
+
postData = void 0;
|
|
295
300
|
removeHeader(headers, `content-encoding`);
|
|
296
301
|
removeHeader(headers, `content-language`);
|
|
297
302
|
removeHeader(headers, `content-length`);
|
|
@@ -305,16 +310,12 @@ class APIRequestContext extends _instrumentation.SdkObject {
|
|
|
305
310
|
maxRedirects: options.maxRedirects - 1,
|
|
306
311
|
timeout: options.timeout,
|
|
307
312
|
deadline: options.deadline,
|
|
308
|
-
...(0,
|
|
313
|
+
...(0, import_socksClientCertificatesInterceptor.getMatchingTLSOptionsForOrigin)(this._defaultOptions().clientCertificates, url.origin),
|
|
309
314
|
__testHookLookup: options.__testHookLookup
|
|
310
315
|
};
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
// HTTP-redirect fetch step 4: If locationURL is null, then return response.
|
|
315
|
-
// Best-effort UTF-8 decoding, per spec it's US-ASCII only, but browsers are more lenient.
|
|
316
|
-
// Node.js parses it as Latin1 via std::v8::String, so we convert it to UTF-8.
|
|
317
|
-
const locationHeaderValue = Buffer.from((_response$headers$loc = response.headers.location) !== null && _response$headers$loc !== void 0 ? _response$headers$loc : '', 'latin1').toString('utf8');
|
|
316
|
+
if (options.rejectUnauthorized === false)
|
|
317
|
+
redirectOptions.rejectUnauthorized = false;
|
|
318
|
+
const locationHeaderValue = Buffer.from(response.headers.location ?? "", "latin1").toString("utf8");
|
|
318
319
|
if (locationHeaderValue) {
|
|
319
320
|
let locationURL;
|
|
320
321
|
try {
|
|
@@ -324,17 +325,18 @@ class APIRequestContext extends _instrumentation.SdkObject {
|
|
|
324
325
|
request.destroy();
|
|
325
326
|
return;
|
|
326
327
|
}
|
|
327
|
-
if (headers[
|
|
328
|
+
if (headers["host"])
|
|
329
|
+
headers["host"] = locationURL.host;
|
|
328
330
|
notifyRequestFinished();
|
|
329
331
|
fulfill(this._sendRequest(progress, locationURL, redirectOptions, postData));
|
|
330
332
|
request.destroy();
|
|
331
333
|
return;
|
|
332
334
|
}
|
|
333
335
|
}
|
|
334
|
-
if (response.statusCode === 401 && !getHeader(options.headers,
|
|
335
|
-
const auth = response.headers[
|
|
336
|
+
if (response.statusCode === 401 && !getHeader(options.headers, "authorization")) {
|
|
337
|
+
const auth = response.headers["www-authenticate"];
|
|
336
338
|
const credentials = this._getHttpCredentials(url);
|
|
337
|
-
if (auth
|
|
339
|
+
if (auth?.trim().startsWith("Basic") && credentials) {
|
|
338
340
|
setBasicAuthorizationHeader(options.headers, credentials);
|
|
339
341
|
notifyRequestFinished();
|
|
340
342
|
fulfill(this._sendRequest(progress, url, options, postData));
|
|
@@ -342,128 +344,123 @@ class APIRequestContext extends _instrumentation.SdkObject {
|
|
|
342
344
|
return;
|
|
343
345
|
}
|
|
344
346
|
}
|
|
345
|
-
response.on(
|
|
347
|
+
response.on("aborted", () => reject(new Error("aborted")));
|
|
346
348
|
const chunks = [];
|
|
347
349
|
const notifyBodyFinished = () => {
|
|
348
|
-
const
|
|
349
|
-
notifyRequestFinished(
|
|
350
|
+
const body2 = Buffer.concat(chunks);
|
|
351
|
+
notifyRequestFinished(body2);
|
|
350
352
|
fulfill({
|
|
351
353
|
url: response.url || url.toString(),
|
|
352
354
|
status: response.statusCode || 0,
|
|
353
|
-
statusText: response.statusMessage ||
|
|
355
|
+
statusText: response.statusMessage || "",
|
|
354
356
|
headers: toHeadersArray(response.rawHeaders),
|
|
355
|
-
body
|
|
357
|
+
body: body2
|
|
356
358
|
});
|
|
357
359
|
};
|
|
358
360
|
let body = response;
|
|
359
361
|
let transform;
|
|
360
|
-
const encoding = response.headers[
|
|
361
|
-
if (encoding ===
|
|
362
|
+
const encoding = response.headers["content-encoding"];
|
|
363
|
+
if (encoding === "gzip" || encoding === "x-gzip") {
|
|
362
364
|
transform = zlib.createGunzip({
|
|
363
365
|
flush: zlib.constants.Z_SYNC_FLUSH,
|
|
364
366
|
finishFlush: zlib.constants.Z_SYNC_FLUSH
|
|
365
367
|
});
|
|
366
|
-
} else if (encoding ===
|
|
368
|
+
} else if (encoding === "br") {
|
|
367
369
|
transform = zlib.createBrotliDecompress({
|
|
368
370
|
flush: zlib.constants.BROTLI_OPERATION_FLUSH,
|
|
369
371
|
finishFlush: zlib.constants.BROTLI_OPERATION_FLUSH
|
|
370
372
|
});
|
|
371
|
-
} else if (encoding ===
|
|
373
|
+
} else if (encoding === "deflate") {
|
|
372
374
|
transform = zlib.createInflate();
|
|
373
375
|
}
|
|
374
376
|
if (transform) {
|
|
375
|
-
// Brotli and deflate decompressors throw if the input stream is empty.
|
|
376
377
|
const emptyStreamTransform = new SafeEmptyStreamTransform(notifyBodyFinished);
|
|
377
|
-
body = (0,
|
|
378
|
-
if (e)
|
|
378
|
+
body = (0, import_stream.pipeline)(response, emptyStreamTransform, transform, (e) => {
|
|
379
|
+
if (e)
|
|
380
|
+
reject(new Error(`failed to decompress '${encoding}' encoding: ${e.message}`));
|
|
379
381
|
});
|
|
380
|
-
body.on(
|
|
382
|
+
body.on("error", (e) => reject(new Error(`failed to decompress '${encoding}' encoding: ${e}`)));
|
|
381
383
|
} else {
|
|
382
|
-
body.on(
|
|
384
|
+
body.on("error", reject);
|
|
383
385
|
}
|
|
384
|
-
body.on(
|
|
385
|
-
body.on(
|
|
386
|
+
body.on("data", (chunk) => chunks.push(chunk));
|
|
387
|
+
body.on("end", notifyBodyFinished);
|
|
386
388
|
});
|
|
387
|
-
request.on(
|
|
388
|
-
listeners.push(
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
389
|
+
request.on("error", reject);
|
|
390
|
+
listeners.push(
|
|
391
|
+
import_utils.eventsHelper.addEventListener(this, APIRequestContext.Events.Dispose, () => {
|
|
392
|
+
reject(new Error("Request context disposed."));
|
|
393
|
+
request.destroy();
|
|
394
|
+
})
|
|
395
|
+
);
|
|
396
|
+
request.on("close", () => import_utils.eventsHelper.removeEventListeners(listeners));
|
|
397
|
+
request.on("socket", (socket) => {
|
|
394
398
|
if (request.reusedSocket) {
|
|
395
|
-
reusedSocketAt = (0,
|
|
399
|
+
reusedSocketAt = (0, import_utils.monotonicTime)();
|
|
396
400
|
return;
|
|
397
401
|
}
|
|
398
|
-
|
|
399
|
-
// happy eyeballs don't emit lookup and connect events, so we use our custom ones
|
|
400
|
-
const happyEyeBallsTimings = (0, _happyEyeballs.timingForSocket)(socket);
|
|
402
|
+
const happyEyeBallsTimings = (0, import_happyEyeballs.timingForSocket)(socket);
|
|
401
403
|
dnsLookupAt = happyEyeBallsTimings.dnsLookupAt;
|
|
402
404
|
tcpConnectionAt = happyEyeBallsTimings.tcpConnectionAt;
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
405
|
+
listeners.push(
|
|
406
|
+
import_utils.eventsHelper.addEventListener(socket, "lookup", () => {
|
|
407
|
+
dnsLookupAt = (0, import_utils.monotonicTime)();
|
|
408
|
+
}),
|
|
409
|
+
import_utils.eventsHelper.addEventListener(socket, "connect", () => {
|
|
410
|
+
tcpConnectionAt = (0, import_utils.monotonicTime)();
|
|
411
|
+
}),
|
|
412
|
+
import_utils.eventsHelper.addEventListener(socket, "secureConnect", () => {
|
|
413
|
+
tlsHandshakeAt = (0, import_utils.monotonicTime)();
|
|
414
|
+
if (socket instanceof import_tls.TLSSocket) {
|
|
415
|
+
const peerCertificate = socket.getPeerCertificate();
|
|
416
|
+
securityDetails = {
|
|
417
|
+
protocol: socket.getProtocol() ?? void 0,
|
|
418
|
+
subjectName: peerCertificate.subject.CN,
|
|
419
|
+
validFrom: new Date(peerCertificate.valid_from).getTime() / 1e3,
|
|
420
|
+
validTo: new Date(peerCertificate.valid_to).getTime() / 1e3,
|
|
421
|
+
issuer: peerCertificate.issuer.CN
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
})
|
|
425
|
+
);
|
|
423
426
|
serverIPAddress = socket.remoteAddress;
|
|
424
427
|
serverPort = socket.remotePort;
|
|
425
428
|
});
|
|
426
|
-
request.on(
|
|
427
|
-
requestFinishAt = (0,
|
|
429
|
+
request.on("finish", () => {
|
|
430
|
+
requestFinishAt = (0, import_utils.monotonicTime)();
|
|
428
431
|
});
|
|
429
|
-
progress.log(
|
|
432
|
+
progress.log(`\u2192 ${options.method} ${url.toString()}`);
|
|
430
433
|
if (options.headers) {
|
|
431
|
-
for (const [name, value] of Object.entries(options.headers))
|
|
434
|
+
for (const [name, value] of Object.entries(options.headers))
|
|
435
|
+
progress.log(` ${name}: ${value}`);
|
|
432
436
|
}
|
|
433
437
|
if (options.deadline) {
|
|
434
438
|
const rejectOnTimeout = () => {
|
|
435
439
|
reject(new Error(`Request timed out after ${options.timeout}ms`));
|
|
436
440
|
request.destroy();
|
|
437
441
|
};
|
|
438
|
-
const remaining = options.deadline - (0,
|
|
442
|
+
const remaining = options.deadline - (0, import_utils.monotonicTime)();
|
|
439
443
|
if (remaining <= 0) {
|
|
440
444
|
rejectOnTimeout();
|
|
441
445
|
return;
|
|
442
446
|
}
|
|
443
447
|
request.setTimeout(remaining, rejectOnTimeout);
|
|
444
448
|
}
|
|
445
|
-
if (postData)
|
|
449
|
+
if (postData)
|
|
450
|
+
request.write(postData);
|
|
446
451
|
request.end();
|
|
447
452
|
});
|
|
448
453
|
}
|
|
449
454
|
_getHttpCredentials(url) {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
return
|
|
455
|
+
if (!this._defaultOptions().httpCredentials?.origin || url.origin.toLowerCase() === this._defaultOptions().httpCredentials?.origin?.toLowerCase())
|
|
456
|
+
return this._defaultOptions().httpCredentials;
|
|
457
|
+
return void 0;
|
|
453
458
|
}
|
|
454
459
|
}
|
|
455
|
-
|
|
456
|
-
APIRequestContext.Events = {
|
|
457
|
-
Dispose: 'dispose',
|
|
458
|
-
Request: 'request',
|
|
459
|
-
RequestFinished: 'requestfinished'
|
|
460
|
-
};
|
|
461
|
-
APIRequestContext.allInstances = new Set();
|
|
462
|
-
class SafeEmptyStreamTransform extends _stream.Transform {
|
|
460
|
+
class SafeEmptyStreamTransform extends import_stream.Transform {
|
|
463
461
|
constructor(onEmptyStreamCallback) {
|
|
464
462
|
super();
|
|
465
463
|
this._receivedSomeData = false;
|
|
466
|
-
this._onEmptyStreamCallback = void 0;
|
|
467
464
|
this._onEmptyStreamCallback = onEmptyStreamCallback;
|
|
468
465
|
}
|
|
469
466
|
_transform(chunk, encoding, callback) {
|
|
@@ -471,15 +468,17 @@ class SafeEmptyStreamTransform extends _stream.Transform {
|
|
|
471
468
|
callback(null, chunk);
|
|
472
469
|
}
|
|
473
470
|
_flush(callback) {
|
|
474
|
-
if (this._receivedSomeData)
|
|
471
|
+
if (this._receivedSomeData)
|
|
472
|
+
callback(null);
|
|
473
|
+
else
|
|
474
|
+
this._onEmptyStreamCallback();
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
477
|
class BrowserContextAPIRequestContext extends APIRequestContext {
|
|
478
478
|
constructor(context) {
|
|
479
479
|
super(context);
|
|
480
|
-
this._context = void 0;
|
|
481
480
|
this._context = context;
|
|
482
|
-
context.once(
|
|
481
|
+
context.once(import_browserContext.BrowserContext.Events.Close, () => this._disposeImpl());
|
|
483
482
|
}
|
|
484
483
|
tracing() {
|
|
485
484
|
return this._context.tracing;
|
|
@@ -492,7 +491,7 @@ class BrowserContextAPIRequestContext extends APIRequestContext {
|
|
|
492
491
|
return {
|
|
493
492
|
userAgent: this._context._options.userAgent || this._context._browser.userAgent(),
|
|
494
493
|
extraHTTPHeaders: this._context._options.extraHTTPHeaders,
|
|
495
|
-
failOnStatusCode:
|
|
494
|
+
failOnStatusCode: void 0,
|
|
496
495
|
httpCredentials: this._context._options.httpCredentials,
|
|
497
496
|
proxy: this._context._options.proxy || this._context._browser.options.proxy,
|
|
498
497
|
timeoutSettings: this._context._timeoutSettings,
|
|
@@ -511,44 +510,32 @@ class BrowserContextAPIRequestContext extends APIRequestContext {
|
|
|
511
510
|
return this._context.storageState(indexedDB);
|
|
512
511
|
}
|
|
513
512
|
}
|
|
514
|
-
exports.BrowserContextAPIRequestContext = BrowserContextAPIRequestContext;
|
|
515
513
|
class GlobalAPIRequestContext extends APIRequestContext {
|
|
516
514
|
constructor(playwright, options) {
|
|
517
515
|
super(playwright);
|
|
518
|
-
this._cookieStore = new
|
|
519
|
-
this._options = void 0;
|
|
520
|
-
this._origins = void 0;
|
|
521
|
-
this._tracing = void 0;
|
|
516
|
+
this._cookieStore = new import_cookieStore.CookieStore();
|
|
522
517
|
this.attribution.context = this;
|
|
523
|
-
const timeoutSettings = new
|
|
524
|
-
if (options.timeout !==
|
|
525
|
-
|
|
526
|
-
if (proxy !== null && proxy !== void 0 && proxy.server) {
|
|
527
|
-
let url = proxy === null || proxy === void 0 ? void 0 : proxy.server.trim();
|
|
528
|
-
if (!/^\w+:\/\//.test(url)) url = 'http://' + url;
|
|
529
|
-
proxy.server = url;
|
|
530
|
-
}
|
|
518
|
+
const timeoutSettings = new import_timeoutSettings.TimeoutSettings();
|
|
519
|
+
if (options.timeout !== void 0)
|
|
520
|
+
timeoutSettings.setDefaultTimeout(options.timeout);
|
|
531
521
|
if (options.storageState) {
|
|
532
|
-
|
|
533
|
-
this._origins = (_options$storageState = options.storageState.origins) === null || _options$storageState === void 0 ? void 0 : _options$storageState.map(origin => ({
|
|
534
|
-
indexedDB: [],
|
|
535
|
-
...origin
|
|
536
|
-
}));
|
|
522
|
+
this._origins = options.storageState.origins?.map((origin) => ({ indexedDB: [], ...origin }));
|
|
537
523
|
this._cookieStore.addCookies(options.storageState.cookies || []);
|
|
538
524
|
}
|
|
539
|
-
(0,
|
|
525
|
+
(0, import_browserContext.verifyClientCertificates)(options.clientCertificates);
|
|
540
526
|
this._options = {
|
|
541
527
|
baseURL: options.baseURL,
|
|
542
|
-
userAgent: options.userAgent || (0,
|
|
528
|
+
userAgent: options.userAgent || (0, import_userAgent.getUserAgent)(),
|
|
543
529
|
extraHTTPHeaders: options.extraHTTPHeaders,
|
|
544
530
|
failOnStatusCode: !!options.failOnStatusCode,
|
|
545
531
|
ignoreHTTPSErrors: !!options.ignoreHTTPSErrors,
|
|
532
|
+
maxRedirects: options.maxRedirects,
|
|
546
533
|
httpCredentials: options.httpCredentials,
|
|
547
534
|
clientCertificates: options.clientCertificates,
|
|
548
|
-
proxy,
|
|
535
|
+
proxy: options.proxy,
|
|
549
536
|
timeoutSettings
|
|
550
537
|
};
|
|
551
|
-
this._tracing = new
|
|
538
|
+
this._tracing = new import_tracing.Tracing(this, options.tracesDir);
|
|
552
539
|
}
|
|
553
540
|
tracing() {
|
|
554
541
|
return this._tracing;
|
|
@@ -571,104 +558,83 @@ class GlobalAPIRequestContext extends APIRequestContext {
|
|
|
571
558
|
async storageState(indexedDB = false) {
|
|
572
559
|
return {
|
|
573
560
|
cookies: this._cookieStore.allCookies(),
|
|
574
|
-
origins: (this._origins || []).map(origin => ({
|
|
575
|
-
...origin,
|
|
576
|
-
indexedDB: indexedDB ? origin.indexedDB : []
|
|
577
|
-
}))
|
|
561
|
+
origins: (this._origins || []).map((origin) => ({ ...origin, indexedDB: indexedDB ? origin.indexedDB : [] }))
|
|
578
562
|
};
|
|
579
563
|
}
|
|
580
564
|
}
|
|
581
|
-
exports.GlobalAPIRequestContext = GlobalAPIRequestContext;
|
|
582
|
-
function createProxyAgent(proxy) {
|
|
583
|
-
var _proxyOpts$protocol;
|
|
584
|
-
const proxyOpts = _url.default.parse(proxy.server);
|
|
585
|
-
if ((_proxyOpts$protocol = proxyOpts.protocol) !== null && _proxyOpts$protocol !== void 0 && _proxyOpts$protocol.startsWith('socks')) {
|
|
586
|
-
return new _utilsBundle.SocksProxyAgent({
|
|
587
|
-
host: proxyOpts.hostname,
|
|
588
|
-
port: proxyOpts.port || undefined
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
if (proxy.username) proxyOpts.auth = `${proxy.username}:${proxy.password || ''}`;
|
|
592
|
-
// TODO: We should use HttpProxyAgent conditional on proxyOpts.protocol instead of always using CONNECT method.
|
|
593
|
-
return new _utilsBundle.HttpsProxyAgent(proxyOpts);
|
|
594
|
-
}
|
|
595
565
|
function toHeadersArray(rawHeaders) {
|
|
596
566
|
const result = [];
|
|
597
|
-
for (let i = 0; i < rawHeaders.length; i += 2)
|
|
598
|
-
name: rawHeaders[i],
|
|
599
|
-
value: rawHeaders[i + 1]
|
|
600
|
-
});
|
|
567
|
+
for (let i = 0; i < rawHeaders.length; i += 2)
|
|
568
|
+
result.push({ name: rawHeaders[i], value: rawHeaders[i + 1] });
|
|
601
569
|
return result;
|
|
602
570
|
}
|
|
603
571
|
const redirectStatus = [301, 302, 303, 307, 308];
|
|
604
572
|
function parseCookie(header) {
|
|
605
|
-
const raw = (0,
|
|
606
|
-
if (!raw)
|
|
573
|
+
const raw = (0, import_cookieStore.parseRawCookie)(header);
|
|
574
|
+
if (!raw)
|
|
575
|
+
return null;
|
|
607
576
|
const cookie = {
|
|
608
|
-
domain:
|
|
609
|
-
path:
|
|
577
|
+
domain: "",
|
|
578
|
+
path: "",
|
|
610
579
|
expires: -1,
|
|
611
580
|
httpOnly: false,
|
|
612
581
|
secure: false,
|
|
613
582
|
// From https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
|
|
614
583
|
// The cookie-sending behavior if SameSite is not specified is SameSite=Lax.
|
|
615
|
-
sameSite:
|
|
584
|
+
sameSite: "Lax",
|
|
616
585
|
...raw
|
|
617
586
|
};
|
|
618
587
|
return cookie;
|
|
619
588
|
}
|
|
620
589
|
function serializePostData(params, headers) {
|
|
621
|
-
(0,
|
|
622
|
-
if (params.jsonData !==
|
|
623
|
-
setHeader(headers,
|
|
624
|
-
return Buffer.from(params.jsonData,
|
|
590
|
+
(0, import_utils.assert)((params.postData ? 1 : 0) + (params.jsonData ? 1 : 0) + (params.formData ? 1 : 0) + (params.multipartData ? 1 : 0) <= 1, `Only one of 'data', 'form' or 'multipart' can be specified`);
|
|
591
|
+
if (params.jsonData !== void 0) {
|
|
592
|
+
setHeader(headers, "content-type", "application/json", true);
|
|
593
|
+
return Buffer.from(params.jsonData, "utf8");
|
|
625
594
|
} else if (params.formData) {
|
|
626
595
|
const searchParams = new URLSearchParams();
|
|
627
|
-
for (const {
|
|
628
|
-
name,
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
setHeader(headers, 'content-type', 'application/x-www-form-urlencoded', true);
|
|
632
|
-
return Buffer.from(searchParams.toString(), 'utf8');
|
|
596
|
+
for (const { name, value } of params.formData)
|
|
597
|
+
searchParams.append(name, value);
|
|
598
|
+
setHeader(headers, "content-type", "application/x-www-form-urlencoded", true);
|
|
599
|
+
return Buffer.from(searchParams.toString(), "utf8");
|
|
633
600
|
} else if (params.multipartData) {
|
|
634
|
-
const formData = new
|
|
601
|
+
const formData = new import_formData.MultipartFormData();
|
|
635
602
|
for (const field of params.multipartData) {
|
|
636
|
-
if (field.file)
|
|
603
|
+
if (field.file)
|
|
604
|
+
formData.addFileField(field.name, field.file);
|
|
605
|
+
else if (field.value)
|
|
606
|
+
formData.addField(field.name, field.value);
|
|
637
607
|
}
|
|
638
|
-
setHeader(headers,
|
|
608
|
+
setHeader(headers, "content-type", formData.contentTypeHeader(), true);
|
|
639
609
|
return formData.finish();
|
|
640
|
-
} else if (params.postData !==
|
|
641
|
-
setHeader(headers,
|
|
610
|
+
} else if (params.postData !== void 0) {
|
|
611
|
+
setHeader(headers, "content-type", "application/octet-stream", true);
|
|
642
612
|
return params.postData;
|
|
643
613
|
}
|
|
644
|
-
return
|
|
614
|
+
return void 0;
|
|
645
615
|
}
|
|
646
616
|
function setHeader(headers, name, value, keepExisting = false) {
|
|
647
|
-
const existing = Object.entries(headers).find(pair => pair[0].toLowerCase() === name.toLowerCase());
|
|
648
|
-
if (!existing)
|
|
617
|
+
const existing = Object.entries(headers).find((pair) => pair[0].toLowerCase() === name.toLowerCase());
|
|
618
|
+
if (!existing)
|
|
619
|
+
headers[name] = value;
|
|
620
|
+
else if (!keepExisting)
|
|
621
|
+
headers[existing[0]] = value;
|
|
649
622
|
}
|
|
650
623
|
function getHeader(headers, name) {
|
|
651
|
-
const existing = Object.entries(headers).find(pair => pair[0].toLowerCase() === name.toLowerCase());
|
|
652
|
-
return existing ? existing[1] :
|
|
624
|
+
const existing = Object.entries(headers).find((pair) => pair[0].toLowerCase() === name.toLowerCase());
|
|
625
|
+
return existing ? existing[1] : void 0;
|
|
653
626
|
}
|
|
654
627
|
function removeHeader(headers, name) {
|
|
655
628
|
delete headers[name];
|
|
656
629
|
}
|
|
657
|
-
function shouldBypassProxy(url, bypass) {
|
|
658
|
-
if (!bypass) return false;
|
|
659
|
-
const domains = bypass.split(',').map(s => {
|
|
660
|
-
s = s.trim();
|
|
661
|
-
if (!s.startsWith('.')) s = '.' + s;
|
|
662
|
-
return s;
|
|
663
|
-
});
|
|
664
|
-
const domain = '.' + url.hostname;
|
|
665
|
-
return domains.some(d => domain.endsWith(d));
|
|
666
|
-
}
|
|
667
630
|
function setBasicAuthorizationHeader(headers, credentials) {
|
|
668
|
-
const {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
631
|
+
const { username, password } = credentials;
|
|
632
|
+
const encoded = Buffer.from(`${username || ""}:${password || ""}`).toString("base64");
|
|
633
|
+
setHeader(headers, "authorization", `Basic ${encoded}`);
|
|
634
|
+
}
|
|
635
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
636
|
+
0 && (module.exports = {
|
|
637
|
+
APIRequestContext,
|
|
638
|
+
BrowserContextAPIRequestContext,
|
|
639
|
+
GlobalAPIRequestContext
|
|
640
|
+
});
|