Avoid clash with window.onbeforeunload

* Use addEventListener instead of window.onbeforeunload