@stablyai/internal-playwright-core 0.1.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 (405) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +3 -0
  4. package/ThirdPartyNotices.txt +1134 -0
  5. package/bin/install_media_pack.ps1 +5 -0
  6. package/bin/install_webkit_wsl.ps1 +35 -0
  7. package/bin/reinstall_chrome_beta_linux.sh +42 -0
  8. package/bin/reinstall_chrome_beta_mac.sh +13 -0
  9. package/bin/reinstall_chrome_beta_win.ps1 +24 -0
  10. package/bin/reinstall_chrome_stable_linux.sh +42 -0
  11. package/bin/reinstall_chrome_stable_mac.sh +12 -0
  12. package/bin/reinstall_chrome_stable_win.ps1 +24 -0
  13. package/bin/reinstall_msedge_beta_linux.sh +48 -0
  14. package/bin/reinstall_msedge_beta_mac.sh +11 -0
  15. package/bin/reinstall_msedge_beta_win.ps1 +23 -0
  16. package/bin/reinstall_msedge_dev_linux.sh +48 -0
  17. package/bin/reinstall_msedge_dev_mac.sh +11 -0
  18. package/bin/reinstall_msedge_dev_win.ps1 +23 -0
  19. package/bin/reinstall_msedge_stable_linux.sh +48 -0
  20. package/bin/reinstall_msedge_stable_mac.sh +11 -0
  21. package/bin/reinstall_msedge_stable_win.ps1 +24 -0
  22. package/browsers.json +80 -0
  23. package/cli.js +18 -0
  24. package/index.d.ts +17 -0
  25. package/index.js +32 -0
  26. package/index.mjs +28 -0
  27. package/lib/androidServerImpl.js +65 -0
  28. package/lib/browserServerImpl.js +120 -0
  29. package/lib/cli/cli.js +58 -0
  30. package/lib/cli/driver.js +97 -0
  31. package/lib/cli/program.js +634 -0
  32. package/lib/cli/programWithTestStub.js +74 -0
  33. package/lib/client/accessibility.js +49 -0
  34. package/lib/client/android.js +361 -0
  35. package/lib/client/api.js +137 -0
  36. package/lib/client/artifact.js +79 -0
  37. package/lib/client/browser.js +163 -0
  38. package/lib/client/browserContext.js +529 -0
  39. package/lib/client/browserType.js +184 -0
  40. package/lib/client/cdpSession.js +51 -0
  41. package/lib/client/channelOwner.js +194 -0
  42. package/lib/client/clientHelper.js +64 -0
  43. package/lib/client/clientInstrumentation.js +55 -0
  44. package/lib/client/clientStackTrace.js +69 -0
  45. package/lib/client/clock.js +68 -0
  46. package/lib/client/connection.js +314 -0
  47. package/lib/client/consoleMessage.js +54 -0
  48. package/lib/client/coverage.js +44 -0
  49. package/lib/client/dialog.js +56 -0
  50. package/lib/client/download.js +62 -0
  51. package/lib/client/electron.js +138 -0
  52. package/lib/client/elementHandle.js +281 -0
  53. package/lib/client/errors.js +77 -0
  54. package/lib/client/eventEmitter.js +314 -0
  55. package/lib/client/events.js +99 -0
  56. package/lib/client/fetch.js +369 -0
  57. package/lib/client/fileChooser.js +46 -0
  58. package/lib/client/fileUtils.js +34 -0
  59. package/lib/client/frame.js +408 -0
  60. package/lib/client/harRouter.js +87 -0
  61. package/lib/client/input.js +84 -0
  62. package/lib/client/jsHandle.js +109 -0
  63. package/lib/client/jsonPipe.js +39 -0
  64. package/lib/client/localUtils.js +60 -0
  65. package/lib/client/locator.js +368 -0
  66. package/lib/client/network.js +747 -0
  67. package/lib/client/page.js +721 -0
  68. package/lib/client/platform.js +74 -0
  69. package/lib/client/playwright.js +71 -0
  70. package/lib/client/selectors.js +55 -0
  71. package/lib/client/stream.js +39 -0
  72. package/lib/client/timeoutSettings.js +79 -0
  73. package/lib/client/tracing.js +117 -0
  74. package/lib/client/types.js +28 -0
  75. package/lib/client/video.js +59 -0
  76. package/lib/client/waiter.js +142 -0
  77. package/lib/client/webError.js +39 -0
  78. package/lib/client/webSocket.js +93 -0
  79. package/lib/client/worker.js +63 -0
  80. package/lib/client/writableStream.js +39 -0
  81. package/lib/common/debugLogger.js +90 -0
  82. package/lib/common/socksProxy.js +569 -0
  83. package/lib/common/timeoutSettings.js +73 -0
  84. package/lib/common/types.js +5 -0
  85. package/lib/generated/bindingsControllerSource.js +28 -0
  86. package/lib/generated/clockSource.js +28 -0
  87. package/lib/generated/consoleApiSource.js +28 -0
  88. package/lib/generated/injectedScriptSource.js +28 -0
  89. package/lib/generated/pollingRecorderSource.js +28 -0
  90. package/lib/generated/recorderSource.js +28 -0
  91. package/lib/generated/storageScriptSource.js +28 -0
  92. package/lib/generated/utilityScriptSource.js +28 -0
  93. package/lib/generated/webSocketMockSource.js +336 -0
  94. package/lib/image_tools/colorUtils.js +98 -0
  95. package/lib/image_tools/compare.js +108 -0
  96. package/lib/image_tools/imageChannel.js +70 -0
  97. package/lib/image_tools/stats.js +102 -0
  98. package/lib/inProcessFactory.js +60 -0
  99. package/lib/index.js +19 -0
  100. package/lib/inprocess.js +3 -0
  101. package/lib/outofprocess.js +76 -0
  102. package/lib/protocol/debug.js +27 -0
  103. package/lib/protocol/serializers.js +192 -0
  104. package/lib/protocol/transport.js +82 -0
  105. package/lib/protocol/validator.js +2919 -0
  106. package/lib/protocol/validatorPrimitives.js +193 -0
  107. package/lib/remote/playwrightConnection.js +129 -0
  108. package/lib/remote/playwrightServer.js +335 -0
  109. package/lib/server/accessibility.js +69 -0
  110. package/lib/server/android/android.js +465 -0
  111. package/lib/server/android/backendAdb.js +177 -0
  112. package/lib/server/artifact.js +127 -0
  113. package/lib/server/bidi/bidiBrowser.js +490 -0
  114. package/lib/server/bidi/bidiChromium.js +153 -0
  115. package/lib/server/bidi/bidiConnection.js +212 -0
  116. package/lib/server/bidi/bidiExecutionContext.js +221 -0
  117. package/lib/server/bidi/bidiFirefox.js +130 -0
  118. package/lib/server/bidi/bidiInput.js +146 -0
  119. package/lib/server/bidi/bidiNetworkManager.js +383 -0
  120. package/lib/server/bidi/bidiOverCdp.js +102 -0
  121. package/lib/server/bidi/bidiPage.js +552 -0
  122. package/lib/server/bidi/bidiPdf.js +106 -0
  123. package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
  124. package/lib/server/bidi/third_party/bidiDeserializer.js +98 -0
  125. package/lib/server/bidi/third_party/bidiKeyboard.js +256 -0
  126. package/lib/server/bidi/third_party/bidiProtocol.js +24 -0
  127. package/lib/server/bidi/third_party/bidiProtocolCore.js +179 -0
  128. package/lib/server/bidi/third_party/bidiProtocolPermissions.js +42 -0
  129. package/lib/server/bidi/third_party/bidiSerializer.js +148 -0
  130. package/lib/server/bidi/third_party/firefoxPrefs.js +259 -0
  131. package/lib/server/browser.js +149 -0
  132. package/lib/server/browserContext.js +695 -0
  133. package/lib/server/browserType.js +328 -0
  134. package/lib/server/callLog.js +82 -0
  135. package/lib/server/chromium/appIcon.png +0 -0
  136. package/lib/server/chromium/chromium.js +402 -0
  137. package/lib/server/chromium/chromiumSwitches.js +95 -0
  138. package/lib/server/chromium/crAccessibility.js +263 -0
  139. package/lib/server/chromium/crBrowser.js +501 -0
  140. package/lib/server/chromium/crConnection.js +202 -0
  141. package/lib/server/chromium/crCoverage.js +235 -0
  142. package/lib/server/chromium/crDevTools.js +113 -0
  143. package/lib/server/chromium/crDragDrop.js +131 -0
  144. package/lib/server/chromium/crExecutionContext.js +146 -0
  145. package/lib/server/chromium/crInput.js +187 -0
  146. package/lib/server/chromium/crNetworkManager.js +666 -0
  147. package/lib/server/chromium/crPage.js +1069 -0
  148. package/lib/server/chromium/crPdf.js +121 -0
  149. package/lib/server/chromium/crProtocolHelper.js +145 -0
  150. package/lib/server/chromium/crServiceWorker.js +123 -0
  151. package/lib/server/chromium/defaultFontFamilies.js +162 -0
  152. package/lib/server/chromium/protocol.d.js +16 -0
  153. package/lib/server/chromium/videoRecorder.js +113 -0
  154. package/lib/server/clock.js +149 -0
  155. package/lib/server/codegen/csharp.js +327 -0
  156. package/lib/server/codegen/java.js +274 -0
  157. package/lib/server/codegen/javascript.js +270 -0
  158. package/lib/server/codegen/jsonl.js +52 -0
  159. package/lib/server/codegen/language.js +132 -0
  160. package/lib/server/codegen/languages.js +68 -0
  161. package/lib/server/codegen/python.js +279 -0
  162. package/lib/server/codegen/types.js +16 -0
  163. package/lib/server/console.js +53 -0
  164. package/lib/server/cookieStore.js +206 -0
  165. package/lib/server/debugController.js +191 -0
  166. package/lib/server/debugger.js +119 -0
  167. package/lib/server/deviceDescriptors.js +39 -0
  168. package/lib/server/deviceDescriptorsSource.json +1779 -0
  169. package/lib/server/dialog.js +116 -0
  170. package/lib/server/dispatchers/androidDispatcher.js +325 -0
  171. package/lib/server/dispatchers/artifactDispatcher.js +118 -0
  172. package/lib/server/dispatchers/browserContextDispatcher.js +364 -0
  173. package/lib/server/dispatchers/browserDispatcher.js +118 -0
  174. package/lib/server/dispatchers/browserTypeDispatcher.js +64 -0
  175. package/lib/server/dispatchers/cdpSessionDispatcher.js +44 -0
  176. package/lib/server/dispatchers/debugControllerDispatcher.js +78 -0
  177. package/lib/server/dispatchers/dialogDispatcher.js +47 -0
  178. package/lib/server/dispatchers/dispatcher.js +371 -0
  179. package/lib/server/dispatchers/electronDispatcher.js +89 -0
  180. package/lib/server/dispatchers/elementHandlerDispatcher.js +181 -0
  181. package/lib/server/dispatchers/frameDispatcher.js +227 -0
  182. package/lib/server/dispatchers/jsHandleDispatcher.js +85 -0
  183. package/lib/server/dispatchers/jsonPipeDispatcher.js +58 -0
  184. package/lib/server/dispatchers/localUtilsDispatcher.js +149 -0
  185. package/lib/server/dispatchers/networkDispatchers.js +213 -0
  186. package/lib/server/dispatchers/pageDispatcher.js +401 -0
  187. package/lib/server/dispatchers/playwrightDispatcher.js +108 -0
  188. package/lib/server/dispatchers/selectorsDispatcher.js +36 -0
  189. package/lib/server/dispatchers/streamDispatcher.js +67 -0
  190. package/lib/server/dispatchers/tracingDispatcher.js +68 -0
  191. package/lib/server/dispatchers/webSocketRouteDispatcher.js +165 -0
  192. package/lib/server/dispatchers/writableStreamDispatcher.js +79 -0
  193. package/lib/server/dom.js +806 -0
  194. package/lib/server/download.js +70 -0
  195. package/lib/server/electron/electron.js +270 -0
  196. package/lib/server/electron/loader.js +29 -0
  197. package/lib/server/errors.js +69 -0
  198. package/lib/server/fetch.js +621 -0
  199. package/lib/server/fileChooser.js +43 -0
  200. package/lib/server/fileUploadUtils.js +84 -0
  201. package/lib/server/firefox/ffAccessibility.js +238 -0
  202. package/lib/server/firefox/ffBrowser.js +428 -0
  203. package/lib/server/firefox/ffConnection.js +147 -0
  204. package/lib/server/firefox/ffExecutionContext.js +150 -0
  205. package/lib/server/firefox/ffInput.js +159 -0
  206. package/lib/server/firefox/ffNetworkManager.js +256 -0
  207. package/lib/server/firefox/ffPage.js +503 -0
  208. package/lib/server/firefox/firefox.js +116 -0
  209. package/lib/server/firefox/protocol.d.js +16 -0
  210. package/lib/server/formData.js +147 -0
  211. package/lib/server/frameSelectors.js +156 -0
  212. package/lib/server/frames.js +1502 -0
  213. package/lib/server/har/harRecorder.js +147 -0
  214. package/lib/server/har/harTracer.js +607 -0
  215. package/lib/server/harBackend.js +157 -0
  216. package/lib/server/helper.js +96 -0
  217. package/lib/server/index.js +58 -0
  218. package/lib/server/input.js +273 -0
  219. package/lib/server/instrumentation.js +69 -0
  220. package/lib/server/isomorphic/utilityScriptSerializers.js +212 -0
  221. package/lib/server/javascript.js +291 -0
  222. package/lib/server/launchApp.js +128 -0
  223. package/lib/server/localUtils.js +218 -0
  224. package/lib/server/macEditingCommands.js +143 -0
  225. package/lib/server/network.js +629 -0
  226. package/lib/server/page.js +871 -0
  227. package/lib/server/pipeTransport.js +89 -0
  228. package/lib/server/playwright.js +69 -0
  229. package/lib/server/progress.js +112 -0
  230. package/lib/server/protocolError.js +52 -0
  231. package/lib/server/recorder/chat.js +161 -0
  232. package/lib/server/recorder/codeGenerator.js +153 -0
  233. package/lib/server/recorder/csharp.js +310 -0
  234. package/lib/server/recorder/java.js +248 -0
  235. package/lib/server/recorder/javascript.js +229 -0
  236. package/lib/server/recorder/jsonl.js +47 -0
  237. package/lib/server/recorder/language.js +44 -0
  238. package/lib/server/recorder/python.js +276 -0
  239. package/lib/server/recorder/recorderActions.js +5 -0
  240. package/lib/server/recorder/recorderApp.js +387 -0
  241. package/lib/server/recorder/recorderRunner.js +138 -0
  242. package/lib/server/recorder/recorderSignalProcessor.js +83 -0
  243. package/lib/server/recorder/recorderUtils.js +157 -0
  244. package/lib/server/recorder/throttledFile.js +57 -0
  245. package/lib/server/recorder/utils.js +45 -0
  246. package/lib/server/recorder.js +499 -0
  247. package/lib/server/registry/browserFetcher.js +175 -0
  248. package/lib/server/registry/dependencies.js +371 -0
  249. package/lib/server/registry/index.js +1331 -0
  250. package/lib/server/registry/nativeDeps.js +1280 -0
  251. package/lib/server/registry/oopDownloadBrowserMain.js +120 -0
  252. package/lib/server/screenshotter.js +333 -0
  253. package/lib/server/selectors.js +112 -0
  254. package/lib/server/socksClientCertificatesInterceptor.js +383 -0
  255. package/lib/server/socksInterceptor.js +95 -0
  256. package/lib/server/stably/ai-tools/http-request.js +70 -0
  257. package/lib/server/stably/ai-tools/stablyApiCaller.js +137 -0
  258. package/lib/server/stably/autohealing/elementHandleFromCoordinates.js +64 -0
  259. package/lib/server/stably/autohealing/healingService.js +228 -0
  260. package/lib/server/stably/autohealing/screenshotFrame.js +41 -0
  261. package/lib/server/stably/constants.js +31 -0
  262. package/lib/server/trace/recorder/snapshotter.js +147 -0
  263. package/lib/server/trace/recorder/snapshotterInjected.js +541 -0
  264. package/lib/server/trace/recorder/tracing.js +602 -0
  265. package/lib/server/trace/test/inMemorySnapshotter.js +87 -0
  266. package/lib/server/trace/viewer/traceViewer.js +240 -0
  267. package/lib/server/transport.js +181 -0
  268. package/lib/server/types.js +28 -0
  269. package/lib/server/usKeyboardLayout.js +145 -0
  270. package/lib/server/utils/ascii.js +44 -0
  271. package/lib/server/utils/comparators.js +161 -0
  272. package/lib/server/utils/crypto.js +216 -0
  273. package/lib/server/utils/debug.js +42 -0
  274. package/lib/server/utils/debugLogger.js +122 -0
  275. package/lib/server/utils/env.js +73 -0
  276. package/lib/server/utils/eventsHelper.js +39 -0
  277. package/lib/server/utils/expectUtils.js +38 -0
  278. package/lib/server/utils/fileUtils.js +191 -0
  279. package/lib/server/utils/happyEyeballs.js +207 -0
  280. package/lib/server/utils/hostPlatform.js +111 -0
  281. package/lib/server/utils/httpServer.js +218 -0
  282. package/lib/server/utils/image_tools/colorUtils.js +89 -0
  283. package/lib/server/utils/image_tools/compare.js +109 -0
  284. package/lib/server/utils/image_tools/imageChannel.js +78 -0
  285. package/lib/server/utils/image_tools/stats.js +102 -0
  286. package/lib/server/utils/linuxUtils.js +71 -0
  287. package/lib/server/utils/network.js +233 -0
  288. package/lib/server/utils/nodePlatform.js +148 -0
  289. package/lib/server/utils/pipeTransport.js +84 -0
  290. package/lib/server/utils/processLauncher.js +241 -0
  291. package/lib/server/utils/profiler.js +65 -0
  292. package/lib/server/utils/socksProxy.js +511 -0
  293. package/lib/server/utils/spawnAsync.js +41 -0
  294. package/lib/server/utils/task.js +51 -0
  295. package/lib/server/utils/userAgent.js +98 -0
  296. package/lib/server/utils/wsServer.js +121 -0
  297. package/lib/server/utils/zipFile.js +74 -0
  298. package/lib/server/utils/zones.js +57 -0
  299. package/lib/server/webkit/protocol.d.js +16 -0
  300. package/lib/server/webkit/webkit.js +119 -0
  301. package/lib/server/webkit/wkAccessibility.js +237 -0
  302. package/lib/server/webkit/wkBrowser.js +339 -0
  303. package/lib/server/webkit/wkConnection.js +149 -0
  304. package/lib/server/webkit/wkExecutionContext.js +154 -0
  305. package/lib/server/webkit/wkInput.js +181 -0
  306. package/lib/server/webkit/wkInterceptableRequest.js +169 -0
  307. package/lib/server/webkit/wkPage.js +1134 -0
  308. package/lib/server/webkit/wkProvisionalPage.js +83 -0
  309. package/lib/server/webkit/wkWorkers.js +104 -0
  310. package/lib/server/webkit/wsl/webkit-wsl-transport-client.js +74 -0
  311. package/lib/server/webkit/wsl/webkit-wsl-transport-server.js +113 -0
  312. package/lib/third_party/diff_match_patch.js +2222 -0
  313. package/lib/third_party/pixelmatch.js +255 -0
  314. package/lib/utils/ascii.js +31 -0
  315. package/lib/utils/comparators.js +171 -0
  316. package/lib/utils/crypto.js +33 -0
  317. package/lib/utils/debug.js +46 -0
  318. package/lib/utils/debugLogger.js +89 -0
  319. package/lib/utils/env.js +49 -0
  320. package/lib/utils/eventsHelper.js +38 -0
  321. package/lib/utils/fileUtils.js +205 -0
  322. package/lib/utils/glob.js +83 -0
  323. package/lib/utils/happy-eyeballs.js +160 -0
  324. package/lib/utils/headers.js +52 -0
  325. package/lib/utils/hostPlatform.js +128 -0
  326. package/lib/utils/httpServer.js +236 -0
  327. package/lib/utils/index.js +346 -0
  328. package/lib/utils/isomorphic/ariaSnapshot.js +392 -0
  329. package/lib/utils/isomorphic/assert.js +31 -0
  330. package/lib/utils/isomorphic/colors.js +72 -0
  331. package/lib/utils/isomorphic/cssParser.js +245 -0
  332. package/lib/utils/isomorphic/cssTokenizer.js +1051 -0
  333. package/lib/utils/isomorphic/headers.js +53 -0
  334. package/lib/utils/isomorphic/locatorGenerators.js +673 -0
  335. package/lib/utils/isomorphic/locatorParser.js +176 -0
  336. package/lib/utils/isomorphic/locatorUtils.js +81 -0
  337. package/lib/utils/isomorphic/manualPromise.js +114 -0
  338. package/lib/utils/isomorphic/mimeType.js +459 -0
  339. package/lib/utils/isomorphic/multimap.js +80 -0
  340. package/lib/utils/isomorphic/protocolFormatter.js +78 -0
  341. package/lib/utils/isomorphic/protocolMetainfo.js +321 -0
  342. package/lib/utils/isomorphic/rtti.js +43 -0
  343. package/lib/utils/isomorphic/selectorParser.js +386 -0
  344. package/lib/utils/isomorphic/semaphore.js +54 -0
  345. package/lib/utils/isomorphic/stackTrace.js +158 -0
  346. package/lib/utils/isomorphic/stringUtils.js +155 -0
  347. package/lib/utils/isomorphic/time.js +49 -0
  348. package/lib/utils/isomorphic/timeoutRunner.js +66 -0
  349. package/lib/utils/isomorphic/traceUtils.js +58 -0
  350. package/lib/utils/isomorphic/types.js +16 -0
  351. package/lib/utils/isomorphic/urlMatch.js +176 -0
  352. package/lib/utils/isomorphic/utilityScriptSerializers.js +251 -0
  353. package/lib/utils/linuxUtils.js +78 -0
  354. package/lib/utils/manualPromise.js +109 -0
  355. package/lib/utils/mimeType.js +29 -0
  356. package/lib/utils/multimap.js +75 -0
  357. package/lib/utils/network.js +188 -0
  358. package/lib/utils/processLauncher.js +248 -0
  359. package/lib/utils/profiler.js +53 -0
  360. package/lib/utils/rtti.js +44 -0
  361. package/lib/utils/semaphore.js +51 -0
  362. package/lib/utils/spawnAsync.js +45 -0
  363. package/lib/utils/stackTrace.js +121 -0
  364. package/lib/utils/task.js +58 -0
  365. package/lib/utils/time.js +37 -0
  366. package/lib/utils/timeoutRunner.js +66 -0
  367. package/lib/utils/traceUtils.js +44 -0
  368. package/lib/utils/userAgent.js +105 -0
  369. package/lib/utils/wsServer.js +127 -0
  370. package/lib/utils/zipFile.js +75 -0
  371. package/lib/utils/zones.js +62 -0
  372. package/lib/utils.js +107 -0
  373. package/lib/utilsBundle.js +109 -0
  374. package/lib/utilsBundleImpl/index.js +218 -0
  375. package/lib/utilsBundleImpl/xdg-open +1066 -0
  376. package/lib/vite/htmlReport/index.html +84 -0
  377. package/lib/vite/recorder/assets/codeMirrorModule-C3UTv-Ge.css +1 -0
  378. package/lib/vite/recorder/assets/codeMirrorModule-RJCXzfmE.js +24 -0
  379. package/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
  380. package/lib/vite/recorder/assets/index-Ri0uHF7I.css +1 -0
  381. package/lib/vite/recorder/assets/index-Y-X2TGJv.js +193 -0
  382. package/lib/vite/recorder/index.html +29 -0
  383. package/lib/vite/recorder/playwright-logo.svg +9 -0
  384. package/lib/vite/traceViewer/assets/codeMirrorModule-Bhnc5o2x.js +24 -0
  385. package/lib/vite/traceViewer/assets/defaultSettingsView-ClwvkA2N.js +265 -0
  386. package/lib/vite/traceViewer/assets/xtermModule-CsJ4vdCR.js +9 -0
  387. package/lib/vite/traceViewer/codeMirrorModule.C3UTv-Ge.css +1 -0
  388. package/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
  389. package/lib/vite/traceViewer/defaultSettingsView.TQ8_7ybu.css +1 -0
  390. package/lib/vite/traceViewer/index.DFO9NNF5.js +2 -0
  391. package/lib/vite/traceViewer/index.I8N9v4jT.css +1 -0
  392. package/lib/vite/traceViewer/index.html +43 -0
  393. package/lib/vite/traceViewer/playwright-logo.svg +9 -0
  394. package/lib/vite/traceViewer/snapshot.html +21 -0
  395. package/lib/vite/traceViewer/sw.bundle.js +3 -0
  396. package/lib/vite/traceViewer/uiMode.Btcz36p_.css +1 -0
  397. package/lib/vite/traceViewer/uiMode.Shu3QS-1.js +5 -0
  398. package/lib/vite/traceViewer/uiMode.html +17 -0
  399. package/lib/vite/traceViewer/xtermModule.DYP7pi_n.css +32 -0
  400. package/lib/zipBundle.js +34 -0
  401. package/lib/zipBundleImpl.js +5 -0
  402. package/package.json +43 -0
  403. package/types/protocol.d.ts +23130 -0
  404. package/types/structs.d.ts +45 -0
  405. package/types/types.d.ts +22857 -0
