What does HackerNews think of NoSleep.js?

Prevent display sleep and enable wake lock in any Android or iOS web browser.

Language: JavaScript

#41 in Android
#25 in iOS
#110 in JavaScript
According to a 2022 survey [1], the average US adult picks up their phone 352 times per day, or approximately once every 2m43s while they're awake. Inspired by Calm's DoNothingFor2Minutes.com which launched on HN 13 years ago [2], I made this simple webapp to see if my friends and I could go an hour without touching our phones. It is surprisingly difficult. If you're reading HN on your phone, definitely give it a shot.

On browsers that support it (iOS 16.4+, most versions of Android Chrome), it uses the Screen Wake Lock API [3] to keep the page open, and falls back to nosleep.js [4] otherwise. From testing on my iPhone 14 Pro Max running iOS 16.6, battery life only went down 3 or 4 percentage points after an hour with the wake lock.

Made this as a web app as a quick demo to be compatible across all mobile devices. As an app, we can probably save more on battery + not have the screen on. One caveat is that on iOS this will actually increase your Screen Time (although hopefully reduce your other category usage). I currently only track time on page through Google Analytics 4. No other calls are made to a server, although if we actually wanted to verify that you kept the page open vs. javascript/inspector-system clock-fu, we could add a verified mode that pings the server every X minutes. As a PWA, possibly due to an iOS/Mobile Safari quirk, neither wake lock nor nosleep.js appear to work .

[1] https://www.asurion.com/connect/news/tech-usage/ [2] https://news.ycombinator.com/item?id=2124106 [3] https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake... [4] https://github.com/richtr/NoSleep.js

https://github.com/richtr/NoSleep.js/

I wonder if something like this will get "extended" to work for desktop browsers now if this needs to become more popular?

I think something simple like looping an empty audio or video file will suffice. Not that I agree with that from a "hijack the user's browser without their consent" perspective. Just spitballing workarounds.

As Firefox (& I think Safari too) does not support the ScreenWakeLock API are you using NoSleep.js? https://github.com/richtr/NoSleep.js

This library implements a hack and plays a very tiny video in a loop too. This should even work on mobile devices and (according to my personal&tiny tests) is not that inefficient as it sounds :)