Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect Chromium specifically vs. Chrome?

Is there a way to detect if a visitor to my site is running Chromium as opposed to Google Chrome? Even basic UA sniffing (which I know is bad practice) would suffice for my particular case, but it appears that Chromium and Chrome share the same UA string – is that correct? Is there any other way that I can differentiate between the two?

like image 687
daGUY Avatar asked Jun 24 '13 15:06

daGUY


5 Answers

Here is another way, using SpeechSynthesis feature.

Google Chrome Browser ships TTS voices, where Chromium browsers (incl. Brave) do not. Voices can be installed manually, with espeak (on linux) however the Google voices all start with Google, where the manually installed voices do not. As far as I know the Chrome voices are propriety, not free.

The collection of voices is an Array where each voices looks like this:

{
    voiceURI: "Google Deutsch",
    name: "Google Deutsch",
    lang: "de-DE",
    localService: false,
    default: true
}

We just need to find one who's name/URI starts with Google ...

function hasGoogleVoices() {
    return window.speechSynthesis.getVoices()
      .some(v => /^google/i.test(v.name));
}

(Tested on Linux for Chrome, Brave, Chromium and Firefox) Please can someone check Safari and Windows. Thx.

like image 124
fliptopbox Avatar answered Oct 18 '22 21:10

fliptopbox


Starting with Chromium 84 there's a new method called User-Agent Client Hints reference

You can check if the userAgentData property exists and look for brand data. It will return an array that looks something like this.

[{
    "brand": " Not;A Brand",
    "version": "99"
}, {
    "brand": "Google Chrome",
    "version": "91"
}, {
    "brand": "Chromium",
    "version": "91"
}]

userAgentData.brands will contain varying values in a varying order, so don't rely on something appearing at a certain index. Instead check if the property exists in the array.

if (navigator.userAgentData) {
    let vendors = window.navigator.userAgentData.brands;
    if (vendors.filter(e => e.brand === 'Google Chrome').length > 0) {
        console.log('Chrome')
    } else {
        console.log('Chromium')
    }
}
like image 35
Josh Avatar answered Oct 20 '22 07:10

Josh


Note:
This no longer works, because now all Chrome-based-navigators have all plugins.

New Chromium-versions do have the PDF-plugin, too.
But they also have Chromium-plugins, so if any plugin starts with "Chromium", it's Chromium:

function isChromium() {

  for (var i = 0, u = "Chromium", l = u.length; i < navigator.plugins.length; i++) {
    if (navigator.plugins[i].name != null && navigator.plugins[i].name.substr(0, l) === u)
      return true;
  }

  return false;
}

Also, use this to identify Microsoft Chredge (aka. Anaheim)

function isEdg() {

  for (var i = 0, u = "Microsoft Edg", l = u.length; i < navigator.plugins.length; i++) {
    if (navigator.plugins[i].name != null && navigator.plugins[i].name.substr(0, l) === u)
      return true;
  }

  return false;
}
like image 7
Stefan Steiger Avatar answered Oct 20 '22 06:10

Stefan Steiger


Chrome ships with a built-in PDF reader, Chromium doesn't.
You could detect this by using JavaScript:

function isChrome() { // Actually, isWithChromePDFReader
    for (var i=0; i<navigator.plugins.length; i++)
        if (navigator.plugins[i].name == 'Chrome PDF Viewer') return true;
    return false;
}

This method is not 100% reliable, because users can copy the PDF reader binary from Chrome to their Chromium directory, see this answer on Ask Ubuntu.

There's almost no difference between Chromium and Chrome (certainly not in the rendering or JavaScript engine), so why do you want to spot the difference?

like image 5
Rob W Avatar answered Oct 20 '22 07:10

Rob W


Here is a variation to Paul W.'s answer that works for Chromium version 42 and above:

function isChromium() { // Actually, isWithChromiumPDFReader
    for (var i=0; i<navigator.plugins.length; i++)
        if (navigator.plugins[i].name == 'Chromium PDF Viewer') return true;
    return false;
}

This of course only works if the plugin has not been disabled by the user.

like image 3
F4Q Avatar answered Oct 20 '22 06:10

F4Q