Skip to content
Merged
17 changes: 17 additions & 0 deletions libraries/devicePixelRatio/devicePixelRatio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {canAccessWindowTop, internal as utilsInternals} from '../../src/utils.js';

function getFallbackWindow(win) {
if (win) {
return win;
}

return canAccessWindowTop() ? utilsInternals.getWindowTop() : utilsInternals.getWindowSelf();
}

export function getDevicePixelRatio(win) {
try {
return getFallbackWindow(win).devicePixelRatio;

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting

devicePixelRatio is an indicator of fingerprinting; weight: 18.91

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting Warning

devicePixelRatio is an indicator of fingerprinting; weight: 18.84
} catch (e) {
}
return 1;
}
3 changes: 2 additions & 1 deletion modules/apstreamBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {getDNT} from '../libraries/dnt/index.js';
import { generateUUID, deepAccess, createTrackPixelHtml } from '../src/utils.js';
import { getDevicePixelRatio } from '../libraries/devicePixelRatio/devicePixelRatio.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { getStorageManager } from '../src/storageManager.js';
Expand Down Expand Up @@ -335,7 +336,7 @@
}

function getScreenParams() {
return `${window.screen.width}x${window.screen.height}@${window.devicePixelRatio}`;
return `${window.screen.width}x${window.screen.height}@${getDevicePixelRatio(window)}`;

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting

devicePixelRatio is an indicator of fingerprinting; weight: 18.91

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting Warning

devicePixelRatio is an indicator of fingerprinting; weight: 18.84
}

function getBids(bids) {
Expand Down
3 changes: 2 additions & 1 deletion modules/datablocksBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {getDevicePixelRatio} from '../libraries/devicePixelRatio/devicePixelRatio.js';
import {deepAccess, getWinDimensions, getWindowTop, isGptPubadsDefined} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {config} from '../src/config.js';
Expand Down Expand Up @@ -135,7 +136,7 @@
'whl': win.history.length,
'wxo': win.pageXOffset,
'wyo': win.pageYOffset,
'wpr': win.devicePixelRatio,
'wpr': getDevicePixelRatio(win),

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting

devicePixelRatio is an indicator of fingerprinting; weight: 18.91
'is_bot': botTest.doTests(),
'is_hid': win.document.hidden,
'vs': win.document.visibilityState
Expand Down Expand Up @@ -216,7 +217,7 @@
h: sizes[0][1],
format: sizes.map(size => ({ w: size[0], h: size[1] }))
};

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting Warning

devicePixelRatio is an indicator of fingerprinting; weight: 18.84
// ADD TO THE LIST OF IMP REQUESTS
imps.push(imp);
}
Expand Down
3 changes: 2 additions & 1 deletion modules/greenbidsBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getValue, logError, deepAccess, parseSizesInput, getBidIdParameter, logInfo, getWinDimensions, getScreenOrientation } from '../src/utils.js';
import { getDevicePixelRatio } from '../libraries/devicePixelRatio/devicePixelRatio.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { getStorageManager } from '../src/storageManager.js';
import { getHLen } from '../libraries/navigatorData/navigatorData.js';
Expand Down Expand Up @@ -65,7 +66,7 @@
device: bidderRequest?.ortb2?.device || {},
deviceWidth: screen.width,
deviceHeight: screen.height,
devicePixelRatio: topWindow.devicePixelRatio,
devicePixelRatio: getDevicePixelRatio(topWindow),

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting

devicePixelRatio is an indicator of fingerprinting; weight: 18.91

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting Warning

devicePixelRatio is an indicator of fingerprinting; weight: 18.84
screenOrientation: getScreenOrientation(),
historyLength: getHLen(),
viewportHeight: getWinDimensions().visualViewport.height,
Expand Down
3 changes: 2 additions & 1 deletion modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {_each, deepAccess, getWinDimensions, logError, logWarn, parseSizesInput} from '../src/utils.js';
import {getDevicePixelRatio} from '../libraries/devicePixelRatio/devicePixelRatio.js';

import {config} from '../src/config.js';
import {getStorageManager} from '../src/storageManager.js';
Expand Down Expand Up @@ -89,7 +90,7 @@
pu: stripGGParams(topUrl),
tpl: mosttopURL,
ce: storage.cookiesAreEnabled(),
dpr: topWindow.devicePixelRatio || 1,
dpr: getDevicePixelRatio(topWindow),

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting

devicePixelRatio is an indicator of fingerprinting; weight: 18.91

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting Warning

devicePixelRatio is an indicator of fingerprinting; weight: 18.84
jcsi: JSON.stringify(JCSI),
ogu: getOgURL()
};
Expand Down
3 changes: 2 additions & 1 deletion modules/hypelabBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import { generateUUID, isFn, isPlainObject, getWinDimensions } from '../src/utils.js';
import { getDevicePixelRatio } from '../libraries/devicePixelRatio/devicePixelRatio.js';
import { ajax } from '../src/ajax.js';
import { getBoundingClientRect } from '../libraries/boundingClientRect/boundingClientRect.js';
import { getWalletPresence, getWalletProviderFlags } from '../libraries/hypelabUtils/hypelabUtils.js';
Expand Down Expand Up @@ -40,7 +41,7 @@

