@checkly/playwright-core 1.41.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +3 -0
- package/ThirdPartyNotices.txt +1513 -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 +23 -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 +23 -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 +22 -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 +22 -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 +23 -0
- package/browsers.json +64 -0
- package/cli.js +17 -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 +97 -0
- package/lib/cli/program.js +582 -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 +272 -0
- package/lib/client/artifact.js +79 -0
- package/lib/client/browser.js +145 -0
- package/lib/client/browserContext.js +509 -0
- package/lib/client/browserType.js +233 -0
- package/lib/client/cdpSession.js +53 -0
- package/lib/client/channelOwner.js +229 -0
- package/lib/client/clientHelper.js +57 -0
- package/lib/client/clientInstrumentation.js +40 -0
- package/lib/client/connection.js +327 -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 +130 -0
- package/lib/client/elementHandle.js +291 -0
- package/lib/client/errors.js +77 -0
- package/lib/client/events.js +93 -0
- package/lib/client/fetch.js +343 -0
- package/lib/client/fileChooser.js +45 -0
- package/lib/client/frame.js +506 -0
- package/lib/client/harRouter.js +93 -0
- package/lib/client/input.js +111 -0
- package/lib/client/jsHandle.js +123 -0
- package/lib/client/jsonPipe.js +35 -0
- package/lib/client/localUtils.js +35 -0
- package/lib/client/locator.js +432 -0
- package/lib/client/network.js +601 -0
- package/lib/client/page.js +707 -0
- package/lib/client/playwright.js +74 -0
- package/lib/client/selectors.js +67 -0
- package/lib/client/stream.js +54 -0
- package/lib/client/tracing.js +135 -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/consoleApiSource.js +7 -0
- package/lib/generated/injectedScriptSource.js +7 -0
- package/lib/generated/recorderSource.js +7 -0
- package/lib/generated/utilityScriptSource.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 +172 -0
- package/lib/protocol/transport.js +82 -0
- package/lib/protocol/validator.js +2599 -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/browser.js +129 -0
- package/lib/server/browserContext.js +609 -0
- package/lib/server/browserType.js +300 -0
- package/lib/server/chromium/appIcon.png +0 -0
- package/lib/server/chromium/chromium.js +346 -0
- package/lib/server/chromium/chromiumSwitches.js +41 -0
- package/lib/server/chromium/crAccessibility.js +237 -0
- package/lib/server/chromium/crBrowser.js +521 -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 +144 -0
- package/lib/server/chromium/crExecutionContext.js +156 -0
- package/lib/server/chromium/crInput.js +171 -0
- package/lib/server/chromium/crNetworkManager.js +723 -0
- package/lib/server/chromium/crPage.js +1173 -0
- package/lib/server/chromium/crPdf.js +147 -0
- package/lib/server/chromium/crProtocolHelper.js +131 -0
- package/lib/server/chromium/crServiceWorker.js +115 -0
- package/lib/server/chromium/defaultFontFamilies.js +145 -0
- package/lib/server/chromium/videoRecorder.js +155 -0
- package/lib/server/console.js +59 -0
- package/lib/server/cookieStore.js +112 -0
- package/lib/server/debugController.js +236 -0
- package/lib/server/debugger.js +132 -0
- package/lib/server/deviceDescriptors.js +21 -0
- package/lib/server/deviceDescriptorsSource.json +1549 -0
- package/lib/server/dialog.js +70 -0
- package/lib/server/dispatchers/androidDispatcher.js +193 -0
- package/lib/server/dispatchers/artifactDispatcher.js +118 -0
- package/lib/server/dispatchers/browserContextDispatcher.js +306 -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 +400 -0
- package/lib/server/dispatchers/electronDispatcher.js +80 -0
- package/lib/server/dispatchers/elementHandlerDispatcher.js +228 -0
- package/lib/server/dispatchers/frameDispatcher.js +287 -0
- package/lib/server/dispatchers/jsHandleDispatcher.js +102 -0
- package/lib/server/dispatchers/jsonPipeDispatcher.js +61 -0
- package/lib/server/dispatchers/localUtilsDispatcher.js +399 -0
- package/lib/server/dispatchers/networkDispatchers.js +221 -0
- package/lib/server/dispatchers/pageDispatcher.js +363 -0
- package/lib/server/dispatchers/playwrightDispatcher.js +105 -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/writableStreamDispatcher.js +55 -0
- package/lib/server/dom.js +808 -0
- package/lib/server/download.js +53 -0
- package/lib/server/electron/electron.js +254 -0
- package/lib/server/electron/loader.js +57 -0
- package/lib/server/errors.js +68 -0
- package/lib/server/fetch.js +611 -0
- package/lib/server/fileChooser.js +42 -0
- package/lib/server/fileUploadUtils.js +71 -0
- package/lib/server/firefox/ffAccessibility.js +215 -0
- package/lib/server/firefox/ffBrowser.js +447 -0
- package/lib/server/firefox/ffConnection.js +168 -0
- package/lib/server/firefox/ffExecutionContext.js +138 -0
- package/lib/server/firefox/ffInput.js +150 -0
- package/lib/server/firefox/ffNetworkManager.js +231 -0
- package/lib/server/firefox/ffPage.js +558 -0
- package/lib/server/firefox/firefox.js +91 -0
- package/lib/server/formData.js +75 -0
- package/lib/server/frameSelectors.js +171 -0
- package/lib/server/frames.js +1597 -0
- package/lib/server/har/harRecorder.js +139 -0
- package/lib/server/har/harTracer.js +539 -0
- package/lib/server/helper.js +103 -0
- package/lib/server/index.js +96 -0
- package/lib/server/input.js +301 -0
- package/lib/server/instrumentation.js +74 -0
- package/lib/server/isomorphic/utilityScriptSerializers.js +212 -0
- package/lib/server/javascript.js +305 -0
- package/lib/server/launchApp.js +90 -0
- package/lib/server/macEditingCommands.js +139 -0
- package/lib/server/network.js +607 -0
- package/lib/server/page.js +793 -0
- package/lib/server/pipeTransport.js +85 -0
- package/lib/server/playwright.js +82 -0
- package/lib/server/progress.js +102 -0
- package/lib/server/protocolError.js +49 -0
- package/lib/server/recorder/codeGenerator.js +153 -0
- package/lib/server/recorder/csharp.js +310 -0
- package/lib/server/recorder/java.js +216 -0
- package/lib/server/recorder/javascript.js +229 -0
- package/lib/server/recorder/jsonl.js +47 -0
- package/lib/server/recorder/language.js +44 -0
- package/lib/server/recorder/python.js +275 -0
- package/lib/server/recorder/recorderActions.js +5 -0
- package/lib/server/recorder/recorderApp.js +181 -0
- package/lib/server/recorder/recorderUtils.js +48 -0
- package/lib/server/recorder/utils.js +45 -0
- package/lib/server/recorder.js +700 -0
- package/lib/server/registry/browserFetcher.js +168 -0
- package/lib/server/registry/dependencies.js +322 -0
- package/lib/server/registry/index.js +925 -0
- package/lib/server/registry/nativeDeps.js +383 -0
- package/lib/server/registry/oopDownloadBrowserMain.js +138 -0
- package/lib/server/screenshotter.js +354 -0
- package/lib/server/selectors.js +73 -0
- package/lib/server/socksInterceptor.js +100 -0
- package/lib/server/trace/recorder/snapshotter.js +168 -0
- package/lib/server/trace/recorder/snapshotterInjected.js +493 -0
- package/lib/server/trace/recorder/tracing.js +552 -0
- package/lib/server/trace/test/inMemorySnapshotter.js +93 -0
- package/lib/server/trace/viewer/traceViewer.js +229 -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 +328 -0
- package/lib/server/webkit/wkConnection.js +173 -0
- package/lib/server/webkit/wkExecutionContext.js +146 -0
- package/lib/server/webkit/wkInput.js +169 -0
- package/lib/server/webkit/wkInterceptableRequest.js +158 -0
- package/lib/server/webkit/wkPage.js +1198 -0
- package/lib/server/webkit/wkProvisionalPage.js +59 -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 +33 -0
- package/lib/utils/debug.js +46 -0
- package/lib/utils/debugLogger.js +89 -0
- package/lib/utils/env.js +47 -0
- package/lib/utils/eventsHelper.js +38 -0
- package/lib/utils/fileUtils.js +66 -0
- package/lib/utils/glob.js +83 -0
- package/lib/utils/happy-eyeballs.js +154 -0
- package/lib/utils/headers.js +52 -0
- package/lib/utils/hostPlatform.js +124 -0
- package/lib/utils/httpServer.js +195 -0
- package/lib/utils/index.js +324 -0
- package/lib/utils/isomorphic/cssParser.js +250 -0
- package/lib/utils/isomorphic/cssTokenizer.js +979 -0
- package/lib/utils/isomorphic/locatorGenerators.js +651 -0
- package/lib/utils/isomorphic/locatorParser.js +179 -0
- package/lib/utils/isomorphic/locatorUtils.js +62 -0
- package/lib/utils/isomorphic/selectorParser.js +397 -0
- package/lib/utils/isomorphic/stringUtils.js +107 -0
- package/lib/utils/isomorphic/traceUtils.js +39 -0
- package/lib/utils/linuxUtils.js +78 -0
- package/lib/utils/manualPromise.js +109 -0
- package/lib/utils/mimeType.js +29 -0
- package/lib/utils/multimap.js +75 -0
- package/lib/utils/network.js +189 -0
- package/lib/utils/processLauncher.js +248 -0
- package/lib/utils/profiler.js +53 -0
- package/lib/utils/rtti.js +41 -0
- package/lib/utils/semaphore.js +51 -0
- package/lib/utils/spawnAsync.js +45 -0
- package/lib/utils/stackTrace.js +123 -0
- package/lib/utils/task.js +58 -0
- package/lib/utils/time.js +37 -0
- package/lib/utils/timeoutRunner.js +131 -0
- package/lib/utils/traceUtils.js +44 -0
- package/lib/utils/userAgent.js +105 -0
- package/lib/utils/wsServer.js +125 -0
- package/lib/utils/zipFile.js +75 -0
- package/lib/utils/zones.js +99 -0
- package/lib/utilsBundle.js +81 -0
- package/lib/utilsBundleImpl/index.js +51 -0
- package/lib/utilsBundleImpl/xdg-open +1066 -0
- package/lib/vite/htmlReport/index.html +66 -0
- package/lib/vite/recorder/assets/codeMirrorModule-Hs9-1ZG4.css +1 -0
- package/lib/vite/recorder/assets/codeMirrorModule-I9ks4y7D.js +24 -0
- package/lib/vite/recorder/assets/codicon-zGuYmc9o.ttf +0 -0
- package/lib/vite/recorder/assets/index-ljsTwXtJ.css +1 -0
- package/lib/vite/recorder/assets/index-yg8ypzl6.js +47 -0
- package/lib/vite/recorder/index.html +29 -0
- package/lib/vite/recorder/playwright-logo.svg +9 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-GluP1cQ1.js +24 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-fqJB1XDu.js +24 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-y3M3aAqy.js +24 -0
- package/lib/vite/traceViewer/assets/wsPort-Rvwd4WC-.js +69 -0
- package/lib/vite/traceViewer/assets/wsPort-dlD7vDkY.js +69 -0
- package/lib/vite/traceViewer/assets/wsPort-qOE2NWrO.js +69 -0
- package/lib/vite/traceViewer/assets/xtermModule-Yt6xwiJ_.js +9 -0
- package/lib/vite/traceViewer/codeMirrorModule.Hs9-1ZG4.css +1 -0
- package/lib/vite/traceViewer/codicon.zGuYmc9o.ttf +0 -0
- package/lib/vite/traceViewer/index.-g_5lMbJ.css +1 -0
- package/lib/vite/traceViewer/index.4X7zDysg.js +2 -0
- package/lib/vite/traceViewer/index.HkJgzlGy.js +2 -0
- package/lib/vite/traceViewer/index.html +26 -0
- package/lib/vite/traceViewer/index.kRjx5sAJ.js +2 -0
- package/lib/vite/traceViewer/playwright-logo.svg +9 -0
- package/lib/vite/traceViewer/snapshot.html +21 -0
- package/lib/vite/traceViewer/sw.bundle.js +4 -0
- package/lib/vite/traceViewer/uiMode.1Wcp_Kto.js +10 -0
- package/lib/vite/traceViewer/uiMode.GTNzARcV.js +10 -0
- package/lib/vite/traceViewer/uiMode.html +17 -0
- package/lib/vite/traceViewer/uiMode.pWy0Re7G.css +1 -0
- package/lib/vite/traceViewer/uiMode.zV-7Lf9v.js +10 -0
- package/lib/vite/traceViewer/wsPort.kSgQKQ0y.css +1 -0
- package/lib/vite/traceViewer/xtermModule.0lwXJFHT.css +32 -0
- package/lib/zipBundle.js +25 -0
- package/lib/zipBundleImpl.js +5 -0
- package/package.json +43 -0
- package/types/protocol.d.ts +20304 -0
- package/types/structs.d.ts +45 -0
- package/types/types.d.ts +20626 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CRPDF = void 0;
|
|
7
|
+
var _utils = require("../../utils");
|
|
8
|
+
var _crProtocolHelper = require("./crProtocolHelper");
|
|
9
|
+
/**
|
|
10
|
+
* Copyright 2017 Google Inc. All rights reserved.
|
|
11
|
+
* Modifications copyright (c) Microsoft Corporation.
|
|
12
|
+
*
|
|
13
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
14
|
+
* you may not use this file except in compliance with the License.
|
|
15
|
+
* You may obtain a copy of the License at
|
|
16
|
+
*
|
|
17
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
+
* See the License for the specific language governing permissions and
|
|
23
|
+
* limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const PagePaperFormats = {
|
|
27
|
+
letter: {
|
|
28
|
+
width: 8.5,
|
|
29
|
+
height: 11
|
|
30
|
+
},
|
|
31
|
+
legal: {
|
|
32
|
+
width: 8.5,
|
|
33
|
+
height: 14
|
|
34
|
+
},
|
|
35
|
+
tabloid: {
|
|
36
|
+
width: 11,
|
|
37
|
+
height: 17
|
|
38
|
+
},
|
|
39
|
+
ledger: {
|
|
40
|
+
width: 17,
|
|
41
|
+
height: 11
|
|
42
|
+
},
|
|
43
|
+
a0: {
|
|
44
|
+
width: 33.1,
|
|
45
|
+
height: 46.8
|
|
46
|
+
},
|
|
47
|
+
a1: {
|
|
48
|
+
width: 23.4,
|
|
49
|
+
height: 33.1
|
|
50
|
+
},
|
|
51
|
+
a2: {
|
|
52
|
+
width: 16.54,
|
|
53
|
+
height: 23.4
|
|
54
|
+
},
|
|
55
|
+
a3: {
|
|
56
|
+
width: 11.7,
|
|
57
|
+
height: 16.54
|
|
58
|
+
},
|
|
59
|
+
a4: {
|
|
60
|
+
width: 8.27,
|
|
61
|
+
height: 11.7
|
|
62
|
+
},
|
|
63
|
+
a5: {
|
|
64
|
+
width: 5.83,
|
|
65
|
+
height: 8.27
|
|
66
|
+
},
|
|
67
|
+
a6: {
|
|
68
|
+
width: 4.13,
|
|
69
|
+
height: 5.83
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const unitToPixels = {
|
|
73
|
+
'px': 1,
|
|
74
|
+
'in': 96,
|
|
75
|
+
'cm': 37.8,
|
|
76
|
+
'mm': 3.78
|
|
77
|
+
};
|
|
78
|
+
function convertPrintParameterToInches(text) {
|
|
79
|
+
if (text === undefined) return undefined;
|
|
80
|
+
let unit = text.substring(text.length - 2).toLowerCase();
|
|
81
|
+
let valueText = '';
|
|
82
|
+
if (unitToPixels.hasOwnProperty(unit)) {
|
|
83
|
+
valueText = text.substring(0, text.length - 2);
|
|
84
|
+
} else {
|
|
85
|
+
// In case of unknown unit try to parse the whole parameter as number of pixels.
|
|
86
|
+
// This is consistent with phantom's paperSize behavior.
|
|
87
|
+
unit = 'px';
|
|
88
|
+
valueText = text;
|
|
89
|
+
}
|
|
90
|
+
const value = Number(valueText);
|
|
91
|
+
(0, _utils.assert)(!isNaN(value), 'Failed to parse parameter value: ' + text);
|
|
92
|
+
const pixels = value * unitToPixels[unit];
|
|
93
|
+
return pixels / 96;
|
|
94
|
+
}
|
|
95
|
+
class CRPDF {
|
|
96
|
+
constructor(client) {
|
|
97
|
+
this._client = void 0;
|
|
98
|
+
this._client = client;
|
|
99
|
+
}
|
|
100
|
+
async generate(options) {
|
|
101
|
+
const {
|
|
102
|
+
scale = 1,
|
|
103
|
+
displayHeaderFooter = false,
|
|
104
|
+
headerTemplate = '',
|
|
105
|
+
footerTemplate = '',
|
|
106
|
+
printBackground = false,
|
|
107
|
+
landscape = false,
|
|
108
|
+
pageRanges = '',
|
|
109
|
+
preferCSSPageSize = false,
|
|
110
|
+
margin = {}
|
|
111
|
+
} = options;
|
|
112
|
+
let paperWidth = 8.5;
|
|
113
|
+
let paperHeight = 11;
|
|
114
|
+
if (options.format) {
|
|
115
|
+
const format = PagePaperFormats[options.format.toLowerCase()];
|
|
116
|
+
(0, _utils.assert)(format, 'Unknown paper format: ' + options.format);
|
|
117
|
+
paperWidth = format.width;
|
|
118
|
+
paperHeight = format.height;
|
|
119
|
+
} else {
|
|
120
|
+
paperWidth = convertPrintParameterToInches(options.width) || paperWidth;
|
|
121
|
+
paperHeight = convertPrintParameterToInches(options.height) || paperHeight;
|
|
122
|
+
}
|
|
123
|
+
const marginTop = convertPrintParameterToInches(margin.top) || 0;
|
|
124
|
+
const marginLeft = convertPrintParameterToInches(margin.left) || 0;
|
|
125
|
+
const marginBottom = convertPrintParameterToInches(margin.bottom) || 0;
|
|
126
|
+
const marginRight = convertPrintParameterToInches(margin.right) || 0;
|
|
127
|
+
const result = await this._client.send('Page.printToPDF', {
|
|
128
|
+
transferMode: 'ReturnAsStream',
|
|
129
|
+
landscape,
|
|
130
|
+
displayHeaderFooter,
|
|
131
|
+
headerTemplate,
|
|
132
|
+
footerTemplate,
|
|
133
|
+
printBackground,
|
|
134
|
+
scale,
|
|
135
|
+
paperWidth,
|
|
136
|
+
paperHeight,
|
|
137
|
+
marginTop,
|
|
138
|
+
marginBottom,
|
|
139
|
+
marginLeft,
|
|
140
|
+
marginRight,
|
|
141
|
+
pageRanges,
|
|
142
|
+
preferCSSPageSize
|
|
143
|
+
});
|
|
144
|
+
return await (0, _crProtocolHelper.readProtocolStream)(this._client, result.stream);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.CRPDF = CRPDF;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.exceptionToError = exceptionToError;
|
|
7
|
+
exports.getExceptionMessage = getExceptionMessage;
|
|
8
|
+
exports.readProtocolStream = readProtocolStream;
|
|
9
|
+
exports.releaseObject = releaseObject;
|
|
10
|
+
exports.saveProtocolStream = saveProtocolStream;
|
|
11
|
+
exports.toButtonsMask = toButtonsMask;
|
|
12
|
+
exports.toConsoleMessageLocation = toConsoleMessageLocation;
|
|
13
|
+
exports.toModifiersMask = toModifiersMask;
|
|
14
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
15
|
+
var _fileUtils = require("../../utils/fileUtils");
|
|
16
|
+
var _stackTrace = require("../../utils/stackTrace");
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
/**
|
|
19
|
+
* Copyright 2017 Google Inc. All rights reserved.
|
|
20
|
+
* Modifications copyright (c) Microsoft Corporation.
|
|
21
|
+
*
|
|
22
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
23
|
+
* you may not use this file except in compliance with the License.
|
|
24
|
+
* You may obtain a copy of the License at
|
|
25
|
+
*
|
|
26
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
27
|
+
*
|
|
28
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
29
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
30
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
31
|
+
* See the License for the specific language governing permissions and
|
|
32
|
+
* limitations under the License.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
function getExceptionMessage(exceptionDetails) {
|
|
36
|
+
if (exceptionDetails.exception) return exceptionDetails.exception.description || String(exceptionDetails.exception.value);
|
|
37
|
+
let message = exceptionDetails.text;
|
|
38
|
+
if (exceptionDetails.stackTrace) {
|
|
39
|
+
for (const callframe of exceptionDetails.stackTrace.callFrames) {
|
|
40
|
+
const location = callframe.url + ':' + callframe.lineNumber + ':' + callframe.columnNumber;
|
|
41
|
+
const functionName = callframe.functionName || '<anonymous>';
|
|
42
|
+
message += `\n at ${functionName} (${location})`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return message;
|
|
46
|
+
}
|
|
47
|
+
async function releaseObject(client, objectId) {
|
|
48
|
+
await client.send('Runtime.releaseObject', {
|
|
49
|
+
objectId
|
|
50
|
+
}).catch(error => {});
|
|
51
|
+
}
|
|
52
|
+
async function saveProtocolStream(client, handle, path) {
|
|
53
|
+
let eof = false;
|
|
54
|
+
await (0, _fileUtils.mkdirIfNeeded)(path);
|
|
55
|
+
const fd = await _fs.default.promises.open(path, 'w');
|
|
56
|
+
while (!eof) {
|
|
57
|
+
const response = await client.send('IO.read', {
|
|
58
|
+
handle
|
|
59
|
+
});
|
|
60
|
+
eof = response.eof;
|
|
61
|
+
const buf = Buffer.from(response.data, response.base64Encoded ? 'base64' : undefined);
|
|
62
|
+
await fd.write(buf);
|
|
63
|
+
}
|
|
64
|
+
await fd.close();
|
|
65
|
+
await client.send('IO.close', {
|
|
66
|
+
handle
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async function readProtocolStream(client, handle) {
|
|
70
|
+
let eof = false;
|
|
71
|
+
const chunks = [];
|
|
72
|
+
while (!eof) {
|
|
73
|
+
const response = await client.send('IO.read', {
|
|
74
|
+
handle
|
|
75
|
+
});
|
|
76
|
+
eof = response.eof;
|
|
77
|
+
const buf = Buffer.from(response.data, response.base64Encoded ? 'base64' : undefined);
|
|
78
|
+
chunks.push(buf);
|
|
79
|
+
}
|
|
80
|
+
await client.send('IO.close', {
|
|
81
|
+
handle
|
|
82
|
+
});
|
|
83
|
+
return Buffer.concat(chunks);
|
|
84
|
+
}
|
|
85
|
+
function toConsoleMessageLocation(stackTrace) {
|
|
86
|
+
return stackTrace && stackTrace.callFrames.length ? {
|
|
87
|
+
url: stackTrace.callFrames[0].url,
|
|
88
|
+
lineNumber: stackTrace.callFrames[0].lineNumber,
|
|
89
|
+
columnNumber: stackTrace.callFrames[0].columnNumber
|
|
90
|
+
} : {
|
|
91
|
+
url: '',
|
|
92
|
+
lineNumber: 0,
|
|
93
|
+
columnNumber: 0
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function exceptionToError(exceptionDetails) {
|
|
97
|
+
const messageWithStack = getExceptionMessage(exceptionDetails);
|
|
98
|
+
const lines = messageWithStack.split('\n');
|
|
99
|
+
const firstStackTraceLine = lines.findIndex(line => line.startsWith(' at'));
|
|
100
|
+
let messageWithName = '';
|
|
101
|
+
let stack = '';
|
|
102
|
+
if (firstStackTraceLine === -1) {
|
|
103
|
+
messageWithName = messageWithStack;
|
|
104
|
+
} else {
|
|
105
|
+
messageWithName = lines.slice(0, firstStackTraceLine).join('\n');
|
|
106
|
+
stack = messageWithStack;
|
|
107
|
+
}
|
|
108
|
+
const {
|
|
109
|
+
name,
|
|
110
|
+
message
|
|
111
|
+
} = (0, _stackTrace.splitErrorMessage)(messageWithName);
|
|
112
|
+
const err = new Error(message);
|
|
113
|
+
err.stack = stack;
|
|
114
|
+
err.name = name;
|
|
115
|
+
return err;
|
|
116
|
+
}
|
|
117
|
+
function toModifiersMask(modifiers) {
|
|
118
|
+
let mask = 0;
|
|
119
|
+
if (modifiers.has('Alt')) mask |= 1;
|
|
120
|
+
if (modifiers.has('Control')) mask |= 2;
|
|
121
|
+
if (modifiers.has('Meta')) mask |= 4;
|
|
122
|
+
if (modifiers.has('Shift')) mask |= 8;
|
|
123
|
+
return mask;
|
|
124
|
+
}
|
|
125
|
+
function toButtonsMask(buttons) {
|
|
126
|
+
let mask = 0;
|
|
127
|
+
if (buttons.has('left')) mask |= 1;
|
|
128
|
+
if (buttons.has('right')) mask |= 2;
|
|
129
|
+
if (buttons.has('middle')) mask |= 4;
|
|
130
|
+
return mask;
|
|
131
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CRServiceWorker = void 0;
|
|
7
|
+
var _page = require("../page");
|
|
8
|
+
var _crExecutionContext = require("./crExecutionContext");
|
|
9
|
+
var _crNetworkManager = require("./crNetworkManager");
|
|
10
|
+
var network = _interopRequireWildcard(require("../network"));
|
|
11
|
+
var _browserContext = require("../browserContext");
|
|
12
|
+
var _utils = require("../../utils");
|
|
13
|
+
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); }
|
|
14
|
+
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; }
|
|
15
|
+
/**
|
|
16
|
+
* Copyright (c) Microsoft Corporation.
|
|
17
|
+
*
|
|
18
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
19
|
+
* you may not use this file except in compliance with the License.
|
|
20
|
+
* You may obtain a copy of the License at
|
|
21
|
+
*
|
|
22
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
23
|
+
*
|
|
24
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
25
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
26
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
27
|
+
* See the License for the specific language governing permissions and
|
|
28
|
+
* limitations under the License.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
class CRServiceWorker extends _page.Worker {
|
|
32
|
+
constructor(browserContext, session, url) {
|
|
33
|
+
super(browserContext, url);
|
|
34
|
+
this._browserContext = void 0;
|
|
35
|
+
this._networkManager = void 0;
|
|
36
|
+
this._session = void 0;
|
|
37
|
+
this._extraHTTPHeaders = null;
|
|
38
|
+
this._session = session;
|
|
39
|
+
this._browserContext = browserContext;
|
|
40
|
+
if (!!process.env.PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS) this._networkManager = new _crNetworkManager.CRNetworkManager(session, null, this, null);
|
|
41
|
+
session.once('Runtime.executionContextCreated', event => {
|
|
42
|
+
this._createExecutionContext(new _crExecutionContext.CRExecutionContext(session, event.context));
|
|
43
|
+
});
|
|
44
|
+
if (this._networkManager && this._isNetworkInspectionEnabled()) {
|
|
45
|
+
this._networkManager.initialize().catch(() => {});
|
|
46
|
+
this.updateRequestInterception();
|
|
47
|
+
this.updateExtraHTTPHeaders(true);
|
|
48
|
+
this.updateHttpCredentials(true);
|
|
49
|
+
this.updateOffline(true);
|
|
50
|
+
}
|
|
51
|
+
session.send('Runtime.enable', {}).catch(e => {});
|
|
52
|
+
session.send('Runtime.runIfWaitingForDebugger').catch(e => {});
|
|
53
|
+
session.on('Inspector.targetReloadedAfterCrash', () => {
|
|
54
|
+
// Resume service worker after restart.
|
|
55
|
+
session._sendMayFail('Runtime.runIfWaitingForDebugger', {});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
didClose() {
|
|
59
|
+
this._session.dispose();
|
|
60
|
+
super.didClose();
|
|
61
|
+
}
|
|
62
|
+
async updateOffline(initial) {
|
|
63
|
+
var _this$_networkManager;
|
|
64
|
+
if (!this._isNetworkInspectionEnabled()) return;
|
|
65
|
+
const offline = !!this._browserContext._options.offline;
|
|
66
|
+
if (!initial || offline) await ((_this$_networkManager = this._networkManager) === null || _this$_networkManager === void 0 ? void 0 : _this$_networkManager.setOffline(offline));
|
|
67
|
+
}
|
|
68
|
+
async updateHttpCredentials(initial) {
|
|
69
|
+
var _this$_networkManager2;
|
|
70
|
+
if (!this._isNetworkInspectionEnabled()) return;
|
|
71
|
+
const credentials = this._browserContext._options.httpCredentials || null;
|
|
72
|
+
if (!initial || credentials) await ((_this$_networkManager2 = this._networkManager) === null || _this$_networkManager2 === void 0 ? void 0 : _this$_networkManager2.authenticate(credentials));
|
|
73
|
+
}
|
|
74
|
+
async updateExtraHTTPHeaders(initial) {
|
|
75
|
+
if (!this._isNetworkInspectionEnabled()) return;
|
|
76
|
+
const headers = network.mergeHeaders([this._browserContext._options.extraHTTPHeaders, this._extraHTTPHeaders]);
|
|
77
|
+
if (!initial || headers.length) await this._session.send('Network.setExtraHTTPHeaders', {
|
|
78
|
+
headers: (0, _utils.headersArrayToObject)(headers, false /* lowerCase */)
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
updateRequestInterception() {
|
|
82
|
+
if (!this._networkManager || !this._isNetworkInspectionEnabled()) return Promise.resolve();
|
|
83
|
+
return this._networkManager.setRequestInterception(this.needsRequestInterception()).catch(e => {});
|
|
84
|
+
}
|
|
85
|
+
needsRequestInterception() {
|
|
86
|
+
return this._isNetworkInspectionEnabled() && !!this._browserContext._requestInterceptor;
|
|
87
|
+
}
|
|
88
|
+
reportRequestFinished(request, response) {
|
|
89
|
+
this._browserContext.emit(_browserContext.BrowserContext.Events.RequestFinished, {
|
|
90
|
+
request,
|
|
91
|
+
response
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
requestFailed(request, _canceled) {
|
|
95
|
+
this._browserContext.emit(_browserContext.BrowserContext.Events.RequestFailed, request);
|
|
96
|
+
}
|
|
97
|
+
requestReceivedResponse(response) {
|
|
98
|
+
this._browserContext.emit(_browserContext.BrowserContext.Events.Response, response);
|
|
99
|
+
}
|
|
100
|
+
requestStarted(request, route) {
|
|
101
|
+
this._browserContext.emit(_browserContext.BrowserContext.Events.Request, request);
|
|
102
|
+
if (route) {
|
|
103
|
+
var _this$_browserContext, _this$_browserContext2;
|
|
104
|
+
const r = new network.Route(request, route);
|
|
105
|
+
if ((_this$_browserContext = (_this$_browserContext2 = this._browserContext)._requestInterceptor) !== null && _this$_browserContext !== void 0 && _this$_browserContext.call(_this$_browserContext2, r, request)) return;
|
|
106
|
+
r.continue({
|
|
107
|
+
isFallback: true
|
|
108
|
+
}).catch(() => {});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
_isNetworkInspectionEnabled() {
|
|
112
|
+
return this._browserContext._options.serviceWorkers !== 'block';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.CRServiceWorker = CRServiceWorker;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.platformToFontFamilies = 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
|
+
// DO NOT EDIT: this map is generated from Chromium source code by utils/generate_chromium_default_font_families.js
|
|
24
|
+
const platformToFontFamilies = exports.platformToFontFamilies = {
|
|
25
|
+
'linux': {
|
|
26
|
+
'fontFamilies': {
|
|
27
|
+
'standard': 'Times New Roman',
|
|
28
|
+
'fixed': 'Monospace',
|
|
29
|
+
'serif': 'Times New Roman',
|
|
30
|
+
'sansSerif': 'Arial',
|
|
31
|
+
'cursive': 'Comic Sans MS',
|
|
32
|
+
'fantasy': 'Impact'
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
'mac': {
|
|
36
|
+
'fontFamilies': {
|
|
37
|
+
'standard': 'Times',
|
|
38
|
+
'fixed': 'Courier',
|
|
39
|
+
'serif': 'Times',
|
|
40
|
+
'sansSerif': 'Helvetica',
|
|
41
|
+
'cursive': 'Apple Chancery',
|
|
42
|
+
'fantasy': 'Papyrus'
|
|
43
|
+
},
|
|
44
|
+
'forScripts': [{
|
|
45
|
+
'script': 'jpan',
|
|
46
|
+
'fontFamilies': {
|
|
47
|
+
'standard': 'Hiragino Kaku Gothic ProN',
|
|
48
|
+
'fixed': 'Osaka-Mono',
|
|
49
|
+
'serif': 'Hiragino Mincho ProN',
|
|
50
|
+
'sansSerif': 'Hiragino Kaku Gothic ProN'
|
|
51
|
+
}
|
|
52
|
+
}, {
|
|
53
|
+
'script': 'hang',
|
|
54
|
+
'fontFamilies': {
|
|
55
|
+
'standard': 'Apple SD Gothic Neo',
|
|
56
|
+
'serif': 'AppleMyungjo',
|
|
57
|
+
'sansSerif': 'Apple SD Gothic Neo'
|
|
58
|
+
}
|
|
59
|
+
}, {
|
|
60
|
+
'script': 'hans',
|
|
61
|
+
'fontFamilies': {
|
|
62
|
+
'standard': ',PingFang SC,STHeiti',
|
|
63
|
+
'serif': 'Songti SC',
|
|
64
|
+
'sansSerif': ',PingFang SC,STHeiti',
|
|
65
|
+
'cursive': 'Kaiti SC'
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
'script': 'hant',
|
|
69
|
+
'fontFamilies': {
|
|
70
|
+
'standard': ',PingFang TC,Heiti TC',
|
|
71
|
+
'serif': 'Songti TC',
|
|
72
|
+
'sansSerif': ',PingFang TC,Heiti TC',
|
|
73
|
+
'cursive': 'Kaiti TC'
|
|
74
|
+
}
|
|
75
|
+
}]
|
|
76
|
+
},
|
|
77
|
+
'win': {
|
|
78
|
+
'fontFamilies': {
|
|
79
|
+
'standard': 'Times New Roman',
|
|
80
|
+
'fixed': 'Consolas',
|
|
81
|
+
'serif': 'Times New Roman',
|
|
82
|
+
'sansSerif': 'Arial',
|
|
83
|
+
'cursive': 'Comic Sans MS',
|
|
84
|
+
'fantasy': 'Impact'
|
|
85
|
+
},
|
|
86
|
+
'forScripts': [{
|
|
87
|
+
'script': 'cyrl',
|
|
88
|
+
'fontFamilies': {
|
|
89
|
+
'standard': 'Times New Roman',
|
|
90
|
+
'fixed': 'Courier New',
|
|
91
|
+
'serif': 'Times New Roman',
|
|
92
|
+
'sansSerif': 'Arial'
|
|
93
|
+
}
|
|
94
|
+
}, {
|
|
95
|
+
'script': 'arab',
|
|
96
|
+
'fontFamilies': {
|
|
97
|
+
'fixed': 'Courier New',
|
|
98
|
+
'sansSerif': 'Segoe UI'
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
'script': 'grek',
|
|
102
|
+
'fontFamilies': {
|
|
103
|
+
'standard': 'Times New Roman',
|
|
104
|
+
'fixed': 'Courier New',
|
|
105
|
+
'serif': 'Times New Roman',
|
|
106
|
+
'sansSerif': 'Arial'
|
|
107
|
+
}
|
|
108
|
+
}, {
|
|
109
|
+
'script': 'jpan',
|
|
110
|
+
'fontFamilies': {
|
|
111
|
+
'standard': ',Meiryo,Yu Gothic',
|
|
112
|
+
'fixed': 'MS Gothic',
|
|
113
|
+
'serif': ',Yu Mincho,MS PMincho',
|
|
114
|
+
'sansSerif': ',Meiryo,Yu Gothic'
|
|
115
|
+
}
|
|
116
|
+
}, {
|
|
117
|
+
'script': 'hang',
|
|
118
|
+
'fontFamilies': {
|
|
119
|
+
'standard': 'Malgun Gothic',
|
|
120
|
+
'fixed': 'Gulimche',
|
|
121
|
+
'serif': 'Batang',
|
|
122
|
+
'sansSerif': 'Malgun Gothic',
|
|
123
|
+
'cursive': 'Gungsuh'
|
|
124
|
+
}
|
|
125
|
+
}, {
|
|
126
|
+
'script': 'hans',
|
|
127
|
+
'fontFamilies': {
|
|
128
|
+
'standard': 'Microsoft YaHei',
|
|
129
|
+
'fixed': 'NSimsun',
|
|
130
|
+
'serif': 'Simsun',
|
|
131
|
+
'sansSerif': 'Microsoft YaHei',
|
|
132
|
+
'cursive': 'KaiTi'
|
|
133
|
+
}
|
|
134
|
+
}, {
|
|
135
|
+
'script': 'hant',
|
|
136
|
+
'fontFamilies': {
|
|
137
|
+
'standard': 'Microsoft JhengHei',
|
|
138
|
+
'fixed': 'MingLiU',
|
|
139
|
+
'serif': 'PMingLiU',
|
|
140
|
+
'sansSerif': 'Microsoft JhengHei',
|
|
141
|
+
'cursive': 'DFKai-SB'
|
|
142
|
+
}
|
|
143
|
+
}]
|
|
144
|
+
}
|
|
145
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.VideoRecorder = void 0;
|
|
7
|
+
var _utils = require("../../utils");
|
|
8
|
+
var _page = require("../page");
|
|
9
|
+
var _processLauncher = require("../../utils/processLauncher");
|
|
10
|
+
var _progress = require("../progress");
|
|
11
|
+
var _instrumentation = require("../instrumentation");
|
|
12
|
+
/**
|
|
13
|
+
* Copyright (c) Microsoft Corporation.
|
|
14
|
+
*
|
|
15
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
16
|
+
* you may not use this file except in compliance with the License.
|
|
17
|
+
* You may obtain a copy of the License at
|
|
18
|
+
*
|
|
19
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
20
|
+
*
|
|
21
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
22
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
23
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24
|
+
* See the License for the specific language governing permissions and
|
|
25
|
+
* limitations under the License.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const fps = 25;
|
|
29
|
+
class VideoRecorder {
|
|
30
|
+
static async launch(page, ffmpegPath, options) {
|
|
31
|
+
if (!options.outputFile.endsWith('.webm')) throw new Error('File must have .webm extension');
|
|
32
|
+
const controller = new _progress.ProgressController((0, _instrumentation.serverSideCallMetadata)(), page);
|
|
33
|
+
controller.setLogName('browser');
|
|
34
|
+
return await controller.run(async progress => {
|
|
35
|
+
const recorder = new VideoRecorder(page, ffmpegPath, progress);
|
|
36
|
+
await recorder._launch(options);
|
|
37
|
+
return recorder;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
constructor(page, ffmpegPath, progress) {
|
|
41
|
+
this._process = null;
|
|
42
|
+
this._gracefullyClose = null;
|
|
43
|
+
this._lastWritePromise = Promise.resolve();
|
|
44
|
+
this._lastFrameTimestamp = 0;
|
|
45
|
+
this._lastFrameBuffer = null;
|
|
46
|
+
this._lastWriteTimestamp = 0;
|
|
47
|
+
this._progress = void 0;
|
|
48
|
+
this._frameQueue = [];
|
|
49
|
+
this._isStopped = false;
|
|
50
|
+
this._ffmpegPath = void 0;
|
|
51
|
+
this._progress = progress;
|
|
52
|
+
this._ffmpegPath = ffmpegPath;
|
|
53
|
+
page.on(_page.Page.Events.ScreencastFrame, frame => this.writeFrame(frame.buffer, frame.timestamp));
|
|
54
|
+
}
|
|
55
|
+
async _launch(options) {
|
|
56
|
+
// How to tune the codec:
|
|
57
|
+
// 1. Read vp8 documentation to figure out the options.
|
|
58
|
+
// https://www.webmproject.org/docs/encoder-parameters/
|
|
59
|
+
// 2. Use the following command to map the options to ffmpeg arguments.
|
|
60
|
+
// $ ./third_party/ffmpeg/ffmpeg-mac -h encoder=vp8
|
|
61
|
+
// 3. A bit more about passing vp8 options to ffmpeg.
|
|
62
|
+
// https://trac.ffmpeg.org/wiki/Encode/VP8
|
|
63
|
+
// 4. Tuning for VP9:
|
|
64
|
+
// https://developers.google.com/media/vp9/live-encoding
|
|
65
|
+
//
|
|
66
|
+
// How to stress-test video recording (runs 10 recorders in parallel to book all cpus available):
|
|
67
|
+
// $ node ./utils/video_stress.js
|
|
68
|
+
//
|
|
69
|
+
// We use the following vp8 options:
|
|
70
|
+
// "-qmin 0 -qmax 50" - quality variation from 0 to 50.
|
|
71
|
+
// Suggested here: https://trac.ffmpeg.org/wiki/Encode/VP8
|
|
72
|
+
// "-crf 8" - constant quality mode, 4-63, lower means better quality.
|
|
73
|
+
// "-deadline realtime -speed 8" - do not use too much cpu to keep up with incoming frames.
|
|
74
|
+
// "-b:v 1M" - video bitrate. Default value is too low for vp8
|
|
75
|
+
// Suggested here: https://trac.ffmpeg.org/wiki/Encode/VP8
|
|
76
|
+
// Note that we can switch to "-qmin 20 -qmax 50 -crf 30" for smaller video size but worse quality.
|
|
77
|
+
//
|
|
78
|
+
// We use "pad" and "crop" video filters (-vf option) to resize incoming frames
|
|
79
|
+
// that might be of the different size to the desired video size.
|
|
80
|
+
// https://ffmpeg.org/ffmpeg-filters.html#pad-1
|
|
81
|
+
// https://ffmpeg.org/ffmpeg-filters.html#crop
|
|
82
|
+
//
|
|
83
|
+
// We use "image2pipe" mode to pipe frames and get a single video - https://trac.ffmpeg.org/wiki/Slideshow
|
|
84
|
+
// "-f image2pipe -c:v mjpeg -i -" forces input to be read from standard input, and forces
|
|
85
|
+
// mjpeg input image format.
|
|
86
|
+
// "-avioflags direct" reduces general buffering.
|
|
87
|
+
// "-fpsprobesize 0 -probesize 32 -analyzeduration 0" reduces initial buffering
|
|
88
|
+
// while analyzing input fps and other stats.
|
|
89
|
+
//
|
|
90
|
+
// "-y" means overwrite output.
|
|
91
|
+
// "-an" means no audio.
|
|
92
|
+
// "-threads 1" means using one thread. This drastically reduces stalling when
|
|
93
|
+
// cpu is overbooked. By default vp8 tries to use all available threads?
|
|
94
|
+
|
|
95
|
+
const w = options.width;
|
|
96
|
+
const h = options.height;
|
|
97
|
+
const args = `-loglevel error -f image2pipe -avioflags direct -fpsprobesize 0 -probesize 32 -analyzeduration 0 -c:v mjpeg -i - -y -an -r ${fps} -c:v vp8 -qmin 0 -qmax 50 -crf 8 -deadline realtime -speed 8 -b:v 1M -threads 1 -vf pad=${w}:${h}:0:0:gray,crop=${w}:${h}:0:0`.split(' ');
|
|
98
|
+
args.push(options.outputFile);
|
|
99
|
+
const progress = this._progress;
|
|
100
|
+
const {
|
|
101
|
+
launchedProcess,
|
|
102
|
+
gracefullyClose
|
|
103
|
+
} = await (0, _processLauncher.launchProcess)({
|
|
104
|
+
command: this._ffmpegPath,
|
|
105
|
+
args,
|
|
106
|
+
stdio: 'stdin',
|
|
107
|
+
log: message => progress.log(message),
|
|
108
|
+
tempDirectories: [],
|
|
109
|
+
attemptToGracefullyClose: async () => {
|
|
110
|
+
progress.log('Closing stdin...');
|
|
111
|
+
launchedProcess.stdin.end();
|
|
112
|
+
},
|
|
113
|
+
onExit: (exitCode, signal) => {
|
|
114
|
+
progress.log(`ffmpeg onkill exitCode=${exitCode} signal=${signal}`);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
launchedProcess.stdin.on('finish', () => {
|
|
118
|
+
progress.log('ffmpeg finished input.');
|
|
119
|
+
});
|
|
120
|
+
launchedProcess.stdin.on('error', () => {
|
|
121
|
+
progress.log('ffmpeg error.');
|
|
122
|
+
});
|
|
123
|
+
this._process = launchedProcess;
|
|
124
|
+
this._gracefullyClose = gracefullyClose;
|
|
125
|
+
}
|
|
126
|
+
writeFrame(frame, timestamp) {
|
|
127
|
+
(0, _utils.assert)(this._process);
|
|
128
|
+
if (this._isStopped) return;
|
|
129
|
+
if (this._lastFrameBuffer) {
|
|
130
|
+
const durationSec = timestamp - this._lastFrameTimestamp;
|
|
131
|
+
const repeatCount = Math.max(1, Math.round(fps * durationSec));
|
|
132
|
+
for (let i = 0; i < repeatCount; ++i) this._frameQueue.push(this._lastFrameBuffer);
|
|
133
|
+
this._lastWritePromise = this._lastWritePromise.then(() => this._sendFrames());
|
|
134
|
+
}
|
|
135
|
+
this._lastFrameBuffer = frame;
|
|
136
|
+
this._lastFrameTimestamp = timestamp;
|
|
137
|
+
this._lastWriteTimestamp = (0, _utils.monotonicTime)();
|
|
138
|
+
}
|
|
139
|
+
async _sendFrames() {
|
|
140
|
+
while (this._frameQueue.length) await this._sendFrame(this._frameQueue.shift());
|
|
141
|
+
}
|
|
142
|
+
async _sendFrame(frame) {
|
|
143
|
+
return new Promise(f => this._process.stdin.write(frame, f)).then(error => {
|
|
144
|
+
if (error) this._progress.log(`ffmpeg failed to write: ${String(error)}`);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
async stop() {
|
|
148
|
+
if (this._isStopped) return;
|
|
149
|
+
this.writeFrame(Buffer.from([]), this._lastFrameTimestamp + ((0, _utils.monotonicTime)() - this._lastWriteTimestamp) / 1000);
|
|
150
|
+
this._isStopped = true;
|
|
151
|
+
await this._lastWritePromise;
|
|
152
|
+
await this._gracefullyClose();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.VideoRecorder = VideoRecorder;
|