In order to capture output audio stream from a tab in manifest v2 one could use chrome.tabCapture.capture
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.
After trying out a few things, I could finally make tabCapture
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 getMediaStreamId
method of tabCapture
which gives me a streamId. So, I came up with this:
chrome.tabs.query({
active: true,
currentWindow: true
}, (tabs) => {
var tab = tabs[0];
chrome.tabCapture.getMediaStreamId({consumerTabId: tab.id}, (streamId) => {
chrome.tabs.sendMessage(tab.id, { action: 'streamId', streamId: streamId });
});
});
In the above script which is present in popup.js
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 documentation mentions using getUserMedia()
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 DOMException: Error starting tab capture
):
navigator.mediaDevices.getUserMedia({
audio: {
mandatory: {
chromeMediaSource: 'tab',
chromeMediaSourceId: streamId
}
}
})
How can I make tabCapture work in manifest v3, is what I'm trying to find out.
tabCapture.capture
API gets called, I get an error like this:Extension has not been invoked for the current page
which is obvious since the src of the iframe ischrome-extension://<extension_runtime_id>/popup.html
. Could you provide more details around the way you suggested? – Doby