rebrowser-playwright-core 1.49.0 → 1.52.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 (373) hide show
  1. package/ThirdPartyNotices.txt +381 -55
  2. package/bin/reinstall_msedge_beta_linux.sh +6 -0
  3. package/bin/reinstall_msedge_dev_linux.sh +6 -0
  4. package/bin/reinstall_msedge_stable_linux.sh +6 -0
  5. package/browsers.json +28 -13
  6. package/index.js +0 -1
  7. package/lib/androidServerImpl.js +42 -48
  8. package/lib/browserServerImpl.js +60 -64
  9. package/lib/cli/driver.js +71 -69
  10. package/lib/cli/program.js +314 -354
  11. package/lib/cli/programWithTestStub.js +51 -44
  12. package/lib/client/accessibility.js +31 -32
  13. package/lib/client/android.js +146 -254
  14. package/lib/client/api.js +135 -283
  15. package/lib/client/artifact.js +39 -39
  16. package/lib/client/browser.js +59 -68
  17. package/lib/client/browserContext.js +302 -322
  18. package/lib/client/browserType.js +95 -143
  19. package/lib/client/cdpSession.js +29 -31
  20. package/lib/client/channelOwner.js +109 -139
  21. package/lib/client/clientHelper.js +49 -42
  22. package/lib/client/clientInstrumentation.js +40 -35
  23. package/lib/client/clientStackTrace.js +69 -0
  24. package/lib/client/clock.js +36 -36
  25. package/lib/client/connection.js +203 -218
  26. package/lib/client/consoleMessage.js +33 -33
  27. package/lib/client/coverage.js +25 -22
  28. package/lib/client/dialog.js +30 -31
  29. package/lib/client/download.js +25 -25
  30. package/lib/client/electron.js +74 -76
  31. package/lib/client/elementHandle.js +126 -163
  32. package/lib/client/errors.js +53 -53
  33. package/lib/client/eventEmitter.js +127 -127
  34. package/lib/client/events.js +72 -68
  35. package/lib/client/fetch.js +154 -178
  36. package/lib/client/fileChooser.js +25 -24
  37. package/lib/client/fileUtils.js +34 -0
  38. package/lib/client/frame.js +189 -307
  39. package/lib/client/harRouter.js +44 -56
  40. package/lib/client/input.js +40 -69
  41. package/lib/client/jsHandle.js +55 -71
  42. package/lib/client/jsonPipe.js +27 -23
  43. package/lib/client/localUtils.js +53 -28
  44. package/lib/client/locator.js +144 -230
  45. package/lib/client/network.js +285 -301
  46. package/lib/client/page.js +273 -312
  47. package/lib/client/platform.js +74 -0
  48. package/lib/client/playwright.js +62 -57
  49. package/lib/client/selectors.js +51 -43
  50. package/lib/client/stream.js +30 -45
  51. package/lib/client/timeoutSettings.js +75 -0
  52. package/lib/client/tracing.js +49 -82
  53. package/lib/client/types.js +26 -22
  54. package/lib/client/video.js +35 -27
  55. package/lib/client/waiter.js +71 -91
  56. package/lib/client/webError.js +25 -23
  57. package/lib/client/webSocket.js +111 -0
  58. package/lib/client/worker.js +48 -56
  59. package/lib/client/writableStream.js +28 -43
  60. package/lib/generated/clockSource.js +26 -5
  61. package/lib/generated/consoleApiSource.js +26 -5
  62. package/lib/generated/injectedScriptSource.js +26 -5
  63. package/lib/generated/pollingRecorderSource.js +26 -5
  64. package/lib/generated/utilityScriptSource.js +26 -5
  65. package/lib/generated/webSocketMockSource.js +375 -4
  66. package/lib/inProcessFactory.js +53 -48
  67. package/lib/inprocess.js +2 -19
  68. package/lib/outofprocess.js +53 -42
  69. package/lib/protocol/debug.js +209 -25
  70. package/lib/protocol/serializers.js +153 -134
  71. package/lib/protocol/validator.js +2712 -2667
  72. package/lib/protocol/validatorPrimitives.js +115 -75
  73. package/lib/remote/playwrightConnection.js +144 -152
  74. package/lib/remote/playwrightServer.js +106 -77
  75. package/lib/server/accessibility.js +44 -37
  76. package/lib/server/android/android.js +216 -206
  77. package/lib/server/android/backendAdb.js +89 -82
  78. package/lib/server/artifact.js +78 -55
  79. package/lib/server/bidi/bidiBrowser.js +227 -158
  80. package/lib/server/bidi/bidiChromium.js +106 -78
  81. package/lib/server/bidi/bidiConnection.js +66 -83
  82. package/lib/server/bidi/bidiExecutionContext.js +161 -97
  83. package/lib/server/bidi/bidiFirefox.js +76 -68
  84. package/lib/server/bidi/bidiInput.js +90 -102
  85. package/lib/server/bidi/bidiNetworkManager.js +141 -159
  86. package/lib/server/bidi/bidiOverCdp.js +57 -58
  87. package/lib/server/bidi/bidiPage.js +262 -261
  88. package/lib/server/bidi/bidiPdf.js +52 -86
  89. package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
  90. package/lib/server/bidi/third_party/bidiDeserializer.js +55 -50
  91. package/lib/server/bidi/third_party/bidiKeyboard.js +241 -223
  92. package/lib/server/bidi/third_party/bidiProtocol.js +144 -131
  93. package/lib/server/bidi/third_party/bidiSerializer.js +67 -63
  94. package/lib/server/bidi/third_party/firefoxPrefs.js +149 -111
  95. package/lib/server/browser.js +76 -84
  96. package/lib/server/browserContext.js +343 -360
  97. package/lib/server/browserType.js +169 -181
  98. package/lib/server/callLog.js +82 -0
  99. package/lib/server/chromium/chromium.js +212 -190
  100. package/lib/server/chromium/chromiumSwitches.js +99 -44
  101. package/lib/server/chromium/crAccessibility.js +157 -131
  102. package/lib/server/chromium/crBrowser.js +262 -280
  103. package/lib/server/chromium/crConnection.js +121 -178
  104. package/lib/server/chromium/crCoverage.js +113 -127
  105. package/lib/server/chromium/crDevTools.js +64 -55
  106. package/lib/server/chromium/crDragDrop.js +62 -79
  107. package/lib/server/chromium/crExecutionContext.js +100 -91
  108. package/lib/server/chromium/crInput.js +101 -88
  109. package/lib/server/chromium/crNetworkManager.js +269 -370
  110. package/lib/server/chromium/crPage.js +509 -595
  111. package/lib/server/chromium/crPdf.js +54 -86
  112. package/lib/server/chromium/crProtocolHelper.js +92 -80
  113. package/lib/server/chromium/crServiceWorker.js +85 -69
  114. package/lib/server/chromium/defaultFontFamilies.js +152 -135
  115. package/lib/server/chromium/protocol.d.js +16 -0
  116. package/lib/server/chromium/videoRecorder.js +65 -99
  117. package/lib/server/clock.js +58 -46
  118. package/lib/server/codegen/csharp.js +191 -156
  119. package/lib/server/codegen/java.js +163 -125
  120. package/lib/server/codegen/javascript.js +166 -143
  121. package/lib/server/codegen/jsonl.js +33 -29
  122. package/lib/server/codegen/language.js +75 -52
  123. package/lib/server/codegen/languages.js +65 -27
  124. package/lib/server/codegen/python.js +141 -125
  125. package/lib/server/codegen/types.js +15 -4
  126. package/lib/server/console.js +28 -32
  127. package/lib/server/cookieStore.js +105 -86
  128. package/lib/server/debugController.js +102 -154
  129. package/lib/server/debugger.js +82 -78
  130. package/lib/server/deviceDescriptors.js +37 -24
  131. package/lib/server/deviceDescriptorsSource.json +131 -131
  132. package/lib/server/dialog.js +36 -35
  133. package/lib/server/dispatchers/androidDispatcher.js +196 -107
  134. package/lib/server/dispatchers/artifactDispatcher.js +62 -62
  135. package/lib/server/dispatchers/browserContextDispatcher.js +177 -217
  136. package/lib/server/dispatchers/browserDispatcher.js +78 -97
  137. package/lib/server/dispatchers/browserTypeDispatcher.js +35 -35
  138. package/lib/server/dispatchers/cdpSessionDispatcher.js +32 -36
  139. package/lib/server/dispatchers/debugControllerDispatcher.js +48 -64
  140. package/lib/server/dispatchers/dialogDispatcher.js +30 -27
  141. package/lib/server/dispatchers/dispatcher.js +180 -229
  142. package/lib/server/dispatchers/electronDispatcher.js +54 -57
  143. package/lib/server/dispatchers/elementHandlerDispatcher.js +79 -116
  144. package/lib/server/dispatchers/frameDispatcher.js +93 -162
  145. package/lib/server/dispatchers/jsHandleDispatcher.js +49 -66
  146. package/lib/server/dispatchers/jsonPipeDispatcher.js +35 -36
  147. package/lib/server/dispatchers/localUtilsDispatcher.js +107 -365
  148. package/lib/server/dispatchers/networkDispatchers.js +92 -109
  149. package/lib/server/dispatchers/pageDispatcher.js +130 -169
  150. package/lib/server/dispatchers/playwrightDispatcher.js +69 -76
  151. package/lib/server/dispatchers/selectorsDispatcher.js +28 -24
  152. package/lib/server/dispatchers/streamDispatcher.js +42 -44
  153. package/lib/server/dispatchers/tracingDispatcher.js +36 -41
  154. package/lib/server/dispatchers/webSocketRouteDispatcher.js +100 -135
  155. package/lib/server/dispatchers/writableStreamDispatcher.js +54 -39
  156. package/lib/server/dom.js +424 -443
  157. package/lib/server/download.js +45 -35
  158. package/lib/server/electron/electron.js +156 -175
  159. package/lib/server/electron/loader.js +8 -36
  160. package/lib/server/errors.js +47 -46
  161. package/lib/server/fetch.js +302 -331
  162. package/lib/server/fileChooser.js +25 -24
  163. package/lib/server/fileUploadUtils.js +66 -57
  164. package/lib/server/firefox/ffAccessibility.js +153 -131
  165. package/lib/server/firefox/ffBrowser.js +218 -274
  166. package/lib/server/firefox/ffConnection.js +63 -84
  167. package/lib/server/firefox/ffExecutionContext.js +103 -77
  168. package/lib/server/firefox/ffInput.js +72 -63
  169. package/lib/server/firefox/ffNetworkManager.js +131 -110
  170. package/lib/server/firefox/ffPage.js +244 -302
  171. package/lib/server/firefox/firefox.js +76 -69
  172. package/lib/server/firefox/protocol.d.js +16 -0
  173. package/lib/server/formData.js +107 -35
  174. package/lib/server/frameSelectors.js +77 -111
  175. package/lib/server/frames.js +719 -855
  176. package/lib/server/har/harRecorder.js +85 -77
  177. package/lib/server/har/harTracer.js +288 -224
  178. package/lib/server/harBackend.js +157 -0
  179. package/lib/server/helper.js +56 -59
  180. package/lib/server/index.js +59 -106
  181. package/lib/server/input.js +136 -166
  182. package/lib/server/instrumentation.js +49 -44
  183. package/lib/server/javascript.js +157 -151
  184. package/lib/server/launchApp.js +92 -73
  185. package/lib/server/localUtils.js +211 -0
  186. package/lib/server/macEditingCommands.js +141 -137
  187. package/lib/server/network.js +263 -297
  188. package/lib/server/page.js +353 -432
  189. package/lib/server/pageBinding.js +88 -0
  190. package/lib/server/pipeTransport.js +49 -45
  191. package/lib/server/playwright.js +60 -67
  192. package/lib/server/progress.js +56 -51
  193. package/lib/server/protocolError.js +34 -31
  194. package/lib/server/recorder/chat.js +161 -0
  195. package/lib/server/recorder/contextRecorder.js +135 -148
  196. package/lib/server/recorder/recorderApp.js +129 -132
  197. package/lib/server/recorder/recorderCollection.js +57 -57
  198. package/lib/server/recorder/recorderFrontend.js +15 -4
  199. package/lib/server/recorder/recorderRunner.js +80 -100
  200. package/lib/server/recorder/recorderUtils.js +59 -72
  201. package/lib/server/recorder/throttledFile.js +42 -31
  202. package/lib/server/recorder.js +186 -190
  203. package/lib/server/registry/browserFetcher.js +107 -100
  204. package/lib/server/registry/dependencies.js +247 -198
  205. package/lib/server/registry/index.js +928 -709
  206. package/lib/server/registry/nativeDeps.js +1073 -461
  207. package/lib/server/registry/oopDownloadBrowserMain.js +57 -75
  208. package/lib/server/screenshotter.js +166 -182
  209. package/lib/server/selectors.js +85 -46
  210. package/lib/server/socksClientCertificatesInterceptor.js +166 -185
  211. package/lib/server/socksInterceptor.js +62 -67
  212. package/lib/server/storageScript.js +154 -0
  213. package/lib/server/timeoutSettings.js +89 -0
  214. package/lib/server/trace/recorder/snapshotter.js +70 -88
  215. package/lib/server/trace/recorder/snapshotterInjected.js +246 -218
  216. package/lib/server/trace/recorder/tracing.js +324 -327
  217. package/lib/server/trace/test/inMemorySnapshotter.js +46 -52
  218. package/lib/server/trace/viewer/traceViewer.js +172 -137
  219. package/lib/server/transport.js +125 -133
  220. package/lib/server/types.js +26 -22
  221. package/lib/server/usKeyboardLayout.js +135 -545
  222. package/lib/server/utils/ascii.js +44 -0
  223. package/lib/server/utils/comparators.js +161 -0
  224. package/lib/server/utils/crypto.js +216 -0
  225. package/lib/server/utils/debug.js +47 -0
  226. package/lib/server/utils/debugLogger.js +114 -0
  227. package/lib/server/utils/env.js +68 -0
  228. package/lib/server/utils/eventsHelper.js +39 -0
  229. package/lib/server/utils/expectUtils.js +38 -0
  230. package/lib/server/utils/fileUtils.js +191 -0
  231. package/lib/server/utils/happyEyeballs.js +207 -0
  232. package/lib/server/utils/hostPlatform.js +109 -0
  233. package/lib/server/utils/httpServer.js +218 -0
  234. package/lib/server/utils/image_tools/colorUtils.js +89 -0
  235. package/lib/{image_tools → server/utils/image_tools}/compare.js +44 -43
  236. package/lib/server/utils/image_tools/imageChannel.js +78 -0
  237. package/lib/{image_tools → server/utils/image_tools}/stats.js +40 -40
  238. package/lib/server/utils/linuxUtils.js +71 -0
  239. package/lib/server/utils/network.js +217 -0
  240. package/lib/server/utils/nodePlatform.js +148 -0
  241. package/lib/server/utils/pipeTransport.js +84 -0
  242. package/lib/server/utils/processLauncher.js +238 -0
  243. package/lib/server/utils/profiler.js +65 -0
  244. package/lib/server/utils/socksProxy.js +511 -0
  245. package/lib/server/utils/spawnAsync.js +41 -0
  246. package/lib/server/utils/task.js +51 -0
  247. package/lib/server/utils/userAgent.js +98 -0
  248. package/lib/server/utils/wsServer.js +132 -0
  249. package/lib/server/utils/zipFile.js +74 -0
  250. package/lib/server/utils/zones.js +57 -0
  251. package/lib/server/webkit/protocol.d.js +16 -0
  252. package/lib/server/webkit/webkit.js +76 -63
  253. package/lib/server/webkit/wkAccessibility.js +161 -118
  254. package/lib/server/webkit/wkBrowser.js +163 -180
  255. package/lib/server/webkit/wkConnection.js +59 -83
  256. package/lib/server/webkit/wkExecutionContext.js +96 -73
  257. package/lib/server/webkit/wkInput.js +87 -75
  258. package/lib/server/webkit/wkInterceptableRequest.js +102 -95
  259. package/lib/server/webkit/wkPage.js +536 -645
  260. package/lib/server/webkit/wkProvisionalPage.js +45 -56
  261. package/lib/server/webkit/wkWorkers.js +77 -77
  262. package/lib/utils/isomorphic/ariaSnapshot.js +245 -128
  263. package/lib/utils/isomorphic/assert.js +31 -0
  264. package/lib/utils/isomorphic/builtins.js +90 -0
  265. package/lib/utils/isomorphic/colors.js +72 -0
  266. package/lib/utils/isomorphic/cssParser.js +123 -127
  267. package/lib/utils/isomorphic/cssTokenizer.js +436 -364
  268. package/lib/utils/isomorphic/headers.js +53 -0
  269. package/lib/utils/isomorphic/locatorGenerators.js +344 -349
  270. package/lib/utils/isomorphic/locatorParser.js +103 -106
  271. package/lib/utils/isomorphic/locatorUtils.js +63 -44
  272. package/lib/utils/isomorphic/manualPromise.js +115 -0
  273. package/lib/utils/isomorphic/mimeType.js +453 -22
  274. package/lib/utils/isomorphic/multimap.js +81 -0
  275. package/lib/utils/isomorphic/rtti.js +43 -0
  276. package/lib/utils/isomorphic/selectorParser.js +183 -193
  277. package/lib/utils/isomorphic/semaphore.js +54 -0
  278. package/lib/utils/isomorphic/stackTrace.js +158 -0
  279. package/lib/utils/isomorphic/stringUtils.js +113 -106
  280. package/lib/utils/isomorphic/time.js +44 -0
  281. package/lib/utils/isomorphic/timeoutRunner.js +67 -0
  282. package/lib/utils/isomorphic/traceUtils.js +52 -32
  283. package/lib/utils/isomorphic/types.js +16 -0
  284. package/lib/utils/isomorphic/urlMatch.js +114 -71
  285. package/lib/utils/isomorphic/utilityScriptSerializers.js +248 -0
  286. package/lib/utils.js +101 -0
  287. package/lib/utilsBundle.js +101 -76
  288. package/lib/utilsBundleImpl/index.js +114 -116
  289. package/lib/vite/htmlReport/index.html +26 -20
  290. package/lib/vite/recorder/assets/codeMirrorModule-DVQi6prl.js +24 -0
  291. package/lib/vite/recorder/assets/index-97EUAAbk.js +184 -0
  292. package/lib/vite/recorder/assets/{index-iA1aAGZg.css → index-eHBmevrY.css} +1 -1
  293. package/lib/vite/recorder/index.html +2 -2
  294. package/lib/vite/traceViewer/assets/codeMirrorModule-DwAiTpyC.js +24 -0
  295. package/lib/vite/traceViewer/assets/defaultSettingsView-DkkRvn5X.js +265 -0
  296. package/lib/vite/traceViewer/assets/{xtermModule-BeNbaIVa.js → xtermModule-BoAIEibi.js} +7 -7
  297. package/lib/vite/traceViewer/defaultSettingsView.QdHITyLI.css +1 -0
  298. package/lib/vite/traceViewer/index.DvtSwn6E.js +2 -0
  299. package/lib/vite/traceViewer/index.html +4 -7
  300. package/lib/vite/traceViewer/sw.bundle.js +3 -3
  301. package/lib/vite/traceViewer/{uiMode.voC1ZiOQ.css → uiMode.BatfzHMG.css} +1 -1
  302. package/lib/vite/traceViewer/uiMode.Sdytl9wc.js +5 -0
  303. package/lib/vite/traceViewer/uiMode.html +4 -7
  304. package/lib/zipBundle.js +32 -23
  305. package/lib/zipBundleImpl.js +4 -4
  306. package/package.json +7 -7
  307. package/types/protocol.d.ts +819 -127
  308. package/types/types.d.ts +196 -75
  309. package/bin/PrintDeps.exe +0 -0
  310. package/bin/README.md +0 -2
  311. package/lib/common/socksProxy.js +0 -569
  312. package/lib/common/timeoutSettings.js +0 -73
  313. package/lib/common/types.js +0 -5
  314. package/lib/image_tools/colorUtils.js +0 -98
  315. package/lib/image_tools/imageChannel.js +0 -70
  316. package/lib/protocol/transport.js +0 -82
  317. package/lib/server/ariaSnapshot.js +0 -33
  318. package/lib/server/isomorphic/utilityScriptSerializers.js +0 -226
  319. package/lib/server/recorder/recorderInTraceViewer.js +0 -144
  320. package/lib/utils/ascii.js +0 -31
  321. package/lib/utils/comparators.js +0 -153
  322. package/lib/utils/crypto.js +0 -171
  323. package/lib/utils/debug.js +0 -46
  324. package/lib/utils/debugLogger.js +0 -91
  325. package/lib/utils/env.js +0 -49
  326. package/lib/utils/eventsHelper.js +0 -38
  327. package/lib/utils/expectUtils.js +0 -33
  328. package/lib/utils/fileUtils.js +0 -205
  329. package/lib/utils/happy-eyeballs.js +0 -194
  330. package/lib/utils/headers.js +0 -52
  331. package/lib/utils/hostPlatform.js +0 -139
  332. package/lib/utils/httpServer.js +0 -237
  333. package/lib/utils/index.js +0 -368
  334. package/lib/utils/isomorphic/recorderUtils.js +0 -227
  335. package/lib/utils/linuxUtils.js +0 -78
  336. package/lib/utils/manualPromise.js +0 -109
  337. package/lib/utils/multimap.js +0 -75
  338. package/lib/utils/network.js +0 -160
  339. package/lib/utils/processLauncher.js +0 -248
  340. package/lib/utils/profiler.js +0 -53
  341. package/lib/utils/rtti.js +0 -44
  342. package/lib/utils/semaphore.js +0 -51
  343. package/lib/utils/sequence.js +0 -64
  344. package/lib/utils/spawnAsync.js +0 -45
  345. package/lib/utils/stackTrace.js +0 -134
  346. package/lib/utils/task.js +0 -58
  347. package/lib/utils/time.js +0 -37
  348. package/lib/utils/timeoutRunner.js +0 -66
  349. package/lib/utils/traceUtils.js +0 -44
  350. package/lib/utils/userAgent.js +0 -105
  351. package/lib/utils/wsServer.js +0 -127
  352. package/lib/utils/zipFile.js +0 -75
  353. package/lib/utils/zones.js +0 -71
  354. package/lib/vite/recorder/assets/codeMirrorModule-AFvV6hAs.js +0 -24
  355. package/lib/vite/recorder/assets/index-_cTWgVuJ.js +0 -184
  356. package/lib/vite/traceViewer/assets/codeMirrorModule-KatbITLF.js +0 -24
  357. package/lib/vite/traceViewer/assets/inspectorTab-DdpLd2bb.js +0 -68
  358. package/lib/vite/traceViewer/assets/testServerConnection-DeE2kSzz.js +0 -1
  359. package/lib/vite/traceViewer/assets/workbench-CdYbzWFD.js +0 -9
  360. package/lib/vite/traceViewer/embedded.6m3UZh7r.js +0 -2
  361. package/lib/vite/traceViewer/embedded.html +0 -18
  362. package/lib/vite/traceViewer/embedded.w7WN2u1R.css +0 -1
  363. package/lib/vite/traceViewer/index.WUV-8boJ.js +0 -2
  364. package/lib/vite/traceViewer/inspectorTab.DEOUW62d.css +0 -1
  365. package/lib/vite/traceViewer/recorder.B_SY1GJM.css +0 -0
  366. package/lib/vite/traceViewer/recorder.OT2tVHgn.js +0 -2
  367. package/lib/vite/traceViewer/recorder.html +0 -17
  368. package/lib/vite/traceViewer/uiMode.BZBTyvGn.js +0 -5
  369. package/lib/vite/traceViewer/workbench.C-zR9ysA.css +0 -1
  370. /package/lib/vite/recorder/assets/{codeMirrorModule-ez37Vkbh.css → codeMirrorModule-C3UTv-Ge.css} +0 -0
  371. /package/lib/vite/traceViewer/{codeMirrorModule.ez37Vkbh.css → codeMirrorModule.C3UTv-Ge.css} +0 -0
  372. /package/lib/vite/traceViewer/{index.CrbWWHbf.css → index.CFOW-Ezb.css} +0 -0
  373. /package/lib/vite/traceViewer/{xtermModule.DSXBckUd.css → xtermModule.Beg8tuEN.css} +0 -0
@@ -1,88 +1,85 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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 page_exports = {};
30
+ __export(page_exports, {
31
+ InitScript: () => InitScript,
32
+ Page: () => Page,
33
+ PageBinding: () => PageBinding,
34
+ Worker: () => Worker,
35
+ kBuiltinsScript: () => kBuiltinsScript
5
36
  });
6
- exports.Worker = exports.PageBinding = exports.Page = exports.InitScript = void 0;
7
- var frames = _interopRequireWildcard(require("./frames"));
8
- var input = _interopRequireWildcard(require("./input"));
9
- var js = _interopRequireWildcard(require("./javascript"));
10
- var _screenshotter = require("./screenshotter");
11
- var _timeoutSettings = require("../common/timeoutSettings");
12
- var _browserContext = require("./browserContext");
13
- var _console = require("./console");
14
- var accessibility = _interopRequireWildcard(require("./accessibility"));
15
- var _fileChooser = require("./fileChooser");
16
- var _progress = require("./progress");
17
- var _utils = require("../utils");
18
- var _manualPromise = require("../utils/manualPromise");
19
- var _debugLogger = require("../utils/debugLogger");
20
- var _comparators = require("../utils/comparators");
21
- var _instrumentation = require("./instrumentation");
22
- var _selectorParser = require("../utils/isomorphic/selectorParser");
23
- var _utilityScriptSerializers = require("./isomorphic/utilityScriptSerializers");
24
- var _errors = require("./errors");
25
- var _helper = require("./helper");
26
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
27
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
28
- /**
29
- * Copyright 2017 Google Inc. All rights reserved.
30
- * Modifications copyright (c) Microsoft Corporation.
31
- *
32
- * Licensed under the Apache License, Version 2.0 (the "License");
33
- * you may not use this file except in compliance with the License.
34
- * You may obtain a copy of the License at
35
- *
36
- * http://www.apache.org/licenses/LICENSE-2.0
37
- *
38
- * Unless required by applicable law or agreed to in writing, software
39
- * distributed under the License is distributed on an "AS IS" BASIS,
40
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
41
- * See the License for the specific language governing permissions and
42
- * limitations under the License.
43
- */
44
-
45
- class Page extends _instrumentation.SdkObject {
37
+ module.exports = __toCommonJS(page_exports);
38
+ var accessibility = __toESM(require("./accessibility"));
39
+ var import_browserContext = require("./browserContext");
40
+ var import_console = require("./console");
41
+ var import_errors = require("./errors");
42
+ var import_fileChooser = require("./fileChooser");
43
+ var frames = __toESM(require("./frames"));
44
+ var import_helper = require("./helper");
45
+ var input = __toESM(require("./input"));
46
+ var import_instrumentation = require("./instrumentation");
47
+ var import_builtins = require("../utils/isomorphic/builtins");
48
+ var import_pageBinding = require("./pageBinding");
49
+ var js = __toESM(require("./javascript"));
50
+ var import_progress = require("./progress");
51
+ var import_screenshotter = require("./screenshotter");
52
+ var import_timeoutSettings = require("./timeoutSettings");
53
+ var import_utils = require("../utils");
54
+ var import_crypto = require("./utils/crypto");
55
+ var import_utils2 = require("../utils");
56
+ var import_comparators = require("./utils/comparators");
57
+ var import_debugLogger = require("./utils/debugLogger");
58
+ var import_selectorParser = require("../utils/isomorphic/selectorParser");
59
+ var import_manualPromise = require("../utils/isomorphic/manualPromise");
60
+ var import_callLog = require("./callLog");
61
+ class Page extends import_instrumentation.SdkObject {
46
62
  constructor(delegate, browserContext) {
47
- super(browserContext, 'page');
48
- this._closedState = 'open';
49
- this._closedPromise = new _manualPromise.ManualPromise();
50
- this._initialized = false;
63
+ super(browserContext, "page");
64
+ this._closedState = "open";
65
+ this._closedPromise = new import_manualPromise.ManualPromise();
66
+ this._initializedPromise = new import_manualPromise.ManualPromise();
51
67
  this._eventsToEmitAfterInitialized = [];
52
68
  this._crashed = false;
53
- this.openScope = new _utils.LongStandingScope();
54
- this._browserContext = void 0;
55
- this.keyboard = void 0;
56
- this.mouse = void 0;
57
- this.touchscreen = void 0;
58
- this._timeoutSettings = void 0;
59
- this._delegate = void 0;
60
- this._emulatedSize = void 0;
61
- this._extraHTTPHeaders = void 0;
69
+ this.openScope = new import_utils.LongStandingScope();
62
70
  this._emulatedMedia = {};
63
71
  this._interceptFileChooser = false;
64
- this._pageBindings = new Map();
72
+ this._pageBindings = /* @__PURE__ */ new Map();
65
73
  this.initScripts = [];
66
- this._screenshotter = void 0;
67
- this._frameManager = void 0;
68
- this.accessibility = void 0;
69
- this._workers = new Map();
70
- this.pdf = void 0;
71
- this.coverage = void 0;
72
- this._clientRequestInterceptor = void 0;
73
- this._serverRequestInterceptor = void 0;
74
- this._ownedContext = void 0;
75
- this._pageIsError = void 0;
74
+ this._workers = /* @__PURE__ */ new Map();
76
75
  this._video = null;
77
- this._opener = void 0;
78
76
  this._isServerSideOnly = false;
79
- this._locatorHandlers = new Map();
77
+ this._locatorHandlers = /* @__PURE__ */ new Map();
80
78
  this._lastLocatorHandlerUid = 0;
81
79
  this._locatorHandlerRunningCounter = 0;
82
80
  // Aiming at 25 fps by default - each frame is 40ms, but we give some slack with 35ms.
83
81
  // When throttling for tracing, 200ms between frames, except for 10 frames around the action.
84
82
  this._frameThrottler = new FrameThrottler(10, 35, 200);
85
- this._closeReason = void 0;
86
83
  this.attribution.page = this;
87
84
  this._delegate = delegate;
88
85
  this._browserContext = browserContext;
@@ -90,82 +87,103 @@ class Page extends _instrumentation.SdkObject {
90
87
  this.keyboard = new input.Keyboard(delegate.rawKeyboard);
91
88
  this.mouse = new input.Mouse(delegate.rawMouse, this);
92
89
  this.touchscreen = new input.Touchscreen(delegate.rawTouchscreen, this);
93
- this._timeoutSettings = new _timeoutSettings.TimeoutSettings(browserContext._timeoutSettings);
94
- this._screenshotter = new _screenshotter.Screenshotter(this);
90
+ this._timeoutSettings = new import_timeoutSettings.TimeoutSettings(browserContext._timeoutSettings);
91
+ this._screenshotter = new import_screenshotter.Screenshotter(this);
95
92
  this._frameManager = new frames.FrameManager(this);
96
- if (delegate.pdf) this.pdf = delegate.pdf.bind(delegate);
93
+ if (delegate.pdf)
94
+ this.pdf = delegate.pdf.bind(delegate);
97
95
  this.coverage = delegate.coverage ? delegate.coverage() : null;
98
96
  }
99
- async initOpener(opener) {
100
- if (!opener) return;
101
- const openerPage = await opener.pageOrError();
102
- if (openerPage instanceof Page && !openerPage.isClosed()) this._opener = openerPage;
97
+ static {
98
+ this.Events = {
99
+ Close: "close",
100
+ Crash: "crash",
101
+ Download: "download",
102
+ FileChooser: "filechooser",
103
+ FrameAttached: "frameattached",
104
+ FrameDetached: "framedetached",
105
+ InternalFrameNavigatedToNewDocument: "internalframenavigatedtonewdocument",
106
+ LocatorHandlerTriggered: "locatorhandlertriggered",
107
+ ScreencastFrame: "screencastframe",
108
+ Video: "video",
109
+ WebSocket: "websocket",
110
+ Worker: "worker"
111
+ };
112
+ }
113
+ async reportAsNew(opener, error = void 0, contextEvent = import_browserContext.BrowserContext.Events.Page) {
114
+ if (opener) {
115
+ const openerPageOrError = await opener.waitForInitializedOrError();
116
+ if (openerPageOrError instanceof Page && !openerPageOrError.isClosed())
117
+ this._opener = openerPageOrError;
118
+ }
119
+ this._markInitialized(error, contextEvent);
103
120
  }
104
- reportAsNew(error = undefined, contextEvent = _browserContext.BrowserContext.Events.Page) {
121
+ _markInitialized(error = void 0, contextEvent = import_browserContext.BrowserContext.Events.Page) {
105
122
  if (error) {
106
- // Initialization error could have happened because of
107
- // context/browser closure. Just ignore the page.
108
- if (this._browserContext.isClosingOrClosed()) return;
109
- this._setIsError(error);
123
+ if (this._browserContext.isClosingOrClosed())
124
+ return;
125
+ this._frameManager.createDummyMainFrameIfNeeded();
110
126
  }
111
- this._initialized = true;
127
+ this._initialized = error || this;
112
128
  this.emitOnContext(contextEvent, this);
113
- for (const {
114
- event,
115
- args
116
- } of this._eventsToEmitAfterInitialized) this._browserContext.emit(event, ...args);
129
+ for (const { event, args } of this._eventsToEmitAfterInitialized)
130
+ this._browserContext.emit(event, ...args);
117
131
  this._eventsToEmitAfterInitialized = [];
118
-
119
- // It may happen that page initialization finishes after Close event has already been sent,
120
- // in that case we fire another Close event to ensure that each reported Page will have
121
- // corresponding Close event after it is reported on the context.
122
- if (this.isClosed()) this.emit(Page.Events.Close);else this.instrumentation.onPageOpen(this);
132
+ if (this.isClosed())
133
+ this.emit(Page.Events.Close);
134
+ else
135
+ this.instrumentation.onPageOpen(this);
136
+ this._initializedPromise.resolve(this._initialized);
123
137
  }
124
138
  initializedOrUndefined() {
125
- return this._initialized ? this : undefined;
139
+ return this._initialized ? this : void 0;
140
+ }
141
+ waitForInitializedOrError() {
142
+ return this._initializedPromise;
126
143
  }
127
144
  emitOnContext(event, ...args) {
128
- if (this._isServerSideOnly) return;
145
+ if (this._isServerSideOnly)
146
+ return;
129
147
  this._browserContext.emit(event, ...args);
130
148
  }
131
149
  emitOnContextOnceInitialized(event, ...args) {
132
- if (this._isServerSideOnly) return;
133
- // Some events, like console messages, may come before page is ready.
134
- // In this case, postpone the event until page is initialized,
135
- // and dispatch it to the client later, either on the live Page,
136
- // or on the "errored" Page.
137
- if (this._initialized) this._browserContext.emit(event, ...args);else this._eventsToEmitAfterInitialized.push({
138
- event,
139
- args
140
- });
150
+ if (this._isServerSideOnly)
151
+ return;
152
+ if (this._initialized)
153
+ this._browserContext.emit(event, ...args);
154
+ else
155
+ this._eventsToEmitAfterInitialized.push({ event, args });
141
156
  }
142
157
  async resetForReuse(metadata) {
143
- this.setDefaultNavigationTimeout(undefined);
144
- this.setDefaultTimeout(undefined);
158
+ this.setDefaultNavigationTimeout(void 0);
159
+ this.setDefaultTimeout(void 0);
145
160
  this._locatorHandlers.clear();
146
161
  await this._removeExposedBindings();
147
162
  await this._removeInitScripts();
148
- await this.setClientRequestInterceptor(undefined);
149
- await this._setServerRequestInterceptor(undefined);
163
+ await this.setClientRequestInterceptor(void 0);
164
+ await this._setServerRequestInterceptor(void 0);
150
165
  await this.setFileChooserIntercepted(false);
151
- // Re-navigate once init scripts are gone.
152
- await this.mainFrame().goto(metadata, 'about:blank');
153
- this._emulatedSize = undefined;
166
+ await this.mainFrame().goto(metadata, "about:blank");
167
+ this._emulatedSize = void 0;
154
168
  this._emulatedMedia = {};
155
- this._extraHTTPHeaders = undefined;
169
+ this._extraHTTPHeaders = void 0;
156
170
  this._interceptFileChooser = false;
157
- await Promise.all([this._delegate.updateEmulatedViewportSize(), this._delegate.updateEmulateMedia(), this._delegate.updateFileChooserInterception()]);
171
+ await Promise.all([
172
+ this._delegate.updateEmulatedViewportSize(),
173
+ this._delegate.updateEmulateMedia(),
174
+ this._delegate.updateFileChooserInterception()
175
+ ]);
158
176
  await this._delegate.resetForReuse();
159
177
  }
160
178
  _didClose() {
161
179
  this._frameManager.dispose();
162
180
  this._frameThrottler.dispose();
163
- (0, _utils.assert)(this._closedState !== 'closed', 'Page closed twice');
164
- this._closedState = 'closed';
181
+ (0, import_utils.assert)(this._closedState !== "closed", "Page closed twice");
182
+ this._closedState = "closed";
165
183
  this.emit(Page.Events.Close);
166
184
  this._closedPromise.resolve();
167
185
  this.instrumentation.onPageClose(this);
168
- this.openScope.close(new _errors.TargetClosedError());
186
+ this.openScope.close(new import_errors.TargetClosedError());
169
187
  }
170
188
  _didCrash() {
171
189
  this._frameManager.dispose();
@@ -173,21 +191,20 @@ class Page extends _instrumentation.SdkObject {
173
191
  this.emit(Page.Events.Crash);
174
192
  this._crashed = true;
175
193
  this.instrumentation.onPageClose(this);
176
- this.openScope.close(new Error('Page crashed'));
194
+ this.openScope.close(new Error("Page crashed"));
177
195
  }
178
196
  async _onFileChooserOpened(handle) {
179
197
  let multiple;
180
198
  try {
181
- multiple = await handle.evaluate(element => !!element.multiple);
199
+ multiple = await handle.evaluate((element) => !!element.multiple);
182
200
  } catch (e) {
183
- // Frame/context may be gone during async processing. Do not throw.
184
201
  return;
185
202
  }
186
203
  if (!this.listenerCount(Page.Events.FileChooser)) {
187
204
  handle.dispose();
188
205
  return;
189
206
  }
190
- const fileChooser = new _fileChooser.FileChooser(this, handle, multiple);
207
+ const fileChooser = new import_fileChooser.FileChooser(this, handle, multiple);
191
208
  this.emit(Page.Events.FileChooser, fileChooser);
192
209
  }
193
210
  context() {
@@ -209,16 +226,20 @@ class Page extends _instrumentation.SdkObject {
209
226
  this._timeoutSettings.setDefaultTimeout(timeout);
210
227
  }
211
228
  async exposeBinding(name, needsHandle, playwrightBinding) {
212
- if (this._pageBindings.has(name)) throw new Error(`Function "${name}" has been already registered`);
213
- if (this._browserContext._pageBindings.has(name)) throw new Error(`Function "${name}" has been already registered in the browser context`);
229
+ if (this._pageBindings.has(name))
230
+ throw new Error(`Function "${name}" has been already registered`);
231
+ if (this._browserContext._pageBindings.has(name))
232
+ throw new Error(`Function "${name}" has been already registered in the browser context`);
214
233
  const binding = new PageBinding(name, playwrightBinding, needsHandle);
215
234
  this._pageBindings.set(name, binding);
216
235
  await this._delegate.addInitScript(binding.initScript);
217
- await Promise.all(this.frames().map(frame => frame.evaluateExpression(binding.initScript.source).catch(e => {})));
236
+ await Promise.all(this.frames().map((frame) => frame.evaluateExpression(binding.initScript.source).catch((e) => {
237
+ })));
218
238
  }
219
239
  async _removeExposedBindings() {
220
240
  for (const [key, binding] of this._pageBindings) {
221
- if (!binding.internal) this._pageBindings.delete(key);
241
+ if (!binding.internal)
242
+ this._pageBindings.delete(key);
222
243
  }
223
244
  }
224
245
  setExtraHTTPHeaders(headers) {
@@ -229,60 +250,61 @@ class Page extends _instrumentation.SdkObject {
229
250
  return this._extraHTTPHeaders;
230
251
  }
231
252
  async _onBindingCalled(payload, context) {
232
- if (this._closedState === 'closed') return;
253
+ if (this._closedState === "closed")
254
+ return;
233
255
  await PageBinding.dispatch(this, payload, context);
234
256
  }
235
257
  _addConsoleMessage(type, args, location, text) {
236
- const message = new _console.ConsoleMessage(this, type, text, args, location);
258
+ const message = new import_console.ConsoleMessage(this, type, text, args, location);
237
259
  const intercepted = this._frameManager.interceptConsoleMessage(message);
238
260
  if (intercepted) {
239
- args.forEach(arg => arg.dispose());
261
+ args.forEach((arg) => arg.dispose());
240
262
  return;
241
263
  }
242
- this.emitOnContextOnceInitialized(_browserContext.BrowserContext.Events.Console, message);
264
+ this.emitOnContextOnceInitialized(import_browserContext.BrowserContext.Events.Console, message);
243
265
  }
244
266
  async reload(metadata, options) {
245
- const controller = new _progress.ProgressController(metadata, this);
246
- return controller.run(progress => this.mainFrame().raceNavigationAction(progress, options, async () => {
247
- // Note: waitForNavigation may fail before we get response to reload(),
248
- // so we should await it immediately.
267
+ const controller = new import_progress.ProgressController(metadata, this);
268
+ return controller.run((progress) => this.mainFrame().raceNavigationAction(progress, options, async () => {
249
269
  const [response] = await Promise.all([
250
- // Reload must be a new document, and should not be confused with a stray pushState.
251
- this.mainFrame()._waitForNavigation(progress, true /* requiresNewDocument */, options), this._delegate.reload()]);
270
+ // Reload must be a new document, and should not be confused with a stray pushState.
271
+ this.mainFrame()._waitForNavigation(progress, true, options),
272
+ this._delegate.reload()
273
+ ]);
252
274
  return response;
253
275
  }), this._timeoutSettings.navigationTimeout(options));
254
276
  }
255
277
  async goBack(metadata, options) {
256
- const controller = new _progress.ProgressController(metadata, this);
257
- return controller.run(progress => this.mainFrame().raceNavigationAction(progress, options, async () => {
258
- // Note: waitForNavigation may fail before we get response to goBack,
259
- // so we should catch it immediately.
278
+ const controller = new import_progress.ProgressController(metadata, this);
279
+ return controller.run((progress) => this.mainFrame().raceNavigationAction(progress, options, async () => {
260
280
  let error;
261
- const waitPromise = this.mainFrame()._waitForNavigation(progress, false /* requiresNewDocument */, options).catch(e => {
281
+ const waitPromise = this.mainFrame()._waitForNavigation(progress, false, options).catch((e) => {
262
282
  error = e;
263
283
  return null;
264
284
  });
265
285
  const result = await this._delegate.goBack();
266
- if (!result) return null;
286
+ if (!result)
287
+ return null;
267
288
  const response = await waitPromise;
268
- if (error) throw error;
289
+ if (error)
290
+ throw error;
269
291
  return response;
270
292
  }), this._timeoutSettings.navigationTimeout(options));
271
293
  }
272
294
  async goForward(metadata, options) {
273
- const controller = new _progress.ProgressController(metadata, this);
274
- return controller.run(progress => this.mainFrame().raceNavigationAction(progress, options, async () => {
275
- // Note: waitForNavigation may fail before we get response to goForward,
276
- // so we should catch it immediately.
295
+ const controller = new import_progress.ProgressController(metadata, this);
296
+ return controller.run((progress) => this.mainFrame().raceNavigationAction(progress, options, async () => {
277
297
  let error;
278
- const waitPromise = this.mainFrame()._waitForNavigation(progress, false /* requiresNewDocument */, options).catch(e => {
298
+ const waitPromise = this.mainFrame()._waitForNavigation(progress, false, options).catch((e) => {
279
299
  error = e;
280
300
  return null;
281
301
  });
282
302
  const result = await this._delegate.goForward();
283
- if (!result) return null;
303
+ if (!result)
304
+ return null;
284
305
  const response = await waitPromise;
285
- if (error) throw error;
306
+ if (error)
307
+ throw error;
286
308
  return response;
287
309
  }), this._timeoutSettings.navigationTimeout(options));
288
310
  }
@@ -291,19 +313,16 @@ class Page extends _instrumentation.SdkObject {
291
313
  }
292
314
  registerLocatorHandler(selector, noWaitAfter) {
293
315
  const uid = ++this._lastLocatorHandlerUid;
294
- this._locatorHandlers.set(uid, {
295
- selector,
296
- noWaitAfter
297
- });
316
+ this._locatorHandlers.set(uid, { selector, noWaitAfter });
298
317
  return uid;
299
318
  }
300
319
  resolveLocatorHandler(uid, remove) {
301
320
  const handler = this._locatorHandlers.get(uid);
302
- if (remove) this._locatorHandlers.delete(uid);
321
+ if (remove)
322
+ this._locatorHandlers.delete(uid);
303
323
  if (handler) {
304
- var _handler$resolved;
305
- (_handler$resolved = handler.resolved) === null || _handler$resolved === void 0 || _handler$resolved.resolve();
306
- handler.resolved = undefined;
324
+ handler.resolved?.resolve();
325
+ handler.resolved = void 0;
307
326
  }
308
327
  }
309
328
  unregisterLocatorHandler(uid) {
@@ -314,106 +333,99 @@ class Page extends _instrumentation.SdkObject {
314
333
  progress.throwIfAborted();
315
334
  await this._performLocatorHandlersCheckpoint(progress);
316
335
  progress.throwIfAborted();
317
- // Wait once again, just in case a locator handler caused a navigation.
318
336
  await this._performWaitForNavigationCheck(progress);
319
337
  }
320
338
  async _performWaitForNavigationCheck(progress) {
321
- var _mainFrame$pendingDoc;
322
- if (process.env.PLAYWRIGHT_SKIP_NAVIGATION_CHECK) return;
339
+ if (process.env.PLAYWRIGHT_SKIP_NAVIGATION_CHECK)
340
+ return;
323
341
  const mainFrame = this._frameManager.mainFrame();
324
- if (!mainFrame || !mainFrame.pendingDocument()) return;
325
- const url = (_mainFrame$pendingDoc = mainFrame.pendingDocument()) === null || _mainFrame$pendingDoc === void 0 || (_mainFrame$pendingDoc = _mainFrame$pendingDoc.request) === null || _mainFrame$pendingDoc === void 0 ? void 0 : _mainFrame$pendingDoc.url();
326
- const toUrl = url ? `" ${(0, _utils.trimStringWithEllipsis)(url, 200)}"` : '';
342
+ if (!mainFrame || !mainFrame.pendingDocument())
343
+ return;
344
+ const url = mainFrame.pendingDocument()?.request?.url();
345
+ const toUrl = url ? `" ${(0, import_utils.trimStringWithEllipsis)(url, 200)}"` : "";
327
346
  progress.log(` waiting for${toUrl} navigation to finish...`);
328
- await _helper.helper.waitForEvent(progress, mainFrame, frames.Frame.Events.InternalNavigation, e => {
329
- if (!e.isPublic) return false;
330
- if (!e.error) progress.log(` navigated to "${(0, _utils.trimStringWithEllipsis)(mainFrame.url(), 200)}"`);
347
+ await import_helper.helper.waitForEvent(progress, mainFrame, frames.Frame.Events.InternalNavigation, (e) => {
348
+ if (!e.isPublic)
349
+ return false;
350
+ if (!e.error)
351
+ progress.log(` navigated to "${(0, import_utils.trimStringWithEllipsis)(mainFrame.url(), 200)}"`);
331
352
  return true;
332
353
  }).promise;
333
354
  }
334
355
  async _performLocatorHandlersCheckpoint(progress) {
335
- // Do not run locator handlers from inside locator handler callbacks to avoid deadlocks.
336
- if (this._locatorHandlerRunningCounter) return;
356
+ if (this._locatorHandlerRunningCounter)
357
+ return;
337
358
  for (const [uid, handler] of this._locatorHandlers) {
338
359
  if (!handler.resolved) {
339
- if (await this.mainFrame().isVisibleInternal(handler.selector, {
340
- strict: true
341
- })) {
342
- handler.resolved = new _manualPromise.ManualPromise();
360
+ if (await this.mainFrame().isVisibleInternal(handler.selector, { strict: true })) {
361
+ handler.resolved = new import_manualPromise.ManualPromise();
343
362
  this.emit(Page.Events.LocatorHandlerTriggered, uid);
344
363
  }
345
364
  }
346
365
  if (handler.resolved) {
347
366
  ++this._locatorHandlerRunningCounter;
348
- progress.log(` found ${(0, _utils.asLocator)(this.attribution.playwright.options.sdkLanguage, handler.selector)}, intercepting action to run the handler`);
367
+ progress.log(` found ${(0, import_utils2.asLocator)(this.attribution.playwright.options.sdkLanguage, handler.selector)}, intercepting action to run the handler`);
349
368
  const promise = handler.resolved.then(async () => {
350
369
  progress.throwIfAborted();
351
370
  if (!handler.noWaitAfter) {
352
- progress.log(` locator handler has finished, waiting for ${(0, _utils.asLocator)(this.attribution.playwright.options.sdkLanguage, handler.selector)} to be hidden`);
353
- await this.mainFrame().waitForSelectorInternal(progress, handler.selector, false, {
354
- state: 'hidden'
355
- });
371
+ progress.log(` locator handler has finished, waiting for ${(0, import_utils2.asLocator)(this.attribution.playwright.options.sdkLanguage, handler.selector)} to be hidden`);
372
+ await this.mainFrame().waitForSelectorInternal(progress, handler.selector, false, { state: "hidden" });
356
373
  } else {
357
374
  progress.log(` locator handler has finished`);
358
375
  }
359
376
  });
360
377
  await this.openScope.race(promise).finally(() => --this._locatorHandlerRunningCounter);
361
- // Avoid side-effects after long-running operation.
362
378
  progress.throwIfAborted();
363
379
  progress.log(` interception handler has finished, continuing`);
364
380
  }
365
381
  }
366
382
  }
367
383
  async emulateMedia(options) {
368
- if (options.media !== undefined) this._emulatedMedia.media = options.media;
369
- if (options.colorScheme !== undefined) this._emulatedMedia.colorScheme = options.colorScheme;
370
- if (options.reducedMotion !== undefined) this._emulatedMedia.reducedMotion = options.reducedMotion;
371
- if (options.forcedColors !== undefined) this._emulatedMedia.forcedColors = options.forcedColors;
384
+ if (options.media !== void 0)
385
+ this._emulatedMedia.media = options.media;
386
+ if (options.colorScheme !== void 0)
387
+ this._emulatedMedia.colorScheme = options.colorScheme;
388
+ if (options.reducedMotion !== void 0)
389
+ this._emulatedMedia.reducedMotion = options.reducedMotion;
390
+ if (options.forcedColors !== void 0)
391
+ this._emulatedMedia.forcedColors = options.forcedColors;
392
+ if (options.contrast !== void 0)
393
+ this._emulatedMedia.contrast = options.contrast;
372
394
  await this._delegate.updateEmulateMedia();
373
395
  }
374
396
  emulatedMedia() {
375
- var _contextOptions$color, _contextOptions$reduc, _contextOptions$force;
376
397
  const contextOptions = this._browserContext._options;
377
398
  return {
378
- media: this._emulatedMedia.media || 'no-override',
379
- colorScheme: this._emulatedMedia.colorScheme !== undefined ? this._emulatedMedia.colorScheme : (_contextOptions$color = contextOptions.colorScheme) !== null && _contextOptions$color !== void 0 ? _contextOptions$color : 'light',
380
- reducedMotion: this._emulatedMedia.reducedMotion !== undefined ? this._emulatedMedia.reducedMotion : (_contextOptions$reduc = contextOptions.reducedMotion) !== null && _contextOptions$reduc !== void 0 ? _contextOptions$reduc : 'no-preference',
381
- forcedColors: this._emulatedMedia.forcedColors !== undefined ? this._emulatedMedia.forcedColors : (_contextOptions$force = contextOptions.forcedColors) !== null && _contextOptions$force !== void 0 ? _contextOptions$force : 'none'
399
+ media: this._emulatedMedia.media || "no-override",
400
+ colorScheme: this._emulatedMedia.colorScheme !== void 0 ? this._emulatedMedia.colorScheme : contextOptions.colorScheme ?? "light",
401
+ reducedMotion: this._emulatedMedia.reducedMotion !== void 0 ? this._emulatedMedia.reducedMotion : contextOptions.reducedMotion ?? "no-preference",
402
+ forcedColors: this._emulatedMedia.forcedColors !== void 0 ? this._emulatedMedia.forcedColors : contextOptions.forcedColors ?? "none",
403
+ contrast: this._emulatedMedia.contrast !== void 0 ? this._emulatedMedia.contrast : contextOptions.contrast ?? "no-preference"
382
404
  };
383
405
  }
384
406
  async setViewportSize(viewportSize) {
385
- this._emulatedSize = {
386
- viewport: {
387
- ...viewportSize
388
- },
389
- screen: {
390
- ...viewportSize
391
- }
392
- };
407
+ this._emulatedSize = { viewport: { ...viewportSize }, screen: { ...viewportSize } };
393
408
  await this._delegate.updateEmulatedViewportSize();
394
409
  }
395
410
  viewportSize() {
396
- var _this$emulatedSize;
397
- return ((_this$emulatedSize = this.emulatedSize()) === null || _this$emulatedSize === void 0 ? void 0 : _this$emulatedSize.viewport) || null;
411
+ return this.emulatedSize()?.viewport || null;
398
412
  }
399
413
  emulatedSize() {
400
- if (this._emulatedSize) return this._emulatedSize;
414
+ if (this._emulatedSize)
415
+ return this._emulatedSize;
401
416
  const contextOptions = this._browserContext._options;
402
- return contextOptions.viewport ? {
403
- viewport: contextOptions.viewport,
404
- screen: contextOptions.screen || contextOptions.viewport
405
- } : null;
417
+ return contextOptions.viewport ? { viewport: contextOptions.viewport, screen: contextOptions.screen || contextOptions.viewport } : null;
406
418
  }
407
419
  async bringToFront() {
408
420
  await this._delegate.bringToFront();
409
421
  }
410
- async addInitScript(source) {
411
- const initScript = new InitScript(source);
422
+ async addInitScript(source, name) {
423
+ const initScript = new InitScript(source, false, name);
412
424
  this.initScripts.push(initScript);
413
425
  await this._delegate.addInitScript(initScript);
414
426
  }
415
427
  async _removeInitScripts() {
416
- this.initScripts = this.initScripts.filter(script => script.internal);
428
+ this.initScripts = this.initScripts.filter((script) => script.internal);
417
429
  await this._delegate.removeNonInternalInitScripts();
418
430
  }
419
431
  needsRequestInterception() {
@@ -436,114 +448,115 @@ class Page extends _instrumentation.SdkObject {
436
448
  await this.mainFrame().rafrafTimeout(timeout);
437
449
  return await this._screenshotter.screenshotPage(progress, options || {});
438
450
  };
439
- const comparator = (0, _comparators.getComparator)('image/png');
440
- const controller = new _progress.ProgressController(metadata, this);
441
- if (!options.expected && options.isNot) return {
442
- errorMessage: '"not" matcher requires expected result'
443
- };
451
+ const comparator = (0, import_comparators.getComparator)("image/png");
452
+ const controller = new import_progress.ProgressController(metadata, this);
453
+ if (!options.expected && options.isNot)
454
+ return { errorMessage: '"not" matcher requires expected result' };
444
455
  try {
445
- const format = (0, _screenshotter.validateScreenshotOptions)(options || {});
446
- if (format !== 'png') throw new Error('Only PNG screenshots are supported');
456
+ const format = (0, import_screenshotter.validateScreenshotOptions)(options || {});
457
+ if (format !== "png")
458
+ throw new Error("Only PNG screenshots are supported");
447
459
  } catch (error) {
448
- return {
449
- errorMessage: error.message
450
- };
460
+ return { errorMessage: error.message };
451
461
  }
452
- let intermediateResult = undefined;
462
+ let intermediateResult = void 0;
453
463
  const areEqualScreenshots = (actual, expected, previous) => {
454
- const comparatorResult = actual && expected ? comparator(actual, expected, options) : undefined;
455
- if (comparatorResult !== undefined && !!comparatorResult === !!options.isNot) return true;
456
- if (comparatorResult) intermediateResult = {
457
- errorMessage: comparatorResult.errorMessage,
458
- diff: comparatorResult.diff,
459
- actual,
460
- previous
461
- };
464
+ const comparatorResult = actual && expected ? comparator(actual, expected, options) : void 0;
465
+ if (comparatorResult !== void 0 && !!comparatorResult === !!options.isNot)
466
+ return true;
467
+ if (comparatorResult)
468
+ intermediateResult = { errorMessage: comparatorResult.errorMessage, diff: comparatorResult.diff, actual, previous };
462
469
  return false;
463
470
  };
464
471
  const callTimeout = this._timeoutSettings.timeout(options);
465
- return controller.run(async progress => {
472
+ return controller.run(async (progress) => {
466
473
  let actual;
467
474
  let previous;
468
475
  const pollIntervals = [0, 100, 250, 500];
469
- progress.log(`${metadata.apiName}${callTimeout ? ` with timeout ${callTimeout}ms` : ''}`);
470
- if (options.expected) progress.log(` verifying given screenshot expectation`);else progress.log(` generating new stable screenshot expectation`);
476
+ progress.log(`${metadata.apiName}${callTimeout ? ` with timeout ${callTimeout}ms` : ""}`);
477
+ if (options.expected)
478
+ progress.log(` verifying given screenshot expectation`);
479
+ else
480
+ progress.log(` generating new stable screenshot expectation`);
471
481
  let isFirstIteration = true;
472
482
  while (true) {
473
- var _pollIntervals$shift;
474
483
  progress.throwIfAborted();
475
- if (this.isClosed()) throw new Error('The page has closed');
476
- const screenshotTimeout = (_pollIntervals$shift = pollIntervals.shift()) !== null && _pollIntervals$shift !== void 0 ? _pollIntervals$shift : 1000;
477
- if (screenshotTimeout) progress.log(`waiting ${screenshotTimeout}ms before taking screenshot`);
484
+ if (this.isClosed())
485
+ throw new Error("The page has closed");
486
+ const screenshotTimeout = pollIntervals.shift() ?? 1e3;
487
+ if (screenshotTimeout)
488
+ progress.log(`waiting ${screenshotTimeout}ms before taking screenshot`);
478
489
  previous = actual;
479
- actual = await rafrafScreenshot(progress, screenshotTimeout).catch(e => {
490
+ actual = await rafrafScreenshot(progress, screenshotTimeout).catch((e) => {
480
491
  progress.log(`failed to take screenshot - ` + e.message);
481
- return undefined;
492
+ return void 0;
482
493
  });
483
- if (!actual) continue;
484
- // Compare against expectation for the first iteration.
494
+ if (!actual)
495
+ continue;
485
496
  const expectation = options.expected && isFirstIteration ? options.expected : previous;
486
- if (areEqualScreenshots(actual, expectation, previous)) break;
487
- if (intermediateResult) progress.log(intermediateResult.errorMessage);
497
+ if (areEqualScreenshots(actual, expectation, previous))
498
+ break;
499
+ if (intermediateResult)
500
+ progress.log(intermediateResult.errorMessage);
488
501
  isFirstIteration = false;
489
502
  }
490
- if (!isFirstIteration) progress.log(`captured a stable screenshot`);
491
- if (!options.expected) return {
492
- actual
493
- };
503
+ if (!isFirstIteration)
504
+ progress.log(`captured a stable screenshot`);
505
+ if (!options.expected)
506
+ return { actual };
494
507
  if (isFirstIteration) {
495
508
  progress.log(`screenshot matched expectation`);
496
509
  return {};
497
510
  }
498
- if (areEqualScreenshots(actual, options.expected, undefined)) {
511
+ if (areEqualScreenshots(actual, options.expected, void 0)) {
499
512
  progress.log(`screenshot matched expectation`);
500
513
  return {};
501
514
  }
502
515
  throw new Error(intermediateResult.errorMessage);
503
- }, callTimeout).catch(e => {
504
- var _intermediateResult;
505
- // Q: Why not throw upon isSessionClosedError(e) as in other places?
506
- // A: We want user to receive a friendly diff between actual and expected/previous.
507
- if (js.isJavaScriptErrorInEvaluate(e) || (0, _selectorParser.isInvalidSelectorError)(e)) throw e;
516
+ }, callTimeout).catch((e) => {
517
+ if (js.isJavaScriptErrorInEvaluate(e) || (0, import_selectorParser.isInvalidSelectorError)(e))
518
+ throw e;
508
519
  let errorMessage = e.message;
509
- if (e instanceof _errors.TimeoutError && (_intermediateResult = intermediateResult) !== null && _intermediateResult !== void 0 && _intermediateResult.previous) errorMessage = `Failed to take two consecutive stable screenshots.`;
520
+ if (e instanceof import_errors.TimeoutError && intermediateResult?.previous)
521
+ errorMessage = `Failed to take two consecutive stable screenshots.`;
510
522
  return {
511
- log: (0, _utils.compressCallLog)(e.message ? [...metadata.log, e.message] : metadata.log),
523
+ log: (0, import_callLog.compressCallLog)(e.message ? [...metadata.log, e.message] : metadata.log),
512
524
  ...intermediateResult,
513
525
  errorMessage,
514
- timedOut: e instanceof _errors.TimeoutError
526
+ timedOut: e instanceof import_errors.TimeoutError
515
527
  };
516
528
  });
517
529
  }
518
530
  async screenshot(metadata, options = {}) {
519
- const controller = new _progress.ProgressController(metadata, this);
520
- return controller.run(progress => this._screenshotter.screenshotPage(progress, options), this._timeoutSettings.timeout(options));
531
+ const controller = new import_progress.ProgressController(metadata, this);
532
+ return controller.run(
533
+ (progress) => this._screenshotter.screenshotPage(progress, options),
534
+ this._timeoutSettings.timeout(options)
535
+ );
521
536
  }
522
537
  async close(metadata, options = {}) {
523
- if (this._closedState === 'closed') return;
524
- if (options.reason) this._closeReason = options.reason;
538
+ if (this._closedState === "closed")
539
+ return;
540
+ if (options.reason)
541
+ this._closeReason = options.reason;
525
542
  const runBeforeUnload = !!options.runBeforeUnload;
526
- if (this._closedState !== 'closing') {
527
- this._closedState = 'closing';
528
- // This might throw if the browser context containing the page closes
529
- // while we are trying to close the page.
530
- await this._delegate.closePage(runBeforeUnload).catch(e => _debugLogger.debugLogger.log('error', e));
543
+ if (this._closedState !== "closing") {
544
+ this._closedState = "closing";
545
+ await this._delegate.closePage(runBeforeUnload).catch((e) => import_debugLogger.debugLogger.log("error", e));
531
546
  }
532
- if (!runBeforeUnload) await this._closedPromise;
533
- if (this._ownedContext) await this._ownedContext.close(options);
534
- }
535
- _setIsError(error) {
536
- this._pageIsError = error;
537
- this._frameManager.createDummyMainFrameIfNeeded();
547
+ if (!runBeforeUnload)
548
+ await this._closedPromise;
549
+ if (this._ownedContext)
550
+ await this._ownedContext.close(options);
538
551
  }
539
552
  isClosed() {
540
- return this._closedState === 'closed';
553
+ return this._closedState === "closed";
541
554
  }
542
555
  hasCrashed() {
543
556
  return this._crashed;
544
557
  }
545
558
  isClosedOrClosingOrCrashed() {
546
- return this._closedState !== 'open' || this._crashed;
559
+ return this._closedState !== "open" || this._crashed;
547
560
  }
548
561
  _addWorker(workerId, worker) {
549
562
  this._workers.set(workerId, worker);
@@ -551,7 +564,8 @@ class Page extends _instrumentation.SdkObject {
551
564
  }
552
565
  _removeWorker(workerId) {
553
566
  const worker = this._workers.get(workerId);
554
- if (!worker) return;
567
+ if (!worker)
568
+ return;
555
569
  worker.didClose();
556
570
  this._workers.delete(workerId);
557
571
  }
@@ -571,233 +585,135 @@ class Page extends _instrumentation.SdkObject {
571
585
  frameNavigatedToNewDocument(frame) {
572
586
  this.emit(Page.Events.InternalFrameNavigatedToNewDocument, frame);
573
587
  const origin = frame.origin();
574
- if (origin) this._browserContext.addVisitedOrigin(origin);
588
+ if (origin)
589
+ this._browserContext.addVisitedOrigin(origin);
575
590
  }
576
591
  allInitScripts() {
577
592
  const bindings = [...this._browserContext._pageBindings.values(), ...this._pageBindings.values()];
578
- return [...bindings.map(binding => binding.initScript), ...this._browserContext.initScripts, ...this.initScripts];
593
+ return [kBuiltinsScript, ...bindings.map((binding) => binding.initScript), ...this._browserContext.initScripts, ...this.initScripts];
579
594
  }
580
595
  getBinding(name) {
581
596
  return this._pageBindings.get(name) || this._browserContext._pageBindings.get(name);
582
597
  }
583
598
  setScreencastOptions(options) {
584
- this._delegate.setScreencastOptions(options).catch(e => _debugLogger.debugLogger.log('error', e));
599
+ this._delegate.setScreencastOptions(options).catch((e) => import_debugLogger.debugLogger.log("error", e));
585
600
  this._frameThrottler.setThrottlingEnabled(!!options);
586
601
  }
587
602
  throttleScreencastFrameAck(ack) {
588
- // Don't ack immediately, tracing has smart throttling logic that is implemented here.
589
603
  this._frameThrottler.ack(ack);
590
604
  }
591
605
  temporarilyDisableTracingScreencastThrottling() {
592
606
  this._frameThrottler.recharge();
593
607
  }
594
608
  async safeNonStallingEvaluateInAllFrames(expression, world, options = {}) {
595
- await Promise.all(this.frames().map(async frame => {
609
+ await Promise.all(this.frames().map(async (frame) => {
596
610
  try {
597
611
  await frame.nonStallingEvaluateInExistingContext(expression, world);
598
612
  } catch (e) {
599
- if (options.throwOnJSErrors && js.isJavaScriptErrorInEvaluate(e)) throw e;
613
+ if (options.throwOnJSErrors && js.isJavaScriptErrorInEvaluate(e))
614
+ throw e;
600
615
  }
601
616
  }));
602
617
  }
603
618
  async hideHighlight() {
604
- await Promise.all(this.frames().map(frame => frame.hideHighlight().catch(() => {})));
619
+ await Promise.all(this.frames().map((frame) => frame.hideHighlight().catch(() => {
620
+ })));
605
621
  }
606
622
  markAsServerSideOnly() {
607
623
  this._isServerSideOnly = true;
608
624
  }
609
625
  }
610
- exports.Page = Page;
611
- Page.Events = {
612
- Close: 'close',
613
- Crash: 'crash',
614
- Download: 'download',
615
- FileChooser: 'filechooser',
616
- FrameAttached: 'frameattached',
617
- FrameDetached: 'framedetached',
618
- InternalFrameNavigatedToNewDocument: 'internalframenavigatedtonewdocument',
619
- LocatorHandlerTriggered: 'locatorhandlertriggered',
620
- ScreencastFrame: 'screencastframe',
621
- Video: 'video',
622
- WebSocket: 'websocket',
623
- Worker: 'worker'
624
- };
625
- class Worker extends _instrumentation.SdkObject {
626
+ class Worker extends import_instrumentation.SdkObject {
626
627
  constructor(parent, url, targetId, session) {
627
- super(parent, 'worker');
628
- this._url = void 0;
629
- this._executionContextPromise = void 0;
630
- this._executionContextCallback = void 0;
628
+ super(parent, "worker");
631
629
  this._existingExecutionContext = null;
632
- this.openScope = new _utils.LongStandingScope();
633
- this._targetId = void 0;
634
- this._session = void 0;
630
+ this.openScope = new import_utils.LongStandingScope();
635
631
  this._url = url;
636
- this._executionContextCallback = () => {};
637
- this._executionContextPromise = new Promise(x => this._executionContextCallback = x);
632
+ this._executionContextCallback = () => {
633
+ };
634
+ this._executionContextPromise = new Promise((x) => this._executionContextCallback = x);
638
635
  this._targetId = targetId;
639
636
  this._session = session;
640
637
  }
638
+ static {
639
+ this.Events = {
640
+ Close: "close"
641
+ };
642
+ }
641
643
  _createExecutionContext(delegate) {
642
- this._existingExecutionContext = new js.ExecutionContext(this, delegate, 'worker');
644
+ this._existingExecutionContext = new js.ExecutionContext(this, delegate, "worker");
643
645
  this._executionContextCallback(this._existingExecutionContext);
646
+ return this._existingExecutionContext;
644
647
  }
645
648
  url() {
646
649
  return this._url;
647
650
  }
648
651
  didClose() {
649
- if (this._existingExecutionContext) this._existingExecutionContext.contextDestroyed('Worker was closed');
652
+ if (this._existingExecutionContext)
653
+ this._existingExecutionContext.contextDestroyed("Worker was closed");
650
654
  this.emit(Worker.Events.Close, this);
651
- this.openScope.close(new Error('Worker closed'));
655
+ this.openScope.close(new Error("Worker closed"));
652
656
  }
653
657
  async getExecutionContext() {
654
- if (process.env['REBROWSER_PATCHES_RUNTIME_FIX_MODE'] !== '0' && !this._existingExecutionContext) {
658
+ if (process.env["REBROWSER_PATCHES_RUNTIME_FIX_MODE"] !== "0" && !this._existingExecutionContext) {
655
659
  await this._session.__re__emitExecutionContext({
656
- world: 'main',
660
+ world: "main",
657
661
  targetId: this._targetId
658
662
  });
659
663
  }
660
664
  return this._executionContextPromise;
661
665
  }
662
666
  async evaluateExpression(expression, isFunction, arg) {
663
- return js.evaluateExpression(await this.getExecutionContext(), expression, {
664
- returnByValue: true,
665
- isFunction
666
- }, arg);
667
+ return js.evaluateExpression(await this.getExecutionContext(), expression, { returnByValue: true, isFunction }, arg);
667
668
  }
668
669
  async evaluateExpressionHandle(expression, isFunction, arg) {
669
- return js.evaluateExpression(await this.getExecutionContext(), expression, {
670
- returnByValue: false,
671
- isFunction
672
- }, arg);
670
+ return js.evaluateExpression(await this.getExecutionContext(), expression, { returnByValue: false, isFunction }, arg);
673
671
  }
674
672
  }
675
- exports.Worker = Worker;
676
- Worker.Events = {
677
- Close: 'close'
678
- };
679
673
  class PageBinding {
674
+ static {
675
+ this.kPlaywrightBinding = "__playwright__binding__";
676
+ }
680
677
  constructor(name, playwrightFunction, needsHandle) {
681
- this.name = void 0;
682
- this.playwrightFunction = void 0;
683
- this.initScript = void 0;
684
- this.needsHandle = void 0;
685
- this.internal = void 0;
686
678
  this.name = name;
687
679
  this.playwrightFunction = playwrightFunction;
688
- this.initScript = new InitScript(`(${addPageBinding.toString()})(${JSON.stringify(PageBinding.kPlaywrightBinding)}, ${JSON.stringify(name)}, ${needsHandle}, (${_utilityScriptSerializers.source})())`, true /* internal */);
680
+ this.initScript = new InitScript(
681
+ (0, import_pageBinding.createPageBindingScript)(PageBinding.kPlaywrightBinding, name, needsHandle),
682
+ true
683
+ /* internal */
684
+ );
689
685
  this.needsHandle = needsHandle;
690
- this.internal = name.startsWith('__pw');
686
+ this.internal = name.startsWith("__pw");
691
687
  }
692
688
  static async dispatch(page, payload, context) {
693
- const {
694
- name,
695
- seq,
696
- serializedArgs
697
- } = JSON.parse(payload);
689
+ if (process.env["REBROWSER_PATCHES_RUNTIME_FIX_MODE"] !== "0" && !payload.includes("{")) {
690
+ return;
691
+ }
692
+ const { name, seq, serializedArgs } = JSON.parse(payload);
698
693
  try {
699
- (0, _utils.assert)(context.world);
694
+ (0, import_utils.assert)(context.world);
700
695
  const binding = page.getBinding(name);
701
- if (!binding) throw new Error(`Function "${name}" is not exposed`);
696
+ if (!binding)
697
+ throw new Error(`Function "${name}" is not exposed`);
702
698
  let result;
703
699
  if (binding.needsHandle) {
704
- const handle = await context.evaluateHandle(takeHandle, {
705
- name,
706
- seq
707
- }).catch(e => null);
708
- result = await binding.playwrightFunction({
709
- frame: context.frame,
710
- page,
711
- context: page._browserContext
712
- }, handle);
700
+ const handle = await context.evaluateHandle(import_pageBinding.takeBindingHandle, { name, seq }).catch((e) => null);
701
+ result = await binding.playwrightFunction({ frame: context.frame, page, context: page._browserContext }, handle);
713
702
  } else {
714
- if (!Array.isArray(serializedArgs)) throw new Error(`serializedArgs is not an array. This can happen when Array.prototype.toJSON is defined incorrectly`);
715
- const args = serializedArgs.map(a => (0, _utilityScriptSerializers.parseEvaluationResultValue)(a));
716
- result = await binding.playwrightFunction({
717
- frame: context.frame,
718
- page,
719
- context: page._browserContext
720
- }, ...args);
703
+ if (!Array.isArray(serializedArgs))
704
+ throw new Error(`serializedArgs is not an array. This can happen when Array.prototype.toJSON is defined incorrectly`);
705
+ const args = serializedArgs.map((a) => js.parseEvaluationResultValue(a));
706
+ result = await binding.playwrightFunction({ frame: context.frame, page, context: page._browserContext }, ...args);
721
707
  }
722
- context.evaluate(deliverResult, {
723
- name,
724
- seq,
725
- result
726
- }).catch(e => _debugLogger.debugLogger.log('error', e));
708
+ context.evaluate(import_pageBinding.deliverBindingResult, { name, seq, result }).catch((e) => import_debugLogger.debugLogger.log("error", e));
727
709
  } catch (error) {
728
- context.evaluate(deliverResult, {
729
- name,
730
- seq,
731
- error
732
- }).catch(e => _debugLogger.debugLogger.log('error', e));
733
- }
734
- function takeHandle(arg) {
735
- const handle = globalThis[arg.name]['handles'].get(arg.seq);
736
- globalThis[arg.name]['handles'].delete(arg.seq);
737
- return handle;
738
- }
739
- function deliverResult(arg) {
740
- const callbacks = globalThis[arg.name]['callbacks'];
741
- if ('error' in arg) callbacks.get(arg.seq).reject(arg.error);else callbacks.get(arg.seq).resolve(arg.result);
742
- callbacks.delete(arg.seq);
710
+ context.evaluate(import_pageBinding.deliverBindingResult, { name, seq, error }).catch((e) => import_debugLogger.debugLogger.log("error", e));
743
711
  }
744
712
  }
745
713
  }
746
- exports.PageBinding = PageBinding;
747
- PageBinding.kPlaywrightBinding = '__playwright__binding__';
748
- function addPageBinding(playwrightBinding, bindingName, needsHandle, utilityScriptSerializers) {
749
- const binding = globalThis[playwrightBinding];
750
- globalThis[bindingName] = (...args) => {
751
- const me = globalThis[bindingName];
752
- if (needsHandle && args.slice(1).some(arg => arg !== undefined)) throw new Error(`exposeBindingHandle supports a single argument, ${args.length} received`);
753
- let callbacks = me['callbacks'];
754
- if (!callbacks) {
755
- callbacks = new Map();
756
- me['callbacks'] = callbacks;
757
- }
758
- const seq = (me['lastSeq'] || 0) + 1;
759
- me['lastSeq'] = seq;
760
- let handles = me['handles'];
761
- if (!handles) {
762
- handles = new Map();
763
- me['handles'] = handles;
764
- }
765
- const promise = new Promise((resolve, reject) => callbacks.set(seq, {
766
- resolve,
767
- reject
768
- }));
769
- let payload;
770
- if (needsHandle) {
771
- handles.set(seq, args[0]);
772
- payload = {
773
- name: bindingName,
774
- seq
775
- };
776
- } else {
777
- const serializedArgs = [];
778
- for (let i = 0; i < args.length; i++) {
779
- serializedArgs[i] = utilityScriptSerializers.serializeAsCallArgument(args[i], v => {
780
- return {
781
- fallThrough: v
782
- };
783
- });
784
- }
785
- payload = {
786
- name: bindingName,
787
- seq,
788
- serializedArgs
789
- };
790
- }
791
- binding(JSON.stringify(payload));
792
- return promise;
793
- };
794
- globalThis[bindingName].__installed = true;
795
- }
796
714
  class InitScript {
797
- constructor(source, internal) {
798
- this.source = void 0;
799
- this.internal = void 0;
800
- const guid = (0, _utils.createGuid)();
715
+ constructor(source, internal, name) {
716
+ const guid = (0, import_crypto.createGuid)();
801
717
  this.source = `(() => {
802
718
  globalThis.__pwInitScripts = globalThis.__pwInitScripts || {};
803
719
  const hasInitScript = globalThis.__pwInitScripts[${JSON.stringify(guid)}];
@@ -807,18 +723,18 @@ class InitScript {
807
723
  ${source}
808
724
  })();`;
809
725
  this.internal = !!internal;
726
+ this.name = name;
810
727
  }
811
728
  }
812
- exports.InitScript = InitScript;
729
+ const kBuiltinsScript = new InitScript(
730
+ `(${import_builtins.builtins})()`,
731
+ true
732
+ /* internal */
733
+ );
813
734
  class FrameThrottler {
814
735
  constructor(nonThrottledFrames, defaultInterval, throttlingInterval) {
815
736
  this._acks = [];
816
- this._defaultInterval = void 0;
817
- this._throttlingInterval = void 0;
818
- this._nonThrottledFrames = void 0;
819
- this._budget = void 0;
820
737
  this._throttlingEnabled = false;
821
- this._timeoutId = void 0;
822
738
  this._nonThrottledFrames = nonThrottledFrames;
823
739
  this._budget = nonThrottledFrames;
824
740
  this._defaultInterval = defaultInterval;
@@ -828,15 +744,15 @@ class FrameThrottler {
828
744
  dispose() {
829
745
  if (this._timeoutId) {
830
746
  clearTimeout(this._timeoutId);
831
- this._timeoutId = undefined;
747
+ this._timeoutId = void 0;
832
748
  }
833
749
  }
834
750
  setThrottlingEnabled(enabled) {
835
751
  this._throttlingEnabled = enabled;
836
752
  }
837
753
  recharge() {
838
- // Send all acks, reset budget.
839
- for (const ack of this._acks) ack();
754
+ for (const ack of this._acks)
755
+ ack();
840
756
  this._acks = [];
841
757
  this._budget = this._nonThrottledFrames;
842
758
  if (this._timeoutId) {
@@ -846,7 +762,6 @@ class FrameThrottler {
846
762
  }
847
763
  ack(ack) {
848
764
  if (!this._timeoutId) {
849
- // Already disposed.
850
765
  ack();
851
766
  return;
852
767
  }
@@ -859,11 +774,17 @@ class FrameThrottler {
859
774
  ack();
860
775
  }
861
776
  if (this._throttlingEnabled && this._budget <= 0) {
862
- // Non-throttled frame budget is exceeded. Next ack will be throttled.
863
777
  this._timeoutId = setTimeout(() => this._tick(), this._throttlingInterval);
864
778
  } else {
865
- // Either not throttling, or still under budget. Next ack will be after the default timeout.
866
779
  this._timeoutId = setTimeout(() => this._tick(), this._defaultInterval);
867
780
  }
868
781
  }
869
- }
782
+ }
783
+ // Annotate the CommonJS export names for ESM import in node:
784
+ 0 && (module.exports = {
785
+ InitScript,
786
+ Page,
787
+ PageBinding,
788
+ Worker,
789
+ kBuiltinsScript
790
+ });