@speedkit/cli 4.50.4 → 4.51.0-run-control.1

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 (416) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +1369 -10
  3. package/dist/base/run-control-command.d.ts +15 -0
  4. package/dist/base/run-control-command.js +20 -0
  5. package/dist/build-info.json +6 -0
  6. package/dist/commands/diff.d.ts +6 -1
  7. package/dist/commands/diff.js +9 -3
  8. package/dist/commands/onboarding/browser/click.d.ts +75 -0
  9. package/dist/commands/onboarding/browser/click.js +19 -0
  10. package/dist/commands/onboarding/browser/emulate.d.ts +93 -0
  11. package/dist/commands/onboarding/browser/emulate.js +23 -0
  12. package/dist/commands/onboarding/browser/navigate.d.ts +67 -0
  13. package/dist/commands/onboarding/browser/navigate.js +18 -0
  14. package/dist/commands/onboarding/browser/panel.d.ts +63 -0
  15. package/dist/commands/onboarding/browser/panel.js +12 -0
  16. package/dist/commands/onboarding/browser/reinstall-sw.d.ts +63 -0
  17. package/dist/commands/onboarding/browser/reinstall-sw.js +14 -0
  18. package/dist/commands/onboarding/browser/reset.d.ts +71 -0
  19. package/dist/commands/onboarding/browser/reset.js +18 -0
  20. package/dist/commands/onboarding/browser/screenshot.d.ts +77 -0
  21. package/dist/commands/onboarding/browser/screenshot.js +19 -0
  22. package/dist/commands/onboarding/browser/state.d.ts +63 -0
  23. package/dist/commands/onboarding/browser/state.js +12 -0
  24. package/dist/commands/onboarding/browser/tabs.d.ts +58 -0
  25. package/dist/commands/onboarding/browser/tabs.js +16 -0
  26. package/dist/commands/onboarding/cache/clear.d.ts +58 -0
  27. package/dist/commands/onboarding/cache/clear.js +12 -0
  28. package/dist/commands/onboarding/cache/errors.d.ts +58 -0
  29. package/dist/commands/onboarding/cache/errors.js +12 -0
  30. package/dist/commands/onboarding/cache/evict.d.ts +62 -0
  31. package/dist/commands/onboarding/cache/evict.js +15 -0
  32. package/dist/commands/onboarding/cache/get.d.ts +85 -0
  33. package/dist/commands/onboarding/cache/get.js +17 -0
  34. package/dist/commands/onboarding/cache/list.d.ts +58 -0
  35. package/dist/commands/onboarding/cache/list.js +15 -0
  36. package/dist/commands/onboarding/cache/prewarm.d.ts +73 -0
  37. package/dist/commands/onboarding/cache/prewarm.js +20 -0
  38. package/dist/commands/onboarding/cache/refresh.d.ts +62 -0
  39. package/dist/commands/onboarding/cache/refresh.js +18 -0
  40. package/dist/commands/onboarding/cdp.d.ts +81 -0
  41. package/dist/commands/onboarding/cdp.js +18 -0
  42. package/dist/commands/onboarding/debug/arm.d.ts +77 -0
  43. package/dist/commands/onboarding/debug/arm.js +18 -0
  44. package/dist/commands/onboarding/debug/await.d.ts +71 -0
  45. package/dist/commands/onboarding/debug/await.js +18 -0
  46. package/dist/commands/onboarding/debug/disarm.d.ts +63 -0
  47. package/dist/commands/onboarding/debug/disarm.js +12 -0
  48. package/dist/commands/onboarding/debug/eval.d.ts +75 -0
  49. package/dist/commands/onboarding/debug/eval.js +16 -0
  50. package/dist/commands/onboarding/debug/release.d.ts +63 -0
  51. package/dist/commands/onboarding/debug/release.js +12 -0
  52. package/dist/commands/onboarding/debug/resume.d.ts +63 -0
  53. package/dist/commands/onboarding/debug/resume.js +12 -0
  54. package/dist/commands/onboarding/debug/status.d.ts +63 -0
  55. package/dist/commands/onboarding/debug/status.js +12 -0
  56. package/dist/commands/onboarding/debug/step.d.ts +67 -0
  57. package/dist/commands/onboarding/debug/step.js +15 -0
  58. package/dist/commands/onboarding/files/list.d.ts +58 -0
  59. package/dist/commands/onboarding/files/list.js +12 -0
  60. package/dist/commands/onboarding/files/read.d.ts +73 -0
  61. package/dist/commands/onboarding/files/read.js +16 -0
  62. package/dist/commands/onboarding/files/rebuild.d.ts +63 -0
  63. package/dist/commands/onboarding/files/rebuild.js +18 -0
  64. package/dist/commands/onboarding/files/validate.d.ts +58 -0
  65. package/dist/commands/onboarding/files/validate.js +12 -0
  66. package/dist/commands/onboarding/fouc.d.ts +77 -0
  67. package/dist/commands/onboarding/fouc.js +16 -0
  68. package/dist/commands/onboarding/inject/add.d.ts +89 -0
  69. package/dist/commands/onboarding/inject/add.js +17 -0
  70. package/dist/commands/onboarding/inject/clear.d.ts +63 -0
  71. package/dist/commands/onboarding/inject/clear.js +12 -0
  72. package/dist/commands/onboarding/inject/list.d.ts +63 -0
  73. package/dist/commands/onboarding/inject/list.js +12 -0
  74. package/dist/commands/onboarding/inject/read.d.ts +75 -0
  75. package/dist/commands/onboarding/inject/read.js +18 -0
  76. package/dist/commands/onboarding/inject/recipes.d.ts +63 -0
  77. package/dist/commands/onboarding/inject/recipes.js +12 -0
  78. package/dist/commands/onboarding/inject/remove.d.ts +67 -0
  79. package/dist/commands/onboarding/inject/remove.js +15 -0
  80. package/dist/commands/onboarding/list.d.ts +13 -0
  81. package/dist/commands/onboarding/list.js +12 -0
  82. package/dist/commands/onboarding/logs.d.ts +41 -0
  83. package/dist/commands/onboarding/logs.js +256 -0
  84. package/dist/commands/onboarding/navwalk.d.ts +95 -0
  85. package/dist/commands/onboarding/navwalk.js +19 -0
  86. package/dist/commands/onboarding/response.d.ts +67 -0
  87. package/dist/commands/onboarding/response.js +18 -0
  88. package/dist/commands/onboarding/rum/beacons.d.ts +75 -0
  89. package/dist/commands/onboarding/rum/beacons.js +16 -0
  90. package/dist/commands/onboarding/rum/get.d.ts +77 -0
  91. package/dist/commands/onboarding/rum/get.js +18 -0
  92. package/dist/commands/onboarding/rum/key.d.ts +67 -0
  93. package/dist/commands/onboarding/rum/key.js +13 -0
  94. package/dist/commands/onboarding/rum/previous.d.ts +63 -0
  95. package/dist/commands/onboarding/rum/previous.js +12 -0
  96. package/dist/commands/onboarding/status.d.ts +13 -0
  97. package/dist/commands/onboarding/status.js +17 -0
  98. package/dist/commands/onboarding/todo.d.ts +58 -0
  99. package/dist/commands/onboarding/todo.js +12 -0
  100. package/dist/commands/onboarding/viewport.d.ts +101 -0
  101. package/dist/commands/onboarding/viewport.js +18 -0
  102. package/dist/commands/onboarding/watch.d.ts +93 -0
  103. package/dist/commands/onboarding/watch.js +16 -0
  104. package/dist/commands/onboarding.d.ts +26 -0
  105. package/dist/commands/onboarding.js +220 -3
  106. package/dist/commands/origin-request.d.ts +4 -0
  107. package/dist/commands/origin-request.js +4 -0
  108. package/dist/commands/spec/onboarding.spec.d.ts +1 -0
  109. package/dist/commands/spec/onboarding.spec.js +127 -0
  110. package/dist/services/cli/build-info.d.ts +33 -0
  111. package/dist/services/cli/build-info.js +63 -0
  112. package/dist/services/cli/cli-environment-factory.d.ts +3 -0
  113. package/dist/services/cli/cli-environment-factory.js +1 -0
  114. package/dist/services/cli/cli-service-build-context.d.ts +3 -0
  115. package/dist/services/cli/cli-service-factory.js +1 -1
  116. package/dist/services/cli/cli-service-model.d.ts +29 -10
  117. package/dist/services/cli/cli-service.d.ts +60 -11
  118. package/dist/services/cli/cli-service.js +196 -32
  119. package/dist/services/cli/index.d.ts +2 -0
  120. package/dist/services/cli/index.js +2 -0
  121. package/dist/services/cli/sink.d.ts +47 -0
  122. package/dist/services/cli/sink.js +31 -0
  123. package/dist/services/cli/spec/build-identity.spec.d.ts +1 -0
  124. package/dist/services/cli/spec/build-identity.spec.js +85 -0
  125. package/dist/services/cli/spec/build-info.spec.d.ts +1 -0
  126. package/dist/services/cli/spec/build-info.spec.js +10 -0
  127. package/dist/services/cli/spec/cli-service-log.spec.d.ts +1 -0
  128. package/dist/services/cli/spec/cli-service-log.spec.js +133 -0
  129. package/dist/services/cli/spec/cli-service.spec.js +113 -50
  130. package/dist/services/cli/spec/memory-cli.d.ts +9 -0
  131. package/dist/services/cli/spec/memory-cli.js +9 -0
  132. package/dist/services/diff/config-at-ref.d.ts +20 -0
  133. package/dist/services/diff/config-at-ref.js +33 -0
  134. package/dist/services/diff/diff-service-build-context.d.ts +8 -0
  135. package/dist/services/diff/diff-service-build-context.js +40 -1
  136. package/dist/services/diff/diff-service-factory.d.ts +2 -0
  137. package/dist/services/diff/diff-service-factory.js +48 -20
  138. package/dist/services/diff/diff-service.d.ts +11 -0
  139. package/dist/services/diff/diff-service.js +37 -11
  140. package/dist/services/diff/page-source.d.ts +12 -0
  141. package/dist/services/diff/page-source.js +16 -11
  142. package/dist/services/diff/sinks/tool-diff-sink.d.ts +3 -2
  143. package/dist/services/diff/sinks/tool-diff-sink.js +3 -2
  144. package/dist/services/diff/spec/config-at-ref.spec.d.ts +1 -0
  145. package/dist/services/diff/spec/config-at-ref.spec.js +46 -0
  146. package/dist/services/diff/spec/diff-service-build-context.spec.js +19 -0
  147. package/dist/services/diff/spec/diff-service.spec.js +95 -0
  148. package/dist/services/git/git-repository.d.ts +2 -0
  149. package/dist/services/git/git-repository.js +6 -0
  150. package/dist/services/integration-api/customer-config-flags.js +1 -0
  151. package/dist/services/onboarding/browser/baqend-response.d.ts +17 -1
  152. package/dist/services/onboarding/browser/baqend-response.js +23 -0
  153. package/dist/services/onboarding/browser/console-log.d.ts +9 -0
  154. package/dist/services/onboarding/browser/console-log.js +27 -0
  155. package/dist/services/onboarding/browser/executable/executable-validator.js +4 -2
  156. package/dist/services/onboarding/browser/extension/extension-bridge.js +5 -3
  157. package/dist/services/onboarding/browser/extension/extension-downloader.js +17 -8
  158. package/dist/services/onboarding/browser/extension/extension-validator.js +9 -4
  159. package/dist/services/onboarding/control/body-inspect.d.ts +24 -0
  160. package/dist/services/onboarding/control/body-inspect.js +106 -0
  161. package/dist/services/onboarding/control/browser-session.d.ts +521 -0
  162. package/dist/services/onboarding/control/browser-session.js +1273 -0
  163. package/dist/services/onboarding/control/config-validation.d.ts +17 -0
  164. package/dist/services/onboarding/control/config-validation.js +46 -0
  165. package/dist/services/onboarding/control/control-protocol.d.ts +1390 -0
  166. package/dist/services/onboarding/control/control-protocol.js +69 -0
  167. package/dist/services/onboarding/control/control-server.d.ts +284 -0
  168. package/dist/services/onboarding/control/control-server.js +1609 -0
  169. package/dist/services/onboarding/control/debug-session.d.ts +190 -0
  170. package/dist/services/onboarding/control/debug-session.js +801 -0
  171. package/dist/services/onboarding/control/fouc.d.ts +23 -0
  172. package/dist/services/onboarding/control/fouc.js +151 -0
  173. package/dist/services/onboarding/control/index.d.ts +4 -0
  174. package/dist/services/onboarding/control/index.js +4 -0
  175. package/dist/services/onboarding/control/navwalk.d.ts +65 -0
  176. package/dist/services/onboarding/control/navwalk.js +248 -0
  177. package/dist/services/onboarding/control/preload-registry.d.ts +150 -0
  178. package/dist/services/onboarding/control/preload-registry.js +829 -0
  179. package/dist/services/onboarding/control/response-explainer.d.ts +24 -0
  180. package/dist/services/onboarding/control/response-explainer.js +257 -0
  181. package/dist/services/onboarding/control/rum.d.ts +8 -0
  182. package/dist/services/onboarding/control/rum.js +220 -0
  183. package/dist/services/onboarding/control/service-worker-tracker.d.ts +68 -0
  184. package/dist/services/onboarding/control/service-worker-tracker.js +119 -0
  185. package/dist/services/onboarding/control/viewport.d.ts +45 -0
  186. package/dist/services/onboarding/control/viewport.js +344 -0
  187. package/dist/services/onboarding/control/watch.d.ts +26 -0
  188. package/dist/services/onboarding/control/watch.js +149 -0
  189. package/dist/services/onboarding/dashboard/diff-against-current-page.js +3 -1
  190. package/dist/services/onboarding/dashboard/index.js +7 -2
  191. package/dist/services/onboarding/fetch-event-handler.d.ts +24 -5
  192. package/dist/services/onboarding/fetch-event-handler.js +94 -32
  193. package/dist/services/onboarding/fetch-events/customer-domain-document-response.js +4 -25
  194. package/dist/services/onboarding/fetch-events/speed-kit-install-js.js +11 -2
  195. package/dist/services/onboarding/fetch-events/speed-kit-rum-pi-request.d.ts +14 -0
  196. package/dist/services/onboarding/fetch-events/speed-kit-rum-pi-request.js +30 -0
  197. package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.d.ts +13 -0
  198. package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.js +28 -1
  199. package/dist/services/onboarding/file-events/file-watcher.d.ts +42 -1
  200. package/dist/services/onboarding/file-events/file-watcher.js +117 -12
  201. package/dist/services/onboarding/html-charset.d.ts +28 -0
  202. package/dist/services/onboarding/html-charset.js +57 -0
  203. package/dist/services/onboarding/onboarding-model.d.ts +30 -1
  204. package/dist/services/onboarding/onboarding-model.js +10 -1
  205. package/dist/services/onboarding/onboarding-service-build-context.d.ts +4 -0
  206. package/dist/services/onboarding/onboarding-service-build-context.js +6 -0
  207. package/dist/services/onboarding/onboarding-service-factory.d.ts +17 -1
  208. package/dist/services/onboarding/onboarding-service-factory.js +131 -17
  209. package/dist/services/onboarding/onboarding-service.d.ts +40 -1
  210. package/dist/services/onboarding/onboarding-service.js +135 -22
  211. package/dist/services/onboarding/request-cache/asset-key.d.ts +61 -0
  212. package/dist/services/onboarding/request-cache/asset-key.js +115 -0
  213. package/dist/services/onboarding/request-cache/cache.d.ts +62 -5
  214. package/dist/services/onboarding/request-cache/cache.js +128 -17
  215. package/dist/services/onboarding/spec/browser/console-log.spec.d.ts +1 -0
  216. package/dist/services/onboarding/spec/browser/console-log.spec.js +42 -0
  217. package/dist/services/onboarding/spec/control/browser-session.spec.d.ts +1 -0
  218. package/dist/services/onboarding/spec/control/browser-session.spec.js +526 -0
  219. package/dist/services/onboarding/spec/control/control-server.spec.d.ts +1 -0
  220. package/dist/services/onboarding/spec/control/control-server.spec.js +338 -0
  221. package/dist/services/onboarding/spec/control/debug-session.spec.d.ts +1 -0
  222. package/dist/services/onboarding/spec/control/debug-session.spec.js +693 -0
  223. package/dist/services/onboarding/spec/control/fakes.d.ts +31 -0
  224. package/dist/services/onboarding/spec/control/fakes.js +66 -0
  225. package/dist/services/onboarding/spec/control/fouc.spec.d.ts +1 -0
  226. package/dist/services/onboarding/spec/control/fouc.spec.js +167 -0
  227. package/dist/services/onboarding/spec/control/navwalk.spec.d.ts +1 -0
  228. package/dist/services/onboarding/spec/control/navwalk.spec.js +222 -0
  229. package/dist/services/onboarding/spec/control/preload-registry.spec.d.ts +1 -0
  230. package/dist/services/onboarding/spec/control/preload-registry.spec.js +432 -0
  231. package/dist/services/onboarding/spec/control/response-explainer.spec.d.ts +1 -0
  232. package/dist/services/onboarding/spec/control/response-explainer.spec.js +324 -0
  233. package/dist/services/onboarding/spec/control/rum.spec.d.ts +1 -0
  234. package/dist/services/onboarding/spec/control/rum.spec.js +222 -0
  235. package/dist/services/onboarding/spec/control/service-worker-tracker.spec.d.ts +1 -0
  236. package/dist/services/onboarding/spec/control/service-worker-tracker.spec.js +193 -0
  237. package/dist/services/onboarding/spec/control/viewport.spec.d.ts +1 -0
  238. package/dist/services/onboarding/spec/control/viewport.spec.js +200 -0
  239. package/dist/services/onboarding/spec/control/watch.spec.d.ts +1 -0
  240. package/dist/services/onboarding/spec/control/watch.spec.js +172 -0
  241. package/dist/services/onboarding/spec/fetch-event-handler.spec.d.ts +1 -0
  242. package/dist/services/onboarding/spec/fetch-event-handler.spec.js +202 -0
  243. package/dist/services/onboarding/spec/fetch-events/customer-domain-document-response.spec.d.ts +1 -0
  244. package/dist/services/onboarding/spec/fetch-events/customer-domain-document-response.spec.js +39 -0
  245. package/dist/services/onboarding/spec/fetch-events/speed-kit-service-worker-js.spec.d.ts +1 -0
  246. package/dist/services/onboarding/spec/fetch-events/speed-kit-service-worker-js.spec.js +41 -0
  247. package/dist/services/onboarding/spec/html-charset.spec.d.ts +1 -0
  248. package/dist/services/onboarding/spec/html-charset.spec.js +58 -0
  249. package/dist/services/onboarding/spec/onboarding-model.spec.js +37 -0
  250. package/dist/services/onboarding/spec/onboarding-service-factory.spec.js +1 -0
  251. package/dist/services/onboarding/spec/request-cache/cache.spec.d.ts +1 -0
  252. package/dist/services/onboarding/spec/request-cache/cache.spec.js +107 -0
  253. package/dist/services/onboarding/spec/todo-collector.spec.d.ts +1 -0
  254. package/dist/services/onboarding/spec/todo-collector.spec.js +136 -0
  255. package/dist/services/onboarding/spec/virtual-orestes-app/index.spec.d.ts +1 -0
  256. package/dist/services/onboarding/spec/virtual-orestes-app/index.spec.js +19 -0
  257. package/dist/services/onboarding/todo-collector.d.ts +7 -2
  258. package/dist/services/onboarding/todo-collector.js +49 -12
  259. package/dist/services/onboarding/virtual-orestes-app/index.d.ts +34 -0
  260. package/dist/services/onboarding/virtual-orestes-app/index.js +85 -53
  261. package/dist/services/origin-request/asset-variations.d.ts +14 -0
  262. package/dist/services/origin-request/asset-variations.js +11 -4
  263. package/dist/services/origin-request/origin-fetcher.d.ts +7 -0
  264. package/dist/services/origin-request/origin-fetcher.js +43 -5
  265. package/dist/services/origin-request/origin-request-service-build-context.d.ts +17 -0
  266. package/dist/services/origin-request/origin-request-service-build-context.js +8 -0
  267. package/dist/services/origin-request/origin-request-service-factory.d.ts +0 -5
  268. package/dist/services/origin-request/origin-request-service-factory.js +2 -30
  269. package/dist/services/origin-request/origin-request-service.d.ts +121 -6
  270. package/dist/services/origin-request/origin-request-service.js +273 -49
  271. package/dist/services/origin-request/runtime-config-source.js +9 -4
  272. package/dist/services/origin-request/spec/asset-variations.spec.js +20 -0
  273. package/dist/services/origin-request/spec/origin-request-service.spec.js +329 -6
  274. package/dist/services/query-builder/rules/rule-match.d.ts +35 -0
  275. package/dist/services/query-builder/rules/rule-match.js +70 -0
  276. package/dist/services/query-builder/spec/rules/rule-match.spec.d.ts +1 -0
  277. package/dist/services/query-builder/spec/rules/rule-match.spec.js +121 -0
  278. package/dist/services/run-control/browser/run-browser-contexts.d.ts +541 -0
  279. package/dist/services/run-control/browser/run-browser-contexts.js +78 -0
  280. package/dist/services/run-control/browser/run-browser-service-factory.d.ts +5 -0
  281. package/dist/services/run-control/browser/run-browser-service-factory.js +7 -0
  282. package/dist/services/run-control/browser/run-browser-service.d.ts +64 -0
  283. package/dist/services/run-control/browser/run-browser-service.js +199 -0
  284. package/dist/services/run-control/cache/run-cache-contexts.d.ts +349 -0
  285. package/dist/services/run-control/cache/run-cache-contexts.js +51 -0
  286. package/dist/services/run-control/cache/run-cache-service-factory.d.ts +6 -0
  287. package/dist/services/run-control/cache/run-cache-service-factory.js +12 -0
  288. package/dist/services/run-control/cache/run-cache-service.d.ts +35 -0
  289. package/dist/services/run-control/cache/run-cache-service.js +151 -0
  290. package/dist/services/run-control/control-client.d.ts +36 -0
  291. package/dist/services/run-control/control-client.js +147 -0
  292. package/dist/services/run-control/debug/run-debug-contexts.d.ts +411 -0
  293. package/dist/services/run-control/debug/run-debug-contexts.js +44 -0
  294. package/dist/services/run-control/debug/run-debug-service-factory.d.ts +5 -0
  295. package/dist/services/run-control/debug/run-debug-service-factory.js +7 -0
  296. package/dist/services/run-control/debug/run-debug-service.d.ts +38 -0
  297. package/dist/services/run-control/debug/run-debug-service.js +161 -0
  298. package/dist/services/run-control/files/run-files-contexts.d.ts +238 -0
  299. package/dist/services/run-control/files/run-files-contexts.js +26 -0
  300. package/dist/services/run-control/files/run-files-service-factory.d.ts +5 -0
  301. package/dist/services/run-control/files/run-files-service-factory.js +7 -0
  302. package/dist/services/run-control/files/run-files-service.d.ts +29 -0
  303. package/dist/services/run-control/files/run-files-service.js +120 -0
  304. package/dist/services/run-control/index.d.ts +32 -0
  305. package/dist/services/run-control/index.js +31 -0
  306. package/dist/services/run-control/inject/run-inject-contexts.d.ts +319 -0
  307. package/dist/services/run-control/inject/run-inject-contexts.js +32 -0
  308. package/dist/services/run-control/inject/run-inject-service-factory.d.ts +5 -0
  309. package/dist/services/run-control/inject/run-inject-service-factory.js +7 -0
  310. package/dist/services/run-control/inject/run-inject-service.d.ts +31 -0
  311. package/dist/services/run-control/inject/run-inject-service.js +203 -0
  312. package/dist/services/run-control/live-run.d.ts +37 -0
  313. package/dist/services/run-control/live-run.js +56 -0
  314. package/dist/services/run-control/probe/run-probe-contexts.d.ts +333 -0
  315. package/dist/services/run-control/probe/run-probe-contexts.js +73 -0
  316. package/dist/services/run-control/probe/run-probe-service-factory.d.ts +5 -0
  317. package/dist/services/run-control/probe/run-probe-service-factory.js +7 -0
  318. package/dist/services/run-control/probe/run-probe-service.d.ts +54 -0
  319. package/dist/services/run-control/probe/run-probe-service.js +193 -0
  320. package/dist/services/run-control/rum/run-rum-contexts.d.ts +216 -0
  321. package/dist/services/run-control/rum/run-rum-contexts.js +34 -0
  322. package/dist/services/run-control/rum/run-rum-service-factory.d.ts +5 -0
  323. package/dist/services/run-control/rum/run-rum-service-factory.js +7 -0
  324. package/dist/services/run-control/rum/run-rum-service.d.ts +36 -0
  325. package/dist/services/run-control/rum/run-rum-service.js +122 -0
  326. package/dist/services/run-control/run-answer.d.ts +28 -0
  327. package/dist/services/run-control/run-answer.js +58 -0
  328. package/dist/services/run-control/run-control-context.d.ts +102 -0
  329. package/dist/services/run-control/run-control-context.js +36 -0
  330. package/dist/services/run-control/run-control-flags.d.ts +12 -0
  331. package/dist/services/run-control/run-control-flags.js +22 -0
  332. package/dist/services/run-control/run-control-model.d.ts +9 -0
  333. package/dist/services/run-control/run-control-model.js +1 -0
  334. package/dist/services/run-control/run-control-service-factory.d.ts +14 -0
  335. package/dist/services/run-control/run-control-service-factory.js +26 -0
  336. package/dist/services/run-control/session/run-session-contexts.d.ts +25 -0
  337. package/dist/services/run-control/session/run-session-contexts.js +20 -0
  338. package/dist/services/run-control/session/run-session-service-factory.d.ts +8 -0
  339. package/dist/services/run-control/session/run-session-service-factory.js +18 -0
  340. package/dist/services/run-control/session/run-session-service.d.ts +25 -0
  341. package/dist/services/run-control/session/run-session-service.js +95 -0
  342. package/dist/services/run-control/spec/browser/run-browser-service.spec.d.ts +1 -0
  343. package/dist/services/run-control/spec/browser/run-browser-service.spec.js +327 -0
  344. package/dist/services/run-control/spec/cache/run-cache-service.spec.d.ts +1 -0
  345. package/dist/services/run-control/spec/cache/run-cache-service.spec.js +454 -0
  346. package/dist/services/run-control/spec/debug/run-debug-service.spec.d.ts +1 -0
  347. package/dist/services/run-control/spec/debug/run-debug-service.spec.js +113 -0
  348. package/dist/services/run-control/spec/files/run-files-service.spec.d.ts +1 -0
  349. package/dist/services/run-control/spec/files/run-files-service.spec.js +234 -0
  350. package/dist/services/run-control/spec/inject/run-inject-service.spec.d.ts +1 -0
  351. package/dist/services/run-control/spec/inject/run-inject-service.spec.js +224 -0
  352. package/dist/services/run-control/spec/live-run-fixture.d.ts +32 -0
  353. package/dist/services/run-control/spec/live-run-fixture.js +109 -0
  354. package/dist/services/run-control/spec/probe/run-probe-service.spec.d.ts +1 -0
  355. package/dist/services/run-control/spec/probe/run-probe-service.spec.js +108 -0
  356. package/dist/services/run-control/spec/rum/run-rum-service.spec.d.ts +1 -0
  357. package/dist/services/run-control/spec/rum/run-rum-service.spec.js +47 -0
  358. package/dist/services/run-control/spec/run-answer.spec.d.ts +1 -0
  359. package/dist/services/run-control/spec/run-answer.spec.js +57 -0
  360. package/dist/services/run-control/spec/session/run-session-service.spec.d.ts +1 -0
  361. package/dist/services/run-control/spec/session/run-session-service.spec.js +101 -0
  362. package/dist/services/run-log/crash-mirror.d.ts +31 -0
  363. package/dist/services/run-log/crash-mirror.js +69 -0
  364. package/dist/services/run-log/index.d.ts +11 -0
  365. package/dist/services/run-log/index.js +11 -0
  366. package/dist/services/run-log/jsonl-appender.d.ts +46 -0
  367. package/dist/services/run-log/jsonl-appender.js +91 -0
  368. package/dist/services/run-log/log-event-model.d.ts +104 -0
  369. package/dist/services/run-log/log-event-model.js +56 -0
  370. package/dist/services/run-log/log-query-service-factory.d.ts +11 -0
  371. package/dist/services/run-log/log-query-service-factory.js +14 -0
  372. package/dist/services/run-log/log-query-service.d.ts +59 -0
  373. package/dist/services/run-log/log-query-service.js +111 -0
  374. package/dist/services/run-log/log-reader.d.ts +84 -0
  375. package/dist/services/run-log/log-reader.js +180 -0
  376. package/dist/services/run-log/log-summary.d.ts +72 -0
  377. package/dist/services/run-log/log-summary.js +208 -0
  378. package/dist/services/run-log/redaction.d.ts +34 -0
  379. package/dist/services/run-log/redaction.js +124 -0
  380. package/dist/services/run-log/request-log.d.ts +80 -0
  381. package/dist/services/run-log/request-log.js +69 -0
  382. package/dist/services/run-log/request-summary.d.ts +76 -0
  383. package/dist/services/run-log/request-summary.js +0 -0
  384. package/dist/services/run-log/run-log.d.ts +61 -0
  385. package/dist/services/run-log/run-log.js +102 -0
  386. package/dist/services/run-log/spec/log-query-service.spec.d.ts +1 -0
  387. package/dist/services/run-log/spec/log-query-service.spec.js +197 -0
  388. package/dist/services/run-log/spec/log-reader.spec.d.ts +1 -0
  389. package/dist/services/run-log/spec/log-reader.spec.js +109 -0
  390. package/dist/services/run-log/spec/log-summary.spec.d.ts +1 -0
  391. package/dist/services/run-log/spec/log-summary.spec.js +153 -0
  392. package/dist/services/run-log/spec/redaction.spec.d.ts +1 -0
  393. package/dist/services/run-log/spec/redaction.spec.js +61 -0
  394. package/dist/services/run-log/spec/request-log.spec.d.ts +1 -0
  395. package/dist/services/run-log/spec/request-log.spec.js +101 -0
  396. package/dist/services/run-log/spec/request-summary.spec.d.ts +1 -0
  397. package/dist/services/run-log/spec/request-summary.spec.js +171 -0
  398. package/dist/services/run-log/spec/run-log.spec.d.ts +1 -0
  399. package/dist/services/run-log/spec/run-log.spec.js +122 -0
  400. package/dist/services/run-registry/exit-classification.d.ts +39 -0
  401. package/dist/services/run-registry/exit-classification.js +42 -0
  402. package/dist/services/run-registry/index.d.ts +3 -0
  403. package/dist/services/run-registry/index.js +3 -0
  404. package/dist/services/run-registry/process-identity.d.ts +28 -0
  405. package/dist/services/run-registry/process-identity.js +80 -0
  406. package/dist/services/run-registry/run-registry-model.d.ts +128 -0
  407. package/dist/services/run-registry/run-registry-model.js +16 -0
  408. package/dist/services/run-registry/run-registry.d.ts +150 -0
  409. package/dist/services/run-registry/run-registry.js +409 -0
  410. package/dist/services/run-registry/spec/exit-classification.spec.d.ts +1 -0
  411. package/dist/services/run-registry/spec/exit-classification.spec.js +82 -0
  412. package/dist/services/run-registry/spec/run-registry.spec.d.ts +1 -0
  413. package/dist/services/run-registry/spec/run-registry.spec.js +509 -0
  414. package/dist/services/setup/os/tool-registry.js +2 -2
  415. package/oclif.manifest.json +3293 -272
  416. package/package.json +21 -3
