Skip to content

Commit f478eab

Browse files
authored
Update availability values and add "downloading"
See webmachinelearning/writing-assistance-apis#29.
1 parent 750d2d9 commit f478eab

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,24 @@ This will allow the implementation to download additional resources like languag
9191

9292
Both APIs provide the ability to know, before calling `create()`, what is possible with the implementation. This is done via `availability()` methods, which takes the same options as `create()`. They return a promise, which fulfills with one of the following values:
9393

94-
* `"no"` means that the implementation does not support translation or language detection of the given language(s).
95-
* `"after-download"` means that the implementation supports translation or language detection of the given language(s), but it will have to download something (e.g., a machine learning model) as part of creating the associated object.
96-
* `"readily"` means that the implementation supports translation or language detection of the given language(s), without performing any downloads.
94+
* `"unavailable"` means that the implementation does not support translation or language detection of the given language(s).
95+
* `"downloadable"` means that the implementation supports translation or language detection of the given language(s), but it will have to download something (e.g., a machine learning model) as part of creating the associated object.
96+
* `"downloading"` means that the implementation supports translation or language detection of the given language(s), but it will have to finish an ongoing download as part of creating the associated object.
97+
* `"available"` means that the implementation supports translation or language detection of the given language(s), without performing any downloads.
9798

9899
Here is an example that adds capability checking to log more information and fall back to cloud services, as part of a language detection plus translation task:
99100

100101
```js
101102
async function translateUnknownCustomerInput(textToTranslate, targetLanguage) {
102-
const canDetect = await ai.languageDetector.availability();
103+
const detectorAvailability = await ai.languageDetector.availability();
103104

104105
// If there is no language detector, then assume the source language is the
105106
// same as the document language.
106107
let sourceLanguage = document.documentElement.lang;
107108

108109
// Otherwise, let's detect the source language.
109-
if (canDetect !== "no") {
110-
if (canDetect === "after-download") {
110+
if (detectorAvailability !== "unavailable") {
111+
if (detectorAvailability !== "available") {
111112
console.log("Language detection is available, but something will have to be downloaded. Hold tight!");
112113
}
113114

@@ -123,13 +124,13 @@ async function translateUnknownCustomerInput(textToTranslate, targetLanguage) {
123124
}
124125

125126
// Now we've figured out the source language. Let's translate it!
126-
const availability = await ai.translator.availability({ sourceLanguage, targetLanguage });
127-
if (availability === "no") {
127+
const translatorAvailability = await ai.translator.availability({ sourceLanguage, targetLanguage });
128+
if (translatorAvailability === "unavailable") {
128129
console.warn("Translation is not available. Falling back to cloud API.");
129130
return await useSomeCloudAPIToTranslate(textToTranslate, { sourceLanguage, targetLanguage });
130131
}
131132

132-
if (availability === "after-download") {
133+
if (translatorAvailability !== "available") {
133134
console.log("Translation is available, but something will have to be downloaded. Hold tight!");
134135
}
135136

@@ -223,7 +224,7 @@ interface AICreateMonitor : EventTarget {
223224
224225
callback AICreateMonitorCallback = undefined (AICreateMonitor monitor);
225226
226-
enum AICapabilityAvailability { "readily", "after-download", "no" };
227+
enum AIAvailability { "unavailable", "downloadable", "downloading", "available" };
227228
```
228229

229230
```webidl
@@ -232,7 +233,7 @@ enum AICapabilityAvailability { "readily", "after-download", "no" };
232233
[Exposed=(Window,Worker), SecureContext]
233234
interface AITranslatorFactory {
234235
Promise<AITranslator> create(AITranslatorCreateOptions options);
235-
Promise<AICapabilityAvailability> availability(AITranslatorCreateCoreOptions options);
236+
Promise<AIAvailability> availability(AITranslatorCreateCoreOptions options);
236237
};
237238
238239
[Exposed=(Window,Worker), SecureContext]
@@ -267,7 +268,7 @@ dictionary AITranslatorTranslateOptions {
267268
[Exposed=(Window,Worker), SecureContext]
268269
interface AILanguageDetectorFactory {
269270
Promise<AILanguageDetector> create(optional AILanguageDetectorCreateOptions options = {});
270-
Promise<AICapabilityAvailability> availability(optional AILanguageDetectorCreateCoreOptions = {});
271+
Promise<AIAvailability> availability(optional AILanguageDetectorCreateCoreOptions = {});
271272
};
272273
273274
[Exposed=(Window,Worker), SecureContext]
@@ -317,15 +318,15 @@ This design means that the implementation must have all information about the ca
317318

318319
This proposal as-is has privacy issues, which we are actively thinking about how to address. They are all centered around how sites that use this API might be able to uniquely fingerprint the user.
319320

320-
The most obvious identifier in the current API design is the list of supported languages, and especially their availability status (`"no"`, `"readily"`, or `"after-download"`). For example, as of the time of this writing [Firefox supports 9 languages](https://www.mozilla.org/firefox/features/translate/), which can each be [independently downloaded](https://support.mozilla.org/kb/website-translation#w_configure-installed-languages). With a naive implementation, this gives 9 bits of identifying information, which various sites can all correlate.
321+
The most obvious identifier in the current API design is the list of supported languages, and especially their availability status (`"unavailable"`, `"downloadable"`, `"downloading"`, and `"available"`). For example, as of the time of this writing [Firefox supports 9 languages](https://www.mozilla.org/firefox/features/translate/), which can each be [independently downloaded](https://support.mozilla.org/kb/website-translation#w_configure-installed-languages). With a naive implementation, this gives 9 bits of identifying information, which various sites can all correlate.
321322

322323
Some sort of mitigation may be necessary here. We believe this is adjacent to other areas that have seen similar mitigation, such as the [Local Font Access API](https://github.com/WICG/local-font-access/blob/main/README.md). Possible techniques are:
323324

324325
* Grouping language packs to reduce the number of bits, so that downloading one language also downloads others in its group.
325326
* Partitioning download status by top-level site, introducing a fake download (which takes time but does not actually download anything) for the second-onward site to download a language pack.
326327
* Only exposing a fixed set of languages to this API, e.g. based on the user's locale or the document's main language.
327328

328-
As a first step, we require that detecting the availability of translation/detection be done via individual calls to `ai.translator.availability()` and `ai.languageDetector.availability()`. This allows browsers to implement possible mitigation techniques, such as detecting excessive calls to these methods and starting to return `"no"`.
329+
As a first step, we require that detecting the availability of translation/detection be done via individual calls to `ai.translator.availability()` and `ai.languageDetector.availability()`. This allows browsers to implement possible mitigation techniques, such as detecting excessive calls to these methods and starting to return `"unavailable"`.
329330

330331
Another way in which this API might enhance the web's fingerprinting surface is if translation and language detection models are updated separately from browser versions. In that case, differing results from different versions of the model provide additional fingerprinting bits beyond those already provided by the browser's major version number. Mandating that older browser versions not receive updates or be able to download models from too far into the future might be a possible remediation for this.
331332

0 commit comments

Comments
 (0)