Skip to content

Commit

Permalink
Nav requestmidi updates (mdn#13479)
Browse files Browse the repository at this point in the history
* Navigator.requestMIDIUpdates() - add security/permission info

* WebMIDI API page - secure context and improve example
  • Loading branch information
hamishwillee authored Mar 4, 2022
1 parent 44a357a commit f47263d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions files/en-us/web/api/navigator/requestmidiaccess/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ tags:
browser-compat: api.Navigator.requestMIDIAccess
---

{{DefaultAPISidebar("Web MIDI API")}}
{{DefaultAPISidebar("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](/en-US/docs/Web/API/Web_MIDI_API), which provides a means for accessing, enumerating, and manipulating MIDI devices.
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](/en-US/docs/Web/API/Web_MIDI_API), which provides a means for accessing, enumerating, and manipulating MIDI devices.

This method prompts the user for access to MIDI devices available to their system. If the user grants permission, then the {{jsxref('Promise')}} resolves and a [`MIDIAccess`](/en-US/docs/Web/API/MIDIAccess) object is returned.
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`](/en-US/docs/Web/API/MIDIAccess) object is returned.

## Syntax

Expand Down Expand Up @@ -48,7 +49,7 @@ A {{jsxref('Promise')}} that resolves with a [`MIDIAccess`](/en-US/docs/Web/API/
- `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](/en-US/docs/Web/API/MIDIAccess) object with the requested options, or if the document is not allowed to use the feature (for example, an iframe without the correct [feature policy](/en-US/docs/Web/HTTP/Feature_Policy)).
- : If the user or system denies the application from creating a [MIDIAccess](/en-US/docs/Web/API/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](/en-US/docs/Web/HTTP/Feature_Policy), or when the user has previously denied a permissions access to the feature).

## Examples

Expand Down
5 changes: 3 additions & 2 deletions files/en-us/web/api/web_midi_api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tags:
- Reference
- Web MIDI API
---
{{DefaultAPISidebar("Web MIDI API")}}
{{DefaultAPISidebar("Web MIDI API")}}{{SecureContext_Header}}

The Web MIDI API connects to and interacts with with Musical Instrument Digital Interface (MIDI) Devices.

Expand Down Expand Up @@ -37,7 +37,8 @@ The interfaces deal with the practical aspects of sending and receiving MIDI mes

### Gaining access to the MIDI port

In the following example the {{domxref("MIDIAccess")}} interface is used to gain access to a MIDI device.
The {{domxref("navigator.requestMIDIAccess()")}} method returns a promise that resolves to a {{domxref("MIDIAccess")}}, which can then be used to access a MIDI device.
The method must be called in a secure context.

```js
var midi = null; // global MIDIAccess object
Expand Down

0 comments on commit f47263d

Please sign in to comment.