VueJS perform background operations only on one tab - javascript

I wanna improve my VueJS application system.
Currently, each browser tab once per 20 seconds makes synchronization with the server - getting notifications and the latest settings.
It's problematic because a typical user often has 20+ opened tabs, so each synchronizes itself.
I know, that I can share the Vuex Store between tabs, using localStorage, and currently I'm doing this, so I don't have to synchronize everyone tab, cause if one of them synchronizes, all of them will have current data about app notifications and settings.
So the question is - how to do it?
I tried using this solution, but what if the user closes the tab? How to control that, one of the tabs synchronized the data?
Thanks in advance, have a nice day!

Related

Communicating two tabs on two devices in javascript using broadcast channel

I need some advice on whether I need to reimplement my project or I can make the current implementation work. I have implemented a user interface to do some wizard of oz testing. I have a user-side page (Page A), which fires up a second page, the wizard page (Page B). When the user asks questions on page A, the question is sent to page B using a broadcast channel, and the answer is received through a broadcast channel. Everything works great on the same computer.
But my problem is that I want to open the wizard page on a second device, so the user doesn't see the wizard is answering the user's question. When I open the wizard page on a second device (my first device is an apple MacBook, and my second device also is an apple MacBook), the communication between the two pages doesn't happen. Both pages are located on the same server and have the same host name.
Is there any way I can make my current implementation work on two devices?
Or should I just re-implement the communication part?
I would very much appreciate any solution or hint.

How to find whether the user is watching our website or not(it should work when switching applications also)?

I am creating a chat application, where I need to send notifications when the user is not watching my website or working in another application.
Now, most of the use cases can be handled using the page visibility API. But there is a particular use case when the user is switching the application from browser to any other application(ex: Outlook), I want to send a notification at that time.
But the issue here is page visibility API does not provide anything on switching applications. That is if the browser active tab has my website and the user switches the application from browser to any other application, it still thinks the user is looking at my website which is wrong because the user is in anther application right now.
I have done R&D on this and I see it is impossible because browsers can't detect these kinds of changes due to security reasons.
But when I checked with Whatsapp web there, javascript is able to find weather user opened the current application or not and based on that they are sending notifications.
So, How can I implement same feature that Whatsapp guys implemented? Is there any web API I am missing here. Are any hacks available to implement this kind feature?
Thanks in advance.

Web Notification API - website doesn't need to be open?

I noticed some news sites such as Washington Post are able to pop up Web Notifications even though I don't have the site open in a tab. I don't recall this being possible before. How is it even possible for a website to execute the JS necessary if the site isn't open? How does one accomplish this using Web Notifications, is there a particular setting to accomplish this?
I believe they are using Push Notifications via Service Workers.
You can check the current support status to see if it's fit for you. It's well supported in modern browsers (although perhaps not the full specification).
A service worker is a script that your browser runs in the background,
separate from a web page, opening the door to features that don't need
a web page or user interaction. Today, they already include features
like push notifications and background sync.
and
A service worker has a lifecycle that is completely separate from your
web page.

Disabling browser refresh programmatically caused by addons or plugins

We are maintaining a website where based on user access of different webpages we keep alive a cookie and do a session timeout based on inactivity(based on the cookies access timestamp).
Recently we found out there are many browser plugins (e.g Reload Every for Firefox etc.) which can programmatically refresh a web page, defeating our purpose of properly calculating when we should timeout the user.
I have tried the AddonManager API(FF version 4) and ExtensionManager(FF 2 and 3), but really reluctant to do some browser specific codes to disable plugins/ addons.
Is there any elegant solution to handle these addons or the auto page refresh scenario?
Thanks for your help.

Close a browser tab opened by Android app

I have an issue where I'm asking my app to open a browser looking at my Server.
From that server page, The user can perform some stuff on an existing site, then redirects the user to a URL that the App catches and the App continues as normal.
The lifecycle looks like this:
App -> Web Site -> App
However, after the life cycle of the app and the app is closed, the webpage is still open in the browser (on the page where the redirect to the app occurred).
It's apparently difficult via javascript to close a tab which wasn't opened by javascript? (In my case, the tab was opened by the app, not by a different tab). Is there any way to get around this?
(I'm aware I could use a WebView, but WebViews are buggy, manufacturer specific, security holes that I want to avoid)
No, sorry. There is no standard Intent structure for this. While it is possible that some browsers offer something, I am not aware of any that do.
Bear in mind that there is no requirement that your ACTION_VIEW Intent open up a browser tab, as the user's chosen browser may not offer any sort of tab UI metaphor. check this reference old question

Categories

Resources