Skip to content

Commit 79c0c19

Browse files
committed
Implement fixes from richtr#138
1 parent 1d15cc8 commit 79c0c19

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

dist/NoSleep.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ var oldIOS = function oldIOS() {
117117
return typeof navigator !== "undefined" && parseFloat(("" + (/CPU.*OS ([0-9_]{3,4})[0-9_]{0,1}|(CPU like).*AppleWebKit.*Mobile/i.exec(navigator.userAgent) || [0, ""])[1]).replace("undefined", "3_2").replace("_", ".").replace("_", "")) < 10 && !window.MSStream;
118118
};
119119

120-
// Detect native Wake Lock API support
120+
// Detect native Wake Lock API support (Samsung Browser supports it but cannot use it)
121121
var nativeWakeLock = function nativeWakeLock() {
122-
return "wakeLock" in navigator;
122+
return "wakeLock" in navigator && window.navigator.userAgent.indexOf("Samsung") === -1;
123123
};
124124

125125
var NoSleep = function () {
@@ -150,6 +150,14 @@ var NoSleep = function () {
150150
this._addSourceToVideo(this.noSleepVideo, "webm", webm);
151151
this._addSourceToVideo(this.noSleepVideo, "mp4", mp4);
152152

153+
// For iOS >15 video needs to be on the document to work as a wake lock
154+
Object.assign(this.noSleepVideo.style, {
155+
position: "absolute",
156+
left: "-100%",
157+
top: "-100%"
158+
});
159+
document.querySelector("body").append(this.noSleepVideo);
160+
153161
this.noSleepVideo.addEventListener("loadedmetadata", function () {
154162
if (_this.noSleepVideo.duration <= 1) {
155163
// webm source

0 commit comments

Comments
 (0)