1

I am developing a simple web application which will be used for tracking GPS position. The general idea is that every couple of minutes it'll send the GPS location back to a server with an AJAX request. Note the device will be connected to power permanently.

We ideally need this to keep running in the background when the screen is turned off. I've put together a test with a Nexus running Lollipop and Chrome and had limited success. The requests keep sending for 5-10 minutes after the screen is off, then they stop.

Oddly there still seems to be occasional requests. For my testing I'm doing a 10 second request interval, in the real world it'll be more like 5-10 minutes. Some sort of queue? If this is a thing and I can figure out how to work with it reliably it might work.

Is there any way I can get them to keep sending indefinitely? Settings in the OS/browser, or different browser (or both) maybe?

1

HTML5 ServiceWorker seems to support what you need via BackgroundSync / PeriodicSync feature. However, since ServiceWorker is still an ongoing effort, I'm not sure what features are currently implemented in Chrome. I couldn't find any good demoes of this, only proposals: https://github.com/clelland/BackgroundSync/blob/master/explainer.md

Cordova has recently added support for Background sync: https://github.com/MobileChromeApps/cordova-plugin-service-worker-background-sync, but this requires you building an Android app.

Without browser's explicit support for such a feature, all your ad hoc efforts will be a waste of time, since your code will be guaranteed to work only when the browser is in foreground. Otherwise, the browser itself can be killed by the OS, and won't be able to continue executing your page's code. The periodic sync feature provided by ServiceWorker implies that the browser would schedule periodic jobs using the corresponding Android services, like you would do in a Java app.

  • Thanks! I'll have a look into that first link in the next couple of days and see if I can throw together a quick proof-of-concept to test with. If not, Cordova might be an option too - spinning up an app which is nothing but an iframe pointing to the actual web site might do what I need without blowing the budget. Will report back. – SpoonNZ Sep 9 '15 at 4:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.