Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep phone screen on with PWA (progressive web app)

I built a fitness "progressive" web app that you can add to your phone home screen. It guides the user through a 7 minute workout.

Is there any way to keep the screen "awake" so the user doesn't have to keep coming back to the phone to turn it on? Another drawback to the screen sleeping is the javascript timer stops, ruining the workout timing.

like image 531
patmood Avatar asked Jan 30 '18 03:01

patmood


1 Answers

https://www.w3.org/TR/wake-lock/

https://developer.mozilla.org/en-US/docs/Archive/B2G_OS/API/Wake_Lock_API

Basically, yes, there is such a thing as a website forcing the screen to stay awake, but it is non-standard currently. It may become standard but right now it seems to only work on FirefoxOS. This is however to be the intended way to achieve wake locking in javascript.

Another solution though that's more of a hack is doing something along the lines of playing a hidden video in the background since as far as i know most browsers stay awake if a video is playing.

like image 111
Simon Hyll Avatar answered Nov 05 '22 17:11

Simon Hyll