If you like promises, it’s best to use browser
namespace and in the Chrome use the web-extension polyfill:
It will allow you to use Promise-based API in both browsers.
But anyway, cross browser development is now pretty challenging due to Manifest V3 / V2 incompatibilities. All of my addons are still V2 and I plan to migrate to V3 as late as possible due to many complications.
I can’t tell what is wrong with the code you’ve posted, it doesn’t really do anything visible unless some other code is listening for the message - but how could it, the background script is usually executed before any other context so when the message is send, nobody will receive it.
Also, use the common debugging techniques to find out what is running when, use console.log
, debugger
statement, etc…