<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>205104</bug_id>
          
          <creation_ts>2019-12-10 23:33:56 -0800</creation_ts>
          <short_desc>Feature Request: Implement the Wake Lock API</short_desc>
          <delta_ts>2023-03-29 19:11:22 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>New Bugs</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Thomas Steiner">tomac</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>clshortfuse</cc>
    
    <cc>eoconnor</cc>
    
    <cc>henry</cc>
    
    <cc>hi</cc>
    
    <cc>igorsantos07</cc>
    
    <cc>jer.noble</cc>
    
    <cc>kieren</cc>
    
    <cc>marcosc</cc>
    
    <cc>mlopez</cc>
    
    <cc>pierre-etienne.lord</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>yordan.kanchelov</cc>
    
    <cc>youennf</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1597533</commentid>
    <comment_count>0</comment_count>
    <who name="Thomas Steiner">tomac</who>
    <bug_when>2019-12-10 23:33:56 -0800</bug_when>
    <thetext>Many websites like recipe sites or tutorial sites have a legit desire to prevent the screen of a device from turning off. Since the user may be busy with performing a task (following the recipe or tutorial steps), in many cases they may not be able or willing to touch the screen to keep it awake, for example, because their hands are dirty with dough or glue. The current workaround for page authors to obtain the desired behavior is to play an invisible video and to loop it infinitely. The Wake Lock API instead provides them with a proper way to programmatically keep the screen awake via a screen wake lock. When the user navigates away from either the tab or multitasks away from their browser completely, the wake lock would be released automatically.

Spec: https://w3c.github.io/wake-lock/

Article: https://web.dev/wakelock/

Demo: https://wake-lock-demo.glitch.me/

Sample code:

```js
// The wake lock sentinel.
let wakeLock = null;

// Function that attempts to request a wake lock.
const requestWakeLock = async () =&gt; {
  try {
    wakeLock = await navigator.wakeLock.request(&apos;screen&apos;);
    wakeLock.addEventListener(&apos;release&apos;, () =&gt; {
      console.log(&apos;Wake Lock was released&apos;);
    });
    console.log(&apos;Wake Lock is active&apos;);
  } catch (err) {
    console.error(`${err.name}, ${err.message}`);
  }
};

// Request a wake lock…
await requestWakeLock();
// …and release it again after 5s.
window.setTimeout(() =&gt; {
  wakeLock.release();
  wakeLock = null;
}, 5000);
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1672879</commentid>
    <comment_count>1</comment_count>
    <who name="Henry">henry</who>
    <bug_when>2020-07-19 06:22:26 -0700</bug_when>
    <thetext>Our web app displays long running photo slideshows and we would love this feature. Like many other sites, we are currently forced to use the &apos;nosleep&apos; library (https://github.com/richtr/NoSleep.js/) to keep the display awake, but a native solution would be preferable, and presumably much better for battery life.

We also use the &apos;nosleep&apos; library when users are performing long running file uploads (e.g. large selections of photos), because whenever the screen goes to sleep the upload dies. (I assume this problem would be better solved by allowing background uploads of some sort, but at the moment &apos;nosleep&apos; seems to be the only option).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1672994</commentid>
    <comment_count>2</comment_count>
    <who name="Thomas Steiner">tomac</who>
    <bug_when>2020-07-20 00:04:05 -0700</bug_when>
    <thetext>(The data upload feature would ideally be solved with Background Fetch: https://wicg.github.io/background-fetch/.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1709398</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2020-11-19 23:52:22 -0800</bug_when>
    <thetext>&lt;rdar://problem/71618179&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1718989</commentid>
    <comment_count>4</comment_count>
    <who name="matías lópez">mlopez</who>
    <bug_when>2021-01-12 07:47:19 -0800</bug_when>
    <thetext>Our platform uses a queue where customers need to wait for to someone answer the call, like a call center. There we need to prevent the screen of a device from turning off or browser go to disconnect from the websocket.

Use a hidden video with a loop is a hack, but is not respectful with battery.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1734729</commentid>
    <comment_count>5</comment_count>
    <who name="Kieren">kieren</who>
    <bug_when>2021-03-01 19:37:38 -0800</bug_when>
    <thetext>Our site uses this for big downloads - The display must be kept on or the requests will fail</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1862156</commentid>
    <comment_count>6</comment_count>
    <who name="yordan kanchelov">yordan.kanchelov</who>
    <bug_when>2022-04-17 13:21:05 -0700</bug_when>
    <thetext>Useful for creating games which don&apos;t require often user interaction</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1896343</commentid>
    <comment_count>7</comment_count>
    <who name="Carlos Lopez">clshortfuse</who>
    <bug_when>2022-09-05 07:50:15 -0700</bug_when>
    <thetext>We need this for fleet management while users use the application while driving. Having to constantly touch the screen is a distraction as well as a safety risk. Right now iOS users extend the system-wide timeout to 30 minutes to bypass this since NoSleep.js workaround have failed in recent updates.

Users can also receive calls with WebRTC while in the application, and it would be useful for the device to stay on, though we&apos;ve already worked around it for the previous reasons.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1945127</commentid>
    <comment_count>8</comment_count>
    <who name="PE Lord">pierre-etienne.lord</who>
    <bug_when>2023-03-29 14:50:51 -0700</bug_when>
    <thetext>Wake lock API has been released (https://github.com/WebKit/WebKit/tree/main/Source/WebCore/Modules/screen-wake-lock) on iOS 16.4

I use NoSleep.js to handle Wake Lock API. NoSleep.js is correctly handled with iOS 16.4.

Here the issue, on iOS 16.4.

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 &quot;Add to home screen&quot;, the Wake Lock API don&apos;t work properly. The Wake Lock API seem to not be able to be acquired.
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

Is it normal?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1945132</commentid>
    <comment_count>9</comment_count>
    <who name="PE Lord">pierre-etienne.lord</who>
    <bug_when>2023-03-29 15:06:22 -0700</bug_when>
    <thetext>More info. 

The previous test page is a PWA.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1945165</commentid>
    <comment_count>10</comment_count>
    <who name="Marcos Caceres">marcosc</who>
    <bug_when>2023-03-29 16:21:58 -0700</bug_when>
    <thetext>Thanks PE Lord! We will take a look.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1945220</commentid>
    <comment_count>11</comment_count>
    <who name="Marcos Caceres">marcosc</who>
    <bug_when>2023-03-29 19:08:16 -0700</bug_when>
    <thetext>Hi again PE Lord!  

tried it on both the Simulator (iPad) and on a couple of iPhones. 

Can confirm that the behavior you described is occurring. 

I&apos;ve filed an internal bug rdar://107397143

I&apos;ll file a separate bug for this as the API itself is implemented:

https://bugs.webkit.org/show_bug.cgi?id=245551</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1945223</commentid>
    <comment_count>12</comment_count>
    <who name="Marcos Caceres">marcosc</who>
    <bug_when>2023-03-29 19:11:22 -0700</bug_when>
    <thetext>Actually, other folks already file it: 
https://bugs.webkit.org/show_bug.cgi?id=254545</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>