Can't use async/await on chrome namespace alias in add-on
Categories
(WebExtensions :: Untriaged, defect)
Tracking
(Not tracked)
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.
Comment 1•5 months ago
|
||
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.
Comment 2•5 months ago
|
||
Hello,
Could you provide an example extension demonstrating the bug? Thank you !
Comment 3•5 months ago
|
||
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.
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.
Description
•