firefox-addonfirefox-addon-webextensions

ai api for firefox - browser.trial is not defined in firefox 136.0


I'm trying out Firefox's WebExtensions Ai API, and trying to run their example code. However, I'm getting the error Uncaught TypeError: browser.trial is undefined.

Their instructions say:

For Beta and Release, toggle the following flags in about:config:

browser.ml.enable → true

extensions.ml.enabled → true

In addition, you must this to the manifest.json:

{
    "optional_permissions": ["trialML"],
}

I feel like they must have missed a flag, because I did the above and it's still not working.


Solution

  • Optional permissions must be enabled. There are two ways to enable the optional permission.

    1. Go to about:addons
    2. Select Extensions. Select your extension. Select Permissions.
    3. Toggle the switch labeled Download and run AI models on your device.

    OR

    Use the browser.permissions API to to see if trialML is already enabled. (browser.permissions.contains( { permissions: [ 'trialML' ] } )) If not, use the API to request it (browser.permissions.request( { permissions: [ 'trialML' ] } );) as a response to user input (e.g., clicking a button).

    FWIW, I tested these things on FF135 released. I didn't test whether the browser.trial.ml API was fully functional, but it did contain createEngine, runEngine, onProgress, and deleteCachedModels.