Skip to content

Commit

Permalink
check if top window can be accessed before getting data from it (preb…
Browse files Browse the repository at this point in the history
  • Loading branch information
ym-atsymuk authored and Chris Pabst committed Jan 10, 2022
1 parent 039a430 commit d73366b
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions modules/yieldmoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,8 @@ export const spec = {
p: [],
page_url: bidderRequest.refererInfo.referer,
bust: new Date().getTime().toString(),
pr: (LOCAL_WINDOW.document && LOCAL_WINDOW.document.referrer) || '',
scrd: LOCAL_WINDOW.devicePixelRatio || 0,
dnt: getDNT(),
description: getPageDescription(),
title: LOCAL_WINDOW.document.title || '',
w: LOCAL_WINDOW.innerWidth,
h: LOCAL_WINDOW.innerHeight,
userConsent: JSON.stringify({
// case of undefined, stringify will remove param
gdprApplies: deepAccess(bidderRequest, 'gdprConsent.gdprApplies') || '',
Expand All @@ -70,6 +65,14 @@ export const spec = {
us_privacy: deepAccess(bidderRequest, 'uspConsent') || ''
};

if (canAccessTopWindow()) {
serverRequest.pr = (LOCAL_WINDOW.document && LOCAL_WINDOW.document.referrer) || '';
serverRequest.scrd = LOCAL_WINDOW.devicePixelRatio || 0;
serverRequest.title = LOCAL_WINDOW.document.title || '';
serverRequest.w = LOCAL_WINDOW.innerWidth;
serverRequest.h = LOCAL_WINDOW.innerHeight;
}

const mtp = window.navigator.maxTouchPoints;
if (mtp) {
serverRequest.mtp = mtp;
Expand Down Expand Up @@ -609,3 +612,18 @@ function getEids(bidRequest) {
return createEidsArray(bidRequest.userId) || [];
}
};

/**
* Check if top window can be accessed
*
* @return {boolean} true if can access top window otherwise false
*/
function canAccessTopWindow() {
try {
if (getWindowTop().location.href) {
return true;
}
} catch (error) {
return false;
}
}

0 comments on commit d73366b

Please sign in to comment.