MIDIAccess: statechange event

Limited availability

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

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The statechange event of the MIDIAccess interface is fired when a new MIDI port is added or when an existing port changes state.

Syntax

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

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

onstatechange = (event) => { }

Event type

A MIDIConnectionEvent. Inherits from Event.

Event MIDIConnectionEvent

Event properties

MIDIConnectionEvent.port Read only

Returns a reference to a MIDIPort instance for a port that has been connected or disconnected.

Example

The Navigator.requestMIDIAccess() method returns a promise that resolves with a MIDIAccess object. When a port changes state, information about that port is printed to the console.

js
navigator.requestMIDIAccess().then((access) => {
  access.onstatechange = (event) => {
    console.log(event.port.name, event.port.manufacturer, event.port.state);
  };
});

Specifications

Specification
Web MIDI API
# dom-midiaccess-onstatechange

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
statechange event
Chrome – Full support
Chrome 43 (Release date: 2015-05-19)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Partial support
Firefox 108 (Release date: 2022-12-13)
footnote Partial support
footnote The onstatechange event handler is supported, but the event never fires. See bug 1802149.
Opera – Full support
Opera 30 (Release date: 2015-06-09)
footnote Full support
Safari – No support
Safari
footnote
footnote See bug 107250
Chrome Android – Full support
Chrome Android 43 (Release date: 2015-05-27)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 30 (Release date: 2015-06-10)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote
footnote See bug 107250
Samsung Internet – Full support
Samsung Internet 4 (Release date: 2016-03-11)
footnote Full support
WebView Android – Full support
WebView Android 43 (Release date: 2015-05-27)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote
footnote See bug 107250

Legend

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

Full support
Full support
Partial support
Partial support
No support
No support
See implementation notes.