Skip to content

Commit

Permalink
Cross domain window parent fix (#62)
Browse files Browse the repository at this point in the history
* if window.location does not match window.parent.location, then avoid cross-domain exception by using referrer instead of parent.location

* add tweaked embed test for cross-domain
  • Loading branch information
pkarl authored Jan 14, 2022
1 parent 2a9f022 commit 1803934
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"watch": "cross-env NODE_ENV=development rollup -c --watch",
"copy-test-files": "copyfiles test/**/* dist -f",
"test-serve": "serve .",
"test": "concurrently pnpm:watch pnpm:copy-test-files pnpm:test-serve",
"test-embed-serve": "serve . -l 3333",
"test": "concurrently pnpm:watch pnpm:copy-test-files pnpm:test-serve pnpm:test-embed-serve",
"lint": "eslint src",
"prepublishOnly": "pnpm run build",
"prepare": "husky install"
Expand Down
4 changes: 3 additions & 1 deletion src/api/js-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ function init() {
// get from url if query param exist
const queryParam = getParameterByName(
queryParamOverridesName,
window.parent ? window.parent.location.href : window.location.href
window.location != window.parent.location
? document.referrer
: window.location.href
);

if (queryParam) {
Expand Down
4 changes: 4 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,9 @@ <h1>Current: <span id="testTitle">embedded-map</span></h1>
</ul>
</div>
<iframe id="testFrame" src="./embedded-map.html"></iframe>
<iframe
id="testFrame_cross_domain"
src="http://localhost:3333/embedded-map.html"
></iframe>
</body>
</html>

0 comments on commit 1803934

Please sign in to comment.