Giter VIP home page Giter VIP logo

nosleep.js's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nosleep.js's Issues

Not work

OS: Android 5.0/Windows Phone 10
Browser: WebView/Edge

Uses tons of CPU

I haven't looked under Android or IOS but under OSX, if I change the UA to android, enabling NoSleep uses tons of CPU by coreaudiod and also the browser. At a wild guess it is playing the media file and this is chewing up CPU.

Perhaps this should be noted in the README, as having a no-sleep solution that doesn't use CPU may be desirable (it is for me).

not working with apple-mobile-web-app-capable

it was not working for the web app i'm designing, so in an attempt to problem solve I cloned the example site, and added :
<meta name="apple-mobile-web-app-capable" content="yes">

I opened the site on device with ios 9, saved it to home screen, opened it, clicked the button, and device went to sleep after standard time. (same behaviour on android)

Bind nosleep state to a cookie for persistency after browser reload?

  • Device Name: Pixel 2
  • Device Version: Android v 9
  • Browser Name: Chrome
  • Browser Version: 70.0.3626.121
  • NoSleep.js Version: v0.9.0

Feature Proposal

Is it (or could it be) possible to store the state of the nosleep in a cookie, so that the setting is persistent even if the user refreshes the browser window?

Feature Use Case

I have a web application where the user is monitoring an output of Wordpress posts, and I have a javascript snippet that is reloading the page every 60 seconds to retrieve any new posts. If the user enables the wake lock, but the page then reloads itself, it turns off the wake lock. I was thinking if the state of the wake lock could be bound to a cookie, then when the page reloads the page the script could check the status of the cookie and decide if the wake lock should be enabled or disabled upon page reload. Is this possible?

Does it drains the batterie?

Starting nosleep js seems to drain my batterie and heats the phone.
Is there any nice tool to test that on android phone? Any hints how to avoid it?

Let package.json point to /dist file

We don't use es6 in our frontend. Therefore our webpack build crashed while trying to build and minify with UglifyJS. This is easily fixed when pointing towards the minified file in your dist folder.

Doesn't work on iOS Chrome 51

Hi!

I did some tests on Android and iOS using Google Chrome 51 on both of them.
On Android works like a charm! But on iOS didn't work.
So I made some tests using Safari and the plugin works!
I did some research but I didn't succeed.
Someone had this problem too?

Thanks!

Not working as expected when NoSleep is defined/initialised and the page was hidden before enabling

Documentation Is:

  • Missing
  • Needed
  • Confusing
  • Not Sure?

Please Explain in Detail…

When you use NoSleep like demonstrated in the Live Demo, where you initialise the NoSleep object via new NoSleep() during page load, and only .enable() it when tapping the button, it won’t activate as expected, if the page was hidden after initial load and before enabling NoSleep.

Here’s how you should be able to reproduce this:

  1. Open the Live Demo in your iOS device’s browser.
  2. Hide the page (switch to another tab, or push the home button, or let the device go to sleep etc.).
  3. Go back to the page in your browser.
  4. Hit the button to enable NoSleep.
  5. After a while, the device will go to sleep.

I experience this on my iOS 12.1 devices. Haven’t tested on Android.

Your Proposal for Changes

Not sure. Maybe this is even intended or preferred behaviour for the demo. But for me it was a bit of a head-scratcher debugging this.
So it might be relevant to amend the example code to avoid this behaviour. Here’s a quick example of what works (this is the JS from the example):

var noSleep = null; // DON’T DEFINE IT HERE
var wakeLockEnabled = false;
var toggleEl = document.querySelector("#toggle");
toggleEl.addEventListener('click', function() {
  if (!wakeLockEnabled) {
    noSleep = new NoSleep(); // DEFINE IT HERE
    noSleep.enable(); // keep the screen on!
    wakeLockEnabled = true;
    toggleEl.value = "Wake Lock is enabled";
    document.body.style.backgroundColor = "green";
  } else {
    noSleep.disable(); // let the screen turn off.
    noSleep = null // DELETING REFERENCE AGAIN
    wakeLockEnabled = false;
    toggleEl.value = "Wake Lock is disabled";
    document.body.style.backgroundColor = "";
  }
}, false);

