Navigator.requestMIDIAccess()

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

navigator.requestMIDIAccess();
navigator.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

If the document or page is closed due to user navigation.

InvalidStateError

If the underlying system raises any errors.

NotSupportedError

If the feature or options are not supported by the system.

SecurityError

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, an iframe without the correct Permission Policy, or when the user has previously denied a permissions access to the feature).

Examples

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

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

});

Specifications

No specification found

No specification data found for api.Navigator.requestMIDIAccess.
Check for problems with this page or contribute a missing spec_url to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility

BCD tables only load in the browser

See also