Skip to content

Instantly share code, notes, and snippets.

@superKalo
Last active October 17, 2017 09:54
Show Gist options
  • Save superKalo/7cee019a3a6a3f0e231b6b4840b5d701 to your computer and use it in GitHub Desktop.
Save superKalo/7cee019a3a6a3f0e231b6b4840b5d701 to your computer and use it in GitHub Desktop.
Make your browser extension code compatible with all browsers APIs
/**
* Тhe Extension API model is currently being standardized to browser.xxx,
* and some browsers are defining their own namespaces in the meantime
* (for example, Edge is using msBrowser).
*
* Fortunately, most of the API remains the same behind the browser.
* So, it’s very simple to support all browsers and namespace definitions.
*
* You’ll also need to use the subset of the API supported by all browsers:
* - Microsoft Edge: https://docs.microsoft.com/en-us/microsoft-edge/extensions/api-support
* - Mozilla Firefox: https://developer.mozilla.org/en-US/Add-ons/WebExtensions
* - Opera: https://dev.opera.com/extensions/apis/
*/
window.browser = (function () {
return window.msBrowser ||
window.browser ||
window.chrome;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment