Recent versions of Chrome on Android have added the ability to create full screen Webapps using the 'mobile-web-app-capable' meta tag in much the same way that you can on iOS.
On iOS when you quit a web app and open it again it will always be refreshed; on Chrome it will be up to the operating system resources; and if you re-open the same web app it will often restore the previous app context without reloading the page.
This is causing problems for my Weather Web App as on re-open it often displays old forecast data which can be days out of date.
Is there a way to detect the page re-open so that I can refresh/reload the content?
It seems that the trick is to use timers. Usually, when a webapp is in the background (not a tab background) it's frozen, so it's not executing code. Therefore, if you have a javascript timer that executes every X seconds and on one execution you see that the time passed between executions is far greater then it means that you need to update your data.
Related
This is to do with the way Android handles its activity which is giving me some problems.
Ive developed an app with a webview that loads the facebook page and keeps looking for new notifications.
and any new notification beeps the device.
Im using the JavascriptInterface to check the Facebook DOM for the notification count.
Javascript running with setTimeout.
The only problem is, it all works fine until i have the screen on. If i shut the screen for a few minutes and turn it back on I find that a new notification had already appeared on facebook a while ago but my webview missed it and is reactivated only the moment the screen is back on.
Is there a way to make sure that any data the browser page needs to load must be allowed and always kept active by the WebView ?
In short is it possible to run a sort of internet service like navigate to a page every few minutes and run a script on it regardless of my device state ?
I have a PWA where users can redeem stuff. The problem comes when it's PWA on iOS because they don't communicate, so users are able to redeem twice (once in the browser and once on the PWA; if they're sneaky), because PWA doesn't update on what's happening on the browser.
My solution for this would be that every time people are using PWA on iOS and they open the app, it will reload to be updated with the same information the browser one is.
first, I created a function to detect if the user is on iOs and a function detecting if the user is on standalone, to know they're on PWA, so combining these who I created:
if(is_iOS() && isInStandaloneMode()){
window.location.reload(true)
}
But this only created a reload on loop, so I wasn't able to even see the information once.
Is there a way to be able to refresh the page every time the PWA is opened?
Usually I post code on my posts but i'm just curios in general with this question on my mind so here's the situation. I have a couple of real time systems which uses one file that produces constant basic polling with CRUD(Create,Read,Update and Delete) traits. The way i'm doing this is
by putting the setTimeout at the end of that page which constantly call a function on the main page to recall that page AKA the polling with CRUD page by AJAX which also constantly analyze different components of the main web page and executes one of the CRUD traits depending on the logic of
the situation between the web page and the database, I know web browsers pauses a setTimeout on purpose for the purpose of saving computing energy when that web page is not being interacted with due to the following situations that I notice
for example on PC when a user revisits that kind of system when revisiting that web page after coming back from the lock screen or when revisiting that web page after coming back from the login page or when revisiting that web page after
coming back from a sleep state and even revisiting that web page after coming back from another web tab after long periods of time and on mobile browsers, when revisiting that web page after coming back from the lock screen or when
revisiting that web page after coming back from another app or when revisiting that web page after coming back from a sleep state. All these situations causes my real time polling with CRUD system to experience glitches but no glitches occurs if I remain on the page so I was just
wondering is there any JavaScript methods that I can use as response code to detect when a browser pauses a web page like this on PC or on Mobile devices like smart phones or tablets? I was thinking if there is a method like that. I can simply just
create a response code that can reload that web page if the browser does that.
I'm using a web framework where everything gets passed through a websocket. New / updated DOM elements are shipped over to the browser, events get shipped back to the server. Works great. Except when the websocket gets closed.
This happens...
when using desktop/mobile Safari's browser navigation buttons are used to leave & come back to the page
on mobile Safari after a timeout when switching to a different app, tab or screen locking
when the WiFi goes down etc.
After that the user simply sees a normal looking page, but everything is obviously dead as no more updates happen and no more events get relayed to the server. I'd like to simply refresh the page in that case. Either everything goes back to normal or the user sees a connection error in case of no network etc.
I tried poking around in the framework's code, adding "window.location.reload(true);" to the "onclose" handler for the websocket kinda does the trick. My state is 100% on the server, so reloading the page will just fix things.
Assuming I can't modify / fix the web framework I'm using, and it doesn't have any onConnectionLost client-side event, what's my best option to detect this scenario and reload the page? Are there any events like 'onPageDisplayedButNotProperlyReloaded', 'onPageVisibleButHasBecomeStaleInTheMeantime', 'onWebSocketsClosed' for me to use? Can I just open some dummy websocket and reload the page when it gets closed or something? Any other good way to detect this?
Thanks!
I'm developing a web app that shows a counter, and when the counter comes down to 0 I want to notify the user(The counter is on a server, so there won't be a problem with reloading the page).
If the user is on a computer, I'm using a popup for the notification, but if the user is on an Android device, I would like the notification to be shown even if the browser isn't open.(I'm using AngularJS if that would be any help)
Is there a way to do this? I rather not build a special Android app.
Thanks.
//G
I'm afraid no, there is no way to do that. When any android application is not active is... not active, frozen. The browser is not a service, so as far as I know it won't process anything while in background. Even it's possible the OS close the browser if it needs more memory than is available.