Closed Bug 1891186 Opened 5 months ago Closed 5 months ago

Can't use async/await on chrome namespace alias in add-on

Categories

(WebExtensions :: Untriaged, defect)

Firefox 124
defect

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: tom_xyz, Unassigned)

References

Details

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0

Steps to reproduce:

Given the code below, using the chrome namespace failed, but browser namespace worked.

background.js:

chrome.runtime.onInstalled.addListener(async () => {
  const chromeItems = await chrome.storage.local.get();
  const browserItems = await browser.storage.local.get();
  // chromeItems is undefined, browserItems is a valid object
  console.log(chromeItems, browserItems);
});

Interestingly, using a callback worked:

chrome.storage.local.get((items) => {
  console.log(items);
});

Actual results:

chromeItems was undefined; browserItems was a valid object.

Expected results:

Both chromeItems and browserItems should have been identical valid objects if chrome is a true alias.

The Bugbug bot thinks this bug should belong to the 'WebExtensions::Untriaged' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Product: Firefox → WebExtensions

Hello,

Could you provide an example extension demonstrating the bug? Thank you !

Flags: needinfo?(tom_xyz)

We fixed this in Manifest Version 3, but in Manifest Version 2 extensions, chrome is still Promise-based. In Chrome's manifest version 2, chrome does not support Promises either.

You should use the browser namespace if you'd like to have a Promise-based extension API.

Flags: needinfo?(tom_xyz)
See Also: → 1711570

Thanks for confirming Rob. I tried my best to move to MV3 while keeping the same code base as the Chrome/Edge version, but unfortunately it was too much of an overhead (mainly because of divergence in how user scripts and service workers are handled), hence I'm stuck in MV2 for now :(. I'll switch to browser and close this.

Status: UNCONFIRMED → RESOLVED
Closed: 5 months ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.