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

Enhance location detection within utils #2167

Merged
merged 23 commits into from
Mar 26, 2018
Merged

Conversation

rachelrj
Copy link
Contributor

Type of change

  • Feature

Description of change

Check other window objects for location if cannot find.

Copy link
Collaborator

@matthewlane matthewlane left a 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) {
Copy link
Collaborator

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?

Copy link
Contributor Author

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() {
Copy link
Collaborator

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?

Copy link
Contributor Author

@rachelrj rachelrj Mar 1, 2018

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.

Copy link
Collaborator

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();
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Rachel Joyce and others added 2 commits March 1, 2018 16:48
@mkendall07 mkendall07 self-assigned this Mar 5, 2018
src/utils.js Outdated
do {
currentWindow = currentWindow ? currentWindow.parent : window;
if (currentWindow.document && currentWindow.document.referrer) {
referrerLoc = currentWindow.document.referrer;
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@mkendall07 mkendall07 left a 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

@rachelrj
Copy link
Contributor Author

rachelrj commented Mar 6, 2018

I'll work on adding some unit tests.

@matthewlane matthewlane removed their assignment Mar 6, 2018
@mkendall07 mkendall07 removed this from the Prebid 1.5.0 milestone Mar 8, 2018
@mkendall07 mkendall07 added this to the 1.6 milestone Mar 8, 2018
@rachelrj
Copy link
Contributor Author

I reorganized the additions to getTopWindowLocation and added unit tests.
To mock the readonly window objects in sinon, I wrapped in accessors.
I couldn't figure out a better way to mock these...

Also to use url.parse for getTopWindowLocation, search needs to be returned as string to mirror window.location object.

@mkendall07
Copy link
Member

There really are not any elegant solutions that I've seen to mock window and the like. The other option is to pass window in the module bootstrap but that's not great either.

Copy link
Member

@mkendall07 mkendall07 left a 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

@mkendall07
Copy link
Member

@rachelrj
could you fix the merge conflict so I can merge? Thanks

@rachelrj
Copy link
Contributor Author

Fixed merge conflict.

@jaiminpanchal27 jaiminpanchal27 merged commit 63159da into prebid:master Mar 26, 2018
mifefr added a commit to mifefr/Prebid.js that referenced this pull request Mar 29, 2018
* '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)
dluxemburg pushed a commit to Genius/Prebid.js that referenced this pull request Jul 17, 2018
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants