Skip to content

Instantly share code, notes, and snippets.

@bakkot
Created December 11, 2016 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bakkot/c93d319ea727260562131765e548fe8d to your computer and use it in GitHub Desktop.
Save bakkot/c93d319ea727260562131765e548fe8d to your computer and use it in GitHub Desktop.
let frame = document.body.appendChild(document.createElement('iframe'));
frame.addEventListener('load', ()=>{
let w = frame.contentWindow;
let evt;
w.addEventListener('error', e=>{evt = e;});
let scr = w.document.createElement('script');
scr.text = 'throw 42;';
w.document.body.appendChild(scr); // this line executes synchronously and triggers w's new 'error' event handler synchronously?
console.log(evt); // so that by the time this line is hit, 'evt' will have been assigned?
});
frame.src='';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment