patchright-bun-core 1.58.0 → 1.58.2

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 (358) hide show
  1. package/README.md +2 -2
  2. package/ThirdPartyNotices.txt +4075 -4075
  3. package/bin/install_media_pack.ps1 +5 -5
  4. package/bin/install_webkit_wsl.ps1 +32 -32
  5. package/bin/reinstall_chrome_beta_linux.sh +42 -42
  6. package/bin/reinstall_chrome_beta_mac.sh +13 -13
  7. package/bin/reinstall_chrome_beta_win.ps1 +24 -24
  8. package/bin/reinstall_chrome_stable_linux.sh +42 -42
  9. package/bin/reinstall_chrome_stable_mac.sh +12 -12
  10. package/bin/reinstall_chrome_stable_win.ps1 +24 -24
  11. package/bin/reinstall_msedge_beta_linux.sh +48 -48
  12. package/bin/reinstall_msedge_beta_mac.sh +11 -11
  13. package/bin/reinstall_msedge_beta_win.ps1 +23 -23
  14. package/bin/reinstall_msedge_dev_linux.sh +48 -48
  15. package/bin/reinstall_msedge_dev_mac.sh +11 -11
  16. package/bin/reinstall_msedge_dev_win.ps1 +23 -23
  17. package/bin/reinstall_msedge_stable_linux.sh +48 -48
  18. package/bin/reinstall_msedge_stable_mac.sh +11 -11
  19. package/bin/reinstall_msedge_stable_win.ps1 +23 -23
  20. package/browsers.json +79 -79
  21. package/cli.js +18 -18
  22. package/index.d.ts +17 -17
  23. package/index.js +32 -32
  24. package/index.mjs +28 -28
  25. package/lib/androidServerImpl.js +65 -65
  26. package/lib/browserServerImpl.js +120 -120
  27. package/lib/cli/driver.js +97 -97
  28. package/lib/cli/program.js +589 -589
  29. package/lib/cli/programWithTestStub.js +74 -74
  30. package/lib/client/android.js +361 -361
  31. package/lib/client/api.js +137 -137
  32. package/lib/client/artifact.js +79 -79
  33. package/lib/client/browser.js +161 -161
  34. package/lib/client/browserContext.js +582 -582
  35. package/lib/client/browserType.js +185 -185
  36. package/lib/client/cdpSession.js +51 -51
  37. package/lib/client/channelOwner.js +194 -194
  38. package/lib/client/clientHelper.js +64 -64
  39. package/lib/client/clientInstrumentation.js +55 -55
  40. package/lib/client/clientStackTrace.js +69 -69
  41. package/lib/client/clock.js +68 -68
  42. package/lib/client/connection.js +318 -318
  43. package/lib/client/consoleMessage.js +58 -58
  44. package/lib/client/coverage.js +44 -44
  45. package/lib/client/dialog.js +56 -56
  46. package/lib/client/download.js +62 -62
  47. package/lib/client/electron.js +138 -138
  48. package/lib/client/elementHandle.js +284 -284
  49. package/lib/client/errors.js +77 -77
  50. package/lib/client/eventEmitter.js +314 -314
  51. package/lib/client/events.js +103 -103
  52. package/lib/client/fetch.js +368 -368
  53. package/lib/client/fileChooser.js +46 -46
  54. package/lib/client/fileUtils.js +34 -34
  55. package/lib/client/frame.js +409 -409
  56. package/lib/client/harRouter.js +87 -87
  57. package/lib/client/input.js +84 -84
  58. package/lib/client/jsHandle.js +109 -109
  59. package/lib/client/jsonPipe.js +39 -39
  60. package/lib/client/localUtils.js +60 -60
  61. package/lib/client/locator.js +369 -369
  62. package/lib/client/network.js +747 -747
  63. package/lib/client/page.js +745 -745
  64. package/lib/client/pageAgent.js +64 -64
  65. package/lib/client/platform.js +77 -77
  66. package/lib/client/playwright.js +71 -71
  67. package/lib/client/selectors.js +55 -55
  68. package/lib/client/stream.js +39 -39
  69. package/lib/client/timeoutSettings.js +79 -79
  70. package/lib/client/tracing.js +119 -119
  71. package/lib/client/types.js +28 -28
  72. package/lib/client/video.js +59 -59
  73. package/lib/client/waiter.js +142 -142
  74. package/lib/client/webError.js +39 -39
  75. package/lib/client/webSocket.js +93 -93
  76. package/lib/client/worker.js +85 -85
  77. package/lib/client/writableStream.js +39 -39
  78. package/lib/generated/bindingsControllerSource.js +28 -28
  79. package/lib/generated/clockSource.js +28 -28
  80. package/lib/generated/injectedScriptSource.js +28 -28
  81. package/lib/generated/pollingRecorderSource.js +28 -28
  82. package/lib/generated/storageScriptSource.js +28 -28
  83. package/lib/generated/utilityScriptSource.js +28 -28
  84. package/lib/generated/webSocketMockSource.js +336 -336
  85. package/lib/inProcessFactory.js +60 -60
  86. package/lib/inprocess.js +3 -3
  87. package/lib/mcpBundle.js +84 -84
  88. package/lib/mcpBundleImpl/index.js +147 -147
  89. package/lib/outofprocess.js +76 -76
  90. package/lib/protocol/serializers.js +197 -197
  91. package/lib/protocol/validator.js +2969 -2969
  92. package/lib/protocol/validatorPrimitives.js +193 -193
  93. package/lib/remote/playwrightConnection.js +129 -129
  94. package/lib/remote/playwrightServer.js +334 -334
  95. package/lib/server/agent/actionRunner.js +335 -335
  96. package/lib/server/agent/actions.js +128 -128
  97. package/lib/server/agent/codegen.js +111 -111
  98. package/lib/server/agent/context.js +150 -150
  99. package/lib/server/agent/expectTools.js +156 -156
  100. package/lib/server/agent/pageAgent.js +204 -204
  101. package/lib/server/agent/performTools.js +262 -262
  102. package/lib/server/agent/tool.js +109 -109
  103. package/lib/server/android/android.js +465 -465
  104. package/lib/server/android/backendAdb.js +177 -177
  105. package/lib/server/artifact.js +127 -127
  106. package/lib/server/bidi/bidiBrowser.js +549 -549
  107. package/lib/server/bidi/bidiChromium.js +149 -148
  108. package/lib/server/bidi/bidiConnection.js +213 -213
  109. package/lib/server/bidi/bidiDeserializer.js +116 -116
  110. package/lib/server/bidi/bidiExecutionContext.js +267 -267
  111. package/lib/server/bidi/bidiFirefox.js +128 -128
  112. package/lib/server/bidi/bidiInput.js +146 -146
  113. package/lib/server/bidi/bidiNetworkManager.js +383 -383
  114. package/lib/server/bidi/bidiOverCdp.js +102 -102
  115. package/lib/server/bidi/bidiPage.js +583 -583
  116. package/lib/server/bidi/bidiPdf.js +106 -106
  117. package/lib/server/bidi/third_party/bidiCommands.d.js +22 -22
  118. package/lib/server/bidi/third_party/bidiKeyboard.js +256 -256
  119. package/lib/server/bidi/third_party/bidiProtocol.js +24 -24
  120. package/lib/server/bidi/third_party/bidiProtocolCore.js +180 -180
  121. package/lib/server/bidi/third_party/bidiProtocolPermissions.js +42 -42
  122. package/lib/server/bidi/third_party/bidiSerializer.js +148 -148
  123. package/lib/server/bidi/third_party/firefoxPrefs.js +259 -259
  124. package/lib/server/browser.js +149 -149
  125. package/lib/server/browserContext.js +702 -702
  126. package/lib/server/browserType.js +336 -336
  127. package/lib/server/callLog.js +82 -82
  128. package/lib/server/chromium/chromium.js +397 -395
  129. package/lib/server/chromium/chromiumSwitches.js +104 -104
  130. package/lib/server/chromium/crBrowser.js +520 -511
  131. package/lib/server/chromium/crConnection.js +197 -197
  132. package/lib/server/chromium/crCoverage.js +235 -235
  133. package/lib/server/chromium/crDevTools.js +111 -111
  134. package/lib/server/chromium/crDragDrop.js +131 -131
  135. package/lib/server/chromium/crExecutionContext.js +146 -146
  136. package/lib/server/chromium/crInput.js +187 -187
  137. package/lib/server/chromium/crNetworkManager.js +707 -707
  138. package/lib/server/chromium/crPage.js +1001 -1001
  139. package/lib/server/chromium/crPdf.js +121 -121
  140. package/lib/server/chromium/crProtocolHelper.js +145 -145
  141. package/lib/server/chromium/crServiceWorker.js +136 -136
  142. package/lib/server/chromium/defaultFontFamilies.js +162 -162
  143. package/lib/server/chromium/protocol.d.js +16 -16
  144. package/lib/server/clock.js +149 -149
  145. package/lib/server/codegen/csharp.js +327 -327
  146. package/lib/server/codegen/java.js +274 -274
  147. package/lib/server/codegen/javascript.js +247 -247
  148. package/lib/server/codegen/jsonl.js +52 -52
  149. package/lib/server/codegen/language.js +132 -132
  150. package/lib/server/codegen/languages.js +68 -68
  151. package/lib/server/codegen/python.js +279 -279
  152. package/lib/server/codegen/types.js +16 -16
  153. package/lib/server/console.js +57 -57
  154. package/lib/server/cookieStore.js +206 -206
  155. package/lib/server/debugController.js +191 -191
  156. package/lib/server/debugger.js +119 -119
  157. package/lib/server/deviceDescriptors.js +39 -39
  158. package/lib/server/deviceDescriptorsSource.json +1778 -1778
  159. package/lib/server/dialog.js +116 -116
  160. package/lib/server/dispatchers/androidDispatcher.js +325 -325
  161. package/lib/server/dispatchers/artifactDispatcher.js +118 -118
  162. package/lib/server/dispatchers/browserContextDispatcher.js +384 -384
  163. package/lib/server/dispatchers/browserDispatcher.js +118 -118
  164. package/lib/server/dispatchers/browserTypeDispatcher.js +64 -64
  165. package/lib/server/dispatchers/cdpSessionDispatcher.js +44 -44
  166. package/lib/server/dispatchers/debugControllerDispatcher.js +78 -78
  167. package/lib/server/dispatchers/dialogDispatcher.js +47 -47
  168. package/lib/server/dispatchers/dispatcher.js +364 -364
  169. package/lib/server/dispatchers/electronDispatcher.js +89 -89
  170. package/lib/server/dispatchers/elementHandlerDispatcher.js +181 -181
  171. package/lib/server/dispatchers/frameDispatcher.js +227 -227
  172. package/lib/server/dispatchers/jsHandleDispatcher.js +85 -85
  173. package/lib/server/dispatchers/jsonPipeDispatcher.js +58 -58
  174. package/lib/server/dispatchers/localUtilsDispatcher.js +149 -149
  175. package/lib/server/dispatchers/networkDispatchers.js +213 -213
  176. package/lib/server/dispatchers/pageAgentDispatcher.js +96 -96
  177. package/lib/server/dispatchers/pageDispatcher.js +393 -393
  178. package/lib/server/dispatchers/playwrightDispatcher.js +108 -108
  179. package/lib/server/dispatchers/streamDispatcher.js +67 -67
  180. package/lib/server/dispatchers/tracingDispatcher.js +68 -68
  181. package/lib/server/dispatchers/webSocketRouteDispatcher.js +165 -165
  182. package/lib/server/dispatchers/writableStreamDispatcher.js +79 -79
  183. package/lib/server/dom.js +815 -815
  184. package/lib/server/download.js +70 -70
  185. package/lib/server/electron/electron.js +273 -273
  186. package/lib/server/electron/loader.js +29 -29
  187. package/lib/server/errors.js +69 -69
  188. package/lib/server/fetch.js +621 -621
  189. package/lib/server/fileChooser.js +43 -43
  190. package/lib/server/fileUploadUtils.js +84 -84
  191. package/lib/server/firefox/ffBrowser.js +418 -418
  192. package/lib/server/firefox/ffConnection.js +142 -142
  193. package/lib/server/firefox/ffExecutionContext.js +150 -150
  194. package/lib/server/firefox/ffInput.js +159 -159
  195. package/lib/server/firefox/ffNetworkManager.js +256 -256
  196. package/lib/server/firefox/ffPage.js +497 -497
  197. package/lib/server/firefox/firefox.js +114 -114
  198. package/lib/server/firefox/protocol.d.js +16 -16
  199. package/lib/server/formData.js +147 -147
  200. package/lib/server/frameSelectors.js +160 -160
  201. package/lib/server/frames.js +1471 -1471
  202. package/lib/server/har/harRecorder.js +147 -147
  203. package/lib/server/har/harTracer.js +607 -607
  204. package/lib/server/harBackend.js +157 -157
  205. package/lib/server/helper.js +96 -96
  206. package/lib/server/index.js +58 -58
  207. package/lib/server/input.js +277 -277
  208. package/lib/server/instrumentation.js +72 -72
  209. package/lib/server/javascript.js +291 -291
  210. package/lib/server/launchApp.js +128 -128
  211. package/lib/server/localUtils.js +214 -214
  212. package/lib/server/macEditingCommands.js +143 -143
  213. package/lib/server/network.js +667 -667
  214. package/lib/server/page.js +830 -830
  215. package/lib/server/pipeTransport.js +89 -89
  216. package/lib/server/playwright.js +69 -69
  217. package/lib/server/progress.js +132 -132
  218. package/lib/server/protocolError.js +52 -52
  219. package/lib/server/recorder/chat.js +161 -161
  220. package/lib/server/recorder/recorderApp.js +366 -366
  221. package/lib/server/recorder/recorderRunner.js +138 -138
  222. package/lib/server/recorder/recorderSignalProcessor.js +83 -83
  223. package/lib/server/recorder/recorderUtils.js +157 -157
  224. package/lib/server/recorder/throttledFile.js +57 -57
  225. package/lib/server/recorder.js +499 -499
  226. package/lib/server/registry/browserFetcher.js +177 -177
  227. package/lib/server/registry/dependencies.js +371 -371
  228. package/lib/server/registry/index.js +1422 -1422
  229. package/lib/server/registry/nativeDeps.js +1280 -1280
  230. package/lib/server/registry/oopDownloadBrowserMain.js +127 -127
  231. package/lib/server/screencast.js +190 -190
  232. package/lib/server/screenshotter.js +333 -333
  233. package/lib/server/selectors.js +112 -112
  234. package/lib/server/socksClientCertificatesInterceptor.js +383 -383
  235. package/lib/server/socksInterceptor.js +95 -95
  236. package/lib/server/trace/recorder/snapshotter.js +147 -147
  237. package/lib/server/trace/recorder/snapshotterInjected.js +561 -561
  238. package/lib/server/trace/recorder/tracing.js +604 -604
  239. package/lib/server/trace/viewer/traceParser.js +72 -72
  240. package/lib/server/trace/viewer/traceViewer.js +245 -245
  241. package/lib/server/transport.js +254 -254
  242. package/lib/server/types.js +28 -28
  243. package/lib/server/usKeyboardLayout.js +145 -145
  244. package/lib/server/utils/ascii.js +44 -44
  245. package/lib/server/utils/comparators.js +139 -139
  246. package/lib/server/utils/crypto.js +216 -216
  247. package/lib/server/utils/debug.js +42 -42
  248. package/lib/server/utils/debugLogger.js +122 -122
  249. package/lib/server/utils/env.js +73 -73
  250. package/lib/server/utils/eventsHelper.js +39 -39
  251. package/lib/server/utils/expectUtils.js +123 -123
  252. package/lib/server/utils/fileUtils.js +191 -191
  253. package/lib/server/utils/happyEyeballs.js +207 -207
  254. package/lib/server/utils/hostPlatform.js +138 -123
  255. package/lib/server/utils/httpServer.js +203 -203
  256. package/lib/server/utils/imageUtils.js +141 -141
  257. package/lib/server/utils/image_tools/colorUtils.js +89 -89
  258. package/lib/server/utils/image_tools/compare.js +109 -109
  259. package/lib/server/utils/image_tools/imageChannel.js +78 -78
  260. package/lib/server/utils/image_tools/stats.js +102 -102
  261. package/lib/server/utils/linuxUtils.js +71 -71
  262. package/lib/server/utils/network.js +242 -242
  263. package/lib/server/utils/nodePlatform.js +154 -154
  264. package/lib/server/utils/pipeTransport.js +84 -84
  265. package/lib/server/utils/processLauncher.js +241 -241
  266. package/lib/server/utils/profiler.js +65 -65
  267. package/lib/server/utils/socksProxy.js +511 -511
  268. package/lib/server/utils/spawnAsync.js +41 -41
  269. package/lib/server/utils/task.js +51 -51
  270. package/lib/server/utils/userAgent.js +98 -98
  271. package/lib/server/utils/wsServer.js +121 -121
  272. package/lib/server/utils/zipFile.js +74 -74
  273. package/lib/server/utils/zones.js +57 -57
  274. package/lib/server/videoRecorder.js +124 -124
  275. package/lib/server/webkit/protocol.d.js +16 -16
  276. package/lib/server/webkit/webkit.js +108 -108
  277. package/lib/server/webkit/wkBrowser.js +335 -335
  278. package/lib/server/webkit/wkConnection.js +144 -144
  279. package/lib/server/webkit/wkExecutionContext.js +154 -154
  280. package/lib/server/webkit/wkInput.js +181 -181
  281. package/lib/server/webkit/wkInterceptableRequest.js +197 -197
  282. package/lib/server/webkit/wkPage.js +1159 -1158
  283. package/lib/server/webkit/wkProvisionalPage.js +83 -83
  284. package/lib/server/webkit/wkWorkers.js +105 -105
  285. package/lib/third_party/pixelmatch.js +255 -255
  286. package/lib/utils/isomorphic/ariaSnapshot.js +455 -455
  287. package/lib/utils/isomorphic/assert.js +31 -31
  288. package/lib/utils/isomorphic/colors.js +72 -72
  289. package/lib/utils/isomorphic/cssParser.js +245 -245
  290. package/lib/utils/isomorphic/cssTokenizer.js +1051 -1051
  291. package/lib/utils/isomorphic/headers.js +53 -53
  292. package/lib/utils/isomorphic/locatorGenerators.js +689 -689
  293. package/lib/utils/isomorphic/locatorParser.js +176 -176
  294. package/lib/utils/isomorphic/locatorUtils.js +81 -81
  295. package/lib/utils/isomorphic/lruCache.js +51 -51
  296. package/lib/utils/isomorphic/manualPromise.js +114 -114
  297. package/lib/utils/isomorphic/mimeType.js +459 -459
  298. package/lib/utils/isomorphic/multimap.js +80 -80
  299. package/lib/utils/isomorphic/protocolFormatter.js +81 -81
  300. package/lib/utils/isomorphic/protocolMetainfo.js +330 -330
  301. package/lib/utils/isomorphic/rtti.js +43 -43
  302. package/lib/utils/isomorphic/selectorParser.js +386 -386
  303. package/lib/utils/isomorphic/semaphore.js +54 -54
  304. package/lib/utils/isomorphic/stackTrace.js +158 -158
  305. package/lib/utils/isomorphic/stringUtils.js +204 -204
  306. package/lib/utils/isomorphic/time.js +49 -49
  307. package/lib/utils/isomorphic/timeoutRunner.js +66 -66
  308. package/lib/utils/isomorphic/trace/entries.js +16 -16
  309. package/lib/utils/isomorphic/trace/snapshotRenderer.js +499 -499
  310. package/lib/utils/isomorphic/trace/snapshotServer.js +120 -120
  311. package/lib/utils/isomorphic/trace/snapshotStorage.js +89 -89
  312. package/lib/utils/isomorphic/trace/traceLoader.js +131 -131
  313. package/lib/utils/isomorphic/trace/traceModel.js +365 -365
  314. package/lib/utils/isomorphic/trace/traceModernizer.js +400 -400
  315. package/lib/utils/isomorphic/trace/versions/traceV3.js +16 -16
  316. package/lib/utils/isomorphic/trace/versions/traceV4.js +16 -16
  317. package/lib/utils/isomorphic/trace/versions/traceV5.js +16 -16
  318. package/lib/utils/isomorphic/trace/versions/traceV6.js +16 -16
  319. package/lib/utils/isomorphic/trace/versions/traceV7.js +16 -16
  320. package/lib/utils/isomorphic/trace/versions/traceV8.js +16 -16
  321. package/lib/utils/isomorphic/traceUtils.js +58 -58
  322. package/lib/utils/isomorphic/types.js +16 -16
  323. package/lib/utils/isomorphic/urlMatch.js +190 -190
  324. package/lib/utils/isomorphic/utilityScriptSerializers.js +251 -251
  325. package/lib/utils/isomorphic/yaml.js +84 -84
  326. package/lib/utils.js +111 -111
  327. package/lib/utilsBundle.js +109 -109
  328. package/lib/utilsBundleImpl/index.js +218 -218
  329. package/lib/utilsBundleImpl/xdg-open +1066 -1066
  330. package/lib/vite/htmlReport/index.html +84 -84
  331. package/lib/vite/recorder/assets/codeMirrorModule-DYBRYzYX.css +1 -1
  332. package/lib/vite/recorder/assets/codeMirrorModule-DadYNm1I.js +32 -32
  333. package/lib/vite/recorder/assets/index-BSjZa4pk.css +1 -1
  334. package/lib/vite/recorder/assets/index-BhTWtUlo.js +193 -193
  335. package/lib/vite/recorder/index.html +29 -29
  336. package/lib/vite/recorder/playwright-logo.svg +9 -9
  337. package/lib/vite/traceViewer/assets/codeMirrorModule-a5XoALAZ.js +32 -32
  338. package/lib/vite/traceViewer/assets/defaultSettingsView-CJSZINFr.js +266 -266
  339. package/lib/vite/traceViewer/assets/xtermModule-CsJ4vdCR.js +9 -9
  340. package/lib/vite/traceViewer/codeMirrorModule.DYBRYzYX.css +1 -1
  341. package/lib/vite/traceViewer/defaultSettingsView.7ch9cixO.css +1 -1
  342. package/lib/vite/traceViewer/{index.Bk2uYQRV.js → index.BDwrLSGN.js} +2 -2
  343. package/lib/vite/traceViewer/index.BVu7tZDe.css +1 -1
  344. package/lib/vite/traceViewer/index.html +43 -43
  345. package/lib/vite/traceViewer/manifest.webmanifest +16 -16
  346. package/lib/vite/traceViewer/playwright-logo.svg +9 -9
  347. package/lib/vite/traceViewer/snapshot.html +21 -21
  348. package/lib/vite/traceViewer/sw.bundle.js +5 -5
  349. package/lib/vite/traceViewer/uiMode.Btcz36p_.css +1 -1
  350. package/lib/vite/traceViewer/uiMode.CQJ9SCIQ.js +5 -5
  351. package/lib/vite/traceViewer/uiMode.html +17 -17
  352. package/lib/vite/traceViewer/xtermModule.DYP7pi_n.css +32 -32
  353. package/lib/zipBundle.js +34 -34
  354. package/lib/zipBundleImpl.js +5 -5
  355. package/package.json +1 -1
  356. package/types/protocol.d.ts +23824 -23824
  357. package/types/structs.d.ts +45 -45
  358. package/types/types.d.ts +22843 -22843
