Keep socket.io connection alive when chrome is running in the background - google-chrome

I have a custom notification service that pushes notifications to a website(NodeJS and Socket.io). I'm not using WebPush for this because the system is in an internal network and won't be able to make a subscription request. So far, it works fine when the website is open and running. Problem is, unlike with WebPush, when chrome is closed and running in the background, I am unable to receive push notifications. This is because after a few seconds, the socket.io connection is closed because chrome stops the service worker(with WebPush, chrome is able to wake up the service worker when a notification comes in)
My question is, how do I make it so when chrome is closed and running in the background, the socket.io connection stays open.

Related

As a developer, what can I run when chrome is closed and running in the background

I was wondering what kinds of processes I can run when Chrome is closed and running in the background.
For context, I created a chrome extension that was supposed to keep a socket.io connection open while chrome is closed and running in the background but after a few seconds, I noticed the connection was closed. This is because I was managing the socket connection in a service worker and service workers are stopped after some time when there's no activity.
So my question is, besides just getting notifications from WebPush, what other things can be run in Chrome when it is closed and running in the background

I have a timeout to make an ajax call, but chrome keeps on calling it even after the tab is closed

Normal js code (no service worker, but the app has a manifest with an empty service worker).
A simple timeout to an ajax call that's the code.
I close all chrome tabs, I close the process in task manager, no more chrome processes and yet I still get requests on my server. This happens locally and on the server, I know this because I can see the cookies sent and for which user id is needed.
Also I know that chrome is running the code because there is a date in the request and is updated as it go.
Triple checked that chrome is closed on all users and all processed in task manager.
Is not a coincidence because at this moment I have 2 different users (different chrome profiles) doing this. Also in my dev server there are a lot of users with the same behaviour.
I'm also not sure is chrome, but has to be, node.js alone can't change the time of the request.
Win 10 and Chrome Version 60.0.3112.90 (Official Build) (64-bit)
Terrible and I don't know what to do...
if I restart my node.js server all the requests stops.
Was my mistake! As I have server side rendering (with react) I forgot that the timeout was also run on the server side. The fix was to don't run any timeouts on the server side.
Thanks anyway for the answers. I was concerned how chrome was still running my js code even shut down, made no sense at all!

How to revive HttpClient after network connection has been restored?

How to revive HttpClient and make it see that the network is available again without fully restarting the application?
In case when a Xamarin.Forms app was launched with no network connection available and then later network connection is enabled, HttpClient.SendAsync(request) throws NameResolutionFailure and it does not recover, no matter how many times the request is repeated.
It seems, HttpClient does not know how to recover when network connection appears.
To reproduce the issue in Android emulator:
ensure your app is completely closed
turn network off (set Data status to Roaming in emulator settings or use the status bar to toggle the data or LTE switch).
launch your app, run a web request to verify that it does not work (obviously, you will need try/catch around the web request to avoid crashing)
while the app is still open, enable the network
run a web request - will get NameResolutionFailure
only full application restart will revive HttpClient
The issue does not happen if I use domain names specified in etc/hosts file.
I tried to fully recreate HttpClient and resend a new request when the issue occurs, but that does not help. Only full restart of the app helps.
Obviously, I cannot ask user to fully kill my app and start it again every time when user has turned on his network connection after launching my app.
This is a known issue. See:
Mono: https://bugzilla.xamarin.com/show_bug.cgi?id=45761
iOS: https://bugzilla.xamarin.com/show_bug.cgi?id=45763
Android: https://bugzilla.xamarin.com/show_bug.cgi?id=45383
The workaround is to manually set the DNS refresh:
System.Net.ServicePointManager.DnsRefreshTimeout = 0;

How to see Chrome's response to Websocket's ping frame

I do not have a choice of installing a network traffic analyzer.
How would I go about looking at the response from chrome to a websocket's ping frame.
In chrome dev tools, it seems we can only see the incoming frames.
Background: I am trying to develop a websocket java client, but the server sends a close soon after a ping, I am assuming this is because of lack of response from the client. I have tried responding with a "pong" and 0xA byte, but still the connection is closed.

Mobile HTML5 API integration support

Would mobile HTML5 support the following, and if not, why?
Device connected to the net
App loaded
App calls remote API and responds to request for API credentials
App receives session token
App requests data from remote API using session token
App pushes data to local database and screen
App closed
Device disconnected from net
App loaded
App loads data from local database
User inputs data which is added to the local database
App closed
Device connected to net
App loaded
App sync's remote/local data
App closed
Device connected to net
App closed
App push notifications enabled in device settings
Push notification sent to device from remote server
Native device prompt displayed for push notification
Maybe this will get you going on the right path? http://mobilehtml5.org/
There's no HTML5 feature called "push notification" nor, as far as I know, any way to create native notifications in iOS or Android from the browser. So right off the bat, that's going to be a tough one.