There are two stages to a navigation, whether that navigation is the result of following a link, or hitting ‘Refresh’.
When you first start the navigation, the page is not immediately killed. The onbeforeunload event will fire, and JavaScript will continue to run normally, including sending AJAX requests. The browser sends an HTTP request for the new page URL and waits for a reply.
Maybe the server will send back a 204 Not Modified response. In that case, the old page will just carry on running. Maybe there'll be some redirects to follow, slowing it down further. Anyway, it could take a while before the browser receives enough of the new HTML page response to start rendering it.
Only then is onunload fired, the previous page killed, AJAX and any other outstanding requests from it aborted, and the new page displayed. At this point your old script definitely won't be running.