Prevent Android chrome from going idle / auto-locking / sleeping phone?

前端 未结 3 1238
梦毁少年i
梦毁少年i 2021-01-18 08:33

I need to do on the website some feature to disabled idle/sleep phone. Does anyone try make this on phone with android ? is it in any way possible?

3条回答
  •  悲哀的现实
    2021-01-18 09:11

    JavaScript in Chrome on Android (7.0) indeed shuts down after 5 min in sleep mode. Aaargh!

    To prevent that, we need e.g. an audio object:

    
    

    and play it at regular intervals:

    function playDummyAudio() { dummyAudio.play(); }    
    $(function() {
       var dummyAudio = document.querySelector('#dummyAudio');
       window.setInterval(playDummyAudio, 60 * 1000);
    }
    

    Note that the Audio object has to be "unlocked" in a user gesture callback. This can be accomplished e.g. by having a grey CSS overlay with a big fat dummy "Start" button, whose onClick() callback only hides the overlay and calls dummyAudio.load().

提交回复
热议问题