This file contains 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
var f = (e, t) => { | |
return (5, 6) + 2; | |
} | |
var e = function () { | |
return f(8,8) + 4; | |
} | |
window['a b'] = function () { | |
return e(5, 7); |
This file contains 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
// run this code in devtools console and than try to shutdown | |
// the tab - see how Chrome suddenly respects `debugger;` statement! | |
window.onunload = (e) => { | |
debugger; | |
}; |
This file contains 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
window.addEventListener('unload', (e) => { | |
function sleep(delay) { | |
const start = new Date().getTime(); | |
while (new Date().getTime() < start + delay); | |
} | |
// unloading won't finish until 10 full seconds pass! | |
sleep(10000); | |
setTimeout(() => { |
This file contains 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 listener() {} | |
const frameset = document.createElement('frameset'); | |
const body = document.body; | |
window.onunload = listener; | |
window.onbeforeunload = listener; | |
body.onunload === listener; // true | |
body.onbeforeunload === listener; // true |
This file contains 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 successful_listener(e) { | |
console.log('would successfully fire!'); | |
} | |
function failing_listener(e) { | |
console.log('would never fire - this message would never be logged to console'); | |
} | |
// both ways to register both beforeunload and unload events would work with window |
This file contains 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
const ifr = document.createElement('iframe'); | |
document.body.appendChild(ifr); | |
// top window's beforeunload event would be the first one to fire | |
window.onbeforeunload = function(e) { | |
console.log('first event to fire (1)'); | |
}; | |
// other windows beforeunload events would fire after top window | |
ifr.contentWindow.onbeforeunload = function(e) { |
This file contains 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
window.addEventListener('unload', (e) => { | |
console.log('unloading!'); // would successfully log to console | |
localStorage.setItem('key', 'value'); // would successfully set new item to local storage | |
debugger; // would fail to break at this point! | |
}); |
This file contains 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
// by https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload#Example | |
window.addEventListener("beforeunload", function (event) { | |
event.preventDefault(); // Cancel the event as stated by the standard. | |
event.returnValue = ''; // Chrome requires returnValue to be set. | |
}); |