diff --git a/src/fpd/sua.js b/src/fpd/sua.js index 30b2be4c13b..565c3e1fd52 100644 --- a/src/fpd/sua.js +++ b/src/fpd/sua.js @@ -15,6 +15,12 @@ export const HIGH_ENTROPY_HINTS = [ 'fullVersionList' ] +export const LOW_ENTROPY_HINTS = [ + 'brands', + 'mobile', + 'platform' +] + /** * Returns low entropy UA client hints encoded as an ortb2.6 device.sua object; or null if no UA client hints are available. */ @@ -32,7 +38,7 @@ export const getLowEntropySUA = lowEntropySUAAccessor(); export const getHighEntropySUA = highEntropySUAAccessor(); export function lowEntropySUAAccessor(uaData = window.navigator?.userAgentData) { - const sua = isEmpty(uaData) ? null : Object.freeze(uaDataToSUA(SUA_SOURCE_LOW_ENTROPY, uaData)); + const sua = (uaData && LOW_ENTROPY_HINTS.some(h => typeof uaData[h] !== 'undefined')) ? Object.freeze(uaDataToSUA(SUA_SOURCE_LOW_ENTROPY, uaData)) : null; return function () { return sua; } @@ -85,7 +91,7 @@ export function uaDataToSUA(source, uaData) { if (uaData.fullVersionList || uaData.brands) { sua.browsers = (uaData.fullVersionList || uaData.brands).map(({brand, version}) => toBrandVersion(brand, version)); } - if (uaData.hasOwnProperty('mobile')) { + if (typeof uaData['mobile'] !== 'undefined') { sua.mobile = uaData.mobile ? 1 : 0; } ['model', 'bitness', 'architecture'].forEach(prop => { diff --git a/test/spec/fpd/enrichment_spec.js b/test/spec/fpd/enrichment_spec.js index 328846ca081..3b3afb15f8c 100644 --- a/test/spec/fpd/enrichment_spec.js +++ b/test/spec/fpd/enrichment_spec.js @@ -275,7 +275,13 @@ describe('FPD enrichment', () => { describe('sua', () => { it('does not set device.sua if resolved sua is null', () => { - sandbox.stub(dep, 'getHighEntropySUA').returns(Promise.resolve()) + sandbox.stub(dep, 'getHighEntropySUA').returns(Promise.resolve()); + // Add hints so it will attempt to retrieve high entropy values + config.setConfig({ + firstPartyData: { + uaHints: ['bitness'], + } + }); return fpd().then(ortb2 => { expect(ortb2.device.sua).to.not.exist; }) diff --git a/test/spec/fpd/sua_spec.js b/test/spec/fpd/sua_spec.js index 431f47268d3..63e0068d0ef 100644 --- a/test/spec/fpd/sua_spec.js +++ b/test/spec/fpd/sua_spec.js @@ -165,6 +165,14 @@ describe('uaDataToSUA', () => { }); describe('lowEntropySUAAccessor', () => { + // Set up a mock data with readonly property + class MockUserAgentData {} + Object.defineProperty(MockUserAgentData.prototype, 'mobile', { + value: false, + writable: false, + enumerable: true + }); + function getSUA(uaData) { return lowEntropySUAAccessor(uaData)(); } @@ -181,6 +189,10 @@ describe('lowEntropySUAAccessor', () => { it('should return null if uaData is empty', () => { expect(getSUA({})).to.eql(null); }) + + it('should return mobile and source', () => { + expect(getSUA(new MockUserAgentData())).to.eql({mobile: 0, source: 1}) + }) }); describe('highEntropySUAAccessor', () => {