Low power mode detection in JavaScript for iOS11?

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

Leave a Comment