Skip to content

Instantly share code, notes, and snippets.

@asutherland
Created November 16, 2015 20:40
Show Gist options
  • Save asutherland/79d629e2c9d1b7a16a2c to your computer and use it in GitHub Desktop.
Save asutherland/79d629e2c9d1b7a16a2c to your computer and use it in GitHub Desktop.
iframe entrainment investigation
<!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>
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();
});
<!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>
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