Skip to main content
The browser can veto prediction when a page is hidden, data saving is enabled, or the connection is slow. NavigationMetrics separately measures whether correct work began early enough to help.

Environment checks

The evaluator blocks prediction when: 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:
The default observer requires a browser. In SSR, workers, and tests, avoid calling it without an explicit observable environment. The framework-neutral coordinator and scheduler do not require the browser entry point.

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:
The runtime’s now() uses Date.now(). For fully controlled clocks, inject a custom PredictionSchedulerRuntime into PredictionScheduler instead. 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.