Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Low power mode detection in JavaScript for iOS11?

Is there a JavaScript API to detect low power mode for iOS 11 Safari? I have not found any info on the subject yet.

like image 838
Arnaud Leyder Avatar asked Oct 10 '17 15:10

Arnaud Leyder


1 Answers

A workaround to get this done is:

Put a video (hidden) in the webpage with autoplay 'on', and then detect the 'suspend' event for that video. Whenever it is invoked, 'power mode is on'.

Here is the script:

const videoElement = document.getElementById('ID_of_video');
    videoElement.addEventListener('suspend', () => {
        // suspend invoked
        // show play button
        // iphone is in low power mode
    });

    videoElement.addEventListener('play', () => {
        // video is played
        // remove play button UI
        // iphone is not in low power mode
    });

You can also read the explanation here: Playing video when low power mode is on

like image 158
Shakti Avatar answered Sep 27 '22 23:09

Shakti