1

I am trying to migrate my extension which records screen/tab/window according to the chosen option from manifest V2 to V3. In manifest V2 I was able to use background script as persistent and reach html page objects such as mediaRecorder, navigator. However in manifest V3 background script works as a service worker. So, I have to start the screen record in content-scripts to be able to reach the html objects. When I start chrome.desktopCapture API from the background script, I have to start the screenRecord in one of the tabs (should give a tabid to chrome.desktopCapture.chooseDesktopMedia API call). I cannot start it on the background page and when the page was refreshed or changed to a new URL screen record stops. Is there any workaround for this?

Aiden Pearce
  • 243
  • 2
  • 13
  • I am also looking for some solution to handle the case when page is refresh/changed. Did u find anything? How it was working in v2? – coure2011 Jun 02 '22 at 04:49

2 Answers2

0

I believe the best way to handle updates such as a URL change on a tab is to attach the onUpdated listener to the chrome tabs in the background script.

chrome.tabs.onUpdated.addListener(function(tabId, changes, tab) {
  //Detect Type of Change and Handle Accordingly
});

There are quite a few other events that may be of use that are listed in the chrome documentation Chrome Tabs Events. It's also possible to inject inline JavaScript from the content script so you can access the pages window object directly and attach event listeners there to handle reloads or URL changes. Check this stack overflow post for more information Modify Window Object in Chrome Extension

0

The best workaround is to create a "hidden" tab and start the recording there. This tab is pinned so it's not easy to close.

You can open this tab, ask for the window/screen to record and then send the user back to the previous tab.

You can see a working example here: https://github.com/wireworks-app/chrome-screen-recording