James Bachini

Prevent Mobile Browsers From Turning Off

The following code has been published to prevent mobile browsers from turning off and going into sleep mode. This was affecting setTimeout functions as the javascript code in the browser is effectively paused preventing the event loop from processing once sleep mode is activated. I originally looked at nosleep.js but ended up simplifying the code and putting it into a standard module for Vue.js

https://github.com/jamesbachini/StayAwake.js

The code works by looping through a video which tricks the browser in to keeping the screen on.

Usage:

npm install –save stayawake.js

import StayAwake from 'stayawake.js';

StayAwake.init();

StayAwake.enable();

Once enabled a silent, hidden video element will play and the mobile device will stay awake on the page.

StayAwake.js | Prevent Mobile Browsers From Turning Off

Get The Blockchain Sector Newsletter, binge the YouTube channel and connect with me on Twitter

The Blockchain Sector newsletter goes out a few times a month when there is breaking news or interesting developments to discuss. All the content I produce is free, if you’d like to help please share this content on social media.

Thank you.

James Bachini

Disclaimer: Not a financial advisor, not financial advice. The content I create is to document my journey and for educational and entertainment purposes only. It is not under any circumstances investment advice. I am not an investment or trading professional and am learning myself while still making plenty of mistakes along the way. Any code published is experimental and not production ready to be used for financial transactions. Do your own research and do not play with funds you do not want to lose.