Can a progressive web app (PWA) run a background service on a mobile device to get data from hardware (accelerometer, gps...)?

Rafael Oliveira picture Rafael Oliveira · Jun 13, 2017 · Viewed 19.8k times · Source

I see we can check the capabilities of a mobile browser using https://whatwebcando.today/, but can the hardware APIs be queried when not running on foreground?

I mean... With PWA am I able to build an app that gets hardware info while running in background, just like Octo U, for Android, and posts that info to a web server?

Answer

Jeff Posnick picture Jeff Posnick · Jun 14, 2017

The modern method of running code "in the background" is by using a service worker, either via its push event handler (triggered via an incoming push message), or via its sync event handler (triggered by an automatic replay of a task that previously failed).

It's not currently possible to access the type of hardware sensors that you're asking about from inside a service worker.