HTMLMediaElement: captureStream() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The captureStream() method of the HTMLMediaElement interface returns a MediaStream object that streams a real-time capture of the content being rendered in the media element.

This can be used, for example, as a source for a WebRTC RTCPeerConnection.

Syntax

js
captureStream()

Parameters

None.

Return value

A MediaStream object which can be used as a source for audio and/or video data by other media processing code, or as a source for WebRTC.

Examples

Basic usage

In this example, an event handler is established so that clicking a button starts capturing the contents of a media element with the ID "playback" into a MediaStream. The stream can then be used for other purposes, such as a WebRTC stream to share prerecorded videos with another person during a video call.

js
document.querySelector(".playAndRecord").addEventListener("click", () => {
  const playbackElement = document.getElementById("playback");
  const captureStream = playbackElement.captureStream();
  playbackElement.play();
});

See Recording a media element for a longer and more intricate example and explanation.

Specifications

Specification
Media Capture from DOM Elements
# dom-htmlmediaelement-capturestream

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
captureStream
Chrome – Full support
Chrome 62 (Release date: 2017-10-17)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Partial support
Firefox 15 – 148 (Release date: 2012-08-28)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: moz
footnote From Firefox 51, if the source changes from a MediaStream after capture starts, the captured stream data cannot be updated until you switch the source back to a MediaStream.
footnote From Firefox 51, if mozCaptureMediaStream() is called on a media element with a MediaStream source, the returned object only contains tracks while the element is playing a MediaStream.
footnote From Firefox 51, if mozCaptureMediaStream() is called on a media element with no source media, its compatibility mode is be based on the first source that's added; and the stream will only work with that kind of stream from then on.
footnote Before Firefox 51, mozCaptureMediaStream() could not be used on a media element whose source is itself a MediaStream (such as a <video> element presenting a stream being received over an RTCPeerConnection).
Firefox – Full support
Firefox 149 (Release date: 2026-03-24)
prefix
prefix Implemented with the vendor prefix: moz
Firefox – Full support
Firefox 149 (Release date: 2026-03-24)
footnote Full support
Opera – Full support
Opera 49 (Release date: 2017-11-08)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 62 (Release date: 2017-10-24)
footnote Full support
Firefox for Android – Partial support
Firefox for Android 15 – 148 (Release date: 2012-08-28)
prefix
footnote Partial support
prefix Implemented with the vendor prefix: moz
footnote From Firefox for Android 51, if the source changes from a MediaStream after capture starts, the captured stream data cannot be updated until you switch the source back to a MediaStream.
footnote From Firefox for Android 51, if mozCaptureMediaStream() is called on a media element with a MediaStream source, the returned object only contains tracks while the element is playing a MediaStream.
footnote From Firefox for Android 51, if mozCaptureMediaStream() is called on a media element with no source media, its compatibility mode is be based on the first source that's added; and the stream will only work with that kind of stream from then on.
footnote Before Firefox for Android 51, mozCaptureMediaStream() could not be used on a media element whose source is itself a MediaStream (such as a <video> element presenting a stream being received over an RTCPeerConnection).
Firefox for Android – Full support
Firefox for Android 149 (Release date: 2026-03-24)
prefix
prefix Implemented with the vendor prefix: moz
Firefox for Android – Full support
Firefox for Android 149 (Release date: 2026-03-24)
footnote Full support
Opera Android – Full support
Opera Android 46 (Release date: 2018-05-14)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 8 (Release date: 2018-07-18)
footnote Full support
WebView Android – Full support
WebView Android 62 (Release date: 2017-10-24)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also