files/en-us/web/api/navigator/requestmidiaccess/index.md
{{APIRef("Web MIDI API")}}{{SecureContext_Header}}
The requestMIDIAccess() method of the {{domxref('Navigator')}} interface returns a {{jsxref('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 {{jsxref('Promise')}} resolves and a MIDIAccess object is returned.
requestMIDIAccess()
requestMIDIAccess(MIDIOptions)
MIDIOptions {{optional_inline}}
sysex
true, allows the ability to send and receive system exclusive (sysex) messages. The default value is false.software
true, allows the system to utilize any installed software synthesizers. The default value is false.A {{jsxref('Promise')}} that resolves with a MIDIAccess object.
AbortError {{domxref("DOMException")}}
InvalidStateError {{domxref("DOMException")}}
NotSupportedError {{domxref("DOMException")}}
NotAllowedError {{domxref("DOMException")}}
Access to the API is subject to the following constraints:
midi HTTP Permission Policy.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:
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
});
In the following example, the Navigator.requestMIDIAccess() method returns the {{domxref("MIDIAccess")}} object, which gives access to information about the input and output MIDI ports.
navigator.requestMIDIAccess().then((access) => {
// Get lists of available MIDI controllers
const inputs = access.inputs.values();
const outputs = access.outputs.values();
// …
});
{{Specifications}}
{{Compat}}