Skip to content

Commit

Permalink
fix: userAgentData.getHighEntropyValues has correct defaults (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
barjin authored Oct 24, 2023
1 parent 930ac21 commit 3bb6922
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/fingerprint-injector/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,7 @@ function overrideUserAgentData(userAgentData) {
const [hints] = args;
await target.apply(ctx, args);

// If the codec is not in our collected data use
const data = {};
const data = { brands, mobile, platform };
hints.forEach((hint) => {
data[hint] = highEntropyValues[hint];
});
Expand Down
14 changes: 14 additions & 0 deletions test/fingerprint-injector/fingerprint-injector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,20 @@ describe('FingerprintInjector', () => {
expect(requestHeaders[header]).toBe(headers[header]);
}
});

test('highEntropyValues contain default values', async () => {
// @ts-expect-error internal browser code
const result = await page.evaluate(() => navigator.userAgentData?.getHighEntropyValues([]));

if (name === 'Chrome') {
expect(result).toHaveProperty('brands');
expect(result.brands).toBeInstanceOf(Array);
expect(result).toHaveProperty('mobile');
expect([true, false]).toContain(result.mobile);
} else if (name === 'Firefox') {
expect(result).toBeFalsy();
}
});
});
});

Expand Down

0 comments on commit 3bb6922

Please sign in to comment.