@checkly/playwright-core 1.51.17-beta.2 → 1.54.2-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ThirdPartyNotices.txt +65 -123
- package/browsers.json +16 -14
- package/index.js +1 -1
- package/lib/androidServerImpl.js +47 -50
- package/lib/browserServerImpl.js +89 -69
- package/lib/checkly/escapeRegExp.js +23 -27
- package/lib/checkly/fetch.js +64 -46
- package/lib/checkly/secretsFilter.js +49 -35
- package/lib/cli/driver.js +71 -69
- package/lib/cli/program.js +400 -359
- package/lib/cli/programWithTestStub.js +51 -45
- package/lib/client/accessibility.js +31 -32
- package/lib/client/android.js +151 -242
- package/lib/client/api.js +135 -283
- package/lib/client/artifact.js +39 -36
- package/lib/client/browser.js +96 -71
- package/lib/client/browserContext.js +314 -345
- package/lib/client/browserType.js +103 -127
- package/lib/client/cdpSession.js +29 -31
- package/lib/client/channelOwner.js +89 -112
- package/lib/client/clientHelper.js +48 -39
- package/lib/client/clientInstrumentation.js +40 -37
- package/lib/client/clientStackTrace.js +41 -37
- package/lib/client/clock.js +36 -36
- package/lib/client/connection.js +188 -214
- package/lib/client/consoleMessage.js +31 -28
- package/lib/client/coverage.js +25 -22
- package/lib/client/dialog.js +30 -31
- package/lib/client/download.js +25 -25
- package/lib/client/electron.js +80 -77
- package/lib/client/elementHandle.js +120 -159
- package/lib/client/errors.js +53 -53
- package/lib/client/eventEmitter.js +124 -121
- package/lib/client/events.js +72 -68
- package/lib/client/fetch.js +166 -190
- package/lib/client/fileChooser.js +25 -24
- package/lib/client/fileUtils.js +31 -28
- package/lib/client/frame.js +207 -306
- package/lib/client/harRouter.js +42 -52
- package/lib/client/input.js +42 -69
- package/lib/client/jsHandle.js +54 -69
- package/lib/client/jsonPipe.js +27 -23
- package/lib/client/localUtils.js +29 -29
- package/lib/client/locator.js +145 -237
- package/lib/client/network.js +282 -307
- package/lib/client/page.js +269 -318
- package/lib/client/platform.js +46 -43
- package/lib/client/playwright.js +51 -76
- package/lib/client/selectors.js +45 -63
- package/lib/client/stream.js +29 -25
- package/lib/client/timeoutSettings.js +55 -41
- package/lib/client/tracing.js +49 -96
- package/lib/client/types.js +26 -22
- package/lib/client/video.js +35 -27
- package/lib/client/waiter.js +69 -88
- package/lib/client/webError.js +25 -23
- package/lib/client/webSocket.js +43 -56
- package/lib/client/worker.js +48 -56
- package/lib/client/writableStream.js +27 -23
- package/lib/generated/bindingsControllerSource.js +28 -0
- package/lib/generated/clockSource.js +26 -6
- package/lib/generated/consoleApiSource.js +26 -6
- package/lib/generated/injectedScriptSource.js +26 -6
- package/lib/generated/pollingRecorderSource.js +26 -6
- package/lib/generated/storageScriptSource.js +28 -0
- package/lib/generated/utilityScriptSource.js +26 -6
- package/lib/generated/webSocketMockSource.js +333 -5
- package/lib/inProcessFactory.js +51 -53
- package/lib/inprocess.js +2 -19
- package/lib/outofprocess.js +51 -46
- package/lib/protocol/serializers.js +153 -134
- package/lib/protocol/validator.js +2807 -2739
- package/lib/protocol/validatorPrimitives.js +114 -73
- package/lib/remote/playwrightConnection.js +88 -242
- package/lib/remote/playwrightServer.js +305 -92
- package/lib/server/accessibility.js +44 -37
- package/lib/server/android/android.js +251 -241
- package/lib/server/android/backendAdb.js +87 -82
- package/lib/server/artifact.js +78 -55
- package/lib/server/bidi/bidiBrowser.js +297 -158
- package/lib/server/bidi/bidiChromium.js +119 -89
- package/lib/server/bidi/bidiConnection.js +66 -83
- package/lib/server/bidi/bidiExecutionContext.js +129 -113
- package/lib/server/bidi/bidiFirefox.js +86 -76
- package/lib/server/bidi/bidiInput.js +106 -117
- package/lib/server/bidi/bidiNetworkManager.js +142 -159
- package/lib/server/bidi/bidiOverCdp.js +57 -58
- package/lib/server/bidi/bidiPage.js +260 -260
- package/lib/server/bidi/bidiPdf.js +52 -86
- package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
- package/lib/server/bidi/third_party/bidiDeserializer.js +55 -50
- package/lib/server/bidi/third_party/bidiKeyboard.js +236 -220
- package/lib/server/bidi/third_party/bidiProtocol.js +22 -137
- package/lib/server/bidi/third_party/bidiProtocolCore.js +152 -0
- package/lib/server/bidi/third_party/bidiProtocolPermissions.js +42 -0
- package/lib/server/bidi/third_party/bidiSerializer.js +67 -63
- package/lib/server/bidi/third_party/firefoxPrefs.js +141 -119
- package/lib/server/browser.js +93 -95
- package/lib/server/browserContext.js +419 -429
- package/lib/server/browserType.js +186 -216
- package/lib/server/callLog.js +47 -44
- package/lib/server/chromium/chromium.js +235 -203
- package/lib/server/chromium/chromiumSwitches.js +100 -67
- package/lib/server/chromium/crAccessibility.js +157 -131
- package/lib/server/chromium/crBrowser.js +310 -292
- package/lib/server/chromium/crConnection.js +95 -121
- package/lib/server/chromium/crCoverage.js +121 -131
- package/lib/server/chromium/crDevTools.js +60 -51
- package/lib/server/chromium/crDragDrop.js +68 -84
- package/lib/server/chromium/crExecutionContext.js +89 -83
- package/lib/server/chromium/crInput.js +118 -113
- package/lib/server/chromium/crNetworkManager.js +274 -375
- package/lib/server/chromium/crPage.js +536 -593
- package/lib/server/chromium/crPdf.js +54 -86
- package/lib/server/chromium/crProtocolHelper.js +92 -80
- package/lib/server/chromium/crServiceWorker.js +84 -73
- package/lib/server/chromium/defaultFontFamilies.js +152 -135
- package/lib/server/chromium/protocol.d.js +16 -0
- package/lib/server/chromium/videoRecorder.js +66 -99
- package/lib/server/clock.js +107 -83
- package/lib/server/codegen/csharp.js +192 -162
- package/lib/server/codegen/java.js +156 -129
- package/lib/server/codegen/javascript.js +163 -148
- package/lib/server/codegen/jsonl.js +32 -28
- package/lib/server/codegen/language.js +75 -52
- package/lib/server/codegen/languages.js +65 -27
- package/lib/server/codegen/python.js +141 -126
- package/lib/server/codegen/types.js +15 -4
- package/lib/server/console.js +28 -32
- package/lib/server/cookieStore.js +108 -86
- package/lib/server/debugController.js +147 -151
- package/lib/server/debugger.js +86 -78
- package/lib/server/deviceDescriptors.js +37 -24
- package/lib/server/deviceDescriptorsSource.json +238 -128
- package/lib/server/dialog.js +84 -39
- package/lib/server/dispatchers/androidDispatcher.js +257 -148
- package/lib/server/dispatchers/artifactDispatcher.js +79 -79
- package/lib/server/dispatchers/browserContextDispatcher.js +289 -259
- package/lib/server/dispatchers/browserDispatcher.js +96 -148
- package/lib/server/dispatchers/browserTypeDispatcher.js +50 -41
- package/lib/server/dispatchers/cdpSessionDispatcher.js +35 -39
- package/lib/server/dispatchers/debugControllerDispatcher.js +65 -83
- package/lib/server/dispatchers/dialogDispatcher.js +34 -31
- package/lib/server/dispatchers/dispatcher.js +208 -248
- package/lib/server/dispatchers/electronDispatcher.js +66 -70
- package/lib/server/dispatchers/elementHandlerDispatcher.js +164 -216
- package/lib/server/dispatchers/frameDispatcher.js +211 -272
- package/lib/server/dispatchers/jsHandleDispatcher.js +63 -75
- package/lib/server/dispatchers/jsonPipeDispatcher.js +37 -38
- package/lib/server/dispatchers/localUtilsDispatcher.js +121 -119
- package/lib/server/dispatchers/networkDispatchers.js +117 -128
- package/lib/server/dispatchers/pageDispatcher.js +256 -248
- package/lib/server/dispatchers/playwrightDispatcher.js +92 -87
- package/lib/server/dispatchers/streamDispatcher.js +52 -48
- package/lib/server/dispatchers/tracingDispatcher.js +47 -52
- package/lib/server/dispatchers/webSocketRouteDispatcher.js +126 -150
- package/lib/server/dispatchers/writableStreamDispatcher.js +65 -43
- package/lib/server/dom.js +485 -582
- package/lib/server/download.js +47 -37
- package/lib/server/electron/electron.js +216 -243
- package/lib/server/electron/loader.js +9 -37
- package/lib/server/errors.js +47 -46
- package/lib/server/fetch.js +317 -360
- package/lib/server/fileChooser.js +25 -24
- package/lib/server/fileUploadUtils.js +66 -60
- package/lib/server/firefox/ffAccessibility.js +153 -131
- package/lib/server/firefox/ffBrowser.js +268 -305
- package/lib/server/firefox/ffConnection.js +63 -84
- package/lib/server/firefox/ffExecutionContext.js +92 -73
- package/lib/server/firefox/ffInput.js +82 -84
- package/lib/server/firefox/ffNetworkManager.js +137 -114
- package/lib/server/firefox/ffPage.js +261 -293
- package/lib/server/firefox/firefox.js +80 -72
- package/lib/server/firefox/protocol.d.js +16 -0
- package/lib/server/formData.js +107 -35
- package/lib/server/frameSelectors.js +98 -114
- package/lib/server/frames.js +845 -1055
- package/lib/server/har/harRecorder.js +85 -77
- package/lib/server/har/harTracer.js +290 -223
- package/lib/server/harBackend.js +80 -80
- package/lib/server/helper.js +55 -59
- package/lib/server/index.js +59 -99
- package/lib/server/input.js +151 -189
- package/lib/server/instrumentation.js +57 -44
- package/lib/server/javascript.js +133 -134
- package/lib/server/launchApp.js +113 -75
- package/lib/server/localUtils.js +150 -142
- package/lib/server/macEditingCommands.js +141 -137
- package/lib/server/network.js +299 -303
- package/lib/server/page.js +513 -544
- package/lib/server/pipeTransport.js +49 -45
- package/lib/server/playwright.js +58 -67
- package/lib/server/progress.js +137 -68
- package/lib/server/protocolError.js +34 -31
- package/lib/server/recorder/chat.js +70 -86
- package/lib/server/recorder/recorderApp.js +341 -176
- package/lib/server/recorder/recorderInTraceViewer.js +65 -94
- package/lib/server/recorder/recorderRunner.js +93 -116
- package/lib/server/recorder/recorderSignalProcessor.js +83 -0
- package/lib/server/recorder/recorderUtils.js +104 -47
- package/lib/server/recorder/throttledFile.js +42 -30
- package/lib/server/recorder.js +395 -275
- package/lib/server/registry/browserFetcher.js +106 -101
- package/lib/server/registry/dependencies.js +245 -196
- package/lib/server/registry/index.js +930 -803
- package/lib/server/registry/nativeDeps.js +1073 -464
- package/lib/server/registry/oopDownloadBrowserMain.js +57 -75
- package/lib/server/screenshotter.js +160 -191
- package/lib/server/selectors.js +90 -51
- package/lib/server/socksClientCertificatesInterceptor.js +171 -186
- package/lib/server/socksInterceptor.js +62 -70
- package/lib/server/trace/recorder/snapshotter.js +76 -102
- package/lib/server/trace/recorder/snapshotterInjected.js +238 -217
- package/lib/server/trace/recorder/tracing.js +354 -362
- package/lib/server/trace/test/inMemorySnapshotter.js +46 -52
- package/lib/server/trace/viewer/traceViewer.js +160 -147
- package/lib/server/transport.js +119 -134
- package/lib/server/types.js +26 -22
- package/lib/server/usKeyboardLayout.js +135 -545
- package/lib/server/utils/ascii.js +39 -26
- package/lib/server/utils/comparators.js +105 -103
- package/lib/server/utils/crypto.js +157 -112
- package/lib/server/utils/debug.js +36 -32
- package/lib/server/utils/debugLogger.js +77 -48
- package/lib/server/utils/env.js +52 -37
- package/lib/server/utils/eventsHelper.js +29 -28
- package/lib/server/utils/expectUtils.js +31 -26
- package/lib/server/utils/fileUtils.js +123 -136
- package/lib/server/utils/happyEyeballs.js +141 -126
- package/lib/server/utils/hostPlatform.js +84 -120
- package/lib/server/utils/httpServer.js +106 -121
- package/lib/server/utils/image_tools/colorUtils.js +42 -51
- package/lib/server/utils/image_tools/compare.js +44 -43
- package/lib/server/utils/image_tools/imageChannel.js +38 -30
- package/lib/server/utils/image_tools/stats.js +40 -40
- package/lib/server/utils/linuxUtils.js +50 -37
- package/lib/server/utils/network.js +152 -96
- package/lib/server/utils/nodePlatform.js +87 -79
- package/lib/server/utils/pipeTransport.js +44 -42
- package/lib/server/utils/processLauncher.js +111 -121
- package/lib/server/utils/profiler.js +52 -39
- package/lib/server/utils/socksProxy.js +280 -339
- package/lib/server/utils/spawnAsync.js +37 -41
- package/lib/server/utils/task.js +31 -38
- package/lib/server/utils/userAgent.js +73 -66
- package/lib/server/utils/wsServer.js +68 -75
- package/lib/server/utils/zipFile.js +36 -37
- package/lib/server/utils/zones.js +37 -34
- package/lib/server/webkit/protocol.d.js +16 -0
- package/lib/server/webkit/webkit.js +77 -61
- package/lib/server/webkit/wkAccessibility.js +161 -118
- package/lib/server/webkit/wkBrowser.js +193 -184
- package/lib/server/webkit/wkConnection.js +59 -83
- package/lib/server/webkit/wkExecutionContext.js +85 -70
- package/lib/server/webkit/wkInput.js +97 -95
- package/lib/server/webkit/wkInterceptableRequest.js +102 -95
- package/lib/server/webkit/wkPage.js +568 -667
- package/lib/server/webkit/wkProvisionalPage.js +45 -56
- package/lib/server/webkit/wkWorkers.js +79 -79
- package/lib/utils/expectUtils.js +31 -26
- package/lib/utils/isomorphic/ariaSnapshot.js +149 -152
- package/lib/utils/isomorphic/assert.js +28 -22
- package/lib/utils/isomorphic/colors.js +66 -59
- package/lib/utils/isomorphic/cssParser.js +120 -125
- package/lib/utils/isomorphic/cssTokenizer.js +436 -364
- package/lib/utils/isomorphic/headers.js +38 -37
- package/lib/utils/isomorphic/locatorGenerators.js +358 -357
- package/lib/utils/isomorphic/locatorParser.js +96 -105
- package/lib/utils/isomorphic/locatorUtils.js +63 -44
- package/lib/utils/isomorphic/manualPromise.js +46 -39
- package/lib/utils/isomorphic/mimeType.js +447 -25
- package/lib/utils/isomorphic/multimap.js +34 -27
- package/lib/utils/isomorphic/protocolFormatter.js +68 -0
- package/lib/utils/isomorphic/protocolMetainfo.js +321 -0
- package/lib/utils/isomorphic/recorderUtils.js +140 -181
- package/lib/utils/isomorphic/rtti.js +35 -33
- package/lib/utils/isomorphic/selectorParser.js +182 -193
- package/lib/utils/isomorphic/semaphore.js +27 -24
- package/lib/utils/isomorphic/stackTrace.js +87 -98
- package/lib/utils/isomorphic/stringUtils.js +98 -112
- package/lib/utils/isomorphic/time.js +46 -22
- package/lib/utils/isomorphic/timeoutRunner.js +53 -53
- package/lib/utils/isomorphic/traceUtils.js +37 -41
- package/lib/utils/isomorphic/types.js +15 -4
- package/lib/utils/isomorphic/urlMatch.js +113 -67
- package/lib/utils/isomorphic/utilityScriptSerializers.js +251 -0
- package/lib/utils.js +101 -443
- package/lib/utilsBundle.js +101 -52
- package/lib/utilsBundleImpl/index.js +160 -150
- package/lib/zipBundle.js +32 -23
- package/lib/zipBundleImpl.js +4 -4
- package/package.json +1 -1
- package/types/protocol.d.ts +1267 -1057
- package/types/types.d.ts +131 -29
- package/lib/common/socksProxy.js +0 -569
- package/lib/common/timeoutSettings.js +0 -73
- package/lib/common/types.js +0 -5
- package/lib/image_tools/colorUtils.js +0 -98
- package/lib/image_tools/compare.js +0 -108
- package/lib/image_tools/imageChannel.js +0 -70
- package/lib/image_tools/stats.js +0 -102
- package/lib/protocol/debug.js +0 -27
- package/lib/protocol/transport.js +0 -82
- package/lib/server/dispatchers/selectorsDispatcher.js +0 -36
- package/lib/server/isomorphic/utilityScriptSerializers.js +0 -229
- package/lib/server/recorder/contextRecorder.js +0 -290
- package/lib/server/recorder/recorderCollection.js +0 -104
- package/lib/server/recorder/recorderFrontend.js +0 -5
- package/lib/server/storageScript.js +0 -160
- package/lib/server/timeoutSettings.js +0 -74
- package/lib/third_party/diff_match_patch.js +0 -2222
- package/lib/utils/ascii.js +0 -31
- package/lib/utils/comparators.js +0 -171
- package/lib/utils/crypto.js +0 -174
- package/lib/utils/debug.js +0 -46
- package/lib/utils/debugLogger.js +0 -91
- package/lib/utils/env.js +0 -49
- package/lib/utils/eventsHelper.js +0 -38
- package/lib/utils/fileUtils.js +0 -205
- package/lib/utils/happy-eyeballs.js +0 -210
- package/lib/utils/headers.js +0 -52
- package/lib/utils/hostPlatform.js +0 -133
- package/lib/utils/httpServer.js +0 -237
- package/lib/utils/index.js +0 -368
- package/lib/utils/linuxUtils.js +0 -78
- package/lib/utils/manualPromise.js +0 -109
- package/lib/utils/multimap.js +0 -75
- package/lib/utils/network.js +0 -160
- package/lib/utils/processLauncher.js +0 -248
- package/lib/utils/profiler.js +0 -53
- package/lib/utils/rtti.js +0 -44
- package/lib/utils/semaphore.js +0 -51
- package/lib/utils/spawnAsync.js +0 -45
- package/lib/utils/stackTrace.js +0 -121
- package/lib/utils/task.js +0 -58
- package/lib/utils/time.js +0 -37
- package/lib/utils/timeoutRunner.js +0 -66
- package/lib/utils/traceUtils.js +0 -44
- package/lib/utils/userAgent.js +0 -105
- package/lib/utils/wsServer.js +0 -127
- package/lib/utils/zipFile.js +0 -75
- package/lib/utils/zones.js +0 -62
- package/lib/vite/htmlReport/index.html +0 -69
- package/lib/vite/recorder/assets/codeMirrorModule-B9YMkrwa.js +0 -24
- package/lib/vite/recorder/assets/codeMirrorModule-C3UTv-Ge.css +0 -1
- package/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
- package/lib/vite/recorder/assets/index-ELPgmkwA.js +0 -184
- package/lib/vite/recorder/assets/index-eHBmevrY.css +0 -1
- package/lib/vite/recorder/index.html +0 -29
- package/lib/vite/recorder/playwright-logo.svg +0 -9
- package/lib/vite/traceViewer/assets/codeMirrorModule-gU1OOCQO.js +0 -24
- package/lib/vite/traceViewer/assets/defaultSettingsView-B5n_FjMx.js +0 -1
- package/lib/vite/traceViewer/assets/inspectorTab-6Tru8Mn_.js +0 -235
- package/lib/vite/traceViewer/assets/workbench-B_Nj4NA2.js +0 -25
- package/lib/vite/traceViewer/assets/xtermModule-BoAIEibi.js +0 -9
- package/lib/vite/traceViewer/codeMirrorModule.C3UTv-Ge.css +0 -1
- package/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
- package/lib/vite/traceViewer/defaultSettingsView.CO3FR0CX.css +0 -1
- package/lib/vite/traceViewer/embedded.DpNPH6mk.js +0 -2
- package/lib/vite/traceViewer/embedded.html +0 -18
- package/lib/vite/traceViewer/embedded.mLhjB5IF.css +0 -1
- package/lib/vite/traceViewer/index.CFOW-Ezb.css +0 -1
- package/lib/vite/traceViewer/index.CuE3SYGw.js +0 -2
- package/lib/vite/traceViewer/index.html +0 -47
- package/lib/vite/traceViewer/inspectorTab.CXDulcFG.css +0 -1
- package/lib/vite/traceViewer/playwright-logo.svg +0 -9
- package/lib/vite/traceViewer/recorder.BD-uZJs7.js +0 -2
- package/lib/vite/traceViewer/recorder.html +0 -17
- package/lib/vite/traceViewer/recorder.tn0RQdqM.css +0 -0
- package/lib/vite/traceViewer/snapshot.html +0 -21
- package/lib/vite/traceViewer/sw.bundle.js +0 -3
- package/lib/vite/traceViewer/uiMode.BatfzHMG.css +0 -1
- package/lib/vite/traceViewer/uiMode.DHrNgddz.js +0 -5
- package/lib/vite/traceViewer/uiMode.html +0 -21
- package/lib/vite/traceViewer/workbench.B9vIAzH9.css +0 -1
- package/lib/vite/traceViewer/xtermModule.Beg8tuEN.css +0 -32
package/lib/server/fetch.js
CHANGED
|
@@ -1,64 +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
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
43
|
-
* See the License for the specific language governing permissions and
|
|
44
|
-
* limitations under the License.
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
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_utils = require("../utils");
|
|
42
|
+
var import_crypto = require("./utils/crypto");
|
|
43
|
+
var import_userAgent = require("./utils/userAgent");
|
|
44
|
+
var import_browserContext = require("./browserContext");
|
|
45
|
+
var import_cookieStore = require("./cookieStore");
|
|
46
|
+
var import_formData = require("./formData");
|
|
47
|
+
var import_instrumentation = require("./instrumentation");
|
|
48
|
+
var import_progress = require("./progress");
|
|
49
|
+
var import_socksClientCertificatesInterceptor = require("./socksClientCertificatesInterceptor");
|
|
50
|
+
var import_happyEyeballs = require("./utils/happyEyeballs");
|
|
51
|
+
var import_happyEyeballs2 = require("./utils/happyEyeballs");
|
|
52
|
+
var import_tracing = require("./trace/recorder/tracing");
|
|
53
|
+
var import_fetch = require("../checkly/fetch");
|
|
54
|
+
class APIRequestContext extends import_instrumentation.SdkObject {
|
|
55
|
+
constructor(parent) {
|
|
56
|
+
super(parent, "request-context");
|
|
57
|
+
this.fetchResponses = /* @__PURE__ */ new Map();
|
|
58
|
+
this.fetchLog = /* @__PURE__ */ new Map();
|
|
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
|
+
}
|
|
48
71
|
static findResponseBody(guid) {
|
|
49
72
|
for (const request of APIRequestContext.allInstances) {
|
|
50
73
|
const body = request.fetchResponses.get(guid);
|
|
51
|
-
if (body)
|
|
74
|
+
if (body)
|
|
75
|
+
return body;
|
|
52
76
|
}
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
constructor(parent) {
|
|
56
|
-
super(parent, 'request-context');
|
|
57
|
-
this.fetchResponses = new Map();
|
|
58
|
-
this.fetchLog = new Map();
|
|
59
|
-
this._activeProgressControllers = new Set();
|
|
60
|
-
this._closeReason = void 0;
|
|
61
|
-
APIRequestContext.allInstances.add(this);
|
|
77
|
+
return void 0;
|
|
62
78
|
}
|
|
63
79
|
_disposeImpl() {
|
|
64
80
|
APIRequestContext.allInstances.delete(this);
|
|
@@ -71,150 +87,155 @@ class APIRequestContext extends _instrumentation.SdkObject {
|
|
|
71
87
|
this.fetchLog.delete(fetchUid);
|
|
72
88
|
}
|
|
73
89
|
_storeResponseBody(body) {
|
|
74
|
-
const uid = (0,
|
|
90
|
+
const uid = (0, import_crypto.createGuid)();
|
|
75
91
|
this.fetchResponses.set(uid, body);
|
|
76
92
|
return uid;
|
|
77
93
|
}
|
|
78
|
-
async fetch(
|
|
79
|
-
var _params$method;
|
|
94
|
+
async fetch(progress, params) {
|
|
80
95
|
const defaults = this._defaultOptions();
|
|
81
96
|
const headers = {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
97
|
+
"user-agent": defaults.userAgent,
|
|
98
|
+
"accept": "*/*",
|
|
99
|
+
"accept-encoding": "gzip,deflate,br"
|
|
85
100
|
};
|
|
86
101
|
if (defaults.extraHTTPHeaders) {
|
|
87
|
-
for (const {
|
|
88
|
-
name,
|
|
89
|
-
value
|
|
90
|
-
} of defaults.extraHTTPHeaders) setHeader(headers, name, value);
|
|
102
|
+
for (const { name, value } of defaults.extraHTTPHeaders)
|
|
103
|
+
setHeader(headers, name, value);
|
|
91
104
|
}
|
|
92
105
|
if (params.headers) {
|
|
93
|
-
for (const {
|
|
94
|
-
name,
|
|
95
|
-
value
|
|
96
|
-
} of params.headers) setHeader(headers, name, value);
|
|
106
|
+
for (const { name, value } of params.headers)
|
|
107
|
+
setHeader(headers, name, value);
|
|
97
108
|
}
|
|
98
|
-
const requestUrl = new URL((0,
|
|
109
|
+
const requestUrl = new URL((0, import_utils.constructURLBasedOnBaseURL)(defaults.baseURL, params.url));
|
|
99
110
|
if (params.encodedParams) {
|
|
100
111
|
requestUrl.search = params.encodedParams;
|
|
101
112
|
} else if (params.params) {
|
|
102
|
-
for (const {
|
|
103
|
-
name,
|
|
104
|
-
value
|
|
105
|
-
} of params.params) requestUrl.searchParams.append(name, value);
|
|
113
|
+
for (const { name, value } of params.params)
|
|
114
|
+
requestUrl.searchParams.append(name, value);
|
|
106
115
|
}
|
|
107
116
|
const credentials = this._getHttpCredentials(requestUrl);
|
|
108
|
-
if (
|
|
109
|
-
|
|
117
|
+
if (credentials?.send === "always")
|
|
118
|
+
setBasicAuthorizationHeader(headers, credentials);
|
|
119
|
+
const method = params.method?.toUpperCase() || "GET";
|
|
110
120
|
const proxy = defaults.proxy;
|
|
111
121
|
let agent;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const deadline = timeout && (0, _utils.monotonicTime)() + timeout;
|
|
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;
|
|
117
126
|
const options = {
|
|
118
127
|
method,
|
|
119
128
|
headers,
|
|
120
129
|
agent,
|
|
121
|
-
maxRedirects
|
|
122
|
-
|
|
123
|
-
deadline,
|
|
124
|
-
...(0, _socksClientCertificatesInterceptor.getMatchingTLSOptionsForOrigin)(this._defaultOptions().clientCertificates, requestUrl.origin),
|
|
130
|
+
maxRedirects,
|
|
131
|
+
...(0, import_socksClientCertificatesInterceptor.getMatchingTLSOptionsForOrigin)(this._defaultOptions().clientCertificates, requestUrl.origin),
|
|
125
132
|
__testHookLookup: params.__testHookLookup,
|
|
133
|
+
// [Checkly]
|
|
134
|
+
// @ts-expect-error It's not part of default PW types.
|
|
126
135
|
tokenizedURL: params.tokenizedURL,
|
|
127
|
-
|
|
136
|
+
// [/Checkly]
|
|
137
|
+
...(0, import_fetch.getClientCertificates)(params)
|
|
128
138
|
};
|
|
129
|
-
|
|
130
|
-
|
|
139
|
+
if (params.ignoreHTTPSErrors || defaults.ignoreHTTPSErrors)
|
|
140
|
+
options.rejectUnauthorized = false;
|
|
131
141
|
const postData = serializePostData(params, headers);
|
|
132
|
-
if (postData)
|
|
133
|
-
|
|
134
|
-
const fetchResponse = await
|
|
135
|
-
return this._sendRequestWithRetries(progress, requestUrl, options, postData, params.maxRetries);
|
|
136
|
-
});
|
|
142
|
+
if (postData)
|
|
143
|
+
setHeader(headers, "content-length", String(postData.byteLength));
|
|
144
|
+
const fetchResponse = await this._sendRequestWithRetries(progress, requestUrl, options, postData, params.maxRetries);
|
|
137
145
|
const fetchUid = this._storeResponseBody(fetchResponse.body);
|
|
138
|
-
this.fetchLog.set(fetchUid,
|
|
139
|
-
const failOnStatusCode = params.failOnStatusCode !==
|
|
146
|
+
this.fetchLog.set(fetchUid, progress.metadata.log);
|
|
147
|
+
const failOnStatusCode = params.failOnStatusCode !== void 0 ? params.failOnStatusCode : !!defaults.failOnStatusCode;
|
|
140
148
|
if (failOnStatusCode && (fetchResponse.status < 200 || fetchResponse.status >= 400)) {
|
|
141
|
-
let responseText =
|
|
149
|
+
let responseText = "";
|
|
142
150
|
if (fetchResponse.body.byteLength) {
|
|
143
|
-
let text = fetchResponse.body.toString(
|
|
144
|
-
if (text.length >
|
|
145
|
-
|
|
151
|
+
let text = fetchResponse.body.toString("utf8");
|
|
152
|
+
if (text.length > 1e3)
|
|
153
|
+
text = text.substring(0, 997) + "...";
|
|
154
|
+
responseText = `
|
|
155
|
+
Response text:
|
|
156
|
+
${text}`;
|
|
146
157
|
}
|
|
147
158
|
throw new Error(`${fetchResponse.status} ${fetchResponse.statusText}${responseText}`);
|
|
148
159
|
}
|
|
149
160
|
return {
|
|
150
161
|
...fetchResponse,
|
|
151
162
|
fetchUid,
|
|
152
|
-
|
|
163
|
+
// [Checkly] Extra data we need for MS checks.
|
|
164
|
+
// @ts-expect-error It's not part of default PW types.
|
|
165
|
+
requestHeaders: (0, import_fetch.getRequestHeaders)(headers),
|
|
153
166
|
responseHeaders: fetchResponse.headers,
|
|
154
|
-
queryParams: (0,
|
|
167
|
+
queryParams: (0, import_fetch.parseQueryParameters)(fetchResponse.url),
|
|
168
|
+
// @ts-expect-error It's not part of default PW types.
|
|
155
169
|
url: params.tokenizedURL || fetchResponse.url,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
170
|
+
// @ts-expect-error It's not part of default PW types.
|
|
171
|
+
timings: (0, import_fetch.getTimings)(fetchResponse.timings),
|
|
172
|
+
requestBody: (0, import_fetch.getRequestBody)(postData, params.multipartData, options),
|
|
173
|
+
body: (0, import_fetch.getBody)(fetchResponse.body),
|
|
159
174
|
method: options.method
|
|
175
|
+
// [/Checkly]
|
|
160
176
|
};
|
|
161
177
|
}
|
|
162
178
|
_parseSetCookieHeader(responseUrl, setCookie) {
|
|
163
|
-
if (!setCookie)
|
|
179
|
+
if (!setCookie)
|
|
180
|
+
return [];
|
|
164
181
|
const url = new URL(responseUrl);
|
|
165
|
-
|
|
166
|
-
const defaultPath = '/' + url.pathname.substr(1).split('/').slice(0, -1).join('/');
|
|
182
|
+
const defaultPath = "/" + url.pathname.substr(1).split("/").slice(0, -1).join("/");
|
|
167
183
|
const cookies = [];
|
|
168
184
|
for (const header of setCookie) {
|
|
169
|
-
// Decode cookie value?
|
|
170
185
|
const cookie = parseCookie(header);
|
|
171
|
-
if (!cookie)
|
|
172
|
-
|
|
173
|
-
if (!cookie.domain)
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
186
|
+
if (!cookie)
|
|
187
|
+
continue;
|
|
188
|
+
if (!cookie.domain)
|
|
189
|
+
cookie.domain = url.hostname;
|
|
190
|
+
else
|
|
191
|
+
(0, import_utils.assert)(cookie.domain.startsWith(".") || !cookie.domain.includes("."));
|
|
192
|
+
if (!(0, import_cookieStore.domainMatches)(url.hostname, cookie.domain))
|
|
193
|
+
continue;
|
|
194
|
+
if (!cookie.path || !cookie.path.startsWith("/"))
|
|
195
|
+
cookie.path = defaultPath;
|
|
177
196
|
cookies.push(cookie);
|
|
178
197
|
}
|
|
179
198
|
return cookies;
|
|
180
199
|
}
|
|
181
|
-
async _updateRequestCookieHeader(url, headers) {
|
|
182
|
-
if (getHeader(headers,
|
|
183
|
-
|
|
200
|
+
async _updateRequestCookieHeader(progress, url, headers) {
|
|
201
|
+
if (getHeader(headers, "cookie") !== void 0)
|
|
202
|
+
return;
|
|
203
|
+
const contextCookies = await progress.race(this._cookies(url));
|
|
204
|
+
const cookies = contextCookies.filter((c) => new import_cookieStore.Cookie(c).matches(url));
|
|
184
205
|
if (cookies.length) {
|
|
185
|
-
const valueArray = cookies.map(c => `${c.name}=${c.value}`);
|
|
186
|
-
setHeader(headers,
|
|
206
|
+
const valueArray = cookies.map((c) => `${c.name}=${c.value}`);
|
|
207
|
+
setHeader(headers, "cookie", valueArray.join("; "));
|
|
187
208
|
}
|
|
188
209
|
}
|
|
189
210
|
async _sendRequestWithRetries(progress, url, options, postData, maxRetries) {
|
|
190
|
-
maxRetries
|
|
211
|
+
maxRetries ??= 0;
|
|
191
212
|
let backoff = 250;
|
|
192
213
|
for (let i = 0; i <= maxRetries; i++) {
|
|
193
214
|
try {
|
|
194
215
|
return await this._sendRequest(progress, url, options, postData);
|
|
195
216
|
} catch (e) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
217
|
+
if ((0, import_progress.isAbortError)(e))
|
|
218
|
+
throw e;
|
|
219
|
+
e = (0, import_socksClientCertificatesInterceptor.rewriteOpenSSLErrorIfNeeded)(e);
|
|
220
|
+
if (maxRetries === 0)
|
|
221
|
+
throw e;
|
|
222
|
+
if (i === maxRetries)
|
|
223
|
+
throw new Error(`Failed after ${i + 1} attempt(s): ${e}`);
|
|
224
|
+
if (e.code !== "ECONNRESET")
|
|
225
|
+
throw e;
|
|
201
226
|
progress.log(` Received ECONNRESET, will retry after ${backoff}ms.`);
|
|
202
|
-
await
|
|
227
|
+
await progress.wait(backoff);
|
|
203
228
|
backoff *= 2;
|
|
204
229
|
}
|
|
205
230
|
}
|
|
206
|
-
throw new Error(
|
|
231
|
+
throw new Error("Unreachable");
|
|
207
232
|
}
|
|
208
233
|
async _sendRequest(progress, url, options, postData) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
name,
|
|
215
|
-
value
|
|
216
|
-
};
|
|
217
|
-
})) || [];
|
|
234
|
+
await this._updateRequestCookieHeader(progress, url, options.headers);
|
|
235
|
+
const requestCookies = getHeader(options.headers, "cookie")?.split(";").map((p) => {
|
|
236
|
+
const [name, value] = p.split("=").map((v) => v.trim());
|
|
237
|
+
return { name, value };
|
|
238
|
+
}) || [];
|
|
218
239
|
const requestEvent = {
|
|
219
240
|
url,
|
|
220
241
|
method: options.method,
|
|
@@ -223,16 +244,12 @@ class APIRequestContext extends _instrumentation.SdkObject {
|
|
|
223
244
|
postData
|
|
224
245
|
};
|
|
225
246
|
this.emit(APIRequestContext.Events.Request, requestEvent);
|
|
226
|
-
|
|
227
|
-
const requestConstructor = (url.protocol ===
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
agent
|
|
233
|
-
};
|
|
234
|
-
const checklyTimings = (0, _fetch.initializeTimings)();
|
|
235
|
-
const startAt = (0, _utils.monotonicTime)();
|
|
247
|
+
const resultPromise = new Promise((fulfill, reject) => {
|
|
248
|
+
const requestConstructor = (url.protocol === "https:" ? import_https.default : import_http.default).request;
|
|
249
|
+
const agent = options.agent || (url.protocol === "https:" ? import_happyEyeballs2.httpsHappyEyeballsAgent : import_happyEyeballs2.httpHappyEyeballsAgent);
|
|
250
|
+
const requestOptions = { ...options, agent };
|
|
251
|
+
const checklyTimings = (0, import_fetch.initializeTimings)();
|
|
252
|
+
const startAt = (0, import_utils.monotonicTime)();
|
|
236
253
|
let reusedSocketAt;
|
|
237
254
|
let dnsLookupAt;
|
|
238
255
|
let tcpConnectionAt;
|
|
@@ -242,13 +259,12 @@ class APIRequestContext extends _instrumentation.SdkObject {
|
|
|
242
259
|
let serverPort;
|
|
243
260
|
let securityDetails;
|
|
244
261
|
const listeners = [];
|
|
245
|
-
const request = requestConstructor(url, requestOptions, async response => {
|
|
246
|
-
const responseAt = (0,
|
|
262
|
+
const request = requestConstructor(url, requestOptions, async (response) => {
|
|
263
|
+
const responseAt = (0, import_utils.monotonicTime)();
|
|
247
264
|
checklyTimings.values.response = performance.now() - checklyTimings.values.startTimeNow;
|
|
248
|
-
const notifyRequestFinished =
|
|
249
|
-
const endAt = (0,
|
|
250
|
-
|
|
251
|
-
const connectEnd = tlsHandshakeAt !== null && tlsHandshakeAt !== void 0 ? tlsHandshakeAt : tcpConnectionAt;
|
|
265
|
+
const notifyRequestFinished = (body2) => {
|
|
266
|
+
const endAt = (0, import_utils.monotonicTime)();
|
|
267
|
+
const connectEnd = tlsHandshakeAt ?? tcpConnectionAt;
|
|
252
268
|
const timings = {
|
|
253
269
|
send: requestFinishAt - startAt,
|
|
254
270
|
wait: responseAt - requestFinishAt,
|
|
@@ -263,11 +279,11 @@ class APIRequestContext extends _instrumentation.SdkObject {
|
|
|
263
279
|
requestEvent,
|
|
264
280
|
httpVersion: response.httpVersion,
|
|
265
281
|
statusCode: response.statusCode || 0,
|
|
266
|
-
statusMessage: response.statusMessage ||
|
|
282
|
+
statusMessage: response.statusMessage || "",
|
|
267
283
|
headers: response.headers,
|
|
268
284
|
rawHeaders: response.rawHeaders,
|
|
269
285
|
cookies,
|
|
270
|
-
body,
|
|
286
|
+
body: body2,
|
|
271
287
|
timings,
|
|
272
288
|
serverIPAddress,
|
|
273
289
|
serverPort,
|
|
@@ -275,36 +291,31 @@ class APIRequestContext extends _instrumentation.SdkObject {
|
|
|
275
291
|
};
|
|
276
292
|
this.emit(APIRequestContext.Events.RequestFinished, requestFinishedEvent);
|
|
277
293
|
};
|
|
278
|
-
progress.log(
|
|
279
|
-
for (const [name, value] of Object.entries(response.headers))
|
|
280
|
-
|
|
294
|
+
progress.log(`\u2190 ${response.statusCode} ${response.statusMessage}`);
|
|
295
|
+
for (const [name, value] of Object.entries(response.headers))
|
|
296
|
+
progress.log(` ${name}: ${value}`);
|
|
297
|
+
const cookies = this._parseSetCookieHeader(response.url || url.toString(), response.headers["set-cookie"]);
|
|
281
298
|
if (cookies.length) {
|
|
282
299
|
try {
|
|
283
300
|
await this._addCookies(cookies);
|
|
284
301
|
} catch (e) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
await Promise.all(cookies.map(c => this._addCookies([c]).catch(() => {})));
|
|
302
|
+
await Promise.all(cookies.map((c) => this._addCookies([c]).catch(() => {
|
|
303
|
+
})));
|
|
288
304
|
}
|
|
289
305
|
}
|
|
290
306
|
if (redirectStatus.includes(response.statusCode) && options.maxRedirects >= 0) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
reject(new Error('Max redirect count exceeded'));
|
|
307
|
+
if (options.maxRedirects === 0) {
|
|
308
|
+
reject(new Error("Max redirect count exceeded"));
|
|
294
309
|
request.destroy();
|
|
295
310
|
return;
|
|
296
311
|
}
|
|
297
|
-
const headers = {
|
|
298
|
-
...options.headers
|
|
299
|
-
};
|
|
312
|
+
const headers = { ...options.headers };
|
|
300
313
|
removeHeader(headers, `cookie`);
|
|
301
|
-
|
|
302
|
-
// HTTP-redirect fetch step 13 (https://fetch.spec.whatwg.org/#http-redirect-fetch)
|
|
303
314
|
const status = response.statusCode;
|
|
304
315
|
let method = options.method;
|
|
305
|
-
if ((status === 301 || status === 302) && method ===
|
|
306
|
-
method =
|
|
307
|
-
postData =
|
|
316
|
+
if ((status === 301 || status === 302) && method === "POST" || status === 303 && !["GET", "HEAD"].includes(method)) {
|
|
317
|
+
method = "GET";
|
|
318
|
+
postData = void 0;
|
|
308
319
|
removeHeader(headers, `content-encoding`);
|
|
309
320
|
removeHeader(headers, `content-language`);
|
|
310
321
|
removeHeader(headers, `content-length`);
|
|
@@ -316,18 +327,12 @@ class APIRequestContext extends _instrumentation.SdkObject {
|
|
|
316
327
|
headers,
|
|
317
328
|
agent: options.agent,
|
|
318
329
|
maxRedirects: options.maxRedirects - 1,
|
|
319
|
-
|
|
320
|
-
deadline: options.deadline,
|
|
321
|
-
...(0, _socksClientCertificatesInterceptor.getMatchingTLSOptionsForOrigin)(this._defaultOptions().clientCertificates, url.origin),
|
|
330
|
+
...(0, import_socksClientCertificatesInterceptor.getMatchingTLSOptionsForOrigin)(this._defaultOptions().clientCertificates, url.origin),
|
|
322
331
|
__testHookLookup: options.__testHookLookup
|
|
323
332
|
};
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
// HTTP-redirect fetch step 4: If locationURL is null, then return response.
|
|
328
|
-
// Best-effort UTF-8 decoding, per spec it's US-ASCII only, but browsers are more lenient.
|
|
329
|
-
// Node.js parses it as Latin1 via std::v8::String, so we convert it to UTF-8.
|
|
330
|
-
const locationHeaderValue = Buffer.from((_response$headers$loc = response.headers.location) !== null && _response$headers$loc !== void 0 ? _response$headers$loc : '', 'latin1').toString('utf8');
|
|
333
|
+
if (options.rejectUnauthorized === false)
|
|
334
|
+
redirectOptions.rejectUnauthorized = false;
|
|
335
|
+
const locationHeaderValue = Buffer.from(response.headers.location ?? "", "latin1").toString("utf8");
|
|
331
336
|
if (locationHeaderValue) {
|
|
332
337
|
let locationURL;
|
|
333
338
|
try {
|
|
@@ -337,17 +342,18 @@ class APIRequestContext extends _instrumentation.SdkObject {
|
|
|
337
342
|
request.destroy();
|
|
338
343
|
return;
|
|
339
344
|
}
|
|
340
|
-
if (headers[
|
|
345
|
+
if (headers["host"])
|
|
346
|
+
headers["host"] = locationURL.host;
|
|
341
347
|
notifyRequestFinished();
|
|
342
348
|
fulfill(this._sendRequest(progress, locationURL, redirectOptions, postData));
|
|
343
349
|
request.destroy();
|
|
344
350
|
return;
|
|
345
351
|
}
|
|
346
352
|
}
|
|
347
|
-
if (response.statusCode === 401 && !getHeader(options.headers,
|
|
348
|
-
const auth = response.headers[
|
|
353
|
+
if (response.statusCode === 401 && !getHeader(options.headers, "authorization")) {
|
|
354
|
+
const auth = response.headers["www-authenticate"];
|
|
349
355
|
const credentials = this._getHttpCredentials(url);
|
|
350
|
-
if (auth
|
|
356
|
+
if (auth?.trim().startsWith("Basic") && credentials) {
|
|
351
357
|
setBasicAuthorizationHeader(options.headers, credentials);
|
|
352
358
|
notifyRequestFinished();
|
|
353
359
|
fulfill(this._sendRequest(progress, url, options, postData));
|
|
@@ -355,138 +361,126 @@ class APIRequestContext extends _instrumentation.SdkObject {
|
|
|
355
361
|
return;
|
|
356
362
|
}
|
|
357
363
|
}
|
|
358
|
-
response.on(
|
|
364
|
+
response.on("aborted", () => reject(new Error("aborted")));
|
|
359
365
|
const chunks = [];
|
|
360
366
|
const notifyBodyFinished = () => {
|
|
361
367
|
checklyTimings.values.endAt = performance.now();
|
|
362
|
-
const
|
|
363
|
-
notifyRequestFinished(
|
|
368
|
+
const body2 = Buffer.concat(chunks);
|
|
369
|
+
notifyRequestFinished(body2);
|
|
364
370
|
fulfill({
|
|
365
371
|
url: response.url || url.toString(),
|
|
366
372
|
status: response.statusCode || 0,
|
|
367
|
-
statusText: response.statusMessage ||
|
|
373
|
+
statusText: response.statusMessage || "",
|
|
368
374
|
headers: toHeadersArray(response.rawHeaders),
|
|
369
|
-
body,
|
|
375
|
+
body: body2,
|
|
376
|
+
// [Checkly]
|
|
377
|
+
// @ts-expect-error We added API timings for each API call, we report them back from this sendRequest fn.
|
|
370
378
|
timings: {
|
|
371
379
|
// @ts-ignore
|
|
372
380
|
values: {
|
|
373
381
|
...checklyTimings.values,
|
|
374
|
-
...
|
|
382
|
+
...import_happyEyeballs.httpHappyEyeballsTimings.values
|
|
375
383
|
},
|
|
376
|
-
agent:
|
|
384
|
+
agent: import_happyEyeballs.httpHappyEyeballsTimings.agent || checklyTimings.agent
|
|
377
385
|
}
|
|
386
|
+
// [/Checkly]
|
|
378
387
|
});
|
|
379
388
|
};
|
|
380
389
|
let body = response;
|
|
381
390
|
let transform;
|
|
382
|
-
const encoding = response.headers[
|
|
383
|
-
if (encoding ===
|
|
391
|
+
const encoding = response.headers["content-encoding"];
|
|
392
|
+
if (encoding === "gzip" || encoding === "x-gzip") {
|
|
384
393
|
transform = zlib.createGunzip({
|
|
385
394
|
flush: zlib.constants.Z_SYNC_FLUSH,
|
|
386
395
|
finishFlush: zlib.constants.Z_SYNC_FLUSH
|
|
387
396
|
});
|
|
388
|
-
} else if (encoding ===
|
|
397
|
+
} else if (encoding === "br") {
|
|
389
398
|
transform = zlib.createBrotliDecompress({
|
|
390
399
|
flush: zlib.constants.BROTLI_OPERATION_FLUSH,
|
|
391
400
|
finishFlush: zlib.constants.BROTLI_OPERATION_FLUSH
|
|
392
401
|
});
|
|
393
|
-
} else if (encoding ===
|
|
402
|
+
} else if (encoding === "deflate") {
|
|
394
403
|
transform = zlib.createInflate();
|
|
395
404
|
}
|
|
396
405
|
if (transform) {
|
|
397
|
-
// Brotli and deflate decompressors throw if the input stream is empty.
|
|
398
406
|
const emptyStreamTransform = new SafeEmptyStreamTransform(notifyBodyFinished);
|
|
399
|
-
body = (0,
|
|
400
|
-
if (e)
|
|
407
|
+
body = (0, import_stream.pipeline)(response, emptyStreamTransform, transform, (e) => {
|
|
408
|
+
if (e)
|
|
409
|
+
reject(new Error(`failed to decompress '${encoding}' encoding: ${e.message}`));
|
|
401
410
|
});
|
|
402
|
-
body.on(
|
|
411
|
+
body.on("error", (e) => reject(new Error(`failed to decompress '${encoding}' encoding: ${e}`)));
|
|
403
412
|
} else {
|
|
404
|
-
body.on(
|
|
413
|
+
body.on("error", reject);
|
|
405
414
|
}
|
|
406
|
-
body.on(
|
|
407
|
-
body.on(
|
|
415
|
+
body.on("data", (chunk) => chunks.push(chunk));
|
|
416
|
+
body.on("end", notifyBodyFinished);
|
|
408
417
|
});
|
|
409
|
-
(0,
|
|
410
|
-
request.on(
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
418
|
+
(0, import_fetch.addRequestListeners)(request, checklyTimings, listeners);
|
|
419
|
+
request.on("error", reject);
|
|
420
|
+
progress.cleanupWhenAborted(() => request.destroy());
|
|
421
|
+
listeners.push(
|
|
422
|
+
import_utils.eventsHelper.addEventListener(this, APIRequestContext.Events.Dispose, () => {
|
|
423
|
+
reject(new Error("Request context disposed."));
|
|
424
|
+
request.destroy();
|
|
425
|
+
})
|
|
426
|
+
);
|
|
427
|
+
request.on("close", () => import_utils.eventsHelper.removeEventListeners(listeners));
|
|
428
|
+
request.on("socket", (socket) => {
|
|
417
429
|
if (request.reusedSocket) {
|
|
418
|
-
reusedSocketAt = (0,
|
|
430
|
+
reusedSocketAt = (0, import_utils.monotonicTime)();
|
|
419
431
|
return;
|
|
420
432
|
}
|
|
421
|
-
|
|
422
|
-
// happy eyeballs don't emit lookup and connect events, so we use our custom ones
|
|
423
|
-
const happyEyeBallsTimings = (0, _happyEyeballs.timingForSocket)(socket);
|
|
433
|
+
const happyEyeBallsTimings = (0, import_happyEyeballs2.timingForSocket)(socket);
|
|
424
434
|
dnsLookupAt = happyEyeBallsTimings.dnsLookupAt;
|
|
425
435
|
tcpConnectionAt = happyEyeBallsTimings.tcpConnectionAt;
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
436
|
+
listeners.push(
|
|
437
|
+
import_utils.eventsHelper.addEventListener(socket, "lookup", () => {
|
|
438
|
+
dnsLookupAt = (0, import_utils.monotonicTime)();
|
|
439
|
+
}),
|
|
440
|
+
import_utils.eventsHelper.addEventListener(socket, "connect", () => {
|
|
441
|
+
tcpConnectionAt = (0, import_utils.monotonicTime)();
|
|
442
|
+
}),
|
|
443
|
+
import_utils.eventsHelper.addEventListener(socket, "secureConnect", () => {
|
|
444
|
+
tlsHandshakeAt = (0, import_utils.monotonicTime)();
|
|
445
|
+
if (socket instanceof import_tls.TLSSocket) {
|
|
446
|
+
const peerCertificate = socket.getPeerCertificate();
|
|
447
|
+
securityDetails = {
|
|
448
|
+
protocol: socket.getProtocol() ?? void 0,
|
|
449
|
+
subjectName: peerCertificate.subject.CN,
|
|
450
|
+
validFrom: new Date(peerCertificate.valid_from).getTime() / 1e3,
|
|
451
|
+
validTo: new Date(peerCertificate.valid_to).getTime() / 1e3,
|
|
452
|
+
issuer: peerCertificate.issuer.CN
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
})
|
|
456
|
+
);
|
|
446
457
|
serverIPAddress = socket.remoteAddress;
|
|
447
458
|
serverPort = socket.remotePort;
|
|
448
459
|
});
|
|
449
|
-
request.on(
|
|
450
|
-
requestFinishAt = (0,
|
|
460
|
+
request.on("finish", () => {
|
|
461
|
+
requestFinishAt = (0, import_utils.monotonicTime)();
|
|
451
462
|
});
|
|
452
|
-
progress.log(
|
|
463
|
+
progress.log(`\u2192 ${options.method} ${url.toString()}`);
|
|
453
464
|
if (options.headers) {
|
|
454
|
-
for (const [name, value] of Object.entries(options.headers))
|
|
455
|
-
|
|
456
|
-
if (options.deadline) {
|
|
457
|
-
const rejectOnTimeout = () => {
|
|
458
|
-
reject(new Error(`Request timed out after ${options.timeout}ms`));
|
|
459
|
-
request.destroy();
|
|
460
|
-
};
|
|
461
|
-
const remaining = options.deadline - (0, _utils.monotonicTime)();
|
|
462
|
-
if (remaining <= 0) {
|
|
463
|
-
rejectOnTimeout();
|
|
464
|
-
return;
|
|
465
|
-
}
|
|
466
|
-
request.setTimeout(remaining, rejectOnTimeout);
|
|
465
|
+
for (const [name, value] of Object.entries(options.headers))
|
|
466
|
+
progress.log(` ${name}: ${value}`);
|
|
467
467
|
}
|
|
468
|
-
if (postData)
|
|
468
|
+
if (postData)
|
|
469
|
+
request.write(postData);
|
|
469
470
|
request.end();
|
|
470
471
|
});
|
|
472
|
+
return progress.race(resultPromise);
|
|
471
473
|
}
|
|
472
474
|
_getHttpCredentials(url) {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
return
|
|
475
|
+
if (!this._defaultOptions().httpCredentials?.origin || url.origin.toLowerCase() === this._defaultOptions().httpCredentials?.origin?.toLowerCase())
|
|
476
|
+
return this._defaultOptions().httpCredentials;
|
|
477
|
+
return void 0;
|
|
476
478
|
}
|
|
477
479
|
}
|
|
478
|
-
|
|
479
|
-
APIRequestContext.Events = {
|
|
480
|
-
Dispose: 'dispose',
|
|
481
|
-
Request: 'request',
|
|
482
|
-
RequestFinished: 'requestfinished'
|
|
483
|
-
};
|
|
484
|
-
APIRequestContext.allInstances = new Set();
|
|
485
|
-
class SafeEmptyStreamTransform extends _stream.Transform {
|
|
480
|
+
class SafeEmptyStreamTransform extends import_stream.Transform {
|
|
486
481
|
constructor(onEmptyStreamCallback) {
|
|
487
482
|
super();
|
|
488
483
|
this._receivedSomeData = false;
|
|
489
|
-
this._onEmptyStreamCallback = void 0;
|
|
490
484
|
this._onEmptyStreamCallback = onEmptyStreamCallback;
|
|
491
485
|
}
|
|
492
486
|
_transform(chunk, encoding, callback) {
|
|
@@ -494,15 +488,17 @@ class SafeEmptyStreamTransform extends _stream.Transform {
|
|
|
494
488
|
callback(null, chunk);
|
|
495
489
|
}
|
|
496
490
|
_flush(callback) {
|
|
497
|
-
if (this._receivedSomeData)
|
|
491
|
+
if (this._receivedSomeData)
|
|
492
|
+
callback(null);
|
|
493
|
+
else
|
|
494
|
+
this._onEmptyStreamCallback();
|
|
498
495
|
}
|
|
499
496
|
}
|
|
500
497
|
class BrowserContextAPIRequestContext extends APIRequestContext {
|
|
501
498
|
constructor(context) {
|
|
502
499
|
super(context);
|
|
503
|
-
this._context = void 0;
|
|
504
500
|
this._context = context;
|
|
505
|
-
context.once(
|
|
501
|
+
context.once(import_browserContext.BrowserContext.Events.Close, () => this._disposeImpl());
|
|
506
502
|
}
|
|
507
503
|
tracing() {
|
|
508
504
|
return this._context.tracing;
|
|
@@ -515,10 +511,9 @@ class BrowserContextAPIRequestContext extends APIRequestContext {
|
|
|
515
511
|
return {
|
|
516
512
|
userAgent: this._context._options.userAgent || this._context._browser.userAgent(),
|
|
517
513
|
extraHTTPHeaders: this._context._options.extraHTTPHeaders,
|
|
518
|
-
failOnStatusCode:
|
|
514
|
+
failOnStatusCode: void 0,
|
|
519
515
|
httpCredentials: this._context._options.httpCredentials,
|
|
520
516
|
proxy: this._context._options.proxy || this._context._browser.options.proxy,
|
|
521
|
-
timeoutSettings: this._context._timeoutSettings,
|
|
522
517
|
ignoreHTTPSErrors: this._context._options.ignoreHTTPSErrors,
|
|
523
518
|
baseURL: this._context._options.baseURL,
|
|
524
519
|
clientCertificates: this._context._options.clientCertificates
|
|
@@ -530,49 +525,32 @@ class BrowserContextAPIRequestContext extends APIRequestContext {
|
|
|
530
525
|
async _cookies(url) {
|
|
531
526
|
return await this._context.cookies(url.toString());
|
|
532
527
|
}
|
|
533
|
-
async storageState(indexedDB) {
|
|
534
|
-
return this._context.storageState(indexedDB);
|
|
528
|
+
async storageState(progress, indexedDB) {
|
|
529
|
+
return this._context.storageState(progress, indexedDB);
|
|
535
530
|
}
|
|
536
531
|
}
|
|
537
|
-
exports.BrowserContextAPIRequestContext = BrowserContextAPIRequestContext;
|
|
538
532
|
class GlobalAPIRequestContext extends APIRequestContext {
|
|
539
533
|
constructor(playwright, options) {
|
|
540
534
|
super(playwright);
|
|
541
|
-
this._cookieStore = new
|
|
542
|
-
this._options = void 0;
|
|
543
|
-
this._origins = void 0;
|
|
544
|
-
this._tracing = void 0;
|
|
535
|
+
this._cookieStore = new import_cookieStore.CookieStore();
|
|
545
536
|
this.attribution.context = this;
|
|
546
|
-
const timeoutSettings = new _timeoutSettings.TimeoutSettings();
|
|
547
|
-
if (options.timeout !== undefined) timeoutSettings.setDefaultTimeout(options.timeout);
|
|
548
|
-
const proxy = options.proxy;
|
|
549
|
-
if (proxy !== null && proxy !== void 0 && proxy.server) {
|
|
550
|
-
let url = proxy === null || proxy === void 0 ? void 0 : proxy.server.trim();
|
|
551
|
-
if (!/^\w+:\/\//.test(url)) url = 'http://' + url;
|
|
552
|
-
proxy.server = url;
|
|
553
|
-
if (options.clientCertificates) throw new Error('Cannot specify both proxy and clientCertificates');
|
|
554
|
-
}
|
|
555
537
|
if (options.storageState) {
|
|
556
|
-
|
|
557
|
-
this._origins = (_options$storageState = options.storageState.origins) === null || _options$storageState === void 0 ? void 0 : _options$storageState.map(origin => ({
|
|
558
|
-
indexedDB: [],
|
|
559
|
-
...origin
|
|
560
|
-
}));
|
|
538
|
+
this._origins = options.storageState.origins?.map((origin) => ({ indexedDB: [], ...origin }));
|
|
561
539
|
this._cookieStore.addCookies(options.storageState.cookies || []);
|
|
562
540
|
}
|
|
563
|
-
(0,
|
|
541
|
+
(0, import_browserContext.verifyClientCertificates)(options.clientCertificates);
|
|
564
542
|
this._options = {
|
|
565
543
|
baseURL: options.baseURL,
|
|
566
|
-
userAgent: options.userAgent || (0,
|
|
544
|
+
userAgent: options.userAgent || (0, import_userAgent.getUserAgent)(),
|
|
567
545
|
extraHTTPHeaders: options.extraHTTPHeaders,
|
|
568
546
|
failOnStatusCode: !!options.failOnStatusCode,
|
|
569
547
|
ignoreHTTPSErrors: !!options.ignoreHTTPSErrors,
|
|
548
|
+
maxRedirects: options.maxRedirects,
|
|
570
549
|
httpCredentials: options.httpCredentials,
|
|
571
550
|
clientCertificates: options.clientCertificates,
|
|
572
|
-
proxy
|
|
573
|
-
timeoutSettings
|
|
551
|
+
proxy: options.proxy
|
|
574
552
|
};
|
|
575
|
-
this._tracing = new
|
|
553
|
+
this._tracing = new import_tracing.Tracing(this, options.tracesDir);
|
|
576
554
|
}
|
|
577
555
|
tracing() {
|
|
578
556
|
return this._tracing;
|
|
@@ -592,107 +570,86 @@ class GlobalAPIRequestContext extends APIRequestContext {
|
|
|
592
570
|
async _cookies(url) {
|
|
593
571
|
return this._cookieStore.cookies(url);
|
|
594
572
|
}
|
|
595
|
-
async storageState(indexedDB = false) {
|
|
573
|
+
async storageState(progress, indexedDB = false) {
|
|
596
574
|
return {
|
|
597
575
|
cookies: this._cookieStore.allCookies(),
|
|
598
|
-
origins: (this._origins || []).map(origin => ({
|
|
599
|
-
...origin,
|
|
600
|
-
indexedDB: indexedDB ? origin.indexedDB : []
|
|
601
|
-
}))
|
|
576
|
+
origins: (this._origins || []).map((origin) => ({ ...origin, indexedDB: indexedDB ? origin.indexedDB : [] }))
|
|
602
577
|
};
|
|
603
578
|
}
|
|
604
579
|
}
|
|
605
|
-
exports.GlobalAPIRequestContext = GlobalAPIRequestContext;
|
|
606
|
-
function createProxyAgent(proxy) {
|
|
607
|
-
var _proxyOpts$protocol;
|
|
608
|
-
const proxyOpts = _url.default.parse(proxy.server);
|
|
609
|
-
if ((_proxyOpts$protocol = proxyOpts.protocol) !== null && _proxyOpts$protocol !== void 0 && _proxyOpts$protocol.startsWith('socks')) {
|
|
610
|
-
return new _utilsBundle.SocksProxyAgent({
|
|
611
|
-
host: proxyOpts.hostname,
|
|
612
|
-
port: proxyOpts.port || undefined
|
|
613
|
-
});
|
|
614
|
-
}
|
|
615
|
-
if (proxy.username) proxyOpts.auth = `${proxy.username}:${proxy.password || ''}`;
|
|
616
|
-
// TODO: We should use HttpProxyAgent conditional on proxyOpts.protocol instead of always using CONNECT method.
|
|
617
|
-
return new _utilsBundle.HttpsProxyAgent(proxyOpts);
|
|
618
|
-
}
|
|
619
580
|
function toHeadersArray(rawHeaders) {
|
|
620
581
|
const result = [];
|
|
621
|
-
for (let i = 0; i < rawHeaders.length; i += 2)
|
|
622
|
-
name: rawHeaders[i],
|
|
623
|
-
value: rawHeaders[i + 1]
|
|
624
|
-
});
|
|
582
|
+
for (let i = 0; i < rawHeaders.length; i += 2)
|
|
583
|
+
result.push({ name: rawHeaders[i], value: rawHeaders[i + 1] });
|
|
625
584
|
return result;
|
|
626
585
|
}
|
|
627
586
|
const redirectStatus = [301, 302, 303, 307, 308];
|
|
628
587
|
function parseCookie(header) {
|
|
629
|
-
const raw = (0,
|
|
630
|
-
if (!raw)
|
|
588
|
+
const raw = (0, import_cookieStore.parseRawCookie)(header);
|
|
589
|
+
if (!raw)
|
|
590
|
+
return null;
|
|
631
591
|
const cookie = {
|
|
632
|
-
domain:
|
|
633
|
-
path:
|
|
592
|
+
domain: "",
|
|
593
|
+
path: "",
|
|
634
594
|
expires: -1,
|
|
635
595
|
httpOnly: false,
|
|
636
596
|
secure: false,
|
|
637
597
|
// From https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
|
|
638
598
|
// The cookie-sending behavior if SameSite is not specified is SameSite=Lax.
|
|
639
|
-
sameSite:
|
|
599
|
+
sameSite: "Lax",
|
|
640
600
|
...raw
|
|
641
601
|
};
|
|
642
602
|
return cookie;
|
|
643
603
|
}
|
|
644
604
|
function serializePostData(params, headers) {
|
|
645
|
-
(0,
|
|
646
|
-
if (params.jsonData !==
|
|
647
|
-
setHeader(headers,
|
|
648
|
-
return Buffer.from(params.jsonData,
|
|
605
|
+
(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`);
|
|
606
|
+
if (params.jsonData !== void 0) {
|
|
607
|
+
setHeader(headers, "content-type", "application/json", true);
|
|
608
|
+
return Buffer.from(params.jsonData, "utf8");
|
|
649
609
|
} else if (params.formData) {
|
|
650
610
|
const searchParams = new URLSearchParams();
|
|
651
|
-
for (const {
|
|
652
|
-
name,
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
setHeader(headers, 'content-type', 'application/x-www-form-urlencoded', true);
|
|
656
|
-
return Buffer.from(searchParams.toString(), 'utf8');
|
|
611
|
+
for (const { name, value } of params.formData)
|
|
612
|
+
searchParams.append(name, value);
|
|
613
|
+
setHeader(headers, "content-type", "application/x-www-form-urlencoded", true);
|
|
614
|
+
return Buffer.from(searchParams.toString(), "utf8");
|
|
657
615
|
} else if (params.multipartData) {
|
|
658
|
-
const formData = new
|
|
616
|
+
const formData = new import_formData.MultipartFormData();
|
|
659
617
|
for (const field of params.multipartData) {
|
|
660
|
-
if (field.file)
|
|
618
|
+
if (field.file)
|
|
619
|
+
formData.addFileField(field.name, field.file);
|
|
620
|
+
else if (field.value)
|
|
621
|
+
formData.addField(field.name, field.value);
|
|
661
622
|
}
|
|
662
|
-
setHeader(headers,
|
|
623
|
+
setHeader(headers, "content-type", formData.contentTypeHeader(), true);
|
|
663
624
|
return formData.finish();
|
|
664
|
-
} else if (params.postData !==
|
|
665
|
-
setHeader(headers,
|
|
625
|
+
} else if (params.postData !== void 0) {
|
|
626
|
+
setHeader(headers, "content-type", "application/octet-stream", true);
|
|
666
627
|
return params.postData;
|
|
667
628
|
}
|
|
668
|
-
return
|
|
629
|
+
return void 0;
|
|
669
630
|
}
|
|
670
631
|
function setHeader(headers, name, value, keepExisting = false) {
|
|
671
|
-
const existing = Object.entries(headers).find(pair => pair[0].toLowerCase() === name.toLowerCase());
|
|
672
|
-
if (!existing)
|
|
632
|
+
const existing = Object.entries(headers).find((pair) => pair[0].toLowerCase() === name.toLowerCase());
|
|
633
|
+
if (!existing)
|
|
634
|
+
headers[name] = value;
|
|
635
|
+
else if (!keepExisting)
|
|
636
|
+
headers[existing[0]] = value;
|
|
673
637
|
}
|
|
674
638
|
function getHeader(headers, name) {
|
|
675
|
-
const existing = Object.entries(headers).find(pair => pair[0].toLowerCase() === name.toLowerCase());
|
|
676
|
-
return existing ? existing[1] :
|
|
639
|
+
const existing = Object.entries(headers).find((pair) => pair[0].toLowerCase() === name.toLowerCase());
|
|
640
|
+
return existing ? existing[1] : void 0;
|
|
677
641
|
}
|
|
678
642
|
function removeHeader(headers, name) {
|
|
679
643
|
delete headers[name];
|
|
680
644
|
}
|
|
681
|
-
function shouldBypassProxy(url, bypass) {
|
|
682
|
-
if (!bypass) return false;
|
|
683
|
-
const domains = bypass.split(',').map(s => {
|
|
684
|
-
s = s.trim();
|
|
685
|
-
if (!s.startsWith('.')) s = '.' + s;
|
|
686
|
-
return s;
|
|
687
|
-
});
|
|
688
|
-
const domain = '.' + url.hostname;
|
|
689
|
-
return domains.some(d => domain.endsWith(d));
|
|
690
|
-
}
|
|
691
645
|
function setBasicAuthorizationHeader(headers, credentials) {
|
|
692
|
-
const {
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
646
|
+
const { username, password } = credentials;
|
|
647
|
+
const encoded = Buffer.from(`${username || ""}:${password || ""}`).toString("base64");
|
|
648
|
+
setHeader(headers, "authorization", `Basic ${encoded}`);
|
|
649
|
+
}
|
|
650
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
651
|
+
0 && (module.exports = {
|
|
652
|
+
APIRequestContext,
|
|
653
|
+
BrowserContextAPIRequestContext,
|
|
654
|
+
GlobalAPIRequestContext
|
|
655
|
+
});
|