Code Monkey home page Code Monkey logo

computer-sleep's Introduction

Prevent sleep inside the browser

This script prevents computer or display sleep with HTML5/JavaScript.

Instructions

Include the sleep.js script in your page, then control the computer's sleep functionality by calling:

sleep.prevent()
sleep.allow()

Limitations

These tables explains the ability of the script to prevent sleep in different scenarios.

macOS

Tested on the following browsers: Chrome 52, Firefox 46 and Safari 9. Firefox and Safari display an audio icon when sleep is being prevented.

                              |Chrome  |Firefox |Safari

----------------------------------|:------:|:------:|:------: Active tab |✔|✔|✘ Active tab; browser in background |✔|✔|✘ Active tab; browser minimised |✔|✘|✘ Background tab |✘|✘|✘

Windows

                              |Chrome  |Firefox |IE 9    |IE 10   |IE 11

----------------------------------|:------:|:------:|:------:|:------:|:------: Active tab |? |? |? |? |? Active tab; browser in background |? |? |? |? |? Active tab; browser minimised |? |? |? |? |? Background tab |? |? |? |? |?

How does it work?

This approach uses a small empty video that is inserted in the page, but off-screen, without sound, but importantly: with an audio track.

This hack in reality controls the video playback which is what makes the browser stay awake.

Troubleshooting

The video files are at these locations; make sure there are no problems accessing them:

https://github.com/ivanmaeder/computer-sleep/raw/master/resources/muted-blank.mp4

https://github.com/ivanmaeder/computer-sleep/raw/master/resources/muted-blank.ogv

Check that your browser supports these video formats.

Check that your browser normally stays awake when playing video.

References

http://stackoverflow.com/questions/10377453/play-infinitely-looping-video-on-load-in-html5

http://stackoverflow.com/questions/26896400/how-to-allow-system-sleep-on-non-fullscreen-html5-video

https://productforums.google.com/forum/#!msg/youtube/C72RHsRYDpo/XE15rBP3gZUJ

computer-sleep's People

Contributors

ivanmaeder avatar jenibarcelos avatar vigneshwerv avatar jaruba avatar zolekm avatar

Watchers

James Cloos avatar

Forkers

tkrevh

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.