PSA: Web Bluetooth and WebUSB changing detached buffer handling

114 views
Skip to first unread message

Reilly Grant

unread,
Oct 18, 2024, 4:58:56 PMOct 18
to blink-dev
Chromium's implementations of Web Bluetooth and WebUSB currently throw a non-standard InvalidStateError when passed an ArrayBuffer or TypedArray which has been detached (e.g. by calling transfer() or using postMessage() to send the buffer through a MessagePort).

I will be changing these APIs to follow the "get a copy of the bytes held by the buffer source" algorithm and treat a detached buffer as an empty byte sequence.

I expect this will not have any web compatibility impact because it is a programming error to pass a detached buffer to these APIs, which is why we added the exception to begin with. This change makes the APIs consistent with other buffer-consuming APIs like Web Serial and WebHID, where we handle this case with the specified behavior.

Reilly Grant | Software Engineer | rei...@google.com | Google Chrome
Reply all
Reply to author
Forward
0 new messages