Fix beforeUnload handler delay