20

I have a Chrome extension, and I am currently writing a website to advertise it. I know that a Chrome extension can be installed in all Chromium-based browsers (Chrome, Opera, etc.).

Is it possible to check if a browser can download the extension from the web store or is chromium-based?

I found code to detect if it was Google Chrome here. Correct me if I'm wrong, but I think window.chrome doesn't return in all Chromium-based browsers.

honk
  • 9,137
  • 11
  • 75
  • 83
Fredthedoggy
  • 341
  • 3
  • 12
  • `window.chrome` does work in Opera – Luca Kiebel Aug 26 '19 at 14:50
  • I know it works in opera, but I don't think it works in all chromium based browsers (like the new edge, and others) @LucaKiebel – Fredthedoggy Aug 26 '19 at 14:52
  • 2
    Relevant: https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser – James Allen Aug 26 '19 at 14:53
  • I saw that, but it wont return all chromium browsers @FAKETAXI – Fredthedoggy Aug 26 '19 at 14:55
  • Extensions can do it by checking (window.chrome && window.chrome.app) which works in any extension script or a content script. – wOxxOm Aug 26 '19 at 15:02
  • I know, but the point is, on my website it checks if it can send people to the chrome web store, or if their browser does not support chrome extensions before it is installed @wOxxOm – Fredthedoggy Aug 26 '19 at 15:03
  • I don't see how that is a problem because AFAIK any chromium-based browser can install extensions from the web store - even Opera. – wOxxOm Aug 26 '19 at 15:04
  • Yes that is the point, but I want to know if I can send them to the chrome web store or say it is a unsupported browser – Fredthedoggy Aug 26 '19 at 15:06
  • It's like we don't understand each other. I'll rephrase my point: all chromium-based browsers are supported. If there is one obscure fork of chromium that can't do it then no one cares about it anyway. And if someone does, they'll let you know so no need to worry about it now. – wOxxOm Aug 26 '19 at 15:08
  • I agree with you, but I just want to check if it is chromium based, since all chromium browsers are supported – Fredthedoggy Aug 26 '19 at 15:09
  • All chromium-based browsers have window.chrome.app, see my first comment here. – wOxxOm Aug 26 '19 at 15:12
  • @wOxxOm I'm pretty sure they're asking "how do I detect whether my user in in Edge, or Firefox, or any other browser that _isn't_ Chromium, so that I can make sure that my on-page links don't go to the Chrome store for these folks". That might of course still be "check for `window.chrome`, but then that's an real answer, not just a comment. – Mike 'Pomax' Kamermans Aug 26 '19 at 15:24
  • yeah, that was partly my question too @Mike'Pomax'Kamermans – Fredthedoggy Aug 27 '19 at 16:30

5 Answers5

25

window.chrome

As of now, window.chrome works in all chromium based browsers

var isChromium = !!window.chrome;

console.log(isChromium)

Resources

navigator.userAgentData

User-Agent Client Hints API returns information about the browser and operating system of a user. (Introduced in chrome 90)

var isChromium = !!navigator.userAgentData && navigator.userAgentData.brands.some(data => data.brand == 'Chromium');

console.log(isChromium)

Resources

User863
  • 19,346
  • 2
  • 17
  • 41
  • 1
    AFAIK `window.chrome` doesn't work for Edge Chromium, see https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser and it's somewhat brittle. – brillout Jul 08 '20 at 14:41
  • 1
    Thanks for your answer! I'm wondering: what makes you think that `window.chrome` will not eventually be renamed to `window.edge`? Seems like a brittle solution, even though it does seem to work :) – brillout Jul 15 '20 at 15:05
  • Opera 18+ having it since 2013 (release), Vivaldi having it since 2016 (release). `window.chrome` has some properties like `runtime` and `app` object. This seems promising. But not sure about the LTS in `edge`.. – User863 Jul 16 '20 at 04:21
  • Is there an API in `window.chrome` that many websites rely on in such a crucial way that any Chromium-based version will most likely never deprecate it? That's the question here – brillout Jul 16 '20 at 08:44
  • No standard API available in `window.chrome`. One way that, you have to keep track of updates and changes. – User863 Jul 16 '20 at 08:59
  • window.chrome does not exist in puppeteer – jacob Mar 01 '22 at 21:36
1

Try using the following expression

navigator.userAgent.includes("Chrome")

Apostolos
  • 10,033
  • 5
  • 24
  • 39
iAmOren
  • 2,760
  • 2
  • 11
  • 23
1

Try this. This check shows true for Chrome, Safari, Edge, Samsung browser… etc

The -webkit-appearance property is used by WebKit-based (e.g., Safari) and Blink-based (e.g., Chrome, Opera) browsers to achieve the same thing.

function isChromium(){
   return window.CSS && window.CSS.supports && window.CSS.supports('(-webkit-appearance:none)');
}
Alex Nikulin
  • 8,194
  • 4
  • 35
  • 37
1

Considering that you just want to get to know whether browser is chromium based or not ,

Method 1: ( Server Side Detection)

-- Get Browser name from client request itself and serving the webpage accordingly. For example, If backend is based on Nodejs, You can get browser name as answered in this answer.

Method 2: ( Client Side Detection)

-- On client Side ,You can first get the Browser Name as answered in this answer , and then check it from HARD-CODED Chromium-based browsers Array.

amangupta
  • 87
  • 7
0

I guess:

var isChrome = navigator.userAgent.match(/Chrome\/\d+/) !== null;