Is it possible for an onbeforeunload event to take too long to complete? What could I be overlooking?

This issue appears to be quite common, yet I haven't come across any identical cases or solutions that actually work. Therefore, I am adding my voice to the chorus.

The code snippet I have handles the scenario where:

window.onbeforeunload = function() { PubNub.publish(...); };

It sends a message to a PubNub channel when a user exits the current page of a chat forum. We aim to inform others in the room that User X has left. (Please refrain from suggesting alternate designs, such as implementing heartbeat signals for each user; this is simply an experimental project I'm tinkering with.)

While monitoring the channel on another tab, I've noticed that the PubNub message consistently gets published whenever I

  • close the tab

and occasionally (both successful and unsuccessful) when I

  • refresh by clicking the circular icon in the address bar

but it seems to never occur when I

  • click on a link to navigate away
  • enter a new URL in the address bar to leave the page
  • reload the same URL in the address bar
  • use ⌘R to refresh

Interestingly, even adding return "please don't exit"; in the onbeforeunload handler leads to inconsistent publishing: sometimes the message is sent upon entering the same URL, while other times it isn't.

Could this be a peculiar behavior specific to Safari? If so, are there known workarounds available? Alternatively, could the issue be related to the speed or threading of PubNub.publish(), hindering its execution during an onbeforeunload event? My understanding of how onbeforeunload operates is limited.

(For now, you can access the entire code here. However, if you stumble upon this question in a month's time, please note that the link may no longer be active or may have been corrected.)

Answer №1

Our Presence feature serves a specific purpose, which you can explore more at the following link:

This functionality allows the Presence system to notify others when you exit the channel. Does this align with what you need?

regards, leonard

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilize MaterialUI Grid to define custom styles for the ::after pseudo-element

I came across a helpful article on Stack Overflow about Flex-box and how to align the last row to the grid. I'm interested in implementing it in my project: .grid::after { content: ""; flex: auto; } However, I'm not sure how to inc ...

Having trouble updating the DataTable with extra details retrieved from a new URL

I'm currently utilizing the DataTable plugin. After loading the DataTable, my aim is to reload the table, while keeping the existing content intact, and adding information gathered from a separate json file. However, I'm encountering an issue wh ...

Using Selenium WebDriver to Extract Variables from JavaScript SourceCode

Currently, I am dealing with a web page source code that utilizes JavaScript to display text. Below is an excerpt from the source: var display_session = get_cookie("LastMRH_Session"); if(null != display_session) { document.getElementById("sessionDIV") ...

Function for adding numbers in Javascript with currying

Can you help me solve this interesting problem? I need a javascript function that can return the sum of all arguments passed to it, even when called multiple times. I have identified different ways in which the function can be called - sum(1, 2, 3, 4); ...

The NextJS i18n feature is encountering an issue with the locale being undefined

Currently, I'm in the process of transitioning my website to NextJS, and I've run into some difficulties with internationalization. Even though I'm following the steps outlined in the official documentation, the locale displayed in the insp ...

Can JavaScript code be utilized within Angular?

Hello, I am wondering if it is acceptable to include JavaScript code within Angular for DOM manipulation purposes. Here is a sample of what I have in mind: document.querySelectorAll('div.links a').forEach(function(item) { const tag = window.lo ...

My React app is experiencing connectivity issues with the proxy server linking to my Express server

Currently, I have both my React app running on port 3000 and my Express server on port 4000 on the same local machine. Within my React app, I utilize the fetch API to send registration form data to my Express server at the '/register' route- con ...

Steps for implementing a Toggle Navigation Bar in CSS

I'm looking to implement a show/hide navigation menu similar to the one showcased in this inspiration source: Code Snippet (HTML) <div id="menus"> <nav id="nav"> <ul> <li><a href="#">HOME</a></li> <li& ...

Is it possible for a controller within a directive in AngularJS to define the ng-model of the directive itself?

Having a directive that utilizes ng-model controller and fetches its model value from the parent controller, "myController", I am seeking guidance on how to enable the consumer to dynamically set the ngModel value as they desire. The directive is designed ...

Rebounding Movement on iPad (React)

I've tried numerous solutions, but none seem to work. I have a page with scrollable content if necessary. While it functions properly in Windows Chrome and Firefox, iOS and Safari introduce an undesired vertical bouncing scroll. Some users have recom ...

Effective techniques for unit testing in Vue.js

Here's a question that's been on my mind: when it comes to unit testing in Vue.js, there are several different packages available. Vue Test Utils Vue Jest Vue Cypress For enterprise projects, which of these options would be considered best ...

Exploring ways to efficiently test the nested promises in an Angular service function

Here is a snippet of what my service implementation looks like: TestService.initializeDefaults = function() { var qPromise = $q.defer(); $q.all({ localResource: localResource.fetch(), item: itemResource.fetch() }).then(functio ...

Animate the tubular geometric pathway by continuously updating its values

When creating a TubeGeometry, I supplied a SplineCurve3 / CatmullRomCurve3 path as a parameter. My goal is to update the position of each point on the path using geometry.parameters.path.points[1].y += 0.01; within the requestAnimationFrame loop. Even tho ...

Display the image in a pop-up window before executing a jQuery script

Lately, I've been focusing on implementing zoom in and zoom out functionality for images. The plugin I've chosen to use is guillotine. It works flawlessly except for one small hiccup. My goal is to integrate it into a website built with angularJ ...

Encountering a JSON_PARSER_ERROR when trying to call Google FCM using MobileFirstAdapter JS

I am working on integrating Google FCM Api for sending Push Notifications. Below is the snippet of code from my JavaScript file: function sendNotificationToUser() { var request={ path :'/fcm/send', method: 'POST&ap ...

Is there a way to convert the existing JavaScript code for a hyperlink so that it can be triggered by clicking a button instead?

I have a JavaScript code that works well when the hyperlink below is clicked: <a href="delete_event.php?event_id=110" onClick="return ConfirmDelete()" class="list-group-item">Delete Event</a> <script> function ConfirmDelete() { var ans ...

What causes the data property to supersede the return false in a jQuery ajax call?

Below is a block of code that I am currently working with: $("#contact_container form, #contact_details form").live( "submit", function(event) { $.ajax({ type: this.method, url: this.action, data: this.s ...

A comprehensive guide to utilizing the GROUP BY YEAR(created_at) function in sequelize

How can I effectively use the GROUP BY clause in sequelize for MySQL to group by year of creation? I attempted the following code but encountered an error: const result = await arbcase.findAll({ attributes: [[arbcase.sequelize.literal(`COUNT(*)`), "co ...

Get Angular events in the proper order

I am currently facing challenges with event handling in AngularJs. In my service, I send out events using the following line of code : $rootScope.$emit("FNH."+this.status, flowNodeHelper); When receiving the event in service "S1," I handle it as follows ...

Unable to refresh HTML table using Vuex data in Vue JS

I am new to working with Vue.js and particularly Nuxt. I am facing an issue with updating a table using data fetched from the backend. Even though I can see the data in the Vuex tab when the page loads, I cannot seem to populate the table with it. The func ...