Skip to content
This repository was archived by the owner on Jan 19, 2023. It is now read-only.

fix for getOrigin issue within iFrames #136 #175

Merged
merged 2 commits into from
Jun 19, 2019
Merged
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ export function getWindowHeight() {
// Get the highest window context that isn't cross-origin
// (When in an iframe)
export function getHighestSafeWindowContext(self = global.window.self) {
const referrer = self.document.referrer;
// If we reached the top level, return self
if (self === global.window.top) {
if (self === global.window.top || !referrer) {
return self;
}

const getOrigin = href => href.match(/(.*\/\/.*?)(\/|$)/)[1];

// If parent is the same origin, we can move up one context
// Reference: https://stackoverflow.com/a/21965342/1601953
if (getOrigin(self.location.href) === getOrigin(self.document.referrer)) {
if (getOrigin(self.location.href) === getOrigin(referrer)) {
return getHighestSafeWindowContext(self.parent);
}

Expand Down