v161 · concept 4 · edge / failure
Failure & policy gates
A phone page has to handle every way Translator.create() can refuse. Each card below triggers one refusal for real and compares the exception with the spec and with Chromium's create_translator_client.cc. None of these paths can start a download, because every one fails before the download step.
Translator is exposed…No gates run yet.
No user gesture
The spec requires transient activation when the pack is downloadable or downloading. This waits 6 s so your tap's activation expires (Chrome's window is 5 s), then calls create(). Expected: NotAllowedError, or success with no download if the pair is already available.
Permissions policy: iframe denied
A same-origin <iframe allow="translator 'none'"> (the translator feature defaults to 'self'). Expected: availability() returns unavailable and create() rejects with NotAllowedError.
Invalid language tag
availability({ sourceLanguage: "en", targetLanguage: "not a tag!" }). Tags are validated and canonicalised first. Expected: RangeError.
Missing targetLanguage
Both members of TranslatorCreateCoreOptions are required. Expected: TypeError from the WebIDL conversion.
Unsupported pair
en → kl (Kalaallisut, not in Chrome's list). Expected: availability() returns unavailable, and create() rejects with NotSupportedError with no download.
Already-aborted signal
The spec rejects with the signal's abort reason before anything else runs. This is how a page cancels when the user navigates away mid-download. Expected: AbortError.
Enterprise policy signature
TranslatorAPIAllowed=false (supported on Android from 161) can't be set by a page. When it's set, every pair reports unavailable even though the API is exposed and the permissions policy allows it, and the console logs “The translation is disallowed by policy.” This card checks four common pairs and says whether the result matches that signature. It's an inference. It doesn't read the policy.
the code
try {
translator = await Translator.create({ sourceLanguage, targetLanguage, signal });
} catch (e) {
switch (e.name) {
case "NotAllowedError": // no gesture for a download, permissions policy, or the user declined
case "NotSupportedError": // unsupported pair, TranslatorAPIAllowed=false, disk space, service limits
case "AbortError": // your signal
case "NetworkError": // download failed
case "RangeError": // bad BCP 47 tag
case "TypeError": // missing required option
}
}