title: How can I get audio stream playing in a tab in chrome extension manifest v3
body: <p>In order to capture output audio stream from a tab in manifest v2 one could use <code>chrome.tabCapture.capture</code> API in the background script to get the stream. But, in manifest v3 tabCapture has been moved to foreground and it isn't available in background script. Neither it is available in content scripts.</p>
  <p>After trying out a few things, I could finally make <code>tabCapture</code> work in popup script. However, in my use case popup can't remain open for a long time for the stream to get captured. Instead, I stumbled upon <code>getMediaStreamId</code> method of <code>tabCapture</code> which gives me a streamId. So, I came up with this:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>chrome.tabs.query({
    active: true,
    currentWindow: true
  }, (tabs) =&gt; {
    var tab = tabs[0];
    chrome.tabCapture.getMediaStreamId({consumerTabId: tab.id}, (streamId) =&gt; {
      chrome.tabs.sendMessage(tab.id, { action: 'streamId', streamId: streamId });
    });
  });</code></pre>
  </div>
  </div>
  </p>
  <p>In the above script which is present in <code>popup.js</code> file, after getting the streamId, I send that to the content script. And I'm stuck here on to how to create a stream out of this streamId so that the stream can be captured/recorded. The <a href="https://developer.chrome.com/docs/extensions/reference/tabCapture/#type-GetMediaStreamOptions" rel="nofollow noreferrer">documentation</a> mentions using <code>getUserMedia()</code> but I haven't been lucky there. This is what I could come up with via a little help from other SO questions (but it doesn't work, I get this error <code>DOMException: Error starting tab capture</code>):</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>navigator.mediaDevices.getUserMedia({
    audio: {
      mandatory: {
        chromeMediaSource: 'tab',
        chromeMediaSourceId: streamId
      }
    }
  })</code></pre>
  </div>
  </div>
  </p>
  <p>How can I make tabCapture work in manifest v3, is what I'm trying to find out.</p>