Skip to content

Conversation

@nikelborm
Copy link
Contributor

@nikelborm nikelborm commented Dec 9, 2025

According to Web IDL spec on InvalidAccessError:

Deprecated. Use TypeError for invalid arguments, "NotSupportedError" DOMException for unsupported operations, and "NotAllowedError" DOMException for denied requests instead.

Previously, while trying to open MIDIPort, "InvalidAccessError" DOMException was thrown when...

the device is unavailable (e.g., is already in use by another process and cannot be opened, or is disconnected)

In this case, I believe NotAllowedError fits well, according to its Web IDL spec description:

The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.

Security and permissions reasons are only a subset of the appropriate causes, according to this definition. An attempt to open the port can fail. Somebody's exclusive lock on the port, or the port being disconnected, is the current context driving the platform's decision not to allow the operation.

And in the context of forbidden .send calls:

If data is a System Exclusive message, and the MIDIAccess did not enable System Exclusive access, throw an InvalidAccessError exception.

NotAllowedError fits even better, because it fits an explicitly defined subset of permission errors.

@nikelborm
Copy link
Contributor Author

For the case when InvalidAccessError is thrown when trying to open the port, instead of the suggested NotAllowedError, we can consider InvalidStateError, which has a usage precedent of being used by .send method in the similar case:

If the port is "disconnected", throw an InvalidStateError exception.

@mjwilson-google mjwilson-google self-requested a review December 9, 2025 20:29
Copy link
Contributor

@svgeesus svgeesus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@mjwilson-google mjwilson-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I think you are right and NotAllowedError is the best fit for both of these. Thank you.

@mjwilson-google mjwilson-google merged commit ccef7f6 into WebAudio:gh-pages Dec 9, 2025
1 check failed
@mjwilson-google
Copy link
Contributor

Chromium change here: https://crrev.com/c/7242095

nikelborm added a commit to nikelborm/mdn-content that referenced this pull request Dec 9, 2025
brave-builds pushed a commit to brave/chromium that referenced this pull request Dec 10, 2025
See WebAudio/web-midi-api#278

The exception type when sysex access is denied has been changed in the
spec to NotAllowedError instead of the deprecated InvalidAccessError.

The exception type was also changed when opening a MIDIPort, but it
looks like Chromium doesn't currently throw an exception in this case
so no update is necessary right now.

Change-Id: Ic80cb39064c8240c6bc00d5f0a7f36e6c7bdd09b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7242095
Reviewed-by: Takashi Toyoshima <[email protected]>
Commit-Queue: Michael Wilson <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1556825}
wbamberg pushed a commit to mdn/content that referenced this pull request Dec 19, 2025
…42334)

MIDI APIs now use NotAllowedError instead of InvalidAccessError

The change in spec: WebAudio/web-midi-api@3795f22
According PR: WebAudio/web-midi-api#278
nikelborm added a commit to nikelborm/firefox that referenced this pull request Dec 19, 2025
…d `SecurityError` and `InvalidAccessError` in favor of `NotAllowedError` r?gsvelto,bholley

= `InvalidAccessError` replaced by `NotAllowedError`:

The change in spec: [WebAudio/web-midi-api@3795f22](WebAudio/web-midi-api@3795f22)
According PR: [WebAudio/web-midi-api#278](WebAudio/web-midi-api#278)
MDN update PR: [mdn/content#42334](mdn/content#42334)

== Affected APIs

1. `.send` method of output MIDI ports
2. `.open` method of MIDI ports

= `SecurityError` replaced by `NotAllowedError`:

The change in spec: [WebAudio/web-midi-api@b7806b8](WebAudio/web-midi-api@b7806b8)
According PR: [WebAudio/web-midi-api#267](WebAudio/web-midi-api#267)
MDN update PR: [mdn/content#41956](mdn/content#41956)

== Affected APIs

1. `navigator.requestMIDIAccess` method
@nikelborm
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants