Skip to content

Commit

Permalink
Improve fingerprint2.js scriptlet
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Aug 9, 2023
1 parent a3a2ac5 commit 3c60979
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/web_accessible_resources/fingerprint2.js
Expand Up @@ -19,19 +19,37 @@
Home: https://github.com/gorhill/uBlock
*/

// Reference:
// https://github.com/fingerprintjs/fingerprintjs/tree/v2

(function() {
'use strict';
let browserId = '';
for ( let i = 0; i < 8; i++ ) {
browserId += (Math.random() * 0x10000 + 0x1000 | 0).toString(16).slice(-4);
}
const hex32 = len => {
return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)
.toString(16)
.slice(-len)
.padStart(len, '0');
};
const browserId = `${hex32(8)}${hex32(8)}${hex32(8)}${hex32(8)}`;
const fp2 = function(){};
fp2.get = function(opts, cb) {
if ( !cb ) { cb = opts; }
setTimeout(( ) => { cb(browserId, []); }, 1);
setTimeout(( ) => { cb([]); }, 1);
};
fp2.getPromise = function() {
return Promise.resolve([]);
};
fp2.getV18 = function() {
return browserId;
};
fp2.x64hash128 = function() {
return browserId;
};
fp2.prototype = {
get: fp2.get
get: function(opts, cb) {
if ( !cb ) { cb = opts; }
setTimeout(( ) => { cb(browserId, []); }, 1);
},
};
window.Fingerprint2 = fp2;
self.Fingerprint2 = fp2;
})();

0 comments on commit 3c60979

Please sign in to comment.