10 ms·
Show HN: Prevent your computer sleeping with just a webpage
There's often times I want to prevent a computer/laptop/VM from sleeping and while, yes, there's various Caffeine/Amphetamine apps they're often overkill.
Instead, this small (12Kb) page does the job and only needs a web browser.
It's just a very simple usage of a web api normally used for things like video players: https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake...
- justusthane 5y agoThis looks cool! It would be nice if there was a little more info on the page about how it works and any potential limitations. For example, does the page have to remain in the foreground? And if it does work in the background, will it still work if the browser unloads the page from memory?
- bradleyjkemp 5y agoOh, 100% I need some more docs on the page: it's definitely not foolproof. From my testing, it works even if the window is in the background somewhere but generally it stops working if you switch to a different tab within the same window. You should get a popup though if you do something that causes the page to lose its Wake Lock (which works by listening to the release event: https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API#listening_for_wake_lock_release https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake...)
- karussell 5y agoAs Firefox (& I think Safari too) does not support the ScreenWakeLock API are you using NoSleep.js? https://github.com/richtr/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 :)
- pdxandi 5y agoAre we seeing different sites when you click on the link? Because that is literally all the landing page says. This tiny site uses the Screen Wake Lock API to prevent your device from sleeping. Where this API isn't supported, an empty silent video is played to emulate this behaviour (using NoSleep.js).
- karussell 5y agoI obviously missed the NoSleep.js at the end ... but then I wonder: what is then so special about this website?
- _trampeltier 5y agoThe idea. A lot of company computers have autolock on, just an example.
- spiderice 5y agoIt prevents your computer from sleeping with just a webpage. Why does it need to be more special than that?
- karussell 5y agoI meant that nosleep.page is basically the example page from NoSleep.js hosted on the internet...
- rzzzt 5y agoI think karrussell is talking about the live demo linked from NoSleep.js' project page: https://richtr.github.io/NoSleep.js/example/ https://richtr.github.io/NoSleep.js/example/
- deleted 5y ago[deleted]
- alloai 5y agowith text file saved as .bat file ` @echo off powercfg.exe -x -monitor-timeout-ac 5 powercfg.exe -x -disk-timeout-ac 180 powercfg.exe -x -standby-timeout-ac 180 powercfg.exe -x -hibernate-timeout-ac 999 `
- gabrielsroka 5y agohttps://news.ycombinator.com/formatdoc https://news.ycombinator.com/formatdoc @echo off powercfg.exe -x -monitor-timeout-ac 5 powercfg.exe -x -disk-timeout-ac 180 powercfg.exe -x -standby-timeout-ac 180 powercfg.exe -x -hibernate-timeout-ac 999
- dend 5y agoAlso would recommend this: https://docs.microsoft.com/en-us/windows/powertoys/awake https://docs.microsoft.com/en-us/windows/powertoys/awake Disclaimer: I built the tool.
- gabrielsroka 5y agoThanks for sharing this. I've seen it on some recipe websites recently and was wondering how it worked. I would recommend making the links (eg to the Mozilla page) use a different color or underlined.
- bradleyjkemp 5y agoYup, that's my bad CSS I'm afraid. https://bulma.io https://bulma.io explicitly resets the color of <a> tags inside a hero, so I need to figure out how to stop/override that
- gabrielsroka 5y agoOne or the other or both of these <a href="https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API" style="text-decoration: underline; color: blue;">Screen Wake Lock API</a>
- pkage 5y agoThe "bulma" way would be to add the `has-text-link` class to the <a> tag [0], which has the benefit of matching your styles as well. [0] https://bulma.io/documentation/helpers/color-helpers/ https://bulma.io/documentation/helpers/color-helpers/
- bradleyjkemp 5y agoAh neat, yeah that's exactly what I need, thanks!
- Too 5y agoWhile the use case for recipes stying alive is very useful. Should this responsibility really be delegated to each website? I didn’t even know this was a feature of my browser. Say for example I write a shopping list based on the recipe web page, then go to the supermarket to buy the ingredients, leaving the tab open because I will need the instructions tomorrow for the cooking. Now my computer will be forced on during the rest of day based on the choice of the website owner?! Wtf. What if I leave the tablet open after finishing cooking, Is there any timeout on this thing or will that differ depending on each website? Honestly this feature is really badly thought through. It should be a feature of the OS and not up to random web sites without even asking for permission. Putting my most cynical hat on you could imagine advertisers enabling this on every website so you are more likely to be exposed to their ads.
- velcrovan 5y agoOn macOS just run `caffeinate` from the terminal (or `man caffeinate` for more info on the options). I know OP copped to “various Caffeine/Amphetamine apps” but said they're often “overkill”. In this case I think a system-provided command is less overkill than a web page that either uses a browser API or plays an empty video.
- reidjs 5y agoFor some reason caffeinate doesn't keep my computer awake (newish macbook pro)
- tomstuart 5y agoYou might need `caffeinate -d` to prevent the display from sleeping.
- jen729w 5y agoWhile this does work, I agree with OP here. The man page for caffeinate says that it prevents system sleep and, as far as I can tell, it does not do that on my M1 MBP using Monterey. I do a `caffeinate -d` and then throw my mouse to a hot corner to activate the screen saver.
- Tao331 5y agoI've been using a Zoom meeting of just myself, locked, audio and camera off. Worked like a charm when I needed to discharge a swelling battery.
- jedberg 5y ago> Worked like a charm when I needed to discharge a swelling battery. I think you buried the lede there...
- Tao331 5y agoIt just happens, apparently. Here's a decent rundown: https://www.ifixit.com/Wiki/What_to_do_with_a_swollen_battery#Section_What_happens_when_a_battery_gets_swollen https://www.ifixit.com/Wiki/What_to_do_with_a_swollen_batter...
- taftster 5y agoSo I like this and I'm trying it out, it seemingly works OK. However, the GREEN background is very annoying. I don't need the whole webpage to be green for me to know it's on and working. I can't minimize the browser (firefox) because then it apparently doesn't work. So I'm left with a very big green screen sitting in the corner of my eye. Wondering too the effect of that in terms of screen color burnout (if that's even a thing anymore). I would definitely recommend to tone down the color scheme. Stay away from green. Just go with grey and darker grey or black for your on/off schemes, including inside of the slider button. My use case is that I have the "nosleep" computer on the side of my desk. It catches IM/chat messages (from Teams, etc.) and email (from Outlook). I don't like my primary development machine bothered by these notifications, but I do like having that machine "awake" and alert to chat/email notifications (and I can't (or shouldn't) change the default policies on that machine).
- JadeNB 5y ago> I can't minimize the browser (firefox) because then it apparently doesn't work. Can't you have a separate, tiny window?
- throwanem 5y agoMDN (linked from the page under discussion) says Firefox doesn't expose this API, so I feel like window configuration may be a side issue here.
- ghotli 5y agoI'm confused, kinda. If you want it to be a different color just alter the color? Lots of ways to attack that, host it yourself, change it with chrome dev tools, a bookmarklet that alters the css, user scripts for css overrides like greasemonkey popularized back in the early days of the web. Hope this helps you get the color you'd like :)
- taftster 5y ago"Show HN" is somewhat asking for feedback, is it not? Or am I mistaken in the format? Yes, I can probably self-host something like this, change the color schema in a myriad of ways. But I thought the point of Show HN was to showcase and somewhat solicit feedback from the HN community.
- addsubtract 5y agoMy work resets my Mac sleep timer settings on reboot or update. This is very annoying for maintaining persistent connections to servers, such as my development machine. I wrote a simple Python script to move my mouse pointer by 1-5 pixels at random intervals. Works great, and it always looks like I’m online for prying eyes in Slack.
- ognarb 5y agoThis is a standard functionality in kde plasma in the system tray.
- mxuribe 5y agoSorry, i'm a kde user but not sure how this would be done...? Would you kindly provide details, or a link to a how to?
- seba_dos1 5y agoThere's a checkbox "Manually block sleep and screen locking" and you just check that.
- sundarurfriend 5y agoWhere in the system tray is it? Do we need to click the battery icon or something? Maybe because I'm on a pretty old version (5.18.6), I don't see that checkbox anywhere I looked.
- seba_dos1 5y agoYes, it's in the battery applet. I'm pretty sure it's been there for a long time, but I think it was named differently before ("disable power management" maybe?)
- sundarurfriend 5y agoAh, yes, there's an "Enable Power management" checkbox, by default checked. Thanks.
- mxuribe 5y agoAh yes, of course! How did i ever miss that? I see it now; thanks very much!
- meibo 5y ago
- Hamcha 5y agoThat's pretty handy! I remember a coworker asking me for something similar years ago and me just making something on the fly in C++ (a glorified wrapper over "SetThreadExecutionState"): https://gist.github.com/Hamcha/3a7b3e7518e13d1fba7e https://gist.github.com/Hamcha/3a7b3e7518e13d1fba7e I wonder if that page would even work, his work PC at the time (late 2015) was a dual-socket Pentium III which ran surprisingly OK given the already 15+ years of age, but lacked in software support as apps like Skype and Chrome at one point started shipping binaries that required.. SSE2
- boo-ga-ga 5y agoVery cool, and looks slick!
- singlow 5y agoSo i get annoyed that my computer doesn't go to sleep sometimes because some website is playing a video. Is there a simple way to tell Linux/Gnome/Chrome to ignore videos and go to sleep anyway? I don't watch long videos on this computer so I hate to come back into my office and find my screen never locked because some website played a video i wasn't even watching.
- rsoto 5y agoAdditionally, something to tell me whether my PC will go to sleep or not if left alone. OP's problem happens to me every so often that I need to make sure the PC is indeed going to sleep before heading out.
- monkeybutton 5y agoNothing like packing up your laptop at the end of the day, clicking "sleep" and wondering if it actually will cooperate or if you have open it back up and close random tabs and programs till it does,then waiting for the fan to audibly stop before putting it into a bag!
- shbooms 5y agoit's gotten to the point now where laptop manufacturers tell you not to put sleeping/hibernating laptop into a bag at all due to amount of heat they still generate even while sleeping [0]. Only those that are fully shut down should be placed in a bag (according to them). [0] https://www.dell.com/community/XPS/FAQ-Modern-Standby/td-p/7514448 https://www.dell.com/community/XPS/FAQ-Modern-Standby/td-p/7... Previous HN discussion: https://news.ycombinator.com/item?id=28639952 https://news.ycombinator.com/item?id=28639952
- monkeybutton 5y agoI miss hibernation. Real, write the contents of RAM to disk and shut-off completely type of hibernation.
- mrep 5y agoWhy not just use keep awake? https://chrome.google.com/webstore/detail/keep-awake/bijihlabcfdnabacffofojgmehjdielb?hl=en https://chrome.google.com/webstore/detail/keep-awake/bijihla...
- tailspin2019 5y agoWhy not just use nosleep.page? https://nosleep.page https://nosleep.page
- 40four 5y agoI can think of a few reasons. Looking at that page, the extension seems to only be compatible with Crome OS. A pretty limited audience can use that. Also, I assume this is a pet project of the author. They had a need, and found a way to solve it. They probably had fun, and learned some things along the way. Often, that’s kind of the whole point of a weekend project. Even if there is another established solution, ‘Why not just … some other thing’ isn’t great feedback. Discovering people’s ideas and projects is one of the beautiful things about HN. This is a perfect example. I didn’t even know the Screen Wake Lock API existed, so I learned something new!
- mrep 5y agoIt has worked on every OS that has chrome that I have used and takes like 30 seconds to install. It is easier to click a chrome extension to stay awake than go to a webpage in my opinion. You do you though
- 40four 5y agoHey fair enough. Good to know. But you’re the one who asked ‘why’? I guess you thought that was rhetorical? :) I was just going off the docs which specifically mention Chrome OS and Chrome-books. Personally, I’ve never really had a use case for something like this. My only point is, I still applaud the author’s effort here, and it taught me something new about Web APIs. It’s interesting that you can do that at all with a web page!
- causality0 5y agoInteresting. The various customizations Asus makes with its gaming software on my laptop somehow stops the PowerToys keep-awake utility from functioning as intended. I wonder if this page will do the trick.
- dend 5y agoHey - developer of PowerToys Awake here. Would be happy to investigate. Feel free to open an issue in the GitHub repo (https://github.com/microsoft/PowerToys/issues https://github.com/microsoft/PowerToys/issues) and I will look into it.
- flakiness 5y agoFYI: There is also a Chrome extension doing similar thing: https://chrome.google.com/webstore/detail/keep-awake/bijihlabcfdnabacffofojgmehjdielb https://chrome.google.com/webstore/detail/keep-awake/bijihla...
- viggity 5y agothis is baller. I'd love an option that was like "keep awake for [hours] [minutes]"... or "keep awake until [time]" so that it could look like i was online until say 6:18pm
- dolmen 5y agoDoes it really need to be 12 Kb of obfuscated JS+CSS? That seems huge for the task.
- GlitchMr 5y agoMost of the JavaScript is two empty videos encoded in WebM or MP4, encoded using Base64 to be stored in plain text, and picked depending on what the web browser supports. Considering I doubt that video formats are designed with empty videos in mind, this is probably not too bad. As for why videos are here, they are a fallback in case web browser doesn't provide Screen Wake Lock API (in particular, Safari and Firefox don't).
- bogota 5y agoThis is awesome my work computer has a stupid 5 minute setting until it sleeps that is locked.
- robbedpeter 5y agoDeliberately bypassing that puts your employment at risk. There's a reason you're being forced to log in.
- TobyTheDog123 5y agoIf an employer is going to fire you for running caffeinate while presumably working from home (if you're leaving your laptop alone and unlocked in a public space God help you), maybe it's time to look for a new job :)
- bogota 5y ago
- skykooler 5y agoMaybe if you're slacking off, but if you're working on a project with 10-minute compile times, you can't really use the computer for anything else while it's doing that, and it's quite annoying if it decides to go to sleep in the middle of that because you haven't nudged the mouse recently enough.
- bogota 5y ago
- Too 5y agoAuto sleep and auto screen lock are two very different things.
- oneweekwonder 5y agoplaying something in windows media player also keep it open, or running a powershell script that presses F13 or scroll lock also works.
- eigenvalue 5y agoIf you absolutely want to prevent a Mac from not only going to sleep, but restarting for any reason at all (say, to install important security updates, which are usually forced on the user with no choice), there aren't many good ways. The only thing I've found that really works reliably is to open MS Word, create a new document, add some random characters to it, and then leave without ever saving. Word will prevent the OS from doing anything that would cause you to lose that unsaved document. I'm sure the MS engineers dug deep into the kernel to find something foolproof. It's a bit annoying that Apple doesn't give you a little switch like that which you could toggle to say "don't restart for any reason at all".
- StrangeSound 5y agoYou can also do this in the browser, using the beforeunload event https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event https://developer.mozilla.org/en-US/docs/Web/API/Window/befo...
- vulcan01 5y agoAmphetamine[0] works pretty well for me. They also have an extension (a kext, I think) that gives it more reliability. I don't know how reliable it is without that extension though. [0]: https://apps.apple.com/us/app/amphetamine/id937984704?mt=12 https://apps.apple.com/us/app/amphetamine/id937984704?mt=12
- adamomada 5y agoI've been using the more bare-bones KeepingYouAwake[0] just because I came across Caffeine first and this was suggested as the continuation of that simple utility. The icon makes it obvious whether it is enabled or disabled Edit: I see now that Amphetamine has the option of a similar-looking icon to make it more obvious whether it is enabled or not [0] https://github.com/newmarcel/KeepingYouAwake https://github.com/newmarcel/KeepingYouAwake (My first HN comment, via Orion Browser)
- ecf 5y ago> (My first HN comment, via Orion Browser) Did you manually type that out or is this some “Sent from my iPhone”-esque growth-hacking strategy by the Orion team?
- Minor49er 5y agoUsing this on Firefox for Android causes the application icon and header bar notifications to blink as long as it's enabled. I don't think there's anything the developers could do about that though
- serf 5y agonosleep.js brings firefox from ~3% cpu usage to ~25-30% cpu usage. (it's playing an invisible video) that's a pretty steep cost to pay to simply keep a computer awake because the browser it's using doesn't support a 'stay-awake api'.
- yyahh 5y agoIndeed, how awful.
- pessimizer 5y agoOr rather because the OS you're using doesn't think you're responsible enough to have that kind of control over your own computer. edit: Ah, I misunderstood. This is for your highly locked down work computer.
- catsarebetter 5y agoI just turn zoom on
- hoistbypetard 5y agoCan this web page keep my computer awake without me explicitly giving it permission? I don't really like that, and would like to tell my browser not to allow it.
- 323 5y agoOnly if the web page is visible - page is active tab and browser is visible. It's a useful feature, I use it to prevent a tablet displaying a dashboard turning off the screen due to lack of user action.
- devit 5y ago_Your_ computer, maybe. My workstation will certainly not be prevented from entering sleep by anything a webpage can do.
- achairapart 5y agoSimple and potentially useful but I think that nosleep.js itself uses the Screen Wake Lock API when available, so maybe it's still overkill using it just as a fallback and writing other code on top of it. Besides, it's a shame that iOS still doesn't support this API. The video-hack has too many drawbacks and this feature would be very useful for a certain kind of PWAs.
- robbedpeter 5y agoYeah, let's make it harder for the people who have to clean up after security incidents. The automatic logout policies are there for a reason. Bypassing that means one day, somebody's going to forget and leave an important workstation open for a passersby or malicious actor. If it's that inconvenient, talk with your IT people and make a case for changing it. If you use stuff like this, I hope you get shitcanned.
- A4ET8a8uTh0 5y agoEh, I hear you and I understand the concern, but.. some very corporate jobs have very corporate ITs with their hands tied by policy that makes exceptions truly exceptional. I was going to provide a more recent anecdote, but decided against since it was a little too specific.
- Tao331 5y ago> let's make it harder for the people who have to clean up after security incidents Uh oh, sounds like you might have to actually do your job too!
- robbedpeter 5y agoI'm so glad I left desktop support, but I still empathize. Running a network of hundreds of endpoints means you have to sacrifice laziness. That means you have to log in again after leaving your computer for five minutes. Because if you don't, the jackass who doesn't like you will wait to surf your computer to porn sites, or your coworkers will replace your wallpaper, or someone actually malicious will delete your project files and backups, or run a zero-day. All sorts of shit like that happens. People are fundamentally lazy and stupid, which is why we can't have nice things, line workplaces where you don't have to worry about leaving your computer unlocked. Stuff like this site that makes it easier to embrace the laziness and stupidity just make life worse. How about no browsers? How about limiting network access to a strict whitelist approved by the boss and nothing else? That's the type of shit that happens when you create tools like this. I 100% guarantee this site will be misused and the resulting corporate overcorrection will make hundreds or thousands of people's lives objectively worse.
- Mikeb85 5y agoDunno, been using Caffeine on GNOME for years, works great.
- boxingrock 5y agoi might be pessimistic but this would be a great bait and switch for some cryptomining, lol.
- WalterBright 5y agoI have higher standards for my computer than sleeping with just a webpage.
- motohagiography 5y agoI fully expect mine to f' everything.
- labrador 5y agoI wouldn't let my computer sleep with this because it could get a virus and then before I know it I'm getting asked for money and if I don't pay up my nudes are all over my social media
- farzher 5y agomy windows computer has trouble sleeping. it always randomly wakes up :( quite annoying waste of power
- tnzk 5y agoOn Mac I have aliases below: alias decafe='killall caffeinate' alias cafe='caffeinate -id' which allows me to just '$ cafe' to keep it awake and '$ decafe' to stop it.
- hk__2 5y ago> they're often overkill Can you explain why? I never wants my Mac to sleep except when I close the lid. Amphetamine does the job; it starts at boot and I don’t have to care about it at all.
- capableweb 5y agoI'm not saying web applications are always better (of course they aren't), but they are better for when you either can't/don't want to install any application that gives access to everything on your computer. If a simple navigation to the URL can give you the same thing as installing a application (implicitly giving them access to all your files and more), wouldn't you normally prefer the first? Again, web applications are not better for everything, but they are more safe for the average computer user, as they run in a restricted environment, compared to native applications.
- emptysea 5y agoDoesn’t seem to work on iOS 15.4.1