Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nosleep.enable() not working on bookmark saved as an application in iphone #161

Open
tazo-taz opened this issue Mar 1, 2024 · 4 comments

Comments

@tazo-taz
Copy link

tazo-taz commented Mar 1, 2024

  • Device Name: iPhone
  • Device Version: 11
  • Browser Name: Safari
  • Browser Version: latest
  • NoSleep.js Version: ^0.12.0

Expected Behavior

The noSleep.enable() function should prevent the screen from sleeping when the web application is launched from a bookmark saved as an application on an iPhone.

Actual Behavior

The noSleep.enable() function does not prevent the screen from sleeping when the web application is launched from a bookmark.

Code

useEffect(() => {
    const noSleep = new NoSleep();
    const documentOnClick = async () => {
      try {
        const a = await noSleep.enable();
        console.debug("no sleep enabled", a);
      } catch (e) {
        console.debug("no sleep prevented");
      }
    };
    document.addEventListener("click", documentOnClick);
    return () => {
      document.removeEventListener("click", documentOnClick);
      noSleep.disable();
    };
  }, []);
@av01d
Copy link

av01d commented May 1, 2024

This is a known bug on iOS: https://bugs.webkit.org/show_bug.cgi?id=254545

@Finesse
Copy link

Finesse commented May 18, 2024

The video method works both in PWA and Safari on iOS 17. But the library doesn't use it because navigator.wakeLock is available. So the library maintainer should either use both navigator.wakeLock and video, or provide an option for us to choose.

As user, you can copy the library code to your website and modify it so both methods are used.

@tazo-taz
Copy link
Author

@Finesse thank you for response, I tried that by break if else if else and it will enter into both condition but still has same problem on PWA any more ideas to fix or did you manage you to fix that

@tazo-taz tazo-taz reopened this Jun 24, 2024
@Finesse
Copy link

Finesse commented Jun 25, 2024

@tazo-taz No, I failed to make it work reliably. I chose to use my app in Safari, because wake lock works more reliably there. Though it requires user action to activate, so I made an infinite loop waiting for any user action, then waiting for a lock release, then waiting for user action and so on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants