w3c / webextensions

Charter and administrivia for the WebExtensions Community Group (WECG)
Other
579 stars 50 forks source link

Inconsistency: storage.managed #497

Open erosman opened 7 months ago

erosman commented 7 months ago

Inconsistency: storage.managed

Please note some inconsistencies regarding the storage.managed API. Other browsers not checked.

(async () => {

  // no catch
  console.log(await chrome.storage.managed.get());
  console.log(await browser.storage.managed.get());

  // with catch
  console.log(await chrome.storage.managed.get().catch(() => {}));
  console.log(await browser.storage.managed.get().catch(() => {}));

})();
ChromeFirefox
manifest.json
"storage": {
  "managed_schema": "schema.json"
},
not required
schema.jsonrequirednot required
not found
no-catch
{ }Uncaught (in promise) Error: Managed storage manifest not found
not found
with-catch
{ }undefined
Policy location: linux /etc/opt/chrome/policies/managed/ /etc/firefox/policies
firefox/distribution
Policy Format
{
  "3rdparty": {
    "extensions": {
      "extension-ID": { }
    }
  }
}

Note: "extensions"
{
  "policies": {
    "3rdparty": {
      "Extensions": {
        "extension-ID": { }
      }
    }
  }
}
Note: "policies" & "Extensions"
Manifest location: linux n/a /usr/lib/mozilla/managed-storage/{name}.json
~/.mozilla/managed-storage/{name}.json

See also: https://bugzilla.mozilla.org/show_bug.cgi?id=1868153

stefanvd commented 7 months ago

I found this also an issue that gives me browser extension no harmony the same for all web browsers. I have discussed it in my latest blog post titled "Firefox Manifest V3 Extension: A Developer's Perspective," which you can read at https://www.stefanvd.net/blog/2023/11/30/firefox-manifest-v3-extension-a-developer-perspective/.

If the group looking for an example that uses the managed store, you can check out my Open-Source Turn Off the Lights Chrome extension and Firefox extension. The code can be found at https://github.com/turnoffthelights/Turn-Off-the-Lights-Chrome-extension/blob/manifest-v3/src/schema.json

(I also added this issue link also on my blog post)

Rob--W commented 7 months ago

The policy location and formats are browser-specific and won't converge to one location.

The managed_schema JSON file is not implemented in Firefox, because we felt that it did not make sense to implement something that was under-specified as Chrome's managed_schema JSON format. The Firefox-side bug to track this feature is at https://bugzilla.mozilla.org/show_bug.cgi?id=1771731

Agreeing on a common schema format is required before an implementation of managed_schema can be considered in Firefox. If the "common format" is too simple and doesn't include features that are supported and used, then a strict enforcement of the schema by Firefox would result in the inability to configure an extension as desired. If the "common format" is too broad, then that would add significant complexity and maintenance burden on Firefox (which introduces the risk of bugs).

If the group looking for an example that uses the managed store, you can check out my Open-Source Turn Off the Lights Chrome extension and Firefox extension. The code can be found at https://github.com/turnoffthelights/Turn-Off-the-Lights-Chrome-extension/blob/manifest-v3/src/schema.json

Here is another example of a more complex schema: https://github.com/mozilla/pdf.js/blob/d56453289c4a37beb3dbbd108e78c18b6d34fa90/extensions/chromium/preferences_schema.json Note that it uses enum, which is supported but not even documented at Chrome's documentation of storage.managed_schema: https://developer.chrome.com/docs/extensions/reference/manifest/storage

The policy formats themselves are also complicated: The policy formats are platform-specific (but in a format that should be recognizable by administrators who already use policy templates).

twschiller commented 7 months ago

In Chromium, I think there's also a bug where managed storage might not be available immediately on extension initialization. Would you happen to know if the intended behavior/guarantees are specified anywhere?

The gotcha is that we want to use managed storage to control enterprise options that impact extension startup, e.g., specifying the SAML URL for authentication. So ideally, we wouldn't have to make a timeout assumption because that impacts user experience because we have to be conservative

erosman commented 7 months ago

Please note that the differences are listed for information and not recommendations.

managed_schema

There are many of new schema features that are not supported in Chrome schema such as: $def, $ref pointing "#/$defs/include" or "#/definitions/include" (I couldn't get it to work on Chrome although they validates fine) and more.

TBH, not having managed_schema makes it simpler.

Return

The return value when the managed storage is not found, is the most relevant inconsistency.

Policy Properties

The inconsistency in the format of the policy could be considered e.g. "policies" & "Extensions"