Stay organized with collections Save and categorize content based on your preferences.
DescriptionUse the chrome.tabCapture
API to interact with tab media streams.
tabCapture
The chrome.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. This is similar to the behavior of the "activeTab"
permission.
When a MediaStream
is obtained for a tab, audio in that tab will no longer be played to the user. This is similar to the behavior of the getDisplayMedia()
function when the suppressLocalAudioPlayback
flag is set to true.
To continue playing audio to the user, use the following:
const output = new AudioContext();
const source = output.createMediaStreamSource(stream);
source.connect(output.destination);
This creates a new AudioContext
and connects the audio of the tab's MediaStream
to the default destination.
Calling chrome.tabCapture.getMediaStreamId()
will return a stream ID. To later access a MediaStream
from the ID, use the following:
navigator.mediaDevices.getUserMedia({
audio: {
mandatory: {
chromeMediaSource: "tab",
chromeMediaSourceId: id,
},
},
video: {
mandatory: {
chromeMediaSource: "tab",
chromeMediaSourceId: id,
},
},
});
Usage restrictions
After calling getMediaStreamId()
, there are restrictions on where the returned stream ID can be used:
consumerTabId
is specified, the ID can be used by a getUserMedia()
call in any frame in the given tab which has the same security origin.Prior to Chrome 116, when a consumerTabId
was not specified, the stream ID was restricted to both the security origin, render process and render frame of the caller.
To learn more about how to use the chrome.tabCapture
API, see Audio recording and screen capture. This demonstrates how to use tabCapture
and related APIs to solve a number of common use cases.
Whether an element in the tab being captured is in fullscreen mode.
The new capture status of the tab.
The id of the tab whose status changed.
consumerTabId
number optional
Optional tab id of the tab which will later invoke getUserMedia()
to consume the stream. If not specified then the resulting stream can be used only by the calling extension. The stream can only be used by frames in the given tab whose security origin matches the consumber tab's origin. The tab's origin must be a secure origin, e.g. HTTPS.
targetTabId
number optional
Optional tab id of the tab which will be captured. If not specified then the current active tab will be selected. Only tabs for which the extension has been granted the activeTab
permission can be used as the target tab.
"pending"
"active"
"stopped"
"error"
chrome.tabCapture.capture(
options: CaptureOptions,
callback: function,
): void
Captures the visible area of the currently active tab. Capture can only be started on the currently active tab after the extension has been invoked, similar to the way that activeTab works. Capture is maintained across page navigations within the tab, and stops when the tab is closed, or the media stream is closed by the extension.
ParametersConfigures the returned media stream.
The callback
parameter looks like:
(stream: LocalMediaStream) => void
chrome.tabCapture.getCapturedTabs(): Promise<CaptureInfo[]>
Returns a list of tabs that have requested capture or are being captured, i.e. status != stopped and status != error. This allows extensions to inform the user that there is an existing tab capture that would prevent a new tab capture from succeeding (or to prevent redundant requests for the same tab).
getMediaStreamId()chrome.tabCapture.getMediaStreamId(
options?: GetMediaStreamOptions,
): Promise<string>
Creates a stream ID to capture the target tab. Similar to chrome.tabCapture.capture() method, but returns a media stream ID, instead of a media stream, to the consumer tab.
Events onStatusChangedchrome.tabCapture.onStatusChanged.addListener(
callback: function,
)
Event fired when the capture status of a tab changes. This allows extension authors to keep track of the capture status of tabs to keep UI elements like page actions in sync.
ParametersThe callback
parameter looks like:
(info: CaptureInfo) => void
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-11 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-11 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4