<?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>281566</bug_id>
          
          <creation_ts>2024-10-16 02:23:08 -0700</creation_ts>
          <short_desc>AudioContext.resume() never resolves if browser is suspended to background</short_desc>
          <delta_ts>2024-11-12 18:29:20 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Web Audio</component>
          <version>Safari 17</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=276016</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=276687</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=263627</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=274954</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=240646</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=206695</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=202846</see_also>
          <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="Luka Erkapic">erkapic.luka.os</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>cdumez</cc>
    
    <cc>jer.noble</cc>
    
    <cc>karlcow</cc>
    
    <cc>mattwindwer</cc>
    
    <cc>self</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2068348</commentid>
    <comment_count>0</comment_count>
    <who name="Luka Erkapic">erkapic.luka.os</who>
    <bug_when>2024-10-16 02:23:08 -0700</bug_when>
    <thetext>AudioContext.resolve() is never resolved if browser is suspended to background.

Use case scenario is that we listen for document.addEventListener(&quot;visibilitychanged&quot;) and try to resume AudioContext when document is visible.
However `AudioContext.resolve()` is never resumed or resolved/rejected.

Typically this will happen if:
- we play sound
- go to background
- go back to browser and try to resume context after visibility changed event
- no sound is played as resume is never resolved

This is not an issue when scrolling between tabs, only if browser is suspended to background.

Can be tested here https://codepen.io/Luka-Erkapic/pen/vYoxvPG
- simply play sound
- go to background
- go back to browser
- no sound is playing even if &quot;AudioContext.resume()&quot; is called.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2068349</commentid>
    <comment_count>1</comment_count>
    <who name="Luka Erkapic">erkapic.luka.os</who>
    <bug_when>2024-10-16 02:37:07 -0700</bug_when>
    <thetext>I could reproduce this on iOS version 17.6.1</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2070016</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-10-23 02:24:29 -0700</bug_when>
    <thetext>&lt;rdar://problem/138466380&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2073107</commentid>
    <comment_count>3</comment_count>
    <who name="">self</who>
    <bug_when>2024-11-05 22:29:11 -0800</bug_when>
    <thetext>This bug has been eating me alive for months.
I thought I was crazy or it was a skill issue,
but no, its just broken :(</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2073110</commentid>
    <comment_count>4</comment_count>
    <who name="">self</who>
    <bug_when>2024-11-05 23:03:10 -0800</bug_when>
    <thetext>Same bug has been reported here 7 other times, its been 5 years 💀:
https://bugs.webkit.org/show_bug.cgi?id=276016
https://bugs.webkit.org/show_bug.cgi?id=276687
https://bugs.webkit.org/show_bug.cgi?id=263627
https://bugs.webkit.org/show_bug.cgi?id=274954
https://bugs.webkit.org/show_bug.cgi?id=240646
https://bugs.webkit.org/show_bug.cgi?id=206695
https://bugs.webkit.org/show_bug.cgi?id=202846</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2074708</commentid>
    <comment_count>5</comment_count>
    <who name="">self</who>
    <bug_when>2024-11-12 18:27:08 -0800</bug_when>
    <thetext>very scuffed workaround if anyone needs it,
but yeah, this is borked.

```js
audioContext = new AudioContext();
const abortController = new AbortController();

function addListeners(){
    document.addEventListener(&quot;pointerdown&quot;, resume, {signal: destructor.signal});
    document.addEventListener(&quot;keydown&quot;, resume, {signal: destructor.signal});
};
addListeners();

function resume(){
    if(audioContext.state !== &quot;running&quot;){
        abortController.abort();
        audioContext.suspend(); /* Needs to be called before resume */
        setTimeout(() =&gt; {audioContext.resume()}, 200);
    };
};

document.addEventListener(&apos;visibilitychange&apos;, () =&gt; {
    if(document.hidden){
        abortController.abort();
        audioContext.suspend();
    }
    else{resume()};
});</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2074711</commentid>
    <comment_count>6</comment_count>
    <who name="">self</who>
    <bug_when>2024-11-12 18:29:20 -0800</bug_when>
    <thetext>oops forgot to rename some stuff

audioContext = new AudioContext();
const abortController = new AbortController();

function addListeners(){
    document.addEventListener(&quot;pointerdown&quot;, resume, {signal: abortController.signal});
    document.addEventListener(&quot;keydown&quot;, resume, {signal: abortController.signal});
};
addListeners();

function resume(){
    if(audioContext.state !== &quot;running&quot;){
        abortController.abort();
        audioContext.suspend(); /* Needs to be called before resume */
        setTimeout(() =&gt; {audioContext.resume()}, 200);
    };
};

document.addEventListener(&apos;visibilitychange&apos;, () =&gt; {
    if(document.hidden){
        abortController.abort();
        audioContext.suspend();
    }
    else{resume()};
});</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>