@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.
Files changed (305) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +3 -0
  4. package/ThirdPartyNotices.txt +1513 -0
  5. package/bin/PrintDeps.exe +0 -0
  6. package/bin/README.md +2 -0
  7. package/bin/install_media_pack.ps1 +5 -0
  8. package/bin/reinstall_chrome_beta_linux.sh +40 -0
  9. package/bin/reinstall_chrome_beta_mac.sh +13 -0
  10. package/bin/reinstall_chrome_beta_win.ps1 +23 -0
  11. package/bin/reinstall_chrome_stable_linux.sh +40 -0
  12. package/bin/reinstall_chrome_stable_mac.sh +12 -0
  13. package/bin/reinstall_chrome_stable_win.ps1 +23 -0
  14. package/bin/reinstall_msedge_beta_linux.sh +40 -0
  15. package/bin/reinstall_msedge_beta_mac.sh +11 -0
  16. package/bin/reinstall_msedge_beta_win.ps1 +22 -0
  17. package/bin/reinstall_msedge_dev_linux.sh +40 -0
  18. package/bin/reinstall_msedge_dev_mac.sh +11 -0
  19. package/bin/reinstall_msedge_dev_win.ps1 +22 -0
  20. package/bin/reinstall_msedge_stable_linux.sh +40 -0
  21. package/bin/reinstall_msedge_stable_mac.sh +11 -0
  22. package/bin/reinstall_msedge_stable_win.ps1 +23 -0
  23. package/browsers.json +64 -0
  24. package/cli.js +17 -0
  25. package/index.d.ts +17 -0
  26. package/index.js +33 -0
  27. package/index.mjs +28 -0
  28. package/lib/androidServerImpl.js +69 -0
  29. package/lib/browserServerImpl.js +92 -0
  30. package/lib/cli/driver.js +97 -0
  31. package/lib/cli/program.js +582 -0
  32. package/lib/cli/programWithTestStub.js +67 -0
  33. package/lib/client/accessibility.js +50 -0
  34. package/lib/client/android.js +473 -0
  35. package/lib/client/api.js +272 -0
  36. package/lib/client/artifact.js +79 -0
  37. package/lib/client/browser.js +145 -0
  38. package/lib/client/browserContext.js +509 -0
  39. package/lib/client/browserType.js +233 -0
  40. package/lib/client/cdpSession.js +53 -0
  41. package/lib/client/channelOwner.js +229 -0
  42. package/lib/client/clientHelper.js +57 -0
  43. package/lib/client/clientInstrumentation.js +40 -0
  44. package/lib/client/connection.js +327 -0
  45. package/lib/client/consoleMessage.js +55 -0
  46. package/lib/client/coverage.js +41 -0
  47. package/lib/client/dialog.js +57 -0
  48. package/lib/client/download.js +62 -0
  49. package/lib/client/electron.js +130 -0
  50. package/lib/client/elementHandle.js +291 -0
  51. package/lib/client/errors.js +77 -0
  52. package/lib/client/events.js +93 -0
  53. package/lib/client/fetch.js +343 -0
  54. package/lib/client/fileChooser.js +45 -0
  55. package/lib/client/frame.js +506 -0
  56. package/lib/client/harRouter.js +93 -0
  57. package/lib/client/input.js +111 -0
  58. package/lib/client/jsHandle.js +123 -0
  59. package/lib/client/jsonPipe.js +35 -0
  60. package/lib/client/localUtils.js +35 -0
  61. package/lib/client/locator.js +432 -0
  62. package/lib/client/network.js +601 -0
  63. package/lib/client/page.js +707 -0
  64. package/lib/client/playwright.js +74 -0
  65. package/lib/client/selectors.js +67 -0
  66. package/lib/client/stream.js +54 -0
  67. package/lib/client/tracing.js +135 -0
  68. package/lib/client/types.js +24 -0
  69. package/lib/client/video.js +51 -0
  70. package/lib/client/waiter.js +158 -0
  71. package/lib/client/webError.js +37 -0
  72. package/lib/client/worker.js +71 -0
  73. package/lib/client/writableStream.js +54 -0
  74. package/lib/common/socksProxy.js +569 -0
  75. package/lib/common/timeoutSettings.js +73 -0
  76. package/lib/common/types.js +5 -0
  77. package/lib/generated/consoleApiSource.js +7 -0
  78. package/lib/generated/injectedScriptSource.js +7 -0
  79. package/lib/generated/recorderSource.js +7 -0
  80. package/lib/generated/utilityScriptSource.js +7 -0
  81. package/lib/image_tools/colorUtils.js +98 -0
  82. package/lib/image_tools/compare.js +108 -0
  83. package/lib/image_tools/imageChannel.js +70 -0
  84. package/lib/image_tools/stats.js +102 -0
  85. package/lib/inProcessFactory.js +54 -0
  86. package/lib/inprocess.js +20 -0
  87. package/lib/outofprocess.js +67 -0
  88. package/lib/protocol/debug.js +27 -0
  89. package/lib/protocol/serializers.js +172 -0
  90. package/lib/protocol/transport.js +82 -0
  91. package/lib/protocol/validator.js +2599 -0
  92. package/lib/protocol/validatorPrimitives.js +139 -0
  93. package/lib/remote/playwrightConnection.js +274 -0
  94. package/lib/remote/playwrightServer.js +110 -0
  95. package/lib/server/accessibility.js +62 -0
  96. package/lib/server/android/android.js +441 -0
  97. package/lib/server/android/backendAdb.js +172 -0
  98. package/lib/server/artifact.js +104 -0
  99. package/lib/server/browser.js +129 -0
  100. package/lib/server/browserContext.js +609 -0
  101. package/lib/server/browserType.js +300 -0
  102. package/lib/server/chromium/appIcon.png +0 -0
  103. package/lib/server/chromium/chromium.js +346 -0
  104. package/lib/server/chromium/chromiumSwitches.js +41 -0
  105. package/lib/server/chromium/crAccessibility.js +237 -0
  106. package/lib/server/chromium/crBrowser.js +521 -0
  107. package/lib/server/chromium/crConnection.js +228 -0
  108. package/lib/server/chromium/crCoverage.js +246 -0
  109. package/lib/server/chromium/crDevTools.js +104 -0
  110. package/lib/server/chromium/crDragDrop.js +144 -0
  111. package/lib/server/chromium/crExecutionContext.js +156 -0
  112. package/lib/server/chromium/crInput.js +171 -0
  113. package/lib/server/chromium/crNetworkManager.js +723 -0
  114. package/lib/server/chromium/crPage.js +1173 -0
  115. package/lib/server/chromium/crPdf.js +147 -0
  116. package/lib/server/chromium/crProtocolHelper.js +131 -0
  117. package/lib/server/chromium/crServiceWorker.js +115 -0
  118. package/lib/server/chromium/defaultFontFamilies.js +145 -0
  119. package/lib/server/chromium/videoRecorder.js +155 -0
  120. package/lib/server/console.js +59 -0
  121. package/lib/server/cookieStore.js +112 -0
  122. package/lib/server/debugController.js +236 -0
  123. package/lib/server/debugger.js +132 -0
  124. package/lib/server/deviceDescriptors.js +21 -0
  125. package/lib/server/deviceDescriptorsSource.json +1549 -0
  126. package/lib/server/dialog.js +70 -0
  127. package/lib/server/dispatchers/androidDispatcher.js +193 -0
  128. package/lib/server/dispatchers/artifactDispatcher.js +118 -0
  129. package/lib/server/dispatchers/browserContextDispatcher.js +306 -0
  130. package/lib/server/dispatchers/browserDispatcher.js +170 -0
  131. package/lib/server/dispatchers/browserTypeDispatcher.js +55 -0
  132. package/lib/server/dispatchers/cdpSessionDispatcher.js +48 -0
  133. package/lib/server/dispatchers/debugControllerDispatcher.js +103 -0
  134. package/lib/server/dispatchers/dialogDispatcher.js +44 -0
  135. package/lib/server/dispatchers/dispatcher.js +400 -0
  136. package/lib/server/dispatchers/electronDispatcher.js +80 -0
  137. package/lib/server/dispatchers/elementHandlerDispatcher.js +228 -0
  138. package/lib/server/dispatchers/frameDispatcher.js +287 -0
  139. package/lib/server/dispatchers/jsHandleDispatcher.js +102 -0
  140. package/lib/server/dispatchers/jsonPipeDispatcher.js +61 -0
  141. package/lib/server/dispatchers/localUtilsDispatcher.js +399 -0
  142. package/lib/server/dispatchers/networkDispatchers.js +221 -0
  143. package/lib/server/dispatchers/pageDispatcher.js +363 -0
  144. package/lib/server/dispatchers/playwrightDispatcher.js +105 -0
  145. package/lib/server/dispatchers/selectorsDispatcher.js +36 -0
  146. package/lib/server/dispatchers/streamDispatcher.js +62 -0
  147. package/lib/server/dispatchers/tracingDispatcher.js +54 -0
  148. package/lib/server/dispatchers/writableStreamDispatcher.js +55 -0
  149. package/lib/server/dom.js +808 -0
  150. package/lib/server/download.js +53 -0
  151. package/lib/server/electron/electron.js +254 -0
  152. package/lib/server/electron/loader.js +57 -0
  153. package/lib/server/errors.js +68 -0
  154. package/lib/server/fetch.js +611 -0
  155. package/lib/server/fileChooser.js +42 -0
  156. package/lib/server/fileUploadUtils.js +71 -0
  157. package/lib/server/firefox/ffAccessibility.js +215 -0
  158. package/lib/server/firefox/ffBrowser.js +447 -0
  159. package/lib/server/firefox/ffConnection.js +168 -0
  160. package/lib/server/firefox/ffExecutionContext.js +138 -0
  161. package/lib/server/firefox/ffInput.js +150 -0
  162. package/lib/server/firefox/ffNetworkManager.js +231 -0
  163. package/lib/server/firefox/ffPage.js +558 -0
  164. package/lib/server/firefox/firefox.js +91 -0
  165. package/lib/server/formData.js +75 -0
  166. package/lib/server/frameSelectors.js +171 -0
  167. package/lib/server/frames.js +1597 -0
  168. package/lib/server/har/harRecorder.js +139 -0
  169. package/lib/server/har/harTracer.js +539 -0
  170. package/lib/server/helper.js +103 -0
  171. package/lib/server/index.js +96 -0
  172. package/lib/server/input.js +301 -0
  173. package/lib/server/instrumentation.js +74 -0
  174. package/lib/server/isomorphic/utilityScriptSerializers.js +212 -0
  175. package/lib/server/javascript.js +305 -0
  176. package/lib/server/launchApp.js +90 -0
  177. package/lib/server/macEditingCommands.js +139 -0
  178. package/lib/server/network.js +607 -0
  179. package/lib/server/page.js +793 -0
  180. package/lib/server/pipeTransport.js +85 -0
  181. package/lib/server/playwright.js +82 -0
  182. package/lib/server/progress.js +102 -0
  183. package/lib/server/protocolError.js +49 -0
  184. package/lib/server/recorder/codeGenerator.js +153 -0
  185. package/lib/server/recorder/csharp.js +310 -0
  186. package/lib/server/recorder/java.js +216 -0
  187. package/lib/server/recorder/javascript.js +229 -0
  188. package/lib/server/recorder/jsonl.js +47 -0
  189. package/lib/server/recorder/language.js +44 -0
  190. package/lib/server/recorder/python.js +275 -0
  191. package/lib/server/recorder/recorderActions.js +5 -0
  192. package/lib/server/recorder/recorderApp.js +181 -0
  193. package/lib/server/recorder/recorderUtils.js +48 -0
  194. package/lib/server/recorder/utils.js +45 -0
  195. package/lib/server/recorder.js +700 -0
  196. package/lib/server/registry/browserFetcher.js +168 -0
  197. package/lib/server/registry/dependencies.js +322 -0
  198. package/lib/server/registry/index.js +925 -0
  199. package/lib/server/registry/nativeDeps.js +383 -0
  200. package/lib/server/registry/oopDownloadBrowserMain.js +138 -0
  201. package/lib/server/screenshotter.js +354 -0
  202. package/lib/server/selectors.js +73 -0
  203. package/lib/server/socksInterceptor.js +100 -0
  204. package/lib/server/trace/recorder/snapshotter.js +168 -0
  205. package/lib/server/trace/recorder/snapshotterInjected.js +493 -0
  206. package/lib/server/trace/recorder/tracing.js +552 -0
  207. package/lib/server/trace/test/inMemorySnapshotter.js +93 -0
  208. package/lib/server/trace/viewer/traceViewer.js +229 -0
  209. package/lib/server/transport.js +191 -0
  210. package/lib/server/types.js +24 -0
  211. package/lib/server/usKeyboardLayout.js +555 -0
  212. package/lib/server/webkit/webkit.js +87 -0
  213. package/lib/server/webkit/wkAccessibility.js +194 -0
  214. package/lib/server/webkit/wkBrowser.js +328 -0
  215. package/lib/server/webkit/wkConnection.js +173 -0
  216. package/lib/server/webkit/wkExecutionContext.js +146 -0
  217. package/lib/server/webkit/wkInput.js +169 -0
  218. package/lib/server/webkit/wkInterceptableRequest.js +158 -0
  219. package/lib/server/webkit/wkPage.js +1198 -0
  220. package/lib/server/webkit/wkProvisionalPage.js +59 -0
  221. package/lib/server/webkit/wkWorkers.js +104 -0
  222. package/lib/third_party/diff_match_patch.js +2222 -0
  223. package/lib/third_party/pixelmatch.js +255 -0
  224. package/lib/utils/ascii.js +31 -0
  225. package/lib/utils/comparators.js +171 -0
  226. package/lib/utils/crypto.js +33 -0
  227. package/lib/utils/debug.js +46 -0
  228. package/lib/utils/debugLogger.js +89 -0
  229. package/lib/utils/env.js +47 -0
  230. package/lib/utils/eventsHelper.js +38 -0
  231. package/lib/utils/fileUtils.js +66 -0
  232. package/lib/utils/glob.js +83 -0
  233. package/lib/utils/happy-eyeballs.js +154 -0
  234. package/lib/utils/headers.js +52 -0
  235. package/lib/utils/hostPlatform.js +124 -0
  236. package/lib/utils/httpServer.js +195 -0
  237. package/lib/utils/index.js +324 -0
  238. package/lib/utils/isomorphic/cssParser.js +250 -0
  239. package/lib/utils/isomorphic/cssTokenizer.js +979 -0
  240. package/lib/utils/isomorphic/locatorGenerators.js +651 -0
  241. package/lib/utils/isomorphic/locatorParser.js +179 -0
  242. package/lib/utils/isomorphic/locatorUtils.js +62 -0
  243. package/lib/utils/isomorphic/selectorParser.js +397 -0
  244. package/lib/utils/isomorphic/stringUtils.js +107 -0
  245. package/lib/utils/isomorphic/traceUtils.js +39 -0
  246. package/lib/utils/linuxUtils.js +78 -0
  247. package/lib/utils/manualPromise.js +109 -0
  248. package/lib/utils/mimeType.js +29 -0
  249. package/lib/utils/multimap.js +75 -0
  250. package/lib/utils/network.js +189 -0
  251. package/lib/utils/processLauncher.js +248 -0
  252. package/lib/utils/profiler.js +53 -0
  253. package/lib/utils/rtti.js +41 -0
  254. package/lib/utils/semaphore.js +51 -0
  255. package/lib/utils/spawnAsync.js +45 -0
  256. package/lib/utils/stackTrace.js +123 -0
  257. package/lib/utils/task.js +58 -0
  258. package/lib/utils/time.js +37 -0
  259. package/lib/utils/timeoutRunner.js +131 -0
  260. package/lib/utils/traceUtils.js +44 -0
  261. package/lib/utils/userAgent.js +105 -0
  262. package/lib/utils/wsServer.js +125 -0
  263. package/lib/utils/zipFile.js +75 -0
  264. package/lib/utils/zones.js +99 -0
  265. package/lib/utilsBundle.js +81 -0
  266. package/lib/utilsBundleImpl/index.js +51 -0
  267. package/lib/utilsBundleImpl/xdg-open +1066 -0
  268. package/lib/vite/htmlReport/index.html +66 -0
  269. package/lib/vite/recorder/assets/codeMirrorModule-Hs9-1ZG4.css +1 -0
  270. package/lib/vite/recorder/assets/codeMirrorModule-I9ks4y7D.js +24 -0
  271. package/lib/vite/recorder/assets/codicon-zGuYmc9o.ttf +0 -0
  272. package/lib/vite/recorder/assets/index-ljsTwXtJ.css +1 -0
  273. package/lib/vite/recorder/assets/index-yg8ypzl6.js +47 -0
  274. package/lib/vite/recorder/index.html +29 -0
  275. package/lib/vite/recorder/playwright-logo.svg +9 -0
  276. package/lib/vite/traceViewer/assets/codeMirrorModule-GluP1cQ1.js +24 -0
  277. package/lib/vite/traceViewer/assets/codeMirrorModule-fqJB1XDu.js +24 -0
  278. package/lib/vite/traceViewer/assets/codeMirrorModule-y3M3aAqy.js +24 -0
  279. package/lib/vite/traceViewer/assets/wsPort-Rvwd4WC-.js +69 -0
  280. package/lib/vite/traceViewer/assets/wsPort-dlD7vDkY.js +69 -0
  281. package/lib/vite/traceViewer/assets/wsPort-qOE2NWrO.js +69 -0
  282. package/lib/vite/traceViewer/assets/xtermModule-Yt6xwiJ_.js +9 -0
  283. package/lib/vite/traceViewer/codeMirrorModule.Hs9-1ZG4.css +1 -0
  284. package/lib/vite/traceViewer/codicon.zGuYmc9o.ttf +0 -0
  285. package/lib/vite/traceViewer/index.-g_5lMbJ.css +1 -0
  286. package/lib/vite/traceViewer/index.4X7zDysg.js +2 -0
  287. package/lib/vite/traceViewer/index.HkJgzlGy.js +2 -0
  288. package/lib/vite/traceViewer/index.html +26 -0
  289. package/lib/vite/traceViewer/index.kRjx5sAJ.js +2 -0
  290. package/lib/vite/traceViewer/playwright-logo.svg +9 -0
  291. package/lib/vite/traceViewer/snapshot.html +21 -0
  292. package/lib/vite/traceViewer/sw.bundle.js +4 -0
  293. package/lib/vite/traceViewer/uiMode.1Wcp_Kto.js +10 -0
  294. package/lib/vite/traceViewer/uiMode.GTNzARcV.js +10 -0
  295. package/lib/vite/traceViewer/uiMode.html +17 -0
  296. package/lib/vite/traceViewer/uiMode.pWy0Re7G.css +1 -0
  297. package/lib/vite/traceViewer/uiMode.zV-7Lf9v.js +10 -0
  298. package/lib/vite/traceViewer/wsPort.kSgQKQ0y.css +1 -0
  299. package/lib/vite/traceViewer/xtermModule.0lwXJFHT.css +32 -0
  300. package/lib/zipBundle.js +25 -0
  301. package/lib/zipBundleImpl.js +5 -0
  302. package/package.json +43 -0
  303. package/types/protocol.d.ts +20304 -0
  304. package/types/structs.d.ts +45 -0
  305. 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;