richtr / NoSleep.js

Prevent display sleep and enable wake lock in any Android or iOS web browser.
MIT License
2.19k stars 379 forks source link

Wakelock API iOS 16.4 browser mode vs Add to home screen mode #156

Open pelord opened 1 year ago

pelord commented 1 year ago

Expected Behavior

NoSleep is suposed to handle iOS 16.4

Actual Behavior

When using the Wake Lock API, on Safari, in a browser mode, the Wake Lock API work properly. On the same website, opened after have done "Add to home screen", the Wake Lock API don't work properly. The Wake Lock API seem to not be able to be acquired.

An issue has been reported to WebKit https://bugs.webkit.org/show_bug.cgi?id=205104

How Do We Reproduce?

Here the test page: https://pelord.github.io/wakeLockApiAddHomeScreen/

To test the Wake Lock API, you have to toggle the ZZZ button.

Unchecked ZZZ = Wake Lock API released Checked ZZZ = Wake Lock API acquired

I'll try do propose a PR soon.

z-x commented 1 year ago

When I saw Safari upgrading to support Wakelock I was like 'AT LAST'. And then I saw it doesn't work in PWA at all, and on top of that it breaks the current NoSleep workaround so my app just broke for people overnight. That is just stupid. Thanks for letting the Safari team know!

pelord commented 1 year ago

Here my local fix.

image

z-x commented 1 year ago

@pelord - this will disable the Wake Lock for both - in-browser and apps pinned to home screen, right? You could test against this as well to target just the PWAs:

window.matchMedia('(display-mode: standalone)').matches
pelord commented 1 year ago

You're right. In my specific use case, my users are strongly encouraged to "Install" the app... but, I will try it soon. Thanks for the hint..

Mrc527 commented 9 months ago

I’m having the same issue, in-browser app works but as soon as I install it on my device, the wake lock is not acquired anymore.

Any chance to incorporate the fix a new revision of the library? I know it’s not nice but if the native functionality is broken in PWA mode, we cannot rely on that.

pelord commented 9 months ago

Still not fixed in iOS 17 https://bugs.webkit.org/show_bug.cgi?id=254545

Mrc527 commented 9 months ago

Anything we can do to overcome the issue at least temporarily?

jebabin commented 9 months ago

The fix provided by @pelord works perfectly, so I would suggest to use it. When IOS will have a fix, then we will need to chance the regex to only match the bugged versions

Mrc527 commented 9 months ago

The fix provided by @pelord works perfectly, so I would suggest to use it. When IOS will have a fix, then we will need to chance the regex to only match the bugged versions

OK but that’s requiring a change in the library, isn’t it? I mean, I’ve to insert nosleep as code instead of installing it via yarn and apply this change on the nosleep code right?

robertvanlienden commented 9 months ago

I think https://github.com/Uriopass/NoSleep.js is the most active/working for for this repo.

Maybe we can submit a PR to that repo to add the fix of pelord. It seems that the owner of this repository never looks back on it :cry: .

For Android this repository works fine on most browsers, but iOS seems to be a pain in the :cake: ...

zakj commented 8 months ago

I forked this repository and included the above fix (with @z-x's modification): https://github.com/zakj/no-sleep

It's published on npm as @zakj/no-sleep. I couldn't resist some refactoring so buyer beware, but it's working for me.

Mrc527 commented 8 months ago

Well done, I’m going to switch to your library immediately.I see you even implemented a check to use the old-fashioned way only in the installed PWA, so on a regular browser it should use the native api right?On 13 Oct 2023, at 07:41, Zak Johnson @.***> wrote: I forked this repository and included the above fix (with @z-x's modification): https://github.com/zakj/no-sleep It's published on npm as @zakj/no-sleep. I couldn't resist some refactoring so buyer beware, but it's working for me.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

HenriqueMatias commented 3 weeks ago

I forked this repository and included the above fix (with @z-x's modification): https://github.com/zakj/no-sleep

It's published on npm as @zakj/no-sleep. I couldn't resist some refactoring so buyer beware, but it's working for me.

Hey thanks for the improvement in the lib. So this should fix the issue with browsers in IOs 16 ? or I misunderstood?

zakj commented 3 weeks ago

Yep, it's working for me.