// Define something in here or the script may get collected window.addEventListener("unload", function () { window.foo = "bar"; });