chrome.tabCapture

Description: Use the chrome.tabCapture API to interact with tab media streams.
Availability: Since Chrome 31.
Permissions: "tabCapture"

Summary

Types
CaptureInfo
MediaStreamConstraint
CaptureOptions
Methods
capture chrome.tabCapture.capture( CaptureOptions options, function callback)
getCapturedTabs chrome.tabCapture.getCapturedTabs(function callback)
captureOffscreenTab chrome.tabCapture.captureOffscreenTab(string startUrl, CaptureOptions options, function callback)
Events
onStatusChanged

Types

CaptureInfo

properties
integer tabId

The id of the tab whose status changed.

enum of "pending", "active", "stopped", or "error" status

The new capture status of the tab.

boolean fullscreen

Whether an element in the tab being captured is in fullscreen mode.

MediaStreamConstraint

properties
object mandatory
object (optional) optional

Since Chrome 32.

CaptureOptions

properties
boolean (optional) audio
boolean (optional) video
MediaStreamConstraint (optional) audioConstraints
MediaStreamConstraint (optional) videoConstraints

Methods

capture

chrome.tabCapture.capture( CaptureOptions options, function callback)

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.

Parameters
CaptureOptions options

Configures the returned media stream.

function callback

Callback with either the tab capture MediaStream or null. null indicates an error has occurred and the client may query chrome.runtime.lastError to access the error details.

The callback parameter should be a function that looks like this:

function(LocalMediaStream stream) {...};
LocalMediaStream stream

getCapturedTabs

chrome.tabCapture.getCapturedTabs(function callback)

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).

Parameters
function callback

Callback invoked with CaptureInfo[] for captured tabs.

The callback parameter should be a function that looks like this:

function(array of CaptureInfo result) {...};
array of CaptureInfo result

captureOffscreenTab

chrome.tabCapture.captureOffscreenTab(string startUrl, CaptureOptions options, function callback)

Since Chrome 47.

Creates an off-screen tab and navigates it to the given |startUrl|. Then, capture is started and a MediaStream is returned via |callback|.

Off-screen tabs are isolated from the user's normal browser experience. They do not show up in the browser window or tab strip, nor are they visible to extensions (e.g., via the chrome.tabs.* APIs).

An off-screen tab remains alive until one of three events occurs: 1. All MediaStreams providing its captured content are closed; 2. the page self-closes (e.g., via window.close()); 3. the extension that called captureOffscreenTab() is unloaded.

Sandboxing: The off-screen tab does not have any access whatsoever to the local user profile (including cookies, HTTP auth, etc.). Instead, it is provided its own sandboxed profile. Also, it cannot access any interactive resources such as keyboard/mouse input, media recording devices (e.g., web cams), copy/paste to/from the system clipboard, etc.

Note: This is a new API, currently only available in Canary/Dev channel, and may change without notice.

Parameters
string startUrl
CaptureOptions options

Constraints for the capture and returned MediaStream.

function callback

Callback with either the tab capture MediaStream or null. null indicates an error has occurred and the client may query chrome.runtime.lastError to access the error details.

The callback parameter should be a function that looks like this:

function(LocalMediaStream stream) {...};
LocalMediaStream stream

Events

onStatusChanged

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.

addListener

chrome.tabCapture.onStatusChanged.addListener(function callback)
Parameters
function callback

The callback parameter should be a function that looks like this:

function( CaptureInfo info) {...};
CaptureInfo info

CaptureInfo with new capture status for the tab.