Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if top window can be accessed before getting data from it #19

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}