Is it possible to wake up the smartphone screen using JS?

  • 0
    When a JS application is running on a mobile device, there are times when some operation takes time. As a result, a progress bar is shown on the screen and the user waits for the process to end.
    However, smart phones have a sleep function and while waiting, the phone can plunge into it and turn off the screen.
    Is it possible to somehow prevent the smartphone from turning off the screen using JS?
    JavaScript Anonymous, Jul 7, 2019

  • 2 Answers
  • 0
    Yes, maybe
    Anonymous

  • 0
    Found a solution that works on Android and uses the API without crutches. I really don't know how it works in older androids and newer ones, as well as in iOS.

    const requestWakeLock = async () => {
    try {
    const wakeLock = await navigator.wakeLock.request('screen');
    } catch (err) {
    // the wake lock request fails - usually system related, such low as battery
    console.log(`${err.name}, ${err.message}`);
    }
    }
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!