tabCapture unavailable in MV3

456 views
Skip to first unread message

Dewde

unread,
Dec 12, 2022, 7:18:00 AM12/12/22
to Chromium Extensions
Our extension uses tabCapture to record the sound of a tab. In MV3, chrome.tabCapture is only available in foreground pages (like popups), which makes the API useless for recording anything in the tab since it can't be kept open.

There's the current hack which opens an extension page in a new Tab while recording, to satisfy both the keep-alive and foreground constraints in the API, but that is less than ideal as it requires tabs pop-in and pop-out of existence without user interaction so it makes for a terrible user experience.

Then there's the new chrome.offscreen API which had this capturing use case as one of its main highlighted use cases in the initial draft request by Devlin Cronin (https://docs.google.com/document/d/1b-I-vXq2h7OFFmus78jZXIWcKilKJLKLeGplnY9wt7k/edit#) Now, the offscreen api is enabled in 109 beta ready to be deployed in production on Jan 10th 2023 and this use case appears ignored. chrome.tabCapture is not exposed to the offscreen document.

So now the question. Is there another way to record the current tab audio that isn't listed above? Not talking about recording the user's mic with getUserMedia and not involving desktopCapture which brings up the nasty popup. The ideal solution would still involve tabCapture. But how?

Dewde

unread,
Dec 12, 2022, 10:39:22 AM12/12/22
to Chromium Extensions

Code example:

  • In the extension service worker:

chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
    chrome.offscreen.hasDocument().then(function(has) {
        if (!has) {
            chrome.offscreen.createDocument({
                justification: 'record audio',
                reasons: [chrome.offscreen.Reason.USER_MEDIA],
                url: chrome.runtime.getURL('record.html'),
            });
        }
    });
});


  • In the offscreen document's JS script:

window.addEventListener("load", () => {
    chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
        console.log(chrome.tabCapture); // **this is always undefined**
    });
});

Simeon Vincent

unread,
Dec 13, 2022, 2:16:09 PM12/13/22
to Chromium Extensions, Dewde
I was about to ask you to create a bug/feature request, but (I think) you already did: https://crbug.com/1400269. Thanks for that!

Simeon - @dotproto
Chrome Extensions DevRel

Dewde

unread,
Dec 14, 2022, 5:20:12 AM12/14/22
to Chromium Extensions, Simeon Vincent
Yes, that was me, thanks
Reply all
Reply to author
Forward
0 new messages