v157 · concept 2 · inspection / configuration
Download on a constrained device
On a phone, downloadable means Chrome would have to fetch the language-detection model over whatever connection the person has right now. This page reads the signals a mobile page can actually see (connection type, Save-Data, device memory, free storage, online state), combines them with availability() and recommends one of three actions: detect now, ask first, or wait. The download itself only starts when you press the button that says so.
LanguageDetector is exposed…1 · what this device reports
Where a signal isn't exposed (for example navigator.connection and deviceMemory are Chromium-only), the page says unknown and doesn't guess.
2 · decide
3 · download only when asked
This calls LanguageDetector.create({ monitor, signal }) inside your tap. If the model is downloadable, Chrome starts fetching it and reports downloadprogress events. Cancel aborts the AbortSignal.
why this matters on Android
- Chromium only allows
create()without a gesture when the model is alreadyavailable. Fordownloadableanddownloadingit needs transient activation, so a page can't silently spend someone's mobile data. - The Language Detector model is a separate component from the Translator language packs. A page that detects and then translates may need two downloads; check both before promising anything (see the composer).
monitorevents report a fraction from 0 to 1, not bytes. Chrome deliberately doesn't expose the model's size to the page, so the page should describe the cost in words.
the code
const ac = new AbortController();
button.onclick = async () => { // inside the tap: transient activation
const detector = await LanguageDetector.create({
signal: ac.signal,
monitor: (m) => m.addEventListener("downloadprogress", (e) => progress.value = e.loaded),
});
};
cancel.onclick = () => ac.abort(); // create() rejects with AbortError
see also
- Availability & expected languages
- Failure & policy gates: the
NotAllowedErroryou get without a tap - The same decision for Translator packs (v161)
- ChromeStatus entry (5087964794322944)
- Spec: creating a language detector