From 3bb69228b8b7bc0d4c9bdfa79029189c5892c492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jind=C5=99ich=20B=C3=A4r?= Date: Tue, 24 Oct 2023 14:58:34 +0200 Subject: [PATCH] fix: userAgentData.getHighEntropyValues has correct defaults (#244) --- packages/fingerprint-injector/src/utils.js | 3 +-- .../fingerprint-injector.test.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/fingerprint-injector/src/utils.js b/packages/fingerprint-injector/src/utils.js index 41b247a9..96af6e2f 100644 --- a/packages/fingerprint-injector/src/utils.js +++ b/packages/fingerprint-injector/src/utils.js @@ -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]; }); diff --git a/test/fingerprint-injector/fingerprint-injector.test.ts b/test/fingerprint-injector/fingerprint-injector.test.ts index 937e0e8b..56b506de 100644 --- a/test/fingerprint-injector/fingerprint-injector.test.ts +++ b/test/fingerprint-injector/fingerprint-injector.test.ts @@ -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(); + } + }); }); });