@@ -0,0 +1,829 @@
1
+ import { createHash } from "node:crypto";
2
+ /** How many may be registered at once. */
3
+ export const PRELOAD_LIMIT = 8;
4
+ /** Minutes a preload lives for when the caller names no TTL. */
5
+ export const DEFAULT_TTL_MINUTES = 30;
6
+ /** Records one script may buffer in a document before it starts dropping. */
7
+ const PAGE_BUFFER_LIMIT = 500;
8
+ /** Records `read` returns when the caller names no limit. */
9
+ const DEFAULT_READ_LIMIT = 100;
10
+ /** The object every injected script hangs itself off, in the page. */
11
+ const PAGE_NAMESPACE = "__sk_inject";
12
+ export class NoSuchPreloadError extends Error {
13
+ code = "NO_SUCH_PRELOAD";
14
+ }
15
+ export class UnknownRecipeError extends Error {
16
+ recipes;
17
+ code = "UNKNOWN_RECIPE";
18
+ constructor(message, recipes) {
19
+ super(message);
20
+ this.recipes = recipes;
21
+ }
22
+ }
23
+ export class BadRecipeParamsError extends Error {
24
+ params;
25
+ code = "BAD_RECIPE_PARAMS";
26
+ constructor(message, params) {
27
+ super(message);
28
+ this.params = params;
29
+ }
30
+ }
31
+ export class InjectSourceRequiredError extends Error {
32
+ code = "INJECT_SOURCE_REQUIRED";
33
+ }
34
+ export class TooManyPreloadsError extends Error {
35
+ registered;
36
+ code = "TOO_MANY_PRELOADS";
37
+ constructor(message, registered) {
38
+ super(message);
39
+ this.registered = registered;
40
+ }
41
+ }
42
+ /**
43
+ * The recipes, and the reason there are recipes at all.
44
+ *
45
+ * Editing `config_loadHandler.js` to test a one-line hypothesis costs a
46
+ * documentHandler rebuild, a service-worker rebuild, an unregister and a
47
+ * reinstall on the next navigation. A preload that wraps the same seam answers
48
+ * the same question in one navigation and rebuilds nothing.
49
+ *
50
+ * These are shapes rather than named seams on purpose. The endpoints plan named
51
+ * four specific ones — `detectDevice`, `SpeedKit.lastNavigate` — and none of
52
+ * them is verifiable from this repo, which vendors `@speedkit/rules` and
53
+ * nothing else of Speed Kit. A shape parameterised by a path is honest about
54
+ * that and covers the named cases as arguments; a preset can be added once a
55
+ * seam has been seen on a real page.
56
+ */
57
+ const RECIPES = [
58
+ {
59
+ name: "mark-timeline",
60
+ summary: "Wrap `performance.mark` and record every mark with its timestamp. The " +
61
+ "Speed Kit lifecycle is marked throughout — `baqend-blocking-script-start`, " +
62
+ "`sk-prerender-change-detection-end` — so this is the cheapest way to see " +
63
+ "which phases ran, in which order, and which never happened.",
64
+ observes: "`{ mark }` per `performance.mark` call.",
65
+ // The marks that matter are emitted before anything an agent could install
66
+ // by hand, which is precisely why this has to be a preload.
67
+ needsReload: true,
68
+ params: [
69
+ {
70
+ name: "pattern",
71
+ required: false,
72
+ description: "Regular expression the mark name must match. Absent records every mark.",
73
+ },
74
+ ],
75
+ build: ({ pattern }) => `
76
+ var test = ${pattern === undefined ? "null" : `new RegExp(${literal(pattern)})`};
77
+ if (typeof performance !== "undefined" && performance.mark) {
78
+ var original = performance.mark;
79
+ performance.mark = function (name) {
80
+ try {
81
+ if (!test || test.test(name)) record({ mark: name });
82
+ } catch (ignored) {
83
+ // A spy must never change what it watches. Recording is best effort;
84
+ // calling through is not.
85
+ }
86
+ return original.apply(this, arguments);
87
+ };
88
+ }`,
89
+ },
90
+ {
91
+ name: "sample",
92
+ summary: "Evaluate an expression on an interval and record a timeline of it. This " +
93
+ "is the one for an intermittent or good-then-broken symptom, which a " +
94
+ "single evaluation cannot catch by construction.",
95
+ observes: "The expression's value per tick, or `{ error }` when it threw.",
96
+ needsReload: false,
97
+ params: [
98
+ {
99
+ name: "expression",
100
+ required: true,
101
+ description: "JavaScript expression returning a JSON-able value. Inlined as code " +
102
+ "and evaluated in the page, so it is as sharp as raw source.",
103
+ code: true,
104
+ },
105
+ {
106
+ name: "intervalMs",
107
+ required: false,
108
+ description: "Milliseconds between samples.",
109
+ default: 200,
110
+ },
111
+ ],
112
+ build: ({ expression, intervalMs }) => `
113
+ var take = guard(function () { record(${expression}); });
114
+ take();
115
+ var timer = setInterval(function () {
116
+ if (slot.disabled) { clearInterval(timer); return; }
117
+ take();
118
+ }, ${Number(intervalMs)});`,
119
+ },
120
+ {
121
+ name: "spy",
122
+ summary: "Wrap a function and record every call's arguments, without changing what " +
123
+ "it does. The tracking seam — `dataLayer.push` and its kin — is the case " +
124
+ "this exists for: it answers what the config *would* read.",
125
+ observes: "`{ call, args }` per call, arguments summarised and depth-limited.",
126
+ needsReload: false,
127
+ params: [
128
+ {
129
+ name: "path",
130
+ required: true,
131
+ description: "Dotted path from `window`, e.g. `dataLayer.push`. Waited for, so a " +
132
+ "seam a later script creates is still caught.",
133
+ },
134
+ ],
135
+ build: ({ path }) => `
136
+ whenPresent(${literal(path)}, function (found) {
137
+ var original = found.owner[found.key];
138
+ if (typeof original !== "function") {
139
+ record({ path: ${literal(path)}, notAFunction: typeof original });
140
+ return;
141
+ }
142
+ found.owner[found.key] = function () {
143
+ // Recorded before calling through, so an argument list survives a call
144
+ // that throws — which is the call most worth having a record of.
145
+ record({ call: ${literal(path)}, args: summarise(Array.prototype.slice.call(arguments)) });
146
+ return original.apply(this, arguments);
147
+ };
148
+ });`,
149
+ },
150
+ {
151
+ name: "web-vitals",
152
+ summary: "Record LCP, CLS, INP, FCP and TTFB as the browser reports them, with the " +
153
+ "element behind each: the LCP element and its resource, the nodes every " +
154
+ "layout shift moved. Buffered, so it also catches what happened before it " +
155
+ "was added. Pair it with `mark-timeline` or `sk onboarding debug` to see " +
156
+ "which Speed Kit phase a shift or the LCP fell into.",
157
+ observes: "`{ metric, value, … }` per entry: `lcp` with `element` and `url`, `cls` " +
158
+ "per shift with the running `total` and its `sources`, `inp` per slow " +
159
+ "interaction, `fcp`, `ttfb`. Times are ms on the page's clock.",
160
+ needsReload: false,
161
+ params: [],
162
+ build: () => `
163
+ function describe(node) {
164
+ if (!node || node.nodeType !== 1) return node ? node.nodeName : null;
165
+ var text = node.tagName.toLowerCase();
166
+ if (node.id) text += "#" + node.id;
167
+ var classes = String(node.className || "").trim().split(/\\s+/).filter(Boolean).slice(0, 3);
168
+ if (classes.length) text += "." + classes.join(".");
169
+ return text;
170
+ }
171
+ // Whether Chrome is producing frames at all. A window the compositor does
172
+ // not draw — a hidden workspace — paints nothing, and then "no LCP" is not
173
+ // a measurement but an absence of one.
174
+ record({
175
+ metric: "page",
176
+ visibility: document.visibilityState,
177
+ focused: document.hasFocus()
178
+ });
179
+ function observe(type, handle, options) {
180
+ try {
181
+ new PerformanceObserver(guard(function (list) {
182
+ list.getEntries().forEach(handle);
183
+ })).observe(Object.assign({ type: type, buffered: true }, options || {}));
184
+ } catch (ignored) {
185
+ record({ metric: type, unsupported: true });
186
+ }
187
+ }
188
+ observe("largest-contentful-paint", function (entry) {
189
+ record({
190
+ metric: "lcp",
191
+ value: Math.round(entry.startTime),
192
+ size: entry.size,
193
+ element: describe(entry.element),
194
+ url: entry.url || null
195
+ });
196
+ });
197
+ var cls = 0;
198
+ var clsLoad = currentLoad();
199
+ observe("layout-shift", function (entry) {
200
+ // A shift right after input is expected, and CLS leaves it out.
201
+ if (entry.hadRecentInput) return;
202
+ // Per page load: a single-page-app navigation starts a new total, where
203
+ // it used to keep climbing across pages.
204
+ if (currentLoad() !== clsLoad) { cls = 0; clsLoad = currentLoad(); }
205
+ cls += entry.value;
206
+ record({
207
+ metric: "cls",
208
+ value: Math.round(entry.value * 10000) / 10000,
209
+ total: Math.round(cls * 10000) / 10000,
210
+ at: Math.round(entry.startTime),
211
+ sources: (entry.sources || []).slice(0, 5).map(function (source) {
212
+ return {
213
+ node: describe(source.node),
214
+ from: source.previousRect && [source.previousRect.x, source.previousRect.y, source.previousRect.width, source.previousRect.height],
215
+ to: source.currentRect && [source.currentRect.x, source.currentRect.y, source.currentRect.width, source.currentRect.height]
216
+ };
217
+ })
218
+ });
219
+ });
220
+ observe("event", function (entry) {
221
+ if (!entry.interactionId) return;
222
+ record({
223
+ metric: "inp",
224
+ value: Math.round(entry.duration),
225
+ event: entry.name,
226
+ target: describe(entry.target),
227
+ at: Math.round(entry.startTime)
228
+ });
229
+ }, { durationThreshold: 40 });
230
+ observe("paint", function (entry) {
231
+ if (entry.name === "first-contentful-paint") {
232
+ record({ metric: "fcp", value: Math.round(entry.startTime) });
233
+ }
234
+ });
235
+ observe("navigation", function (entry) {
236
+ record({ metric: "ttfb", value: Math.round(entry.responseStart) });
237
+ });`,
238
+ },
239
+ {
240
+ name: "stub",
241
+ summary: "Replace what a path holds, to force a branch without editing the config " +
242
+ "or the environment — a variation signal, a feature probe. The one recipe " +
243
+ "here that changes the page rather than watching it.",
244
+ observes: "`{ replaced }` on install, and `{ call }` per call in `returns` mode.",
245
+ needsReload: false,
246
+ params: [
247
+ {
248
+ name: "path",
249
+ required: true,
250
+ description: "Dotted path from `window` to replace.",
251
+ },
252
+ {
253
+ name: "value",
254
+ required: false,
255
+ description: "The value to put there, as JSON. Exclusive with `returns`.",
256
+ },
257
+ {
258
+ name: "returns",
259
+ required: false,
260
+ description: "Replace with a function returning this, as JSON. Exclusive with `value`.",
261
+ },
262
+ ],
263
+ build: ({ path, value, returns }) => {
264
+ if ((value === undefined) === (returns === undefined)) {
265
+ throw new BadRecipeParamsError("`stub` takes exactly one of `value` and `returns` — the first replaces what the path holds, the second replaces it with a function answering that.", recipeByName("stub").params);
266
+ }
267
+ const replacement = returns === undefined
268
+ ? literal(value)
269
+ : `function () { record({ call: ${literal(path)} }); return ${literal(returns)}; }`;
270
+ return `
271
+ whenPresent(${literal(path)}, function (found) {
272
+ found.owner[found.key] = ${replacement};
273
+ record({ path: ${literal(path)}, replaced: true });
274
+ });`;
275
+ },
276
+ },
277
+ ];
278
+ /**
279
+ * The preloads a run has registered, and the only thing allowed to add one.
280
+ *
281
+ * Three consumers wanted `Page.addScriptToEvaluateOnNewDocument` — the sampler,
282
+ * the breakpoint bridge's flag delivery, and injected hooks — and three ad-hoc
283
+ * call sites would have meant three ways to leave a script behind. A preload
284
+ * outlives the turn that added it, survives every navigation, and is invisible
285
+ * to the human watching the run's output. So it is registered in one place that
286
+ * can list them, expire them, and switch off the copy already running.
287
+ */
288
+ export class PreloadRegistry {
289
+ transport;
290
+ onChange;
291
+ registered = new Map();
292
+ /** Set while a retire is in flight, so one notification covers the batch. */
293
+ changed = false;
294
+ counter = 0;
295
+ /** Expired since the last time anyone was told, so an absence is explained. */
296
+ expired = [];
297
+ constructor(transport,
298
+ /**
299
+ * Told whenever what is installed changes.
300
+ *
301
+ * The hook the tab marker hangs off: "an agent has left something in this
302
+ * page" is exactly the set of moments this fires on, and it is the
303
+ * condition worth showing rather than the fact that a tool ran.
304
+ */
305
+ onChange) {
306
+ this.transport = transport;
307
+ this.onChange = onChange;
308
+ }
309
+ /**
310
+ * What is installed, without asking the page.
311
+ *
312
+ * `list` needs an evaluation to say whether a script is running; this only
313
+ * answers what is registered, which is all a status label needs and cheap
314
+ * enough to compute on every change.
315
+ */
316
+ summary() {
317
+ const entries = [...this.registered.values()];
318
+ return {
319
+ count: entries.length,
320
+ origins: [...new Set(entries.map((one) => one.entry.origin))],
321
+ };
322
+ }
323
+ get size() {
324
+ return this.registered.size;
325
+ }
326
+ recipes() {
327
+ return {
328
+ recipes: RECIPES.map(({ build: _build, ...info }) => info),
329
+ };
330
+ }
331
+ async add(request) {
332
+ const { recipe, params = {}, source, ttlMinutes } = request;
333
+ if ((recipe === undefined) === (source === undefined)) {
334
+ throw new InjectSourceRequiredError("`add` takes exactly one of `recipe` and `source`. Call `recipes` for the named ones; `source` is the escape hatch.");
335
+ }
336
+ // Reserved entries are another tool's and not the caller's to remove, so
337
+ // counting them here would refuse an add over a budget nobody can free.
338
+ const owned = [...this.registered.values()].filter((registered) => !registered.entry.reserved);
339
+ if (owned.length >= PRELOAD_LIMIT) {
340
+ throw new TooManyPreloadsError(`this run already has ${PRELOAD_LIMIT} preloads registered — remove one before adding another, or \`clear\` them all`, owned.map((registered) => registered.entry.id));
341
+ }
342
+ const definition = recipe === undefined ? undefined : recipeByName(recipe);
343
+ const body = definition === undefined
344
+ ? source
345
+ : definition.build(withDefaults(definition, params));
346
+ const preload = `p${(this.counter += 1)}`;
347
+ const ttl = ttlMinutes ?? DEFAULT_TTL_MINUTES;
348
+ const expiresAt = ttl > 0 ? new Date(Date.now() + ttl * 60_000) : null;
349
+ const origin = definition?.name ?? "raw";
350
+ const wrapped = envelope({
351
+ preload,
352
+ origin,
353
+ body,
354
+ expiresAt,
355
+ keepAcrossLoads: true,
356
+ });
357
+ const identifier = await this.transport.addScript(wrapped);
358
+ const entry = {
359
+ id: preload,
360
+ origin,
361
+ addedAt: new Date().toISOString(),
362
+ expiresAt: expiresAt?.toISOString() ?? null,
363
+ sourceSha: createHash("sha256")
364
+ .update(wrapped)
365
+ .digest("hex")
366
+ .slice(0, 12),
367
+ bytes: Buffer.byteLength(wrapped),
368
+ needsReload: definition?.needsReload ?? true,
369
+ };
370
+ const registered = { entry, identifier, source: wrapped };
371
+ this.registered.set(preload, registered);
372
+ this.onChange?.();
373
+ if (expiresAt) {
374
+ // unref'd: a pending expiry is not a reason for the run to stay up.
375
+ registered.timer = setTimeout(() => void this.expire(preload), expiresAt.getTime() - Date.now());
376
+ registered.timer.unref();
377
+ }
378
+ // A preload only ever runs at document start, so one added now does nothing
379
+ // until the next navigation — unless it is a kind that still means something
380
+ // mid-life, in which case running it once here is the difference between a
381
+ // tool that works and one that always answers "reload and ask again".
382
+ if (!entry.needsReload && this.transport.pageAvailable) {
383
+ await this.evaluateQuietly(wrapped);
384
+ }
385
+ return {
386
+ preload: await this.describe(registered),
387
+ recipe: definition?.name,
388
+ expired: this.drainExpired(),
389
+ };
390
+ }
391
+ async list() {
392
+ const state = await this.pageState();
393
+ return {
394
+ preloads: [...this.registered.values()].map((registered) => describeWith(registered, state)),
395
+ expired: this.drainExpired(),
396
+ limit: PRELOAD_LIMIT,
397
+ };
398
+ }
399
+ async read(preload, limit = DEFAULT_READ_LIMIT) {
400
+ const registered = this.require(preload);
401
+ const state = await this.pageState();
402
+ const slot = state?.[preload];
403
+ if (!slot) {
404
+ return {
405
+ preload,
406
+ origin: registered.entry.origin,
407
+ records: null,
408
+ active: false,
409
+ total: 0,
410
+ truncated: false,
411
+ dropped: 0,
412
+ };
413
+ }
414
+ const records = slot.records ?? [];
415
+ return {
416
+ preload,
417
+ origin: registered.entry.origin,
418
+ // Newest last, so a timeline reads in the direction it happened.
419
+ records: records.slice(Math.max(0, records.length - limit)),
420
+ active: true,
421
+ total: records.length,
422
+ truncated: records.length > limit,
423
+ dropped: slot.dropped ?? 0,
424
+ ...(slot.error ? { error: slot.error } : {}),
425
+ };
426
+ }
427
+ async remove(preload) {
428
+ this.require(preload);
429
+ const stoppedInPage = await this.retire([preload]);
430
+ return {
431
+ removed: [preload],
432
+ remaining: this.registered.size,
433
+ stoppedInPage,
434
+ };
435
+ }
436
+ async clear() {
437
+ const all = [...this.registered.values()]
438
+ .filter((registered) => !registered.entry.reserved)
439
+ .map((registered) => registered.entry.id);
440
+ const stoppedInPage = await this.retire(all);
441
+ return { removed: all, remaining: this.registered.size, stoppedInPage };
442
+ }
443
+ /**
444
+ * Install a script another tool owns, under a name instead of an id.
445
+ *
446
+ * Registered here rather than straight onto the transport so that one place
447
+ * still knows about every script running in the page: an agent that reads
448
+ * `sk onboarding inject list`, sees nothing, and concludes the page is unmodified while
449
+ * `sk onboarding debug` has hooks in it has been misled by the tool built to prevent
450
+ * exactly that. Replacing an existing reservation is the normal case — arming
451
+ * a different set of breakpoints is a new script under the same name.
452
+ */
453
+ async reserve(name, body) {
454
+ await this.release(name);
455
+ // Wrapped like any other preload, so a reserved script gets the same
456
+ // containment and the same `record`/`guard`/`summarise` helpers — and so
457
+ // `read` can drain its buffer through the one path that knows the shape.
458
+ const source = envelope({
459
+ preload: name,
460
+ origin: name,
461
+ body,
462
+ expiresAt: null,
463
+ });
464
+ const identifier = await this.transport.addScript(source);
465
+ this.changed = true;
466
+ this.registered.set(name, {
467
+ identifier,
468
+ source,
469
+ entry: {
470
+ id: name,
471
+ origin: name,
472
+ addedAt: new Date().toISOString(),
473
+ expiresAt: null,
474
+ sourceSha: createHash("sha256")
475
+ .update(source)
476
+ .digest("hex")
477
+ .slice(0, 12),
478
+ bytes: Buffer.byteLength(source),
479
+ needsReload: true,
480
+ reserved: true,
481
+ },
482
+ });
483
+ this.onChange?.();
484
+ }
485
+ async release(name) {
486
+ if (!this.registered.has(name)) {
487
+ return false;
488
+ }
489
+ await this.retire([name]);
490
+ return true;
491
+ }
492
+ /**
493
+ * Register everything again against a session that has just been made.
494
+ *
495
+ * A CDP session does not survive being detached, and the identifiers it
496
+ * handed out do not either. Without this a preload would keep appearing in
497
+ * `list` while no longer running in the browser, which is the one failure
498
+ * this tool cannot afford: every conclusion drawn from an empty buffer would
499
+ * be wrong in the same direction.
500
+ */
501
+ async reapply() {
502
+ for (const registered of this.registered.values()) {
503
+ registered.identifier = await this.transport.addScript(registered.source);
504
+ }
505
+ }
506
+ /** Whatever is left at the end of the run, dropped without ceremony. */
507
+ dispose() {
508
+ for (const registered of this.registered.values()) {
509
+ clearTimeout(registered.timer);
510
+ }
511
+ const had = this.registered.size > 0;
512
+ this.registered.clear();
513
+ if (had) {
514
+ this.onChange?.();
515
+ }
516
+ }
517
+ require(preload) {
518
+ const registered = this.registered.get(preload);
519
+ if (!registered) {
520
+ throw new NoSuchPreloadError(`no preload ${preload} on this run${this.registered.size > 0
521
+ ? ` — registered: ${[...this.registered.keys()].join(", ")}`
522
+ : " — none are registered"}`);
523
+ }
524
+ return registered;
525
+ }
526
+ async expire(preload) {
527
+ if (!this.registered.has(preload)) {
528
+ return;
529
+ }
530
+ await this.retire([preload]);
531
+ this.expired.push(preload);
532
+ }
533
+ /**
534
+ * Unregister and switch off, in that order.
535
+ *
536
+ * Unregistering stops the *next* document. The copy already running in this
537
+ * one has already installed its hooks and cannot be taken back out, so it is
538
+ * switched off through the flag every recipe checks before it records. A
539
+ * removal that did only the first half would leave a spy recording into a
540
+ * buffer nothing lists.
541
+ */
542
+ async retire(preloads) {
543
+ for (const preload of preloads) {
544
+ const registered = this.registered.get(preload);
545
+ if (!registered) {
546
+ continue;
547
+ }
548
+ clearTimeout(registered.timer);
549
+ await this.transport.removeScript(registered.identifier).catch(() => {
550
+ // A session that has gone took its registrations with it. Dropping the
551
+ // entry is still right, and reporting a CDP failure here would name the
552
+ // wrong problem.
553
+ });
554
+ this.registered.delete(preload);
555
+ this.changed = true;
556
+ }
557
+ if (this.changed) {
558
+ this.changed = false;
559
+ this.onChange?.();
560
+ }
561
+ if (!this.transport.pageAvailable || preloads.length === 0) {
562
+ return false;
563
+ }
564
+ return this.evaluateQuietly(`(function () {
565
+ var ns = window.${PAGE_NAMESPACE};
566
+ if (!ns) return false;
567
+ ${JSON.stringify(preloads)}.forEach(function (id) {
568
+ if (!ns[id]) return;
569
+ // Disabled first, then dropped. Disabling is what stops the hooks
570
+ // that are already installed; dropping it is what lets the same id
571
+ // install again, which a re-armed debugger and a second watch both
572
+ // need — the envelope's idempotency guard would otherwise refuse.
573
+ ns[id].disabled = true;
574
+ delete ns[id];
575
+ });
576
+ return true;
577
+ })()`);
578
+ }
579
+ /** Every entry's page-side state in one evaluation, or null when there is no page. */
580
+ async pageState() {
581
+ if (!this.transport.pageAvailable) {
582
+ return null;
583
+ }
584
+ try {
585
+ const serialized = await this.transport.evaluate(`JSON.stringify(window.${PAGE_NAMESPACE} || null)`);
586
+ return serialized
587
+ ? JSON.parse(serialized)
588
+ : null;
589
+ }
590
+ catch {
591
+ // A page that cannot answer is a page with no records to report, not a
592
+ // failed call: `active: false` is the honest answer and the caller still
593
+ // gets the registration it asked about.
594
+ return null;
595
+ }
596
+ }
597
+ async describe(registered) {
598
+ return describeWith(registered, await this.pageState());
599
+ }
600
+ async evaluateQuietly(expression) {
601
+ try {
602
+ await this.transport.evaluate(expression);
603
+ return true;
604
+ }
605
+ catch {
606
+ return false;
607
+ }
608
+ }
609
+ drainExpired() {
610
+ const expired = this.expired;
611
+ this.expired = [];
612
+ return expired;
613
+ }
614
+ }
615
+ function describeWith(registered, state) {
616
+ const slot = state?.[registered.entry.id];
617
+ return {
618
+ ...registered.entry,
619
+ active: Boolean(slot),
620
+ buffered: slot ? (slot.records?.length ?? 0) : null,
621
+ ...(slot?.error ? { error: slot.error } : {}),
622
+ };
623
+ }
624
+ function recipeByName(name) {
625
+ const recipe = RECIPES.find((candidate) => candidate.name === name);
626
+ if (!recipe) {
627
+ throw new UnknownRecipeError(`no recipe ${name} — this run has ${RECIPES.map((one) => one.name).join(", ")}`, RECIPES.map((one) => one.name));
628
+ }
629
+ return recipe;
630
+ }
631
+ /**
632
+ * The params a recipe will be built with, or the reason it cannot be.
633
+ *
634
+ * An unknown param is refused rather than ignored. A caller that misspells
635
+ * `intervalMs` and is silently given 200 gets a timeline that looks right and
636
+ * is not the one it asked for.
637
+ */
638
+ function withDefaults(recipe, params) {
639
+ const known = new Set(recipe.params.map((param) => param.name));
640
+ const unknown = Object.keys(params).filter((name) => !known.has(name));
641
+ if (unknown.length > 0) {
642
+ throw new BadRecipeParamsError(`\`${recipe.name}\` takes no param ${unknown.join(", ")} — it takes ${[...known].join(", ")}`, recipe.params);
643
+ }
644
+ const missing = recipe.params.filter((param) => param.required && params[param.name] === undefined);
645
+ if (missing.length > 0) {
646
+ throw new BadRecipeParamsError(`\`${recipe.name}\` needs ${missing.map((param) => param.name).join(", ")}`, recipe.params);
647
+ }
648
+ const resolved = { ...params };
649
+ for (const param of recipe.params) {
650
+ if (resolved[param.name] === undefined && param.default !== undefined) {
651
+ resolved[param.name] = param.default;
652
+ }
653
+ }
654
+ return resolved;
655
+ }
656
+ /** A value rendered as source. JSON is a subset of JavaScript literals. */
657
+ function literal(value) {
658
+ return JSON.stringify(value ?? null);
659
+ }
660
+ /**
661
+ * What every injected script is wrapped in, recipe or raw alike.
662
+ *
663
+ * Four things it guarantees, each of which has bitten someone:
664
+ *
665
+ * - **It cannot take the page down.** A preload runs in the MAIN world before
666
+ * any page script, so an exception in it is thrown before the site has run a
667
+ * line. The install is wrapped, and every hook a recipe installs is wrapped
668
+ * again, because the second throw comes later and would otherwise land inside
669
+ * the customer's own call stack.
670
+ * - **It is idempotent.** A document that somehow runs it twice — two sessions,
671
+ * a re-apply after a reconnect — must not wrap a seam twice and report every
672
+ * call twice.
673
+ * - **It is bounded.** The buffer has a ceiling and counts what it dropped, so
674
+ * a sampler left running overnight does not grow the tab until it dies, and
675
+ * a truncated timeline says that it is one.
676
+ * - **It is attributable.** `sourceURL` puts a name on it, so an exception in
677
+ * the run's output points here rather than at an anonymous eval.
678
+ *
679
+ * Globals are reached as properties of `window`, never as bare identifiers: a
680
+ * bare identifier that does not exist throws a `ReferenceError` that takes the
681
+ * whole script with it, which is the lesson the breakpoint pause-hook learned.
682
+ */
683
+ function envelope(options) {
684
+ const { preload, origin, body, expiresAt, keepAcrossLoads } = options;
685
+ return `(function () {
686
+ var ID = ${literal(preload)};
687
+ var NS = window.${PAGE_NAMESPACE} || (window.${PAGE_NAMESPACE} = {});
688
+ if (NS[ID]) return;
689
+ var EXPIRES = ${expiresAt ? expiresAt.getTime() : 0};
690
+ if (EXPIRES && Date.now() > EXPIRES) return;
691
+
692
+ var slot = (NS[ID] = {
693
+ id: ID,
694
+ origin: ${literal(origin)},
695
+ records: [],
696
+ dropped: 0,
697
+ disabled: false
698
+ });
699
+
700
+ // Which page load a record belongs to. A hard load is a new document and a
701
+ // new buffer; a single-page-app navigation or a back/forward-cache restore
702
+ // keeps the document, and without this its records ran on into the next
703
+ // page's: web-vitals' CLS total climbing across two pages. Shared by every
704
+ // preload in the document, so their load ids agree.
705
+ if (!NS.__load) {
706
+ var load = (NS.__load = {
707
+ id: String(Math.round((performance && performance.timeOrigin) || Date.now())),
708
+ nav: 0
709
+ });
710
+ // Best effort: a page without these still records, just without telling
711
+ // its single-page navigations apart.
712
+ try {
713
+ ["pushState", "replaceState"].forEach(function (name) {
714
+ var original = history[name];
715
+ if (typeof original !== "function") return;
716
+ history[name] = function () {
717
+ var before = location.href;
718
+ var result = original.apply(this, arguments);
719
+ if (location.href !== before) load.nav++;
720
+ return result;
721
+ };
722
+ });
723
+ addEventListener("popstate", function () { load.nav++; });
724
+ addEventListener("pageshow", function (event) { if (event.persisted) load.nav++; });
725
+ } catch (ignored) {}
726
+ }
727
+
728
+ function currentLoad() {
729
+ return NS.__load.nav ? NS.__load.id + "." + NS.__load.nav : NS.__load.id;
730
+ }
731
+
732
+ function currentUrl() {
733
+ try { return location.href; } catch (ignored) { return null; }
734
+ }
735
+
736
+ // A hard navigation is a new document and a new buffer, and the records of
737
+ // the load before went with the old one — the SSR load and the one Speed Kit
738
+ // hands over to are two loads, and the first was simply gone. Kept in
739
+ // sessionStorage across the origin's loads, labelled with their load ids.
740
+ var KEEP = ${keepAcrossLoads ? "true" : "false"};
741
+ var ARCHIVE = "__sk_inject:" + ID;
742
+ if (KEEP) {
743
+ try {
744
+ var kept = JSON.parse(sessionStorage.getItem(ARCHIVE) || "null");
745
+ if (kept && kept.records) {
746
+ slot.records = kept.records.slice(-${PAGE_BUFFER_LIMIT});
747
+ slot.dropped = kept.dropped || 0;
748
+ }
749
+ addEventListener("pagehide", function () {
750
+ try {
751
+ if (slot.disabled) { sessionStorage.removeItem(ARCHIVE); return; }
752
+ sessionStorage.setItem(ARCHIVE, JSON.stringify({
753
+ records: slot.records.slice(-${PAGE_BUFFER_LIMIT}),
754
+ dropped: slot.dropped
755
+ }));
756
+ } catch (ignored) {}
757
+ });
758
+ } catch (ignored) {}
759
+ }
760
+
761
+ function record(value) {
762
+ if (slot.disabled) return;
763
+ if (EXPIRES && Date.now() > EXPIRES) { slot.disabled = true; return; }
764
+ // Full: the oldest load gives way, so the page in front is always kept.
765
+ if (slot.records.length >= ${PAGE_BUFFER_LIMIT}) { slot.records.shift(); slot.dropped++; }
766
+ slot.records.push({
767
+ t: Math.round(performance.now()),
768
+ v: value,
769
+ load: currentLoad(),
770
+ url: currentUrl()
771
+ });
772
+ }
773
+
774
+ function guard(fn) {
775
+ return function () {
776
+ try { return fn.apply(this, arguments); }
777
+ catch (error) { slot.error = String((error && error.message) || error); }
778
+ };
779
+ }
780
+
781
+ function summarise(value, depth) {
782
+ depth = depth || 0;
783
+ if (typeof value === "function") return "[function " + (value.name || "anonymous") + "]";
784
+ if (value && value.nodeType) return "[node " + value.nodeName + "]";
785
+ if (value === null || typeof value !== "object") {
786
+ return typeof value === "string" && value.length > 200 ? value.slice(0, 200) + "\\u2026" : value;
787
+ }
788
+ if (depth >= 3) return "[deep]";
789
+ if (Array.isArray(value)) return value.slice(0, 20).map(function (item) { return summarise(item, depth + 1); });
790
+ var out = {};
791
+ var keys = Object.keys(value).slice(0, 30);
792
+ for (var i = 0; i < keys.length; i++) {
793
+ try { out[keys[i]] = summarise(value[keys[i]], depth + 1); }
794
+ catch (error) { out[keys[i]] = "[unreadable]"; }
795
+ }
796
+ return out;
797
+ }
798
+
799
+ function resolvePath(path) {
800
+ var parts = String(path).split(".");
801
+ var key = parts.pop();
802
+ var owner = window;
803
+ for (var i = 0; i < parts.length; i++) {
804
+ if (owner == null) return null;
805
+ owner = owner[parts[i]];
806
+ }
807
+ return owner == null ? null : { owner: owner, key: key };
808
+ }
809
+
810
+ function whenPresent(path, apply) {
811
+ var waited = 0;
812
+ (function attempt() {
813
+ if (slot.disabled) return;
814
+ var found = resolvePath(path);
815
+ if (found && found.owner[found.key] !== undefined) { guard(apply)(found); return; }
816
+ waited += 50;
817
+ if (waited > 10000) { record({ missing: path }); return; }
818
+ setTimeout(attempt, 50);
819
+ })();
820
+ }
821
+
822
+ try {${body}
823
+ } catch (error) {
824
+ slot.error = String((error && error.stack) || error);
825
+ }
826
+ })();
827
+ //# sourceURL=__sk-inject-${preload}.js
828
+ `;
829
+ }