@@ -0,0 +1,1069 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var crPage_exports = {};
30
+ __export(crPage_exports, {
31
+ CRPage: () => CRPage
32
+ });
33
+ module.exports = __toCommonJS(crPage_exports);
34
+ var import_path = __toESM(require("path"));
35
+ var import_assert = require("../../utils/isomorphic/assert");
36
+ var import_crypto = require("../utils/crypto");
37
+ var import_eventsHelper = require("../utils/eventsHelper");
38
+ var import_stackTrace = require("../../utils/isomorphic/stackTrace");
39
+ var dialog = __toESM(require("../dialog"));
40
+ var dom = __toESM(require("../dom"));
41
+ var frames = __toESM(require("../frames"));
42
+ var import_helper = require("../helper");
43
+ var network = __toESM(require("../network"));
44
+ var import_page = require("../page");
45
+ var import_registry = require("../registry");
46
+ var import_crAccessibility = require("./crAccessibility");
47
+ var import_crCoverage = require("./crCoverage");
48
+ var import_crDragDrop = require("./crDragDrop");
49
+ var import_crExecutionContext = require("./crExecutionContext");
50
+ var import_crInput = require("./crInput");
51
+ var import_crNetworkManager = require("./crNetworkManager");
52
+ var import_crPdf = require("./crPdf");
53
+ var import_crProtocolHelper = require("./crProtocolHelper");
54
+ var import_defaultFontFamilies = require("./defaultFontFamilies");
55
+ var import_videoRecorder = require("./videoRecorder");
56
+ var import_errors = require("../errors");
57
+ var import_protocolError = require("../protocolError");
58
+ class CRPage {
59
+ constructor(client, targetId, browserContext, opener, bits) {
60
+ this._sessions = /* @__PURE__ */ new Map();
61
+ // Holds window features for the next popup being opened via window.open,
62
+ // until the popup target arrives. This could be racy if two oopifs
63
+ // simultaneously call window.open with window features: the order
64
+ // of their Page.windowOpen events is not guaranteed to match the order
65
+ // of new popup targets.
66
+ this._nextWindowOpenPopupFeatures = [];
67
+ this._targetId = targetId;
68
+ this._opener = opener;
69
+ const dragManager = new import_crDragDrop.DragManager(this);
70
+ this.rawKeyboard = new import_crInput.RawKeyboardImpl(client, browserContext._browser._platform() === "mac", dragManager);
71
+ this.rawMouse = new import_crInput.RawMouseImpl(this, client, dragManager);
72
+ this.rawTouchscreen = new import_crInput.RawTouchscreenImpl(client);
73
+ this._pdf = new import_crPdf.CRPDF(client);
74
+ this._coverage = new import_crCoverage.CRCoverage(client);
75
+ this._browserContext = browserContext;
76
+ this._page = new import_page.Page(this, browserContext);
77
+ this.utilityWorldName = `__playwright_utility_world_${this._page.guid}`;
78
+ this._networkManager = new import_crNetworkManager.CRNetworkManager(this._page, null);
79
+ this.updateOffline();
80
+ this.updateExtraHTTPHeaders();
81
+ this.updateHttpCredentials();
82
+ this.updateRequestInterception();
83
+ this._mainFrameSession = new FrameSession(this, client, targetId, null);
84
+ this._sessions.set(targetId, this._mainFrameSession);
85
+ if (opener && !browserContext._options.noDefaultViewport) {
86
+ const features = opener._nextWindowOpenPopupFeatures.shift() || [];
87
+ const viewportSize = import_helper.helper.getViewportSizeFromWindowFeatures(features);
88
+ if (viewportSize)
89
+ this._page.setEmulatedSizeFromWindowOpen({ viewport: viewportSize, screen: viewportSize });
90
+ }
91
+ this._mainFrameSession._initialize(bits.hasUIWindow).then(
92
+ () => this._page.reportAsNew(this._opener?._page, void 0),
93
+ (error) => this._page.reportAsNew(this._opener?._page, error)
94
+ );
95
+ }
96
+ static mainFrameSession(page) {
97
+ const crPage = page.delegate;
98
+ return crPage._mainFrameSession;
99
+ }
100
+ async _forAllFrameSessions(cb) {
101
+ const frameSessions = Array.from(this._sessions.values());
102
+ await Promise.all(frameSessions.map((frameSession) => {
103
+ if (frameSession._isMainFrame())
104
+ return cb(frameSession);
105
+ return cb(frameSession).catch((e) => {
106
+ if ((0, import_protocolError.isSessionClosedError)(e))
107
+ return;
108
+ throw e;
109
+ });
110
+ }));
111
+ }
112
+ _sessionForFrame(frame) {
113
+ while (!this._sessions.has(frame._id)) {
114
+ const parent = frame.parentFrame();
115
+ if (!parent)
116
+ throw new Error(`Frame has been detached.`);
117
+ frame = parent;
118
+ }
119
+ return this._sessions.get(frame._id);
120
+ }
121
+ _sessionForHandle(handle) {
122
+ const frame = handle._context.frame;
123
+ return this._sessionForFrame(frame);
124
+ }
125
+ willBeginDownload() {
126
+ this._mainFrameSession._willBeginDownload();
127
+ }
128
+ didClose() {
129
+ for (const session of this._sessions.values())
130
+ session.dispose();
131
+ this._page._didClose();
132
+ }
133
+ async navigateFrame(frame, url, referrer) {
134
+ return this._sessionForFrame(frame)._navigate(frame, url, referrer);
135
+ }
136
+ async updateExtraHTTPHeaders() {
137
+ const headers = network.mergeHeaders([
138
+ this._browserContext._options.extraHTTPHeaders,
139
+ this._page.extraHTTPHeaders()
140
+ ]);
141
+ await this._networkManager.setExtraHTTPHeaders(headers);
142
+ }
143
+ async updateGeolocation() {
144
+ await this._forAllFrameSessions((frame) => frame._updateGeolocation(false));
145
+ }
146
+ async updateOffline() {
147
+ await this._networkManager.setOffline(!!this._browserContext._options.offline);
148
+ }
149
+ async updateHttpCredentials() {
150
+ await this._networkManager.authenticate(this._browserContext._options.httpCredentials || null);
151
+ }
152
+ async updateEmulatedViewportSize(preserveWindowBoundaries) {
153
+ await this._mainFrameSession._updateViewport(preserveWindowBoundaries);
154
+ }
155
+ async bringToFront() {
156
+ await this._mainFrameSession._client.send("Page.bringToFront");
157
+ }
158
+ async updateEmulateMedia() {
159
+ await this._forAllFrameSessions((frame) => frame._updateEmulateMedia());
160
+ }
161
+ async updateUserAgent() {
162
+ await this._forAllFrameSessions((frame) => frame._updateUserAgent());
163
+ }
164
+ async updateRequestInterception() {
165
+ await this._networkManager.setRequestInterception(this._page.needsRequestInterception());
166
+ }
167
+ async updateFileChooserInterception() {
168
+ await this._forAllFrameSessions((frame) => frame._updateFileChooserInterception(false));
169
+ }
170
+ async reload() {
171
+ await this._mainFrameSession._client.send("Page.reload");
172
+ }
173
+ async _go(delta) {
174
+ const history = await this._mainFrameSession._client.send("Page.getNavigationHistory");
175
+ const entry = history.entries[history.currentIndex + delta];
176
+ if (!entry)
177
+ return false;
178
+ await this._mainFrameSession._client.send("Page.navigateToHistoryEntry", { entryId: entry.id });
179
+ return true;
180
+ }
181
+ goBack() {
182
+ return this._go(-1);
183
+ }
184
+ goForward() {
185
+ return this._go(1);
186
+ }
187
+ async requestGC() {
188
+ await this._mainFrameSession._client.send("HeapProfiler.collectGarbage");
189
+ }
190
+ async addInitScript(initScript, world = "main") {
191
+ await this._forAllFrameSessions((frame) => frame._evaluateOnNewDocument(initScript, world));
192
+ }
193
+ async exposePlaywrightBinding() {
194
+ await this._forAllFrameSessions((frame) => frame.exposePlaywrightBinding());
195
+ }
196
+ async removeInitScripts(initScripts) {
197
+ await this._forAllFrameSessions((frame) => frame._removeEvaluatesOnNewDocument(initScripts));
198
+ }
199
+ async closePage(runBeforeUnload) {
200
+ if (runBeforeUnload)
201
+ await this._mainFrameSession._client.send("Page.close");
202
+ else
203
+ await this._browserContext._browser._closePage(this);
204
+ }
205
+ async setBackgroundColor(color) {
206
+ await this._mainFrameSession._client.send("Emulation.setDefaultBackgroundColorOverride", { color });
207
+ }
208
+ async takeScreenshot(progress, format, documentRect, viewportRect, quality, fitsViewport, scale) {
209
+ const { visualViewport } = await progress.race(this._mainFrameSession._client.send("Page.getLayoutMetrics"));
210
+ if (!documentRect) {
211
+ documentRect = {
212
+ x: visualViewport.pageX + viewportRect.x,
213
+ y: visualViewport.pageY + viewportRect.y,
214
+ ...import_helper.helper.enclosingIntSize({
215
+ width: viewportRect.width / visualViewport.scale,
216
+ height: viewportRect.height / visualViewport.scale
217
+ })
218
+ };
219
+ }
220
+ const clip = { ...documentRect, scale: viewportRect ? visualViewport.scale : 1 };
221
+ if (scale === "css") {
222
+ const deviceScaleFactor = this._browserContext._options.deviceScaleFactor || 1;
223
+ clip.scale /= deviceScaleFactor;
224
+ }
225
+ const result = await progress.race(this._mainFrameSession._client.send("Page.captureScreenshot", { format, quality, clip, captureBeyondViewport: !fitsViewport }));
226
+ return Buffer.from(result.data, "base64");
227
+ }
228
+ async getContentFrame(handle) {
229
+ return this._sessionForHandle(handle)._getContentFrame(handle);
230
+ }
231
+ async getOwnerFrame(handle) {
232
+ return this._sessionForHandle(handle)._getOwnerFrame(handle);
233
+ }
234
+ async getBoundingBox(handle) {
235
+ return this._sessionForHandle(handle)._getBoundingBox(handle);
236
+ }
237
+ async scrollRectIntoViewIfNeeded(handle, rect) {
238
+ return this._sessionForHandle(handle)._scrollRectIntoViewIfNeeded(handle, rect);
239
+ }
240
+ async setScreencastOptions(options) {
241
+ if (options) {
242
+ await this._mainFrameSession._startScreencast(this, {
243
+ format: "jpeg",
244
+ quality: options.quality,
245
+ maxWidth: options.width,
246
+ maxHeight: options.height
247
+ });
248
+ } else {
249
+ await this._mainFrameSession._stopScreencast(this);
250
+ }
251
+ }
252
+ rafCountForStablePosition() {
253
+ return 1;
254
+ }
255
+ async getContentQuads(handle) {
256
+ return this._sessionForHandle(handle)._getContentQuads(handle);
257
+ }
258
+ async setInputFilePaths(handle, files) {
259
+ const frame = await handle.ownerFrame();
260
+ if (!frame)
261
+ throw new Error("Cannot set input files to detached input element");
262
+ const parentSession = this._sessionForFrame(frame);
263
+ await parentSession._client.send("DOM.setFileInputFiles", {
264
+ objectId: handle._objectId,
265
+ files
266
+ });
267
+ }
268
+ async adoptElementHandle(handle, to) {
269
+ return this._sessionForHandle(handle)._adoptElementHandle(handle, to);
270
+ }
271
+ async getAccessibilityTree(needle) {
272
+ return (0, import_crAccessibility.getAccessibilityTree)(this._mainFrameSession._client, needle);
273
+ }
274
+ async inputActionEpilogue() {
275
+ await this._mainFrameSession._client.send("Page.enable").catch((e) => {
276
+ });
277
+ }
278
+ async resetForReuse(progress) {
279
+ await this.rawMouse.move(progress, -1, -1, "none", /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set(), true);
280
+ }
281
+ async pdf(options) {
282
+ return this._pdf.generate(options);
283
+ }
284
+ coverage() {
285
+ return this._coverage;
286
+ }
287
+ async getFrameElement(frame) {
288
+ let parent = frame.parentFrame();
289
+ if (!parent)
290
+ throw new Error("Frame has been detached.");
291
+ const parentSession = this._sessionForFrame(parent);
292
+ const { backendNodeId } = await parentSession._client.send("DOM.getFrameOwner", { frameId: frame._id }).catch((e) => {
293
+ if (e instanceof Error && e.message.includes("Frame with the given id was not found."))
294
+ (0, import_stackTrace.rewriteErrorMessage)(e, "Frame has been detached.");
295
+ throw e;
296
+ });
297
+ parent = frame.parentFrame();
298
+ if (!parent)
299
+ throw new Error("Frame has been detached.");
300
+ return parentSession._adoptBackendNodeId(backendNodeId, await parent._mainContext());
301
+ }
302
+ shouldToggleStyleSheetToSyncAnimations() {
303
+ return false;
304
+ }
305
+ }
306
+ class FrameSession {
307
+ constructor(crPage, client, targetId, parentSession) {
308
+ this._childSessions = /* @__PURE__ */ new Set();
309
+ this._contextIdToContext = /* @__PURE__ */ new Map();
310
+ this._eventListeners = [];
311
+ this._firstNonInitialNavigationCommittedFulfill = () => {
312
+ };
313
+ this._firstNonInitialNavigationCommittedReject = (e) => {
314
+ };
315
+ // Marks the oopif session that remote -> local transition has happened in the parent.
316
+ // See Target.detachedFromTarget handler for details.
317
+ this._swappedIn = false;
318
+ this._videoRecorder = null;
319
+ this._screencastId = null;
320
+ this._screencastClients = /* @__PURE__ */ new Set();
321
+ this._workerSessions = /* @__PURE__ */ new Map();
322
+ this._initScriptIds = /* @__PURE__ */ new Map();
323
+ this._client = client;
324
+ this._crPage = crPage;
325
+ this._page = crPage._page;
326
+ this._targetId = targetId;
327
+ this._parentSession = parentSession;
328
+ if (parentSession)
329
+ parentSession._childSessions.add(this);
330
+ this._firstNonInitialNavigationCommittedPromise = new Promise((f, r) => {
331
+ this._firstNonInitialNavigationCommittedFulfill = f;
332
+ this._firstNonInitialNavigationCommittedReject = r;
333
+ });
334
+ this._firstNonInitialNavigationCommittedPromise.catch(() => {
335
+ });
336
+ }
337
+ _isMainFrame() {
338
+ return this._targetId === this._crPage._targetId;
339
+ }
340
+ _addRendererListeners() {
341
+ this._eventListeners.push(...[
342
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Log.entryAdded", (event) => this._onLogEntryAdded(event)),
343
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.fileChooserOpened", (event) => this._onFileChooserOpened(event)),
344
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.frameAttached", (event) => this._onFrameAttached(event.frameId, event.parentFrameId)),
345
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.frameDetached", (event) => this._onFrameDetached(event.frameId, event.reason)),
346
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.frameNavigated", (event) => this._onFrameNavigated(event.frame, false)),
347
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.frameRequestedNavigation", (event) => this._onFrameRequestedNavigation(event)),
348
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.javascriptDialogOpening", (event) => this._onDialog(event)),
349
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.navigatedWithinDocument", (event) => this._onFrameNavigatedWithinDocument(event.frameId, event.url)),
350
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Runtime.bindingCalled", (event) => this._onBindingCalled(event)),
351
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Runtime.consoleAPICalled", (event) => this._onConsoleAPI(event)),
352
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Runtime.exceptionThrown", (exception) => this._handleException(exception.exceptionDetails)),
353
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Runtime.executionContextCreated", (event) => this._onExecutionContextCreated(event.context)),
354
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Runtime.executionContextDestroyed", (event) => this._onExecutionContextDestroyed(event.executionContextId)),
355
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Runtime.executionContextsCleared", (event) => this._onExecutionContextsCleared())
356
+ ]);
357
+ }
358
+ _addBrowserListeners() {
359
+ this._eventListeners.push(...[
360
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Target.attachedToTarget", (event) => this._onAttachedToTarget(event)),
361
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Target.detachedFromTarget", (event) => this._onDetachedFromTarget(event)),
362
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Inspector.targetCrashed", (event) => this._onTargetCrashed()),
363
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.screencastFrame", (event) => this._onScreencastFrame(event)),
364
+ import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.windowOpen", (event) => this._onWindowOpen(event))
365
+ ]);
366
+ }
367
+ async _initialize(hasUIWindow) {
368
+ if (!this._page.isStorageStatePage && hasUIWindow && !this._crPage._browserContext._browser.isClank() && !this._crPage._browserContext._options.noDefaultViewport) {
369
+ const { windowId } = await this._client.send("Browser.getWindowForTarget");
370
+ this._windowId = windowId;
371
+ }
372
+ let screencastOptions;
373
+ if (!this._page.isStorageStatePage && this._isMainFrame() && this._crPage._browserContext._options.recordVideo && hasUIWindow) {
374
+ const screencastId = (0, import_crypto.createGuid)();
375
+ const outputFile = import_path.default.join(this._crPage._browserContext._options.recordVideo.dir, screencastId + ".webm");
376
+ screencastOptions = {
377
+ // validateBrowserContextOptions ensures correct video size.
378
+ ...this._crPage._browserContext._options.recordVideo.size,
379
+ outputFile
380
+ };
381
+ await this._crPage._browserContext._ensureVideosPath();
382
+ await this._createVideoRecorder(screencastId, screencastOptions);
383
+ this._crPage._page.waitForInitializedOrError().then((p) => {
384
+ if (p instanceof Error)
385
+ this._stopVideoRecording().catch(() => {
386
+ });
387
+ });
388
+ }
389
+ let lifecycleEventsEnabled;
390
+ if (!this._isMainFrame())
391
+ this._addRendererListeners();
392
+ this._addBrowserListeners();
393
+ this._bufferedAttachedToTargetEvents = [];
394
+ const promises = [
395
+ this._client.send("Page.enable"),
396
+ this._client.send("Page.getFrameTree").then(({ frameTree }) => {
397
+ if (this._isMainFrame()) {
398
+ this._handleFrameTree(frameTree);
399
+ this._addRendererListeners();
400
+ }
401
+ const attachedToTargetEvents = this._bufferedAttachedToTargetEvents || [];
402
+ this._bufferedAttachedToTargetEvents = void 0;
403
+ for (const event of attachedToTargetEvents)
404
+ this._onAttachedToTarget(event);
405
+ const localFrames = this._isMainFrame() ? this._page.frames() : [this._page.frameManager.frame(this._targetId)];
406
+ for (const frame of localFrames) {
407
+ this._client._sendMayFail("Page.createIsolatedWorld", {
408
+ frameId: frame._id,
409
+ grantUniveralAccess: true,
410
+ worldName: this._crPage.utilityWorldName
411
+ });
412
+ }
413
+ const isInitialEmptyPage = this._isMainFrame() && this._page.mainFrame().url() === ":";
414
+ if (isInitialEmptyPage) {
415
+ lifecycleEventsEnabled.catch((e) => {
416
+ }).then(() => {
417
+ this._eventListeners.push(import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.lifecycleEvent", (event) => this._onLifecycleEvent(event)));
418
+ });
419
+ } else {
420
+ this._firstNonInitialNavigationCommittedFulfill();
421
+ this._eventListeners.push(import_eventsHelper.eventsHelper.addEventListener(this._client, "Page.lifecycleEvent", (event) => this._onLifecycleEvent(event)));
422
+ }
423
+ }),
424
+ this._client.send("Log.enable", {}),
425
+ lifecycleEventsEnabled = this._client.send("Page.setLifecycleEventsEnabled", { enabled: true }),
426
+ this._client.send("Runtime.enable", {}),
427
+ this._client.send("Page.addScriptToEvaluateOnNewDocument", {
428
+ source: "",
429
+ worldName: this._crPage.utilityWorldName
430
+ }),
431
+ this._crPage._networkManager.addSession(this._client, void 0, this._isMainFrame()),
432
+ this._client.send("Target.setAutoAttach", { autoAttach: true, waitForDebuggerOnStart: true, flatten: true })
433
+ ];
434
+ if (!this._page.isStorageStatePage) {
435
+ if (this._crPage._browserContext.needsPlaywrightBinding())
436
+ promises.push(this.exposePlaywrightBinding());
437
+ if (this._isMainFrame())
438
+ promises.push(this._client.send("Emulation.setFocusEmulationEnabled", { enabled: true }));
439
+ const options = this._crPage._browserContext._options;
440
+ if (options.bypassCSP)
441
+ promises.push(this._client.send("Page.setBypassCSP", { enabled: true }));
442
+ if (options.ignoreHTTPSErrors || options.internalIgnoreHTTPSErrors)
443
+ promises.push(this._client.send("Security.setIgnoreCertificateErrors", { ignore: true }));
444
+ if (this._isMainFrame())
445
+ promises.push(this._updateViewport());
446
+ if (options.hasTouch)
447
+ promises.push(this._client.send("Emulation.setTouchEmulationEnabled", { enabled: true }));
448
+ if (options.javaScriptEnabled === false)
449
+ promises.push(this._client.send("Emulation.setScriptExecutionDisabled", { value: true }));
450
+ if (options.userAgent || options.locale)
451
+ promises.push(this._updateUserAgent());
452
+ if (options.locale)
453
+ promises.push(emulateLocale(this._client, options.locale));
454
+ if (options.timezoneId)
455
+ promises.push(emulateTimezone(this._client, options.timezoneId));
456
+ if (!this._crPage._browserContext._browser.options.headful)
457
+ promises.push(this._setDefaultFontFamilies(this._client));
458
+ promises.push(this._updateGeolocation(true));
459
+ promises.push(this._updateEmulateMedia());
460
+ promises.push(this._updateFileChooserInterception(true));
461
+ for (const initScript of this._crPage._page.allInitScripts())
462
+ promises.push(this._evaluateOnNewDocument(
463
+ initScript,
464
+ "main",
465
+ true
466
+ /* runImmediately */
467
+ ));
468
+ if (screencastOptions)
469
+ promises.push(this._startVideoRecording(screencastOptions));
470
+ }
471
+ promises.push(this._client.send("Runtime.runIfWaitingForDebugger"));
472
+ promises.push(this._firstNonInitialNavigationCommittedPromise);
473
+ await Promise.all(promises);
474
+ }
475
+ dispose() {
476
+ this._firstNonInitialNavigationCommittedReject(new import_errors.TargetClosedError());
477
+ for (const childSession of this._childSessions)
478
+ childSession.dispose();
479
+ if (this._parentSession)
480
+ this._parentSession._childSessions.delete(this);
481
+ import_eventsHelper.eventsHelper.removeEventListeners(this._eventListeners);
482
+ this._crPage._networkManager.removeSession(this._client);
483
+ this._crPage._sessions.delete(this._targetId);
484
+ this._client.dispose();
485
+ }
486
+ async _navigate(frame, url, referrer) {
487
+ const response = await this._client.send("Page.navigate", { url, referrer, frameId: frame._id, referrerPolicy: "unsafeUrl" });
488
+ if (response.isDownload)
489
+ throw new frames.NavigationAbortedError(response.loaderId, "Download is starting");
490
+ if (response.errorText)
491
+ throw new frames.NavigationAbortedError(response.loaderId, `${response.errorText} at ${url}`);
492
+ return { newDocumentId: response.loaderId };
493
+ }
494
+ _onLifecycleEvent(event) {
495
+ if (this._eventBelongsToStaleFrame(event.frameId))
496
+ return;
497
+ if (event.name === "load")
498
+ this._page.frameManager.frameLifecycleEvent(event.frameId, "load");
499
+ else if (event.name === "DOMContentLoaded")
500
+ this._page.frameManager.frameLifecycleEvent(event.frameId, "domcontentloaded");
501
+ }
502
+ _handleFrameTree(frameTree) {
503
+ this._onFrameAttached(frameTree.frame.id, frameTree.frame.parentId || null);
504
+ this._onFrameNavigated(frameTree.frame, true);
505
+ if (!frameTree.childFrames)
506
+ return;
507
+ for (const child of frameTree.childFrames)
508
+ this._handleFrameTree(child);
509
+ }
510
+ _eventBelongsToStaleFrame(frameId) {
511
+ const frame = this._page.frameManager.frame(frameId);
512
+ if (!frame)
513
+ return true;
514
+ const session = this._crPage._sessionForFrame(frame);
515
+ return session && session !== this && !session._swappedIn;
516
+ }
517
+ _onFrameAttached(frameId, parentFrameId) {
518
+ const frameSession = this._crPage._sessions.get(frameId);
519
+ if (frameSession && frameId !== this._targetId) {
520
+ frameSession._swappedIn = true;
521
+ const frame = this._page.frameManager.frame(frameId);
522
+ if (frame)
523
+ this._page.frameManager.removeChildFramesRecursively(frame);
524
+ return;
525
+ }
526
+ if (parentFrameId && !this._page.frameManager.frame(parentFrameId)) {
527
+ return;
528
+ }
529
+ this._page.frameManager.frameAttached(frameId, parentFrameId);
530
+ }
531
+ _onFrameNavigated(framePayload, initial) {
532
+ if (this._eventBelongsToStaleFrame(framePayload.id))
533
+ return;
534
+ this._page.frameManager.frameCommittedNewDocumentNavigation(framePayload.id, framePayload.url + (framePayload.urlFragment || ""), framePayload.name || "", framePayload.loaderId, initial);
535
+ if (!initial)
536
+ this._firstNonInitialNavigationCommittedFulfill();
537
+ }
538
+ _onFrameRequestedNavigation(payload) {
539
+ if (this._eventBelongsToStaleFrame(payload.frameId))
540
+ return;
541
+ if (payload.disposition === "currentTab")
542
+ this._page.frameManager.frameRequestedNavigation(payload.frameId);
543
+ }
544
+ _onFrameNavigatedWithinDocument(frameId, url) {
545
+ if (this._eventBelongsToStaleFrame(frameId))
546
+ return;
547
+ this._page.frameManager.frameCommittedSameDocumentNavigation(frameId, url);
548
+ }
549
+ _onFrameDetached(frameId, reason) {
550
+ if (this._crPage._sessions.has(frameId)) {
551
+ return;
552
+ }
553
+ if (reason === "swap") {
554
+ const frame = this._page.frameManager.frame(frameId);
555
+ if (frame)
556
+ this._page.frameManager.removeChildFramesRecursively(frame);
557
+ return;
558
+ }
559
+ this._page.frameManager.frameDetached(frameId);
560
+ }
561
+ _onExecutionContextCreated(contextPayload) {
562
+ const frame = contextPayload.auxData ? this._page.frameManager.frame(contextPayload.auxData.frameId) : null;
563
+ if (!frame || this._eventBelongsToStaleFrame(frame._id))
564
+ return;
565
+ const delegate = new import_crExecutionContext.CRExecutionContext(this._client, contextPayload);
566
+ let worldName = null;
567
+ if (contextPayload.auxData && !!contextPayload.auxData.isDefault)
568
+ worldName = "main";
569
+ else if (contextPayload.name === this._crPage.utilityWorldName)
570
+ worldName = "utility";
571
+ const context = new dom.FrameExecutionContext(delegate, frame, worldName);
572
+ if (worldName)
573
+ frame._contextCreated(worldName, context);
574
+ this._contextIdToContext.set(contextPayload.id, context);
575
+ }
576
+ _onExecutionContextDestroyed(executionContextId) {
577
+ const context = this._contextIdToContext.get(executionContextId);
578
+ if (!context)
579
+ return;
580
+ this._contextIdToContext.delete(executionContextId);
581
+ context.frame._contextDestroyed(context);
582
+ }
583
+ _onExecutionContextsCleared() {
584
+ for (const contextId of Array.from(this._contextIdToContext.keys()))
585
+ this._onExecutionContextDestroyed(contextId);
586
+ }
587
+ _onAttachedToTarget(event) {
588
+ if (this._bufferedAttachedToTargetEvents) {
589
+ this._bufferedAttachedToTargetEvents.push(event);
590
+ return;
591
+ }
592
+ const session = this._client.createChildSession(event.sessionId);
593
+ if (event.targetInfo.type === "iframe") {
594
+ const targetId = event.targetInfo.targetId;
595
+ let frame = this._page.frameManager.frame(targetId);
596
+ if (!frame && event.targetInfo.parentFrameId) {
597
+ frame = this._page.frameManager.frameAttached(targetId, event.targetInfo.parentFrameId);
598
+ }
599
+ if (!frame)
600
+ return;
601
+ this._page.frameManager.removeChildFramesRecursively(frame);
602
+ for (const [contextId, context] of this._contextIdToContext) {
603
+ if (context.frame === frame)
604
+ this._onExecutionContextDestroyed(contextId);
605
+ }
606
+ const frameSession = new FrameSession(this._crPage, session, targetId, this);
607
+ this._crPage._sessions.set(targetId, frameSession);
608
+ frameSession._initialize(false).catch((e) => e);
609
+ return;
610
+ }
611
+ if (event.targetInfo.type !== "worker") {
612
+ session.detach().catch(() => {
613
+ });
614
+ return;
615
+ }
616
+ const url = event.targetInfo.url;
617
+ const worker = new import_page.Worker(this._page, url);
618
+ this._page.addWorker(event.sessionId, worker);
619
+ this._workerSessions.set(event.sessionId, session);
620
+ session.once("Runtime.executionContextCreated", async (event2) => {
621
+ worker.createExecutionContext(new import_crExecutionContext.CRExecutionContext(session, event2.context));
622
+ });
623
+ session._sendMayFail("Runtime.enable");
624
+ this._crPage._networkManager.addSession(session, this._page.frameManager.frame(this._targetId) ?? void 0).catch(() => {
625
+ });
626
+ session._sendMayFail("Runtime.runIfWaitingForDebugger");
627
+ session._sendMayFail("Target.setAutoAttach", { autoAttach: true, waitForDebuggerOnStart: true, flatten: true });
628
+ session.on("Target.attachedToTarget", (event2) => this._onAttachedToTarget(event2));
629
+ session.on("Target.detachedFromTarget", (event2) => this._onDetachedFromTarget(event2));
630
+ session.on("Runtime.consoleAPICalled", (event2) => {
631
+ const args = event2.args.map((o) => (0, import_crExecutionContext.createHandle)(worker.existingExecutionContext, o));
632
+ this._page.addConsoleMessage(event2.type, args, (0, import_crProtocolHelper.toConsoleMessageLocation)(event2.stackTrace));
633
+ });
634
+ session.on("Runtime.exceptionThrown", (exception) => this._page.addPageError((0, import_crProtocolHelper.exceptionToError)(exception.exceptionDetails)));
635
+ }
636
+ _onDetachedFromTarget(event) {
637
+ const workerSession = this._workerSessions.get(event.sessionId);
638
+ if (workerSession) {
639
+ workerSession.dispose();
640
+ this._page.removeWorker(event.sessionId);
641
+ return;
642
+ }
643
+ const childFrameSession = this._crPage._sessions.get(event.targetId);
644
+ if (!childFrameSession)
645
+ return;
646
+ if (childFrameSession._swappedIn) {
647
+ childFrameSession.dispose();
648
+ return;
649
+ }
650
+ this._client.send("Page.enable").catch((e) => null).then(() => {
651
+ if (!childFrameSession._swappedIn)
652
+ this._page.frameManager.frameDetached(event.targetId);
653
+ childFrameSession.dispose();
654
+ });
655
+ }
656
+ _onWindowOpen(event) {
657
+ this._crPage._nextWindowOpenPopupFeatures.push(event.windowFeatures);
658
+ }
659
+ async _onConsoleAPI(event) {
660
+ if (event.executionContextId === 0) {
661
+ return;
662
+ }
663
+ const context = this._contextIdToContext.get(event.executionContextId);
664
+ if (!context)
665
+ return;
666
+ const values = event.args.map((arg) => (0, import_crExecutionContext.createHandle)(context, arg));
667
+ this._page.addConsoleMessage(event.type, values, (0, import_crProtocolHelper.toConsoleMessageLocation)(event.stackTrace));
668
+ }
669
+ async _onBindingCalled(event) {
670
+ const pageOrError = await this._crPage._page.waitForInitializedOrError();
671
+ if (!(pageOrError instanceof Error)) {
672
+ const context = this._contextIdToContext.get(event.executionContextId);
673
+ if (context)
674
+ await this._page.onBindingCalled(event.payload, context);
675
+ }
676
+ }
677
+ _onDialog(event) {
678
+ if (!this._page.frameManager.frame(this._targetId))
679
+ return;
680
+ this._page.browserContext.dialogManager.dialogDidOpen(new dialog.Dialog(
681
+ this._page,
682
+ event.type,
683
+ event.message,
684
+ async (accept, promptText) => {
685
+ if (this._isMainFrame() && event.type === "beforeunload" && !accept)
686
+ this._page.frameManager.frameAbortedNavigation(this._page.mainFrame()._id, "navigation cancelled by beforeunload dialog");
687
+ await this._client.send("Page.handleJavaScriptDialog", { accept, promptText });
688
+ },
689
+ event.defaultPrompt
690
+ ));
691
+ }
692
+ _handleException(exceptionDetails) {
693
+ this._page.addPageError((0, import_crProtocolHelper.exceptionToError)(exceptionDetails));
694
+ }
695
+ async _onTargetCrashed() {
696
+ this._client._markAsCrashed();
697
+ this._page._didCrash();
698
+ }
699
+ _onLogEntryAdded(event) {
700
+ const { level, text, args, source, url, lineNumber } = event.entry;
701
+ if (args)
702
+ args.map((arg) => (0, import_crProtocolHelper.releaseObject)(this._client, arg.objectId));
703
+ if (source !== "worker") {
704
+ const location = {
705
+ url: url || "",
706
+ lineNumber: lineNumber || 0,
707
+ columnNumber: 0
708
+ };
709
+ this._page.addConsoleMessage(level, [], location, text);
710
+ }
711
+ }
712
+ async _onFileChooserOpened(event) {
713
+ if (!event.backendNodeId)
714
+ return;
715
+ const frame = this._page.frameManager.frame(event.frameId);
716
+ if (!frame)
717
+ return;
718
+ let handle;
719
+ try {
720
+ const utilityContext = await frame._utilityContext();
721
+ handle = await this._adoptBackendNodeId(event.backendNodeId, utilityContext);
722
+ } catch (e) {
723
+ return;
724
+ }
725
+ await this._page._onFileChooserOpened(handle);
726
+ }
727
+ _willBeginDownload() {
728
+ if (!this._crPage._page.initializedOrUndefined()) {
729
+ this._firstNonInitialNavigationCommittedReject(new Error("Starting new page download"));
730
+ }
731
+ }
732
+ _onScreencastFrame(payload) {
733
+ this._page.throttleScreencastFrameAck(() => {
734
+ this._client.send("Page.screencastFrameAck", { sessionId: payload.sessionId }).catch(() => {
735
+ });
736
+ });
737
+ const buffer = Buffer.from(payload.data, "base64");
738
+ this._page.emit(import_page.Page.Events.ScreencastFrame, {
739
+ buffer,
740
+ frameSwapWallTime: payload.metadata.timestamp ? payload.metadata.timestamp * 1e3 : void 0,
741
+ width: payload.metadata.deviceWidth,
742
+ height: payload.metadata.deviceHeight
743
+ });
744
+ }
745
+ async _createVideoRecorder(screencastId, options) {
746
+ (0, import_assert.assert)(!this._screencastId);
747
+ const ffmpegPath = import_registry.registry.findExecutable("ffmpeg").executablePathOrDie(this._page.browserContext._browser.sdkLanguage());
748
+ this._videoRecorder = await import_videoRecorder.VideoRecorder.launch(this._crPage._page, ffmpegPath, options);
749
+ this._screencastId = screencastId;
750
+ }
751
+ async _startVideoRecording(options) {
752
+ const screencastId = this._screencastId;
753
+ (0, import_assert.assert)(screencastId);
754
+ this._page.once(import_page.Page.Events.Close, () => this._stopVideoRecording().catch(() => {
755
+ }));
756
+ const gotFirstFrame = new Promise((f) => this._client.once("Page.screencastFrame", f));
757
+ await this._startScreencast(this._videoRecorder, {
758
+ format: "jpeg",
759
+ quality: 90,
760
+ maxWidth: options.width,
761
+ maxHeight: options.height
762
+ });
763
+ gotFirstFrame.then(() => {
764
+ this._crPage._browserContext._browser._videoStarted(this._crPage._browserContext, screencastId, options.outputFile, this._crPage._page.waitForInitializedOrError());
765
+ });
766
+ }
767
+ async _stopVideoRecording() {
768
+ if (!this._screencastId)
769
+ return;
770
+ const screencastId = this._screencastId;
771
+ this._screencastId = null;
772
+ const recorder = this._videoRecorder;
773
+ this._videoRecorder = null;
774
+ await this._stopScreencast(recorder);
775
+ await recorder.stop().catch(() => {
776
+ });
777
+ const video = this._crPage._browserContext._browser._takeVideo(screencastId);
778
+ video?.reportFinished();
779
+ }
780
+ async _startScreencast(client, options = {}) {
781
+ this._screencastClients.add(client);
782
+ if (this._screencastClients.size === 1)
783
+ await this._client.send("Page.startScreencast", options);
784
+ }
785
+ async _stopScreencast(client) {
786
+ this._screencastClients.delete(client);
787
+ if (!this._screencastClients.size)
788
+ await this._client._sendMayFail("Page.stopScreencast");
789
+ }
790
+ async _updateGeolocation(initial) {
791
+ const geolocation = this._crPage._browserContext._options.geolocation;
792
+ if (!initial || geolocation)
793
+ await this._client.send("Emulation.setGeolocationOverride", geolocation || {});
794
+ }
795
+ async _updateViewport(preserveWindowBoundaries) {
796
+ if (this._crPage._browserContext._browser.isClank())
797
+ return;
798
+ (0, import_assert.assert)(this._isMainFrame());
799
+ const options = this._crPage._browserContext._options;
800
+ const emulatedSize = this._page.emulatedSize();
801
+ if (!emulatedSize)
802
+ return;
803
+ const viewportSize = emulatedSize.viewport;
804
+ const screenSize = emulatedSize.screen;
805
+ const isLandscape = screenSize.width > screenSize.height;
806
+ const metricsOverride = {
807
+ mobile: !!options.isMobile,
808
+ width: viewportSize.width,
809
+ height: viewportSize.height,
810
+ screenWidth: screenSize.width,
811
+ screenHeight: screenSize.height,
812
+ deviceScaleFactor: options.deviceScaleFactor || 1,
813
+ screenOrientation: !!options.isMobile ? isLandscape ? { angle: 90, type: "landscapePrimary" } : { angle: 0, type: "portraitPrimary" } : { angle: 0, type: "landscapePrimary" },
814
+ dontSetVisibleSize: preserveWindowBoundaries
815
+ };
816
+ if (JSON.stringify(this._metricsOverride) === JSON.stringify(metricsOverride))
817
+ return;
818
+ const promises = [];
819
+ if (!preserveWindowBoundaries && this._windowId) {
820
+ let insets = { width: 0, height: 0 };
821
+ if (this._crPage._browserContext._browser.options.headful) {
822
+ insets = { width: 24, height: 88 };
823
+ if (process.platform === "win32")
824
+ insets = { width: 16, height: 88 };
825
+ else if (process.platform === "linux")
826
+ insets = { width: 8, height: 85 };
827
+ else if (process.platform === "darwin")
828
+ insets = { width: 2, height: 80 };
829
+ if (this._crPage._browserContext.isPersistentContext()) {
830
+ insets.height += 46;
831
+ }
832
+ }
833
+ promises.push(this.setWindowBounds({
834
+ width: viewportSize.width + insets.width,
835
+ height: viewportSize.height + insets.height
836
+ }));
837
+ }
838
+ promises.push(this._client.send("Emulation.setDeviceMetricsOverride", metricsOverride));
839
+ await Promise.all(promises);
840
+ this._metricsOverride = metricsOverride;
841
+ }
842
+ async windowBounds() {
843
+ const { bounds } = await this._client.send("Browser.getWindowBounds", {
844
+ windowId: this._windowId
845
+ });
846
+ return bounds;
847
+ }
848
+ async setWindowBounds(bounds) {
849
+ return await this._client.send("Browser.setWindowBounds", {
850
+ windowId: this._windowId,
851
+ bounds
852
+ });
853
+ }
854
+ async _updateEmulateMedia() {
855
+ const emulatedMedia = this._page.emulatedMedia();
856
+ const media = emulatedMedia.media === "no-override" ? "" : emulatedMedia.media;
857
+ const colorScheme = emulatedMedia.colorScheme === "no-override" ? "" : emulatedMedia.colorScheme;
858
+ const reducedMotion = emulatedMedia.reducedMotion === "no-override" ? "" : emulatedMedia.reducedMotion;
859
+ const forcedColors = emulatedMedia.forcedColors === "no-override" ? "" : emulatedMedia.forcedColors;
860
+ const contrast = emulatedMedia.contrast === "no-override" ? "" : emulatedMedia.contrast;
861
+ const features = [
862
+ { name: "prefers-color-scheme", value: colorScheme },
863
+ { name: "prefers-reduced-motion", value: reducedMotion },
864
+ { name: "forced-colors", value: forcedColors },
865
+ { name: "prefers-contrast", value: contrast }
866
+ ];
867
+ await this._client.send("Emulation.setEmulatedMedia", { media, features });
868
+ }
869
+ async _updateUserAgent() {
870
+ const options = this._crPage._browserContext._options;
871
+ await this._client.send("Emulation.setUserAgentOverride", {
872
+ userAgent: options.userAgent || "",
873
+ acceptLanguage: options.locale,
874
+ userAgentMetadata: calculateUserAgentMetadata(options)
875
+ });
876
+ }
877
+ async _setDefaultFontFamilies(session) {
878
+ const fontFamilies = import_defaultFontFamilies.platformToFontFamilies[this._crPage._browserContext._browser._platform()];
879
+ await session.send("Page.setFontFamilies", fontFamilies);
880
+ }
881
+ async _updateFileChooserInterception(initial) {
882
+ const enabled = this._page.fileChooserIntercepted();
883
+ if (initial && !enabled)
884
+ return;
885
+ await this._client.send("Page.setInterceptFileChooserDialog", { enabled }).catch(() => {
886
+ });
887
+ }
888
+ async _evaluateOnNewDocument(initScript, world, runImmediately) {
889
+ const worldName = world === "utility" ? this._crPage.utilityWorldName : void 0;
890
+ const { identifier } = await this._client.send("Page.addScriptToEvaluateOnNewDocument", { source: initScript.source, worldName, runImmediately });
891
+ this._initScriptIds.set(initScript, identifier);
892
+ }
893
+ async _removeEvaluatesOnNewDocument(initScripts) {
894
+ const ids = [];
895
+ for (const script of initScripts) {
896
+ const id = this._initScriptIds.get(script);
897
+ if (id)
898
+ ids.push(id);
899
+ this._initScriptIds.delete(script);
900
+ }
901
+ await Promise.all(ids.map((identifier) => this._client.send("Page.removeScriptToEvaluateOnNewDocument", { identifier }).catch(() => {
902
+ })));
903
+ }
904
+ async exposePlaywrightBinding() {
905
+ await this._client.send("Runtime.addBinding", { name: import_page.PageBinding.kBindingName });
906
+ }
907
+ async _getContentFrame(handle) {
908
+ const nodeInfo = await this._client.send("DOM.describeNode", {
909
+ objectId: handle._objectId
910
+ });
911
+ if (!nodeInfo || typeof nodeInfo.node.frameId !== "string")
912
+ return null;
913
+ return this._page.frameManager.frame(nodeInfo.node.frameId);
914
+ }
915
+ async _getOwnerFrame(handle) {
916
+ const documentElement = await handle.evaluateHandle((node) => {
917
+ const doc = node;
918
+ if (doc.documentElement && doc.documentElement.ownerDocument === doc)
919
+ return doc.documentElement;
920
+ return node.ownerDocument ? node.ownerDocument.documentElement : null;
921
+ });
922
+ if (!documentElement)
923
+ return null;
924
+ if (!documentElement._objectId)
925
+ return null;
926
+ const nodeInfo = await this._client.send("DOM.describeNode", {
927
+ objectId: documentElement._objectId
928
+ });
929
+ const frameId = nodeInfo && typeof nodeInfo.node.frameId === "string" ? nodeInfo.node.frameId : null;
930
+ documentElement.dispose();
931
+ return frameId;
932
+ }
933
+ async _getBoundingBox(handle) {
934
+ const result = await this._client._sendMayFail("DOM.getBoxModel", {
935
+ objectId: handle._objectId
936
+ });
937
+ if (!result)
938
+ return null;
939
+ const quad = result.model.border;
940
+ const x = Math.min(quad[0], quad[2], quad[4], quad[6]);
941
+ const y = Math.min(quad[1], quad[3], quad[5], quad[7]);
942
+ const width = Math.max(quad[0], quad[2], quad[4], quad[6]) - x;
943
+ const height = Math.max(quad[1], quad[3], quad[5], quad[7]) - y;
944
+ const position = await this._framePosition();
945
+ if (!position)
946
+ return null;
947
+ return { x: x + position.x, y: y + position.y, width, height };
948
+ }
949
+ async _framePosition() {
950
+ const frame = this._page.frameManager.frame(this._targetId);
951
+ if (!frame)
952
+ return null;
953
+ if (frame === this._page.mainFrame())
954
+ return { x: 0, y: 0 };
955
+ const element = await frame.frameElement();
956
+ const box = await element.boundingBox();
957
+ return box;
958
+ }
959
+ async _scrollRectIntoViewIfNeeded(handle, rect) {
960
+ return await this._client.send("DOM.scrollIntoViewIfNeeded", {
961
+ objectId: handle._objectId,
962
+ rect
963
+ }).then(() => "done").catch((e) => {
964
+ if (e instanceof Error && e.message.includes("Node does not have a layout object"))
965
+ return "error:notvisible";
966
+ if (e instanceof Error && e.message.includes("Node is detached from document"))
967
+ return "error:notconnected";
968
+ throw e;
969
+ });
970
+ }
971
+ async _getContentQuads(handle) {
972
+ const result = await this._client._sendMayFail("DOM.getContentQuads", {
973
+ objectId: handle._objectId
974
+ });
975
+ if (!result)
976
+ return null;
977
+ const position = await this._framePosition();
978
+ if (!position)
979
+ return null;
980
+ return result.quads.map((quad) => [
981
+ { x: quad[0] + position.x, y: quad[1] + position.y },
982
+ { x: quad[2] + position.x, y: quad[3] + position.y },
983
+ { x: quad[4] + position.x, y: quad[5] + position.y },
984
+ { x: quad[6] + position.x, y: quad[7] + position.y }
985
+ ]);
986
+ }
987
+ async _adoptElementHandle(handle, to) {
988
+ const nodeInfo = await this._client.send("DOM.describeNode", {
989
+ objectId: handle._objectId
990
+ });
991
+ return this._adoptBackendNodeId(nodeInfo.node.backendNodeId, to);
992
+ }
993
+ async _adoptBackendNodeId(backendNodeId, to) {
994
+ const result = await this._client._sendMayFail("DOM.resolveNode", {
995
+ backendNodeId,
996
+ executionContextId: to.delegate._contextId
997
+ });
998
+ if (!result || result.object.subtype === "null")
999
+ throw new Error(dom.kUnableToAdoptErrorMessage);
1000
+ return (0, import_crExecutionContext.createHandle)(to, result.object).asElement();
1001
+ }
1002
+ }
1003
+ async function emulateLocale(session, locale) {
1004
+ try {
1005
+ await session.send("Emulation.setLocaleOverride", { locale });
1006
+ } catch (exception) {
1007
+ if (exception.message.includes("Another locale override is already in effect"))
1008
+ return;
1009
+ throw exception;
1010
+ }
1011
+ }
1012
+ async function emulateTimezone(session, timezoneId) {
1013
+ try {
1014
+ await session.send("Emulation.setTimezoneOverride", { timezoneId });
1015
+ } catch (exception) {
1016
+ if (exception.message.includes("Timezone override is already in effect"))
1017
+ return;
1018
+ if (exception.message.includes("Invalid timezone"))
1019
+ throw new Error(`Invalid timezone ID: ${timezoneId}`);
1020
+ throw exception;
1021
+ }
1022
+ }
1023
+ function calculateUserAgentMetadata(options) {
1024
+ const ua = options.userAgent;
1025
+ if (!ua)
1026
+ return void 0;
1027
+ const metadata = {
1028
+ mobile: !!options.isMobile,
1029
+ model: "",
1030
+ architecture: "x86",
1031
+ platform: "Windows",
1032
+ platformVersion: ""
1033
+ };
1034
+ const androidMatch = ua.match(/Android (\d+(\.\d+)?(\.\d+)?)/);
1035
+ const iPhoneMatch = ua.match(/iPhone OS (\d+(_\d+)?)/);
1036
+ const iPadMatch = ua.match(/iPad; CPU OS (\d+(_\d+)?)/);
1037
+ const macOSMatch = ua.match(/Mac OS X (\d+(_\d+)?(_\d+)?)/);
1038
+ const windowsMatch = ua.match(/Windows\D+(\d+(\.\d+)?(\.\d+)?)/);
1039
+ if (androidMatch) {
1040
+ metadata.platform = "Android";
1041
+ metadata.platformVersion = androidMatch[1];
1042
+ metadata.architecture = "arm";
1043
+ } else if (iPhoneMatch) {
1044
+ metadata.platform = "iOS";
1045
+ metadata.platformVersion = iPhoneMatch[1];
1046
+ metadata.architecture = "arm";
1047
+ } else if (iPadMatch) {
1048
+ metadata.platform = "iOS";
1049
+ metadata.platformVersion = iPadMatch[1];
1050
+ metadata.architecture = "arm";
1051
+ } else if (macOSMatch) {
1052
+ metadata.platform = "macOS";
1053
+ metadata.platformVersion = macOSMatch[1];
1054
+ if (!ua.includes("Intel"))
1055
+ metadata.architecture = "arm";
1056
+ } else if (windowsMatch) {
1057
+ metadata.platform = "Windows";
1058
+ metadata.platformVersion = windowsMatch[1];
1059
+ } else if (ua.toLowerCase().includes("linux")) {
1060
+ metadata.platform = "Linux";
1061
+ }
1062
+ if (ua.includes("ARM"))
1063
+ metadata.architecture = "arm";
1064
+ return metadata;
1065
+ }
1066
+ // Annotate the CommonJS export names for ESM import in node:
1067
+ 0 && (module.exports = {
1068
+ CRPage
1069
+ });