getDisplayMedia, encode it with MediaRecorder, and save the result with the downloads API.
Choose a capture API
getDisplayMedia needs no manifest permission. The browser shows a source picker, and that prompt is the consent. tabCapture skips the picker but requires the tabCapture permission and a prior user gesture on the extension, such as an action click.
Manifest
Addoffscreen to the permissions only when you record from an offscreen document.
manifest.json
Open a recorder page
A popup closes when it loses focus, which kills its recording. Host the recorder on a dedicated page instead. Putrecorder.html and recorder.js in the pages/ special folder, and Extension.js compiles them as entrypoints.
background.js
Record with getDisplayMedia
getDisplayMedia requires a user gesture, so call it from a click handler, never on page load.
pages/recorder.js
Capture the active tab instead
WithtabCapture, the background hands a stream id to your page, and the page turns it into a stream. No picker appears.
pages/recorder.js
MediaRecorder flow as above.
Record in the background
To keep recording without any visible extension page, Chrome offers offscreen documents. Create one withchrome.offscreen.createDocument and the USER_MEDIA reason, then run the capture code there. This needs the offscreen permission and stays Chromium-only.
Run it
Firefox notes
getDisplayMediaandMediaRecorderwork in Firefox extension pages, so the main recipe is portable.- Firefox does not support
tabCaptureor offscreen documents. - Use browser-specific manifest fields to keep the
tabCapturepermission out of the Firefox build.
Start from a template
Thespecial-folders-pages template shows the pages/ layout that hosts the recorder page.
Best practices
- Stop every track when recording ends, so the browser removes the sharing indicator.
- Choose the capture API per browser:
getDisplayMediaeverywhere,tabCapturefor Chromium tab-only flows. - Keep
saveAs: true, so users choose where recordings go. - Chunk long recordings with
recorder.start(timeslice)to bound memory use.
Next steps
- Manage the saved files in Manage downloads.
- Review the special folders contract for
pages/entries. - Audit capture permissions with the Security checklist.

