Unregister not running in Chrome on unload

I noticed a strange issue whereby when refreshing a page with SSE on, the session count was increasing and the old sessions was remaining until cleanup occurred. On further investigation, it appears in Chrome that the $(window).on(“unload”) is not firing to unregister the event stream before reloading the page. It doesn’t occur even when moving to another site either.

It works fine with Firefox so I did a bit of research and people seem to state the onbeforeunload event works better than unload in Chrome.

Just wondered if you’d heard/seen this issue before?

Seems to be a recent issue: https://support.google.com/chrome/thread/37756390?hl=en

I’ve added a fix in this commit for firing on both unload/beforeunload events in this commit.

Thanks for the update.

Unfortunately the fix doesn’t seem to work when tested here. Looks like they’ve broken that part of Chrome…

I’ve found the information that relates to this issue:

Disallow Synchronous XMLHTTPRequest() in Page Dismissal

Chrome now disallows synchronous calls to XMLHTTPRequest() during page dismissal when the page is being navigated away from or is closed by the user. This applies to beforeunload , unload , pagehide , and visibilitychange .

To ensure that data is sent to the server when a page unloads, we recommend sendBeacon() or Fetch keep-alive . For now, enterprise users can use the AllowSyncXHRInPageDismissal policy flag and developers can use the origin trial flag allow-sync-xhr-in-page-dismissal to allow synchronous XHR requests during page unload. This is a temporary “opt-out” measure, and we expect to remove this flag in Chrome 82.

For details about this and the alternatives, see Disallowing synchronous XMLHTTPRequest() during page dismissal.

I changed the code in ss-utils.js and it seems to work, hope this helps! You can probably do it neater!

$.ss.onUnload = function () {
    var url = $.ss.unRegisterUrl;
    if (url) {
        $.ss.unRegisterUrl = null;
        if (navigator.sendBeacon) {
            navigator.sendBeacon(url, new FormData());
        } else {
            $.ajax({ type: 'POST', url: url, async: false });

This was my commit