MIDIPort

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 MIDIPort interface of the Web MIDI API represents a MIDI input or output port.

A MIDIPort instance is created when a new MIDI device is connected. Therefore it has no constructor.

EventTarget MIDIPort

Instance properties

MIDIPort.id Read only

Returns a string containing the unique ID of the port.

MIDIPort.manufacturer Read only

Returns a string containing the manufacturer of the port.

MIDIPort.name Read only

Returns a string containing the system name of the port.

MIDIPort.type Read only

Returns a string containing the type of the port, one of:

"input"

The MIDIPort is an input port.

"output"

The MIDIPort is an output port.

MIDIPort.version Read only

Returns a string containing the version of the port.

MIDIPort.state Read only

Returns a string containing the state of the port, one of:

"disconnected"

The device that this MIDIPort represents is disconnected from the system.

"connected"

The device that this MIDIPort represents is currently connected.

MIDIPort.connection Read only

Returns a string containing the connection state of the port, one of:

"open"

The device that this MIDIPort represents has been opened and is available.

"closed"

The device that this MIDIPort represents has not been opened, or has been closed.

"pending"

The device that this MIDIPort represents has been opened but has subsequently disconnected.

Instance methods

This interface also inherits methods from EventTarget.

MIDIPort.open()

Makes the MIDI device connected to this MIDIPort explicitly available, and returns a Promise which resolves once access to the port has been successful.

MIDIPort.close()

Makes the MIDI device connected to this MIDIPort unavailable, changing the state from "open" to "closed". This returns a Promise which resolves once the port has been closed.

Events

statechange

Called when an existing port changes its state or connection.

Examples

List ports and their information

The following example lists input and output ports, and displays information about them using properties of MIDIPort.

js
function listInputsAndOutputs(midiAccess) {
  for (const entry of midiAccess.inputs) {
    const input = entry[1];
    console.log(
      `Input port [type:'${input.type}'] id:'${input.id}' manufacturer: '${input.manufacturer}' name: '${input.name}' version: '${input.version}'`,
    );
  }

  for (const entry of midiAccess.outputs) {
    const output = entry[1];
    console.log(
      `Output port [type:'${output.type}'] id: '${output.id}' manufacturer: '${output.manufacturer}' name: '${output.name}' version: '${output.version}'`,
    );
  }
}

Add available ports to a select list

The following example takes the list of input ports and adds them to a select list, in order that a user can choose the device they want to use.

js
inputs.forEach((port, key) => {
  const opt = document.createElement("option");
  opt.text = port.name;
  document.getElementById("port-selector").add(opt);
});

Specifications

Specification
Web MIDI API
# MIDIPort

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
MIDIPort
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 – Full support
Firefox 108 (Release date: 2022-12-13)
footnote Full support
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
close
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 – Full support
Firefox 108 (Release date: 2022-12-13)
footnote Full support
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
connection
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 – Full support
Firefox 108 (Release date: 2022-12-13)
footnote Full support
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
id
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 – Full support
Firefox 108 (Release date: 2022-12-13)
footnote Full support
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
manufacturer
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 – Full support
Firefox 108 (Release date: 2022-12-13)
footnote Full support
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
name
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 – Full support
Firefox 108 (Release date: 2022-12-13)
footnote Full support
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
open
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 – Full support
Firefox 108 (Release date: 2022-12-13)
footnote Full support
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
state
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 – Full support
Firefox 108 (Release date: 2022-12-13)
footnote Full support
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
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 – Full support
Firefox 108 (Release date: 2022-12-13)
footnote Full support
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
type
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 – Full support
Firefox 108 (Release date: 2022-12-13)
footnote Full support
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
version
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 – Full support
Firefox 108 (Release date: 2022-12-13)
footnote Full support
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
No support
No support
See implementation notes.