MediaRecorder: error event

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

Bubbles No
Cancelable No
Interface MediaRecorderErrorEvent
Event handler property onerror

For details of the all the possible errors see the documentation for the event handler property: onerror.

Examples

Using addEventListener to listen for error events:

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:

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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
error_event
49
79
25
No
36
14
49
49
25
36
14
5.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/error_event