NEW310373
TextDecoder fails occasionally, not each time.
https://bugs.webkit.org/show_bug.cgi?id=310373
Summary TextDecoder fails occasionally, not each time.
Andrew Hodel
Reported 2026-03-20 10:39:57 PDT
Created attachment 478734 [details] error in console that shows value aaaa of ArrayBuffer and occasional failure The first parameter to `TextDecoder.decode` is as specified at https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/decode Parameters buffer Optional An ArrayBuffer, a TypedArray, or a DataView object containing the encoded text to decode. It is a `ArrayBuffer` with the utf8 value `aaaa` as shown in the screenshot. ``` 9052 unicode_string_from_ab_decode(ab) { 9053 9054 var r = Math.random(100); 9055 9056 console.log(r, ab instanceof Uint8Array, ab, new Uint8Array(ab)); 9057 9058 let decoder = new TextDecoder('utf-8'); 9059 let decoded_value = decoder.decode(ab); 9060 9061 console.log(r, ab instanceof Uint8Array, typeof(decoded_value)); 9062 9063 return decoded_value; 9064 9065 } ```
Attachments
error in console that shows value aaaa of ArrayBuffer and occasional failure (465.14 KB, image/png)
2026-03-20 10:39 PDT, Andrew Hodel
no flags
Andrew Hodel
Comment 1 2026-03-20 10:54:12 PDT
It works if you create another non resizable ArrayBuffer, thereby doubling the memory usage. From MDN Web Docs via Google Gemini: TextDecoder.decode() generally expects a fixed-length ArrayBuffer or a TypedArray. While newer JavaScript standards allow resizable ArrayBuffers, they can cause issues in older APIs. To fix this, create a new, non-resizable Uint8Array view or copy of the buffer content before passing it to TextDecoder.
Radar WebKit Bug Importer
Comment 2 2026-03-27 10:40:13 PDT
fantasai
Comment 3 2026-03-27 10:53:12 PDT
Thanks for the simplified testcase. Is there a live site also associated with this error?
Andrew Hodel
Comment 4 2026-03-27 11:33:15 PDT
Yes, but it is on an RFC1918 network plus requires authentication.
Anne van Kesteren
Comment 5 2026-03-31 07:32:06 PDT
This API doesn't support resizable buffers. Are you sure it's really non-determinism you're seeing and not just the result of you occasionally passing in a resizable buffer?
Anne van Kesteren
Comment 6 2026-03-31 07:32:54 PDT
(Bug 310341 was recently filed for considering adding resizable buffer support to this API.)
Note You need to log in before you can comment on or make changes to this bug.