Created
November 16, 2015 20:40
-
-
Save asutherland/79d629e2c9d1b7a16a2c to your computer and use it in GitHub Desktop.
iframe entrainment investigation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<script src="child-frame.js" type="application/javascript"></script> | |
</head> | |
<body id="content"> | |
<div id="expando-friend"> | |
Child! | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sendMessage() { | |
var data = { foo: 'bar' }; | |
var message = new MessageEvent('message', { data, source: window }); | |
window.parent.dispatchEvent(message); | |
} | |
function makeGiantArray(megs) { | |
var arr = new Uint8Array(megs * 1024 * 1024); | |
for (var i = 0; i < arr.length; i++) { | |
arr[i] = i&0xff; | |
} | |
return arr; | |
} | |
window.addEventListener('load', function() { | |
// Let's save off giant arrays to the global and as a DOM expando. Give them | |
// different sizes so we can see which is the one being retained. | |
window.jsGiantArray = makeGiantArray(2); | |
document.getElementById('expando-friend').expandoGiantArray = | |
makeGiantArray(3); | |
sendMessage(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<script src="parent-root.js" type="application/javascript"></script> | |
</head> | |
<body id="content"> | |
<iframe id="child" src="child-frame.html" /> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function killIframeSoon() { | |
setTimeout(function() { | |
var ifr = document.getElementById("child"); | |
ifr.parentNode.removeChild(ifr); | |
}); | |
} | |
window.addEventListener('message', function(event) { | |
window.savedData = event.data; | |
killIframeSoon(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment