How do you get the device name (or hostname) from a Chrome Extension?

23,872

Solution 1

No. A persistent and unique identifier associated with the user's hardware would basically be an undeletable cookie. For privacy reasons, browsers (and browser-extension APIs) don't provide such identifiers.

Edit: from experimental.systemInfo.* you might be able to construct something that will describe certain attributes about the user's system. It won't be distinctive enough to guarantee uniqueness in a dropdown menu, for example, but it might be a step in the right direction. Note that these APIs are experimental so you won't be able to distribute extensions using them through the web store.

Solution 2

Yes. Since Chrome version 43, released a while after the question and other answer here, you can get a unique device ID in a Chrome extension with chrome.instanceID.getID().

The device names in the Other Devices menu (chrome://history/syncedTabs) can be found with chrome.sessions.getDevices() but it only includes all your other devices, not the current one!

Share:
23,872
michele b
Author by

michele b

I like to build things. Especially if I can do that by typing on a keyboard.

Updated on June 30, 2021

Comments

  • michele b
    michele b almost 3 years

    Is there a way to retrieve the device name from a Chrome Extension?

    Ideally I'd like to get the same String that is displayed in the 'Other devices' menu on the new tab page... Is that piece of information available to extensions?

    Alternatively, is the hostname available?

    What I managed to get is the user-agent by accessing window.navigator.userAgent, but that's it...

  • michele b
    michele b about 11 years
    well device names in the sessions menu aren't unique, and sometimes the OS name is used (my Debian machine is simply listed as Debian GNU/Linux 7.0 (wheezy)), so I don't think they're giving away more information than user agents do.. do you have any reference?
  • sowbug
    sowbug about 11 years
    User agents definitely leak information, and the standard "nothing is private anyway" link is panopticlick.eff.org. Just to be clear, when you say "device name" are you talking about something like "Nexus 7" (which is more like hardware capabilities) or "Michele's Nexus 7" (which is more like a unique identifier)? Since you asked about hostnames I was assuming the latter interpretation.
  • michele b
    michele b about 11 years
    it would be interesting to know how Chrome obtains those names, they look like bits of the user-agent manipulated to look more user-friendly.. for instance, my Android devices are listed by means of their model names (e.g. GT-I9100), whereas my Windows 7 VM is labeled MICHELE-LAPTOP7 (I guess it's the hostname? Can't check now). I can have users resolve name conflicts, so I don't need uniqueness.. probably the model name is enough. I'll wait to see if something else comes up, otherwise I'm accepting this answer, thanks!
  • sowbug
    sowbug about 11 years
    Thanks. Sorry I couldn't give a more helpful answer. Chrome is always going to be more powerful than Chrome extensions, because it's a native app. It's probably calling the OS-level APIs (e.g., msdn.microsoft.com/en-us/library/windows/desktop/… on Windows). But that kind of information wouldn't be provided via the extensions API for the reasons in my answer.