50

is there anyway to create a unique ID for a browser within javascript?

Im not talking about an ID that is random everytime it is generated but an ID that is unique to the browser it is generated in but also takes into account the computer its running on.

Example:

Windows 7 Chrome might generate: asdh128hakj4gh

Windows 7 Opera might generate: 23hjad823hjakk

Windows 7 Chrome, diff hardware, might generate: asd238881jaal

etc...

Is there anyway to do this?

Ozzy
  • 10,285
  • 26
  • 94
  • 138
  • 2
    Should the ID be the same for all computers running Chrome on Windows 7, or are you thinking of a ID similar to a session ID? – Jan Aagaard Feb 08 '11 at 17:08
  • the id would be different depending on os, hardware and browser but the id would be the same if generated twice on the same os hardware and browser – Ozzy Feb 08 '11 at 17:11

6 Answers6

50

What you are looking for is called Browser Fingerprinting.

You can google for some open source libraries. Ex: fingerprintjs2

Check out EFF's demo

Makubex
  • 1,054
  • 1
  • 9
  • 16
12

Use cookies and some unique hash into its. (Each browser has own cookie jar, even if on computer is many browsers)

IProblemFactory
  • 9,551
  • 8
  • 50
  • 66
  • Maybe not true. I opened a FireFox, gave it a random ID in a cookie, opened 2nd FireFox, and it reads the same cookie. – Doug Null Jun 04 '12 at 16:51
  • 21
    Yeah, each browser installation has their own cookie jar, not each browser instance... – IProblemFactory Jun 04 '12 at 17:04
  • I like the concept but some sample code would help here. How should I use the random hash? As cookie body somewhere or maybe cookie name? If name, how should I get it back then? – Wojciech Jakubas Oct 22 '21 at 19:37
  • Just try to generate some id using for example `uuid` - here is popular npm package: https://www.npmjs.com/package/uuid and save it as a cookie. You can use Js for that as well – IProblemFactory Oct 24 '21 at 13:00
6

You can use biri library. The ID is generated per computer, and doesn't change unless the MAC address of the computer changes.

3

     var Sys = {};
        var ua = navigator.userAgent.toLowerCase();
        var s;
        (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
        (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
        (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
        (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
        (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;

   
        if (Sys.ie) document.write('IE: ' + Sys.ie);
        if (Sys.firefox) document.write('Firefox: ' + Sys.firefox);
        if (Sys.chrome) document.write('Chrome: ' + Sys.chrome);
        if (Sys.opera) document.write('Opera: ' + Sys.opera);
        if (Sys.safari) document.write('Safari: ' + Sys.safari);

With these code you can get the type and the version of the browser, and the value should be unique according to different browser , if you want to generate other unique ID base on it , then use it

Jswq
  • 758
  • 1
  • 7
  • 23
1

How about the MD5 of the UserAgent + ClientIP + 'extrasalt'?

That will get you close but not perfect because it is possible for 2 clients to have the same IP (using NAT) and exact same UserAgent (tightly controlled IT department = same deployment, or just luck).

Bill
  • 187
  • 1
  • 2
  • 10
    -1: Most clients have dynamic IPs, and you're lucky if a client keeps the same IP for some days. So when the IP changes, you're wrongly going to consider the new hash as a new browser instance. – reallynice Oct 04 '17 at 10:13
0

What it looks like you are trying to do is some kind of licensing? So that only so many browsers can be registered to use your app?

Unfortunately there is no way of reading the users computer hardware setup. As one answer says you can store a cookie on the machine but it can easily go missing.

If you were restricted to using old IE browsers you could use ActiveX to read computer hardware: http://www.devarticles.com/c/a/JavaScript/How-to-Use-JavaScript-for-Hardware-Knowledge/

xlm
  • 6,854
  • 14
  • 53
  • 55
Scott
  • 3,967
  • 9
  • 38
  • 56