Hi,
Fast forward 8 years. Is there now an option I can use for that?
If not, can you suggest JS code that will work for both iOS and Android?
I tried this (only on Android), but it didn't do the trick:
async function preventScreenTimeout() {
try {
if ('wakeLock' in navigator) {
const wakeLock = await navigator.wakeLock.request('screen');
console.log('Screen Wake Lock is active');
return wakeLock;
}
} catch (err) {
}
}
// To release the wake lock when no longer needed
async function releaseScreenTimeout(wakeLock) {
if (wakeLock) {
await wakeLock.release();
console.log('Screen Wake Lock is released');
}
}
// Example usage
let wakeLock = null;
document.addEventListener('visibilitychange', async () => {
if (document.visibilityState === 'visible') {
wakeLock = await preventScreenTimeout();
} else {
await releaseScreenTimeout(wakeLock);
}
});