Skip to content

Commit

Permalink
Merge pull request #236 from tilfinltd/fix/msg-to-iframe
Browse files Browse the repository at this point in the history
Skip receiving message in iframes
  • Loading branch information
tilfin committed Jan 10, 2022
2 parents 09e2fa5 + 25825e5 commit b705b98
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,27 @@ if (document.body) {
}

(chrome || browser).runtime.onMessage.addListener(function(msg, sender, cb) {
const metaASE = document.getElementById('awsc-signin-endpoint');
if (!metaASE) return false;

const { data, action } = msg;
if (action === 'loadInfo') {
if (!window.AESR_script) {
window.AESR_script = document.createElement('script');
AESR_script.src = chrome.extension.getURL('/js/attach_target.js');
document.body.appendChild(AESR_script);
setTimeout(() => {
AESR_script.onload = () => {
const infoJson = document.getElementById('AESR_info').dataset.content;
cb(JSON.parse(infoJson));
}, 50);
};
document.body.appendChild(AESR_script);
return true;
} else {
const infoJson = document.getElementById('AESR_info').dataset.content;
cb(JSON.parse(infoJson));
return false;
}
} else if (action === 'switch') {
const metaASE = document.querySelector('meta#awsc-signin-endpoint');
let actionHost = metaASE ? metaASE.getAttribute('content') : 'signin.aws.amazon.com';
let actionHost = metaASE.getAttribute('content');
const { actionSubdomain } = data;
if (actionSubdomain && actionHost === 'signin.aws.amazon.com') {
actionHost = actionSubdomain + '.' + actionHost;
Expand Down

0 comments on commit b705b98

Please sign in to comment.