7

Environments

  • iOS 14.4.2 (safari)
  • chrome 91.4472.80

As I was trying to find a way to prevent my iPhone going to sleep while a browser page is opened, I found 3 ways.

  1. use Screen Wake Lock API https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API
  2. call window.location.href periodically and stop it
  3. play a video with a user interaction

For #1, this doesn't work on iPhone, should work on Android.
#2, didn't seem to work on either safari or chrome on iPhone.
#3, also didn't work (even playing a video after user interaction).

I tried https://github.com/richtr/NoSleep.js/ but didn't prevent from sleeping.
I also tried https://github.com/roldanjr/use-stay-awake and it opened a blank video in fullscreen (this maybe fixed by just adding https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#attr-playsinline)

Then, I noticed browser version of Youtube preventing my phone from sleeping while it's playing a video (I set my sleep time for 30 seconds, and it can play a 10 min video without turning itself off).

Does anyone know what kind of technics they are using to do that?

kukrt
  • 2,117
  • 3
  • 21
  • 32
  • Did you find out how youtube is doing it? – Eric Kim Nov 29 '21 at 02:37
  • 1
    https://github.com/richtr/NoSleep.js/ This actually is working for me. https://gist.github.com/github0013/7bba37c108cb8983ff3f0dd2f7102cc7 This is how I am using it. – kukrt Nov 29 '21 at 02:47

0 Answers0