Unfortunately, the implementation of onunload or onbeforeunload is not so great between browsers, and in case of failure, the unload event will never be fired. Itโs best not to worry about catching unloading events and just have reasonable deadlines.
If you don't need to worry about the difference between form submissions and updates, you could get pretty good coverage with onunload, but it still won't be 100%.
source share