Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/fingerprint-injector/src/fingerprint-injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Fingerprint,
FingerprintGenerator,
FingerprintGeneratorOptions,
NavigatorFingerprint,
type UserAgentData,
} from 'fingerprint-generator';
import {
Expand Down Expand Up @@ -42,6 +43,7 @@ declare function overrideIntlAPI(language: string): void;
declare function overrideStatic(): void;
declare function runHeadlessFixes(): void;
declare function blockWebRTC(): void;
declare function overrideWebWorker(navigatorFingerprint: NavigatorFingerprint): void;

/**
* Fingerprint injector class.
Expand Down Expand Up @@ -251,6 +253,8 @@ export class FingerprintInjector {
clientWidth,
};

// @ts-expect-error internal browser code
overrideWebWorker(fp.navigator);
runHeadlessFixes();

if (mockWebRTC) blockWebRTC();
Expand Down
67 changes: 67 additions & 0 deletions packages/fingerprint-injector/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,3 +798,70 @@ function overrideStatic() {
console.error(e);
}
}

function overrideWebWorker(navigatorFingerprint) {
const navigatorWorker = `
Object.defineProperties(navigator, {
userAgent: {
get: () => "${navigatorFingerprint.userAgent}"
},
deviceMemory: {
get: () => ${navigatorFingerprint.deviceMemory}
},
platform: {
get: () => "${navigatorFingerprint.platform}"
},
hardwareConcurrency: {
get: () => ${navigatorFingerprint.hardwareConcurrency}
},
languages: {
get: () => ${JSON.stringify(navigatorFingerprint.languages)}
},
appVersion: {
get: () => "${navigatorFingerprint.appVersion}"
}
});

if(navigator.userAgentData){
Object.defineProperty(navigator, 'userAgentData', {
get: function(){
return ${JSON.stringify(navigatorFingerprint.userAgentData)}
}
});
}
\n`;

const DefaultWorker = window.Worker;
window.Worker = class extends DefaultWorker {
constructor(scriptURL, options) {
const xhr = new XMLHttpRequest();
xhr.open('GET', scriptURL, false);
xhr.send();
if (xhr.status === 200) {
const blob = new Blob([navigatorWorker, xhr.response], {
type: 'application/javascript',
});
super(URL.createObjectURL(blob), options);
return;
}
super(scriptURL, options);
}
};

const DefaultSharedWorker = window.SharedWorker;
window.SharedWorker = class extends DefaultSharedWorker {
constructor(scriptURL, options) {
const xhr = new XMLHttpRequest();
xhr.open('GET', scriptURL, false);
xhr.send();
if (xhr.status === 200) {
const blob = new Blob([navigatorWorker, xhr.response], {
type: 'application/javascript',
});
super(URL.createObjectURL(blob), options);
return;
}
super(scriptURL, options);
}
};
}