I am using the chrome
namespace for both Chrome and Firefox, but would like to know which browser is running the web extension.
Check chrome.app
which is absent in Firefox:
const isFirefox = !chrome.app;
Check for browser
which is absent in Chrome:
const isFirefox = window.browser && browser.runtime;
(the additional check is to avoid false positives on pages that have an element with id="browser"
that creates a named property on window
object for this element)
Use the asynchronous browser.runtime.getBrowserInfo.
P.S. navigator.userAgent
may be changed during debugging in devtools when switching to device mode or via about:config
option in Firefox so it's an unreliable source.