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