Screen Capture and Sharing: getDisplayMedia, Cropping, and Extension APIs
How web and extension APIs capture tabs and screens, crop shared video, control privacy, focus, and remote scroll.
This page summarises Chrome for Developers documentation on capturing and sharing tabs, windows, and screens: the Screen Capture API (getDisplayMedia()), privacy-oriented picker options, companion APIs (Capture Handle, Conditional Focus, Region Capture, Element Capture, Captured Surface Control), and extension surfaces such as browser.tabCapture and browser.desktopCapture. Most of these capabilities are Chromium desktop features; Firefox and Safari generally do not support the newer web-platform pieces described here.
getDisplayMedia(): how to start screen or tab sharing
Section titled “getDisplayMedia(): how to start screen or tab sharing”getDisplayMedia() is the standard entry point for a web app to ask the user to share a tab, window, or entire screen. The browser shows a picker; the chosen surface becomes a MediaStream you can preview, send over WebRTC, or pass to MediaRecorder.
For screen recording, call getDisplayMedia(), which triggers the dialog box shown below. This provides the user with the ability to select which tab, window or screen they wish to share and provides a clear indication that recording is taking place.
— Google Chrome, Audio recording and screen capture
A minimal request for both audio and video:
const stream = await navigator.mediaDevices.getDisplayMedia({ audio: true, video: true });If you call getDisplayMedia() from an extension content script, capture stops when the user navigates away. For recording across navigations, Chrome recommends an offscreen document with reason DISPLAY_MEDIA (for display capture) or the tab-capture patterns below.
| Goal | Typical API | User sees picker? |
|---|---|---|
| Standard web app screen share | navigator.mediaDevices.getDisplayMedia() |
Yes |
| Extension captures active tab after toolbar click | browser.tabCapture |
Often no extra picker when user already invoked the extension |
| Extension picks screen/window/tab via extension UI | browser.desktopCapture.chooseDesktopMedia() |
Yes (desktop picker) |
| Single full-page snapshot | browser.tabs.captureVisibleTab() |
No stream; PNG/JPEG data URL |
Privacy-preserving getDisplayMedia() options: avoid oversharing
Section titled “Privacy-preserving getDisplayMedia() options: avoid oversharing”Chrome added options on getDisplayMedia() so conferencing and collaboration apps can steer users away from accidental full-screen or self-tab shares. Google groups these under Privacy-preserving screen sharing controls.
Here’s a list of controls you can use for privacy-preserving screen sharing:
— Google Chrome, Privacy-preserving screen sharing controls
displaySurface and monitorTypeSurfaces: limit what the picker offers
Section titled “displaySurface and monitorTypeSurfaces: limit what the picker offers”video: { displaySurface: "browser" | "window" | "monitor" }pre-selects the Tabs, Window, or Entire Screen pane (it does not pre-select a specific tab or window).monitorTypeSurfaces: "exclude"removes the Entire Screen pane—useful when whole-monitor capture is too risky for enterprise users. This is mutually exclusive withdisplaySurface: "monitor".
selfBrowserSurface and preferCurrentTab: self-capture vs hall of mirrors
Section titled “selfBrowserSurface and preferCurrentTab: self-capture vs hall of mirrors”Video calls often break when users share the same tab that shows the call preview (“hall of mirrors”). Set selfBrowserSurface: "exclude" to hide the current tab from the list. That conflicts with preferCurrentTab: true, which nudges users toward sharing the current tab—needed for Region Capture and Element Capture workflows.
surfaceSwitching: “Share this tab instead”
Section titled “surfaceSwitching: “Share this tab instead””With surfaceSwitching: "include", Chrome can expose UI that lets the user switch which tab is shared mid-session without your app orchestrating a new capture.
systemAudio: tab audio without loopback
Section titled “systemAudio: tab audio without loopback”For conferences, tab/window audio is often desirable; system audio from an entire screen can echo remote participants. systemAudio: "exclude" limits audio offers to tab/window capture, not full screen.
Capture Handle: identify which tab is being shared
Section titled “Capture Handle: identify which tab is being shared”Capture Handle lets a captured page opt in to exposing a string handle (and optionally its origin) to the capturing app, so the capturer knows what was shared—for example, to enable slide controls in the meeting UI or detect self-capture.
Capture Handle consists of two complementary parts:
Captured web apps can opt-in to exposing certain information to some origins with navigator.mediaDevices.setCaptureHandleConfig(). Capturing web apps can then read that information with getCaptureHandle() on MediaStreamTrack objects.
— Google Chrome, Better tab sharing with Capture Handle
On the captured page (HTTPS top-level frame only):
navigator.mediaDevices.setCaptureHandleConfig({ handle: crypto.randomUUID(), exposeOrigin: true, permittedOrigins: ['*'], // or specific origins});On the capturing side, after getDisplayMedia():
const [videoTrack] = stream.getVideoTracks();const captureHandle = videoTrack.getCaptureHandle();Listen for capturehandlechange when the captured app updates its config or navigates. Capture Handle returns null if nothing was exposed or your origin is not in permittedOrigins.
Conditional Focus: stay in the meeting or focus the shared tab
Section titled “Conditional Focus: stay in the meeting or focus the shared tab”When capture starts, the browser must decide whether to focus the shared tab/window or keep focus on the capturing page. Conditional Focus uses CaptureController and setFocusBehavior().
Instantiate a CaptureController and pass it to getDisplayMedia(). By calling setFocusBehavior() immediately after the getDiplayMedia() returned promise resolves, you can control whether the captured tab or window will be focused or not. This can only be done if the user shared a tab or a window.
— Google Chrome, Better screen sharing with Conditional Focus
Values include focus-captured-surface and focus-capturing-application. You may call setFocusBehavior() multiple times before getDisplayMedia() resolves, or once immediately after the promise resolves (same microtask turn). Later calls throw or no-op; setFocusBehavior() does not apply when the user shared a monitor, only tab or window.
Combine track.getSettings().displaySurface and track.getCaptureHandle().origin to mirror Google’s conferencing example: keep focus in the meeting for trusted presentation origins, focus the editor otherwise.
Region Capture vs Element Capture: crop what remote viewers see
Section titled “Region Capture vs Element Capture: crop what remote viewers see”Both APIs refine a tab-capture video track after getDisplayMedia({ preferCurrentTab: true }), but they differ in what pixels they keep.
Region Capture: bounding-box crop (cropTo)
Section titled “Region Capture: bounding-box crop (cropTo)”Region Capture crops to an element’s bounding box. Layout changes on the host page update the crop automatically—more reliable than per-frame canvas cropping.
- Host:
const cropTarget = await CropTarget.fromElement(mainContentArea) - Pass
cropTargetto the embed (for example viapostMessage) - Capturer:
await track.cropTo(cropTarget)on the tab-capture track;await track.cropTo(null)to stop
For Region Capture, only the position and size of the target matter, not the z-index. Pixels occluding the target will be captured. Occluded parts of the target will not be captured.
— Google Chrome, Better tab sharing with Region Capture
cropTo() can fail if the source element was removed, the track has clones, or the track is not a tab-capture video track. Check self-capture with Capture Handle before cropping. Region Capture does not add local security: another document that receives the full track could call cropTo(null) and see the whole tab again.
Element Capture: DOM subtree only (restrictTo)
Section titled “Element Capture: DOM subtree only (restrictTo)”Element Capture restricts frames to a target element and its direct DOM descendants, dropping occluding UI (menus, notifications) outside that subtree.
const restrictionTarget = await RestrictionTarget.fromElement(captureTarget);await track.restrictTo(restrictionTarget);For now, Element Capture is intended for self-capture; verify with Capture Handle. Targets must form a coherent rectangular stacking context—isolation: isolate is a common fix. Ineligible targets (for example display: none) stop producing frames until eligible again. Partial transparency becomes opaque in capture, which can shift colors or reveal unexpected black regions.
| Mechanism | Occluders over target | Occluded parts of target |
|---|---|---|
| Region Capture | Included | Excluded |
| Element Capture | Excluded | Included (within subtree) |
Captured Surface Control: scroll and zoom a shared tab from the meeting UI
Section titled “Captured Surface Control: scroll and zoom a shared tab from the meeting UI”Captured Surface Control addresses a UX problem: presenters leave the call tab to scroll shared content. With a CaptureController tied to getDisplayMedia(), if displaySurface is browser, you can forward wheel events from a preview <video> to the captured tab:
await controller.forwardWheel(previewTile); // or null to stopZoom APIs on the same controller adjust the captured tab’s zoom when the user grants the relevant permission. Scope is browser tabs only (not windows or monitors). Feature-detect CaptureController.prototype.forwardWheel.
browser.tabCapture and related extension APIs
Section titled “browser.tabCapture and related extension APIs”Extension capture is documented in Audio recording and screen capture and the reference pages for browser.tabCapture, browser.desktopCapture, and browser.tabs.captureVisibleTab.
The browser.tabCapture API lets you access a MediaStream containing video and audio of the current tab. It can only be called after the user invokes an extension, such as by clicking the extension’s action button.
— Google Chrome, browser.tabCapture
Tab audio routing
Section titled “Tab audio routing”Tab capture stops playing tab audio to the user (similar to suppressLocalAudioPlayback). Route audio back through an AudioContext:
const output = new AudioContext();const source = output.createMediaStreamSource(stream);source.connect(output.destination);getMediaStreamId() and offscreen recording (Chrome 116+)
Section titled “getMediaStreamId() and offscreen recording (Chrome 116+)”For background recording across navigations, obtain a stream ID in the service worker after a user gesture, then consume it in an offscreen document:
const streamId = await browser.tabCapture.getMediaStreamId({ targetTabId: tab.id });Pass the ID to offscreen code and open the stream with getUserMedia constraints using chromeMediaSource: "tab" and chromeMediaSourceId. From Chrome 116, when consumerTabId is omitted, the ID may be used in any same-origin frame in the same render process as the caller—enabling service worker → offscreen flows. Create the offscreen document with reasons such as USER_MEDIA or DISPLAY_MEDIA as appropriate.
browser.tabCapture.capture({ audio: true }) works in a popup for audio only; video capture closes the popup when focus shifts.
desktopCapture and static snapshots
Section titled “desktopCapture and static snapshots”browser.desktopCapture.chooseDesktopMedia() shows Chrome’s desktop picker and returns a short-lived streamId for getUserMedia(). Respect options.canRequestAudioTrack before requesting audio.
browser.tabs.captureVisibleTab() returns an image of the visible tab (not a live stream) and can capture restricted chrome:// or extension pages when activeTab applies.
pageCapture (MHTML)
Section titled “pageCapture (MHTML)”browser.pageCapture saves a tab as MHTML (page plus resources). MHTML loads only from the file system in the main frame, for security.
Recording the stream
Section titled “Recording the stream”Google points extension authors to the MediaRecorder API for persisting captured MediaStream data. Low-level frame pipelines may also use Insertable streams for MediaStreamTrack or WebCodecs when you need per-frame processing.
Policy note for installed web apps
Section titled “Policy note for installed web apps”Chrome IWA developer policy lists unrestricted screen recording as a restricted capability: it must be core to the product (meetings, tutorials), with clear user awareness before use.
Common mistakes
Section titled “Common mistakes”- Sharing the conference tab without
selfBrowserSurface: "exclude"or Capture Handle–based self-capture mitigation. - Using
preferCurrentTab: truetogether withselfBrowserSurface: "exclude"(mutually exclusive). - Calling
setFocusBehavior()afterawait getDisplayMedia()without doing it in the same turn as the resolved promise. - Assuming Region Capture hides overlays; use Element Capture when menus or notifications must not appear to remote viewers.
- Expecting
cropTo()/restrictTo()on non-tab tracks or cloned tracks. - Extension tab capture without re-routing audio, so the user hears silence from the captured tab.
- Using
getMediaStreamId()in the wrong tab/process/origin relative to Chrome 116 consumption rules. - Popup-only video capture via
tabCapture.capture()(focus loss ends the popup).
Browser support snapshot
Section titled “Browser support snapshot”| Feature | Chrome / Edge (typical) | Firefox | Safari |
|---|---|---|---|
| Capture Handle | 102+ | No | No |
Privacy picker options (displaySurface, etc.) |
105–107+ desktop | No | No |
| Region Capture | 104+ desktop | No | No |
| Conditional Focus | 109+ | No | No |
| Element Capture | 132+ desktop | — | — |
| Captured Surface Control | 136+ desktop | — | — |
Always feature-detect (CaptureController, getCaptureHandle, CropTarget, RestrictionTarget, forwardWheel) before branching.
How to check this on your site
Section titled “How to check this on your site”- In Chrome, run your share flow and confirm the picker matches your
getDisplayMedia()constraints using the privacy-preserving screen sharing controls demo. - After capture, log
videoTrack.getSettings().displaySurfaceandvideoTrack.getCaptureHandle()to verify self-capture, origin, and handle visibility per Capture Handle. - For embedded crop workflows, confirm
cropTo()orrestrictTo()with the Region Capture or Element Capture demos. - For extensions, step through Audio recording and screen capture (offscreen +
getMediaStreamId) and verify audio playback viaAudioContext. - You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.