Bug 255363

Summary: Wake Lock permission denied after visibilitychange
Product: WebKit Reporter: siim <webkit>
Component: New BugsAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, cryze92, marcosc, tomac, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 16   
Hardware: Unspecified   
OS: Unspecified   
URL: https://mdn.github.io/dom-examples/screen-wake-lock-api/

Description siim 2023-04-12 13:59:50 PDT
Wake Lock releases when app is not visible. This is expected and is same in all platforms (iOS, Android, Windows)

document.visibilitychange event is used to aquire wake lock after user has started using app again.

In iOS Wake Lock does not work after "visibilitychange" event to re-aquire wake lock if user *goes to home screen*.
If apps are changed *without going to home screen*, then wake lock is re-aquired or stays active.

Error message: NotAllowedError: Permission was denied

Expected result:
There should be permission to re-aquire wake lock after going back to home screen & back to Safari.
There are no permission errors in Android or Windows.


Example:
https://mdn.github.io/dom-examples/screen-wake-lock-api/

Code:
https://github.com/mdn/dom-examples/blob/main/screen-wake-lock-api/script.js
Comment 1 Radar WebKit Bug Importer 2023-04-19 14:00:21 PDT
<rdar://problem/108279602>
Comment 2 Chris Dumez 2023-04-24 09:04:14 PDT
This is because we require transient activation to request the wake lock.
When you're calling request() from the visibility change handler, you don't have transient activation.
Comment 3 Chris Dumez 2023-04-24 10:08:23 PDT
Pull request: https://github.com/WebKit/WebKit/pull/13104
Comment 4 EWS 2023-04-25 10:33:43 PDT
Committed 263382@main (d901ad78bdb6): <https://commits.webkit.org/263382@main>

Reviewed commits have been landed. Closing PR #13104 and removing active labels.