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