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
42 changes: 42 additions & 0 deletions packages/fingerprint-injector/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,3 +798,45 @@ function overrideStatic() {
console.error(e);
}
}

function overrideWebWorker(navigatorFingerprint) {
const worker = `
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`;
// eslint-disable-next-line
const createObjectURL = URL.createObjectURL;
URL.createObjectURL = function (blob) {
if (blob.type === 'application/javascript') {
// eslint-disable-next-line
blob = new Blob([worker, blob], { type: blob.type });
}
return createObjectURL.call(this, blob);
};
Comment on lines +835 to +841
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this will only work with Web Workers initialized with new Worker(URL.createObjectURL(new Blob(...))), which is quite specific and doesn't cover all the possible use cases (e.g. const myWorker = new Worker("worker.js");).

Also, this approach will edit URL.createObjectURL return value for all application/javascript blobs, not only the Web Worker-related ones.

}