Get to know MDN better
This feature is not Baseline because it does not work in some of the most widely-used browsers.
The srcObject property of the HTMLMediaElement interface sets or returns the object which serves as the source of the media associated with the HTMLMediaElement, or null if not assigned.
The object can be a MediaStream, a MediaSource, a Blob, or a File (which inherits from Blob).
Note: As of March 2020, only Safari has full support for srcObject, i.e., using MediaSource, MediaStream, Blob, and File objects as values. Other browsers support MediaStream objects; until they catch up, consider falling back to creating a URL with URL.createObjectURL() and assigning it to HTMLMediaElement.src (see below for an example). In addition, as of version 108 Chromium supports attaching a dedicated worker MediaSource object by assigning that object's MediaSourceHandle instance (transferred from the worker) to srcObject.
A MediaStream, MediaSource, Blob, or File object (though see the compatibility table for what is actually supported), or null if not assigned.
Older versions of the Media Source specification required using URL.createObjectURL() to create an object URL then setting src to that URL. Now you can just set srcObject to the MediaStream directly.
In this example, a MediaStream from a camera is assigned to a newly-created <video> element.
In this example, a new MediaSource is assigned to a newly-created <video> element.
The examples below support older browser versions that require you to create an object URL and assign it to src if srcObject isn't supported.
First, a MediaStream from a camera is assigned to a newly-created <video> element, with fallback for older browsers.
Second, a new MediaSource is assigned to a newly-created <video> element, with fallback for older browsers and browsers that don't yet support assignment of MediaSource directly.
The MediaSource.handle property can be accessed inside a dedicated worker and the resulting MediaSourceHandle object is then transferred over to the thread that created the worker (in this case the main thread) via a postMessage() call:
Over in the main thread, we receive the handle via a message event handler, attach it to a <video> via its HTMLMediaElement.srcObject property, and play the video:
Note: MediaSourceHandles cannot be successfully transferred into or via a shared worker or service worker.
| HTML # dom-media-srcobject-dev |
| Media Source Extensions™ # htmlmediaelement-extensions-srcobject |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jun 24, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.