@speedkit/cli 4.51.0-run-control.4 → 4.51.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 (485) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +14 -1426
  3. package/dist/commands/diff.d.ts +1 -7
  4. package/dist/commands/diff.js +3 -9
  5. package/dist/commands/login.d.ts +0 -3
  6. package/dist/commands/login.js +3 -14
  7. package/dist/commands/onboarding.d.ts +0 -26
  8. package/dist/commands/onboarding.js +4 -221
  9. package/dist/commands/origin-request.d.ts +0 -4
  10. package/dist/commands/origin-request.js +0 -4
  11. package/dist/services/browser-fetch/device-emulation.d.ts +0 -11
  12. package/dist/services/browser-fetch/device-emulation.js +0 -14
  13. package/dist/services/bundler/bundle-service-factory.d.ts +3 -0
  14. package/dist/services/bundler/bundle-service-factory.js +5 -1
  15. package/dist/services/bundler/bundle-service.d.ts +10 -1
  16. package/dist/services/bundler/bundle-service.js +16 -1
  17. package/dist/services/bundler/error/packjockel-error.d.ts +3 -0
  18. package/dist/services/bundler/error/packjockel-error.js +3 -0
  19. package/dist/services/bundler/index.d.ts +1 -0
  20. package/dist/services/bundler/index.js +1 -0
  21. package/dist/services/bundler/packjockel-service.d.ts +112 -0
  22. package/dist/services/bundler/packjockel-service.js +202 -0
  23. package/dist/services/bundler/spec/packjockel-service.spec.js +186 -0
  24. package/dist/services/cli/cli-environment-factory.d.ts +0 -3
  25. package/dist/services/cli/cli-environment-factory.js +0 -1
  26. package/dist/services/cli/cli-service-build-context.d.ts +0 -3
  27. package/dist/services/cli/cli-service-factory.js +1 -1
  28. package/dist/services/cli/cli-service-model.d.ts +10 -29
  29. package/dist/services/cli/cli-service.d.ts +11 -60
  30. package/dist/services/cli/cli-service.js +32 -196
  31. package/dist/services/cli/index.d.ts +0 -2
  32. package/dist/services/cli/index.js +0 -2
  33. package/dist/services/cli/spec/cli-service.spec.js +50 -113
  34. package/dist/services/deploy/checks/activation/customer-approval-check.js +1 -1
  35. package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +2 -3
  36. package/dist/services/deploy/checks/pre-deploy/split-change-check.js +2 -3
  37. package/dist/services/deploy/handler/customer-config-handler.d.ts +9 -0
  38. package/dist/services/deploy/handler/customer-config-handler.js +41 -6
  39. package/dist/services/deploy/interface/install.d.ts +7 -1
  40. package/dist/services/deploy/mr/live-state-check.js +21 -2
  41. package/dist/services/deploy/policy/auto-deploy-policy.js +2 -0
  42. package/dist/services/deploy/policy/deploy-policy-model.d.ts +4 -0
  43. package/dist/services/deploy/policy/deploy-policy-model.js +4 -0
  44. package/dist/services/deploy/policy/testing-deploy-policy.js +2 -0
  45. package/dist/services/deploy/spec/handler/customer-config-handler.spec.js +98 -0
  46. package/dist/services/deploy/spec/mr/live-state-check.spec.js +45 -4
  47. package/dist/services/deploy/spec/policy/auto-deploy-policy.spec.js +2 -0
  48. package/dist/services/deploy/spec/policy/testing-deploy-policy.spec.js +3 -1
  49. package/dist/services/diff/diff-service-build-context.d.ts +0 -12
  50. package/dist/services/diff/diff-service-build-context.js +1 -45
  51. package/dist/services/diff/diff-service-factory.d.ts +0 -2
  52. package/dist/services/diff/diff-service-factory.js +25 -65
  53. package/dist/services/diff/diff-service.d.ts +0 -11
  54. package/dist/services/diff/diff-service.js +11 -37
  55. package/dist/services/diff/page-source.d.ts +0 -12
  56. package/dist/services/diff/page-source.js +11 -16
  57. package/dist/services/diff/sinks/tool-diff-sink.d.ts +2 -3
  58. package/dist/services/diff/sinks/tool-diff-sink.js +2 -3
  59. package/dist/services/diff/spec/diff-service-build-context.spec.js +0 -19
  60. package/dist/services/diff/spec/diff-service.spec.js +0 -95
  61. package/dist/services/document-handler-runtime/document-handler-browser-mock.d.ts +13 -0
  62. package/dist/services/document-handler-runtime/document-handler-browser-mock.js +69 -0
  63. package/dist/services/document-handler-runtime/document-handler-server.d.ts +27 -0
  64. package/dist/services/document-handler-runtime/document-handler-server.js +112 -19
  65. package/dist/services/document-handler-runtime/spec/document-handler-browser-mock.spec.js +34 -0
  66. package/dist/services/git/git-repository.d.ts +0 -2
  67. package/dist/services/git/git-repository.js +0 -6
  68. package/dist/services/integration-api/customer-config-flags.js +0 -1
  69. package/dist/services/integration-api/integration-api-model.d.ts +4 -1
  70. package/dist/services/integration-api/spec/customer-config-file.spec.js +56 -0
  71. package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +68 -8
  72. package/dist/services/integration-api/struct/customer-config-file.d.ts +15 -0
  73. package/dist/services/integration-api/struct/customer-config-file.js +42 -0
  74. package/dist/services/integration-api/struct/customer-config.d.ts +55 -1
  75. package/dist/services/integration-api/struct/customer-config.js +70 -3
  76. package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +11 -4
  77. package/dist/services/integration-api/struct/speed-kit-config-file.js +31 -10
  78. package/dist/services/onboarding/browse/browse-service.d.ts +1 -13
  79. package/dist/services/onboarding/browse/browse-service.js +7 -43
  80. package/dist/services/onboarding/browser/baqend-response.d.ts +1 -17
  81. package/dist/services/onboarding/browser/baqend-response.js +0 -23
  82. package/dist/services/onboarding/browser/emulate-device.d.ts +1 -12
  83. package/dist/services/onboarding/browser/emulate-device.js +13 -68
  84. package/dist/services/onboarding/browser/executable/executable-validator.js +2 -4
  85. package/dist/services/onboarding/browser/extension/extension-bridge.js +3 -5
  86. package/dist/services/onboarding/browser/extension/extension-downloader.js +8 -17
  87. package/dist/services/onboarding/browser/extension/extension-validator.js +4 -9
  88. package/dist/services/onboarding/browser/launch-browser.d.ts +1 -2
  89. package/dist/services/onboarding/browser/launch-browser.js +1 -6
  90. package/dist/services/onboarding/config-renderer/speed-kit-install-context.d.ts +2 -0
  91. package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +29 -8
  92. package/dist/services/onboarding/dashboard/diff-against-current-page.js +1 -3
  93. package/dist/services/onboarding/dashboard/index.js +2 -7
  94. package/dist/services/onboarding/fetch-event-handler.d.ts +5 -24
  95. package/dist/services/onboarding/fetch-event-handler.js +32 -103
  96. package/dist/services/onboarding/fetch-events/speed-kit-install-js.js +2 -11
  97. package/dist/services/onboarding/fetch-events/speed-kit-rum-pi-request.d.ts +0 -14
  98. package/dist/services/onboarding/fetch-events/speed-kit-rum-pi-request.js +0 -30
  99. package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.d.ts +3 -14
  100. package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.js +10 -29
  101. package/dist/services/onboarding/file-events/file-watcher.d.ts +4 -43
  102. package/dist/services/onboarding/file-events/file-watcher.js +21 -119
  103. package/dist/services/onboarding/inject/inject-service.js +1 -1
  104. package/dist/services/onboarding/onboarding-model.d.ts +7 -40
  105. package/dist/services/onboarding/onboarding-model.js +9 -20
  106. package/dist/services/onboarding/onboarding-service-build-context.d.ts +0 -4
  107. package/dist/services/onboarding/onboarding-service-build-context.js +1 -7
  108. package/dist/services/onboarding/onboarding-service-factory.d.ts +1 -17
  109. package/dist/services/onboarding/onboarding-service-factory.js +35 -152
  110. package/dist/services/onboarding/onboarding-service.d.ts +1 -40
  111. package/dist/services/onboarding/onboarding-service.js +23 -139
  112. package/dist/services/onboarding/request-cache/cache.d.ts +5 -62
  113. package/dist/services/onboarding/request-cache/cache.js +17 -128
  114. package/dist/services/onboarding/spec/file-events/file-watcher.spec.js +67 -0
  115. package/dist/services/onboarding/spec/onboarding-model.spec.js +3 -39
  116. package/dist/services/onboarding/spec/onboarding-service-factory.spec.js +1 -25
  117. package/dist/services/onboarding/templates/install-speed-kit-js-template.js +5 -0
  118. package/dist/services/onboarding/todo-collector.d.ts +2 -7
  119. package/dist/services/onboarding/todo-collector.js +12 -49
  120. package/dist/services/onboarding/virtual-orestes-app/index.d.ts +0 -38
  121. package/dist/services/onboarding/virtual-orestes-app/index.js +27 -113
  122. package/dist/services/origin-request/asset-variations.d.ts +0 -14
  123. package/dist/services/origin-request/asset-variations.js +4 -11
  124. package/dist/services/origin-request/origin-fetcher.d.ts +0 -7
  125. package/dist/services/origin-request/origin-fetcher.js +5 -43
  126. package/dist/services/origin-request/origin-request-service-build-context.d.ts +0 -17
  127. package/dist/services/origin-request/origin-request-service-build-context.js +0 -8
  128. package/dist/services/origin-request/origin-request-service-factory.d.ts +5 -0
  129. package/dist/services/origin-request/origin-request-service-factory.js +30 -2
  130. package/dist/services/origin-request/origin-request-service.d.ts +6 -121
  131. package/dist/services/origin-request/origin-request-service.js +49 -273
  132. package/dist/services/origin-request/runtime-config-source.d.ts +0 -6
  133. package/dist/services/origin-request/runtime-config-source.js +4 -15
  134. package/dist/services/origin-request/spec/asset-variations.spec.js +0 -20
  135. package/dist/services/origin-request/spec/origin-request-service.spec.js +6 -329
  136. package/dist/services/pull/pull-service.js +23 -5
  137. package/dist/services/query-builder/query-builder-factory.js +3 -3
  138. package/dist/services/setup/os/tool-registry.js +2 -2
  139. package/oclif.manifest.json +288 -3409
  140. package/package.json +3 -20
  141. package/dist/base/run-control-command.d.ts +0 -15
  142. package/dist/base/run-control-command.js +0 -20
  143. package/dist/build-info.json +0 -6
  144. package/dist/commands/onboarding/browser/click.d.ts +0 -75
  145. package/dist/commands/onboarding/browser/click.js +0 -19
  146. package/dist/commands/onboarding/browser/emulate.d.ts +0 -105
  147. package/dist/commands/onboarding/browser/emulate.js +0 -26
  148. package/dist/commands/onboarding/browser/navigate.d.ts +0 -75
  149. package/dist/commands/onboarding/browser/navigate.js +0 -19
  150. package/dist/commands/onboarding/browser/panel.d.ts +0 -63
  151. package/dist/commands/onboarding/browser/panel.js +0 -12
  152. package/dist/commands/onboarding/browser/reinstall-sw.d.ts +0 -63
  153. package/dist/commands/onboarding/browser/reinstall-sw.js +0 -14
  154. package/dist/commands/onboarding/browser/reset.d.ts +0 -71
  155. package/dist/commands/onboarding/browser/reset.js +0 -18
  156. package/dist/commands/onboarding/browser/screenshot.d.ts +0 -77
  157. package/dist/commands/onboarding/browser/screenshot.js +0 -19
  158. package/dist/commands/onboarding/browser/state.d.ts +0 -63
  159. package/dist/commands/onboarding/browser/state.js +0 -12
  160. package/dist/commands/onboarding/browser/tabs.d.ts +0 -58
  161. package/dist/commands/onboarding/browser/tabs.js +0 -16
  162. package/dist/commands/onboarding/cache/clear.d.ts +0 -58
  163. package/dist/commands/onboarding/cache/clear.js +0 -12
  164. package/dist/commands/onboarding/cache/errors.d.ts +0 -58
  165. package/dist/commands/onboarding/cache/errors.js +0 -12
  166. package/dist/commands/onboarding/cache/evict.d.ts +0 -62
  167. package/dist/commands/onboarding/cache/evict.js +0 -15
  168. package/dist/commands/onboarding/cache/get.d.ts +0 -85
  169. package/dist/commands/onboarding/cache/get.js +0 -17
  170. package/dist/commands/onboarding/cache/list.d.ts +0 -58
  171. package/dist/commands/onboarding/cache/list.js +0 -15
  172. package/dist/commands/onboarding/cache/prewarm.d.ts +0 -73
  173. package/dist/commands/onboarding/cache/prewarm.js +0 -20
  174. package/dist/commands/onboarding/cache/refresh.d.ts +0 -62
  175. package/dist/commands/onboarding/cache/refresh.js +0 -18
  176. package/dist/commands/onboarding/cdp.d.ts +0 -81
  177. package/dist/commands/onboarding/cdp.js +0 -18
  178. package/dist/commands/onboarding/debug/arm.d.ts +0 -83
  179. package/dist/commands/onboarding/debug/arm.js +0 -19
  180. package/dist/commands/onboarding/debug/await.d.ts +0 -71
  181. package/dist/commands/onboarding/debug/await.js +0 -18
  182. package/dist/commands/onboarding/debug/disarm.d.ts +0 -63
  183. package/dist/commands/onboarding/debug/disarm.js +0 -12
  184. package/dist/commands/onboarding/debug/eval.d.ts +0 -75
  185. package/dist/commands/onboarding/debug/eval.js +0 -16
  186. package/dist/commands/onboarding/debug/release.d.ts +0 -63
  187. package/dist/commands/onboarding/debug/release.js +0 -12
  188. package/dist/commands/onboarding/debug/resume.d.ts +0 -63
  189. package/dist/commands/onboarding/debug/resume.js +0 -12
  190. package/dist/commands/onboarding/debug/status.d.ts +0 -63
  191. package/dist/commands/onboarding/debug/status.js +0 -12
  192. package/dist/commands/onboarding/debug/step.d.ts +0 -67
  193. package/dist/commands/onboarding/debug/step.js +0 -15
  194. package/dist/commands/onboarding/files/list.d.ts +0 -58
  195. package/dist/commands/onboarding/files/list.js +0 -12
  196. package/dist/commands/onboarding/files/read.d.ts +0 -73
  197. package/dist/commands/onboarding/files/read.js +0 -16
  198. package/dist/commands/onboarding/files/rebuild.d.ts +0 -63
  199. package/dist/commands/onboarding/files/rebuild.js +0 -18
  200. package/dist/commands/onboarding/files/validate.d.ts +0 -58
  201. package/dist/commands/onboarding/files/validate.js +0 -12
  202. package/dist/commands/onboarding/fouc.d.ts +0 -77
  203. package/dist/commands/onboarding/fouc.js +0 -16
  204. package/dist/commands/onboarding/inject/add.d.ts +0 -89
  205. package/dist/commands/onboarding/inject/add.js +0 -17
  206. package/dist/commands/onboarding/inject/clear.d.ts +0 -63
  207. package/dist/commands/onboarding/inject/clear.js +0 -12
  208. package/dist/commands/onboarding/inject/list.d.ts +0 -63
  209. package/dist/commands/onboarding/inject/list.js +0 -12
  210. package/dist/commands/onboarding/inject/read.d.ts +0 -75
  211. package/dist/commands/onboarding/inject/read.js +0 -18
  212. package/dist/commands/onboarding/inject/recipes.d.ts +0 -63
  213. package/dist/commands/onboarding/inject/recipes.js +0 -12
  214. package/dist/commands/onboarding/inject/remove.d.ts +0 -67
  215. package/dist/commands/onboarding/inject/remove.js +0 -15
  216. package/dist/commands/onboarding/list.d.ts +0 -13
  217. package/dist/commands/onboarding/list.js +0 -12
  218. package/dist/commands/onboarding/logs.d.ts +0 -41
  219. package/dist/commands/onboarding/logs.js +0 -257
  220. package/dist/commands/onboarding/navwalk.d.ts +0 -95
  221. package/dist/commands/onboarding/navwalk.js +0 -19
  222. package/dist/commands/onboarding/response.d.ts +0 -67
  223. package/dist/commands/onboarding/response.js +0 -18
  224. package/dist/commands/onboarding/rum/beacons.d.ts +0 -75
  225. package/dist/commands/onboarding/rum/beacons.js +0 -16
  226. package/dist/commands/onboarding/rum/get.d.ts +0 -77
  227. package/dist/commands/onboarding/rum/get.js +0 -18
  228. package/dist/commands/onboarding/rum/key.d.ts +0 -67
  229. package/dist/commands/onboarding/rum/key.js +0 -13
  230. package/dist/commands/onboarding/rum/previous.d.ts +0 -63
  231. package/dist/commands/onboarding/rum/previous.js +0 -12
  232. package/dist/commands/onboarding/status.d.ts +0 -13
  233. package/dist/commands/onboarding/status.js +0 -17
  234. package/dist/commands/onboarding/stop.d.ts +0 -13
  235. package/dist/commands/onboarding/stop.js +0 -17
  236. package/dist/commands/onboarding/todo.d.ts +0 -58
  237. package/dist/commands/onboarding/todo.js +0 -12
  238. package/dist/commands/onboarding/viewport.d.ts +0 -101
  239. package/dist/commands/onboarding/viewport.js +0 -18
  240. package/dist/commands/onboarding/watch.d.ts +0 -93
  241. package/dist/commands/onboarding/watch.js +0 -16
  242. package/dist/commands/spec/onboarding.spec.js +0 -127
  243. package/dist/services/cli/build-info.d.ts +0 -33
  244. package/dist/services/cli/build-info.js +0 -63
  245. package/dist/services/cli/sink.d.ts +0 -47
  246. package/dist/services/cli/sink.js +0 -31
  247. package/dist/services/cli/spec/build-identity.spec.js +0 -85
  248. package/dist/services/cli/spec/build-info.spec.js +0 -10
  249. package/dist/services/cli/spec/cli-service-log.spec.js +0 -133
  250. package/dist/services/cli/spec/memory-cli.d.ts +0 -9
  251. package/dist/services/cli/spec/memory-cli.js +0 -9
  252. package/dist/services/diff/config-at-ref.d.ts +0 -20
  253. package/dist/services/diff/config-at-ref.js +0 -33
  254. package/dist/services/diff/run-runtime-config.d.ts +0 -33
  255. package/dist/services/diff/run-runtime-config.js +0 -74
  256. package/dist/services/diff/spec/config-at-ref.spec.js +0 -46
  257. package/dist/services/diff/spec/run-runtime-config.spec.d.ts +0 -1
  258. package/dist/services/diff/spec/run-runtime-config.spec.js +0 -87
  259. package/dist/services/onboarding/browser/answer-dialogs.d.ts +0 -12
  260. package/dist/services/onboarding/browser/answer-dialogs.js +0 -25
  261. package/dist/services/onboarding/browser/console-log.d.ts +0 -9
  262. package/dist/services/onboarding/browser/console-log.js +0 -27
  263. package/dist/services/onboarding/browser/resume-restarted-workers.d.ts +0 -14
  264. package/dist/services/onboarding/browser/resume-restarted-workers.js +0 -26
  265. package/dist/services/onboarding/control/body-inspect.d.ts +0 -24
  266. package/dist/services/onboarding/control/body-inspect.js +0 -106
  267. package/dist/services/onboarding/control/browser-session.d.ts +0 -547
  268. package/dist/services/onboarding/control/browser-session.js +0 -1337
  269. package/dist/services/onboarding/control/config-validation.d.ts +0 -17
  270. package/dist/services/onboarding/control/config-validation.js +0 -46
  271. package/dist/services/onboarding/control/control-protocol.d.ts +0 -1430
  272. package/dist/services/onboarding/control/control-protocol.js +0 -58
  273. package/dist/services/onboarding/control/control-server.d.ts +0 -292
  274. package/dist/services/onboarding/control/control-server.js +0 -1629
  275. package/dist/services/onboarding/control/debug-session.d.ts +0 -219
  276. package/dist/services/onboarding/control/debug-session.js +0 -897
  277. package/dist/services/onboarding/control/fouc.d.ts +0 -23
  278. package/dist/services/onboarding/control/fouc.js +0 -151
  279. package/dist/services/onboarding/control/index.d.ts +0 -4
  280. package/dist/services/onboarding/control/index.js +0 -4
  281. package/dist/services/onboarding/control/navigate-wait.d.ts +0 -33
  282. package/dist/services/onboarding/control/navigate-wait.js +0 -56
  283. package/dist/services/onboarding/control/navwalk.d.ts +0 -65
  284. package/dist/services/onboarding/control/navwalk.js +0 -248
  285. package/dist/services/onboarding/control/preload-registry.d.ts +0 -150
  286. package/dist/services/onboarding/control/preload-registry.js +0 -829
  287. package/dist/services/onboarding/control/response-explainer.d.ts +0 -24
  288. package/dist/services/onboarding/control/response-explainer.js +0 -257
  289. package/dist/services/onboarding/control/rum.d.ts +0 -8
  290. package/dist/services/onboarding/control/rum.js +0 -220
  291. package/dist/services/onboarding/control/service-worker-tracker.d.ts +0 -68
  292. package/dist/services/onboarding/control/service-worker-tracker.js +0 -120
  293. package/dist/services/onboarding/control/viewport.d.ts +0 -45
  294. package/dist/services/onboarding/control/viewport.js +0 -344
  295. package/dist/services/onboarding/control/watch.d.ts +0 -26
  296. package/dist/services/onboarding/control/watch.js +0 -157
  297. package/dist/services/onboarding/request-cache/asset-key.d.ts +0 -61
  298. package/dist/services/onboarding/request-cache/asset-key.js +0 -115
  299. package/dist/services/onboarding/spec/browser/answer-dialogs.spec.d.ts +0 -1
  300. package/dist/services/onboarding/spec/browser/answer-dialogs.spec.js +0 -66
  301. package/dist/services/onboarding/spec/browser/console-log.spec.d.ts +0 -1
  302. package/dist/services/onboarding/spec/browser/console-log.spec.js +0 -42
  303. package/dist/services/onboarding/spec/browser/resume-restarted-workers.spec.d.ts +0 -1
  304. package/dist/services/onboarding/spec/browser/resume-restarted-workers.spec.js +0 -45
  305. package/dist/services/onboarding/spec/control/browser-session.spec.d.ts +0 -1
  306. package/dist/services/onboarding/spec/control/browser-session.spec.js +0 -753
  307. package/dist/services/onboarding/spec/control/control-server.spec.d.ts +0 -1
  308. package/dist/services/onboarding/spec/control/control-server.spec.js +0 -371
  309. package/dist/services/onboarding/spec/control/debug-session.spec.d.ts +0 -1
  310. package/dist/services/onboarding/spec/control/debug-session.spec.js +0 -751
  311. package/dist/services/onboarding/spec/control/fakes.d.ts +0 -31
  312. package/dist/services/onboarding/spec/control/fakes.js +0 -67
  313. package/dist/services/onboarding/spec/control/fouc.spec.d.ts +0 -1
  314. package/dist/services/onboarding/spec/control/fouc.spec.js +0 -167
  315. package/dist/services/onboarding/spec/control/navigate-wait.spec.d.ts +0 -1
  316. package/dist/services/onboarding/spec/control/navigate-wait.spec.js +0 -47
  317. package/dist/services/onboarding/spec/control/navwalk.spec.d.ts +0 -1
  318. package/dist/services/onboarding/spec/control/navwalk.spec.js +0 -222
  319. package/dist/services/onboarding/spec/control/preload-registry.spec.d.ts +0 -1
  320. package/dist/services/onboarding/spec/control/preload-registry.spec.js +0 -432
  321. package/dist/services/onboarding/spec/control/response-explainer.spec.d.ts +0 -1
  322. package/dist/services/onboarding/spec/control/response-explainer.spec.js +0 -324
  323. package/dist/services/onboarding/spec/control/rum.spec.d.ts +0 -1
  324. package/dist/services/onboarding/spec/control/rum.spec.js +0 -222
  325. package/dist/services/onboarding/spec/control/service-worker-tracker.spec.d.ts +0 -1
  326. package/dist/services/onboarding/spec/control/service-worker-tracker.spec.js +0 -193
  327. package/dist/services/onboarding/spec/control/viewport.spec.d.ts +0 -1
  328. package/dist/services/onboarding/spec/control/viewport.spec.js +0 -200
  329. package/dist/services/onboarding/spec/control/watch.spec.d.ts +0 -1
  330. package/dist/services/onboarding/spec/control/watch.spec.js +0 -187
  331. package/dist/services/onboarding/spec/fetch-event-handler.spec.d.ts +0 -1
  332. package/dist/services/onboarding/spec/fetch-event-handler.spec.js +0 -219
  333. package/dist/services/onboarding/spec/fetch-events/speed-kit-service-worker-js.spec.d.ts +0 -1
  334. package/dist/services/onboarding/spec/fetch-events/speed-kit-service-worker-js.spec.js +0 -41
  335. package/dist/services/onboarding/spec/request-cache/cache.spec.d.ts +0 -1
  336. package/dist/services/onboarding/spec/request-cache/cache.spec.js +0 -107
  337. package/dist/services/onboarding/spec/todo-collector.spec.d.ts +0 -1
  338. package/dist/services/onboarding/spec/todo-collector.spec.js +0 -136
  339. package/dist/services/onboarding/spec/virtual-orestes-app/virtual-orestes-app.spec.d.ts +0 -1
  340. package/dist/services/onboarding/spec/virtual-orestes-app/virtual-orestes-app.spec.js +0 -65
  341. package/dist/services/query-builder/rules/rule-match.d.ts +0 -35
  342. package/dist/services/query-builder/rules/rule-match.js +0 -70
  343. package/dist/services/query-builder/spec/rules/rule-match.spec.d.ts +0 -1
  344. package/dist/services/query-builder/spec/rules/rule-match.spec.js +0 -121
  345. package/dist/services/run-control/browser/run-browser-contexts.d.ts +0 -557
  346. package/dist/services/run-control/browser/run-browser-contexts.js +0 -91
  347. package/dist/services/run-control/browser/run-browser-service-factory.d.ts +0 -5
  348. package/dist/services/run-control/browser/run-browser-service-factory.js +0 -7
  349. package/dist/services/run-control/browser/run-browser-service.d.ts +0 -68
  350. package/dist/services/run-control/browser/run-browser-service.js +0 -206
  351. package/dist/services/run-control/cache/run-cache-contexts.d.ts +0 -349
  352. package/dist/services/run-control/cache/run-cache-contexts.js +0 -51
  353. package/dist/services/run-control/cache/run-cache-service-factory.d.ts +0 -6
  354. package/dist/services/run-control/cache/run-cache-service-factory.js +0 -12
  355. package/dist/services/run-control/cache/run-cache-service.d.ts +0 -35
  356. package/dist/services/run-control/cache/run-cache-service.js +0 -151
  357. package/dist/services/run-control/control-client.d.ts +0 -36
  358. package/dist/services/run-control/control-client.js +0 -147
  359. package/dist/services/run-control/debug/run-debug-contexts.d.ts +0 -416
  360. package/dist/services/run-control/debug/run-debug-contexts.js +0 -47
  361. package/dist/services/run-control/debug/run-debug-service-factory.d.ts +0 -5
  362. package/dist/services/run-control/debug/run-debug-service-factory.js +0 -7
  363. package/dist/services/run-control/debug/run-debug-service.d.ts +0 -39
  364. package/dist/services/run-control/debug/run-debug-service.js +0 -164
  365. package/dist/services/run-control/files/run-files-contexts.d.ts +0 -238
  366. package/dist/services/run-control/files/run-files-contexts.js +0 -26
  367. package/dist/services/run-control/files/run-files-service-factory.d.ts +0 -5
  368. package/dist/services/run-control/files/run-files-service-factory.js +0 -7
  369. package/dist/services/run-control/files/run-files-service.d.ts +0 -29
  370. package/dist/services/run-control/files/run-files-service.js +0 -120
  371. package/dist/services/run-control/index.d.ts +0 -32
  372. package/dist/services/run-control/index.js +0 -31
  373. package/dist/services/run-control/inject/run-inject-contexts.d.ts +0 -319
  374. package/dist/services/run-control/inject/run-inject-contexts.js +0 -38
  375. package/dist/services/run-control/inject/run-inject-service-factory.d.ts +0 -5
  376. package/dist/services/run-control/inject/run-inject-service-factory.js +0 -7
  377. package/dist/services/run-control/inject/run-inject-service.d.ts +0 -31
  378. package/dist/services/run-control/inject/run-inject-service.js +0 -227
  379. package/dist/services/run-control/live-run.d.ts +0 -37
  380. package/dist/services/run-control/live-run.js +0 -56
  381. package/dist/services/run-control/probe/run-probe-contexts.d.ts +0 -333
  382. package/dist/services/run-control/probe/run-probe-contexts.js +0 -73
  383. package/dist/services/run-control/probe/run-probe-service-factory.d.ts +0 -5
  384. package/dist/services/run-control/probe/run-probe-service-factory.js +0 -7
  385. package/dist/services/run-control/probe/run-probe-service.d.ts +0 -54
  386. package/dist/services/run-control/probe/run-probe-service.js +0 -194
  387. package/dist/services/run-control/rum/run-rum-contexts.d.ts +0 -216
  388. package/dist/services/run-control/rum/run-rum-contexts.js +0 -34
  389. package/dist/services/run-control/rum/run-rum-service-factory.d.ts +0 -5
  390. package/dist/services/run-control/rum/run-rum-service-factory.js +0 -7
  391. package/dist/services/run-control/rum/run-rum-service.d.ts +0 -36
  392. package/dist/services/run-control/rum/run-rum-service.js +0 -122
  393. package/dist/services/run-control/run-answer.d.ts +0 -28
  394. package/dist/services/run-control/run-answer.js +0 -58
  395. package/dist/services/run-control/run-control-context.d.ts +0 -102
  396. package/dist/services/run-control/run-control-context.js +0 -36
  397. package/dist/services/run-control/run-control-flags.d.ts +0 -12
  398. package/dist/services/run-control/run-control-flags.js +0 -22
  399. package/dist/services/run-control/run-control-model.d.ts +0 -9
  400. package/dist/services/run-control/run-control-model.js +0 -1
  401. package/dist/services/run-control/run-control-service-factory.d.ts +0 -14
  402. package/dist/services/run-control/run-control-service-factory.js +0 -26
  403. package/dist/services/run-control/session/run-session-contexts.d.ts +0 -25
  404. package/dist/services/run-control/session/run-session-contexts.js +0 -20
  405. package/dist/services/run-control/session/run-session-service-factory.d.ts +0 -8
  406. package/dist/services/run-control/session/run-session-service-factory.js +0 -18
  407. package/dist/services/run-control/session/run-session-service.d.ts +0 -32
  408. package/dist/services/run-control/session/run-session-service.js +0 -151
  409. package/dist/services/run-control/spec/browser/run-browser-service.spec.d.ts +0 -1
  410. package/dist/services/run-control/spec/browser/run-browser-service.spec.js +0 -328
  411. package/dist/services/run-control/spec/cache/run-cache-service.spec.d.ts +0 -1
  412. package/dist/services/run-control/spec/cache/run-cache-service.spec.js +0 -454
  413. package/dist/services/run-control/spec/debug/run-debug-service.spec.d.ts +0 -1
  414. package/dist/services/run-control/spec/debug/run-debug-service.spec.js +0 -113
  415. package/dist/services/run-control/spec/files/run-files-service.spec.d.ts +0 -1
  416. package/dist/services/run-control/spec/files/run-files-service.spec.js +0 -234
  417. package/dist/services/run-control/spec/inject/run-inject-service.spec.d.ts +0 -1
  418. package/dist/services/run-control/spec/inject/run-inject-service.spec.js +0 -251
  419. package/dist/services/run-control/spec/live-run-fixture.d.ts +0 -32
  420. package/dist/services/run-control/spec/live-run-fixture.js +0 -109
  421. package/dist/services/run-control/spec/probe/run-probe-service.spec.d.ts +0 -1
  422. package/dist/services/run-control/spec/probe/run-probe-service.spec.js +0 -108
  423. package/dist/services/run-control/spec/rum/run-rum-service.spec.d.ts +0 -1
  424. package/dist/services/run-control/spec/rum/run-rum-service.spec.js +0 -47
  425. package/dist/services/run-control/spec/run-answer.spec.d.ts +0 -1
  426. package/dist/services/run-control/spec/run-answer.spec.js +0 -57
  427. package/dist/services/run-control/spec/session/run-session-service.spec.d.ts +0 -1
  428. package/dist/services/run-control/spec/session/run-session-service.spec.js +0 -150
  429. package/dist/services/run-log/crash-mirror.d.ts +0 -31
  430. package/dist/services/run-log/crash-mirror.js +0 -69
  431. package/dist/services/run-log/index.d.ts +0 -11
  432. package/dist/services/run-log/index.js +0 -11
  433. package/dist/services/run-log/jsonl-appender.d.ts +0 -46
  434. package/dist/services/run-log/jsonl-appender.js +0 -91
  435. package/dist/services/run-log/log-event-model.d.ts +0 -104
  436. package/dist/services/run-log/log-event-model.js +0 -56
  437. package/dist/services/run-log/log-query-service-factory.d.ts +0 -11
  438. package/dist/services/run-log/log-query-service-factory.js +0 -14
  439. package/dist/services/run-log/log-query-service.d.ts +0 -59
  440. package/dist/services/run-log/log-query-service.js +0 -111
  441. package/dist/services/run-log/log-reader.d.ts +0 -84
  442. package/dist/services/run-log/log-reader.js +0 -180
  443. package/dist/services/run-log/log-summary.d.ts +0 -72
  444. package/dist/services/run-log/log-summary.js +0 -208
  445. package/dist/services/run-log/redaction.d.ts +0 -34
  446. package/dist/services/run-log/redaction.js +0 -124
  447. package/dist/services/run-log/request-log.d.ts +0 -82
  448. package/dist/services/run-log/request-log.js +0 -69
  449. package/dist/services/run-log/request-summary.d.ts +0 -76
  450. package/dist/services/run-log/request-summary.js +0 -0
  451. package/dist/services/run-log/run-log.d.ts +0 -61
  452. package/dist/services/run-log/run-log.js +0 -102
  453. package/dist/services/run-log/spec/log-query-service.spec.d.ts +0 -1
  454. package/dist/services/run-log/spec/log-query-service.spec.js +0 -197
  455. package/dist/services/run-log/spec/log-reader.spec.d.ts +0 -1
  456. package/dist/services/run-log/spec/log-reader.spec.js +0 -109
  457. package/dist/services/run-log/spec/log-summary.spec.d.ts +0 -1
  458. package/dist/services/run-log/spec/log-summary.spec.js +0 -153
  459. package/dist/services/run-log/spec/redaction.spec.d.ts +0 -1
  460. package/dist/services/run-log/spec/redaction.spec.js +0 -61
  461. package/dist/services/run-log/spec/request-log.spec.d.ts +0 -1
  462. package/dist/services/run-log/spec/request-log.spec.js +0 -101
  463. package/dist/services/run-log/spec/request-summary.spec.d.ts +0 -1
  464. package/dist/services/run-log/spec/request-summary.spec.js +0 -171
  465. package/dist/services/run-log/spec/run-log.spec.d.ts +0 -1
  466. package/dist/services/run-log/spec/run-log.spec.js +0 -122
  467. package/dist/services/run-registry/exit-classification.d.ts +0 -39
  468. package/dist/services/run-registry/exit-classification.js +0 -42
  469. package/dist/services/run-registry/index.d.ts +0 -3
  470. package/dist/services/run-registry/index.js +0 -3
  471. package/dist/services/run-registry/process-identity.d.ts +0 -28
  472. package/dist/services/run-registry/process-identity.js +0 -80
  473. package/dist/services/run-registry/run-registry-model.d.ts +0 -128
  474. package/dist/services/run-registry/run-registry-model.js +0 -16
  475. package/dist/services/run-registry/run-registry.d.ts +0 -155
  476. package/dist/services/run-registry/run-registry.js +0 -430
  477. package/dist/services/run-registry/spec/exit-classification.spec.d.ts +0 -1
  478. package/dist/services/run-registry/spec/exit-classification.spec.js +0 -82
  479. package/dist/services/run-registry/spec/run-registry.spec.d.ts +0 -1
  480. package/dist/services/run-registry/spec/run-registry.spec.js +0 -526
  481. /package/dist/{commands/spec/onboarding.spec.d.ts → services/bundler/spec/packjockel-service.spec.d.ts} +0 -0
  482. /package/dist/services/{cli/spec/build-identity.spec.d.ts → deploy/spec/handler/customer-config-handler.spec.d.ts} +0 -0
  483. /package/dist/services/{cli/spec/build-info.spec.d.ts → document-handler-runtime/spec/document-handler-browser-mock.spec.d.ts} +0 -0
  484. /package/dist/services/{cli/spec/cli-service-log.spec.d.ts → integration-api/spec/customer-config-file.spec.d.ts} +0 -0
  485. /package/dist/services/{diff/spec/config-at-ref.spec.d.ts → onboarding/spec/file-events/file-watcher.spec.d.ts} +0 -0
