Skip to content

Prevent display sleep and enable wake lock in any Android or iOS web browser.

License

Notifications You must be signed in to change notification settings

joumorisu/NoSleep.js

 
 

Repository files navigation

NoSleep.js

Prevent display sleep and enable wake lock in all Android and iOS web browsers.

This fork merges many of the community fixes/features into a single place. The following sources were used:

Doxee/NoSleep.js - iOS and Samsung browser fixes MaRossetti/NoSleep.js - feature to specify a title CorentinChauvin/NoSleep.js - fix autoplay DOMException by muting the audio suxscribe/NoSleep.js - fix for Opera in Android

Create a new NoSleep object and then enable or disable it when needed.

To create a new NoSleep object:

var noSleep = new NoSleep("Optional Title");

To enable wake lock:

NOTE: This function call must be wrapped in a user input event handler e.g. a mouse or touch handler

// Enable wake lock.
// (must be wrapped in a user input event handler e.g. a mouse or touch handler)
document.addEventListener('click', function enableNoSleep() {
  document.removeEventListener('click', enableNoSleep, false);
  noSleep.enable();
}, false);

To disable wake lock:

// Disable wake lock at some point in the future.
// (does not need to be wrapped in any user input event handler)
noSleep.disable();

License

MIT. Copyright (c) Rich Tibbett

About

Prevent display sleep and enable wake lock in any Android or iOS web browser.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 80.0%
  • HTML 20.0%