I have found success! Works 100% of the time and no pop up alerts!
<script>
window.addEventListener('unload', function () {
navigator.sendBeacon('/dmxConnect/api/Authentication/Forms/logout.php', '');
});
</script>
I’m very happy!