I am using Javascript on Windows Chrome.
I can successfully set a wakelock and have tested that it does, in fact, prevent my screen from going dark. However, I’m not able to release it. The error I get is
wakeLock.release is not a function
I’ve also tried putting the release code in an async function and using await.
async function set_wakelock() {
wakeLock = await navigator.wakeLock.request('screen');
return wakeLock;
}
var wakeLock = set_wakelock();
// alert(wakeLock); // Correctly shows [Object promise]
try {
wakeLock.release();
wakeLock = null;
} catch (err) {
alert(err); // wakeLock.release is not a function
}
2
Answers
From @derpirscher's comment, I needed to call release() a different way.
The
set_wakelock
is an async method, therefore the immediate return is a promise. Change your code to await for the resultSomething like: