Open Bug 1868153 Opened 6 months ago Updated 6 months ago

Inconsistency: storage.managed.get() rejects with an error when the enterprise policy is not found

Categories

(WebExtensions :: General, defect, P3)

defect

Tracking

(Not tracked)

People

(Reporter: eros_uk, Unassigned)

References

(Depends on 1 open bug)

Details

(Whiteboard: [wecg])

As posted in 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(() => {}));

})();

Not found Result

Chrome

  • no-catch: { }
  • with-catch: { }

Firefox

  • no-catch: Uncaught (in promise) Error: Managed storage manifest not found
  • with-catch: undefined

The behavior is a consequence of the storage.managed_schema support.
In Chrome, managed_schema describes the supported keys, with fallbacks if any. When the enterprise policy is not set, the keys specified in the schema JSON file (referenced by storage.managed_schema in manifest.json) are used, including their default value if any.
In Firefox, managed_schema is not supported. The managed storage values are directly taken from the enterprise policy. If it does not exists, an error is raised.

Even if we could silence the errors, extension developers should still be prepared to not have identical behavior between the browsers, until managed_schema is supported (bug 1771731).


P.S. The catch vs no-catch in the report is not meaningful.

When a promise rejects, the .catch(() => {}) part is executed. The {} after the arrow function does not denote an object, but the delimiters of the arrow function's body. The following lines are equivalent:

  console.log(await chrome.storage.managed.get().catch(() => {}));
  console.log(await chrome.storage.managed.get().catch(function () {}));
  console.log(await chrome.storage.managed.get().catch(function () { return undefined; }));
Component: Enterprise Policies → General
Depends on: 1771731
Product: Firefox → WebExtensions
Whiteboard: [wecg]
Summary: Inconsistency: Enterprise Policy and storage.managed → Inconsistency: storage.managed.get() rejects with an error when the enterprise policy is not found

When a promise rejects, the .catch(() => {})part is executed. The {} after the arrow function does not denote an object, but the delimiters of the arrow function's body.

The catch in the examples was not meant to return an object {} but to silence the rejection error.

Note: even if if we don't implement validation (bug 1771731), the least we could do is to use storage.managed_schema to provide the keys (and defaults) if any, merged with the enterprise policy-specified defaults.

:zombie stated that Firefox's implementation mirrors the enterprise policy and that my suggestion would result in the inability to detect the absence of the enterprise policy. Both scenarios can be supported: if the extension does not define storage.managed_schema, then Firefox's current behavior can be used. If storage.managed_schema is provided, extension developers would reasonably expect Chrome behavior, and we could close the API compatibility gap there.

In any case, we're not going to make any changes until a consensus has been reached in the WECG at https://github.com/w3c/webextensions/issues/497

Severity: -- → S4
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.