const uuid = uids[0] ? uids[0] : generateTemporaryUUID();
const floor = getBidFloor(request, request.sizes || []);
const dpr = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
const dpr = typeof window !== 'undefined' ? getDevicePixelRatio(window) : 1;

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting

devicePixelRatio is an indicator of fingerprinting; weight: 18.91

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting Warning

devicePixelRatio is an indicator of fingerprinting; weight: 18.84
const wp = getWalletPresence();
const wpfs = getWalletProviderFlags();
const winDimensions = getWinDimensions();
Expand Down
3 changes: 2 additions & 1 deletion modules/oguryBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { BANNER } from '../src/mediaTypes.js';
import { getWindowSelf, getWindowTop, isFn, deepAccess, isPlainObject, deepSetValue, mergeDeep } from '../src/utils.js';
import { getDevicePixelRatio } from '../libraries/devicePixelRatio/devicePixelRatio.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { ajax } from '../src/ajax.js';
import { getAdUnitSizes } from '../libraries/sizeUtils/sizeUtils.js';
Expand All @@ -25,7 +26,7 @@
request(buildRequest, imps, bidderRequest, context) {
const req = buildRequest(imps, bidderRequest, context);
req.tmax = DEFAULT_TIMEOUT;
deepSetValue(req, 'device.pxratio', window.devicePixelRatio);
deepSetValue(req, 'device.pxratio', getDevicePixelRatio(getWindowContext()));

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting

devicePixelRatio is an indicator of fingerprinting; weight: 18.91

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting Warning

devicePixelRatio is an indicator of fingerprinting; weight: 18.84
deepSetValue(req, 'site.page', getWindowContext().location.href);

req.ext = mergeDeep({}, req.ext, {
Expand Down
3 changes: 2 additions & 1 deletion modules/sspBCBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { deepAccess, getWinDimensions, getWindowTop, isArray, logInfo, logWarn } from '../src/utils.js';
import { getDevicePixelRatio } from '../libraries/devicePixelRatio/devicePixelRatio.js';
import { ajax } from '../src/ajax.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
Expand Down Expand Up @@ -174,7 +175,7 @@
'CH-SaveData': connection.saveData,
'CH-Downlink': connection.downlink,
'CH-DeviceMemory': null,
'CH-Dpr': W.devicePixelRatio,
'CH-Dpr': getDevicePixelRatio(W),

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting

devicePixelRatio is an indicator of fingerprinting; weight: 18.91

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting Warning

devicePixelRatio is an indicator of fingerprinting; weight: 18.84
'CH-ViewportWidth': viewport.width,
'CH-BrowserBrands': JSON.stringify(userAgentData.brands),
'CH-isMobile': userAgentData.mobile,
Expand Down
3 changes: 2 additions & 1 deletion modules/teadsBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {logError, parseSizesInput, isArray, getBidIdParameter, getWinDimensions, getScreenOrientation} from '../src/utils.js';
import {getDevicePixelRatio} from '../libraries/devicePixelRatio/devicePixelRatio.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {getStorageManager} from '../src/storageManager.js';
import {isAutoplayEnabled} from '../libraries/autoplayDetection/autoplay.js';
Expand Down Expand Up @@ -72,7 +73,7 @@
device: bidderRequest?.ortb2?.device || {},
deviceWidth: screen.width,
deviceHeight: screen.height,
devicePixelRatio: topWindow.devicePixelRatio,
devicePixelRatio: getDevicePixelRatio(topWindow),

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting

devicePixelRatio is an indicator of fingerprinting; weight: 18.91

Check warning

Code scanning / CodeQL

Use of browser API associated with fingerprinting Warning

devicePixelRatio is an indicator of fingerprinting; weight: 18.84
screenOrientation: getScreenOrientation(),
historyLength: getHLen(),
viewportHeight: getWinDimensions().visualViewport.height,
Expand Down
8 changes: 4 additions & 4 deletions src/utils/winDimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ const winDimensions = new CachedApiWrapper(
);

export const internal = {
reset: winDimensions.reset,
winDimensions,
};

export const getWinDimensions = (() => {
let lastCheckTimestamp;
return function () {
if (!lastCheckTimestamp || (Date.now() - lastCheckTimestamp > CHECK_INTERVAL_MS)) {
internal.reset();
internal.winDimensions.reset();
lastCheckTimestamp = Date.now();
}
return winDimensions.obj;
return internal.winDimensions.obj;
}
})();

export function resetWinDimensions() {
internal.reset();
internal.winDimensions.reset();
}

export function getScreenOrientation(win) {
Expand Down
3 changes: 2 additions & 1 deletion test/spec/modules/greenbidsBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect } from 'chai';
import { newBidder } from 'src/adapters/bidderFactory.js';
import { spec, ENDPOINT_URL } from 'modules/greenbidsBidAdapter.js';
import { getScreenOrientation } from 'src/utils.js';
import {getDevicePixelRatio} from '../../../libraries/devicePixelRatio/devicePixelRatio.js';
const AD_SCRIPT = '<script type="text/javascript" class="greenbids" async="true" src="https://greenbids.ai/settings"></script>"';

describe('greenbidsBidAdapter', () => {
Expand Down Expand Up @@ -277,7 +278,7 @@ describe('greenbidsBidAdapter', () => {
it('should add pixelRatio info to payload', function () {
const request = spec.buildRequests(bidRequests, bidderRequestDefault);
const payload = JSON.parse(request.data);
const pixelRatio = window.top.devicePixelRatio
const pixelRatio = getDevicePixelRatio()

expect(payload.devicePixelRatio).to.exist;
expect(payload.devicePixelRatio).to.deep.equal(pixelRatio);
Expand Down
3 changes: 2 additions & 1 deletion test/spec/modules/hypelabBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from 'modules/hypelabBidAdapter.js';

import { BANNER } from 'src/mediaTypes.js';
import {getDevicePixelRatio} from '../../../libraries/devicePixelRatio/devicePixelRatio.js';

const mockValidBidRequest = {
bidder: 'hypelab',
Expand Down Expand Up @@ -177,7 +178,7 @@ describe('hypelabBidAdapter', function () {
expect(data.dpr).to.be.a('number');
expect(data.location).to.be.a('string');
expect(data.floor).to.equal(null);
expect(data.dpr).to.equal(1);
expect(data.dpr).to.equal(getDevicePixelRatio());
expect(data.wp).to.deep.equal({
ada: false,
bnb: false,
Expand Down
8 changes: 2 additions & 6 deletions test/spec/modules/oguryBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { spec, ortbConverterProps } from 'modules/oguryBidAdapter';
import * as utils from 'src/utils.js';
import { server } from '../../mocks/xhr.js';
import {getDevicePixelRatio} from '../../../libraries/devicePixelRatio/devicePixelRatio.js';

const BID_URL = 'https://mweb-hb.presage.io/api/header-bidding-request';
const TIMEOUT_URL = 'https://ms-ads-monitoring-events.presage.io/bid_timeout'
Expand Down Expand Up @@ -577,10 +578,6 @@
return stubbedCurrentTime;
});

const stubbedDevicePixelMethod = sinon.stub(window, 'devicePixelRatio').get(function() {
return stubbedDevicePixelRatio;
});

const defaultTimeout = 1000;

function assertImpObject(ortbBidRequest, bidRequest) {
Expand Down Expand Up @@ -639,7 +636,7 @@

beforeEach(() => {
windowTopStub = sinon.stub(utils, 'getWindowTop');
windowTopStub.returns({ location: { href: currentLocation } });
windowTopStub.returns({ location: { href: currentLocation } , devicePixelRatio: stubbedDevicePixelRatio});

Check failure on line 639 in test/spec/modules/oguryBidAdapter_spec.js

View workflow job for this annotation

GitHub Actions / Run linter

There should be no space before ','
});

afterEach(() => {
Expand All @@ -648,7 +645,6 @@

after(() => {
stubbedCurrentTimeMethod.restore();
stubbedDevicePixelMethod.restore();
});

it('sends bid request to ENDPOINT via POST', function () {
Expand Down
3 changes: 2 additions & 1 deletion test/spec/modules/teadsBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as autoplay from 'libraries/autoplayDetection/autoplay.js';
import { spec, storage } from 'modules/teadsBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import { getScreenOrientation } from 'src/utils.js';
import {getDevicePixelRatio} from '../../../libraries/devicePixelRatio/devicePixelRatio.js';

const ENDPOINT = 'https://a.teads.tv/hb/bid-request';
const AD_SCRIPT = '<script type="text/javascript" class="teads" async="true" src="https://a.teads.tv/hb/getAdSettings"></script>"';
Expand Down Expand Up @@ -360,7 +361,7 @@ describe('teadsBidAdapter', () => {
it('should add pixelRatio info to payload', function () {
const request = spec.buildRequests(bidRequests, bidderRequestDefault);
const payload = JSON.parse(request.data);
const pixelRatio = window.top.devicePixelRatio
const pixelRatio = getDevicePixelRatio();

expect(payload.devicePixelRatio).to.exist;
expect(payload.devicePixelRatio).to.deep.equal(pixelRatio);
Expand Down
2 changes: 1 addition & 1 deletion test/spec/utils_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ describe('getWinDimensions', () => {
});

it('should clear cache once per 20ms', () => {
const resetWinDimensionsSpy = sinon.spy(winDimensions.internal, 'reset');
const resetWinDimensionsSpy = sinon.spy(winDimensions.internal.winDimensions, 'reset');
expect(getWinDimensions().innerHeight).to.exist;
clock.tick(1);
expect(getWinDimensions().innerHeight).to.exist;
Expand Down
Loading