NoSleep.js icon indicating copy to clipboard operation
NoSleep.js copied to clipboard

Not working with Safari IOS 15.0

Open vivipeder opened this issue 2 years ago • 25 comments

Not working with last update IOS 15.0!

vivipeder avatar Sep 26 '21 13:09 vivipeder

From my quick tests, iOS 15 Safari stays awake only if the video is playing, has no loop flag, is not muted AND is visible on a webpage (also tried absolute positioning with opacity:0 with no luck).

At this point, with no new workarounds available, there's only hope for proper Screen Wake Lock API support somewhere in the future.

pinoceniccola avatar Sep 28 '21 10:09 pinoceniccola

I can confirm, doesn't work since IOS 15

RotemAkerman avatar Sep 30 '21 11:09 RotemAkerman

Reckon this'll work with a 1x1 mp4? Perhaps it's the new spacer.gif...

marcphk avatar Oct 02 '21 18:10 marcphk

Apparently it's working again on IOS 15.0.1 update!

vivipeder avatar Oct 07 '21 13:10 vivipeder

Not working for me on iOS 15.0.2. Also I am seeing in Network tab that the video is infinitely fetched?

cerchez07 avatar Oct 15 '21 13:10 cerchez07

Anyone found a solution to this?

rhamnett avatar Nov 07 '21 15:11 rhamnett

@rhamnett I think if your iPhone is seeing your face, it will not lock.

steida avatar Nov 08 '21 20:11 steida

@steida thanks, seems you are correct!

rhamnett avatar Nov 08 '21 20:11 rhamnett

It happens to me too. I have it set that once you press the login button, the function is activated to prevent the screen from suspending. The call and execution seems to work fine, but it doesn't work, and both on IOS and Android and on computers, the screen turns off.

paulaegido avatar Nov 16 '21 09:11 paulaegido

I can confirm it's not working on iOS 15.1 but on Androids are. Seems the event 'timeupdate' is not being called. Then, the video is only played once. Tried many things but none gave any good result.

brunocarneiro avatar Nov 18 '21 06:11 brunocarneiro

@brunocarneiro @paulaegido @rhamnett Found a solution. It seems that the timeupdate event is only triggered when the element is actually appended to DOM, so this few lines did the trick.

const hideCss = {
  position: 'absolute',
  left: '-100%',
  top: '-100%'
}
Object.assign(this.noSleepVideo.style, hideCss);

document.querySelector('body').append(this.noSleepVideo);

this.noSleepVideo.addEventListener("loadedmetadata", () => {
[...]

@richtr - I'm kinda too lazy to fork the whole repo, would you apply this to the code?

z-x avatar Nov 19 '21 17:11 z-x

@RotemAkerman - Well I guess you are missing something, would need to see the code to help.

z-x avatar Nov 20 '21 20:11 z-x

My bad, had the script in <head> so <body> wasn't indeed present during execution

RotemAkerman avatar Nov 20 '21 20:11 RotemAkerman

@z-x Nice! I can confirm it's working now! Many thanks!

brunocarneiro avatar Nov 26 '21 13:11 brunocarneiro

This works on an iPhone 8 but doesn't work on an iPhone SE2020 both running 15.1

andy88ctv avatar Nov 29 '21 09:11 andy88ctv

const hideCss = { position: 'absolute', left: '-100%', top: '-100%' } Object.assign(this.noSleepVideo.style, hideCss);

document.querySelector('body').append(this.noSleepVideo);

this.noSleepVideo.addEventListener("loadedmetadata", () => { [...]

@z-x where should I put this? I have my NoSleepJS in my custom.js.

paulaegido avatar Jan 18 '22 08:01 paulaegido

Okey this works for me! https://github.com/Uriopass/NoSleep.js

Found it in https://github.com/richtr/NoSleep.js/pull/138

paulaegido avatar Jan 18 '22 08:01 paulaegido

Hey everyone, it seems it stopped working. Is it happening with you too?

brunocarneiro avatar Sep 02 '22 17:09 brunocarneiro

It's not working for me in iOS 15.6.1 with NoSleep 0.12.

dkt01 avatar Sep 02 '22 17:09 dkt01

@brunocarneiro @dkt01 iOS 15.6.1 seems to be working for https://pushu.ps running as a PWA, the source is open if you want to figure it out by yourselves: https://github.com/z-x/pushu.ps/

z-x avatar Sep 09 '22 17:09 z-x

@z-x That site isn't working on my phone either. It still locks the screen after the time I've configured. My app is also an open source PWA ( Sequence Timer - Source ). nosleep.js is activated while the timer is running. On the pushu.ps site, at what point is it supposed to disable sleep?

dkt01 avatar Sep 09 '22 17:09 dkt01

@dkt01 - on the training screen, right after you click 'Start next training'. I've just checked and left the screen open and it does not turn off.

z-x avatar Sep 09 '22 17:09 z-x

@z-x, thanks. I can confirm that that page within pushu.ps does keep my screen awake and unlocked. I'll have to check how my application is misusing the nosleep.js library.

dkt01 avatar Sep 09 '22 19:09 dkt01

    [ Quote pinoceniccola @ CE 2021-09-28 10:56:16 UTC: https://github.com/richtr/NoSleep.js/issues/135#issuecomment-929079462     iOS 15 Safari stays awake only if the video ... is visible on a webpage ] <^>    Unsure what's going on with Safari.     But from my testing on large variety of browsers [1]: all of them could work without having the "<video>" attached to the DOM.     And Chrome (all versions) doesn't seem to require the existence of audio.

[1] Both contemporary and legacy Firefox and Chrome.

MasterInQuestion avatar May 02 '23 00:05 MasterInQuestion

fwiw, i'm using iOS 15.7 and i cannot reproduce this issue. i'm not sure if something changed in later versions of iOS 15, but inserting the video into the document seems not to be necessary anymore...

aroman avatar Jul 24 '23 21:07 aroman