NavigationMetrics separately measures whether correct work began early enough to help.
Environment checks
browserAllowsPrediction() returns the boolean result. Both functions accept an explicit
environment for deterministic tests.
Observe changes
observeBrowserPredictionEnvironment() calls its listener immediately and after visibility or
connection changes:
Idle scheduling
createBrowserPredictionSchedulerRuntime() uses requestIdleCallback when available and falls back
to a zero-delay timer. Foreground and environment gates still run first.
You can pass an explicit BrowserSchedulerHost for tests or embedded runtimes:
now() uses Date.now(). For fully controlled clocks, inject a custom
PredictionSchedulerRuntime into PredictionScheduler instead.
Navigation metrics
NavigationMetrics correlates prefetch and navigation timestamps with the same host-owned key:
recordNavigationCompleted() returns undefined if no navigation start exists. Otherwise it
returns:
Ordinary navigation can be measured without a prediction. The prefetch fields are then absent and
prefetchSettledBeforeNavigation is false, giving the host a natural baseline.
The class stores pending records in memory. It defaults to at most 24 records and a 120-second TTL;
maxPending and ttlMs are configurable. clear(key?) removes one correlation or all pending
correlations. Telemetry callback failures are isolated from navigation.
Interpret timing
prefetchLeadMs measures the head start; prefetchSettledBeforeNavigation shows whether work
finished before commitment. Pair timing with markReused() and quality() because timing alone does
not prove reuse.
Optional ranking
@inttegro/cogni-client/chrome-ai can rerank a bounded host allowlist. It cannot invent destinations,
assign probabilities, start work, or download a model. It returns null when unavailable or invalid.
See the client API.