I have written a Chrome extension and I am migrating it to other browsers like Firefox and Edge. However, the WebExtensions API on Firefox has some differences compared to Chrome's API.
So I have to detect whether I should use callback-style APIs (in Chrome, as well as in Edge) or the promise-style APIs (in Firefox).
For example:
if(RUNNING_ON_CHROME)
chrome.permissions.request({
permissions: ...,
origins: ...,
}, function(result) { // callback-style
...
});
else // running on firefox
browser.permissions.request({
permissions: ...,
origins: ...,
}).then(function(result) { // promise-style
...
});
I'm wondering how can I perform the RUNNING_ON_CHROME
test. Should I check the related string in UserAgent, or check browser!==undefined
?
ps. Edge uses browser.*
APIs but its API is callback-styled.
browser = browser || chrome
? – Vallybrowser.*
and Promises on Firefox while also having code that useschrome.*
and callbacks on Chrome? Just usechrome.*
and callbacks on both. Firefox fully supports using callbacks and thechrome.*
namespace for direct code compatibility (with some differences), where Firefox implements the API at all. – Earpiercing