MediaRecorder: error event

Limited availability

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

The error event of the MediaRecorder interface is fired when an error occurs: for example because recording wasn't allowed or was attempted using an unsupported codec.

This event is not cancelable and does not bubble.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js
addEventListener("error", (event) => { })

onerror = (event) => { }

Event type

A MediaRecorderErrorEvent. Inherits from Event.

Event properties

Inherits properties from its parent interface, Event.

error Read only

A DOMException containing information about the error that occurred.

Description

Trigger

A function to be called whenever an error occurs during the recorder's lifetime. In addition to other general errors that might occur, the following errors are specifically possible when using the MediaStream Recording API; to determine which occurred, check the value of MediaRecorderErrorEvent.error.name.

SecurityError

The MediaStream is configured to disallow recording. This may be the case, for example, with sources obtained using getUserMedia() when the user denies permission to use an input device.

InvalidModificationError

The number of tracks on the stream being recorded has changed. You can't add or remove tracks while recording media.

UnknownError

A non-security related error occurred that cannot otherwise be categorized. Recording stops, the MediaRecorder's state becomes inactive, one last dataavailable event is sent to the MediaRecorder with the remaining received data, and finally a stop event is sent.

Examples

Using addEventListener() to listen for error events:

js
async function record() {
  const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
  const recorder = new MediaRecorder(stream);
  recorder.addEventListener("error", (event) => {
    console.error(`error recording stream: ${event.error.name}`);
  });
  recorder.start();
}

record();

The same, but using the onerror event handler property:

js
async function record() {
  const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
  const recorder = new MediaRecorder(stream);
  recorder.onerror = (event) => {
    console.error(`error recording stream: ${event.error.name}`);
  };
  recorder.start();
}

record();

Specifications

Specification
MediaStream Recording
# dom-mediarecorder-onerror

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
error event
Chrome – Partial support
Chrome 49 (Release date: 2016-03-02)
footnote Partial support
footnote The interface for this event is a plain Event, not ErrorEvent. See bug 40791876.
Edge – Partial support
Edge 79 (Release date: 2020-01-15)
footnote Partial support
footnote The interface for this event is a plain Event, not ErrorEvent. See bug 40791876.
Firefox – Full support
Firefox 25 (Release date: 2013-10-29)
footnote Full support
Opera – Partial support
Opera 36 (Release date: 2016-03-15)
footnote Partial support
footnote The interface for this event is a plain Event, not ErrorEvent. See bug 40791876.
Safari – Full support
Safari 14.1 (Release date: 2021-04-26)
footnote Full support
Chrome Android – Partial support
Chrome Android 49 (Release date: 2016-03-09)
footnote Partial support
footnote The interface for this event is a plain Event, not ErrorEvent. See bug 40791876.
Firefox for Android – Full support
Firefox for Android 25 (Release date: 2013-10-29)
footnote Full support
Opera Android – Partial support
Opera Android 36 (Release date: 2016-03-31)
footnote Partial support
footnote The interface for this event is a plain Event, not ErrorEvent. See bug 40791876.
Safari on iOS – Full support
Safari on iOS 14 (Release date: 2020-09-16)
footnote Full support
Samsung Internet – Partial support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Partial support
footnote The interface for this event is a plain Event, not ErrorEvent. See bug 40791876.
WebView Android – Partial support
WebView Android 49 (Release date: 2016-03-09)
footnote Partial support
footnote The interface for this event is a plain Event, not ErrorEvent. See bug 40791876.
WebView on iOS – Full support
WebView on iOS 14 (Release date: 2020-09-16)
footnote Full support

Legend

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

Full support
Full support
Partial support
Partial support

See also