Navigator: requestMIDIAccess() method

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 requestMIDIAccess() method of the Navigator interface returns a Promise representing a request for access to MIDI devices on a user's system. This method is part of the Web MIDI API, which provides a means for accessing, enumerating, and manipulating MIDI devices.

This method may prompt the user for access to MIDI devices available to their system, or it may use a previously established preference to grant or deny access. If permission is granted then the Promise resolves and a MIDIAccess object is returned.

Syntax

js
requestMIDIAccess()
requestMIDIAccess(MIDIOptions)

Parameters

MIDIOptions Optional

An Object representing options to pass into the method. These options are:

sysex

A Boolean value that, if set to true, allows the ability to send and receive system exclusive (sysex) messages. The default value is false.

software

A Boolean value that, if set to true, allows the system to utilize any installed software synthesizers. The default value is false.

Return value

A Promise that resolves with a MIDIAccess object.

Exceptions

AbortError DOMException

Thrown if the document or page is closed due to user navigation.

InvalidStateError DOMException

Thrown if the underlying system raises any errors.

NotSupportedError DOMException

Thrown if the feature or options are not supported by the system.

NotAllowedError DOMException

Thrown if the user or system denies the application from creating a MIDIAccess object with the requested options, or if the document is not allowed to use the feature (for example, because of a Permission Policy, or because the user previously denied a permission request).

Security requirements

Access to the API is subject to the following constraints:

  • The method must be called in a secure context.
  • Access may be gated by the midi HTTP Permission Policy.
  • The user must explicitly grant permission to use the API though a user-agent specific mechanism, or have previously granted permission. Note that if access is denied by a permission policy it cannot be granted by a user permission.

The permission status can be queried using the Permissions API method navigator.permissions.query(), passing a permission descriptor with the midi permission and (optional) sysex property:

js
navigator.permissions.query({ name: "midi", sysex: true }).then((result) => {
  if (result.state === "granted") {
    // Access granted.
  } else if (result.state === "prompt") {
    // Using API will prompt for permission
  }
  // Permission was denied by user prompt or permission policy
});

Examples

Request MIDI access

In the following example, the Navigator.requestMIDIAccess() method returns the MIDIAccess object, which gives access to information about the input and output MIDI ports.

js
navigator.requestMIDIAccess().then((access) => {
  // Get lists of available MIDI controllers
  const inputs = access.inputs.values();
  const outputs = access.outputs.values();
  // …
});

Specifications

Specification
Web MIDI API
# dom-navigator-requestmidiaccess

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Node.js
requestMIDIAccess
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
footnote API access is gated by installation of a site permission add-on (user prompt), secure context, and Permission Policy: midi.
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
Node.js – No support
Node.js
footnote No support
Secure context required
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 No support
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 No support
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 No support
Node.js – No support
Node.js
footnote No support

Legend

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

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

See also