@@ -1,1337 +0,0 @@
1
- import { DebugSession } from "./debug-session.js";
2
- import { WAIT_MARKS, WAIT_PROBE, decideWait, } from "./navigate-wait.js";
3
- import { onboardingDeviceEmulation } from "../../browser-fetch/device-emulation.js";
4
- import { onEveryTarget } from "../browser/emulate-device.js";
5
- import { PreloadRegistry } from "./preload-registry.js";
6
- import { PanelNotFoundError, showDevtoolsPanel, } from "../browser/extension/devtools-panel.js";
7
- /** Long enough for a real expression, short enough that a stall is reported. */
8
- const DEFAULT_EVAL_TIMEOUT_MS = 5000;
9
- /**
10
- * How long an evaluation may go unanswered before the thread is probed.
11
- *
12
- * Well inside the control client's own 5s: a paused page has to come back as
13
- * `PAGE_PAUSED` from here, not as a timeout on the other end of the socket.
14
- */
15
- const PAUSE_CHECK_AFTER_MS = 1000;
16
- /** A plain evaluation that does not answer in this long means a hung thread. */
17
- const THREAD_ANSWER_MS = 1000;
18
- /** An already-settled promise that does not settle in this long means a pause. */
19
- const MICROTASK_ANSWER_MS = 300;
20
- /**
21
- * How long any other CDP call may take.
22
- *
23
- * Under the control client's 5s, so the caller hears which call hung rather
24
- * than a bare CONTROL_TIMEOUT. Nothing times a request out on the server's side
25
- * either, and the server answers one connection strictly in order — so before
26
- * this, one call that never came back held the connection, and the run-wide
27
- * mutation queue with it, until the run stopped.
28
- */
29
- const CDP_ANSWER_MS = 4000;
30
- /** For the calls that clear storage, which can take a while on a full origin. */
31
- const SLOW_CDP_ANSWER_MS = 15_000;
32
- /**
33
- * How long to wait for a navigation to finish loading.
34
- *
35
- * Generous, because a customer's page under a cold documentHandler is genuinely
36
- * slow and the alternative is reporting a failure for a navigation that worked.
37
- */
38
- const NAVIGATION_TIMEOUT_MS = 25_000;
39
- /**
40
- * How long the devtools extension may take to register its panel.
41
- *
42
- * Its devtools page loads after DevTools does, so on a DevTools window this op
43
- * just opened the panel is a moment behind. The op as a whole gets a little
44
- * longer, for opening the window itself.
45
- */
46
- const PANEL_APPEAR_MS = 10_000;
47
- /** How long `emulate` waits for a reinstalled worker to activate. */
48
- const WORKER_SETTLE_MS = 5000;
49
- /** A full-page capture of a long customer page is megabytes of PNG. */
50
- const SCREENSHOT_MS = 30_000;
51
- export class NoSuchElementError extends Error {
52
- code = "NO_SUCH_ELEMENT";
53
- }
54
- export class NoSuchTabError extends Error {
55
- tabs;
56
- code = "NO_SUCH_TAB";
57
- constructor(message, tabs) {
58
- super(message);
59
- this.tabs = tabs;
60
- }
61
- }
62
- /** A passthrough call the run refuses, because it would break the run itself. */
63
- export class CdpRefusedError extends Error {
64
- code = "CDP_REFUSED";
65
- }
66
- /** What the browser answered a passthrough call with, when it was an error. */
67
- export class CdpCallError extends Error {
68
- code = "CDP_ERROR";
69
- }
70
- /**
71
- * Methods the passthrough will not send.
72
- *
73
- * `Fetch` is the run's request interception, `Target` its view of the
74
- * browser's tabs and workers, and the rest end the page or the browser. Each
75
- * would break the run itself rather than tell anyone anything about the page.
76
- */
77
- const CDP_REFUSED = [
78
- "Fetch.",
79
- "Target.",
80
- "Browser.close",
81
- "Browser.crash",
82
- "Page.close",
83
- "Page.crash",
84
- ];
85
- /** A passthrough call may be anything, including a slow one. */
86
- const CDP_PASSTHROUGH_MS = 30_000;
87
- const PANEL_OP_MS = PANEL_APPEAR_MS + 5000;
88
- export class NoBrowserError extends Error {
89
- code = "BROWSER_UNAVAILABLE";
90
- }
91
- export class BadUrlError extends Error {
92
- code = "BAD_URL";
93
- }
94
- export class NoPageError extends Error {
95
- code = "NO_PAGE";
96
- constructor(message = "This run has no page open.") {
97
- super(message);
98
- }
99
- }
100
- export class PageEvaluationError extends Error {
101
- expression;
102
- code = "PAGE_EVALUATION_FAILED";
103
- constructor(message, expression) {
104
- super(message);
105
- this.expression = expression;
106
- }
107
- }
108
- /** A CDP call that did not answer. Names the method, which is the whole lead. */
109
- export class CdpTimeoutError extends Error {
110
- method;
111
- code = "CDP_TIMEOUT";
112
- constructor(method, ms) {
113
- super(`CDP ${method} did not answer within ${ms}ms — the page may be navigating (a service-worker reinstall does that), or the renderer is stuck`);
114
- this.method = method;
115
- }
116
- }
117
- /** `work`, or a {@link CdpTimeoutError} naming `method` once `ms` has passed. */
118
- function bounded(work, method, ms) {
119
- let timer;
120
- return Promise.race([
121
- work,
122
- new Promise((_, reject) => {
123
- timer = setTimeout(() => reject(new CdpTimeoutError(method, ms)), ms);
124
- timer.unref();
125
- }),
126
- ]).finally(() => clearTimeout(timer));
127
- }
128
- /**
129
- * The page's JavaScript thread is stopped in a debugger.
130
- *
131
- * Its own code because the cure is not the one for a failed evaluation: nothing
132
- * that waits on the page will answer until the pause ends, whoever holds it —
133
- * this run's `sk onboarding debug`, a switch left lit in the devtools panel, a breakpoint
134
- * in DevTools' Sources panel.
135
- */
136
- export class PagePausedError extends PageEvaluationError {
137
- code = "PAGE_PAUSED";
138
- constructor(expression) {
139
- super("the page is paused in the debugger, so nothing that waits on it can answer — `sk onboarding debug status` says who holds the pause, `sk onboarding debug release` gets the page running", expression);
140
- }
141
- }
142
- /**
143
- * Holds the browser and page a run opened, so something other than `run()` can
144
- * reach them.
145
- *
146
- * `OnboardingService.run` keeps its browser and page as locals, which is right
147
- * for the run itself and useless for anything outside it. This is the seam: the
148
- * run attaches when the page is ready and detaches when it goes, and the
149
- * control handlers see an evaluator whose answer to "there is no page" is a
150
- * typed error rather than a puppeteer stack trace.
151
- */
152
- export class BrowserSession {
153
- cdpAnswerMs;
154
- browser;
155
- page;
156
- cdp;
157
- context;
158
- /** The emulation in force, re-applied whenever the page's session is remade. */
159
- emulation;
160
- /**
161
- * One session per service worker carrying the user-agent override. Kept
162
- * open: an override lasts as long as the session that set it.
163
- */
164
- workers = [];
165
- /** The browser-wide auto-attach that overrides every service worker as it starts. */
166
- workerAttach;
167
- /** One session per other tab a caller has asked about, made on demand. */
168
- tabSessions = new Map();
169
- /**
170
- * The passthrough's own CDP session: what a caller enables there stays on
171
- * between calls, and cannot touch the session the debugger and the preloads
172
- * live in.
173
- */
174
- passthrough;
175
- /**
176
- * Built here rather than injected: the registry needs a transport, and this
177
- * is the only thing that has one. Handing it out through
178
- * {@link BrowserController} keeps the ownership in one direction.
179
- */
180
- preloads = new PreloadRegistry(this, () => this.refreshTabMark());
181
- debug = new DebugSession(this, this.preloads, () => Boolean(this.context?.extensionArms?.()), () => this.markReleased());
182
- /**
183
- * @param cdpAnswerMs how long a CDP call may take — {@link CDP_ANSWER_MS}
184
- * unless a spec needs to see a hang in less than four seconds
185
- */
186
- constructor(cdpAnswerMs = CDP_ANSWER_MS) {
187
- this.cdpAnswerMs = cdpAnswerMs;
188
- }
189
- /** When `sk onboarding debug release` last ran, for every report after it. */
190
- releasedAt;
191
- markReleased() {
192
- this.releasedAt = new Date().toISOString();
193
- this.refreshTabMark();
194
- }
195
- /**
196
- * Subscriptions that must outlive the session they were made on.
197
- *
198
- * A CDP session takes its listeners with it when it detaches, and the page
199
- * remakes one. A pause handler that did not survive that would miss the pause
200
- * it was waiting for, and report a timeout as though nothing had happened.
201
- */
202
- listeners = [];
203
- get available() {
204
- return Boolean(this.page && !this.page.isClosed());
205
- }
206
- /**
207
- * Put the reported agent activity in step with what is installed.
208
- *
209
- * Fire and forget on purpose. The report is cosmetic and the run is not: a
210
- * headless run has no tab strip to colour and an extension that never loaded
211
- * has nothing to read this, and neither is a reason for an injection to fail.
212
- */
213
- refreshTabMark() {
214
- const report = this.context?.reportAgentActivity;
215
- if (!report) {
216
- return;
217
- }
218
- const { count, origins } = this.preloads.summary();
219
- void report(count === 0 ? null : labelFor(count, origins),
220
- // Sent with every report rather than on arming alone: the panel's
221
- // switches are a mirror, and a mirror that only updates on the way in
222
- // shows a breakpoint as armed after it has been disarmed.
223
- this.debug.armedBreakpoints, this.releasedAt).catch(() => {
224
- // A run whose extension never loaded cannot show this, and that is not a
225
- // reason for an injection to fail. The terminal still carries the fact.
226
- });
227
- }
228
- /** {@link PreloadTransport}'s name for {@link available}. */
229
- get pageAvailable() {
230
- return this.available;
231
- }
232
- attach(browser, page, context) {
233
- this.browser = browser;
234
- this.page = page;
235
- this.cdp = undefined;
236
- this.context = context;
237
- }
238
- /**
239
- * The run is over, or its page has gone.
240
- *
241
- * The preloads go with it. Every registration lives in a CDP session that is
242
- * about to stop existing, so keeping the entries would mean `list` reporting
243
- * scripts on a dead run that can never run again.
244
- */
245
- detach() {
246
- for (const child of this.tabSessions.values()) {
247
- child.detach();
248
- }
249
- this.tabSessions.clear();
250
- this.passthrough = undefined;
251
- this.forgetWorkers();
252
- this.emulation = undefined;
253
- this.browser = undefined;
254
- this.page = undefined;
255
- this.cdp = undefined;
256
- this.context = undefined;
257
- this.preloads.dispose();
258
- this.debug.dispose();
259
- }
260
- url() {
261
- return this.available ? this.page.url() : null;
262
- }
263
- /** {@link DebugTransport}: a named CDP call, for {@link DebugSession} only. */
264
- async send(method, params = {}, ms) {
265
- return this.call(method, params, ms);
266
- }
267
- /**
268
- * A CDP call on the page's session, bounded — getting the session included,
269
- * since remaking one re-applies every preload.
270
- */
271
- call(method, params = {}, ms = this.cdpAnswerMs) {
272
- return bounded((async () => {
273
- const session = await this.cdpSession();
274
- return session.send(method, params);
275
- })(), method, ms);
276
- }
277
- /** {@link DebugTransport}: a subscription that survives a remade session. */
278
- onCdp(event, handler) {
279
- this.listeners.push({ event, handler });
280
- this.cdp?.on(event, handler);
281
- }
282
- /**
283
- * Reload, without the origin check `navigate` applies.
284
- *
285
- * A reload cannot leave the origin by definition, and `arm` needs one: a
286
- * preload only runs at document start, so arming without reloading arms for
287
- * a load that has already happened.
288
- */
289
- async reload() {
290
- this.require();
291
- await this.send("Page.reload");
292
- }
293
- /** Pin the viewport, for {@link runViewportSweep}. */
294
- async resize(width, height) {
295
- this.require();
296
- await this.send("Emulation.setDeviceMetricsOverride", {
297
- width,
298
- height,
299
- deviceScaleFactor: 1,
300
- mobile: false,
301
- });
302
- }
303
- async clearResize() {
304
- // A sweep run under an emulation hands the page back emulated, not bare.
305
- if (this.emulation) {
306
- await this.applyEmulation(await this.cdpSession()).catch(() => undefined);
307
- return;
308
- }
309
- await this.send("Emulation.clearDeviceMetricsOverride").catch(() => {
310
- // A page that has gone has no override left to clear, and failing the
311
- // sweep's cleanup over that would hide whatever actually went wrong.
312
- });
313
- }
314
- /**
315
- * Enable Network on every target, now and as they appear.
316
- *
317
- * A popup is its own target, so this attaches per target rather than per
318
- * page. The race is real and worth naming: a target that navigates before
319
- * the session is up would not be seen, and the first hop is the one that
320
- * matters most — which is why the sweep discards what it caught before the
321
- * trigger rather than relying on timing.
322
- */
323
- async collectDocumentRequests(onHit) {
324
- const browser = this.browser;
325
- if (!browser) {
326
- throw new NoBrowserError("this run did not lend its browser to the control socket");
327
- }
328
- const sessions = [];
329
- const mainTarget = this.page?.target();
330
- const attach = async (target) => {
331
- if (target.type() !== "page" && target.type() !== "other") {
332
- return;
333
- }
334
- let session;
335
- try {
336
- session = await target.createCDPSession();
337
- }
338
- catch {
339
- // Some targets refuse a session. One that will not talk cannot be a
340
- // source of hops either.
341
- return;
342
- }
343
- sessions.push(session);
344
- const main = target === mainTarget;
345
- await bounded(session.send("Network.enable"), "Network.enable", this.cdpAnswerMs).catch(() => undefined);
346
- session.on("Network.requestWillBeSent", (event) => {
347
- if (event.type !== "Document") {
348
- return;
349
- }
350
- // The redirect is the hop: a 302 to an auth path is the url that has
351
- // to be scoped, and it is only ever reported as someone else's
352
- // redirectResponse.
353
- if (event.redirectResponse) {
354
- onHit({
355
- url: event.redirectResponse.url,
356
- status: event.redirectResponse.status,
357
- main,
358
- });
359
- }
360
- onHit({ url: event.request.url, status: null, main });
361
- });
362
- session.on("Network.responseReceived", (event) => {
363
- if (event.type === "Document") {
364
- onHit({
365
- url: event.response.url,
366
- status: event.response.status,
367
- main,
368
- });
369
- }
370
- });
371
- };
372
- const onCreated = (target) => void attach(target);
373
- browser.on("targetcreated", onCreated);
374
- await Promise.all(browser.targets().map((target) => attach(target)));
375
- return async () => {
376
- browser.off("targetcreated", onCreated);
377
- await Promise.all(sessions.map((session) => session.detach().catch(() => undefined)));
378
- };
379
- }
380
- /** `Page.addScriptToEvaluateOnNewDocument`, for {@link PreloadRegistry}. */
381
- async addScript(source) {
382
- const { identifier } = await this.call("Page.addScriptToEvaluateOnNewDocument", { source });
383
- return identifier;
384
- }
385
- async removeScript(identifier) {
386
- await this.call("Page.removeScriptToEvaluateOnNewDocument", {
387
- identifier,
388
- });
389
- }
390
- async evaluate(expression, timeoutMs = DEFAULT_EVAL_TIMEOUT_MS) {
391
- if (!this.available) {
392
- throw new NoPageError();
393
- }
394
- const session = await this.cdpSession();
395
- // Runtime.evaluate, never page.evaluate: CDP keeps servicing requests while
396
- // the inspector is paused, which is the state this has to survive.
397
- const result = (await Promise.race([
398
- session.send("Runtime.evaluate", {
399
- expression,
400
- returnByValue: true,
401
- awaitPromise: true,
402
- }),
403
- timeout(timeoutMs, expression),
404
- // An awaited evaluation never settles on a paused page. Without this
405
- // check the caller waits out the whole timeout and is then told the page
406
- // "may be paused, or busy" — the one thing this can find out for sure.
407
- this.failWhenPaused(expression),
408
- ]));
409
- if (result.exceptionDetails) {
410
- throw new PageEvaluationError(result.exceptionDetails.exception?.description ??
411
- result.exceptionDetails.text, expression);
412
- }
413
- return result.result?.value;
414
- }
415
- /**
416
- * Whether the page's JavaScript thread is running, paused or stuck.
417
- *
418
- * Two evaluations, because a pause is the one state that answers one and not
419
- * the other: a plain value comes back from the inspector's nested loop, a
420
- * settled promise does not, since its continuation is a microtask. It needs
421
- * no debugger attached, so it sees a pause held by anyone. Null without a
422
- * page.
423
- */
424
- async threadState() {
425
- if (!this.available) {
426
- return null;
427
- }
428
- const session = await this.cdpSession();
429
- const answers = (work, ms) => Promise.race([
430
- work.then(() => true, () => true),
431
- new Promise((resolve) => setTimeout(() => resolve(false), ms).unref()),
432
- ]);
433
- const plain = await answers(session.send("Runtime.evaluate", {
434
- expression: "1",
435
- returnByValue: true,
436
- }), THREAD_ANSWER_MS);
437
- if (!plain) {
438
- return "unresponsive";
439
- }
440
- // Left pending when the page is paused, and harmless: it settles, and is
441
- // dropped, the moment the page resumes.
442
- const settled = await answers(session.send("Runtime.evaluate", {
443
- expression: "Promise.resolve(1)",
444
- returnByValue: true,
445
- awaitPromise: true,
446
- }), MICROTASK_ANSWER_MS);
447
- return settled ? "running" : "paused";
448
- }
449
- /** Rejects with {@link PagePausedError} when a slow evaluation is due to a pause; never resolves otherwise. */
450
- failWhenPaused(expression) {
451
- return new Promise((_, reject) => {
452
- setTimeout(() => {
453
- this.threadState().then((state) => {
454
- if (state === "paused") {
455
- reject(new PagePausedError(expression));
456
- }
457
- }, () => undefined);
458
- }, PAUSE_CHECK_AFTER_MS).unref();
459
- });
460
- }
461
- /**
462
- * What service workers are on this origin, and whose build they are.
463
- *
464
- * Read out of the run's tracker rather than off the page, because the
465
- * question that matters — is the *deployed* worker in charge — cannot be
466
- * answered by `navigator.serviceWorker.getRegistrations()`. See
467
- * {@link ServiceWorkerTracker}.
468
- */
469
- async state() {
470
- const context = this.require();
471
- const url = this.url();
472
- return {
473
- url,
474
- // The page url, because the active worker is the one whose scope covers
475
- // it — see {@link ServiceWorkerTracker.state}.
476
- serviceWorkers: context.serviceWorkers.state(url),
477
- emulation: this.emulation?.state ?? null,
478
- };
479
- }
480
- /**
481
- * Present the page as a device until switched off — what DevTools' device
482
- * toolbar does, and the reason it is not enough on its own here.
483
- *
484
- * Speed Kit decides the device in its service worker, and an override set on
485
- * the page never reaches a worker. So the user agent is overridden on every
486
- * service worker target too, now and as they appear, and read back from each
487
- * one: the answer says whether the worker sees the device, rather than
488
- * assuming it does.
489
- */
490
- async emulate(request) {
491
- this.require();
492
- if (request.device === "off") {
493
- const session = await this.cdpSession();
494
- await this.clearEmulation(session);
495
- await this.serveWorkerAs(null);
496
- const reloaded = await this.reloadUnder(request);
497
- return {
498
- url: this.url(),
499
- did: `switched device emulation off${reloaded}`,
500
- emulation: null,
501
- serviceWorkers: [],
502
- };
503
- }
504
- // The same profile as `--device`, so a run started on a device and one switched to it match.
505
- const device = onboardingDeviceEmulation((await this.browser?.version()) ?? "", request.device);
506
- const preset = device.viewport;
507
- const state = {
508
- device: request.device,
509
- width: request.width ?? preset.width,
510
- height: request.height ?? preset.height,
511
- dpr: request.dpr ?? preset.deviceScaleFactor ?? 1,
512
- mobile: preset.isMobile ?? false,
513
- touch: request.touch ?? preset.hasTouch ?? false,
514
- userAgent: request.userAgent ?? device.userAgent ?? null,
515
- since: new Date().toISOString(),
516
- };
517
- // The session first: making one re-applies whatever emulation is set, and
518
- // setting it before would apply this one twice.
519
- const session = await this.cdpSession();
520
- this.emulation = {
521
- state,
522
- metadata: request.userAgent ? undefined : device.metadata,
523
- };
524
- await this.applyEmulation(session);
525
- // Before the reinstall, so the worker it starts is held until it is overridden.
526
- await this.emulateWorkers();
527
- await this.serveWorkerAs(state.userAgent);
528
- const reloaded = await this.reloadUnder(request);
529
- // The worker that ends up active is not always the one the reinstall
530
- // produced: a short-lived registration can come first, and the run's own
531
- // worker activates after it — unemulated. A second install reaches it, so
532
- // the answer does that itself instead of leaving it to the caller.
533
- // Waiting for a worker to activate only makes sense after a load.
534
- const settle = request.reload !== false;
535
- let serviceWorkers = await this.workerUserAgents(settle);
536
- let installs = 1;
537
- if (request.reload !== false &&
538
- serviceWorkers.some((worker) => worker.active && !worker.emulated)) {
539
- await this.serveWorkerAs(state.userAgent);
540
- await this.reloadUnder(request);
541
- serviceWorkers = await this.workerUserAgents(settle);
542
- installs = 2;
543
- }
544
- return {
545
- url: this.url(),
546
- did: `emulating ${state.device}, ${state.width}×${state.height} at DPR ${state.dpr}${reloaded}${installs === 2 ? ", worker installed twice to reach the active one" : ""}`,
547
- emulation: state,
548
- serviceWorkers,
549
- };
550
- }
551
- /** A PNG of the viewport, the whole page, or one element. */
552
- async screenshot(request) {
553
- this.require();
554
- // Everything here goes through CDP's DOM and Page domains, never a page
555
- // evaluation: those keep answering while the page is paused in the
556
- // debugger, and a screenshot at a breakpoint is the one most worth having.
557
- const metrics = await this.send("Page.getLayoutMetrics");
558
- const scroll = metrics.cssVisualViewport;
559
- let clip;
560
- if (request.selector) {
561
- const box = await this.boxOf(await this.nodeFor({ selector: request.selector }));
562
- clip = {
563
- x: box.x + scroll.pageX,
564
- y: box.y + scroll.pageY,
565
- width: box.width,
566
- height: box.height,
567
- scale: 1,
568
- };
569
- }
570
- else if (request.fullPage) {
571
- clip = {
572
- x: 0,
573
- y: 0,
574
- width: metrics.cssContentSize.width,
575
- height: metrics.cssContentSize.height,
576
- scale: 1,
577
- };
578
- }
579
- const { data } = await this.call("Page.captureScreenshot", {
580
- format: "png",
581
- ...(clip ? { clip, captureBeyondViewport: true } : {}),
582
- }, SCREENSHOT_MS);
583
- const viewport = clip ?? {
584
- width: metrics.cssLayoutViewport.clientWidth,
585
- height: metrics.cssLayoutViewport.clientHeight,
586
- };
587
- return {
588
- data,
589
- width: Math.round(viewport.width),
590
- height: Math.round(viewport.height),
591
- emulation: this.emulation?.state ?? null,
592
- };
593
- }
594
- async tabs() {
595
- const pages = await this.openPages();
596
- const tabs = [];
597
- for (const [index, page] of pages.entries()) {
598
- tabs.push({
599
- index,
600
- url: page.url(),
601
- // Bounded: a tab paused in the debugger never answers a title.
602
- title: await bounded(page.title(), "Page.title", this.cdpAnswerMs).catch(() => null),
603
- main: page === this.page,
604
- });
605
- }
606
- return tabs;
607
- }
608
- /**
609
- * The controller for another tab — a popup a login opened, a second window.
610
- *
611
- * Each tab gets a session of its own, so what is injected, armed or emulated
612
- * in one stays there, the way Chrome scopes it anyway. It shares the run's
613
- * context, but reports no tab mark: that belongs to the run's own page.
614
- */
615
- async tab(selector) {
616
- const context = this.require();
617
- const pages = await this.openPages();
618
- const page = /^\d+$/.test(selector)
619
- ? pages[Number(selector)]
620
- : pages.find((candidate) => candidate.url().includes(selector));
621
- if (!page) {
622
- const tabs = await this.tabs();
623
- throw new NoSuchTabError(`no tab matches "${selector}" — there are ${tabs.length}: ${tabs
624
- .map((tab) => `${tab.index} ${tab.url}`)
625
- .join(", ")}`, tabs);
626
- }
627
- if (page === this.page) {
628
- return this;
629
- }
630
- let child = this.tabSessions.get(page);
631
- if (!child?.available) {
632
- child = new BrowserSession(this.cdpAnswerMs);
633
- child.attach(this.browser, page, {
634
- ...context,
635
- reportAgentActivity: undefined,
636
- });
637
- this.tabSessions.set(page, child);
638
- }
639
- return child;
640
- }
641
- /**
642
- * One CDP call, without a debug port: the run already holds the connection.
643
- *
644
- * On a session of its own, so a domain a caller enables stays enabled
645
- * between calls without reaching the run's own session. Refuses what would
646
- * break the run — see {@link CDP_REFUSED}.
647
- */
648
- async rawCdp(method, params = {}) {
649
- this.require();
650
- if (CDP_REFUSED.some((refused) => method.startsWith(refused))) {
651
- throw new CdpRefusedError(`${method} would break the run itself — the request interception, its view of the tabs, or the browser — so it is not sent`);
652
- }
653
- if (!this.passthrough || this.passthrough.detached) {
654
- this.passthrough = await bounded(this.page.target().createCDPSession(), "Target.attachToTarget", this.cdpAnswerMs);
655
- }
656
- try {
657
- const result = await bounded(this.passthrough.send(method, params), method, CDP_PASSTHROUGH_MS);
658
- return { method, result, url: this.url() };
659
- }
660
- catch (error) {
661
- if (error instanceof CdpTimeoutError) {
662
- throw error;
663
- }
664
- throw new CdpCallError(`${method}: ${error instanceof Error ? error.message : String(error)}`);
665
- }
666
- }
667
- /**
668
- * Click an element the way a person does: scrolled into view, then a mouse
669
- * press and release at its centre, dispatched by the browser. Under touch
670
- * emulation it is a tap instead: Chrome makes the touchstart, touchend,
671
- * mousedown, mouseup and click from it, as on a phone.
672
- *
673
- * Not `element.click()`: that event is untrusted, and a consent banner or an
674
- * add-to-cart handler that checks `isTrusted` ignores it — which is exactly
675
- * the tracking this exists to verify.
676
- *
677
- * Not a mouse press under touch emulation: `--device` turns on
678
- * `Emulation.setEmitTouchEventsForMouse`, and Chrome then never answers
679
- * `Input.dispatchMouseEvent` for the press.
680
- */
681
- async click(target) {
682
- this.require();
683
- const nodeId = await this.nodeFor(target);
684
- await this.send("DOM.scrollIntoViewIfNeeded", { nodeId }).catch(() => undefined);
685
- const box = await this.boxOf(nodeId);
686
- const x = Math.round(box.x + box.width / 2);
687
- const y = Math.round(box.y + box.height / 2);
688
- const before = this.url();
689
- // The state of `browser emulate` wins over the run's `--device`: it is the later one.
690
- const input = (this.emulation?.state.touch ?? this.context?.touch) ? "touch" : "mouse";
691
- if (input === "touch") {
692
- // The tap of the ux-report journeys: a finger held for 60 ms.
693
- await this.send("Input.dispatchTouchEvent", {
694
- type: "touchStart",
695
- touchPoints: [{ x, y, radiusX: 4, radiusY: 4, force: 1, id: 1 }],
696
- });
697
- await new Promise((resolve) => setTimeout(resolve, 60));
698
- await this.send("Input.dispatchTouchEvent", {
699
- type: "touchEnd",
700
- touchPoints: [],
701
- });
702
- }
703
- else {
704
- for (const type of ["mouseMoved", "mousePressed", "mouseReleased"]) {
705
- await this.send("Input.dispatchMouseEvent", {
706
- type,
707
- x,
708
- y,
709
- button: type === "mouseMoved" ? "none" : "left",
710
- clickCount: type === "mouseMoved" ? 0 : 1,
711
- });
712
- }
713
- }
714
- const { node } = await this.send("DOM.describeNode", { nodeId }).catch(() => ({ node: undefined }));
715
- return {
716
- url: this.url(),
717
- did: `${input === "touch" ? "tapped" : "clicked"} ${target.selector ?? `"${target.text}"`} at ${x},${y}`,
718
- element: node ? describeNode(node) : null,
719
- at: { x, y },
720
- input,
721
- urlBefore: before,
722
- };
723
- }
724
- /**
725
- * The element a selector or a text names, through CDP's DOM domain: it
726
- * answers while the page is paused, where a page evaluation cannot.
727
- */
728
- async nodeFor(target) {
729
- const { root } = await this.send("DOM.getDocument", { depth: 0 });
730
- if (target.selector) {
731
- const { nodeId } = await this.send("DOM.querySelector", { nodeId: root.nodeId, selector: target.selector });
732
- if (nodeId) {
733
- return nodeId;
734
- }
735
- // A selector stops at a shadow root. Speed Kit's SSR tree lives in one —
736
- // SK-SHADOW-APP-ROOT at BP3 — so the page's own h1 is not in the light
737
- // DOM at all exactly where it matters most.
738
- const shadowRoots = await this.shadowRoots();
739
- for (const shadowRoot of shadowRoots) {
740
- const inShadow = await this.send("DOM.querySelector", { nodeId: shadowRoot, selector: target.selector }).catch(() => ({ nodeId: 0 }));
741
- if (inShadow.nodeId) {
742
- return inShadow.nodeId;
743
- }
744
- }
745
- throw new NoSuchElementError(`nothing on the page matches ${target.selector}, in the light DOM or in its ${shadowRoots.length} shadow root${shadowRoots.length === 1 ? "" : "s"}`);
746
- }
747
- // Links, buttons and anything acting as one, by the text a person reads.
748
- const text = JSON.stringify(target.text ?? "");
749
- const query = `//*[self::a or self::button or @role="button" or self::summary or self::label or (self::input and (@type="submit" or @type="button"))][contains(normalize-space(.), ${text}) or contains(@aria-label, ${text}) or contains(@value, ${text})]`;
750
- const { searchId, resultCount } = await this.send("DOM.performSearch", { query });
751
- try {
752
- if (resultCount === 0) {
753
- throw new NoSuchElementError(`no link or button on the page reads "${target.text}"`);
754
- }
755
- const { nodeIds } = await this.send("DOM.getSearchResults", { searchId, fromIndex: 0, toIndex: 1 });
756
- return nodeIds[0];
757
- }
758
- finally {
759
- await this.send("DOM.discardSearchResults", { searchId }).catch(() => undefined);
760
- }
761
- }
762
- /**
763
- * Every shadow root in the page, nested ones included, as node ids.
764
- *
765
- * The whole tree with `pierce`, which reissues the node ids — so this is
766
- * asked only once the light DOM has come up empty.
767
- */
768
- async shadowRoots() {
769
- const { root } = await this.send("DOM.getDocument", { depth: -1, pierce: true });
770
- const found = [];
771
- const walk = (node) => {
772
- for (const shadowRoot of node.shadowRoots ?? []) {
773
- found.push(shadowRoot.nodeId);
774
- walk(shadowRoot);
775
- }
776
- for (const child of node.children ?? []) {
777
- walk(child);
778
- }
779
- if (node.contentDocument) {
780
- walk(node.contentDocument);
781
- }
782
- };
783
- walk(root);
784
- return found;
785
- }
786
- /** The element's border box, in viewport coordinates. */
787
- async boxOf(nodeId) {
788
- const { model } = await this.send("DOM.getBoxModel", { nodeId }).catch(() => ({ model: undefined }));
789
- if (!model || model.width === 0 || model.height === 0) {
790
- throw new NoSuchElementError("the element has no size — it is hidden or not laid out");
791
- }
792
- const [x1, y1, x2, , , y3] = model.border;
793
- return { x: x1, y: y1, width: x2 - x1, height: y3 - y1 };
794
- }
795
- /** The tabs a person would call tabs: no DevTools, no extension pages. */
796
- async openPages() {
797
- const pages = (await this.browser?.pages()) ?? [];
798
- return pages.filter((page) => !page.isClosed() &&
799
- !page.url().startsWith("devtools://") &&
800
- !page.url().startsWith("chrome-extension://"));
801
- }
802
- /** The device metrics, touch and user agent, on the page's session. */
803
- async applyEmulation(session) {
804
- const emulation = this.emulation;
805
- if (!emulation) {
806
- return;
807
- }
808
- const { state, metadata } = emulation;
809
- const send = (method, params) => bounded(session.send(method, params), method, this.cdpAnswerMs);
810
- await send("Emulation.setDeviceMetricsOverride", {
811
- width: state.width,
812
- height: state.height,
813
- deviceScaleFactor: state.dpr,
814
- mobile: state.mobile,
815
- screenWidth: state.width,
816
- screenHeight: state.height,
817
- screenOrientation: state.width > state.height
818
- ? { type: "landscapePrimary", angle: 90 }
819
- : { type: "portraitPrimary", angle: 0 },
820
- });
821
- await setTouch(send, state.touch);
822
- await this.context?.setDeviceTouch?.(state.touch);
823
- if (state.userAgent) {
824
- await send("Emulation.setUserAgentOverride", {
825
- userAgent: state.userAgent,
826
- ...(metadata ? { userAgentMetadata: metadata } : {}),
827
- });
828
- }
829
- }
830
- async clearEmulation(session) {
831
- const had = this.emulation;
832
- this.emulation = undefined;
833
- this.forgetWorkers();
834
- if (!had) {
835
- return;
836
- }
837
- const send = (method, params = {}) => bounded(session.send(method, params), method, this.cdpAnswerMs).catch(() => undefined);
838
- // Back to the start, not to bare Chrome: the page shares one screen and one touch state with `--device`.
839
- const start = this.context?.deviceMetrics;
840
- await (start
841
- ? send("Emulation.setDeviceMetricsOverride", start)
842
- : send("Emulation.clearDeviceMetricsOverride"));
843
- await setTouch(send, this.context?.touch === true);
844
- await this.context?.setDeviceTouch?.(this.context.touch === true);
845
- // An empty user agent is CDP's way of saying "no override".
846
- await send("Emulation.setUserAgentOverride", { userAgent: "" });
847
- }
848
- /**
849
- * Serve Speed Kit's worker with this user agent, and reinstall it so the
850
- * worker that runs is that one. A worker already installed keeps the script it
851
- * was installed from, so without the reinstall the override would wait for
852
- * Chrome's next update check.
853
- */
854
- async serveWorkerAs(userAgent) {
855
- const context = this.require();
856
- if (!context.setWorkerUserAgent) {
857
- return;
858
- }
859
- context.setWorkerUserAgent(userAgent);
860
- await context.reinstall();
861
- }
862
- /**
863
- * Override the user agent and its client hints on every service worker, and
864
- * on each one that starts later, before its first line runs: a stopped worker
865
- * has no target, and the next fetch starts it fresh.
866
- */
867
- async emulateWorkers() {
868
- const browser = this.browser;
869
- this.forgetWorkers();
870
- if (!browser || !this.emulation?.state.userAgent) {
871
- return;
872
- }
873
- this.workerAttach = await bounded(onEveryTarget(browser, (session, targetInfo) => this.overrideWorker(session, targetInfo), [{ type: "service_worker" }]), "Target.setAutoAttach", this.cdpAnswerMs);
874
- }
875
- async overrideWorker(session, { url, targetId }) {
876
- const emulation = this.emulation;
877
- if (!emulation?.state.userAgent) {
878
- return;
879
- }
880
- this.workers.push({ session, url, targetId });
881
- await bounded(session.send("Network.setUserAgentOverride", {
882
- userAgent: emulation.state.userAgent,
883
- ...(emulation.metadata
884
- ? { userAgentMetadata: emulation.metadata }
885
- : {}),
886
- }), "Network.setUserAgentOverride", this.cdpAnswerMs);
887
- }
888
- /**
889
- * What the worker in charge of the page says its user agent is, read in the
890
- * worker, once one is active.
891
- *
892
- * Only that one: it decides the device. A run collects stale registrations,
893
- * and asking each of them, one stopped worker after the other, ran past the
894
- * op's budget. An empty list means no worker is in charge yet.
895
- */
896
- async workerUserAgents(settle) {
897
- const wanted = this.emulation?.state.userAgent ?? null;
898
- const active = await this.activeWorker(settle ? WORKER_SETTLE_MS : 0);
899
- if (!active) {
900
- return [];
901
- }
902
- const known = this.workers.find((worker) => !worker.session.detached &&
903
- (active.targetId
904
- ? worker.targetId === active.targetId
905
- : worker.url === active.scriptURL));
906
- const target = known
907
- ? undefined
908
- : (this.browser?.targets() ?? []).find((one) => one.type() === "service_worker" && one.url() === active.scriptURL);
909
- const session = known?.session ??
910
- (target &&
911
- (await bounded(target.createCDPSession(), "Target.attachToTarget", this.cdpAnswerMs).catch(() => undefined)));
912
- if (session && !known) {
913
- this.workers.push({ session, url: active.scriptURL });
914
- }
915
- const userAgent = session
916
- ? await bounded(session.send("Runtime.evaluate", {
917
- expression: "navigator.userAgent",
918
- returnByValue: true,
919
- }), "Runtime.evaluate", this.cdpAnswerMs)
920
- .then((result) => String(result.result?.value ??
921
- "") || null)
922
- .catch(() => null)
923
- : null;
924
- return [
925
- {
926
- url: active.scriptURL,
927
- userAgent,
928
- emulated: wanted !== null && userAgent === wanted,
929
- active: true,
930
- },
931
- ];
932
- }
933
- /**
934
- * The version of the worker in charge of the page, waiting briefly for one
935
- * to activate after a reinstall. Null when none did in time.
936
- */
937
- async activeWorker(waitMs) {
938
- const context = this.require();
939
- const deadline = Date.now() + waitMs;
940
- for (;;) {
941
- const state = context.serviceWorkers.state(this.url());
942
- const version = state.versions.find((one) => one.versionId === state.activeVersionId);
943
- if (version) {
944
- return version;
945
- }
946
- if (Date.now() > deadline) {
947
- return null;
948
- }
949
- await new Promise((resolve) => setTimeout(resolve, 250).unref());
950
- }
951
- }
952
- forgetWorkers() {
953
- void this.workerAttach?.detach().catch(() => undefined);
954
- this.workerAttach = undefined;
955
- for (const { session } of this.workers) {
956
- void session.detach().catch(() => undefined);
957
- }
958
- this.workers = [];
959
- }
960
- /**
961
- * Load the page again, as a navigation: a document already loaded was laid
962
- * out, detected and served as the old device.
963
- */
964
- async reloadUnder(request) {
965
- if (request.reload === false || !this.page) {
966
- return " — the page is still the one loaded before; navigate to see it as that device";
967
- }
968
- try {
969
- await this.page.goto(this.page.url(), { timeout: NAVIGATION_TIMEOUT_MS });
970
- return ", page loaded again";
971
- }
972
- catch (error) {
973
- if (!isTimeout(error)) {
974
- throw error;
975
- }
976
- return `, page loading again (not finished after ${NAVIGATION_TIMEOUT_MS}ms)`;
977
- }
978
- }
979
- /**
980
- * Put the origin back to a known state.
981
- *
982
- * `cache` clears the caches and nothing else, which is the one to reach for:
983
- * a logged-in session costs real effort to re-establish and a custom
984
- * variation often needs one, so wiping cookies to test a caching change
985
- * throws away more than it proves. `all` is the full clean start the run
986
- * performs for itself — storage, cookies, and the worker registration with
987
- * them.
988
- */
989
- async reset(scope) {
990
- this.require();
991
- // The origin the page is on, not the one the run started on. Storage in
992
- // Chrome is partitioned per origin, so a reset aimed at the wrong one
993
- // reports success and leaves the stale service-worker cache exactly where
994
- // it was — after which a config change looks like it never landed.
995
- const { origin, offApp } = this.targetOrigin();
996
- if (scope === "all") {
997
- await this.call("ServiceWorker.enable");
998
- await this.call("ServiceWorker.unregister", { scopeURL: origin }, SLOW_CDP_ANSWER_MS);
999
- await this.call("Storage.clearCookies");
1000
- // The tracker is deliberately not cleared here. Unregistering makes
1001
- // Chrome emit a registration update with `isDeleted`, and the tracker
1002
- // already records that — which is the better answer: "there was one and
1003
- // this reset removed it" rather than "there has never been one".
1004
- }
1005
- await this.call("Storage.clearDataForOrigin", { origin, storageTypes: scope === "all" ? "all" : "cache_storage" }, SLOW_CDP_ANSWER_MS);
1006
- // Injected scripts go too, whatever the scope. A reset is a promise that
1007
- // the origin is back to a known state, and a spy that survived it would be
1008
- // an unknown the caller has been told is not there.
1009
- const { removed } = await this.preloads.clear();
1010
- const parts = [
1011
- scope === "all"
1012
- ? `cleared every store on ${origin}, unregistered its service worker and dropped its cookies`
1013
- : `cleared cache storage on ${origin}, leaving cookies and the session intact`,
1014
- ];
1015
- if (removed.length > 0) {
1016
- parts.push(`removed ${removed.length} injected preload${removed.length === 1 ? "" : "s"}`);
1017
- }
1018
- if (offApp) {
1019
- // Said rather than silently assumed: the page is somewhere this app does
1020
- // not cover — mid-auth on an identity provider, most likely — so the
1021
- // caller's "the current origin" and this op's are not the same thing.
1022
- parts.push(`the page is on ${this.pageOrigin()}, which is not one of this app's origins, so the run's own (${origin}) was cleared instead`);
1023
- }
1024
- return { url: this.url(), did: parts.join(", and "), origin };
1025
- }
1026
- /**
1027
- * The origin a storage op should act on.
1028
- *
1029
- * The page's, when the app covers it. An app is regularly several domains and
1030
- * the run starts on one of them; scoping to that one is right exactly until
1031
- * someone navigates, which is the first thing anyone does.
1032
- */
1033
- targetOrigin() {
1034
- const context = this.require();
1035
- const base = normalise(context.origin);
1036
- const current = this.pageOrigin();
1037
- if (!current) {
1038
- return { origin: base, offApp: false };
1039
- }
1040
- if (current === base || this.appOrigins().includes(current)) {
1041
- return { origin: current, offApp: false };
1042
- }
1043
- return { origin: base, offApp: true };
1044
- }
1045
- pageOrigin() {
1046
- const url = this.url();
1047
- if (!url) {
1048
- return null;
1049
- }
1050
- try {
1051
- const parsed = new URL(url);
1052
- // `about:blank` and the rest parse fine and have the origin `"null"`,
1053
- // which is not a site and cannot be cleared. A page that has not gone
1054
- // anywhere yet is the same case as no page at all.
1055
- return parsed.protocol === "http:" || parsed.protocol === "https:"
1056
- ? parsed.origin
1057
- : null;
1058
- }
1059
- catch {
1060
- return null;
1061
- }
1062
- }
1063
- /** The app's origins, normalised, with the run's own always among them. */
1064
- appOrigins() {
1065
- const context = this.require();
1066
- const origins = [context.origin, ...(context.origins ?? [])]
1067
- .map(normalise)
1068
- .filter(Boolean);
1069
- return [...new Set(origins)];
1070
- }
1071
- /**
1072
- * Reinstall the local Speed Kit build through the install page.
1073
- *
1074
- * Delegated to the run, which owns the install page's address and the
1075
- * bookkeeping around navigating to it. This is the repair for a deployed
1076
- * worker that took over — going back through the install page puts the fetch
1077
- * back on the intercepted path.
1078
- */
1079
- async reinstallServiceWorker() {
1080
- const context = this.require();
1081
- await context.reinstall();
1082
- return {
1083
- url: this.url(),
1084
- did: "reinstalled Speed Kit through the install page",
1085
- };
1086
- }
1087
- /**
1088
- * Go somewhere this app covers.
1089
- *
1090
- * Any of the app's origins, not only the one the run started on: a customer
1091
- * with a second brand domain or a market per country is one app, and
1092
- * refusing its siblings would make the tool useless on exactly the setups
1093
- * that need it most. Anything else is still refused, because every storage op
1094
- * here is scoped to an origin and a page parked on a third party would make
1095
- * all of them quietly answer about the wrong site.
1096
- *
1097
- * A relative url resolves against the page's current origin, which is where
1098
- * the caller is looking.
1099
- */
1100
- async navigate(url, wait = "load", waitMs = NAVIGATION_TIMEOUT_MS) {
1101
- const started = Date.now();
1102
- // The page's origin when the app covers it, the run's own otherwise. A
1103
- // login flow regularly leaves the tab on an identity provider, and a
1104
- // relative url resolved against that is refused as off-app — when what
1105
- // was meant is the shop the run is on.
1106
- const { origin: base } = this.targetOrigin();
1107
- let target;
1108
- try {
1109
- target = new URL(url, base);
1110
- }
1111
- catch {
1112
- throw new BadUrlError(`${url} is not a url, absolute or relative`);
1113
- }
1114
- const allowed = this.appOrigins();
1115
- if (!allowed.includes(target.origin)) {
1116
- throw new BadUrlError(`${target.href} is not on an origin this app covers — this run drives ${allowed.join(", ")}`);
1117
- }
1118
- // A navigation that loads slowly is still a navigation. `goto` waits for
1119
- // the load event, and a customer page that takes longer than the control
1120
- // socket's patience used to surface as CONTROL_TIMEOUT on a page that had
1121
- // in fact moved — an error about something that worked. Bounded here and
1122
- // reported as what it is.
1123
- // A wait for a mark needs the new document only, not its load event.
1124
- let loaded = true;
1125
- try {
1126
- await this.page.goto(target.href, {
1127
- timeout: waitMs,
1128
- waitUntil: wait === "load" ? "load" : "domcontentloaded",
1129
- });
1130
- }
1131
- catch (error) {
1132
- if (!isTimeout(error)) {
1133
- throw error;
1134
- }
1135
- loaded = false;
1136
- }
1137
- const point = wait === "load"
1138
- ? undefined
1139
- : await this.waitForMark(wait, started + waitMs);
1140
- return {
1141
- url: this.url(),
1142
- did: (loaded || point
1143
- ? `navigated to ${target.href}`
1144
- : `navigated to ${target.href}, which had not finished loading after ${waitMs}ms — the page did move, so read from it as usual`) +
1145
- (point
1146
- ? point.reached
1147
- ? `; ${point.point} (${point.mark}) at ${point.atMs}ms`
1148
- : `; ${point.point} ${point.reason}`
1149
- : ""),
1150
- origin: target.origin,
1151
- ...(point ? { wait: point } : {}),
1152
- };
1153
- }
1154
- /**
1155
- * Looks at the page until `point`'s mark lands, or until it cannot land any more, or until
1156
- * `deadline`. Never pauses the page.
1157
- */
1158
- async waitForMark(point, deadline) {
1159
- let loadedAt;
1160
- let probe;
1161
- for (;;) {
1162
- probe = await this.call("Runtime.evaluate", { expression: WAIT_PROBE, returnByValue: true }, Math.max(500, Math.min(2000, deadline - Date.now())))
1163
- .then(({ result }) => JSON.parse(result?.value ?? "null"))
1164
- .catch(() => undefined);
1165
- if (probe) {
1166
- if (probe.readyState === "complete")
1167
- loadedAt ??= Date.now();
1168
- const decided = decideWait(point, probe, loadedAt === undefined ? undefined : Date.now() - loadedAt);
1169
- if (decided)
1170
- return decided;
1171
- }
1172
- if (Date.now() >= deadline) {
1173
- return {
1174
- point,
1175
- mark: WAIT_MARKS[point],
1176
- reached: false,
1177
- reason: probe
1178
- ? `not reached: timed out (document ${probe.readyState}, responseSource ${probe.responseSource ?? "none"})`
1179
- : "not reached: timed out, and the page did not answer",
1180
- };
1181
- }
1182
- await new Promise((resolve) => setTimeout(resolve, 100));
1183
- }
1184
- }
1185
- /**
1186
- * Bring the devtools extension's panel to the front, opening DevTools for
1187
- * the page if it is closed.
1188
- *
1189
- * Not read-only, although it changes nothing about the page by itself:
1190
- * DevTools being open does. A breakpoint switch lit in the panel pauses
1191
- * every load only while DevTools is open, and a ticked "Disable cache" in
1192
- * the Network panel only applies then — so opening it can change what the
1193
- * next measurement sees.
1194
- */
1195
- async showPanel() {
1196
- const context = this.require();
1197
- const extensionId = context.devtoolsExtensionId?.() ?? null;
1198
- if (!extensionId) {
1199
- throw new NoBrowserError("This run has no devtools extension loaded, so there is no Speed Kit panel to show. Set `chromeExtensionPaths` in the sk config.");
1200
- }
1201
- try {
1202
- const shown = await bounded(showDevtoolsPanel(this.page, extensionId, PANEL_APPEAR_MS), "DevTools panel", PANEL_OP_MS);
1203
- return {
1204
- url: this.url(),
1205
- did: shown.openedDevTools
1206
- ? "opened DevTools on the Speed Kit panel"
1207
- : "switched DevTools to the Speed Kit panel",
1208
- };
1209
- }
1210
- catch (error) {
1211
- if (error instanceof PanelNotFoundError) {
1212
- throw new NoBrowserError(`${error.message} — DevTools shows ${error.tabs.join(", ") || "no tabs at all"}`);
1213
- }
1214
- if (error instanceof CdpTimeoutError) {
1215
- throw error;
1216
- }
1217
- // The selection goes through DevTools' own internals, which a Chrome
1218
- // update is free to move. Said as such, so nobody debugs the run for it.
1219
- throw new NoBrowserError(`could not select the Speed Kit panel, most likely because this Chrome's DevTools internals differ from the ones sk knows: ${error instanceof Error ? error.message : String(error)}`);
1220
- }
1221
- }
1222
- /** The page and the run context, or the typed reason there is none. */
1223
- require() {
1224
- if (!this.available) {
1225
- throw new NoPageError();
1226
- }
1227
- if (!this.context) {
1228
- throw new NoBrowserError("This run did not lend its browser to the control socket — it is older than the browser ops, or started without one.");
1229
- }
1230
- return this.context;
1231
- }
1232
- /**
1233
- * One CDP session, made on demand and remade when the page replaces it.
1234
- *
1235
- * A navigation can invalidate the session, so a cached handle is not
1236
- * something to trust for the life of the run.
1237
- */
1238
- async cdpSession() {
1239
- if (this.cdp && !this.cdp.detached) {
1240
- return this.cdp;
1241
- }
1242
- // Assigned before the preloads are re-applied, because re-applying goes
1243
- // back through this method: with the handle already in place that is a
1244
- // cache hit rather than a second session and an infinite descent.
1245
- this.cdp = await bounded(this.page.target().createCDPSession(), "Target.attachToTarget", this.cdpAnswerMs);
1246
- // Page.enable before anything else touches the session, and not optional.
1247
- // A session with the page agent disabled still *accepts*
1248
- // `Page.addScriptToEvaluateOnNewDocument` and hands back an identifier —
1249
- // and then never runs the script. Every preload registers successfully,
1250
- // `sk onboarding inject read` reports the document never ran it, and `sk onboarding debug`'s
1251
- // breakpoints stay silent while their marks are written. That is a
1252
- // registration which reports success and does nothing, so this is allowed
1253
- // to throw rather than being swallowed.
1254
- await bounded(this.cdp.send("Page.enable"), "Page.enable", this.cdpAnswerMs);
1255
- // Listeners next: a re-applied preload can pause the page the moment it
1256
- // runs, and a pause nobody is listening for is a run wedged with no
1257
- // explanation.
1258
- for (const { event, handler } of this.listeners) {
1259
- this.cdp.on(event, handler);
1260
- }
1261
- // A detached session took its script registrations with it. Without this
1262
- // they would stay in `list` while running nowhere, and every empty buffer
1263
- // read afterwards would be wrong in the same direction.
1264
- await this.preloads.reapply();
1265
- // The same for an emulation: it lives in the session that set it.
1266
- await this.applyEmulation(this.cdp);
1267
- return this.cdp;
1268
- }
1269
- }
1270
- /** `button#buy.primary`, for saying what was clicked. */
1271
- function describeNode(node) {
1272
- const attributes = node.attributes ?? [];
1273
- const value = (name) => {
1274
- const index = attributes.indexOf(name);
1275
- return index >= 0 && index % 2 === 0 ? attributes[index + 1] : "";
1276
- };
1277
- const id = value("id");
1278
- const classes = value("class")
1279
- .trim()
1280
- .split(/\s+/)
1281
- .filter(Boolean)
1282
- .slice(0, 2);
1283
- return `${node.localName}${id ? `#${id}` : ""}${classes.length ? `.${classes.join(".")}` : ""}`;
1284
- }
1285
- /**
1286
- * What the tab's group is called, which is the whole of what it communicates.
1287
- *
1288
- * Names the sharpest thing installed rather than counting: someone glancing at
1289
- * a tab strip reads one word, and "the debugger is armed in there" is worth
1290
- * more than "three things are installed".
1291
- */
1292
- function labelFor(count, origins) {
1293
- if (origins.includes("debug")) {
1294
- return "sk debug";
1295
- }
1296
- if (origins.includes("watch") || origins.includes("fouc")) {
1297
- return "sk measuring";
1298
- }
1299
- return count === 1 ? "sk inject" : `sk inject (${count})`;
1300
- }
1301
- /** Puppeteer's navigation timeout, told apart from a real failure. */
1302
- function isTimeout(error) {
1303
- return (error instanceof Error &&
1304
- (error.name === "TimeoutError" || /timeout/i.test(error.message)));
1305
- }
1306
- /** An origin string as `URL` spells it, or the input when it is not a url. */
1307
- function normalise(origin) {
1308
- try {
1309
- return new URL(origin).origin;
1310
- }
1311
- catch {
1312
- return origin;
1313
- }
1314
- }
1315
- function timeout(ms, expression) {
1316
- return new Promise((_, reject) => {
1317
- const timer = setTimeout(() => reject(new PageEvaluationError(`the page did not answer within ${ms}ms — it may be paused at a breakpoint, or busy`, expression)), ms);
1318
- timer.unref();
1319
- });
1320
- }
1321
- /**
1322
- * Switch touch emulation and Chrome's mouse-to-touch translation together.
1323
- *
1324
- * `--device` turns the translation on for a touch device. Left on under a
1325
- * desktop emulation, it swallows the mouse press of `click`, which then never
1326
- * gets an answer.
1327
- */
1328
- async function setTouch(send, touch) {
1329
- await send("Emulation.setTouchEmulationEnabled", {
1330
- enabled: touch,
1331
- ...(touch ? { maxTouchPoints: 5 } : {}),
1332
- });
1333
- await send("Emulation.setEmitTouchEventsForMouse", {
1334
- enabled: touch,
1335
- configuration: "mobile",
1336
- });
1337
- }