@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,354 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Screenshotter = void 0;
7
+ exports.validateScreenshotOptions = validateScreenshotOptions;
8
+ var _helper = require("./helper");
9
+ var _utils = require("../utils");
10
+ var _multimap = require("../utils/multimap");
11
+ /**
12
+ * Copyright 2019 Google Inc. All rights reserved.
13
+ * Modifications 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
+ function inPagePrepareForScreenshots(screenshotStyle, hideCaret, disableAnimations, syncAnimations) {
29
+ // In WebKit, sync the animations.
30
+ if (syncAnimations) {
31
+ const style = document.createElement('style');
32
+ style.textContent = 'body {}';
33
+ document.head.appendChild(style);
34
+ document.documentElement.getBoundingClientRect();
35
+ style.remove();
36
+ }
37
+ if (!screenshotStyle && !hideCaret && !disableAnimations) return;
38
+ const collectRoots = (root, roots = []) => {
39
+ roots.push(root);
40
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
41
+ do {
42
+ const node = walker.currentNode;
43
+ const shadowRoot = node instanceof Element ? node.shadowRoot : null;
44
+ if (shadowRoot) collectRoots(shadowRoot, roots);
45
+ } while (walker.nextNode());
46
+ return roots;
47
+ };
48
+ const roots = collectRoots(document);
49
+ const cleanupCallbacks = [];
50
+ if (screenshotStyle) {
51
+ for (const root of roots) {
52
+ const styleTag = document.createElement('style');
53
+ styleTag.textContent = screenshotStyle;
54
+ if (root === document) document.documentElement.append(styleTag);else root.append(styleTag);
55
+ cleanupCallbacks.push(() => {
56
+ styleTag.remove();
57
+ });
58
+ }
59
+ }
60
+ if (hideCaret) {
61
+ const elements = new Map();
62
+ for (const root of roots) {
63
+ root.querySelectorAll('input,textarea,[contenteditable]').forEach(element => {
64
+ elements.set(element, {
65
+ value: element.style.getPropertyValue('caret-color'),
66
+ priority: element.style.getPropertyPriority('caret-color')
67
+ });
68
+ element.style.setProperty('caret-color', 'transparent', 'important');
69
+ });
70
+ }
71
+ cleanupCallbacks.push(() => {
72
+ for (const [element, value] of elements) element.style.setProperty('caret-color', value.value, value.priority);
73
+ });
74
+ }
75
+ if (disableAnimations) {
76
+ const infiniteAnimationsToResume = new Set();
77
+ const handleAnimations = root => {
78
+ for (const animation of root.getAnimations()) {
79
+ if (!animation.effect || animation.playbackRate === 0 || infiniteAnimationsToResume.has(animation)) continue;
80
+ const endTime = animation.effect.getComputedTiming().endTime;
81
+ if (Number.isFinite(endTime)) {
82
+ try {
83
+ animation.finish();
84
+ } catch (e) {
85
+ // animation.finish() should not throw for
86
+ // finite animations, but we'd like to be on the
87
+ // safe side.
88
+ }
89
+ } else {
90
+ try {
91
+ animation.cancel();
92
+ infiniteAnimationsToResume.add(animation);
93
+ } catch (e) {
94
+ // animation.cancel() should not throw for
95
+ // infinite animations, but we'd like to be on the
96
+ // safe side.
97
+ }
98
+ }
99
+ }
100
+ };
101
+ for (const root of roots) {
102
+ const handleRootAnimations = handleAnimations.bind(null, root);
103
+ handleRootAnimations();
104
+ root.addEventListener('transitionrun', handleRootAnimations);
105
+ root.addEventListener('animationstart', handleRootAnimations);
106
+ cleanupCallbacks.push(() => {
107
+ root.removeEventListener('transitionrun', handleRootAnimations);
108
+ root.removeEventListener('animationstart', handleRootAnimations);
109
+ });
110
+ }
111
+ cleanupCallbacks.push(() => {
112
+ for (const animation of infiniteAnimationsToResume) {
113
+ try {
114
+ animation.play();
115
+ } catch (e) {
116
+ // animation.play() should never throw, but
117
+ // we'd like to be on the safe side.
118
+ }
119
+ }
120
+ });
121
+ }
122
+ window.__pwCleanupScreenshot = () => {
123
+ for (const cleanupCallback of cleanupCallbacks) cleanupCallback();
124
+ delete window.__pwCleanupScreenshot;
125
+ };
126
+ }
127
+ class Screenshotter {
128
+ constructor(page) {
129
+ this._queue = new TaskQueue();
130
+ this._page = void 0;
131
+ this._page = page;
132
+ this._queue = new TaskQueue();
133
+ }
134
+ async _originalViewportSize(progress) {
135
+ const originalViewportSize = this._page.viewportSize();
136
+ let viewportSize = originalViewportSize;
137
+ if (!viewportSize) viewportSize = await this._page.mainFrame().waitForFunctionValueInUtility(progress, () => ({
138
+ width: window.innerWidth,
139
+ height: window.innerHeight
140
+ }));
141
+ return {
142
+ viewportSize,
143
+ originalViewportSize
144
+ };
145
+ }
146
+ async _fullPageSize(progress) {
147
+ const fullPageSize = await this._page.mainFrame().waitForFunctionValueInUtility(progress, () => {
148
+ if (!document.body || !document.documentElement) return null;
149
+ return {
150
+ width: Math.max(document.body.scrollWidth, document.documentElement.scrollWidth, document.body.offsetWidth, document.documentElement.offsetWidth, document.body.clientWidth, document.documentElement.clientWidth),
151
+ height: Math.max(document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.body.clientHeight, document.documentElement.clientHeight)
152
+ };
153
+ });
154
+ return fullPageSize;
155
+ }
156
+ async screenshotPage(progress, options) {
157
+ const format = validateScreenshotOptions(options);
158
+ return this._queue.postTask(async () => {
159
+ progress.log('taking page screenshot');
160
+ const {
161
+ viewportSize
162
+ } = await this._originalViewportSize(progress);
163
+ await this._preparePageForScreenshot(progress, options.style, options.caret !== 'initial', options.animations === 'disabled');
164
+ progress.throwIfAborted(); // Avoid restoring after failure - should be done by cleanup.
165
+
166
+ if (options.fullPage) {
167
+ const fullPageSize = await this._fullPageSize(progress);
168
+ let documentRect = {
169
+ x: 0,
170
+ y: 0,
171
+ width: fullPageSize.width,
172
+ height: fullPageSize.height
173
+ };
174
+ const fitsViewport = fullPageSize.width <= viewportSize.width && fullPageSize.height <= viewportSize.height;
175
+ if (options.clip) documentRect = trimClipToSize(options.clip, documentRect);
176
+ const buffer = await this._screenshot(progress, format, documentRect, undefined, fitsViewport, options);
177
+ progress.throwIfAborted(); // Avoid restoring after failure - should be done by cleanup.
178
+ await this._restorePageAfterScreenshot();
179
+ return buffer;
180
+ }
181
+ const viewportRect = options.clip ? trimClipToSize(options.clip, viewportSize) : {
182
+ x: 0,
183
+ y: 0,
184
+ ...viewportSize
185
+ };
186
+ const buffer = await this._screenshot(progress, format, undefined, viewportRect, true, options);
187
+ progress.throwIfAborted(); // Avoid restoring after failure - should be done by cleanup.
188
+ await this._restorePageAfterScreenshot();
189
+ return buffer;
190
+ });
191
+ }
192
+ async screenshotElement(progress, handle, options) {
193
+ const format = validateScreenshotOptions(options);
194
+ return this._queue.postTask(async () => {
195
+ progress.log('taking element screenshot');
196
+ const {
197
+ viewportSize
198
+ } = await this._originalViewportSize(progress);
199
+ await this._preparePageForScreenshot(progress, options.style, options.caret !== 'initial', options.animations === 'disabled');
200
+ progress.throwIfAborted(); // Do not do extra work.
201
+
202
+ await handle._waitAndScrollIntoViewIfNeeded(progress, true /* waitForVisible */);
203
+ progress.throwIfAborted(); // Do not do extra work.
204
+ const boundingBox = await handle.boundingBox();
205
+ (0, _utils.assert)(boundingBox, 'Node is either not visible or not an HTMLElement');
206
+ (0, _utils.assert)(boundingBox.width !== 0, 'Node has 0 width.');
207
+ (0, _utils.assert)(boundingBox.height !== 0, 'Node has 0 height.');
208
+ const fitsViewport = boundingBox.width <= viewportSize.width && boundingBox.height <= viewportSize.height;
209
+ progress.throwIfAborted(); // Avoid extra work.
210
+ const scrollOffset = await this._page.mainFrame().waitForFunctionValueInUtility(progress, () => ({
211
+ x: window.scrollX,
212
+ y: window.scrollY
213
+ }));
214
+ const documentRect = {
215
+ ...boundingBox
216
+ };
217
+ documentRect.x += scrollOffset.x;
218
+ documentRect.y += scrollOffset.y;
219
+ const buffer = await this._screenshot(progress, format, _helper.helper.enclosingIntRect(documentRect), undefined, fitsViewport, options);
220
+ progress.throwIfAborted(); // Avoid restoring after failure - should be done by cleanup.
221
+ await this._restorePageAfterScreenshot();
222
+ return buffer;
223
+ });
224
+ }
225
+ async _preparePageForScreenshot(progress, screenshotStyle, hideCaret, disableAnimations) {
226
+ if (disableAnimations) progress.log(' disabled all CSS animations');
227
+ const syncAnimations = this._page._delegate.shouldToggleStyleSheetToSyncAnimations();
228
+ await Promise.all(this._page.frames().map(async frame => {
229
+ await frame.nonStallingEvaluateInExistingContext('(' + inPagePrepareForScreenshots.toString() + `)(${JSON.stringify(screenshotStyle)}, ${hideCaret}, ${disableAnimations}, ${syncAnimations})`, false, 'utility').catch(() => {});
230
+ }));
231
+ if (!process.env.PW_TEST_SCREENSHOT_NO_FONTS_READY) {
232
+ progress.log('waiting for fonts to load...');
233
+ await Promise.all(this._page.frames().map(async frame => {
234
+ await frame.nonStallingEvaluateInExistingContext('document.fonts.ready', false, 'utility').catch(() => {});
235
+ }));
236
+ progress.log('fonts loaded');
237
+ }
238
+ progress.cleanupWhenAborted(() => this._restorePageAfterScreenshot());
239
+ }
240
+ async _restorePageAfterScreenshot() {
241
+ await Promise.all(this._page.frames().map(async frame => {
242
+ frame.nonStallingEvaluateInExistingContext('window.__pwCleanupScreenshot && window.__pwCleanupScreenshot()', false, 'utility').catch(() => {});
243
+ }));
244
+ }
245
+ async _maskElements(progress, options) {
246
+ const framesToParsedSelectors = new _multimap.MultiMap();
247
+ const cleanup = async () => {
248
+ await Promise.all([...framesToParsedSelectors.keys()].map(async frame => {
249
+ await frame.hideHighlight();
250
+ }));
251
+ };
252
+ if (!options.mask || !options.mask.length) return cleanup;
253
+ await Promise.all((options.mask || []).map(async ({
254
+ frame,
255
+ selector
256
+ }) => {
257
+ const pair = await frame.selectors.resolveFrameForSelector(selector);
258
+ if (pair) framesToParsedSelectors.set(pair.frame, pair.info.parsed);
259
+ }));
260
+ progress.throwIfAborted(); // Avoid extra work.
261
+
262
+ await Promise.all([...framesToParsedSelectors.keys()].map(async frame => {
263
+ await frame.maskSelectors(framesToParsedSelectors.get(frame), options.maskColor || '#F0F');
264
+ }));
265
+ progress.cleanupWhenAborted(cleanup);
266
+ return cleanup;
267
+ }
268
+ async _screenshot(progress, format, documentRect, viewportRect, fitsViewport, options) {
269
+ var _options$quality;
270
+ if (options.__testHookBeforeScreenshot) await options.__testHookBeforeScreenshot();
271
+ progress.throwIfAborted(); // Screenshotting is expensive - avoid extra work.
272
+ const shouldSetDefaultBackground = options.omitBackground && format === 'png';
273
+ if (shouldSetDefaultBackground) {
274
+ await this._page._delegate.setBackgroundColor({
275
+ r: 0,
276
+ g: 0,
277
+ b: 0,
278
+ a: 0
279
+ });
280
+ progress.cleanupWhenAborted(() => this._page._delegate.setBackgroundColor());
281
+ }
282
+ progress.throwIfAborted(); // Avoid extra work.
283
+
284
+ const cleanupHighlight = await this._maskElements(progress, options);
285
+ progress.throwIfAborted(); // Avoid extra work.
286
+
287
+ const quality = format === 'jpeg' ? (_options$quality = options.quality) !== null && _options$quality !== void 0 ? _options$quality : 80 : undefined;
288
+ const buffer = await this._page._delegate.takeScreenshot(progress, format, documentRect, viewportRect, quality, fitsViewport, options.scale || 'device');
289
+ progress.throwIfAborted(); // Avoid restoring after failure - should be done by cleanup.
290
+
291
+ await cleanupHighlight();
292
+ progress.throwIfAborted(); // Avoid restoring after failure - should be done by cleanup.
293
+
294
+ if (shouldSetDefaultBackground) await this._page._delegate.setBackgroundColor();
295
+ progress.throwIfAborted(); // Avoid side effects.
296
+ if (options.__testHookAfterScreenshot) await options.__testHookAfterScreenshot();
297
+ return buffer;
298
+ }
299
+ }
300
+ exports.Screenshotter = Screenshotter;
301
+ class TaskQueue {
302
+ constructor() {
303
+ this._chain = void 0;
304
+ this._chain = Promise.resolve();
305
+ }
306
+ postTask(task) {
307
+ const result = this._chain.then(task);
308
+ this._chain = result.catch(() => {});
309
+ return result;
310
+ }
311
+ }
312
+ function trimClipToSize(clip, size) {
313
+ const p1 = {
314
+ x: Math.max(0, Math.min(clip.x, size.width)),
315
+ y: Math.max(0, Math.min(clip.y, size.height))
316
+ };
317
+ const p2 = {
318
+ x: Math.max(0, Math.min(clip.x + clip.width, size.width)),
319
+ y: Math.max(0, Math.min(clip.y + clip.height, size.height))
320
+ };
321
+ const result = {
322
+ x: p1.x,
323
+ y: p1.y,
324
+ width: p2.x - p1.x,
325
+ height: p2.y - p1.y
326
+ };
327
+ (0, _utils.assert)(result.width && result.height, 'Clipped area is either empty or outside the resulting image');
328
+ return result;
329
+ }
330
+ function validateScreenshotOptions(options) {
331
+ let format = null;
332
+ // options.type takes precedence over inferring the type from options.path
333
+ // because it may be a 0-length file with no extension created beforehand (i.e. as a temp file).
334
+ if (options.type) {
335
+ (0, _utils.assert)(options.type === 'png' || options.type === 'jpeg', 'Unknown options.type value: ' + options.type);
336
+ format = options.type;
337
+ }
338
+ if (!format) format = 'png';
339
+ if (options.quality !== undefined) {
340
+ (0, _utils.assert)(format === 'jpeg', 'options.quality is unsupported for the ' + format + ' screenshots');
341
+ (0, _utils.assert)(typeof options.quality === 'number', 'Expected options.quality to be a number but found ' + typeof options.quality);
342
+ (0, _utils.assert)(Number.isInteger(options.quality), 'Expected options.quality to be an integer');
343
+ (0, _utils.assert)(options.quality >= 0 && options.quality <= 100, 'Expected options.quality to be between 0 and 100 (inclusive), got ' + options.quality);
344
+ }
345
+ if (options.clip) {
346
+ (0, _utils.assert)(typeof options.clip.x === 'number', 'Expected options.clip.x to be a number but found ' + typeof options.clip.x);
347
+ (0, _utils.assert)(typeof options.clip.y === 'number', 'Expected options.clip.y to be a number but found ' + typeof options.clip.y);
348
+ (0, _utils.assert)(typeof options.clip.width === 'number', 'Expected options.clip.width to be a number but found ' + typeof options.clip.width);
349
+ (0, _utils.assert)(typeof options.clip.height === 'number', 'Expected options.clip.height to be a number but found ' + typeof options.clip.height);
350
+ (0, _utils.assert)(options.clip.width !== 0, 'Expected options.clip.width not to be 0.');
351
+ (0, _utils.assert)(options.clip.height !== 0, 'Expected options.clip.height not to be 0.');
352
+ }
353
+ return format;
354
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Selectors = void 0;
7
+ var _selectorParser = require("../utils/isomorphic/selectorParser");
8
+ var _utils = require("../utils");
9
+ /**
10
+ * Copyright (c) Microsoft Corporation.
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+
25
+ class Selectors {
26
+ constructor() {
27
+ this._builtinEngines = void 0;
28
+ this._builtinEnginesInMainWorld = void 0;
29
+ this._engines = void 0;
30
+ this.guid = `selectors@${(0, _utils.createGuid)()}`;
31
+ this._testIdAttributeName = 'data-testid';
32
+ // Note: keep in sync with InjectedScript class.
33
+ this._builtinEngines = new Set(['css', 'css:light', 'xpath', 'xpath:light', '_react', '_vue', 'text', 'text:light', 'id', 'id:light', 'data-testid', 'data-testid:light', 'data-test-id', 'data-test-id:light', 'data-test', 'data-test:light', 'nth', 'visible', 'internal:control', 'internal:has', 'internal:has-not', 'internal:has-text', 'internal:has-not-text', 'internal:and', 'internal:or', 'internal:chain', 'role', 'internal:attr', 'internal:label', 'internal:text', 'internal:role', 'internal:testid']);
34
+ this._builtinEnginesInMainWorld = new Set(['_react', '_vue']);
35
+ this._engines = new Map();
36
+ }
37
+ async register(name, source, contentScript = false) {
38
+ if (!name.match(/^[a-zA-Z_0-9-]+$/)) throw new Error('Selector engine name may only contain [a-zA-Z0-9_] characters');
39
+ // Note: we keep 'zs' for future use.
40
+ if (this._builtinEngines.has(name) || name === 'zs' || name === 'zs:light') throw new Error(`"${name}" is a predefined selector engine`);
41
+ if (this._engines.has(name)) throw new Error(`"${name}" selector engine has been already registered`);
42
+ this._engines.set(name, {
43
+ source,
44
+ contentScript
45
+ });
46
+ }
47
+ testIdAttributeName() {
48
+ return this._testIdAttributeName;
49
+ }
50
+ setTestIdAttributeName(testIdAttributeName) {
51
+ this._testIdAttributeName = testIdAttributeName;
52
+ }
53
+ unregisterAll() {
54
+ this._engines.clear();
55
+ }
56
+ parseSelector(selector, strict) {
57
+ const parsed = typeof selector === 'string' ? (0, _selectorParser.parseSelector)(selector) : selector;
58
+ let needsMainWorld = false;
59
+ (0, _selectorParser.visitAllSelectorParts)(parsed, part => {
60
+ const name = part.name;
61
+ const custom = this._engines.get(name);
62
+ if (!custom && !this._builtinEngines.has(name)) throw new _selectorParser.InvalidSelectorError(`Unknown engine "${name}" while parsing selector ${(0, _selectorParser.stringifySelector)(parsed)}`);
63
+ if (custom && !custom.contentScript) needsMainWorld = true;
64
+ if (this._builtinEnginesInMainWorld.has(name)) needsMainWorld = true;
65
+ });
66
+ return {
67
+ parsed,
68
+ world: needsMainWorld ? 'main' : 'utility',
69
+ strict
70
+ };
71
+ }
72
+ }
73
+ exports.Selectors = Selectors;
@@ -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
+ }