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,340 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ClientCertificatesProxy = void 0;
|
|
7
|
+
exports.getMatchingTLSOptionsForOrigin = getMatchingTLSOptionsForOrigin;
|
|
8
|
+
exports.rewriteOpenSSLErrorIfNeeded = rewriteOpenSSLErrorIfNeeded;
|
|
9
|
+
var _net = _interopRequireDefault(require("net"));
|
|
10
|
+
var _http = _interopRequireDefault(require("http2"));
|
|
11
|
+
var _tls = _interopRequireDefault(require("tls"));
|
|
12
|
+
var _stream = _interopRequireDefault(require("stream"));
|
|
13
|
+
var _happyEyeballs = require("../utils/happy-eyeballs");
|
|
14
|
+
var _utils = require("../utils");
|
|
15
|
+
var _socksProxy = require("../common/socksProxy");
|
|
16
|
+
var _debugLogger = require("../utils/debugLogger");
|
|
17
|
+
var _fetch = require("./fetch");
|
|
18
|
+
var _events = require("events");
|
|
19
|
+
var _browserContext = require("./browserContext");
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
/**
|
|
22
|
+
* Copyright (c) Microsoft Corporation.
|
|
23
|
+
*
|
|
24
|
+
* Licensed under the Apache License, Version 2.0 (the 'License");
|
|
25
|
+
* you may not use this file except in compliance with the License.
|
|
26
|
+
* You may obtain a copy of the License at
|
|
27
|
+
*
|
|
28
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
29
|
+
*
|
|
30
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
31
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
32
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
33
|
+
* See the License for the specific language governing permissions and
|
|
34
|
+
* limitations under the License.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
let dummyServerTlsOptions = undefined;
|
|
38
|
+
function loadDummyServerCertsIfNeeded() {
|
|
39
|
+
if (dummyServerTlsOptions) return;
|
|
40
|
+
const {
|
|
41
|
+
cert,
|
|
42
|
+
key
|
|
43
|
+
} = (0, _utils.generateSelfSignedCertificate)();
|
|
44
|
+
dummyServerTlsOptions = {
|
|
45
|
+
key,
|
|
46
|
+
cert
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
class ALPNCache {
|
|
50
|
+
constructor() {
|
|
51
|
+
this._cache = new Map();
|
|
52
|
+
}
|
|
53
|
+
get(host, port, success) {
|
|
54
|
+
const cacheKey = `${host}:${port}`;
|
|
55
|
+
{
|
|
56
|
+
const result = this._cache.get(cacheKey);
|
|
57
|
+
if (result) {
|
|
58
|
+
result.then(success);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const result = new _utils.ManualPromise();
|
|
63
|
+
this._cache.set(cacheKey, result);
|
|
64
|
+
result.then(success);
|
|
65
|
+
(0, _happyEyeballs.createTLSSocket)({
|
|
66
|
+
host,
|
|
67
|
+
port,
|
|
68
|
+
servername: _net.default.isIP(host) ? undefined : host,
|
|
69
|
+
ALPNProtocols: ['h2', 'http/1.1'],
|
|
70
|
+
rejectUnauthorized: false
|
|
71
|
+
}).then(socket => {
|
|
72
|
+
// The server may not respond with ALPN, in which case we default to http/1.1.
|
|
73
|
+
result.resolve(socket.alpnProtocol || 'http/1.1');
|
|
74
|
+
socket.end();
|
|
75
|
+
}).catch(error => {
|
|
76
|
+
_debugLogger.debugLogger.log('client-certificates', `ALPN error: ${error.message}`);
|
|
77
|
+
result.resolve('http/1.1');
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
class SocksProxyConnection {
|
|
82
|
+
constructor(socksProxy, uid, host, port) {
|
|
83
|
+
this.socksProxy = void 0;
|
|
84
|
+
this.uid = void 0;
|
|
85
|
+
this.host = void 0;
|
|
86
|
+
this.port = void 0;
|
|
87
|
+
this.firstPackageReceived = false;
|
|
88
|
+
this.target = void 0;
|
|
89
|
+
// In case of http, we just pipe data to the target socket and they are |undefined|.
|
|
90
|
+
this.internal = void 0;
|
|
91
|
+
this.internalTLS = void 0;
|
|
92
|
+
this._targetCloseEventListener = void 0;
|
|
93
|
+
this._dummyServer = void 0;
|
|
94
|
+
this._closed = false;
|
|
95
|
+
this.socksProxy = socksProxy;
|
|
96
|
+
this.uid = uid;
|
|
97
|
+
this.host = host;
|
|
98
|
+
this.port = port;
|
|
99
|
+
this._targetCloseEventListener = () => {
|
|
100
|
+
var _this$internalTLS, _this$_dummyServer;
|
|
101
|
+
// Close the other end and cleanup TLS resources.
|
|
102
|
+
this.socksProxy._socksProxy.sendSocketEnd({
|
|
103
|
+
uid: this.uid
|
|
104
|
+
});
|
|
105
|
+
(_this$internalTLS = this.internalTLS) === null || _this$internalTLS === void 0 || _this$internalTLS.destroy();
|
|
106
|
+
(_this$_dummyServer = this._dummyServer) === null || _this$_dummyServer === void 0 || _this$_dummyServer.close();
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
async connect() {
|
|
110
|
+
if (this.socksProxy.proxyAgentFromOptions) this.target = await this.socksProxy.proxyAgentFromOptions.callback(new _events.EventEmitter(), {
|
|
111
|
+
host: rewriteToLocalhostIfNeeded(this.host),
|
|
112
|
+
port: this.port,
|
|
113
|
+
secureEndpoint: false
|
|
114
|
+
});else this.target = await (0, _happyEyeballs.createSocket)(rewriteToLocalhostIfNeeded(this.host), this.port);
|
|
115
|
+
this.target.once('close', this._targetCloseEventListener);
|
|
116
|
+
this.target.once('error', error => this.socksProxy._socksProxy.sendSocketError({
|
|
117
|
+
uid: this.uid,
|
|
118
|
+
error: error.message
|
|
119
|
+
}));
|
|
120
|
+
if (this._closed) {
|
|
121
|
+
this.target.destroy();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
this.socksProxy._socksProxy.socketConnected({
|
|
125
|
+
uid: this.uid,
|
|
126
|
+
host: this.target.localAddress,
|
|
127
|
+
port: this.target.localPort
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
onClose() {
|
|
131
|
+
var _this$internalTLS2, _this$_dummyServer2;
|
|
132
|
+
// Close the other end and cleanup TLS resources.
|
|
133
|
+
this.target.destroy();
|
|
134
|
+
(_this$internalTLS2 = this.internalTLS) === null || _this$internalTLS2 === void 0 || _this$internalTLS2.destroy();
|
|
135
|
+
(_this$_dummyServer2 = this._dummyServer) === null || _this$_dummyServer2 === void 0 || _this$_dummyServer2.close();
|
|
136
|
+
this._closed = true;
|
|
137
|
+
}
|
|
138
|
+
onData(data) {
|
|
139
|
+
// HTTP / TLS are client-hello based protocols. This allows us to detect
|
|
140
|
+
// the protocol on the first package and attach appropriate listeners.
|
|
141
|
+
if (!this.firstPackageReceived) {
|
|
142
|
+
this.firstPackageReceived = true;
|
|
143
|
+
// 0x16 is SSLv3/TLS "handshake" content type: https://en.wikipedia.org/wiki/Transport_Layer_Security#TLS_record
|
|
144
|
+
if (data[0] === 0x16) this._attachTLSListeners();else this.target.on('data', data => this.socksProxy._socksProxy.sendSocketData({
|
|
145
|
+
uid: this.uid,
|
|
146
|
+
data
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
if (this.internal) this.internal.push(data);else this.target.write(data);
|
|
150
|
+
}
|
|
151
|
+
_attachTLSListeners() {
|
|
152
|
+
this.internal = new _stream.default.Duplex({
|
|
153
|
+
read: () => {},
|
|
154
|
+
write: (data, encoding, callback) => {
|
|
155
|
+
this.socksProxy._socksProxy.sendSocketData({
|
|
156
|
+
uid: this.uid,
|
|
157
|
+
data
|
|
158
|
+
});
|
|
159
|
+
callback();
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
this.socksProxy.alpnCache.get(rewriteToLocalhostIfNeeded(this.host), this.port, alpnProtocolChosenByServer => {
|
|
163
|
+
_debugLogger.debugLogger.log('client-certificates', `Proxy->Target ${this.host}:${this.port} chooses ALPN ${alpnProtocolChosenByServer}`);
|
|
164
|
+
if (this._closed) return;
|
|
165
|
+
this._dummyServer = _tls.default.createServer({
|
|
166
|
+
...dummyServerTlsOptions,
|
|
167
|
+
ALPNProtocols: alpnProtocolChosenByServer === 'h2' ? ['h2', 'http/1.1'] : ['http/1.1']
|
|
168
|
+
});
|
|
169
|
+
this._dummyServer.emit('connection', this.internal);
|
|
170
|
+
this._dummyServer.once('secureConnection', internalTLS => {
|
|
171
|
+
this.internalTLS = internalTLS;
|
|
172
|
+
_debugLogger.debugLogger.log('client-certificates', `Browser->Proxy ${this.host}:${this.port} chooses ALPN ${internalTLS.alpnProtocol}`);
|
|
173
|
+
let targetTLS = undefined;
|
|
174
|
+
const handleError = error => {
|
|
175
|
+
_debugLogger.debugLogger.log('client-certificates', `error when connecting to target: ${error.message.replaceAll('\n', ' ')}`);
|
|
176
|
+
const responseBody = (0, _utils.escapeHTML)('Playwright client-certificate error: ' + error.message).replaceAll('\n', ' <br>');
|
|
177
|
+
if ((internalTLS === null || internalTLS === void 0 ? void 0 : internalTLS.alpnProtocol) === 'h2') {
|
|
178
|
+
// This method is available only in Node.js 20+
|
|
179
|
+
if ('performServerHandshake' in _http.default) {
|
|
180
|
+
// In case of an 'error' event on the target connection, we still need to perform the http2 handshake on the browser side.
|
|
181
|
+
// This is an async operation, so we need to remove the listener to prevent the socket from being closed too early.
|
|
182
|
+
// This means we call this._targetCloseEventListener manually.
|
|
183
|
+
this.target.removeListener('close', this._targetCloseEventListener);
|
|
184
|
+
// @ts-expect-error
|
|
185
|
+
const session = _http.default.performServerHandshake(internalTLS);
|
|
186
|
+
session.on('error', () => {
|
|
187
|
+
this.target.destroy();
|
|
188
|
+
this._targetCloseEventListener();
|
|
189
|
+
});
|
|
190
|
+
session.once('stream', stream => {
|
|
191
|
+
stream.respond({
|
|
192
|
+
'content-type': 'text/html',
|
|
193
|
+
[_http.default.constants.HTTP2_HEADER_STATUS]: 503
|
|
194
|
+
});
|
|
195
|
+
const cleanup = () => {
|
|
196
|
+
session.close();
|
|
197
|
+
this.target.destroy();
|
|
198
|
+
this._targetCloseEventListener();
|
|
199
|
+
};
|
|
200
|
+
stream.end(responseBody, cleanup);
|
|
201
|
+
stream.once('error', cleanup);
|
|
202
|
+
});
|
|
203
|
+
} else {
|
|
204
|
+
this.target.destroy();
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
internalTLS.end(['HTTP/1.1 503 Internal Server Error', 'Content-Type: text/html; charset=utf-8', 'Content-Length: ' + Buffer.byteLength(responseBody), '', responseBody].join('\r\n'));
|
|
208
|
+
this.target.destroy();
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
if (this._closed) {
|
|
212
|
+
internalTLS.destroy();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
targetTLS = _tls.default.connect({
|
|
216
|
+
socket: this.target,
|
|
217
|
+
host: this.host,
|
|
218
|
+
port: this.port,
|
|
219
|
+
rejectUnauthorized: !this.socksProxy.ignoreHTTPSErrors,
|
|
220
|
+
ALPNProtocols: [internalTLS.alpnProtocol || 'http/1.1'],
|
|
221
|
+
servername: !_net.default.isIP(this.host) ? this.host : undefined,
|
|
222
|
+
secureContext: this.socksProxy.secureContextMap.get(new URL(`https://${this.host}:${this.port}`).origin)
|
|
223
|
+
});
|
|
224
|
+
targetTLS.once('secureConnect', () => {
|
|
225
|
+
internalTLS.pipe(targetTLS);
|
|
226
|
+
targetTLS.pipe(internalTLS);
|
|
227
|
+
});
|
|
228
|
+
internalTLS.once('error', () => this.target.destroy());
|
|
229
|
+
targetTLS.once('error', handleError);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
class ClientCertificatesProxy {
|
|
235
|
+
constructor(contextOptions) {
|
|
236
|
+
this._socksProxy = void 0;
|
|
237
|
+
this._connections = new Map();
|
|
238
|
+
this.ignoreHTTPSErrors = void 0;
|
|
239
|
+
this.secureContextMap = new Map();
|
|
240
|
+
this.alpnCache = void 0;
|
|
241
|
+
this.proxyAgentFromOptions = void 0;
|
|
242
|
+
(0, _browserContext.verifyClientCertificates)(contextOptions.clientCertificates);
|
|
243
|
+
this.alpnCache = new ALPNCache();
|
|
244
|
+
this.ignoreHTTPSErrors = contextOptions.ignoreHTTPSErrors;
|
|
245
|
+
this.proxyAgentFromOptions = contextOptions.proxy ? (0, _fetch.createProxyAgent)(contextOptions.proxy) : undefined;
|
|
246
|
+
this._initSecureContexts(contextOptions.clientCertificates);
|
|
247
|
+
this._socksProxy = new _socksProxy.SocksProxy();
|
|
248
|
+
this._socksProxy.setPattern('*');
|
|
249
|
+
this._socksProxy.addListener(_socksProxy.SocksProxy.Events.SocksRequested, async payload => {
|
|
250
|
+
try {
|
|
251
|
+
const connection = new SocksProxyConnection(this, payload.uid, payload.host, payload.port);
|
|
252
|
+
await connection.connect();
|
|
253
|
+
this._connections.set(payload.uid, connection);
|
|
254
|
+
} catch (error) {
|
|
255
|
+
this._socksProxy.socketFailed({
|
|
256
|
+
uid: payload.uid,
|
|
257
|
+
errorCode: error.code
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
this._socksProxy.addListener(_socksProxy.SocksProxy.Events.SocksData, async payload => {
|
|
262
|
+
var _this$_connections$ge;
|
|
263
|
+
(_this$_connections$ge = this._connections.get(payload.uid)) === null || _this$_connections$ge === void 0 || _this$_connections$ge.onData(payload.data);
|
|
264
|
+
});
|
|
265
|
+
this._socksProxy.addListener(_socksProxy.SocksProxy.Events.SocksClosed, payload => {
|
|
266
|
+
var _this$_connections$ge2;
|
|
267
|
+
(_this$_connections$ge2 = this._connections.get(payload.uid)) === null || _this$_connections$ge2 === void 0 || _this$_connections$ge2.onClose();
|
|
268
|
+
this._connections.delete(payload.uid);
|
|
269
|
+
});
|
|
270
|
+
loadDummyServerCertsIfNeeded();
|
|
271
|
+
}
|
|
272
|
+
_initSecureContexts(clientCertificates) {
|
|
273
|
+
// Step 1. Group certificates by origin.
|
|
274
|
+
const origin2certs = new Map();
|
|
275
|
+
for (const cert of clientCertificates || []) {
|
|
276
|
+
const origin = normalizeOrigin(cert.origin);
|
|
277
|
+
const certs = origin2certs.get(origin) || [];
|
|
278
|
+
certs.push(cert);
|
|
279
|
+
origin2certs.set(origin, certs);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Step 2. Create secure contexts for each origin.
|
|
283
|
+
for (const [origin, certs] of origin2certs) {
|
|
284
|
+
try {
|
|
285
|
+
this.secureContextMap.set(origin, _tls.default.createSecureContext(convertClientCertificatesToTLSOptions(certs)));
|
|
286
|
+
} catch (error) {
|
|
287
|
+
error = rewriteOpenSSLErrorIfNeeded(error);
|
|
288
|
+
throw (0, _utils.rewriteErrorMessage)(error, `Failed to load client certificate: ${error.message}`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
async listen() {
|
|
293
|
+
const port = await this._socksProxy.listen(0, '127.0.0.1');
|
|
294
|
+
return {
|
|
295
|
+
server: `socks5://127.0.0.1:${port}`
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
async close() {
|
|
299
|
+
await this._socksProxy.close();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
exports.ClientCertificatesProxy = ClientCertificatesProxy;
|
|
303
|
+
function normalizeOrigin(origin) {
|
|
304
|
+
try {
|
|
305
|
+
return new URL(origin).origin;
|
|
306
|
+
} catch (error) {
|
|
307
|
+
return origin;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function convertClientCertificatesToTLSOptions(clientCertificates) {
|
|
311
|
+
if (!clientCertificates || !clientCertificates.length) return;
|
|
312
|
+
const tlsOptions = {
|
|
313
|
+
pfx: [],
|
|
314
|
+
key: [],
|
|
315
|
+
cert: []
|
|
316
|
+
};
|
|
317
|
+
for (const cert of clientCertificates) {
|
|
318
|
+
if (cert.cert) tlsOptions.cert.push(cert.cert);
|
|
319
|
+
if (cert.key) tlsOptions.key.push({
|
|
320
|
+
pem: cert.key,
|
|
321
|
+
passphrase: cert.passphrase
|
|
322
|
+
});
|
|
323
|
+
if (cert.pfx) tlsOptions.pfx.push({
|
|
324
|
+
buf: cert.pfx,
|
|
325
|
+
passphrase: cert.passphrase
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
return tlsOptions;
|
|
329
|
+
}
|
|
330
|
+
function getMatchingTLSOptionsForOrigin(clientCertificates, origin) {
|
|
331
|
+
const matchingCerts = clientCertificates === null || clientCertificates === void 0 ? void 0 : clientCertificates.filter(c => normalizeOrigin(c.origin) === origin);
|
|
332
|
+
return convertClientCertificatesToTLSOptions(matchingCerts);
|
|
333
|
+
}
|
|
334
|
+
function rewriteToLocalhostIfNeeded(host) {
|
|
335
|
+
return host === 'local.playwright' ? 'localhost' : host;
|
|
336
|
+
}
|
|
337
|
+
function rewriteOpenSSLErrorIfNeeded(error) {
|
|
338
|
+
if (error.message !== 'unsupported' && error.code !== 'ERR_CRYPTO_UNSUPPORTED_OPERATION') return error;
|
|
339
|
+
return (0, _utils.rewriteErrorMessage)(error, ['Unsupported TLS certificate.', 'Most likely, the security algorithm of the given certificate was deprecated by OpenSSL.', 'For more details, see https://github.com/openssl/openssl/blob/master/README-PROVIDERS.md#the-legacy-provider', 'You could probably modernize the certificate by following the steps at https://github.com/nodejs/node/issues/40672#issuecomment-1243648223'].join('\n'));
|
|
340
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SocksInterceptor = void 0;
|
|
7
|
+
var socks = _interopRequireWildcard(require("../common/socksProxy"));
|
|
8
|
+
var _events = _interopRequireDefault(require("events"));
|
|
9
|
+
var _validator = require("../protocol/validator");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
+
/**
|
|
14
|
+
* Copyright (c) Microsoft Corporation.
|
|
15
|
+
*
|
|
16
|
+
* Licensed under the Apache License, Version 2.0 (the 'License");
|
|
17
|
+
* you may not use this file except in compliance with the License.
|
|
18
|
+
* You may obtain a copy of the License at
|
|
19
|
+
*
|
|
20
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
21
|
+
*
|
|
22
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
23
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
24
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
25
|
+
* See the License for the specific language governing permissions and
|
|
26
|
+
* limitations under the License.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
class SocksInterceptor {
|
|
30
|
+
constructor(transport, pattern, redirectPortForTest) {
|
|
31
|
+
this._handler = void 0;
|
|
32
|
+
this._channel = void 0;
|
|
33
|
+
this._socksSupportObjectGuid = void 0;
|
|
34
|
+
this._ids = new Set();
|
|
35
|
+
this._handler = new socks.SocksProxyHandler(pattern, redirectPortForTest);
|
|
36
|
+
let lastId = -1;
|
|
37
|
+
this._channel = new Proxy(new _events.default(), {
|
|
38
|
+
get: (obj, prop) => {
|
|
39
|
+
if (prop in obj || obj[prop] !== undefined || typeof prop !== 'string') return obj[prop];
|
|
40
|
+
return params => {
|
|
41
|
+
try {
|
|
42
|
+
const id = --lastId;
|
|
43
|
+
this._ids.add(id);
|
|
44
|
+
const validator = (0, _validator.findValidator)('SocksSupport', prop, 'Params');
|
|
45
|
+
params = validator(params, '', {
|
|
46
|
+
tChannelImpl: tChannelForSocks,
|
|
47
|
+
binary: 'toBase64'
|
|
48
|
+
});
|
|
49
|
+
transport.send({
|
|
50
|
+
id,
|
|
51
|
+
guid: this._socksSupportObjectGuid,
|
|
52
|
+
method: prop,
|
|
53
|
+
params,
|
|
54
|
+
metadata: {
|
|
55
|
+
stack: [],
|
|
56
|
+
apiName: '',
|
|
57
|
+
internal: true
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
} catch (e) {}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
this._handler.on(socks.SocksProxyHandler.Events.SocksConnected, payload => this._channel.socksConnected(payload));
|
|
65
|
+
this._handler.on(socks.SocksProxyHandler.Events.SocksData, payload => this._channel.socksData(payload));
|
|
66
|
+
this._handler.on(socks.SocksProxyHandler.Events.SocksError, payload => this._channel.socksError(payload));
|
|
67
|
+
this._handler.on(socks.SocksProxyHandler.Events.SocksFailed, payload => this._channel.socksFailed(payload));
|
|
68
|
+
this._handler.on(socks.SocksProxyHandler.Events.SocksEnd, payload => this._channel.socksEnd(payload));
|
|
69
|
+
this._channel.on('socksRequested', payload => this._handler.socketRequested(payload));
|
|
70
|
+
this._channel.on('socksClosed', payload => this._handler.socketClosed(payload));
|
|
71
|
+
this._channel.on('socksData', payload => this._handler.sendSocketData(payload));
|
|
72
|
+
}
|
|
73
|
+
cleanup() {
|
|
74
|
+
this._handler.cleanup();
|
|
75
|
+
}
|
|
76
|
+
interceptMessage(message) {
|
|
77
|
+
if (this._ids.has(message.id)) {
|
|
78
|
+
this._ids.delete(message.id);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
if (message.method === '__create__' && message.params.type === 'SocksSupport') {
|
|
82
|
+
this._socksSupportObjectGuid = message.params.guid;
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
if (this._socksSupportObjectGuid && message.guid === this._socksSupportObjectGuid) {
|
|
86
|
+
const validator = (0, _validator.findValidator)('SocksSupport', message.method, 'Event');
|
|
87
|
+
const params = validator(message.params, '', {
|
|
88
|
+
tChannelImpl: tChannelForSocks,
|
|
89
|
+
binary: 'fromBase64'
|
|
90
|
+
});
|
|
91
|
+
this._channel.emit(message.method, params);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.SocksInterceptor = SocksInterceptor;
|
|
98
|
+
function tChannelForSocks(names, arg, path, context) {
|
|
99
|
+
throw new _validator.ValidationError(`${path}: channels are not expected in SocksSupport`);
|
|
100
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Snapshotter = void 0;
|
|
7
|
+
var _browserContext = require("../../browserContext");
|
|
8
|
+
var _page = require("../../page");
|
|
9
|
+
var _eventsHelper = require("../../../utils/eventsHelper");
|
|
10
|
+
var _debugLogger = require("../../../utils/debugLogger");
|
|
11
|
+
var _snapshotterInjected = require("./snapshotterInjected");
|
|
12
|
+
var _utils = require("../../../utils");
|
|
13
|
+
var _utilsBundle = require("../../../utilsBundle");
|
|
14
|
+
/**
|
|
15
|
+
* Copyright (c) Microsoft Corporation.
|
|
16
|
+
*
|
|
17
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
18
|
+
* you may not use this file except in compliance with the License.
|
|
19
|
+
* You may obtain a copy of the License at
|
|
20
|
+
*
|
|
21
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
22
|
+
*
|
|
23
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
25
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
26
|
+
* See the License for the specific language governing permissions and
|
|
27
|
+
* limitations under the License.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
class Snapshotter {
|
|
31
|
+
constructor(context, delegate) {
|
|
32
|
+
this._context = void 0;
|
|
33
|
+
this._delegate = void 0;
|
|
34
|
+
this._eventListeners = [];
|
|
35
|
+
this._snapshotStreamer = void 0;
|
|
36
|
+
this._initialized = false;
|
|
37
|
+
this._started = false;
|
|
38
|
+
this._context = context;
|
|
39
|
+
this._delegate = delegate;
|
|
40
|
+
const guid = (0, _utils.createGuid)();
|
|
41
|
+
this._snapshotStreamer = '__playwright_snapshot_streamer_' + guid;
|
|
42
|
+
}
|
|
43
|
+
started() {
|
|
44
|
+
return this._started;
|
|
45
|
+
}
|
|
46
|
+
async start() {
|
|
47
|
+
this._started = true;
|
|
48
|
+
if (!this._initialized) {
|
|
49
|
+
this._initialized = true;
|
|
50
|
+
await this._initialize();
|
|
51
|
+
}
|
|
52
|
+
await this.reset();
|
|
53
|
+
}
|
|
54
|
+
async reset() {
|
|
55
|
+
if (this._started) await this._runInAllFrames(`window["${this._snapshotStreamer}"].reset()`);
|
|
56
|
+
}
|
|
57
|
+
async stop() {
|
|
58
|
+
this._started = false;
|
|
59
|
+
}
|
|
60
|
+
resetForReuse() {
|
|
61
|
+
// Next time we start recording, we will call addInitScript again.
|
|
62
|
+
this._initialized = false;
|
|
63
|
+
}
|
|
64
|
+
async _initialize() {
|
|
65
|
+
for (const page of this._context.pages()) this._onPage(page);
|
|
66
|
+
this._eventListeners = [_eventsHelper.eventsHelper.addEventListener(this._context, _browserContext.BrowserContext.Events.Page, this._onPage.bind(this))];
|
|
67
|
+
const {
|
|
68
|
+
javaScriptEnabled
|
|
69
|
+
} = this._context._options;
|
|
70
|
+
const initScript = `(${_snapshotterInjected.frameSnapshotStreamer})("${this._snapshotStreamer}", ${javaScriptEnabled || javaScriptEnabled === undefined})`;
|
|
71
|
+
await this._context.addInitScript(initScript);
|
|
72
|
+
await this._runInAllFrames(initScript);
|
|
73
|
+
}
|
|
74
|
+
async _runInAllFrames(expression) {
|
|
75
|
+
const frames = [];
|
|
76
|
+
for (const page of this._context.pages()) frames.push(...page.frames());
|
|
77
|
+
await Promise.all(frames.map(frame => {
|
|
78
|
+
return frame.nonStallingRawEvaluateInExistingMainContext(expression).catch(e => _debugLogger.debugLogger.log('error', e));
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
dispose() {
|
|
82
|
+
_eventsHelper.eventsHelper.removeEventListeners(this._eventListeners);
|
|
83
|
+
}
|
|
84
|
+
async captureSnapshot(page, callId, snapshotName, element) {
|
|
85
|
+
// Prepare expression synchronously.
|
|
86
|
+
const expression = `window["${this._snapshotStreamer}"].captureSnapshot(${JSON.stringify(snapshotName)})`;
|
|
87
|
+
|
|
88
|
+
// In a best-effort manner, without waiting for it, mark target element.
|
|
89
|
+
element === null || element === void 0 || element.callFunctionNoReply((element, callId) => {
|
|
90
|
+
const customEvent = new CustomEvent('__playwright_target__', {
|
|
91
|
+
bubbles: true,
|
|
92
|
+
cancelable: true,
|
|
93
|
+
detail: callId,
|
|
94
|
+
composed: true
|
|
95
|
+
});
|
|
96
|
+
element.dispatchEvent(customEvent);
|
|
97
|
+
}, callId);
|
|
98
|
+
|
|
99
|
+
// In each frame, in a non-stalling manner, capture the snapshots.
|
|
100
|
+
const snapshots = page.frames().map(async frame => {
|
|
101
|
+
const data = await frame.nonStallingRawEvaluateInExistingMainContext(expression).catch(e => _debugLogger.debugLogger.log('error', e));
|
|
102
|
+
// Something went wrong -> bail out, our snapshots are best-efforty.
|
|
103
|
+
if (!data || !this._started) return;
|
|
104
|
+
const snapshot = {
|
|
105
|
+
callId,
|
|
106
|
+
snapshotName,
|
|
107
|
+
pageId: page.guid,
|
|
108
|
+
frameId: frame.guid,
|
|
109
|
+
frameUrl: data.url,
|
|
110
|
+
doctype: data.doctype,
|
|
111
|
+
html: data.html,
|
|
112
|
+
viewport: data.viewport,
|
|
113
|
+
timestamp: (0, _utils.monotonicTime)(),
|
|
114
|
+
wallTime: data.wallTime,
|
|
115
|
+
collectionTime: data.collectionTime,
|
|
116
|
+
resourceOverrides: [],
|
|
117
|
+
isMainFrame: page.mainFrame() === frame
|
|
118
|
+
};
|
|
119
|
+
for (const {
|
|
120
|
+
url,
|
|
121
|
+
content,
|
|
122
|
+
contentType
|
|
123
|
+
} of data.resourceOverrides) {
|
|
124
|
+
if (typeof content === 'string') {
|
|
125
|
+
const buffer = Buffer.from(content);
|
|
126
|
+
const sha1 = (0, _utils.calculateSha1)(buffer) + '.' + (_utilsBundle.mime.getExtension(contentType) || 'dat');
|
|
127
|
+
this._delegate.onSnapshotterBlob({
|
|
128
|
+
sha1,
|
|
129
|
+
buffer
|
|
130
|
+
});
|
|
131
|
+
snapshot.resourceOverrides.push({
|
|
132
|
+
url,
|
|
133
|
+
sha1
|
|
134
|
+
});
|
|
135
|
+
} else {
|
|
136
|
+
snapshot.resourceOverrides.push({
|
|
137
|
+
url,
|
|
138
|
+
ref: content
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
this._delegate.onFrameSnapshot(snapshot);
|
|
143
|
+
});
|
|
144
|
+
await Promise.all(snapshots);
|
|
145
|
+
}
|
|
146
|
+
_onPage(page) {
|
|
147
|
+
// Annotate frame hierarchy so that snapshots could include frame ids.
|
|
148
|
+
for (const frame of page.frames()) this._annotateFrameHierarchy(frame);
|
|
149
|
+
this._eventListeners.push(_eventsHelper.eventsHelper.addEventListener(page, _page.Page.Events.FrameAttached, frame => this._annotateFrameHierarchy(frame)));
|
|
150
|
+
}
|
|
151
|
+
async _annotateFrameHierarchy(frame) {
|
|
152
|
+
try {
|
|
153
|
+
const frameElement = await frame.frameElement();
|
|
154
|
+
const parent = frame.parentFrame();
|
|
155
|
+
if (!parent) return;
|
|
156
|
+
const context = await parent._mainContext();
|
|
157
|
+
await (context === null || context === void 0 ? void 0 : context.evaluate(({
|
|
158
|
+
snapshotStreamer,
|
|
159
|
+
frameElement,
|
|
160
|
+
frameId
|
|
161
|
+
}) => {
|
|
162
|
+
window[snapshotStreamer].markIframe(frameElement, frameId);
|
|
163
|
+
}, {
|
|
164
|
+
snapshotStreamer: this._snapshotStreamer,
|
|
165
|
+
frameElement,
|
|
166
|
+
frameId: frame.guid
|
|
167
|
+
}));
|
|
168
|
+
frameElement.dispose();
|
|
169
|
+
} catch (e) {}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.Snapshotter = Snapshotter;
|