5

So I couldn't find anything that talked about using chrome.* or browser.* specifically. In some of the WebExtension examples it uses browser.* (browser.runtime.getManifest();) https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/getManifest, and in others it uses chrome.* (chrome.notifications.create), https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/notifications.

I'm not entirely sure what's the difference. Is it contextual? Both chrome.* and browser.* are available in my content script and in the background script in Firefox. I looked at IEs docs as well and they use browser.* ( didn't see chrome.* in their docs)

I'd like to know what the difference is between and do Chrome extensions only use chrome.* or does it have browser.* as well (does IE only have browser.*)?

Knight Yoshi
  • 924
  • 3
  • 11
  • 32
  • Highly related, potentially a duplicate: [Using chrome.tabs vs browser.tabs for browser compatibility](http://stackoverflow.com/questions/39544625/using-chrome-tabs-vs-browser-tabs-for-browser-compatibility) – Makyen Nov 24 '16 at 03:02
  • As of 2021 there is way to make plugins that will work in Chrome, Firefox, Safari, see https://stackoverflow.com/questions/68571983/web-extension-browser-plugin-for-chrome-firefox-safari-standard-reference-an – Paul Verest Jul 29 '21 at 07:47

3 Answers3

9

Chrome only has chrome.apis. Edge only has browser.apis. Firefox has both browser.apis and chrome.apis for compatibility with existing Chrome extensions.

The main difference is that in Firefox the browser.apis use promises but the chrome.apis use callbacks.

Daniel Herr
  • 19,083
  • 6
  • 44
  • 61
  • Chrome's chrome.apis use callbacks as well? I also quickly looked up Edge's browser.storage, it doesn't use promises? https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9420301/ Basically I'm looking at how to make it most cross-browser compatible without having to go and change every JS file where the *.api is called between the different browsers or is that going to happen anyway? – Knight Yoshi Nov 24 '16 at 03:03
  • To note, I'm developing in Firefox and utilizing it's promises from browser.*. – Knight Yoshi Nov 24 '16 at 03:04
  • 1
    @KnightYoshi, If you want cross browser compatibility use `chrome.*`, not `browser.*` It is relatively easy to polyfill from `chrome.*` (callback) calls to their `browser.*` (Promise) equivalents. It is difficult to do the reverse because the callback function information does not exist in the API call when you call a `browser.*` API. Also, even if you don't polyfill, using `chrome.*` gives you Chrome and Firefox. together those two give you the majority of the marketplace (You can polyfill for the rest). – Makyen Nov 24 '16 at 03:08
1

As of 2021

Check https://github.com/mozilla/webextension-polyfill
(or TypeScript counterpart https://github.com/Lusito/webextension-polyfill-ts)
for some better compatibility between Chrome and Firefox

Paul Verest
  • 60,022
  • 51
  • 208
  • 332
0

I think your best solution for now is to use callbacks instead of promises as they work for chrome, firefox and edge. In addition you can use something like browser = browser || chrome; to solve the chrome vs browser issue and browser.runtime.lastError; for error handling. Firefox support both the callback and the promise version of the api, callback version will work for both the chrome and browser objects.