patchright-core 1.48.2
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/README.md +3 -0
- package/ThirdPartyNotices.txt +1548 -0
- package/bin/PrintDeps.exe +0 -0
- package/bin/README.md +2 -0
- package/bin/install_media_pack.ps1 +5 -0
- package/bin/reinstall_chrome_beta_linux.sh +40 -0
- package/bin/reinstall_chrome_beta_mac.sh +13 -0
- package/bin/reinstall_chrome_beta_win.ps1 +24 -0
- package/bin/reinstall_chrome_stable_linux.sh +40 -0
- package/bin/reinstall_chrome_stable_mac.sh +12 -0
- package/bin/reinstall_chrome_stable_win.ps1 +24 -0
- package/bin/reinstall_msedge_beta_linux.sh +40 -0
- package/bin/reinstall_msedge_beta_mac.sh +11 -0
- package/bin/reinstall_msedge_beta_win.ps1 +23 -0
- package/bin/reinstall_msedge_dev_linux.sh +40 -0
- package/bin/reinstall_msedge_dev_mac.sh +11 -0
- package/bin/reinstall_msedge_dev_win.ps1 +23 -0
- package/bin/reinstall_msedge_stable_linux.sh +40 -0
- package/bin/reinstall_msedge_stable_mac.sh +11 -0
- package/bin/reinstall_msedge_stable_win.ps1 +24 -0
- package/browsers.json +57 -0
- package/cli.js +18 -0
- package/index.d.ts +17 -0
- package/index.js +33 -0
- package/index.mjs +28 -0
- package/lib/androidServerImpl.js +69 -0
- package/lib/browserServerImpl.js +92 -0
- package/lib/cli/driver.js +95 -0
- package/lib/cli/program.js +589 -0
- package/lib/cli/programWithTestStub.js +67 -0
- package/lib/client/accessibility.js +50 -0
- package/lib/client/android.js +473 -0
- package/lib/client/api.js +285 -0
- package/lib/client/artifact.js +79 -0
- package/lib/client/browser.js +145 -0
- package/lib/client/browserContext.js +583 -0
- package/lib/client/browserType.js +241 -0
- package/lib/client/cdpSession.js +53 -0
- package/lib/client/channelOwner.js +235 -0
- package/lib/client/clientHelper.js +57 -0
- package/lib/client/clientInstrumentation.js +50 -0
- package/lib/client/clock.js +69 -0
- package/lib/client/connection.js +333 -0
- package/lib/client/consoleMessage.js +55 -0
- package/lib/client/coverage.js +41 -0
- package/lib/client/dialog.js +57 -0
- package/lib/client/download.js +62 -0
- package/lib/client/electron.js +135 -0
- package/lib/client/elementHandle.js +321 -0
- package/lib/client/errors.js +77 -0
- package/lib/client/eventEmitter.js +314 -0
- package/lib/client/events.js +94 -0
- package/lib/client/fetch.js +391 -0
- package/lib/client/fileChooser.js +45 -0
- package/lib/client/frame.js +504 -0
- package/lib/client/harRouter.js +99 -0
- package/lib/client/input.js +111 -0
- package/lib/client/jsHandle.js +121 -0
- package/lib/client/jsonPipe.js +35 -0
- package/lib/client/localUtils.js +36 -0
- package/lib/client/locator.js +441 -0
- package/lib/client/network.js +762 -0
- package/lib/client/page.js +770 -0
- package/lib/client/playwright.js +80 -0
- package/lib/client/selectors.js +67 -0
- package/lib/client/stream.js +54 -0
- package/lib/client/tracing.js +134 -0
- package/lib/client/types.js +24 -0
- package/lib/client/video.js +51 -0
- package/lib/client/waiter.js +158 -0
- package/lib/client/webError.js +37 -0
- package/lib/client/worker.js +71 -0
- package/lib/client/writableStream.js +54 -0
- package/lib/common/socksProxy.js +569 -0
- package/lib/common/timeoutSettings.js +73 -0
- package/lib/common/types.js +5 -0
- package/lib/generated/clockSource.js +7 -0
- package/lib/generated/consoleApiSource.js +7 -0
- package/lib/generated/injectedScriptSource.js +7 -0
- package/lib/generated/pollingRecorderSource.js +7 -0
- package/lib/generated/utilityScriptSource.js +7 -0
- package/lib/generated/webSocketMockSource.js +7 -0
- package/lib/image_tools/colorUtils.js +98 -0
- package/lib/image_tools/compare.js +108 -0
- package/lib/image_tools/imageChannel.js +70 -0
- package/lib/image_tools/stats.js +102 -0
- package/lib/inProcessFactory.js +54 -0
- package/lib/inprocess.js +20 -0
- package/lib/outofprocess.js +67 -0
- package/lib/protocol/debug.js +27 -0
- package/lib/protocol/serializers.js +173 -0
- package/lib/protocol/transport.js +82 -0
- package/lib/protocol/validator.js +2760 -0
- package/lib/protocol/validatorPrimitives.js +139 -0
- package/lib/remote/playwrightConnection.js +274 -0
- package/lib/remote/playwrightServer.js +110 -0
- package/lib/server/accessibility.js +62 -0
- package/lib/server/android/android.js +441 -0
- package/lib/server/android/backendAdb.js +172 -0
- package/lib/server/artifact.js +104 -0
- package/lib/server/bidi/bidiBrowser.js +311 -0
- package/lib/server/bidi/bidiChromium.js +124 -0
- package/lib/server/bidi/bidiConnection.js +206 -0
- package/lib/server/bidi/bidiExecutionContext.js +159 -0
- package/lib/server/bidi/bidiFirefox.js +104 -0
- package/lib/server/bidi/bidiInput.js +158 -0
- package/lib/server/bidi/bidiNetworkManager.js +338 -0
- package/lib/server/bidi/bidiOverCdp.js +103 -0
- package/lib/server/bidi/bidiPage.js +529 -0
- package/lib/server/bidi/bidiPdf.js +140 -0
- package/lib/server/bidi/third_party/bidiDeserializer.js +93 -0
- package/lib/server/bidi/third_party/bidiKeyboard.js +238 -0
- package/lib/server/bidi/third_party/bidiProtocol.js +139 -0
- package/lib/server/bidi/third_party/bidiSerializer.js +144 -0
- package/lib/server/bidi/third_party/firefoxPrefs.js +221 -0
- package/lib/server/browser.js +148 -0
- package/lib/server/browserContext.js +666 -0
- package/lib/server/browserType.js +335 -0
- package/lib/server/chromium/appIcon.png +0 -0
- package/lib/server/chromium/chromium.js +350 -0
- package/lib/server/chromium/chromiumSwitches.js +36 -0
- package/lib/server/chromium/crAccessibility.js +237 -0
- package/lib/server/chromium/crBrowser.js +522 -0
- package/lib/server/chromium/crConnection.js +228 -0
- package/lib/server/chromium/crCoverage.js +246 -0
- package/lib/server/chromium/crDevTools.js +104 -0
- package/lib/server/chromium/crDragDrop.js +143 -0
- package/lib/server/chromium/crExecutionContext.js +149 -0
- package/lib/server/chromium/crInput.js +171 -0
- package/lib/server/chromium/crNetworkManager.js +809 -0
- package/lib/server/chromium/crPage.js +1235 -0
- package/lib/server/chromium/crPdf.js +153 -0
- package/lib/server/chromium/crProtocolHelper.js +133 -0
- package/lib/server/chromium/crServiceWorker.js +111 -0
- package/lib/server/chromium/defaultFontFamilies.js +145 -0
- package/lib/server/chromium/videoRecorder.js +155 -0
- package/lib/server/clock.js +133 -0
- package/lib/server/codegen/csharp.js +299 -0
- package/lib/server/codegen/java.js +235 -0
- package/lib/server/codegen/javascript.js +223 -0
- package/lib/server/codegen/jsonl.js +47 -0
- package/lib/server/codegen/language.js +88 -0
- package/lib/server/codegen/languages.js +30 -0
- package/lib/server/codegen/python.js +265 -0
- package/lib/server/codegen/types.js +5 -0
- package/lib/server/console.js +57 -0
- package/lib/server/cookieStore.js +185 -0
- package/lib/server/debugController.js +234 -0
- package/lib/server/debugger.js +132 -0
- package/lib/server/deviceDescriptors.js +26 -0
- package/lib/server/deviceDescriptorsSource.json +1669 -0
- package/lib/server/dialog.js +71 -0
- package/lib/server/dispatchers/androidDispatcher.js +193 -0
- package/lib/server/dispatchers/artifactDispatcher.js +118 -0
- package/lib/server/dispatchers/browserContextDispatcher.js +368 -0
- package/lib/server/dispatchers/browserDispatcher.js +170 -0
- package/lib/server/dispatchers/browserTypeDispatcher.js +55 -0
- package/lib/server/dispatchers/cdpSessionDispatcher.js +48 -0
- package/lib/server/dispatchers/debugControllerDispatcher.js +103 -0
- package/lib/server/dispatchers/dialogDispatcher.js +44 -0
- package/lib/server/dispatchers/dispatcher.js +395 -0
- package/lib/server/dispatchers/electronDispatcher.js +93 -0
- package/lib/server/dispatchers/elementHandlerDispatcher.js +228 -0
- package/lib/server/dispatchers/frameDispatcher.js +286 -0
- package/lib/server/dispatchers/jsHandleDispatcher.js +97 -0
- package/lib/server/dispatchers/jsonPipeDispatcher.js +59 -0
- package/lib/server/dispatchers/localUtilsDispatcher.js +413 -0
- package/lib/server/dispatchers/networkDispatchers.js +221 -0
- package/lib/server/dispatchers/pageDispatcher.js +367 -0
- package/lib/server/dispatchers/playwrightDispatcher.js +107 -0
- package/lib/server/dispatchers/selectorsDispatcher.js +36 -0
- package/lib/server/dispatchers/streamDispatcher.js +62 -0
- package/lib/server/dispatchers/tracingDispatcher.js +54 -0
- package/lib/server/dispatchers/webSocketRouteDispatcher.js +189 -0
- package/lib/server/dispatchers/writableStreamDispatcher.js +58 -0
- package/lib/server/dom.js +845 -0
- package/lib/server/download.js +60 -0
- package/lib/server/electron/electron.js +296 -0
- package/lib/server/electron/loader.js +57 -0
- package/lib/server/errors.js +68 -0
- package/lib/server/fetch.js +656 -0
- package/lib/server/fileChooser.js +42 -0
- package/lib/server/fileUploadUtils.js +75 -0
- package/lib/server/firefox/ffAccessibility.js +216 -0
- package/lib/server/firefox/ffBrowser.js +460 -0
- package/lib/server/firefox/ffConnection.js +168 -0
- package/lib/server/firefox/ffExecutionContext.js +135 -0
- package/lib/server/firefox/ffInput.js +150 -0
- package/lib/server/firefox/ffNetworkManager.js +233 -0
- package/lib/server/firefox/ffPage.js +559 -0
- package/lib/server/firefox/firefox.js +99 -0
- package/lib/server/formData.js +75 -0
- package/lib/server/frameSelectors.js +171 -0
- package/lib/server/frames.js +1808 -0
- package/lib/server/har/harRecorder.js +139 -0
- package/lib/server/har/harTracer.js +542 -0
- package/lib/server/helper.js +103 -0
- package/lib/server/index.js +114 -0
- package/lib/server/input.js +310 -0
- package/lib/server/instrumentation.js +70 -0
- package/lib/server/isomorphic/utilityScriptSerializers.js +226 -0
- package/lib/server/javascript.js +299 -0
- package/lib/server/launchApp.js +91 -0
- package/lib/server/macEditingCommands.js +139 -0
- package/lib/server/network.js +617 -0
- package/lib/server/page.js +819 -0
- package/lib/server/pipeTransport.js +85 -0
- package/lib/server/playwright.js +88 -0
- package/lib/server/progress.js +102 -0
- package/lib/server/protocolError.js +49 -0
- package/lib/server/recorder/contextRecorder.js +299 -0
- package/lib/server/recorder/recorderApp.js +196 -0
- package/lib/server/recorder/recorderCollection.js +116 -0
- package/lib/server/recorder/recorderFrontend.js +5 -0
- package/lib/server/recorder/recorderInTraceViewer.js +144 -0
- package/lib/server/recorder/recorderRunner.js +155 -0
- package/lib/server/recorder/recorderUtils.js +112 -0
- package/lib/server/recorder/throttledFile.js +46 -0
- package/lib/server/recorder.js +329 -0
- package/lib/server/registry/browserFetcher.js +168 -0
- package/lib/server/registry/dependencies.js +322 -0
- package/lib/server/registry/index.js +1005 -0
- package/lib/server/registry/nativeDeps.js +490 -0
- package/lib/server/registry/oopDownloadBrowserMain.js +138 -0
- package/lib/server/screenshotter.js +348 -0
- package/lib/server/selectors.js +73 -0
- package/lib/server/socksClientCertificatesInterceptor.js +340 -0
- package/lib/server/socksInterceptor.js +100 -0
- package/lib/server/trace/recorder/snapshotter.js +172 -0
- package/lib/server/trace/recorder/snapshotterInjected.js +493 -0
- package/lib/server/trace/recorder/tracing.js +542 -0
- package/lib/server/trace/test/inMemorySnapshotter.js +93 -0
- package/lib/server/trace/viewer/traceViewer.js +213 -0
- package/lib/server/transport.js +191 -0
- package/lib/server/types.js +24 -0
- package/lib/server/usKeyboardLayout.js +555 -0
- package/lib/server/webkit/webkit.js +87 -0
- package/lib/server/webkit/wkAccessibility.js +194 -0
- package/lib/server/webkit/wkBrowser.js +329 -0
- package/lib/server/webkit/wkConnection.js +173 -0
- package/lib/server/webkit/wkExecutionContext.js +143 -0
- package/lib/server/webkit/wkInput.js +169 -0
- package/lib/server/webkit/wkInterceptableRequest.js +162 -0
- package/lib/server/webkit/wkPage.js +1219 -0
- package/lib/server/webkit/wkProvisionalPage.js +94 -0
- package/lib/server/webkit/wkWorkers.js +104 -0
- package/lib/third_party/diff_match_patch.js +2222 -0
- package/lib/third_party/pixelmatch.js +255 -0
- package/lib/utils/ascii.js +31 -0
- package/lib/utils/comparators.js +171 -0
- package/lib/utils/crypto.js +174 -0
- package/lib/utils/debug.js +46 -0
- package/lib/utils/debugLogger.js +91 -0
- package/lib/utils/env.js +49 -0
- package/lib/utils/eventsHelper.js +38 -0
- package/lib/utils/expectUtils.js +33 -0
- package/lib/utils/fileUtils.js +205 -0
- package/lib/utils/happy-eyeballs.js +194 -0
- package/lib/utils/headers.js +52 -0
- package/lib/utils/hostPlatform.js +133 -0
- package/lib/utils/httpServer.js +237 -0
- package/lib/utils/index.js +368 -0
- package/lib/utils/isomorphic/cssParser.js +250 -0
- package/lib/utils/isomorphic/cssTokenizer.js +979 -0
- package/lib/utils/isomorphic/locatorGenerators.js +642 -0
- package/lib/utils/isomorphic/locatorParser.js +179 -0
- package/lib/utils/isomorphic/locatorUtils.js +62 -0
- package/lib/utils/isomorphic/mimeType.js +29 -0
- package/lib/utils/isomorphic/recorderUtils.js +195 -0
- package/lib/utils/isomorphic/selectorParser.js +397 -0
- package/lib/utils/isomorphic/stringUtils.js +139 -0
- package/lib/utils/isomorphic/traceUtils.js +39 -0
- package/lib/utils/isomorphic/urlMatch.js +120 -0
- package/lib/utils/linuxUtils.js +78 -0
- package/lib/utils/manualPromise.js +109 -0
- package/lib/utils/multimap.js +75 -0
- package/lib/utils/network.js +160 -0
- package/lib/utils/processLauncher.js +248 -0
- package/lib/utils/profiler.js +53 -0
- package/lib/utils/rtti.js +44 -0
- package/lib/utils/semaphore.js +51 -0
- package/lib/utils/spawnAsync.js +45 -0
- package/lib/utils/stackTrace.js +121 -0
- package/lib/utils/task.js +58 -0
- package/lib/utils/time.js +37 -0
- package/lib/utils/timeoutRunner.js +66 -0
- package/lib/utils/traceUtils.js +44 -0
- package/lib/utils/userAgent.js +105 -0
- package/lib/utils/wsServer.js +127 -0
- package/lib/utils/zipFile.js +75 -0
- package/lib/utils/zones.js +62 -0
- package/lib/utilsBundle.js +82 -0
- package/lib/utilsBundleImpl/index.js +53 -0
- package/lib/utilsBundleImpl/xdg-open +1066 -0
- package/lib/vite/htmlReport/index.html +66 -0
- package/lib/vite/recorder/assets/codeMirrorModule-baozm8ur.js +24 -0
- package/lib/vite/recorder/assets/codeMirrorModule-ez37Vkbh.css +1 -0
- package/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
- package/lib/vite/recorder/assets/index-2ElAIWFB.js +42 -0
- package/lib/vite/recorder/assets/index-BW-aOBcL.css +1 -0
- package/lib/vite/recorder/index.html +29 -0
- package/lib/vite/recorder/playwright-logo.svg +9 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-Bh1rfd2w.js +24 -0
- package/lib/vite/traceViewer/assets/inspectorTab-7GHnKvSD.js +64 -0
- package/lib/vite/traceViewer/assets/testServerConnection-DeE2kSzz.js +1 -0
- package/lib/vite/traceViewer/assets/workbench-DPQnTHYP.js +9 -0
- package/lib/vite/traceViewer/assets/xtermModule-BeNbaIVa.js +9 -0
- package/lib/vite/traceViewer/codeMirrorModule.ez37Vkbh.css +1 -0
- package/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
- package/lib/vite/traceViewer/embedded.BlHoW5LY.js +2 -0
- package/lib/vite/traceViewer/embedded.html +18 -0
- package/lib/vite/traceViewer/embedded.w7WN2u1R.css +1 -0
- package/lib/vite/traceViewer/index.CrbWWHbf.css +1 -0
- package/lib/vite/traceViewer/index.DaWVfou1.js +2 -0
- package/lib/vite/traceViewer/index.html +29 -0
- package/lib/vite/traceViewer/inspectorTab.DLjBDrQR.css +1 -0
- package/lib/vite/traceViewer/playwright-logo.svg +9 -0
- package/lib/vite/traceViewer/recorder.B_SY1GJM.css +0 -0
- package/lib/vite/traceViewer/recorder.C4zxcvd2.js +2 -0
- package/lib/vite/traceViewer/recorder.html +17 -0
- package/lib/vite/traceViewer/snapshot.html +21 -0
- package/lib/vite/traceViewer/sw.bundle.js +3 -0
- package/lib/vite/traceViewer/uiMode.CAYqod-m.css +1 -0
- package/lib/vite/traceViewer/uiMode.html +20 -0
- package/lib/vite/traceViewer/uiMode.mTXWniJb.js +5 -0
- package/lib/vite/traceViewer/workbench.D3JVcA9K.css +1 -0
- package/lib/vite/traceViewer/xtermModule.DSXBckUd.css +32 -0
- package/lib/zipBundle.js +25 -0
- package/lib/zipBundleImpl.js +5 -0
- package/package.json +44 -0
- package/types/protocol.d.ts +21571 -0
- package/types/structs.d.ts +45 -0
- package/types/types.d.ts +22519 -0
|
@@ -0,0 +1,656 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.GlobalAPIRequestContext = exports.BrowserContextAPIRequestContext = exports.APIRequestContext = void 0;
|
|
7
|
+
exports.createProxyAgent = createProxyAgent;
|
|
8
|
+
var _http = _interopRequireDefault(require("http"));
|
|
9
|
+
var _https = _interopRequireDefault(require("https"));
|
|
10
|
+
var _stream = require("stream");
|
|
11
|
+
var _url = _interopRequireDefault(require("url"));
|
|
12
|
+
var _zlib = _interopRequireDefault(require("zlib"));
|
|
13
|
+
var _timeoutSettings = require("../common/timeoutSettings");
|
|
14
|
+
var _userAgent = require("../utils/userAgent");
|
|
15
|
+
var _utils = require("../utils");
|
|
16
|
+
var _utilsBundle = require("../utilsBundle");
|
|
17
|
+
var _browserContext = require("./browserContext");
|
|
18
|
+
var _cookieStore = require("./cookieStore");
|
|
19
|
+
var _formData = require("./formData");
|
|
20
|
+
var _happyEyeballs = require("../utils/happy-eyeballs");
|
|
21
|
+
var _instrumentation = require("./instrumentation");
|
|
22
|
+
var _progress = require("./progress");
|
|
23
|
+
var _tracing = require("./trace/recorder/tracing");
|
|
24
|
+
var _socksClientCertificatesInterceptor = require("./socksClientCertificatesInterceptor");
|
|
25
|
+
var _tls = require("tls");
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
+
/**
|
|
28
|
+
* Copyright (c) Microsoft Corporation.
|
|
29
|
+
*
|
|
30
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
31
|
+
* you may not use this file except in compliance with the License.
|
|
32
|
+
* You may obtain a copy of the License at
|
|
33
|
+
*
|
|
34
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
35
|
+
*
|
|
36
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
37
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
38
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
39
|
+
* See the License for the specific language governing permissions and
|
|
40
|
+
* limitations under the License.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
class APIRequestContext extends _instrumentation.SdkObject {
|
|
44
|
+
static findResponseBody(guid) {
|
|
45
|
+
for (const request of APIRequestContext.allInstances) {
|
|
46
|
+
const body = request.fetchResponses.get(guid);
|
|
47
|
+
if (body) return body;
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
constructor(parent) {
|
|
52
|
+
super(parent, 'request-context');
|
|
53
|
+
this.fetchResponses = new Map();
|
|
54
|
+
this.fetchLog = new Map();
|
|
55
|
+
this._activeProgressControllers = new Set();
|
|
56
|
+
this._closeReason = void 0;
|
|
57
|
+
APIRequestContext.allInstances.add(this);
|
|
58
|
+
}
|
|
59
|
+
_disposeImpl() {
|
|
60
|
+
APIRequestContext.allInstances.delete(this);
|
|
61
|
+
this.fetchResponses.clear();
|
|
62
|
+
this.fetchLog.clear();
|
|
63
|
+
this.emit(APIRequestContext.Events.Dispose);
|
|
64
|
+
}
|
|
65
|
+
disposeResponse(fetchUid) {
|
|
66
|
+
this.fetchResponses.delete(fetchUid);
|
|
67
|
+
this.fetchLog.delete(fetchUid);
|
|
68
|
+
}
|
|
69
|
+
_storeResponseBody(body) {
|
|
70
|
+
const uid = (0, _utils.createGuid)();
|
|
71
|
+
this.fetchResponses.set(uid, body);
|
|
72
|
+
return uid;
|
|
73
|
+
}
|
|
74
|
+
async fetch(params, metadata) {
|
|
75
|
+
var _params$method;
|
|
76
|
+
const defaults = this._defaultOptions();
|
|
77
|
+
const headers = {
|
|
78
|
+
'user-agent': defaults.userAgent,
|
|
79
|
+
'accept': '*/*',
|
|
80
|
+
'accept-encoding': 'gzip,deflate,br'
|
|
81
|
+
};
|
|
82
|
+
if (defaults.extraHTTPHeaders) {
|
|
83
|
+
for (const {
|
|
84
|
+
name,
|
|
85
|
+
value
|
|
86
|
+
} of defaults.extraHTTPHeaders) setHeader(headers, name, value);
|
|
87
|
+
}
|
|
88
|
+
if (params.headers) {
|
|
89
|
+
for (const {
|
|
90
|
+
name,
|
|
91
|
+
value
|
|
92
|
+
} of params.headers) setHeader(headers, name, value);
|
|
93
|
+
}
|
|
94
|
+
const requestUrl = new URL(params.url, defaults.baseURL);
|
|
95
|
+
if (params.encodedParams) {
|
|
96
|
+
requestUrl.search = params.encodedParams;
|
|
97
|
+
} else if (params.params) {
|
|
98
|
+
for (const {
|
|
99
|
+
name,
|
|
100
|
+
value
|
|
101
|
+
} of params.params) requestUrl.searchParams.append(name, value);
|
|
102
|
+
}
|
|
103
|
+
const credentials = this._getHttpCredentials(requestUrl);
|
|
104
|
+
if ((credentials === null || credentials === void 0 ? void 0 : credentials.send) === 'always') setBasicAuthorizationHeader(headers, credentials);
|
|
105
|
+
const method = ((_params$method = params.method) === null || _params$method === void 0 ? void 0 : _params$method.toUpperCase()) || 'GET';
|
|
106
|
+
const proxy = defaults.proxy;
|
|
107
|
+
let agent;
|
|
108
|
+
// We skip 'per-context' in order to not break existing users. 'per-context' was previously used to
|
|
109
|
+
// workaround an upstream Chromium bug. Can be removed in the future.
|
|
110
|
+
if (proxy && proxy.server !== 'per-context' && !shouldBypassProxy(requestUrl, proxy.bypass)) agent = createProxyAgent(proxy);
|
|
111
|
+
const timeout = defaults.timeoutSettings.timeout(params);
|
|
112
|
+
const deadline = timeout && (0, _utils.monotonicTime)() + timeout;
|
|
113
|
+
const options = {
|
|
114
|
+
method,
|
|
115
|
+
headers,
|
|
116
|
+
agent,
|
|
117
|
+
maxRedirects: params.maxRedirects === 0 ? -1 : params.maxRedirects === undefined ? 20 : params.maxRedirects,
|
|
118
|
+
timeout,
|
|
119
|
+
deadline,
|
|
120
|
+
...(0, _socksClientCertificatesInterceptor.getMatchingTLSOptionsForOrigin)(this._defaultOptions().clientCertificates, requestUrl.origin),
|
|
121
|
+
__testHookLookup: params.__testHookLookup
|
|
122
|
+
};
|
|
123
|
+
// rejectUnauthorized = undefined is treated as true in Node.js 12.
|
|
124
|
+
if (params.ignoreHTTPSErrors || defaults.ignoreHTTPSErrors) options.rejectUnauthorized = false;
|
|
125
|
+
const postData = serializePostData(params, headers);
|
|
126
|
+
if (postData) setHeader(headers, 'content-length', String(postData.byteLength));
|
|
127
|
+
const controller = new _progress.ProgressController(metadata, this);
|
|
128
|
+
const fetchResponse = await controller.run(progress => {
|
|
129
|
+
return this._sendRequestWithRetries(progress, requestUrl, options, postData, params.maxRetries);
|
|
130
|
+
});
|
|
131
|
+
const fetchUid = this._storeResponseBody(fetchResponse.body);
|
|
132
|
+
this.fetchLog.set(fetchUid, controller.metadata.log);
|
|
133
|
+
if (params.failOnStatusCode && (fetchResponse.status < 200 || fetchResponse.status >= 400)) {
|
|
134
|
+
let responseText = '';
|
|
135
|
+
if (fetchResponse.body.byteLength) {
|
|
136
|
+
let text = fetchResponse.body.toString('utf8');
|
|
137
|
+
if (text.length > 1000) text = text.substring(0, 997) + '...';
|
|
138
|
+
responseText = `\nResponse text:\n${text}`;
|
|
139
|
+
}
|
|
140
|
+
throw new Error(`${fetchResponse.status} ${fetchResponse.statusText}${responseText}`);
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
...fetchResponse,
|
|
144
|
+
fetchUid
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
_parseSetCookieHeader(responseUrl, setCookie) {
|
|
148
|
+
if (!setCookie) return [];
|
|
149
|
+
const url = new URL(responseUrl);
|
|
150
|
+
// https://datatracker.ietf.org/doc/html/rfc6265#section-5.1.4
|
|
151
|
+
const defaultPath = '/' + url.pathname.substr(1).split('/').slice(0, -1).join('/');
|
|
152
|
+
const cookies = [];
|
|
153
|
+
for (const header of setCookie) {
|
|
154
|
+
// Decode cookie value?
|
|
155
|
+
const cookie = parseCookie(header);
|
|
156
|
+
if (!cookie) continue;
|
|
157
|
+
// https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.3
|
|
158
|
+
if (!cookie.domain) cookie.domain = url.hostname;else (0, _utils.assert)(cookie.domain.startsWith('.') || !cookie.domain.includes('.'));
|
|
159
|
+
if (!(0, _cookieStore.domainMatches)(url.hostname, cookie.domain)) continue;
|
|
160
|
+
// https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.4
|
|
161
|
+
if (!cookie.path || !cookie.path.startsWith('/')) cookie.path = defaultPath;
|
|
162
|
+
cookies.push(cookie);
|
|
163
|
+
}
|
|
164
|
+
return cookies;
|
|
165
|
+
}
|
|
166
|
+
async _updateRequestCookieHeader(url, headers) {
|
|
167
|
+
if (getHeader(headers, 'cookie') !== undefined) return;
|
|
168
|
+
const cookies = await this._cookies(url);
|
|
169
|
+
if (cookies.length) {
|
|
170
|
+
const valueArray = cookies.map(c => `${c.name}=${c.value}`);
|
|
171
|
+
setHeader(headers, 'cookie', valueArray.join('; '));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async _sendRequestWithRetries(progress, url, options, postData, maxRetries) {
|
|
175
|
+
var _maxRetries;
|
|
176
|
+
(_maxRetries = maxRetries) !== null && _maxRetries !== void 0 ? _maxRetries : maxRetries = 0;
|
|
177
|
+
let backoff = 250;
|
|
178
|
+
for (let i = 0; i <= maxRetries; i++) {
|
|
179
|
+
try {
|
|
180
|
+
return await this._sendRequest(progress, url, options, postData);
|
|
181
|
+
} catch (e) {
|
|
182
|
+
e = (0, _socksClientCertificatesInterceptor.rewriteOpenSSLErrorIfNeeded)(e);
|
|
183
|
+
if (maxRetries === 0) throw e;
|
|
184
|
+
if (i === maxRetries || options.deadline && (0, _utils.monotonicTime)() + backoff > options.deadline) throw new Error(`Failed after ${i + 1} attempt(s): ${e}`);
|
|
185
|
+
// Retry on connection reset only.
|
|
186
|
+
if (e.code !== 'ECONNRESET') throw e;
|
|
187
|
+
progress.log(` Received ECONNRESET, will retry after ${backoff}ms.`);
|
|
188
|
+
await new Promise(f => setTimeout(f, backoff));
|
|
189
|
+
backoff *= 2;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
throw new Error('Unreachable');
|
|
193
|
+
}
|
|
194
|
+
async _sendRequest(progress, url, options, postData) {
|
|
195
|
+
var _getHeader;
|
|
196
|
+
await this._updateRequestCookieHeader(url, options.headers);
|
|
197
|
+
const requestCookies = ((_getHeader = getHeader(options.headers, 'cookie')) === null || _getHeader === void 0 ? void 0 : _getHeader.split(';').map(p => {
|
|
198
|
+
const [name, value] = p.split('=').map(v => v.trim());
|
|
199
|
+
return {
|
|
200
|
+
name,
|
|
201
|
+
value
|
|
202
|
+
};
|
|
203
|
+
})) || [];
|
|
204
|
+
const requestEvent = {
|
|
205
|
+
url,
|
|
206
|
+
method: options.method,
|
|
207
|
+
headers: options.headers,
|
|
208
|
+
cookies: requestCookies,
|
|
209
|
+
postData
|
|
210
|
+
};
|
|
211
|
+
this.emit(APIRequestContext.Events.Request, requestEvent);
|
|
212
|
+
return new Promise((fulfill, reject) => {
|
|
213
|
+
const requestConstructor = (url.protocol === 'https:' ? _https.default : _http.default).request;
|
|
214
|
+
// If we have a proxy agent already, do not override it.
|
|
215
|
+
const agent = options.agent || (url.protocol === 'https:' ? _happyEyeballs.httpsHappyEyeballsAgent : _happyEyeballs.httpHappyEyeballsAgent);
|
|
216
|
+
const requestOptions = {
|
|
217
|
+
...options,
|
|
218
|
+
agent
|
|
219
|
+
};
|
|
220
|
+
const startAt = (0, _utils.monotonicTime)();
|
|
221
|
+
let dnsLookupAt;
|
|
222
|
+
let tcpConnectionAt;
|
|
223
|
+
let tlsHandshakeAt;
|
|
224
|
+
let requestFinishAt;
|
|
225
|
+
let serverIPAddress;
|
|
226
|
+
let serverPort;
|
|
227
|
+
let securityDetails;
|
|
228
|
+
const listeners = [];
|
|
229
|
+
const request = requestConstructor(url, requestOptions, async response => {
|
|
230
|
+
const responseAt = (0, _utils.monotonicTime)();
|
|
231
|
+
const notifyRequestFinished = body => {
|
|
232
|
+
var _tlsHandshakeAt;
|
|
233
|
+
const endAt = (0, _utils.monotonicTime)();
|
|
234
|
+
// spec: http://www.softwareishard.com/blog/har-12-spec/#timings
|
|
235
|
+
const timings = {
|
|
236
|
+
send: requestFinishAt - startAt,
|
|
237
|
+
wait: responseAt - requestFinishAt,
|
|
238
|
+
receive: endAt - responseAt,
|
|
239
|
+
dns: dnsLookupAt ? dnsLookupAt - startAt : -1,
|
|
240
|
+
connect: ((_tlsHandshakeAt = tlsHandshakeAt) !== null && _tlsHandshakeAt !== void 0 ? _tlsHandshakeAt : tcpConnectionAt) - startAt,
|
|
241
|
+
// "If [ssl] is defined then the time is also included in the connect field "
|
|
242
|
+
ssl: tlsHandshakeAt ? tlsHandshakeAt - tcpConnectionAt : -1,
|
|
243
|
+
blocked: -1
|
|
244
|
+
};
|
|
245
|
+
const requestFinishedEvent = {
|
|
246
|
+
requestEvent,
|
|
247
|
+
httpVersion: response.httpVersion,
|
|
248
|
+
statusCode: response.statusCode || 0,
|
|
249
|
+
statusMessage: response.statusMessage || '',
|
|
250
|
+
headers: response.headers,
|
|
251
|
+
rawHeaders: response.rawHeaders,
|
|
252
|
+
cookies,
|
|
253
|
+
body,
|
|
254
|
+
timings,
|
|
255
|
+
serverIPAddress,
|
|
256
|
+
serverPort,
|
|
257
|
+
securityDetails
|
|
258
|
+
};
|
|
259
|
+
this.emit(APIRequestContext.Events.RequestFinished, requestFinishedEvent);
|
|
260
|
+
};
|
|
261
|
+
progress.log(`← ${response.statusCode} ${response.statusMessage}`);
|
|
262
|
+
for (const [name, value] of Object.entries(response.headers)) progress.log(` ${name}: ${value}`);
|
|
263
|
+
const cookies = this._parseSetCookieHeader(response.url || url.toString(), response.headers['set-cookie']);
|
|
264
|
+
if (cookies.length) {
|
|
265
|
+
try {
|
|
266
|
+
await this._addCookies(cookies);
|
|
267
|
+
} catch (e) {
|
|
268
|
+
// Cookie value is limited by 4096 characters in the browsers. If setCookies failed,
|
|
269
|
+
// we try setting each cookie individually just in case only some of them are bad.
|
|
270
|
+
await Promise.all(cookies.map(c => this._addCookies([c]).catch(() => {})));
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (redirectStatus.includes(response.statusCode) && options.maxRedirects >= 0) {
|
|
274
|
+
var _response$headers$loc;
|
|
275
|
+
if (!options.maxRedirects) {
|
|
276
|
+
reject(new Error('Max redirect count exceeded'));
|
|
277
|
+
request.destroy();
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const headers = {
|
|
281
|
+
...options.headers
|
|
282
|
+
};
|
|
283
|
+
removeHeader(headers, `cookie`);
|
|
284
|
+
|
|
285
|
+
// HTTP-redirect fetch step 13 (https://fetch.spec.whatwg.org/#http-redirect-fetch)
|
|
286
|
+
const status = response.statusCode;
|
|
287
|
+
let method = options.method;
|
|
288
|
+
if ((status === 301 || status === 302) && method === 'POST' || status === 303 && !['GET', 'HEAD'].includes(method)) {
|
|
289
|
+
method = 'GET';
|
|
290
|
+
postData = undefined;
|
|
291
|
+
removeHeader(headers, `content-encoding`);
|
|
292
|
+
removeHeader(headers, `content-language`);
|
|
293
|
+
removeHeader(headers, `content-length`);
|
|
294
|
+
removeHeader(headers, `content-location`);
|
|
295
|
+
removeHeader(headers, `content-type`);
|
|
296
|
+
}
|
|
297
|
+
const redirectOptions = {
|
|
298
|
+
method,
|
|
299
|
+
headers,
|
|
300
|
+
agent: options.agent,
|
|
301
|
+
maxRedirects: options.maxRedirects - 1,
|
|
302
|
+
timeout: options.timeout,
|
|
303
|
+
deadline: options.deadline,
|
|
304
|
+
...(0, _socksClientCertificatesInterceptor.getMatchingTLSOptionsForOrigin)(this._defaultOptions().clientCertificates, url.origin),
|
|
305
|
+
__testHookLookup: options.__testHookLookup
|
|
306
|
+
};
|
|
307
|
+
// rejectUnauthorized = undefined is treated as true in node 12.
|
|
308
|
+
if (options.rejectUnauthorized === false) redirectOptions.rejectUnauthorized = false;
|
|
309
|
+
|
|
310
|
+
// HTTP-redirect fetch step 4: If locationURL is null, then return response.
|
|
311
|
+
// Best-effort UTF-8 decoding, per spec it's US-ASCII only, but browsers are more lenient.
|
|
312
|
+
// Node.js parses it as Latin1 via std::v8::String, so we convert it to UTF-8.
|
|
313
|
+
const locationHeaderValue = Buffer.from((_response$headers$loc = response.headers.location) !== null && _response$headers$loc !== void 0 ? _response$headers$loc : '', 'latin1').toString('utf8');
|
|
314
|
+
if (locationHeaderValue) {
|
|
315
|
+
let locationURL;
|
|
316
|
+
try {
|
|
317
|
+
locationURL = new URL(locationHeaderValue, url);
|
|
318
|
+
} catch (error) {
|
|
319
|
+
reject(new Error(`uri requested responds with an invalid redirect URL: ${locationHeaderValue}`));
|
|
320
|
+
request.destroy();
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (headers['host']) headers['host'] = locationURL.host;
|
|
324
|
+
notifyRequestFinished();
|
|
325
|
+
fulfill(this._sendRequest(progress, locationURL, redirectOptions, postData));
|
|
326
|
+
request.destroy();
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (response.statusCode === 401 && !getHeader(options.headers, 'authorization')) {
|
|
331
|
+
const auth = response.headers['www-authenticate'];
|
|
332
|
+
const credentials = this._getHttpCredentials(url);
|
|
333
|
+
if (auth !== null && auth !== void 0 && auth.trim().startsWith('Basic') && credentials) {
|
|
334
|
+
setBasicAuthorizationHeader(options.headers, credentials);
|
|
335
|
+
notifyRequestFinished();
|
|
336
|
+
fulfill(this._sendRequest(progress, url, options, postData));
|
|
337
|
+
request.destroy();
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
response.on('aborted', () => reject(new Error('aborted')));
|
|
342
|
+
const chunks = [];
|
|
343
|
+
const notifyBodyFinished = () => {
|
|
344
|
+
const body = Buffer.concat(chunks);
|
|
345
|
+
notifyRequestFinished(body);
|
|
346
|
+
fulfill({
|
|
347
|
+
url: response.url || url.toString(),
|
|
348
|
+
status: response.statusCode || 0,
|
|
349
|
+
statusText: response.statusMessage || '',
|
|
350
|
+
headers: toHeadersArray(response.rawHeaders),
|
|
351
|
+
body
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
let body = response;
|
|
355
|
+
let transform;
|
|
356
|
+
const encoding = response.headers['content-encoding'];
|
|
357
|
+
if (encoding === 'gzip' || encoding === 'x-gzip') {
|
|
358
|
+
transform = _zlib.default.createGunzip({
|
|
359
|
+
flush: _zlib.default.constants.Z_SYNC_FLUSH,
|
|
360
|
+
finishFlush: _zlib.default.constants.Z_SYNC_FLUSH
|
|
361
|
+
});
|
|
362
|
+
} else if (encoding === 'br') {
|
|
363
|
+
transform = _zlib.default.createBrotliDecompress({
|
|
364
|
+
flush: _zlib.default.constants.BROTLI_OPERATION_FLUSH,
|
|
365
|
+
finishFlush: _zlib.default.constants.BROTLI_OPERATION_FLUSH
|
|
366
|
+
});
|
|
367
|
+
} else if (encoding === 'deflate') {
|
|
368
|
+
transform = _zlib.default.createInflate();
|
|
369
|
+
}
|
|
370
|
+
if (transform) {
|
|
371
|
+
// Brotli and deflate decompressors throw if the input stream is empty.
|
|
372
|
+
const emptyStreamTransform = new SafeEmptyStreamTransform(notifyBodyFinished);
|
|
373
|
+
body = (0, _stream.pipeline)(response, emptyStreamTransform, transform, e => {
|
|
374
|
+
if (e) reject(new Error(`failed to decompress '${encoding}' encoding: ${e.message}`));
|
|
375
|
+
});
|
|
376
|
+
body.on('error', e => reject(new Error(`failed to decompress '${encoding}' encoding: ${e}`)));
|
|
377
|
+
} else {
|
|
378
|
+
body.on('error', reject);
|
|
379
|
+
}
|
|
380
|
+
body.on('data', chunk => chunks.push(chunk));
|
|
381
|
+
body.on('end', notifyBodyFinished);
|
|
382
|
+
});
|
|
383
|
+
request.on('error', reject);
|
|
384
|
+
listeners.push(_utils.eventsHelper.addEventListener(this, APIRequestContext.Events.Dispose, () => {
|
|
385
|
+
reject(new Error('Request context disposed.'));
|
|
386
|
+
request.destroy();
|
|
387
|
+
}));
|
|
388
|
+
request.on('close', () => _utils.eventsHelper.removeEventListeners(listeners));
|
|
389
|
+
request.on('socket', socket => {
|
|
390
|
+
// happy eyeballs don't emit lookup and connect events, so we use our custom ones
|
|
391
|
+
const happyEyeBallsTimings = (0, _happyEyeballs.timingForSocket)(socket);
|
|
392
|
+
dnsLookupAt = happyEyeBallsTimings.dnsLookupAt;
|
|
393
|
+
tcpConnectionAt = happyEyeBallsTimings.tcpConnectionAt;
|
|
394
|
+
|
|
395
|
+
// non-happy-eyeballs sockets
|
|
396
|
+
listeners.push(_utils.eventsHelper.addEventListener(socket, 'lookup', () => {
|
|
397
|
+
dnsLookupAt = (0, _utils.monotonicTime)();
|
|
398
|
+
}), _utils.eventsHelper.addEventListener(socket, 'connect', () => {
|
|
399
|
+
tcpConnectionAt = (0, _utils.monotonicTime)();
|
|
400
|
+
}), _utils.eventsHelper.addEventListener(socket, 'secureConnect', () => {
|
|
401
|
+
tlsHandshakeAt = (0, _utils.monotonicTime)();
|
|
402
|
+
if (socket instanceof _tls.TLSSocket) {
|
|
403
|
+
var _socket$getProtocol;
|
|
404
|
+
const peerCertificate = socket.getPeerCertificate();
|
|
405
|
+
securityDetails = {
|
|
406
|
+
protocol: (_socket$getProtocol = socket.getProtocol()) !== null && _socket$getProtocol !== void 0 ? _socket$getProtocol : undefined,
|
|
407
|
+
subjectName: peerCertificate.subject.CN,
|
|
408
|
+
validFrom: new Date(peerCertificate.valid_from).getTime() / 1000,
|
|
409
|
+
validTo: new Date(peerCertificate.valid_to).getTime() / 1000,
|
|
410
|
+
issuer: peerCertificate.issuer.CN
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
}));
|
|
414
|
+
serverIPAddress = socket.remoteAddress;
|
|
415
|
+
serverPort = socket.remotePort;
|
|
416
|
+
});
|
|
417
|
+
request.on('finish', () => {
|
|
418
|
+
requestFinishAt = (0, _utils.monotonicTime)();
|
|
419
|
+
});
|
|
420
|
+
progress.log(`→ ${options.method} ${url.toString()}`);
|
|
421
|
+
if (options.headers) {
|
|
422
|
+
for (const [name, value] of Object.entries(options.headers)) progress.log(` ${name}: ${value}`);
|
|
423
|
+
}
|
|
424
|
+
if (options.deadline) {
|
|
425
|
+
const rejectOnTimeout = () => {
|
|
426
|
+
reject(new Error(`Request timed out after ${options.timeout}ms`));
|
|
427
|
+
request.destroy();
|
|
428
|
+
};
|
|
429
|
+
const remaining = options.deadline - (0, _utils.monotonicTime)();
|
|
430
|
+
if (remaining <= 0) {
|
|
431
|
+
rejectOnTimeout();
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
request.setTimeout(remaining, rejectOnTimeout);
|
|
435
|
+
}
|
|
436
|
+
if (postData) request.write(postData);
|
|
437
|
+
request.end();
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
_getHttpCredentials(url) {
|
|
441
|
+
var _this$_defaultOptions, _this$_defaultOptions2;
|
|
442
|
+
if (!((_this$_defaultOptions = this._defaultOptions().httpCredentials) !== null && _this$_defaultOptions !== void 0 && _this$_defaultOptions.origin) || url.origin.toLowerCase() === ((_this$_defaultOptions2 = this._defaultOptions().httpCredentials) === null || _this$_defaultOptions2 === void 0 || (_this$_defaultOptions2 = _this$_defaultOptions2.origin) === null || _this$_defaultOptions2 === void 0 ? void 0 : _this$_defaultOptions2.toLowerCase())) return this._defaultOptions().httpCredentials;
|
|
443
|
+
return undefined;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
exports.APIRequestContext = APIRequestContext;
|
|
447
|
+
APIRequestContext.Events = {
|
|
448
|
+
Dispose: 'dispose',
|
|
449
|
+
Request: 'request',
|
|
450
|
+
RequestFinished: 'requestfinished'
|
|
451
|
+
};
|
|
452
|
+
APIRequestContext.allInstances = new Set();
|
|
453
|
+
class SafeEmptyStreamTransform extends _stream.Transform {
|
|
454
|
+
constructor(onEmptyStreamCallback) {
|
|
455
|
+
super();
|
|
456
|
+
this._receivedSomeData = false;
|
|
457
|
+
this._onEmptyStreamCallback = void 0;
|
|
458
|
+
this._onEmptyStreamCallback = onEmptyStreamCallback;
|
|
459
|
+
}
|
|
460
|
+
_transform(chunk, encoding, callback) {
|
|
461
|
+
this._receivedSomeData = true;
|
|
462
|
+
callback(null, chunk);
|
|
463
|
+
}
|
|
464
|
+
_flush(callback) {
|
|
465
|
+
if (this._receivedSomeData) callback(null);else this._onEmptyStreamCallback();
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
class BrowserContextAPIRequestContext extends APIRequestContext {
|
|
469
|
+
constructor(context) {
|
|
470
|
+
super(context);
|
|
471
|
+
this._context = void 0;
|
|
472
|
+
this._context = context;
|
|
473
|
+
context.once(_browserContext.BrowserContext.Events.Close, () => this._disposeImpl());
|
|
474
|
+
}
|
|
475
|
+
tracing() {
|
|
476
|
+
return this._context.tracing;
|
|
477
|
+
}
|
|
478
|
+
async dispose(options) {
|
|
479
|
+
this._closeReason = options.reason;
|
|
480
|
+
this.fetchResponses.clear();
|
|
481
|
+
}
|
|
482
|
+
_defaultOptions() {
|
|
483
|
+
return {
|
|
484
|
+
userAgent: this._context._options.userAgent || this._context._browser.userAgent(),
|
|
485
|
+
extraHTTPHeaders: this._context._options.extraHTTPHeaders,
|
|
486
|
+
httpCredentials: this._context._options.httpCredentials,
|
|
487
|
+
proxy: this._context._options.proxy || this._context._browser.options.proxy,
|
|
488
|
+
timeoutSettings: this._context._timeoutSettings,
|
|
489
|
+
ignoreHTTPSErrors: this._context._options.ignoreHTTPSErrors,
|
|
490
|
+
baseURL: this._context._options.baseURL,
|
|
491
|
+
clientCertificates: this._context._options.clientCertificates
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
async _addCookies(cookies) {
|
|
495
|
+
await this._context.addCookies(cookies);
|
|
496
|
+
}
|
|
497
|
+
async _cookies(url) {
|
|
498
|
+
return await this._context.cookies(url.toString());
|
|
499
|
+
}
|
|
500
|
+
async storageState() {
|
|
501
|
+
return this._context.storageState();
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
exports.BrowserContextAPIRequestContext = BrowserContextAPIRequestContext;
|
|
505
|
+
class GlobalAPIRequestContext extends APIRequestContext {
|
|
506
|
+
constructor(playwright, options) {
|
|
507
|
+
super(playwright);
|
|
508
|
+
this._cookieStore = new _cookieStore.CookieStore();
|
|
509
|
+
this._options = void 0;
|
|
510
|
+
this._origins = void 0;
|
|
511
|
+
this._tracing = void 0;
|
|
512
|
+
this.attribution.context = this;
|
|
513
|
+
const timeoutSettings = new _timeoutSettings.TimeoutSettings();
|
|
514
|
+
if (options.timeout !== undefined) timeoutSettings.setDefaultTimeout(options.timeout);
|
|
515
|
+
const proxy = options.proxy;
|
|
516
|
+
if (proxy !== null && proxy !== void 0 && proxy.server) {
|
|
517
|
+
let url = proxy === null || proxy === void 0 ? void 0 : proxy.server.trim();
|
|
518
|
+
if (!/^\w+:\/\//.test(url)) url = 'http://' + url;
|
|
519
|
+
proxy.server = url;
|
|
520
|
+
}
|
|
521
|
+
if (options.storageState) {
|
|
522
|
+
this._origins = options.storageState.origins;
|
|
523
|
+
this._cookieStore.addCookies(options.storageState.cookies || []);
|
|
524
|
+
}
|
|
525
|
+
(0, _browserContext.verifyClientCertificates)(options.clientCertificates);
|
|
526
|
+
this._options = {
|
|
527
|
+
baseURL: options.baseURL,
|
|
528
|
+
userAgent: options.userAgent || (0, _userAgent.getUserAgent)(),
|
|
529
|
+
extraHTTPHeaders: options.extraHTTPHeaders,
|
|
530
|
+
ignoreHTTPSErrors: !!options.ignoreHTTPSErrors,
|
|
531
|
+
httpCredentials: options.httpCredentials,
|
|
532
|
+
clientCertificates: options.clientCertificates,
|
|
533
|
+
proxy,
|
|
534
|
+
timeoutSettings
|
|
535
|
+
};
|
|
536
|
+
this._tracing = new _tracing.Tracing(this, options.tracesDir);
|
|
537
|
+
}
|
|
538
|
+
tracing() {
|
|
539
|
+
return this._tracing;
|
|
540
|
+
}
|
|
541
|
+
async dispose(options) {
|
|
542
|
+
this._closeReason = options.reason;
|
|
543
|
+
await this._tracing.flush();
|
|
544
|
+
await this._tracing.deleteTmpTracesDir();
|
|
545
|
+
this._disposeImpl();
|
|
546
|
+
}
|
|
547
|
+
_defaultOptions() {
|
|
548
|
+
return this._options;
|
|
549
|
+
}
|
|
550
|
+
async _addCookies(cookies) {
|
|
551
|
+
this._cookieStore.addCookies(cookies);
|
|
552
|
+
}
|
|
553
|
+
async _cookies(url) {
|
|
554
|
+
return this._cookieStore.cookies(url);
|
|
555
|
+
}
|
|
556
|
+
async storageState() {
|
|
557
|
+
return {
|
|
558
|
+
cookies: this._cookieStore.allCookies(),
|
|
559
|
+
origins: this._origins || []
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
exports.GlobalAPIRequestContext = GlobalAPIRequestContext;
|
|
564
|
+
function createProxyAgent(proxy) {
|
|
565
|
+
var _proxyOpts$protocol;
|
|
566
|
+
const proxyOpts = _url.default.parse(proxy.server);
|
|
567
|
+
if ((_proxyOpts$protocol = proxyOpts.protocol) !== null && _proxyOpts$protocol !== void 0 && _proxyOpts$protocol.startsWith('socks')) {
|
|
568
|
+
return new _utilsBundle.SocksProxyAgent({
|
|
569
|
+
host: proxyOpts.hostname,
|
|
570
|
+
port: proxyOpts.port || undefined
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
if (proxy.username) proxyOpts.auth = `${proxy.username}:${proxy.password || ''}`;
|
|
574
|
+
// TODO: We should use HttpProxyAgent conditional on proxyOpts.protocol instead of always using CONNECT method.
|
|
575
|
+
return new _utilsBundle.HttpsProxyAgent(proxyOpts);
|
|
576
|
+
}
|
|
577
|
+
function toHeadersArray(rawHeaders) {
|
|
578
|
+
const result = [];
|
|
579
|
+
for (let i = 0; i < rawHeaders.length; i += 2) result.push({
|
|
580
|
+
name: rawHeaders[i],
|
|
581
|
+
value: rawHeaders[i + 1]
|
|
582
|
+
});
|
|
583
|
+
return result;
|
|
584
|
+
}
|
|
585
|
+
const redirectStatus = [301, 302, 303, 307, 308];
|
|
586
|
+
function parseCookie(header) {
|
|
587
|
+
const raw = (0, _cookieStore.parseRawCookie)(header);
|
|
588
|
+
if (!raw) return null;
|
|
589
|
+
const cookie = {
|
|
590
|
+
domain: '',
|
|
591
|
+
path: '',
|
|
592
|
+
expires: -1,
|
|
593
|
+
httpOnly: false,
|
|
594
|
+
secure: false,
|
|
595
|
+
// From https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
|
|
596
|
+
// The cookie-sending behavior if SameSite is not specified is SameSite=Lax.
|
|
597
|
+
sameSite: 'Lax',
|
|
598
|
+
...raw
|
|
599
|
+
};
|
|
600
|
+
return cookie;
|
|
601
|
+
}
|
|
602
|
+
function serializePostData(params, headers) {
|
|
603
|
+
(0, _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`);
|
|
604
|
+
if (params.jsonData !== undefined) {
|
|
605
|
+
setHeader(headers, 'content-type', 'application/json', true);
|
|
606
|
+
return Buffer.from(params.jsonData, 'utf8');
|
|
607
|
+
} else if (params.formData) {
|
|
608
|
+
const searchParams = new URLSearchParams();
|
|
609
|
+
for (const {
|
|
610
|
+
name,
|
|
611
|
+
value
|
|
612
|
+
} of params.formData) searchParams.append(name, value);
|
|
613
|
+
setHeader(headers, 'content-type', 'application/x-www-form-urlencoded', true);
|
|
614
|
+
return Buffer.from(searchParams.toString(), 'utf8');
|
|
615
|
+
} else if (params.multipartData) {
|
|
616
|
+
const formData = new _formData.MultipartFormData();
|
|
617
|
+
for (const field of params.multipartData) {
|
|
618
|
+
if (field.file) formData.addFileField(field.name, field.file);else if (field.value) formData.addField(field.name, field.value);
|
|
619
|
+
}
|
|
620
|
+
setHeader(headers, 'content-type', formData.contentTypeHeader(), true);
|
|
621
|
+
return formData.finish();
|
|
622
|
+
} else if (params.postData !== undefined) {
|
|
623
|
+
setHeader(headers, 'content-type', 'application/octet-stream', true);
|
|
624
|
+
return params.postData;
|
|
625
|
+
}
|
|
626
|
+
return undefined;
|
|
627
|
+
}
|
|
628
|
+
function setHeader(headers, name, value, keepExisting = false) {
|
|
629
|
+
const existing = Object.entries(headers).find(pair => pair[0].toLowerCase() === name.toLowerCase());
|
|
630
|
+
if (!existing) headers[name] = value;else if (!keepExisting) headers[existing[0]] = value;
|
|
631
|
+
}
|
|
632
|
+
function getHeader(headers, name) {
|
|
633
|
+
const existing = Object.entries(headers).find(pair => pair[0].toLowerCase() === name.toLowerCase());
|
|
634
|
+
return existing ? existing[1] : undefined;
|
|
635
|
+
}
|
|
636
|
+
function removeHeader(headers, name) {
|
|
637
|
+
delete headers[name];
|
|
638
|
+
}
|
|
639
|
+
function shouldBypassProxy(url, bypass) {
|
|
640
|
+
if (!bypass) return false;
|
|
641
|
+
const domains = bypass.split(',').map(s => {
|
|
642
|
+
s = s.trim();
|
|
643
|
+
if (!s.startsWith('.')) s = '.' + s;
|
|
644
|
+
return s;
|
|
645
|
+
});
|
|
646
|
+
const domain = '.' + url.hostname;
|
|
647
|
+
return domains.some(d => domain.endsWith(d));
|
|
648
|
+
}
|
|
649
|
+
function setBasicAuthorizationHeader(headers, credentials) {
|
|
650
|
+
const {
|
|
651
|
+
username,
|
|
652
|
+
password
|
|
653
|
+
} = credentials;
|
|
654
|
+
const encoded = Buffer.from(`${username || ''}:${password || ''}`).toString('base64');
|
|
655
|
+
setHeader(headers, 'authorization', `Basic ${encoded}`);
|
|
656
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FileChooser = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) Microsoft Corporation.
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License.
|
|
12
|
+
* You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
class FileChooser {
|
|
24
|
+
constructor(page, elementHandle, isMultiple) {
|
|
25
|
+
this._page = void 0;
|
|
26
|
+
this._elementHandle = void 0;
|
|
27
|
+
this._isMultiple = void 0;
|
|
28
|
+
this._page = page;
|
|
29
|
+
this._elementHandle = elementHandle;
|
|
30
|
+
this._isMultiple = isMultiple;
|
|
31
|
+
}
|
|
32
|
+
element() {
|
|
33
|
+
return this._elementHandle;
|
|
34
|
+
}
|
|
35
|
+
isMultiple() {
|
|
36
|
+
return this._isMultiple;
|
|
37
|
+
}
|
|
38
|
+
page() {
|
|
39
|
+
return this._page;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.FileChooser = FileChooser;
|