-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Enhance location detection within utils #2167
Conversation
send 'iv' param if present and full url in `site.page`
Enhance location detection within utils
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rachelrj Thanks for the PR. Adapter changes look good, a few comments regarding the changes to utils
for your review
src/utils.js
Outdated
|
||
return location; | ||
const parseFullUrl = function(locString) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a parse
function in the src/url.js
module that parses a url and returns a similar looking object, would reusing that function in place of this one fit this use case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, though I added the href
into the return object of that function.
src/utils.js
Outdated
@@ -157,17 +157,50 @@ export function parseGPTSingleSizeArray(singleSize) { | |||
} | |||
}; | |||
|
|||
exports.getTopWindowLocation = function () { | |||
let location; | |||
export function getTopWindowLocation() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several modules rely on this function, changing it may introduce subtle differences. Any reason to not keep the existing getTopWindowLocation
as is, and create a new function for this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old function getTopWindowLocation
either returns window.top.location or returns window.location.
The new getTopWindowLocation
returns window.location, window.top.location, window.document.referrer, window.document.location.ancestorOrigins[0], or an object that recreates the values within window.location
The new version attempts to get the same info, just from additional objects.
I checked the modules, and I think this new version should fit all the current use cases.
I am not opposed to creating a new function if you’re worried about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks for the explanation. Changes to core require a second review, assigning that now
src/utils.js
Outdated
try { | ||
// force an exception in x-domain enviornments. #1509 | ||
window.top.location.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the comment, not sure removing this is the correct thing to do, unless there's an equivalent fix in the new code i'm not seeing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I didn't realize that the exception wasn't thrown when trying to access window.top until I read that 1509 PR. Interesting. Thanks for pointing out. I added back in.
CR for enhanced-location-detection PR
src/utils.js
Outdated
do { | ||
currentWindow = currentWindow ? currentWindow.parent : window; | ||
if (currentWindow.document && currentWindow.document.referrer) { | ||
referrerLoc = currentWindow.document.referrer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't this return a string when an object is expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returns a string to getIframeParentLoc
which then gets sent to parse
which turns the string into the expected object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd feel better if we had unit tests to cover the getTopWindowLocation
changes
I'll work on adding some unit tests. |
Reorg gettopwindowlocation util & add tests.
I reorganized the additions to Also to use |
There really are not any elegant solutions that I've seen to mock window and the like. The other option is to pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for adding tests
@rachelrj |
Fixed merge conflict. |
* 'master' of https://github.com/prebid/Prebid.js: EngageBDR New Bid Adapter (prebid#2309) [FEAT] adunit sizes support (prebid#2320) Support aliases in prebidServer (prebid#2257) Changing default currency file to https (prebid#2306) Update stalebot labels (prebid#2319) Enhance location detection within utils (prebid#2167) if cache markup is not enabled, set it to the default value 0 (prebid#2302) Serverbid Bid Adapter: Added archon alias (prebid#2293) Smart Ad Server: Fix bug when multi bids (prebid#2170) NEW adapter AdtelligentBidAdapter (prebid#2137) add optional param to bridgewellBidAdapter (prebid#2289) Increment Pre Version Prebid 1.6.0 Release Unit test fixes (prebid#2301) PBS videoCacheKey and vastUrl (prebid#2101) Add Oneplanetonly Bid Adapter (prebid#2269) firing new adRenderFailed event when renderAd() fails (prebid#2210) Add Content Ignite adapter (prebid#2268) add hb_cache_id, hb_uuid should be deprecated and replaced by hb_cache_id (prebid#2273) Update Yieldlab adapter and add official maintainer (prebid#2231) Update for Media.net adapter (prebid#2232) Update to Rubicon Adapter for mediaTypes support (prebid#2272) message formatting (prebid#2285) Yieldbot impression image creation fix (prebid#2277) Updated Bid params (prebid#2275) Audience Network: Add 'pbv' and 'cb' query params (prebid#2252) Add e-planning analytics adapter (prebid#2211) Add vastUrl for Gamma Adapter Video (prebid#2261) update params for test bid (prebid#2267) Updated adUnitCode (prebid#2262)
* fix sovrn dealid * send 'iv' param if present * `page` field in `site` object sends full url * Enhance location detection within util function. * fix func call * fix tagid var type * add test for converting tagid to string * CR * Reorg gettopwindowlocation util & add tests. * lint fixes * search param is string in window location objects
Type of change
Description of change
Check other window objects for location if cannot find.