Alternatively, it might be more suitable to amend the constructor and the enable() method, so that you could use the example code as is (and avoid creating and destroying a NoSleep object on each run) and still avoiding this “issue”.

S8+ refreshing

It work great for older Android OS and somewhat somehow Google Nougat force refresh in 20 mins. I turn off the battery optimization and keep stay on with no luck and still hard refreshed the page automatically after 20 mins. The same page on older Android works great as well as iOS iPhone6 and iPhone7. Please help with S8+ Samsung Chrome browser.

Is the audio track required (it interferes with music)?

I noticed that music from Spotify would get quieter when I opened a page with NoSleep. Even if no music was playing there would always be a hiss in my Bluetooth headphones which means NoSleep was keeping a "wakelock" on them too.

I tried setting mute to true and volume to 0 (#45) but neither worked. Completely removing the audio track did work and the wakelock is still acquired on Chrome on Android. Do other browsers require the audio track?

Here's the video I used:

data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAABpBtZGF0AAAC8wYF///v3EXpvebZSLeWLNgg2SPu73gyNjQgLSBjb3JlIDE0MiByMjQ3OSBkZDc5YTYxIC0gSC4yNjQvTVBFRy00IEFWQyBjb2RlYyAtIENvcHlsZWZ0IDIwMDMtMjAxNCAtIGh0dHA6Ly93d3cudmlkZW9sYW4ub3JnL3gyNjQuaHRtbCAtIG9wdGlvbnM6IGNhYmFjPTEgcmVmPTEgZGVibG9jaz0xOjA6MCBhbmFseXNlPTB4MToweDExMSBtZT1oZXggc3VibWU9MiBwc3k9MSBwc3lfcmQ9MS4wMDowLjAwIG1peGVkX3JlZj0wIG1lX3JhbmdlPTE2IGNocm9tYV9tZT0xIHRyZWxsaXM9MCA4eDhkY3Q9MCBjcW09MCBkZWFkem9uZT0yMSwxMS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AAAQAAC7gAAAABAAA6mAAAAAEAABdwAAAAAQAAAAAAAAABAAALuAAAAAEAAC7gAAAAAQAAF3AAAAABAAAAAAAAABxzdHNjAAAAAAAAAAEAAAABAAAAPAAAAAEAAAEEc3RzegAAAAAAAAAAAAAAPAAAAzQAAAAQAAAADQAAAA0AAAANAAAAEQAAAA8AAAANAAAADQAAABEAAAAPAAAADQAAAA0AAAARAAAADwAAAA0AAAANAAAAEQAAAA8AAAANAAAADQAAABEAAAAPAAAADQAAAA0AAAARAAAADwAAAA0AAAANAAAAEQAAAA8AAAANAAAADQAAABEAAAAPAAAADQAAAA0AAAARAAAADwAAAA0AAAANAAAAEQAAAA8AAAANAAAADQAAABEAAAAPAAAADQAAAA0AAAARAAAADwAAAA0AAAANAAAAEQAAAA8AAAANAAAADQAAABEAAAANAAAADQAAABRzdGNvAAAAAAAAAAEAAAAwAAAAYXVkdGEAAABZbWV0YQAAAAAAAAAhaGRscgAAAAAAAAAAbWRpcmFwcGwAAAAAAAAAAAAAAAAsaWxzdAAAACSpdG9vAAAAHGRhdGEAAAABAAAAAExhdmY1OC4zLjEwMA==

iOS 11.3 WebApp shows blank video

Tried this on iOS 11.3 WebApp (safari under the hood). It "works" in so far as it does not sleep but it pops up a blank square on a black background covering the WebApp which I am guessing is the video. Tried basic things like hidden:true and display:none without success. If I home and return it goes away and the app is still humming along. Used same JS on android WebApp and all good so high degree of confidence that implementation is correct.

Not working on Chrome on Android devices?

It's working on iOS's Safari - but on Android Chrome, it's not working?

Anyone else having this issue?

[Edit]

It works on Android's Firefox.
On Chrome, I get a Javascript-Error.

The console says:

NoSleep.min.js:2 Failed to execute 'play' on 'HTMLMediaElement': API can only be initiated by a user gesture.

and:

NoSleep.min.js:2 Uncaught (in promise) DOMException: play() can only be initiated by a user gesture.

[Edit 2]

I fixed the issue by calling nosleep.noSleepVideo.play(); directly from a click-Event ($('.el').on('click', function(e){ nosleep.noSleepVideo.play(); });

this of course doesn't work on older iOS devices as the code intends to do...

Why not run in desktop browsers?

Hello,
I need to prevent sleep in desktop browsers too. Is there a reason why you did not target that? Do you care for a pull request? Thanks

Doesn't work on Samsung Galaxy s5

Just tried this in a mobile app I built. The code I used is:

noSleep = new NoSleep();

function enableNoSleep() {
  noSleep.enable();
  document.removeEventListener('touchstart', enableNoSleep, false);
}

document.addEventListener('touchstart', enableNoSleep, false);

Did nothing to stop the screen from going to sleep.

Cannot enable noSleep programatically on Android

Thanks for this project! However, I have encountered this issue.

The demo page works fine on Android. And porting the code into my app with the button to enable noSleep also works. However, enabling noSleep via Javascript code that does not originate from a button click does not work. In my case I want the page to start with noSleep enabled.

I went so far as to include the button and use $('#toggle').click() to click it programatically seconds after the page was loaded. But still doesn't work. I printed noSleep.noSleepVideo.paused and found that the video was remaining paused despite the play() execution. I have come to the conclusion that Android inhibits the playing of video without user interaction. I suspect it is related to the same reason that autoplay is disabled:

https://www.aerserv.com/why-does-video-autoplay-on-mobile-devices-not-work/

Does not work in QR code reader

This does not seem to work when you start your webpage from a QR reader like the one from Scan, which I understand is the most popular one for iOS. I tried this e.g. on iPhone 6 with iOS9.2.
The reason seems to be that this mobile QR app uses its own browser, which behaves differently.
Any ideas?

Broken from iOS 10.3

I tested the script yesterday, seemed to be working perfectly. After updating to iOS 10.3 it stopped working. Hope you can find a fix for this.

installing with bower pulls in older version of NoSleep.js?

Hey there,

I did an install using bower and it looks like my local version of NoSleep.js doesn't have the most recent commit. My local version has window.location = window.location; instead of window.location.href = '/';, which results in the library not working on iOS (9.3.1). Could it be that the library version number needs to be incremented?

Great work otherwise!

-Brian

Not compatiable with jQuery handler function

Documentation Is:

  • Missing
  • Needed
  • Confusing
  • [x ] Not Sure?

Please Explain in Detail...

Howdy! I think NoSleep.js doesn't work with with a jQuery click event when a handler reference is used rather than an anonymous function (I hope I got those terms right :-P ).

E.g.

Doesn't work (NoSleep.enable() is in the start_ex_wizard function)
$('#start-link').click(start_ex_wizard);

Does work
$('#start-link').click(function(){
NoSleep.enable(); // Prevent device from sleeping
start_ex_wizard();
});

Your Proposal for Changes

I thought you might like to add a note to the readme.md so others are aware. Alternatively I could document it on StackOverflow.

oldIOS mode incorrectly redirection to root path

When NoSleep detects oldIOS it seems to redirect users to the root path when the timeout hits.
Found this in chrome when using browser to emulate an iPhone 5. Not sure if it affects actual devices.

Dug around a bit and the problem seems to be here

    if (oldIOS) {
      this.disable()
      this.noSleepTimer = window.setInterval(function () {
        window.location.href = '/'
        window.setTimeout(window.stop, 0)
      }, 15000)
    } 

The behaviour is pretty bad. Basically a user is randomly kicked off whatever page theyre on back to the root domain after 15 seconds.

Using Chrome's speech recognition API on Android

I have a wep page that, on the press of a button, enables noSleep and starts recording the microphone using Chrome's speech recognition API.

If I remove all speech recognition code, noSleep works. But if I enable it, the screen eventually locks. Is there a workaround?

Thanks in advance!

<!> Requests cancelled on iOS every 15 seconds when NoSleep.js is enabled (status code 0)

The current implementation of NoSleep.js on iOS makes a redirect request and immediately cancels it, which resets the sleep timeout and therefore prevents the device from sleeping.

However, the window.stop() call actually cancels all pending requests, with a 0 status code. That means your application will "randomly" fail requests, like the connection was lost, but without any log of any kind.

This has been excruciatingly painful to debug (we were a whole team of people trying to diagnose networking issues and XmlHttpRequest constructs for two days), and obviously won't happen while you develop (unless it happens that your request was "in progress" when the stop call was made).

I think this library, even though very useful by itself, can cause serious damage if used unknowingly by misinformed developers.

I suggest these changes:

  • Every time NoSleep.js is enabled using enable(), display a console.warn (fallback to console.log) saying that requests may be cancelled while nosleep is enabled. This will allow developers to see what caused any failed requests following that message.
  • Clearly document on the home page that on iOS, requests will be cancelled every 15 seconds, and that any code running during a no sleep session should not make any HTTP requests (e.g. html presentations and kiosk apps are okay, and nosleep can be disabled when doing new xhr requests)
  • Clearly document on the home page that NoSleep.js cannot be used to keep a device awake while uploading large files.

Sadly, many production applications do not have active logging, and it's very easy to blame the wifi on an iPad (that's what we initially thought), therefore I would not underestimate the gravity of this issue.

Very high CPU usage on desktop Chrome and Brave browsers

  • Device Name: Ubuntu Linux (Dell XPS 13, Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz)
  • Device Version: Ubuntu 16.04.5 LTS ( 4.15.0-42-generic #45~16.04.1-Ubuntu SMP Mon Nov 19 13:02:27 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux)
  • Browser Name: Chrome / Brave
  • Browser Version: Chrome 72.0.3626.81 (Official Build) (64-bit) / Brave 0.58.21 Chromium: 71.0.3578.98 (Official Build)
  • NoSleep.js Version: 0.9.0

Expected Behavior

Do not use excessive CPU

Actual Behavior

The CPU usage goes up to 170-180% (inspecting in Chrome task manager) as soon as the NoSleep enable() function is called and my laptop starts overheating.

I doesn't seem to happen with Firefox and I also tested on Android 9 (Pixel 3) which didn't seem to overheat or use much cpu.

I understand that the primary target of this library is mobile devices, but it still shouldn't behave as described above on desktop.

Code

I used the live example page

How Do We Reproduce?

Go to the live demo page and enable wake lock, press Shift+Esc and see the CPU usage shooting up.

NoSleep.js trigger by auto click does not work

I know it (must be wrapped in a user input event handler e.g. a mouse or touch handler) in order to make the playvideo works.

It works when I use finger manually click the button , but when I use jquery to auto trigger the button then the play video does not work.

And i also find out that, after i use finger click it then I implement timer to click it repeatedly with 5 sec. it works also.

But what I want is the button was hidden in display and then trigger the nosleep at background.

I test in Iphone X.

Anyone know any solution to achieve that?

How much data does this use?

I assume the video that's playing in the background [to keep the browser awake] is of very low quality to keep bandwidth usage low, can you please confirm how much bandwidth is used over the course of 1 minute? Also, is the video just "black" in that there or no images that might be seen by anyone if someone digs into the data? Lastly, how long is the video?

DOMException not catched

Hi,

When running a webpage using NoSleep in the latest Chromium build for Android, I get a

DOMException: Failed to load because no supported source was found.

Which is never caught. I tracked it down to https://github.com/richtr/NoSleep.js/blob/master/src/index.js#L37 where it should be caught on play. I guess actually the enable method might return the play Promise so that user can deal with issue the way they want, no?

For the deeper underneath issue raising this exception, it seems Chromium on Android has no support for MP4 video files (not sure whether Chrome does). Replacing https://github.com/richtr/NoSleep.js/blob/master/src/media.js by a WebM converted video works well!

Maybe NoSleep could provide the source file in both MP4 and WebM and let the browser play the best fitted one?

Thanks!

Does not work.

Hi I tried this on Android Lollipop and Chrome and it does not work...
I tried the example and a custom app using NoSleep.js....
any advice?

Doesn't work with iOS web app

I just wrote a web app that requires the screen to turn on. This library does work nicely while the page is displayed in safari, but when I add it to the home screen and launch it from there, it won't prevent the device from entering sleep mode.

Webm file is invalid for playback in Firefox for Android

Hi,

Since the recent addition of webm file, NoSleep is no longer working on my Android phone with Firefox. Tested and confirmed with the examples.

Expected Behavior

Webm video should play back and NoSleep should work.

Actual Behavior

Webm video is considered somehow invalid by Firefox for Android and not played back. MP4 file is working fine. If I use a WebM-encoded version of the MP4 file (encoding done with default "webm" profile in VLC), it works.

It seems to be working fine in Chrome/Chromium for Android though.

Best,

Does the iOS file dialog interfere with NoSleep?

I'm trying to implement this to prevent the screen locking while my users wait for files to upload.

I can't get it to work consistently in my web app yet the demo page works perfectly on the same test device (iPhone X).

Could it be something to do with the fact that my web app is accessing the users' photos and videos after NoSleep is enabled? I'm enabling on the 'Choose File' button press then disabling when the upload is complete.

I should also maybe mention I"m using the Uploadcare widget for picking files.

Any ideas? 🤔

HTML5 canvas support?

In addition to playing videos, while playing HTML5 games, I also want to prevent mobile phone screen sleep.

Main entry point use CommonJS and ES module entry point with the module field

HI i'm use NoSleep.js with CRA

When CRA build it throw following error
https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify

I'm solve this build warnning now import dist/NoSleep.js file

import NoSleep from 'nosleep.js/dist/NoSleep';

So I think main entry point use CommonJS and ES module entry point with the module field

package.json
{
...
-  "main": "src/index.js",
+  "main": "dist/NoSleep.js",
+  "module": "src/index.js",
...
}

[question] about the HTML5-VIDEO-tag

I was wondering if placing a HTML5 VIDEO tag in my HTML-page will have the save effect as embedding 'nosleep.js', I've encoded few 'blank videos' with FFMPEG and I was going to test it..
I was just curious on how it works, and why there is a jump in playing time on MP4 and for WEBM the 'loop' attribute is enough..

would this thing work in the same manner? (after manually clicking play):

<video autoplay="true" crossorigin="anonymous" loop="true" muted="true" preload="auto" playsinline="true" poster="poster.jpg">
  <source src="video_h264.mp4"    type='video/mp4;  codecs="avc1.42001E"'  />
  <source src="video_vp9.webm"    type='video/webm; codecs="vp9.0"'        />
  <source src="video_vp8.webm"    type='video/webm; codecs="vp8.0"'        />
  <source src="video_theora.ogv"  type='video/ogg;  codecs="theora"'       />
  <source src="video_mpeg4.avi"   type='video/avi;  codecs="mpeg4"'        />
  <p>No Support For HTML5's-video.</p>
</video>

New Safari solution

NoSleep with the latest safari is redirecting to root of the website when the screen is off.

Problem is the window.location.href = "/" in the enable() function code for iOS

Solution appears to be in the code used for the demo, which instead uses window.location = window.location

https://richtr.github.io/NoSleep.js/NoSleep.js

For iOS use: window.location.href = window.location.href

Currently for iOS the location reload employs window.location.href = '/'. But the problem is that if the phone is turned off, then the page is changed to / when it reawakened.

Alternatively if reload employs window.location.href = window.location.href, the page will remain unchanged after phone sleep. (Although it will be reloaded.) This still works to keep the phone awake.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.