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

Specification Status
MediaStream Recording Working Draft

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
error eventChrome Full support 49Edge No support NoFirefox Full support 25IE ? Opera Full support 36Safari ? WebView Android Full support 49Chrome Android Full support 49Firefox Android Full support 25Opera Android Full support 36Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

See also