richtr / NoSleep.js

Prevent display sleep and enable wake lock in any Android or iOS web browser.
MIT License
2.23k stars 380 forks source link

Does not work on mobile Firefox #78

Open mqnc opened 5 years ago

mqnc commented 5 years ago

Expected Behavior

I expect that the live demo keeps my screen from going black when I click the button and the background turns green.

Actual Behavior

The screen goes to sleep.

How Do We Reproduce?

I don't know if you can reproduce it, I was a bit surprised that I seem to be the only one with this. It works in chrome, my firefox doesn't turn off when I am on youtube, but surprisingly it also turns the screen off when I am running this site: https://gist.github.com/dmlap/5643609 (I added loop to the video tag and pressed play, still goes to sleep after a while). Maybe it has something todo with the fact that I installed adblock plus there but I deactivated it and it still happened. And also it seems to work on youtube with adblock on.

Jackovic commented 5 years ago

I can confirm that nosleep.js does not work on firefox 68.0 on android 8.1.0.

madeInLagny commented 4 years ago

For what it's worth, there is a webcomponent WakeLock repo here. Disclaimer: I am the author.

jalbam commented 4 years ago

Hello.

I can confirm that it does not work either using Firefox Browser 68.3.0 on Android 9 Pie.

Is there any trick to make it work without using that web component?

Thanks!

louisabraham commented 4 years ago

@madeInLagny I could not make your solution work on the latest version of Firefox android. There must be a way as Firefox does not go to sleep when watching a video.

Has anyone found a solution?

louisabraham commented 4 years ago

Hi, I could fix this by commenting the line

this._addSourceToVideo(this.noSleepVideo, 'webm', webm)
karussell commented 3 years ago

Is this still a problem with the latest version 91.2.0? It seems to work for me on two different Android devices (using Android 10). For an older version I was able to reproduce the problem I think it was 89.0 but not 100% sure.

( Be aware of caching as I initially played around with source modification too and couldn't get it working, but after clearing the caches it worked (using npm pack to create a local distribution nosleep.js-0.12.0.tgz and then npm install nosleep.js-0.12.0.tgz in my app to install it). And so I digged in code in firefox that seems to detect the audio part and decides not to lock the screen if no audio is available. See the code comment here and the comment in this repo containing no sound. See also these firefox tests indicating that this is expected behaviour. But likely they use different code for their mobile browser as it seems to be working now. Not sure. )

marcoangelo commented 2 years ago

Seems to intermittently be an issue on Firefox 99.2.0 on Android.

karussell commented 2 years ago

I have Firefox 99.2.0 (for Android 11) here too and nosleep is working for me. Really strange...

toxicantidote commented 2 years ago

I suspect this could be caused on some devices by the (default?) blocking of auto-play media.

This is what I encountered on Firefox 102.0 on Ubuntu, with the browser informing me that it had blocked auto-play media.

karussell commented 1 year ago

I had again problems with Firefox on Android and I got it working when I always set the "loop" attribute:

this.noSleepVideo.loop = true;

(Currently this is only done if webm is the source)