@@ -1,589 +1,589 @@
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 program_exports = {};
30
- __export(program_exports, {
31
- program: () => import_utilsBundle2.program
32
- });
33
- module.exports = __toCommonJS(program_exports);
34
- var import_fs = __toESM(require("fs"));
35
- var import_os = __toESM(require("os"));
36
- var import_path = __toESM(require("path"));
37
- var playwright = __toESM(require("../.."));
38
- var import_driver = require("./driver");
39
- var import_server = require("../server");
40
- var import_utils = require("../utils");
41
- var import_traceViewer = require("../server/trace/viewer/traceViewer");
42
- var import_utils2 = require("../utils");
43
- var import_ascii = require("../server/utils/ascii");
44
- var import_utilsBundle = require("../utilsBundle");
45
- var import_utilsBundle2 = require("../utilsBundle");
46
- const packageJSON = require("../../package.json");
47
- import_utilsBundle.program.version("Version " + (process.env.PW_CLI_DISPLAY_VERSION || packageJSON.version)).name(buildBasePlaywrightCLICommand(process.env.PW_LANG_NAME));
48
- import_utilsBundle.program.command("mark-docker-image [dockerImageNameTemplate]", { hidden: true }).description("mark docker image").allowUnknownOption(true).action(function(dockerImageNameTemplate) {
49
- (0, import_utils2.assert)(dockerImageNameTemplate, "dockerImageNameTemplate is required");
50
- (0, import_server.writeDockerVersion)(dockerImageNameTemplate).catch(logErrorAndExit);
51
- });
52
- commandWithOpenOptions("open [url]", "open page in browser specified via -b, --browser", []).action(function(url, options) {
53
- open(options, url).catch(logErrorAndExit);
54
- }).addHelpText("afterAll", `
55
- Examples:
56
-
57
- $ open
58
- $ open -b webkit https://example.com`);
59
- commandWithOpenOptions(
60
- "codegen [url]",
61
- "open page and generate code for user actions",
62
- [
63
- ["-o, --output <file name>", "saves the generated script to a file"],
64
- ["--target <language>", `language to generate, one of javascript, playwright-test, python, python-async, python-pytest, csharp, csharp-mstest, csharp-nunit, java, java-junit`, codegenId()],
65
- ["--test-id-attribute <attributeName>", "use the specified attribute to generate data test ID selectors"]
66
- ]
67
- ).action(async function(url, options) {
68
- await codegen(options, url);
69
- }).addHelpText("afterAll", `
70
- Examples:
71
-
72
- $ codegen
73
- $ codegen --target=python
74
- $ codegen -b webkit https://example.com`);
75
- function printInstalledBrowsers(browsers2) {
76
- const browserPaths = /* @__PURE__ */ new Set();
77
- for (const browser of browsers2)
78
- browserPaths.add(browser.browserPath);
79
- console.log(` Browsers:`);
80
- for (const browserPath of [...browserPaths].sort())
81
- console.log(` ${browserPath}`);
82
- console.log(` References:`);
83
- const references = /* @__PURE__ */ new Set();
84
- for (const browser of browsers2)
85
- references.add(browser.referenceDir);
86
- for (const reference of [...references].sort())
87
- console.log(` ${reference}`);
88
- }
89
- function printGroupedByPlaywrightVersion(browsers2) {
90
- const dirToVersion = /* @__PURE__ */ new Map();
91
- for (const browser of browsers2) {
92
- if (dirToVersion.has(browser.referenceDir))
93
- continue;
94
- const packageJSON2 = require(import_path.default.join(browser.referenceDir, "package.json"));
95
- const version = packageJSON2.version;
96
- dirToVersion.set(browser.referenceDir, version);
97
- }
98
- const groupedByPlaywrightMinorVersion = /* @__PURE__ */ new Map();
99
- for (const browser of browsers2) {
100
- const version = dirToVersion.get(browser.referenceDir);
101
- let entries = groupedByPlaywrightMinorVersion.get(version);
102
- if (!entries) {
103
- entries = [];
104
- groupedByPlaywrightMinorVersion.set(version, entries);
105
- }
106
- entries.push(browser);
107
- }
108
- const sortedVersions = [...groupedByPlaywrightMinorVersion.keys()].sort((a, b) => {
109
- const aComponents = a.split(".");
110
- const bComponents = b.split(".");
111
- const aMajor = parseInt(aComponents[0], 10);
112
- const bMajor = parseInt(bComponents[0], 10);
113
- if (aMajor !== bMajor)
114
- return aMajor - bMajor;
115
- const aMinor = parseInt(aComponents[1], 10);
116
- const bMinor = parseInt(bComponents[1], 10);
117
- if (aMinor !== bMinor)
118
- return aMinor - bMinor;
119
- return aComponents.slice(2).join(".").localeCompare(bComponents.slice(2).join("."));
120
- });
121
- for (const version of sortedVersions) {
122
- console.log(`
123
- Playwright version: ${version}`);
124
- printInstalledBrowsers(groupedByPlaywrightMinorVersion.get(version));
125
- }
126
- }
127
- import_utilsBundle.program.command("install [browser...]").description("ensure browsers necessary for this version of Playwright are installed").option("--with-deps", "install system dependencies for browsers").option("--dry-run", "do not execute installation, only print information").option("--list", "prints list of browsers from all playwright installations").option("--force", "force reinstall of already installed browsers").option("--only-shell", "only install headless shell when installing chromium").option("--no-shell", "do not install chromium headless shell").action(async function(args, options) {
128
- if ((0, import_utils.isLikelyNpxGlobal)()) {
129
- console.error((0, import_ascii.wrapInASCIIBox)([
130
- `WARNING: It looks like you are running 'npx playwright install' without first`,
131
- `installing your project's dependencies.`,
132
- ``,
133
- `To avoid unexpected behavior, please install your dependencies first, and`,
134
- `then run Playwright's install command:`,
135
- ``,
136
- ` npm install`,
137
- ` npx playwright install`,
138
- ``,
139
- `If your project does not yet depend on Playwright, first install the`,
140
- `applicable npm package (most commonly @playwright/test), and`,
141
- `then run Playwright's install command to download the browsers:`,
142
- ``,
143
- ` npm install @playwright/test`,
144
- ` npx playwright install`,
145
- ``
146
- ].join("\n"), 1));
147
- }
148
- try {
149
- if (options.shell === false && options.onlyShell)
150
- throw new Error(`Only one of --no-shell and --only-shell can be specified`);
151
- const shell = options.shell === false ? "no" : options.onlyShell ? "only" : void 0;
152
- const executables = import_server.registry.resolveBrowsers(args, { shell });
153
- if (options.withDeps)
154
- await import_server.registry.installDeps(executables, !!options.dryRun);
155
- if (options.dryRun && options.list)
156
- throw new Error(`Only one of --dry-run and --list can be specified`);
157
- if (options.dryRun) {
158
- for (const executable of executables) {
159
- console.log(import_server.registry.calculateDownloadTitle(executable));
160
- console.log(` Install location: ${executable.directory ?? "<system>"}`);
161
- if (executable.downloadURLs?.length) {
162
- const [url, ...fallbacks] = executable.downloadURLs;
163
- console.log(` Download url: ${url}`);
164
- for (let i = 0; i < fallbacks.length; ++i)
165
- console.log(` Download fallback ${i + 1}: ${fallbacks[i]}`);
166
- }
167
- console.log(``);
168
- }
169
- } else if (options.list) {
170
- const browsers2 = await import_server.registry.listInstalledBrowsers();
171
- printGroupedByPlaywrightVersion(browsers2);
172
- } else {
173
- await import_server.registry.install(executables, { force: options.force });
174
- await import_server.registry.validateHostRequirementsForExecutablesIfNeeded(executables, process.env.PW_LANG_NAME || "javascript").catch((e) => {
175
- e.name = "Playwright Host validation warning";
176
- console.error(e);
177
- });
178
- }
179
- } catch (e) {
180
- console.log(`Failed to install browsers
181
- ${e}`);
182
- (0, import_utils.gracefullyProcessExitDoNotHang)(1);
183
- }
184
- }).addHelpText("afterAll", `
185
-
186
- Examples:
187
- - $ install
188
- Install default browsers.
189
-
190
- - $ install chrome firefox
191
- Install custom browsers, supports ${import_server.registry.suggestedBrowsersToInstall()}.`);
192
- import_utilsBundle.program.command("uninstall").description("Removes browsers used by this installation of Playwright from the system (chromium, firefox, webkit, ffmpeg). This does not include branded channels.").option("--all", "Removes all browsers used by any Playwright installation from the system.").action(async (options) => {
193
- delete process.env.PLAYWRIGHT_SKIP_BROWSER_GC;
194
- await import_server.registry.uninstall(!!options.all).then(({ numberOfBrowsersLeft }) => {
195
- if (!options.all && numberOfBrowsersLeft > 0) {
196
- console.log("Successfully uninstalled Playwright browsers for the current Playwright installation.");
197
- console.log(`There are still ${numberOfBrowsersLeft} browsers left, used by other Playwright installations.
198
- To uninstall Playwright browsers for all installations, re-run with --all flag.`);
199
- }
200
- }).catch(logErrorAndExit);
201
- });
202
- import_utilsBundle.program.command("install-deps [browser...]").description("install dependencies necessary to run browsers (will ask for sudo permissions)").option("--dry-run", "Do not execute installation commands, only print them").action(async function(args, options) {
203
- try {
204
- await import_server.registry.installDeps(import_server.registry.resolveBrowsers(args, {}), !!options.dryRun);
205
- } catch (e) {
206
- console.log(`Failed to install browser dependencies
207
- ${e}`);
208
- (0, import_utils.gracefullyProcessExitDoNotHang)(1);
209
- }
210
- }).addHelpText("afterAll", `
211
- Examples:
212
- - $ install-deps
213
- Install dependencies for default browsers.
214
-
215
- - $ install-deps chrome firefox
216
- Install dependencies for specific browsers, supports ${import_server.registry.suggestedBrowsersToInstall()}.`);
217
- const browsers = [
218
- { alias: "cr", name: "Chromium", type: "chromium" },
219
- { alias: "ff", name: "Firefox", type: "firefox" },
220
- { alias: "wk", name: "WebKit", type: "webkit" }
221
- ];
222
- for (const { alias, name, type } of browsers) {
223
- commandWithOpenOptions(`${alias} [url]`, `open page in ${name}`, []).action(function(url, options) {
224
- open({ ...options, browser: type }, url).catch(logErrorAndExit);
225
- }).addHelpText("afterAll", `
226
- Examples:
227
-
228
- $ ${alias} https://example.com`);
229
- }
230
- commandWithOpenOptions(
231
- "screenshot <url> <filename>",
232
- "capture a page screenshot",
233
- [
234
- ["--wait-for-selector <selector>", "wait for selector before taking a screenshot"],
235
- ["--wait-for-timeout <timeout>", "wait for timeout in milliseconds before taking a screenshot"],
236
- ["--full-page", "whether to take a full page screenshot (entire scrollable area)"]
237
- ]
238
- ).action(function(url, filename, command) {
239
- screenshot(command, command, url, filename).catch(logErrorAndExit);
240
- }).addHelpText("afterAll", `
241
- Examples:
242
-
243
- $ screenshot -b webkit https://example.com example.png`);
244
- commandWithOpenOptions(
245
- "pdf <url> <filename>",
246
- "save page as pdf",
247
- [
248
- ["--paper-format <format>", "paper format: Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6"],
249
- ["--wait-for-selector <selector>", "wait for given selector before saving as pdf"],
250
- ["--wait-for-timeout <timeout>", "wait for given timeout in milliseconds before saving as pdf"]
251
- ]
252
- ).action(function(url, filename, options) {
253
- pdf(options, options, url, filename).catch(logErrorAndExit);
254
- }).addHelpText("afterAll", `
255
- Examples:
256
-
257
- $ pdf https://example.com example.pdf`);
258
- import_utilsBundle.program.command("run-driver", { hidden: true }).action(function(options) {
259
- (0, import_driver.runDriver)();
260
- });
261
- import_utilsBundle.program.command("run-server", { hidden: true }).option("--port <port>", "Server port").option("--host <host>", "Server host").option("--path <path>", "Endpoint Path", "/").option("--max-clients <maxClients>", "Maximum clients").option("--mode <mode>", 'Server mode, either "default" or "extension"').action(function(options) {
262
- (0, import_driver.runServer)({
263
- port: options.port ? +options.port : void 0,
264
- host: options.host,
265
- path: options.path,
266
- maxConnections: options.maxClients ? +options.maxClients : Infinity,
267
- extension: options.mode === "extension" || !!process.env.PW_EXTENSION_MODE
268
- }).catch(logErrorAndExit);
269
- });
270
- import_utilsBundle.program.command("print-api-json", { hidden: true }).action(function(options) {
271
- (0, import_driver.printApiJson)();
272
- });
273
- import_utilsBundle.program.command("launch-server", { hidden: true }).requiredOption("--browser <browserName>", 'Browser name, one of "chromium", "firefox" or "webkit"').option("--config <path-to-config-file>", "JSON file with launchServer options").action(function(options) {
274
- (0, import_driver.launchBrowserServer)(options.browser, options.config);
275
- });
276
- import_utilsBundle.program.command("show-trace [trace]").option("-b, --browser <browserType>", "browser to use, one of cr, chromium, ff, firefox, wk, webkit", "chromium").option("-h, --host <host>", "Host to serve trace on; specifying this option opens trace in a browser tab").option("-p, --port <port>", "Port to serve trace on, 0 for any free port; specifying this option opens trace in a browser tab").option("--stdin", "Accept trace URLs over stdin to update the viewer").description("show trace viewer").action(function(trace, options) {
277
- if (options.browser === "cr")
278
- options.browser = "chromium";
279
- if (options.browser === "ff")
280
- options.browser = "firefox";
281
- if (options.browser === "wk")
282
- options.browser = "webkit";
283
- const openOptions = {
284
- host: options.host,
285
- port: +options.port,
286
- isServer: !!options.stdin
287
- };
288
- if (options.port !== void 0 || options.host !== void 0)
289
- (0, import_traceViewer.runTraceInBrowser)(trace, openOptions).catch(logErrorAndExit);
290
- else
291
- (0, import_traceViewer.runTraceViewerApp)(trace, options.browser, openOptions, true).catch(logErrorAndExit);
292
- }).addHelpText("afterAll", `
293
- Examples:
294
-
295
- $ show-trace
296
- $ show-trace https://example.com/trace.zip`);
297
- async function launchContext(options, extraOptions) {
298
- validateOptions(options);
299
- const browserType = lookupBrowserType(options);
300
- const launchOptions = extraOptions;
301
- if (options.channel)
302
- launchOptions.channel = options.channel;
303
- launchOptions.handleSIGINT = false;
304
- const contextOptions = (
305
- // Copy the device descriptor since we have to compare and modify the options.
306
- options.device ? { ...playwright.devices[options.device] } : {}
307
- );
308
- if (!extraOptions.headless)
309
- contextOptions.deviceScaleFactor = import_os.default.platform() === "darwin" ? 2 : 1;
310
- if (browserType.name() === "webkit" && process.platform === "linux") {
311
- delete contextOptions.hasTouch;
312
- delete contextOptions.isMobile;
313
- }
314
- if (contextOptions.isMobile && browserType.name() === "firefox")
315
- contextOptions.isMobile = void 0;
316
- if (options.blockServiceWorkers)
317
- contextOptions.serviceWorkers = "block";
318
- if (options.proxyServer) {
319
- launchOptions.proxy = {
320
- server: options.proxyServer
321
- };
322
- if (options.proxyBypass)
323
- launchOptions.proxy.bypass = options.proxyBypass;
324
- }
325
- if (options.viewportSize) {
326
- try {
327
- const [width, height] = options.viewportSize.split(",").map((n) => +n);
328
- if (isNaN(width) || isNaN(height))
329
- throw new Error("bad values");
330
- contextOptions.viewport = { width, height };
331
- } catch (e) {
332
- throw new Error('Invalid viewport size format: use "width,height", for example --viewport-size="800,600"');
333
- }
334
- }
335
- if (options.geolocation) {
336
- try {
337
- const [latitude, longitude] = options.geolocation.split(",").map((n) => parseFloat(n.trim()));
338
- contextOptions.geolocation = {
339
- latitude,
340
- longitude
341
- };
342
- } catch (e) {
343
- throw new Error('Invalid geolocation format, should be "lat,long". For example --geolocation="37.819722,-122.478611"');
344
- }
345
- contextOptions.permissions = ["geolocation"];
346
- }
347
- if (options.userAgent)
348
- contextOptions.userAgent = options.userAgent;
349
- if (options.lang)
350
- contextOptions.locale = options.lang;
351
- if (options.colorScheme)
352
- contextOptions.colorScheme = options.colorScheme;
353
- if (options.timezone)
354
- contextOptions.timezoneId = options.timezone;
355
- if (options.loadStorage)
356
- contextOptions.storageState = options.loadStorage;
357
- if (options.ignoreHttpsErrors)
358
- contextOptions.ignoreHTTPSErrors = true;
359
- if (options.saveHar) {
360
- contextOptions.recordHar = { path: import_path.default.resolve(process.cwd(), options.saveHar), mode: "minimal" };
361
- if (options.saveHarGlob)
362
- contextOptions.recordHar.urlFilter = options.saveHarGlob;
363
- contextOptions.serviceWorkers = "block";
364
- }
365
- let browser;
366
- let context;
367
- if (options.userDataDir) {
368
- context = await browserType.launchPersistentContext(options.userDataDir, { ...launchOptions, ...contextOptions });
369
- browser = context.browser();
370
- } else {
371
- browser = await browserType.launch(launchOptions);
372
- context = await browser.newContext(contextOptions);
373
- }
374
- let closingBrowser = false;
375
- async function closeBrowser() {
376
- if (closingBrowser)
377
- return;
378
- closingBrowser = true;
379
- if (options.saveStorage)
380
- await context.storageState({ path: options.saveStorage }).catch((e) => null);
381
- if (options.saveHar)
382
- await context.close();
383
- await browser.close();
384
- }
385
- context.on("page", (page) => {
386
- page.on("dialog", () => {
387
- });
388
- page.on("close", () => {
389
- const hasPage = browser.contexts().some((context2) => context2.pages().length > 0);
390
- if (hasPage)
391
- return;
392
- closeBrowser().catch(() => {
393
- });
394
- });
395
- });
396
- process.on("SIGINT", async () => {
397
- await closeBrowser();
398
- (0, import_utils.gracefullyProcessExitDoNotHang)(130);
399
- });
400
- const timeout = options.timeout ? parseInt(options.timeout, 10) : 0;
401
- context.setDefaultTimeout(timeout);
402
- context.setDefaultNavigationTimeout(timeout);
403
- delete launchOptions.headless;
404
- delete launchOptions.executablePath;
405
- delete launchOptions.handleSIGINT;
406
- delete contextOptions.deviceScaleFactor;
407
- return { browser, browserName: browserType.name(), context, contextOptions, launchOptions, closeBrowser };
408
- }
409
- async function openPage(context, url) {
410
- let page = context.pages()[0];
411
- if (!page)
412
- page = await context.newPage();
413
- if (url) {
414
- if (import_fs.default.existsSync(url))
415
- url = "file://" + import_path.default.resolve(url);
416
- else if (!url.startsWith("http") && !url.startsWith("file://") && !url.startsWith("about:") && !url.startsWith("data:"))
417
- url = "http://" + url;
418
- await page.goto(url);
419
- }
420
- return page;
421
- }
422
- async function open(options, url) {
423
- const { context } = await launchContext(options, { headless: !!process.env.PWTEST_CLI_HEADLESS, executablePath: process.env.PWTEST_CLI_EXECUTABLE_PATH });
424
- await context._exposeConsoleApi();
425
- await openPage(context, url);
426
- }
427
- async function codegen(options, url) {
428
- const { target: language, output: outputFile, testIdAttribute: testIdAttributeName } = options;
429
- const tracesDir = import_path.default.join(import_os.default.tmpdir(), `playwright-recorder-trace-${Date.now()}`);
430
- const { context, browser, launchOptions, contextOptions, closeBrowser } = await launchContext(options, {
431
- headless: !!process.env.PWTEST_CLI_HEADLESS,
432
- executablePath: process.env.PWTEST_CLI_EXECUTABLE_PATH,
433
- tracesDir
434
- });
435
- const donePromise = new import_utils.ManualPromise();
436
- maybeSetupTestHooks(browser, closeBrowser, donePromise);
437
- import_utilsBundle.dotenv.config({ path: "playwright.env" });
438
- await context._enableRecorder({
439
- language,
440
- launchOptions,
441
- contextOptions,
442
- device: options.device,
443
- saveStorage: options.saveStorage,
444
- mode: "recording",
445
- testIdAttributeName,
446
- outputFile: outputFile ? import_path.default.resolve(outputFile) : void 0,
447
- handleSIGINT: false
448
- });
449
- await openPage(context, url);
450
- donePromise.resolve();
451
- }
452
- async function maybeSetupTestHooks(browser, closeBrowser, donePromise) {
453
- if (!process.env.PWTEST_CLI_IS_UNDER_TEST)
454
- return;
455
- const logs = [];
456
- require("playwright-core/lib/utilsBundle").debug.log = (...args) => {
457
- const line = require("util").format(...args) + "\n";
458
- logs.push(line);
459
- process.stderr.write(line);
460
- };
461
- browser.on("disconnected", () => {
462
- const hasCrashLine = logs.some((line) => line.includes("process did exit:") && !line.includes("process did exit: exitCode=0, signal=null"));
463
- if (hasCrashLine) {
464
- process.stderr.write("Detected browser crash.\n");
465
- (0, import_utils.gracefullyProcessExitDoNotHang)(1);
466
- }
467
- });
468
- const close = async () => {
469
- await donePromise;
470
- await closeBrowser();
471
- };
472
- if (process.env.PWTEST_CLI_EXIT_AFTER_TIMEOUT) {
473
- setTimeout(close, +process.env.PWTEST_CLI_EXIT_AFTER_TIMEOUT);
474
- return;
475
- }
476
- let stdin = "";
477
- process.stdin.on("data", (data) => {
478
- stdin += data.toString();
479
- if (stdin.startsWith("exit")) {
480
- process.stdin.destroy();
481
- close();
482
- }
483
- });
484
- }
485
- async function waitForPage(page, captureOptions) {
486
- if (captureOptions.waitForSelector) {
487
- console.log(`Waiting for selector ${captureOptions.waitForSelector}...`);
488
- await page.waitForSelector(captureOptions.waitForSelector);
489
- }
490
- if (captureOptions.waitForTimeout) {
491
- console.log(`Waiting for timeout ${captureOptions.waitForTimeout}...`);
492
- await page.waitForTimeout(parseInt(captureOptions.waitForTimeout, 10));
493
- }
494
- }
495
- async function screenshot(options, captureOptions, url, path2) {
496
- const { context } = await launchContext(options, { headless: true });
497
- console.log("Navigating to " + url);
498
- const page = await openPage(context, url);
499
- await waitForPage(page, captureOptions);
500
- console.log("Capturing screenshot into " + path2);
501
- await page.screenshot({ path: path2, fullPage: !!captureOptions.fullPage });
502
- await page.close();
503
- }
504
- async function pdf(options, captureOptions, url, path2) {
505
- if (options.browser !== "chromium")
506
- throw new Error("PDF creation is only working with Chromium");
507
- const { context } = await launchContext({ ...options, browser: "chromium" }, { headless: true });
508
- console.log("Navigating to " + url);
509
- const page = await openPage(context, url);
510
- await waitForPage(page, captureOptions);
511
- console.log("Saving as pdf into " + path2);
512
- await page.pdf({ path: path2, format: captureOptions.paperFormat });
513
- await page.close();
514
- }
515
- function lookupBrowserType(options) {
516
- let name = options.browser;
517
- if (options.device) {
518
- const device = playwright.devices[options.device];
519
- name = device.defaultBrowserType;
520
- }
521
- let browserType;
522
- switch (name) {
523
- case "chromium":
524
- browserType = playwright.chromium;
525
- break;
526
- case "webkit":
527
- browserType = playwright.webkit;
528
- break;
529
- case "firefox":
530
- browserType = playwright.firefox;
531
- break;
532
- case "cr":
533
- browserType = playwright.chromium;
534
- break;
535
- case "wk":
536
- browserType = playwright.webkit;
537
- break;
538
- case "ff":
539
- browserType = playwright.firefox;
540
- break;
541
- }
542
- if (browserType)
543
- return browserType;
544
- import_utilsBundle.program.help();
545
- }
546
- function validateOptions(options) {
547
- if (options.device && !(options.device in playwright.devices)) {
548
- const lines = [`Device descriptor not found: '${options.device}', available devices are:`];
549
- for (const name in playwright.devices)
550
- lines.push(` "${name}"`);
551
- throw new Error(lines.join("\n"));
552
- }
553
- if (options.colorScheme && !["light", "dark"].includes(options.colorScheme))
554
- throw new Error('Invalid color scheme, should be one of "light", "dark"');
555
- }
556
- function logErrorAndExit(e) {
557
- if (process.env.PWDEBUGIMPL)
558
- console.error(e);
559
- else
560
- console.error(e.name + ": " + e.message);
561
- (0, import_utils.gracefullyProcessExitDoNotHang)(1);
562
- }
563
- function codegenId() {
564
- return process.env.PW_LANG_NAME || "playwright-test";
565
- }
566
- function commandWithOpenOptions(command, description, options) {
567
- let result = import_utilsBundle.program.command(command).description(description);
568
- for (const option of options)
569
- result = result.option(option[0], ...option.slice(1));
570
- return result.option("-b, --browser <browserType>", "browser to use, one of cr, chromium, ff, firefox, wk, webkit", "chromium").option("--block-service-workers", "block service workers").option("--channel <channel>", 'Chromium distribution channel, "chrome", "chrome-beta", "msedge-dev", etc').option("--color-scheme <scheme>", 'emulate preferred color scheme, "light" or "dark"').option("--device <deviceName>", 'emulate device, for example "iPhone 11"').option("--geolocation <coordinates>", 'specify geolocation coordinates, for example "37.819722,-122.478611"').option("--ignore-https-errors", "ignore https errors").option("--load-storage <filename>", "load context storage state from the file, previously saved with --save-storage").option("--lang <language>", 'specify language / locale, for example "en-GB"').option("--proxy-server <proxy>", 'specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"').option("--proxy-bypass <bypass>", 'comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com"').option("--save-har <filename>", "save HAR file with all network activity at the end").option("--save-har-glob <glob pattern>", "filter entries in the HAR by matching url against this glob pattern").option("--save-storage <filename>", "save context storage state at the end, for later use with --load-storage").option("--timezone <time zone>", 'time zone to emulate, for example "Europe/Rome"').option("--timeout <timeout>", "timeout for Playwright actions in milliseconds, no timeout by default").option("--user-agent <ua string>", "specify user agent string").option("--user-data-dir <directory>", "use the specified user data directory instead of a new context").option("--viewport-size <size>", 'specify browser viewport size in pixels, for example "1280, 720"');
571
- }
572
- function buildBasePlaywrightCLICommand(cliTargetLang) {
573
- switch (cliTargetLang) {
574
- case "python":
575
- return `playwright`;
576
- case "java":
577
- return `mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="...options.."`;
578
- case "csharp":
579
- return `pwsh bin/Debug/netX/playwright.ps1`;
580
- default: {
581
- const packageManagerCommand = (0, import_utils2.getPackageManagerExecCommand)();
582
- return `${packageManagerCommand} playwright`;
583
- }
584
- }
585
- }
586
- // Annotate the CommonJS export names for ESM import in node:
587
- 0 && (module.exports = {
588
- program
589
- });
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 program_exports = {};
30
+ __export(program_exports, {
31
+ program: () => import_utilsBundle2.program
32
+ });
33
+ module.exports = __toCommonJS(program_exports);
34
+ var import_fs = __toESM(require("fs"));
35
+ var import_os = __toESM(require("os"));
36
+ var import_path = __toESM(require("path"));
37
+ var playwright = __toESM(require("../.."));
38
+ var import_driver = require("./driver");
39
+ var import_server = require("../server");
40
+ var import_utils = require("../utils");
41
+ var import_traceViewer = require("../server/trace/viewer/traceViewer");
42
+ var import_utils2 = require("../utils");
43
+ var import_ascii = require("../server/utils/ascii");
44
+ var import_utilsBundle = require("../utilsBundle");
45
+ var import_utilsBundle2 = require("../utilsBundle");
46
+ const packageJSON = require("../../package.json");
47
+ import_utilsBundle.program.version("Version " + (process.env.PW_CLI_DISPLAY_VERSION || packageJSON.version)).name(buildBasePlaywrightCLICommand(process.env.PW_LANG_NAME));
48
+ import_utilsBundle.program.command("mark-docker-image [dockerImageNameTemplate]", { hidden: true }).description("mark docker image").allowUnknownOption(true).action(function(dockerImageNameTemplate) {
49
+ (0, import_utils2.assert)(dockerImageNameTemplate, "dockerImageNameTemplate is required");
50
+ (0, import_server.writeDockerVersion)(dockerImageNameTemplate).catch(logErrorAndExit);
51
+ });
52
+ commandWithOpenOptions("open [url]", "open page in browser specified via -b, --browser", []).action(function(url, options) {
53
+ open(options, url).catch(logErrorAndExit);
54
+ }).addHelpText("afterAll", `
55
+ Examples:
56
+
57
+ $ open
58
+ $ open -b webkit https://example.com`);
59
+ commandWithOpenOptions(
60
+ "codegen [url]",
61
+ "open page and generate code for user actions",
62
+ [
63
+ ["-o, --output <file name>", "saves the generated script to a file"],
64
+ ["--target <language>", `language to generate, one of javascript, playwright-test, python, python-async, python-pytest, csharp, csharp-mstest, csharp-nunit, java, java-junit`, codegenId()],
65
+ ["--test-id-attribute <attributeName>", "use the specified attribute to generate data test ID selectors"]
66
+ ]
67
+ ).action(async function(url, options) {
68
+ await codegen(options, url);
69
+ }).addHelpText("afterAll", `
70
+ Examples:
71
+
72
+ $ codegen
73
+ $ codegen --target=python
74
+ $ codegen -b webkit https://example.com`);
75
+ function printInstalledBrowsers(browsers2) {
76
+ const browserPaths = /* @__PURE__ */ new Set();
77
+ for (const browser of browsers2)
78
+ browserPaths.add(browser.browserPath);
79
+ console.log(` Browsers:`);
80
+ for (const browserPath of [...browserPaths].sort())
81
+ console.log(` ${browserPath}`);
82
+ console.log(` References:`);
83
+ const references = /* @__PURE__ */ new Set();
84
+ for (const browser of browsers2)
85
+ references.add(browser.referenceDir);
86
+ for (const reference of [...references].sort())
87
+ console.log(` ${reference}`);
88
+ }
89
+ function printGroupedByPlaywrightVersion(browsers2) {
90
+ const dirToVersion = /* @__PURE__ */ new Map();
91
+ for (const browser of browsers2) {
92
+ if (dirToVersion.has(browser.referenceDir))
93
+ continue;
94
+ const packageJSON2 = require(import_path.default.join(browser.referenceDir, "package.json"));
95
+ const version = packageJSON2.version;
96
+ dirToVersion.set(browser.referenceDir, version);
97
+ }
98
+ const groupedByPlaywrightMinorVersion = /* @__PURE__ */ new Map();
99
+ for (const browser of browsers2) {
100
+ const version = dirToVersion.get(browser.referenceDir);
101
+ let entries = groupedByPlaywrightMinorVersion.get(version);
102
+ if (!entries) {
103
+ entries = [];
104
+ groupedByPlaywrightMinorVersion.set(version, entries);
105
+ }
106
+ entries.push(browser);
107
+ }
108
+ const sortedVersions = [...groupedByPlaywrightMinorVersion.keys()].sort((a, b) => {
109
+ const aComponents = a.split(".");
110
+ const bComponents = b.split(".");
111
+ const aMajor = parseInt(aComponents[0], 10);
112
+ const bMajor = parseInt(bComponents[0], 10);
113
+ if (aMajor !== bMajor)
114
+ return aMajor - bMajor;
115
+ const aMinor = parseInt(aComponents[1], 10);
116
+ const bMinor = parseInt(bComponents[1], 10);
117
+ if (aMinor !== bMinor)
118
+ return aMinor - bMinor;
119
+ return aComponents.slice(2).join(".").localeCompare(bComponents.slice(2).join("."));
120
+ });
121
+ for (const version of sortedVersions) {
122
+ console.log(`
123
+ Playwright version: ${version}`);
124
+ printInstalledBrowsers(groupedByPlaywrightMinorVersion.get(version));
125
+ }
126
+ }
127
+ import_utilsBundle.program.command("install [browser...]").description("ensure browsers necessary for this version of Playwright are installed").option("--with-deps", "install system dependencies for browsers").option("--dry-run", "do not execute installation, only print information").option("--list", "prints list of browsers from all playwright installations").option("--force", "force reinstall of already installed browsers").option("--only-shell", "only install headless shell when installing chromium").option("--no-shell", "do not install chromium headless shell").action(async function(args, options) {
128
+ if ((0, import_utils.isLikelyNpxGlobal)()) {
129
+ console.error((0, import_ascii.wrapInASCIIBox)([
130
+ `WARNING: It looks like you are running 'npx playwright install' without first`,
131
+ `installing your project's dependencies.`,
132
+ ``,
133
+ `To avoid unexpected behavior, please install your dependencies first, and`,
134
+ `then run Playwright's install command:`,
135
+ ``,
136
+ ` npm install`,
137
+ ` npx playwright install`,
138
+ ``,
139
+ `If your project does not yet depend on Playwright, first install the`,
140
+ `applicable npm package (most commonly @playwright/test), and`,
141
+ `then run Playwright's install command to download the browsers:`,
142
+ ``,
143
+ ` npm install @playwright/test`,
144
+ ` npx playwright install`,
145
+ ``
146
+ ].join("\n"), 1));
147
+ }
148
+ try {
149
+ if (options.shell === false && options.onlyShell)
150
+ throw new Error(`Only one of --no-shell and --only-shell can be specified`);
151
+ const shell = options.shell === false ? "no" : options.onlyShell ? "only" : void 0;
152
+ const executables = import_server.registry.resolveBrowsers(args, { shell });
153
+ if (options.withDeps)
154
+ await import_server.registry.installDeps(executables, !!options.dryRun);
155
+ if (options.dryRun && options.list)
156
+ throw new Error(`Only one of --dry-run and --list can be specified`);
157
+ if (options.dryRun) {
158
+ for (const executable of executables) {
159
+ console.log(import_server.registry.calculateDownloadTitle(executable));
160
+ console.log(` Install location: ${executable.directory ?? "<system>"}`);
161
+ if (executable.downloadURLs?.length) {
162
+ const [url, ...fallbacks] = executable.downloadURLs;
163
+ console.log(` Download url: ${url}`);
164
+ for (let i = 0; i < fallbacks.length; ++i)
165
+ console.log(` Download fallback ${i + 1}: ${fallbacks[i]}`);
166
+ }
167
+ console.log(``);
168
+ }
169
+ } else if (options.list) {
170
+ const browsers2 = await import_server.registry.listInstalledBrowsers();
171
+ printGroupedByPlaywrightVersion(browsers2);
172
+ } else {
173
+ await import_server.registry.install(executables, { force: options.force });
174
+ await import_server.registry.validateHostRequirementsForExecutablesIfNeeded(executables, process.env.PW_LANG_NAME || "javascript").catch((e) => {
175
+ e.name = "Playwright Host validation warning";
176
+ console.error(e);
177
+ });
178
+ }
179
+ } catch (e) {
180
+ console.log(`Failed to install browsers
181
+ ${e}`);
182
+ (0, import_utils.gracefullyProcessExitDoNotHang)(1);
183
+ }
184
+ }).addHelpText("afterAll", `
185
+
186
+ Examples:
187
+ - $ install
188
+ Install default browsers.
189
+
190
+ - $ install chrome firefox
191
+ Install custom browsers, supports ${import_server.registry.suggestedBrowsersToInstall()}.`);
192
+ import_utilsBundle.program.command("uninstall").description("Removes browsers used by this installation of Playwright from the system (chromium, firefox, webkit, ffmpeg). This does not include branded channels.").option("--all", "Removes all browsers used by any Playwright installation from the system.").action(async (options) => {
193
+ delete process.env.PLAYWRIGHT_SKIP_BROWSER_GC;
194
+ await import_server.registry.uninstall(!!options.all).then(({ numberOfBrowsersLeft }) => {
195
+ if (!options.all && numberOfBrowsersLeft > 0) {
196
+ console.log("Successfully uninstalled Playwright browsers for the current Playwright installation.");
197
+ console.log(`There are still ${numberOfBrowsersLeft} browsers left, used by other Playwright installations.
198
+ To uninstall Playwright browsers for all installations, re-run with --all flag.`);
199
+ }
200
+ }).catch(logErrorAndExit);
201
+ });
202
+ import_utilsBundle.program.command("install-deps [browser...]").description("install dependencies necessary to run browsers (will ask for sudo permissions)").option("--dry-run", "Do not execute installation commands, only print them").action(async function(args, options) {
203
+ try {
204
+ await import_server.registry.installDeps(import_server.registry.resolveBrowsers(args, {}), !!options.dryRun);
205
+ } catch (e) {
206
+ console.log(`Failed to install browser dependencies
207
+ ${e}`);
208
+ (0, import_utils.gracefullyProcessExitDoNotHang)(1);
209
+ }
210
+ }).addHelpText("afterAll", `
211
+ Examples:
212
+ - $ install-deps
213
+ Install dependencies for default browsers.
214
+
215
+ - $ install-deps chrome firefox
216
+ Install dependencies for specific browsers, supports ${import_server.registry.suggestedBrowsersToInstall()}.`);
217
+ const browsers = [
218
+ { alias: "cr", name: "Chromium", type: "chromium" },
219
+ { alias: "ff", name: "Firefox", type: "firefox" },
220
+ { alias: "wk", name: "WebKit", type: "webkit" }
221
+ ];
222
+ for (const { alias, name, type } of browsers) {
223
+ commandWithOpenOptions(`${alias} [url]`, `open page in ${name}`, []).action(function(url, options) {
224
+ open({ ...options, browser: type }, url).catch(logErrorAndExit);
225
+ }).addHelpText("afterAll", `
226
+ Examples:
227
+
228
+ $ ${alias} https://example.com`);
229
+ }
230
+ commandWithOpenOptions(
231
+ "screenshot <url> <filename>",
232
+ "capture a page screenshot",
233
+ [
234
+ ["--wait-for-selector <selector>", "wait for selector before taking a screenshot"],
235
+ ["--wait-for-timeout <timeout>", "wait for timeout in milliseconds before taking a screenshot"],
236
+ ["--full-page", "whether to take a full page screenshot (entire scrollable area)"]
237
+ ]
238
+ ).action(function(url, filename, command) {
239
+ screenshot(command, command, url, filename).catch(logErrorAndExit);
240
+ }).addHelpText("afterAll", `
241
+ Examples:
242
+
243
+ $ screenshot -b webkit https://example.com example.png`);
244
+ commandWithOpenOptions(
245
+ "pdf <url> <filename>",
246
+ "save page as pdf",
247
+ [
248
+ ["--paper-format <format>", "paper format: Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6"],
249
+ ["--wait-for-selector <selector>", "wait for given selector before saving as pdf"],
250
+ ["--wait-for-timeout <timeout>", "wait for given timeout in milliseconds before saving as pdf"]
251
+ ]
252
+ ).action(function(url, filename, options) {
253
+ pdf(options, options, url, filename).catch(logErrorAndExit);
254
+ }).addHelpText("afterAll", `
255
+ Examples:
256
+
257
+ $ pdf https://example.com example.pdf`);
258
+ import_utilsBundle.program.command("run-driver", { hidden: true }).action(function(options) {
259
+ (0, import_driver.runDriver)();
260
+ });
261
+ import_utilsBundle.program.command("run-server", { hidden: true }).option("--port <port>", "Server port").option("--host <host>", "Server host").option("--path <path>", "Endpoint Path", "/").option("--max-clients <maxClients>", "Maximum clients").option("--mode <mode>", 'Server mode, either "default" or "extension"').action(function(options) {
262
+ (0, import_driver.runServer)({
263
+ port: options.port ? +options.port : void 0,
264
+ host: options.host,
265
+ path: options.path,
266
+ maxConnections: options.maxClients ? +options.maxClients : Infinity,
267
+ extension: options.mode === "extension" || !!process.env.PW_EXTENSION_MODE
268
+ }).catch(logErrorAndExit);
269
+ });
270
+ import_utilsBundle.program.command("print-api-json", { hidden: true }).action(function(options) {
271
+ (0, import_driver.printApiJson)();
272
+ });
273
+ import_utilsBundle.program.command("launch-server", { hidden: true }).requiredOption("--browser <browserName>", 'Browser name, one of "chromium", "firefox" or "webkit"').option("--config <path-to-config-file>", "JSON file with launchServer options").action(function(options) {
274
+ (0, import_driver.launchBrowserServer)(options.browser, options.config);
275
+ });
276
+ import_utilsBundle.program.command("show-trace [trace]").option("-b, --browser <browserType>", "browser to use, one of cr, chromium, ff, firefox, wk, webkit", "chromium").option("-h, --host <host>", "Host to serve trace on; specifying this option opens trace in a browser tab").option("-p, --port <port>", "Port to serve trace on, 0 for any free port; specifying this option opens trace in a browser tab").option("--stdin", "Accept trace URLs over stdin to update the viewer").description("show trace viewer").action(function(trace, options) {
277
+ if (options.browser === "cr")
278
+ options.browser = "chromium";
279
+ if (options.browser === "ff")
280
+ options.browser = "firefox";
281
+ if (options.browser === "wk")
282
+ options.browser = "webkit";
283
+ const openOptions = {
284
+ host: options.host,
285
+ port: +options.port,
286
+ isServer: !!options.stdin
287
+ };
288
+ if (options.port !== void 0 || options.host !== void 0)
289
+ (0, import_traceViewer.runTraceInBrowser)(trace, openOptions).catch(logErrorAndExit);
290
+ else
291
+ (0, import_traceViewer.runTraceViewerApp)(trace, options.browser, openOptions, true).catch(logErrorAndExit);
292
+ }).addHelpText("afterAll", `
293
+ Examples:
294
+
295
+ $ show-trace
296
+ $ show-trace https://example.com/trace.zip`);
297
+ async function launchContext(options, extraOptions) {
298
+ validateOptions(options);
299
+ const browserType = lookupBrowserType(options);
300
+ const launchOptions = extraOptions;
301
+ if (options.channel)
302
+ launchOptions.channel = options.channel;
303
+ launchOptions.handleSIGINT = false;
304
+ const contextOptions = (
305
+ // Copy the device descriptor since we have to compare and modify the options.
306
+ options.device ? { ...playwright.devices[options.device] } : {}
307
+ );
308
+ if (!extraOptions.headless)
309
+ contextOptions.deviceScaleFactor = import_os.default.platform() === "darwin" ? 2 : 1;
310
+ if (browserType.name() === "webkit" && process.platform === "linux") {
311
+ delete contextOptions.hasTouch;
312
+ delete contextOptions.isMobile;
313
+ }
314
+ if (contextOptions.isMobile && browserType.name() === "firefox")
315
+ contextOptions.isMobile = void 0;
316
+ if (options.blockServiceWorkers)
317
+ contextOptions.serviceWorkers = "block";
318
+ if (options.proxyServer) {
319
+ launchOptions.proxy = {
320
+ server: options.proxyServer
321
+ };
322
+ if (options.proxyBypass)
323
+ launchOptions.proxy.bypass = options.proxyBypass;
324
+ }
325
+ if (options.viewportSize) {
326
+ try {
327
+ const [width, height] = options.viewportSize.split(",").map((n) => +n);
328
+ if (isNaN(width) || isNaN(height))
329
+ throw new Error("bad values");
330
+ contextOptions.viewport = { width, height };
331
+ } catch (e) {
332
+ throw new Error('Invalid viewport size format: use "width,height", for example --viewport-size="800,600"');
333
+ }
334
+ }
335
+ if (options.geolocation) {
336
+ try {
337
+ const [latitude, longitude] = options.geolocation.split(",").map((n) => parseFloat(n.trim()));
338
+ contextOptions.geolocation = {
339
+ latitude,
340
+ longitude
341
+ };
342
+ } catch (e) {
343
+ throw new Error('Invalid geolocation format, should be "lat,long". For example --geolocation="37.819722,-122.478611"');
344
+ }
345
+ contextOptions.permissions = ["geolocation"];
346
+ }
347
+ if (options.userAgent)
348
+ contextOptions.userAgent = options.userAgent;
349
+ if (options.lang)
350
+ contextOptions.locale = options.lang;
351
+ if (options.colorScheme)
352
+ contextOptions.colorScheme = options.colorScheme;
353
+ if (options.timezone)
354
+ contextOptions.timezoneId = options.timezone;
355
+ if (options.loadStorage)
356
+ contextOptions.storageState = options.loadStorage;
357
+ if (options.ignoreHttpsErrors)
358
+ contextOptions.ignoreHTTPSErrors = true;
359
+ if (options.saveHar) {
360
+ contextOptions.recordHar = { path: import_path.default.resolve(process.cwd(), options.saveHar), mode: "minimal" };
361
+ if (options.saveHarGlob)
362
+ contextOptions.recordHar.urlFilter = options.saveHarGlob;
363
+ contextOptions.serviceWorkers = "block";
364
+ }
365
+ let browser;
366
+ let context;
367
+ if (options.userDataDir) {
368
+ context = await browserType.launchPersistentContext(options.userDataDir, { ...launchOptions, ...contextOptions });
369
+ browser = context.browser();
370
+ } else {
371
+ browser = await browserType.launch(launchOptions);
372
+ context = await browser.newContext(contextOptions);
373
+ }
374
+ let closingBrowser = false;
375
+ async function closeBrowser() {
376
+ if (closingBrowser)
377
+ return;
378
+ closingBrowser = true;
379
+ if (options.saveStorage)
380
+ await context.storageState({ path: options.saveStorage }).catch((e) => null);
381
+ if (options.saveHar)
382
+ await context.close();
383
+ await browser.close();
384
+ }
385
+ context.on("page", (page) => {
386
+ page.on("dialog", () => {
387
+ });
388
+ page.on("close", () => {
389
+ const hasPage = browser.contexts().some((context2) => context2.pages().length > 0);
390
+ if (hasPage)
391
+ return;
392
+ closeBrowser().catch(() => {
393
+ });
394
+ });
395
+ });
396
+ process.on("SIGINT", async () => {
397
+ await closeBrowser();
398
+ (0, import_utils.gracefullyProcessExitDoNotHang)(130);
399
+ });
400
+ const timeout = options.timeout ? parseInt(options.timeout, 10) : 0;
401
+ context.setDefaultTimeout(timeout);
402
+ context.setDefaultNavigationTimeout(timeout);
403
+ delete launchOptions.headless;
404
+ delete launchOptions.executablePath;
405
+ delete launchOptions.handleSIGINT;
406
+ delete contextOptions.deviceScaleFactor;
407
+ return { browser, browserName: browserType.name(), context, contextOptions, launchOptions, closeBrowser };
408
+ }
409
+ async function openPage(context, url) {
410
+ let page = context.pages()[0];
411
+ if (!page)
412
+ page = await context.newPage();
413
+ if (url) {
414
+ if (import_fs.default.existsSync(url))
415
+ url = "file://" + import_path.default.resolve(url);
416
+ else if (!url.startsWith("http") && !url.startsWith("file://") && !url.startsWith("about:") && !url.startsWith("data:"))
417
+ url = "http://" + url;
418
+ await page.goto(url);
419
+ }
420
+ return page;
421
+ }
422
+ async function open(options, url) {
423
+ const { context } = await launchContext(options, { headless: !!process.env.PWTEST_CLI_HEADLESS, executablePath: process.env.PWTEST_CLI_EXECUTABLE_PATH });
424
+ await context._exposeConsoleApi();
425
+ await openPage(context, url);
426
+ }
427
+ async function codegen(options, url) {
428
+ const { target: language, output: outputFile, testIdAttribute: testIdAttributeName } = options;
429
+ const tracesDir = import_path.default.join(import_os.default.tmpdir(), `playwright-recorder-trace-${Date.now()}`);
430
+ const { context, browser, launchOptions, contextOptions, closeBrowser } = await launchContext(options, {
431
+ headless: !!process.env.PWTEST_CLI_HEADLESS,
432
+ executablePath: process.env.PWTEST_CLI_EXECUTABLE_PATH,
433
+ tracesDir
434
+ });
435
+ const donePromise = new import_utils.ManualPromise();
436
+ maybeSetupTestHooks(browser, closeBrowser, donePromise);
437
+ import_utilsBundle.dotenv.config({ path: "playwright.env" });
438
+ await context._enableRecorder({
439
+ language,
440
+ launchOptions,
441
+ contextOptions,
442
+ device: options.device,
443
+ saveStorage: options.saveStorage,
444
+ mode: "recording",
445
+ testIdAttributeName,
446
+ outputFile: outputFile ? import_path.default.resolve(outputFile) : void 0,
447
+ handleSIGINT: false
448
+ });
449
+ await openPage(context, url);
450
+ donePromise.resolve();
451
+ }
452
+ async function maybeSetupTestHooks(browser, closeBrowser, donePromise) {
453
+ if (!process.env.PWTEST_CLI_IS_UNDER_TEST)
454
+ return;
455
+ const logs = [];
456
+ require("playwright-core/lib/utilsBundle").debug.log = (...args) => {
457
+ const line = require("util").format(...args) + "\n";
458
+ logs.push(line);
459
+ process.stderr.write(line);
460
+ };
461
+ browser.on("disconnected", () => {
462
+ const hasCrashLine = logs.some((line) => line.includes("process did exit:") && !line.includes("process did exit: exitCode=0, signal=null"));
463
+ if (hasCrashLine) {
464
+ process.stderr.write("Detected browser crash.\n");
465
+ (0, import_utils.gracefullyProcessExitDoNotHang)(1);
466
+ }
467
+ });
468
+ const close = async () => {
469
+ await donePromise;
470
+ await closeBrowser();
471
+ };
472
+ if (process.env.PWTEST_CLI_EXIT_AFTER_TIMEOUT) {
473
+ setTimeout(close, +process.env.PWTEST_CLI_EXIT_AFTER_TIMEOUT);
474
+ return;
475
+ }
476
+ let stdin = "";
477
+ process.stdin.on("data", (data) => {
478
+ stdin += data.toString();
479
+ if (stdin.startsWith("exit")) {
480
+ process.stdin.destroy();
481
+ close();
482
+ }
483
+ });
484
+ }
485
+ async function waitForPage(page, captureOptions) {
486
+ if (captureOptions.waitForSelector) {
487
+ console.log(`Waiting for selector ${captureOptions.waitForSelector}...`);
488
+ await page.waitForSelector(captureOptions.waitForSelector);
489
+ }
490
+ if (captureOptions.waitForTimeout) {
491
+ console.log(`Waiting for timeout ${captureOptions.waitForTimeout}...`);
492
+ await page.waitForTimeout(parseInt(captureOptions.waitForTimeout, 10));
493
+ }
494
+ }
495
+ async function screenshot(options, captureOptions, url, path2) {
496
+ const { context } = await launchContext(options, { headless: true });
497
+ console.log("Navigating to " + url);
498
+ const page = await openPage(context, url);
499
+ await waitForPage(page, captureOptions);
500
+ console.log("Capturing screenshot into " + path2);
501
+ await page.screenshot({ path: path2, fullPage: !!captureOptions.fullPage });
502
+ await page.close();
503
+ }
504
+ async function pdf(options, captureOptions, url, path2) {
505
+ if (options.browser !== "chromium")
506
+ throw new Error("PDF creation is only working with Chromium");
507
+ const { context } = await launchContext({ ...options, browser: "chromium" }, { headless: true });
508
+ console.log("Navigating to " + url);
509
+ const page = await openPage(context, url);
510
+ await waitForPage(page, captureOptions);
511
+ console.log("Saving as pdf into " + path2);
512
+ await page.pdf({ path: path2, format: captureOptions.paperFormat });
513
+ await page.close();
514
+ }
515
+ function lookupBrowserType(options) {
516
+ let name = options.browser;
517
+ if (options.device) {
518
+ const device = playwright.devices[options.device];
519
+ name = device.defaultBrowserType;
520
+ }
521
+ let browserType;
522
+ switch (name) {
523
+ case "chromium":
524
+ browserType = playwright.chromium;
525
+ break;
526
+ case "webkit":
527
+ browserType = playwright.webkit;
528
+ break;
529
+ case "firefox":
530
+ browserType = playwright.firefox;
531
+ break;
532
+ case "cr":
533
+ browserType = playwright.chromium;
534
+ break;
535
+ case "wk":
536
+ browserType = playwright.webkit;
537
+ break;
538
+ case "ff":
539
+ browserType = playwright.firefox;
540
+ break;
541
+ }
542
+ if (browserType)
543
+ return browserType;
544
+ import_utilsBundle.program.help();
545
+ }
546
+ function validateOptions(options) {
547
+ if (options.device && !(options.device in playwright.devices)) {
548
+ const lines = [`Device descriptor not found: '${options.device}', available devices are:`];
549
+ for (const name in playwright.devices)
550
+ lines.push(` "${name}"`);
551
+ throw new Error(lines.join("\n"));
552
+ }
553
+ if (options.colorScheme && !["light", "dark"].includes(options.colorScheme))
554
+ throw new Error('Invalid color scheme, should be one of "light", "dark"');
555
+ }
556
+ function logErrorAndExit(e) {
557
+ if (process.env.PWDEBUGIMPL)
558
+ console.error(e);
559
+ else
560
+ console.error(e.name + ": " + e.message);
561
+ (0, import_utils.gracefullyProcessExitDoNotHang)(1);
562
+ }
563
+ function codegenId() {
564
+ return process.env.PW_LANG_NAME || "playwright-test";
565
+ }
566
+ function commandWithOpenOptions(command, description, options) {
567
+ let result = import_utilsBundle.program.command(command).description(description);
568
+ for (const option of options)
569
+ result = result.option(option[0], ...option.slice(1));
570
+ return result.option("-b, --browser <browserType>", "browser to use, one of cr, chromium, ff, firefox, wk, webkit", "chromium").option("--block-service-workers", "block service workers").option("--channel <channel>", 'Chromium distribution channel, "chrome", "chrome-beta", "msedge-dev", etc').option("--color-scheme <scheme>", 'emulate preferred color scheme, "light" or "dark"').option("--device <deviceName>", 'emulate device, for example "iPhone 11"').option("--geolocation <coordinates>", 'specify geolocation coordinates, for example "37.819722,-122.478611"').option("--ignore-https-errors", "ignore https errors").option("--load-storage <filename>", "load context storage state from the file, previously saved with --save-storage").option("--lang <language>", 'specify language / locale, for example "en-GB"').option("--proxy-server <proxy>", 'specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"').option("--proxy-bypass <bypass>", 'comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com"').option("--save-har <filename>", "save HAR file with all network activity at the end").option("--save-har-glob <glob pattern>", "filter entries in the HAR by matching url against this glob pattern").option("--save-storage <filename>", "save context storage state at the end, for later use with --load-storage").option("--timezone <time zone>", 'time zone to emulate, for example "Europe/Rome"').option("--timeout <timeout>", "timeout for Playwright actions in milliseconds, no timeout by default").option("--user-agent <ua string>", "specify user agent string").option("--user-data-dir <directory>", "use the specified user data directory instead of a new context").option("--viewport-size <size>", 'specify browser viewport size in pixels, for example "1280, 720"');
571
+ }
572
+ function buildBasePlaywrightCLICommand(cliTargetLang) {
573
+ switch (cliTargetLang) {
574
+ case "python":
575
+ return `playwright`;
576
+ case "java":
577
+ return `mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="...options.."`;
578
+ case "csharp":
579
+ return `pwsh bin/Debug/netX/playwright.ps1`;
580
+ default: {
581
+ const packageManagerCommand = (0, import_utils2.getPackageManagerExecCommand)();
582
+ return `${packageManagerCommand} playwright`;
583
+ }
584
+ }
585
+ }
586
+ // Annotate the CommonJS export names for ESM import in node:
587
+ 0 && (module.exports = {
588
+ program
589
+ });