@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,229 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.JavaScriptLanguageGenerator = exports.JavaScriptFormatter = void 0;
7
+ var _language = require("./language");
8
+ var _utils = require("./utils");
9
+ var _deviceDescriptors = require("../deviceDescriptors");
10
+ var _stringUtils = require("../../utils/isomorphic/stringUtils");
11
+ var _locatorGenerators = require("../../utils/isomorphic/locatorGenerators");
12
+ /**
13
+ * Copyright (c) Microsoft Corporation.
14
+ *
15
+ * Licensed under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License.
17
+ * You may obtain a copy of the License at
18
+ *
19
+ * http://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software
22
+ * distributed under the License is distributed on an "AS IS" BASIS,
23
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ * See the License for the specific language governing permissions and
25
+ * limitations under the License.
26
+ */
27
+
28
+ class JavaScriptLanguageGenerator {
29
+ constructor(isTest) {
30
+ this.id = void 0;
31
+ this.groupName = 'Node.js';
32
+ this.name = void 0;
33
+ this.highlighter = 'javascript';
34
+ this._isTest = void 0;
35
+ this.id = isTest ? 'playwright-test' : 'javascript';
36
+ this.name = isTest ? 'Test Runner' : 'Library';
37
+ this._isTest = isTest;
38
+ }
39
+ generateAction(actionInContext) {
40
+ const action = actionInContext.action;
41
+ if (this._isTest && (action.name === 'openPage' || action.name === 'closePage')) return '';
42
+ const pageAlias = actionInContext.frame.pageAlias;
43
+ const formatter = new JavaScriptFormatter(2);
44
+ if (action.name === 'openPage') {
45
+ formatter.add(`const ${pageAlias} = await context.newPage();`);
46
+ if (action.url && action.url !== 'about:blank' && action.url !== 'chrome://newtab/') formatter.add(`await ${pageAlias}.goto(${quote(action.url)});`);
47
+ return formatter.format();
48
+ }
49
+ let subject;
50
+ if (actionInContext.frame.isMainFrame) {
51
+ subject = pageAlias;
52
+ } else {
53
+ const locators = actionInContext.frame.selectorsChain.map(selector => `.frameLocator(${quote(selector)})`);
54
+ subject = `${pageAlias}${locators.join('')}`;
55
+ }
56
+ const signals = (0, _language.toSignalMap)(action);
57
+ if (signals.dialog) {
58
+ formatter.add(` ${pageAlias}.once('dialog', dialog => {
59
+ console.log(\`Dialog message: $\{dialog.message()}\`);
60
+ dialog.dismiss().catch(() => {});
61
+ });`);
62
+ }
63
+ if (signals.popup) formatter.add(`const ${signals.popup.popupAlias}Promise = ${pageAlias}.waitForEvent('popup');`);
64
+ if (signals.download) formatter.add(`const download${signals.download.downloadAlias}Promise = ${pageAlias}.waitForEvent('download');`);
65
+ formatter.add(this._generateActionCall(subject, action));
66
+ if (signals.popup) formatter.add(`const ${signals.popup.popupAlias} = await ${signals.popup.popupAlias}Promise;`);
67
+ if (signals.download) formatter.add(`const download${signals.download.downloadAlias} = await download${signals.download.downloadAlias}Promise;`);
68
+ return formatter.format();
69
+ }
70
+ _generateActionCall(subject, action) {
71
+ switch (action.name) {
72
+ case 'openPage':
73
+ throw Error('Not reached');
74
+ case 'closePage':
75
+ return `await ${subject}.close();`;
76
+ case 'click':
77
+ {
78
+ let method = 'click';
79
+ if (action.clickCount === 2) method = 'dblclick';
80
+ const modifiers = (0, _utils.toModifiers)(action.modifiers);
81
+ const options = {};
82
+ if (action.button !== 'left') options.button = action.button;
83
+ if (modifiers.length) options.modifiers = modifiers;
84
+ if (action.clickCount > 2) options.clickCount = action.clickCount;
85
+ if (action.position) options.position = action.position;
86
+ const optionsString = formatOptions(options, false);
87
+ return `await ${subject}.${this._asLocator(action.selector)}.${method}(${optionsString});`;
88
+ }
89
+ case 'check':
90
+ return `await ${subject}.${this._asLocator(action.selector)}.check();`;
91
+ case 'uncheck':
92
+ return `await ${subject}.${this._asLocator(action.selector)}.uncheck();`;
93
+ case 'fill':
94
+ return `await ${subject}.${this._asLocator(action.selector)}.fill(${quote(action.text)});`;
95
+ case 'setInputFiles':
96
+ return `await ${subject}.${this._asLocator(action.selector)}.setInputFiles(${formatObject(action.files.length === 1 ? action.files[0] : action.files)});`;
97
+ case 'press':
98
+ {
99
+ const modifiers = (0, _utils.toModifiers)(action.modifiers);
100
+ const shortcut = [...modifiers, action.key].join('+');
101
+ return `await ${subject}.${this._asLocator(action.selector)}.press(${quote(shortcut)});`;
102
+ }
103
+ case 'navigate':
104
+ return `await ${subject}.goto(${quote(action.url)});`;
105
+ case 'select':
106
+ return `await ${subject}.${this._asLocator(action.selector)}.selectOption(${formatObject(action.options.length > 1 ? action.options : action.options[0])});`;
107
+ case 'assertText':
108
+ return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)}).${action.substring ? 'toContainText' : 'toHaveText'}(${quote(action.text)});`;
109
+ case 'assertChecked':
110
+ return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)})${action.checked ? '' : '.not'}.toBeChecked();`;
111
+ case 'assertVisible':
112
+ return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)}).toBeVisible();`;
113
+ case 'assertValue':
114
+ {
115
+ const assertion = action.value ? `toHaveValue(${quote(action.value)})` : `toBeEmpty()`;
116
+ return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)}).${assertion};`;
117
+ }
118
+ }
119
+ }
120
+ _asLocator(selector) {
121
+ return (0, _locatorGenerators.asLocator)('javascript', selector);
122
+ }
123
+ generateHeader(options) {
124
+ if (this._isTest) return this.generateTestHeader(options);
125
+ return this.generateStandaloneHeader(options);
126
+ }
127
+ generateFooter(saveStorage) {
128
+ if (this._isTest) return this.generateTestFooter(saveStorage);
129
+ return this.generateStandaloneFooter(saveStorage);
130
+ }
131
+ generateTestHeader(options) {
132
+ const formatter = new JavaScriptFormatter();
133
+ const useText = formatContextOptions(options.contextOptions, options.deviceName);
134
+ formatter.add(`
135
+ import { test, expect${options.deviceName ? ', devices' : ''} } from '@playwright/test';
136
+ ${useText ? '\ntest.use(' + useText + ');\n' : ''}
137
+ test('test', async ({ page }) => {`);
138
+ return formatter.format();
139
+ }
140
+ generateTestFooter(saveStorage) {
141
+ return `});`;
142
+ }
143
+ generateStandaloneHeader(options) {
144
+ const formatter = new JavaScriptFormatter();
145
+ formatter.add(`
146
+ const { ${options.browserName}${options.deviceName ? ', devices' : ''} } = require('playwright');
147
+
148
+ (async () => {
149
+ const browser = await ${options.browserName}.launch(${formatObjectOrVoid(options.launchOptions)});
150
+ const context = await browser.newContext(${formatContextOptions(options.contextOptions, options.deviceName)});`);
151
+ return formatter.format();
152
+ }
153
+ generateStandaloneFooter(saveStorage) {
154
+ const storageStateLine = saveStorage ? `\n await context.storageState({ path: ${quote(saveStorage)} });` : '';
155
+ return `\n // ---------------------${storageStateLine}
156
+ await context.close();
157
+ await browser.close();
158
+ })();`;
159
+ }
160
+ }
161
+ exports.JavaScriptLanguageGenerator = JavaScriptLanguageGenerator;
162
+ function formatOptions(value, hasArguments) {
163
+ const keys = Object.keys(value);
164
+ if (!keys.length) return '';
165
+ return (hasArguments ? ', ' : '') + formatObject(value);
166
+ }
167
+ function formatObject(value, indent = ' ') {
168
+ if (typeof value === 'string') return quote(value);
169
+ if (Array.isArray(value)) return `[${value.map(o => formatObject(o)).join(', ')}]`;
170
+ if (typeof value === 'object') {
171
+ const keys = Object.keys(value).filter(key => value[key] !== undefined).sort();
172
+ if (!keys.length) return '{}';
173
+ const tokens = [];
174
+ for (const key of keys) tokens.push(`${key}: ${formatObject(value[key])}`);
175
+ return `{\n${indent}${tokens.join(`,\n${indent}`)}\n}`;
176
+ }
177
+ return String(value);
178
+ }
179
+ function formatObjectOrVoid(value, indent = ' ') {
180
+ const result = formatObject(value, indent);
181
+ return result === '{}' ? '' : result;
182
+ }
183
+ function formatContextOptions(options, deviceName) {
184
+ const device = deviceName && _deviceDescriptors.deviceDescriptors[deviceName];
185
+ if (!device) return formatObjectOrVoid(options);
186
+ // Filter out all the properties from the device descriptor.
187
+ let serializedObject = formatObjectOrVoid((0, _language.sanitizeDeviceOptions)(device, options));
188
+ // When there are no additional context options, we still want to spread the device inside.
189
+ if (!serializedObject) serializedObject = '{\n}';
190
+ const lines = serializedObject.split('\n');
191
+ lines.splice(1, 0, `...devices[${quote(deviceName)}],`);
192
+ return lines.join('\n');
193
+ }
194
+ class JavaScriptFormatter {
195
+ constructor(offset = 0) {
196
+ this._baseIndent = void 0;
197
+ this._baseOffset = void 0;
198
+ this._lines = [];
199
+ this._baseIndent = ' '.repeat(2);
200
+ this._baseOffset = ' '.repeat(offset);
201
+ }
202
+ prepend(text) {
203
+ this._lines = text.trim().split('\n').map(line => line.trim()).concat(this._lines);
204
+ }
205
+ add(text) {
206
+ this._lines.push(...text.trim().split('\n').map(line => line.trim()));
207
+ }
208
+ newLine() {
209
+ this._lines.push('');
210
+ }
211
+ format() {
212
+ let spaces = '';
213
+ let previousLine = '';
214
+ return this._lines.map(line => {
215
+ if (line === '') return line;
216
+ if (line.startsWith('}') || line.startsWith(']')) spaces = spaces.substring(this._baseIndent.length);
217
+ const extraSpaces = /^(for|while|if|try).*\(.*\)$/.test(previousLine) ? this._baseIndent : '';
218
+ previousLine = line;
219
+ const callCarryOver = line.startsWith('.set');
220
+ line = spaces + extraSpaces + (callCarryOver ? this._baseIndent : '') + line;
221
+ if (line.endsWith('{') || line.endsWith('[')) spaces += this._baseIndent;
222
+ return this._baseOffset + line;
223
+ }).join('\n');
224
+ }
225
+ }
226
+ exports.JavaScriptFormatter = JavaScriptFormatter;
227
+ function quote(text) {
228
+ return (0, _stringUtils.escapeWithQuotes)(text, '\'');
229
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.JsonlLanguageGenerator = void 0;
7
+ var _locatorGenerators = require("../../utils/isomorphic/locatorGenerators");
8
+ /**
9
+ * Copyright (c) Microsoft Corporation.
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+
24
+ class JsonlLanguageGenerator {
25
+ constructor() {
26
+ this.id = 'jsonl';
27
+ this.groupName = '';
28
+ this.name = 'JSONL';
29
+ this.highlighter = 'javascript';
30
+ }
31
+ generateAction(actionInContext) {
32
+ const locator = actionInContext.action.selector ? JSON.parse((0, _locatorGenerators.asLocator)('jsonl', actionInContext.action.selector)) : undefined;
33
+ const entry = {
34
+ ...actionInContext.action,
35
+ pageAlias: actionInContext.frame.pageAlias,
36
+ locator
37
+ };
38
+ return JSON.stringify(entry);
39
+ }
40
+ generateHeader(options) {
41
+ return JSON.stringify(options);
42
+ }
43
+ generateFooter(saveStorage) {
44
+ return '';
45
+ }
46
+ }
47
+ exports.JsonlLanguageGenerator = JsonlLanguageGenerator;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sanitizeDeviceOptions = sanitizeDeviceOptions;
7
+ exports.toSignalMap = toSignalMap;
8
+ /**
9
+ * Copyright (c) Microsoft Corporation.
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+
24
+ function sanitizeDeviceOptions(device, options) {
25
+ // Filter out all the properties from the device descriptor.
26
+ const cleanedOptions = {};
27
+ for (const property in options) {
28
+ if (JSON.stringify(device[property]) !== JSON.stringify(options[property])) cleanedOptions[property] = options[property];
29
+ }
30
+ return cleanedOptions;
31
+ }
32
+ function toSignalMap(action) {
33
+ let popup;
34
+ let download;
35
+ let dialog;
36
+ for (const signal of action.signals) {
37
+ if (signal.name === 'popup') popup = signal;else if (signal.name === 'download') download = signal;else if (signal.name === 'dialog') dialog = signal;
38
+ }
39
+ return {
40
+ popup,
41
+ download,
42
+ dialog
43
+ };
44
+ }
@@ -0,0 +1,276 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PythonLanguageGenerator = void 0;
7
+ var _language = require("./language");
8
+ var _utils = require("./utils");
9
+ var _stringUtils = require("../../utils/isomorphic/stringUtils");
10
+ var _deviceDescriptors = require("../deviceDescriptors");
11
+ var _locatorGenerators = require("../../utils/isomorphic/locatorGenerators");
12
+ /**
13
+ * Copyright (c) Microsoft Corporation.
14
+ *
15
+ * Licensed under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License.
17
+ * You may obtain a copy of the License at
18
+ *
19
+ * http://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software
22
+ * distributed under the License is distributed on an "AS IS" BASIS,
23
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ * See the License for the specific language governing permissions and
25
+ * limitations under the License.
26
+ */
27
+
28
+ class PythonLanguageGenerator {
29
+ constructor(isAsync, isPyTest) {
30
+ this.id = void 0;
31
+ this.groupName = 'Python';
32
+ this.name = void 0;
33
+ this.highlighter = 'python';
34
+ this._awaitPrefix = void 0;
35
+ this._asyncPrefix = void 0;
36
+ this._isAsync = void 0;
37
+ this._isPyTest = void 0;
38
+ this.id = isPyTest ? 'python-pytest' : isAsync ? 'python-async' : 'python';
39
+ this.name = isPyTest ? 'Pytest' : isAsync ? 'Library Async' : 'Library';
40
+ this._isAsync = isAsync;
41
+ this._isPyTest = isPyTest;
42
+ this._awaitPrefix = isAsync ? 'await ' : '';
43
+ this._asyncPrefix = isAsync ? 'async ' : '';
44
+ }
45
+ generateAction(actionInContext) {
46
+ const action = actionInContext.action;
47
+ if (this._isPyTest && (action.name === 'openPage' || action.name === 'closePage')) return '';
48
+ const pageAlias = actionInContext.frame.pageAlias;
49
+ const formatter = new PythonFormatter(4);
50
+ if (action.name === 'openPage') {
51
+ formatter.add(`${pageAlias} = ${this._awaitPrefix}context.new_page()`);
52
+ if (action.url && action.url !== 'about:blank' && action.url !== 'chrome://newtab/') formatter.add(`${this._awaitPrefix}${pageAlias}.goto(${quote(action.url)})`);
53
+ return formatter.format();
54
+ }
55
+ let subject;
56
+ if (actionInContext.frame.isMainFrame) {
57
+ subject = pageAlias;
58
+ } else {
59
+ const locators = actionInContext.frame.selectorsChain.map(selector => `.frame_locator(${quote(selector)})`);
60
+ subject = `${pageAlias}${locators.join('')}`;
61
+ }
62
+ const signals = (0, _language.toSignalMap)(action);
63
+ if (signals.dialog) formatter.add(` ${pageAlias}.once("dialog", lambda dialog: dialog.dismiss())`);
64
+ let code = `${this._awaitPrefix}${this._generateActionCall(subject, action)}`;
65
+ if (signals.popup) {
66
+ code = `${this._asyncPrefix}with ${pageAlias}.expect_popup() as ${signals.popup.popupAlias}_info {
67
+ ${code}
68
+ }
69
+ ${signals.popup.popupAlias} = ${this._awaitPrefix}${signals.popup.popupAlias}_info.value`;
70
+ }
71
+ if (signals.download) {
72
+ code = `${this._asyncPrefix}with ${pageAlias}.expect_download() as download${signals.download.downloadAlias}_info {
73
+ ${code}
74
+ }
75
+ download${signals.download.downloadAlias} = ${this._awaitPrefix}download${signals.download.downloadAlias}_info.value`;
76
+ }
77
+ formatter.add(code);
78
+ return formatter.format();
79
+ }
80
+ _generateActionCall(subject, action) {
81
+ switch (action.name) {
82
+ case 'openPage':
83
+ throw Error('Not reached');
84
+ case 'closePage':
85
+ return `${subject}.close()`;
86
+ case 'click':
87
+ {
88
+ let method = 'click';
89
+ if (action.clickCount === 2) method = 'dblclick';
90
+ const modifiers = (0, _utils.toModifiers)(action.modifiers);
91
+ const options = {};
92
+ if (action.button !== 'left') options.button = action.button;
93
+ if (modifiers.length) options.modifiers = modifiers;
94
+ if (action.clickCount > 2) options.clickCount = action.clickCount;
95
+ if (action.position) options.position = action.position;
96
+ const optionsString = formatOptions(options, false);
97
+ return `${subject}.${this._asLocator(action.selector)}.${method}(${optionsString})`;
98
+ }
99
+ case 'check':
100
+ return `${subject}.${this._asLocator(action.selector)}.check()`;
101
+ case 'uncheck':
102
+ return `${subject}.${this._asLocator(action.selector)}.uncheck()`;
103
+ case 'fill':
104
+ return `${subject}.${this._asLocator(action.selector)}.fill(${quote(action.text)})`;
105
+ case 'setInputFiles':
106
+ return `${subject}.${this._asLocator(action.selector)}.set_input_files(${formatValue(action.files.length === 1 ? action.files[0] : action.files)})`;
107
+ case 'press':
108
+ {
109
+ const modifiers = (0, _utils.toModifiers)(action.modifiers);
110
+ const shortcut = [...modifiers, action.key].join('+');
111
+ return `${subject}.${this._asLocator(action.selector)}.press(${quote(shortcut)})`;
112
+ }
113
+ case 'navigate':
114
+ return `${subject}.goto(${quote(action.url)})`;
115
+ case 'select':
116
+ return `${subject}.${this._asLocator(action.selector)}.select_option(${formatValue(action.options.length === 1 ? action.options[0] : action.options)})`;
117
+ case 'assertText':
118
+ return `expect(${subject}.${this._asLocator(action.selector)}).${action.substring ? 'to_contain_text' : 'to_have_text'}(${quote(action.text)})`;
119
+ case 'assertChecked':
120
+ return `expect(${subject}.${this._asLocator(action.selector)}).${action.checked ? 'to_be_checked()' : 'not_to_be_checked()'}`;
121
+ case 'assertVisible':
122
+ return `expect(${subject}.${this._asLocator(action.selector)}).to_be_visible()`;
123
+ case 'assertValue':
124
+ {
125
+ const assertion = action.value ? `to_have_value(${quote(action.value)})` : `to_be_empty()`;
126
+ return `expect(${subject}.${this._asLocator(action.selector)}).${assertion};`;
127
+ }
128
+ }
129
+ }
130
+ _asLocator(selector) {
131
+ return (0, _locatorGenerators.asLocator)('python', selector);
132
+ }
133
+ generateHeader(options) {
134
+ const formatter = new PythonFormatter();
135
+ if (this._isPyTest) {
136
+ const contextOptions = formatContextOptions(options.contextOptions, options.deviceName, true /* asDict */);
137
+ const fixture = contextOptions ? `
138
+
139
+ @pytest.fixture(scope="session")
140
+ def browser_context_args(browser_context_args, playwright) {
141
+ return {${contextOptions}}
142
+ }
143
+ ` : '';
144
+ formatter.add(`${options.deviceName ? 'import pytest\n' : ''}import re
145
+ from playwright.sync_api import Page, expect
146
+ ${fixture}
147
+
148
+ def test_example(page: Page) -> None {`);
149
+ } else if (this._isAsync) {
150
+ formatter.add(`
151
+ import asyncio
152
+ import re
153
+ from playwright.async_api import Playwright, async_playwright, expect
154
+
155
+
156
+ async def run(playwright: Playwright) -> None {
157
+ browser = await playwright.${options.browserName}.launch(${formatOptions(options.launchOptions, false)})
158
+ context = await browser.new_context(${formatContextOptions(options.contextOptions, options.deviceName)})`);
159
+ } else {
160
+ formatter.add(`
161
+ import re
162
+ from playwright.sync_api import Playwright, sync_playwright, expect
163
+
164
+
165
+ def run(playwright: Playwright) -> None {
166
+ browser = playwright.${options.browserName}.launch(${formatOptions(options.launchOptions, false)})
167
+ context = browser.new_context(${formatContextOptions(options.contextOptions, options.deviceName)})`);
168
+ }
169
+ return formatter.format();
170
+ }
171
+ generateFooter(saveStorage) {
172
+ if (this._isPyTest) {
173
+ return '';
174
+ } else if (this._isAsync) {
175
+ const storageStateLine = saveStorage ? `\n await context.storage_state(path=${quote(saveStorage)})` : '';
176
+ return `\n # ---------------------${storageStateLine}
177
+ await context.close()
178
+ await browser.close()
179
+
180
+
181
+ async def main() -> None:
182
+ async with async_playwright() as playwright:
183
+ await run(playwright)
184
+
185
+
186
+ asyncio.run(main())
187
+ `;
188
+ } else {
189
+ const storageStateLine = saveStorage ? `\n context.storage_state(path=${quote(saveStorage)})` : '';
190
+ return `\n # ---------------------${storageStateLine}
191
+ context.close()
192
+ browser.close()
193
+
194
+
195
+ with sync_playwright() as playwright:
196
+ run(playwright)
197
+ `;
198
+ }
199
+ }
200
+ }
201
+ exports.PythonLanguageGenerator = PythonLanguageGenerator;
202
+ function formatValue(value) {
203
+ if (value === false) return 'False';
204
+ if (value === true) return 'True';
205
+ if (value === undefined) return 'None';
206
+ if (Array.isArray(value)) return `[${value.map(formatValue).join(', ')}]`;
207
+ if (typeof value === 'string') return quote(value);
208
+ if (typeof value === 'object') return JSON.stringify(value);
209
+ return String(value);
210
+ }
211
+ function formatOptions(value, hasArguments, asDict) {
212
+ const keys = Object.keys(value).filter(key => value[key] !== undefined).sort();
213
+ if (!keys.length) return '';
214
+ return (hasArguments ? ', ' : '') + keys.map(key => {
215
+ if (asDict) return `"${(0, _stringUtils.toSnakeCase)(key)}": ${formatValue(value[key])}`;
216
+ return `${(0, _stringUtils.toSnakeCase)(key)}=${formatValue(value[key])}`;
217
+ }).join(', ');
218
+ }
219
+ function convertContextOptions(options) {
220
+ const result = {
221
+ ...options
222
+ };
223
+ if (options.recordHar) {
224
+ result['record_har_path'] = options.recordHar.path;
225
+ result['record_har_content'] = options.recordHar.content;
226
+ result['record_har_mode'] = options.recordHar.mode;
227
+ result['record_har_omit_content'] = options.recordHar.omitContent;
228
+ result['record_har_url_filter'] = options.recordHar.urlFilter;
229
+ delete result.recordHar;
230
+ }
231
+ return result;
232
+ }
233
+ function formatContextOptions(options, deviceName, asDict) {
234
+ const device = deviceName && _deviceDescriptors.deviceDescriptors[deviceName];
235
+ if (!device) return formatOptions(convertContextOptions(options), false, asDict);
236
+ return `**playwright.devices[${quote(deviceName)}]` + formatOptions(convertContextOptions((0, _language.sanitizeDeviceOptions)(device, options)), true, asDict);
237
+ }
238
+ class PythonFormatter {
239
+ constructor(offset = 0) {
240
+ this._baseIndent = void 0;
241
+ this._baseOffset = void 0;
242
+ this._lines = [];
243
+ this._baseIndent = ' '.repeat(4);
244
+ this._baseOffset = ' '.repeat(offset);
245
+ }
246
+ prepend(text) {
247
+ this._lines = text.trim().split('\n').map(line => line.trim()).concat(this._lines);
248
+ }
249
+ add(text) {
250
+ this._lines.push(...text.trim().split('\n').map(line => line.trim()));
251
+ }
252
+ newLine() {
253
+ this._lines.push('');
254
+ }
255
+ format() {
256
+ let spaces = '';
257
+ const lines = [];
258
+ this._lines.forEach(line => {
259
+ if (line === '') return lines.push(line);
260
+ if (line === '}') {
261
+ spaces = spaces.substring(this._baseIndent.length);
262
+ return;
263
+ }
264
+ line = spaces + line;
265
+ if (line.endsWith('{')) {
266
+ spaces += this._baseIndent;
267
+ line = line.substring(0, line.length - 1).trimEnd() + ':';
268
+ }
269
+ return lines.push(this._baseOffset + line);
270
+ });
271
+ return lines.join('\n');
272
+ }
273
+ }
274
+ function quote(text) {
275
+ return (0, _stringUtils.escapeWithQuotes)(text, '\"');
276
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });