# Testing an offline shell around on-device AI

> A React editor separates shell, draft, and model readiness, then verifies a controlled offline reload and an honest storage-failure recovery path.

On 2026-11-27, Raju Dandigam published a React brief-editor example that treats the application shell, a locally saved draft, and a browser-provided AI model as independent offline dependencies. Its documented browser run established service worker control, disabled connectivity, reloaded Headless Chrome 153, and recovered the exact synthetic text; the run did not claim that model inference had passed offline ([Raju Dandigam](https://dev.to/gde/your-on-device-ai-works-offline-does-your-web-app-38kj)).

## Impact of separating shell, draft, and model readiness

Chrome's built-in AI documentation lists APIs at different development stages. Some are in Chrome Stable, others are in origin trials, and others are limited to Early Preview Program participants. A product therefore has to check the requested API and task in its target Chrome release; the existence of one built-in API does not establish availability of another ([Chrome for Developers](https://developer.chrome.com/docs/ai/built-in-apis)).

The surrounding web application has a separate delivery path. Dandigam's editor generates a versioned cache name from its emitted HTML and JavaScript, with CSS included too. It then precaches that allowlist during service worker installation. A failed required fetch makes installation fail instead of presenting the shell as complete. The worker handles root navigation with a network request and cached fallback, and it leaves requests outside the same-origin allowlist untouched ([Raju Dandigam](https://dev.to/gde/your-on-device-ai-works-offline-does-your-web-app-38kj)).

Chrome's caching-strategy guide defines cache first and network first as different request policies. It also defines stale-while-revalidate alongside network-only and cache-only policies. Network first suits resources where the newest response matters and a cached response can serve as fallback. Cache first suits assets whose cached version is acceptable. Choose per request type; registering a worker does not choose a correct policy for the application ([Chrome for Developers](https://developer.chrome.com/docs/workbox/caching-strategies-overview)).

The draft is the third dependency. MDN says `window.localStorage` exposes storage for the document's origin and that its data is saved across browser sessions. Private-browsing data is cleared when the last private tab closes. A successful shell load therefore does not prove that a draft write succeeded, and a `localStorage` result does not say whether a model is prepared ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage)).

### Expose three readiness checks

Track the shell controller and draft write separately from the requested AI capability. The source example warns against setting a single "Offline ready" label after registration because registration does not prove that the worker controls the page, that required assets entered the cache, or that the model can run. It also treats native AI as optional and checks it independently ([Raju Dandigam](https://dev.to/gde/your-on-device-ai-works-offline-does-your-web-app-38kj)).

Use a small diagnostic object in the UI or test harness:

```js
const readiness = {
  shellControlled: Boolean(navigator.serviceWorker.controller),
  draftSaved: false,
  modelStatus: "unchecked",
};

function saveDraft(text) {
  try {
    localStorage.setItem("web-ai-lab-brief", text);
    readiness.draftSaved =
      localStorage.getItem("web-ai-lab-brief") === text;
  } catch {
    readiness.draftSaved = false;
  }
  renderReadiness(readiness);
}
```

The equality check confirms that this attempted value can be read back in the same origin and session. It does not test backup or retention guarantees. It also does not check multi-device synchronization. Dandigam's implementation catches write failures and tells the person to copy the draft before closing; MDN documents `localStorage` as origin storage persisted across browser sessions, with separate private-browsing behavior ([Raju Dandigam](https://dev.to/gde/your-on-device-ai-works-offline-does-your-web-app-38kj); [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage)).

Do not use `navigator.onLine` as proof that the model or an application endpoint is reachable. MDN describes the property as inherently unreliable because browsers and operating systems use different heuristics; a local network can count as online even when internet access is absent. Use it only as a hint and test the operation whose result the UI promises ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/onLine)).

### Build and verify the returning-user route

The source project's production path runs `npm run build` and then `npm run preview`; its development server intentionally does not register the production worker. Use the equivalent production build and preview commands for your application, and inspect the generated worker to confirm that its allowlist names the emitted shell assets. A placeholder cache list cannot establish that the deployed output is covered ([Raju Dandigam](https://dev.to/gde/your-on-device-ai-works-offline-does-your-web-app-38kj)).

With the production preview running, follow this sequence:

1. Open the editor online and wait for `navigator.serviceWorker.ready`.
2. Reload once, then confirm `navigator.serviceWorker.controller` is non-null.
3. Enter a synthetic brief that contains no confidential information, then save it.
4. Read the same storage key and confirm exact equality.
5. Disable connectivity in the browser test environment.
6. Reload the document completely.
7. Assert that the editor renders and the recovered text equals the saved value.
8. Invoke the selected AI task separately and record its own availability or result.

The source's Headless Chrome 153 run passed steps that cover the controlled editor shell and exact draft recovery after the disconnected reload. It explicitly leaves model inference to a separate native preparation and offline run. Keep those outcomes separate in test output so an editor success cannot be presented as an AI success ([Raju Dandigam](https://dev.to/gde/your-on-device-ai-works-offline-does-your-web-app-38kj)).

Repeat from a fresh browser profile with no earlier visit. Dandigam identifies offline first visit as unsupported because that profile has no installed shell. The expected observation is a load failure or browser offline response. The returning-user editor should not appear. Record that result as a separate scenario instead of combining it with the prepared returning-user run ([Raju Dandigam](https://dev.to/gde/your-on-device-ai-works-offline-does-your-web-app-38kj)).

### Test the failure paths that preserve work

Force the storage write path to fail in a controlled test and assert that the UI removes any unqualified saved indicator. The recovery message must tell the person to copy the text before closing. The source uses exactly that fallback for a failed `localStorage.setItem()` call and recommends retaining the same user-facing rule if a richer editor moves to IndexedDB ([Raju Dandigam](https://dev.to/gde/your-on-device-ai-works-offline-does-your-web-app-38kj)).

Next, remove one required shell asset from a test deployment. The service worker installation should fail and avoid advertising a complete offline shell. Restore the asset, change the generated cache version, reload online until the fixed worker controls the page, and repeat the disconnected reload. This recovery follows the source's rule that a required precache failure invalidates installation ([Raju Dandigam](https://dev.to/gde/your-on-device-ai-works-offline-does-your-web-app-38kj)).

Test a model-unavailable state while the editor still opens. Chrome's API table has different release channels and availability for each API, so the UI should report the requested task's own state. If model preparation is required, expose that state. Do not call the complete experience offline-ready until the intended inference succeeds after a reload without connectivity ([Chrome for Developers](https://developer.chrome.com/docs/ai/built-in-apis); [Raju Dandigam](https://dev.to/gde/your-on-device-ai-works-offline-does-your-web-app-38kj)).

The source worker does not cache Chrome's built-in model internals. For an application-served model and runtime, model files join the application's own delivery plan. They need explicit versions and integrity records, plus defined download behavior and cache rules. Keep them out of a small editor-shell precache unless the product deliberately makes that download part of installation ([Raju Dandigam](https://dev.to/gde/your-on-device-ai-works-offline-does-your-web-app-38kj)).

### Update the shell without interrupting the draft

Dandigam's worker deletes only older caches bearing its application prefix when a new version activates. It avoids forcing immediate activation with `skipWaiting()` because replacing the worker beneath an open editor can mix versions or interrupt work. A larger editor should offer the update after the draft has been saved or exported ([Raju Dandigam](https://dev.to/gde/your-on-device-ai-works-offline-does-your-web-app-38kj)).

Keep old versioned assets on the server during the supported update window. A cache can help a previously installed client only when it already contains the requested asset; it cannot retrieve a missing file after the server has removed it. Verify an update with an open old tab and a waiting new worker. Save the draft before a controlled reload into the new shell ([Raju Dandigam](https://dev.to/gde/your-on-device-ai-works-offline-does-your-web-app-38kj)).

Storage policy also belongs in the product design. The example calls its brief synthetic and small. It does not present browser storage as backup or synchronization. It says real products need retention and deletion controls, with a storage choice matched to data sensitivity and size. Preserve that boundary when adapting the sample to user documents ([Raju Dandigam](https://dev.to/gde/your-on-device-ai-works-offline-does-your-web-app-38kj)).

:::caution
`navigator.onLine` uses browser and operating-system heuristics and can report a network connection that cannot reach the internet. Do not use it as the pass condition for model availability or draft synchronization. It does not establish API reachability either ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/onLine)).
:::

## Related entries

- [Capabilities](/reference/capabilities/): follow this entry for capability categories and their supporting evidence.
- [Performance](/reference/performance/): follow this entry for loading and runtime guidance, including measurement.
- [Storage](/reference/storage/): follow this entry for browser storage behavior covering quota and persistence.

## Open and unverified

The cited Headless Chrome 153 result verifies only the source project's controlled shell reload and exact synthetic-draft recovery. This repository has not repeated that run. No tested device or operating-system version was supplied here, and neither was a screenshot or evidence file.

Offline inference for any specific built-in AI API remains unverified in this entry. Test its availability and preparation state for the selected API and Chrome release. Test the downloaded model state and result too. Retention after browser storage eviction and recovery across devices are also unverified.

## Sources

- [Your On-Device AI Works Offline. Does Your Web App?](https://dev.to/gde/your-on-device-ai-works-offline-does-your-web-app-38kj) (DEV Community)
- [Built-in AI APIs](https://developer.chrome.com/docs/ai/built-in-apis) (Chrome for Developers)
- [Caching strategies](https://developer.chrome.com/docs/workbox/caching-strategies-overview) (Chrome for Developers)
- [Window: localStorage property](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) (MDN)
- [Navigator: onLine property](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/onLine) (MDN)