Skip to content

Instantly share code, notes, and snippets.

@fhtino
Last active October 4, 2021 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fhtino/963e36294a1490782dc6ab863b2802b6 to your computer and use it in GitHub Desktop.
Save fhtino/963e36294a1490782dc6ab863b2802b6 to your computer and use it in GitHub Desktop.
wakelocktests
<html>
<body>
<div id="infoDiv">...<br /></div>
<script type="text/javascript">
async function DoTest() {
var infoDiv = document.getElementById("infoDiv");
let wakeLock = null;
if ('wakeLock' in navigator) {
infoDiv.innerHTML += "wakeLock supported<br/>";
wakeLock = await navigator.wakeLock.request('screen');
infoDiv.innerHTML += "Active!<br/>";
wakeLock.addEventListener('release', () => {
// the wake lock has been released
infoDiv.innerHTML += 'Wake Lock has been released<br/>';
});
} else {
alert("NOT supported");
}
}
DoTest();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment