How can extension tell what browser it's running on?

338 views
Skip to first unread message

Wesley Branton

unread,
Mar 21, 2021, 2:19:09 PM3/21/21
to Chromium Extensions
I'm working on porting a Firefox add-on to Chromium-based browsers. Detecting whether the add-on is running on Chromium or Firefox is easy because Chromium doesn't have the "browser" object, but is there no API to tell what Chromium-based browser it's running on?

I don't see any way to tell if the extension is running on Google Chrome or Microsoft Edge or Opera. Each browser is a little different in the naming of some features (like Private Browsing, for example) and I'd like to have that terminology change dynamically in my add-on depending on what browser it's running on.

How can this be done?

Shu

unread,
Mar 21, 2021, 2:21:59 PM3/21/21
to Chromium Extensions, ComputerWhiz
I use this one, just test what is for Opera, I ignore that browser :)

function getBrowser(){
if (api.runtime.getURL('').startsWith('moz-extension://'))
return "Firefox";
else if (api.runtime.getURL('').startsWith('edge://extension'))
return "Edge";
else
return "Chrome";
}

ComputerWhiz

unread,
Mar 21, 2021, 2:26:04 PM3/21/21
to Chromium Extensions, Shu
Just what I was looking for. Thanks!

ComputerWhiz

unread,
Mar 21, 2021, 2:48:42 PM3/21/21
to Chromium Extensions, Shu
Edge returns a URL that starts with "chrome-extension://", so that's not going to work.

On Sunday, March 21, 2021 at 6:21:59 PM UTC Shu wrote:

Shu

unread,
Mar 21, 2021, 2:52:35 PM3/21/21
to Chromium Extensions, ComputerWhiz, Shu
This means that extension was downloaded from chrome store and not from Edge store

ComputerWhiz

unread,
Mar 21, 2021, 2:54:43 PM3/21/21
to Chromium Extensions, Shu
It's downloaded from neither. It's the unpacked source code that I'm using for testing.

hrg...@gmail.com

unread,
Mar 22, 2021, 2:24:10 AM3/22/21
to Chromium Extensions, ComputerWhiz, Shu
I've just tried this from an extension hosted in the Edge store and it still gives "chrome-extension://".

In any case, the omnibox in Edge displays the extension URLs as "extension://..." not "edge://extension'/...", so that technique wouldn't have worked.

Browser Extenstion

unread,
Mar 22, 2021, 3:34:44 AM3/22/21
to Chromium Extensions, hrg...@gmail.com, ComputerWhiz, Shu
navigator.userAgent.search(/OPR/) > 0 ? 'Opera' : navigator.userAgent.search(/Edg/) > 0 ? 'Edge' : navigator.userAgent.search(/Chrome/) > 0 ? 'Chrome' : undefined;

ka...@couponfollow.com

unread,
Apr 1, 2021, 11:20:24 AM4/1/21
to Chromium Extensions, Browser Extenstion, hrg...@gmail.com, ComputerWhiz, Shu
Actually, detecting the browser manually is not so simple, but we use 'bowser' npm package and it works well. 
Reply all
Reply to author
Forward
0 new messages