Skip to content

Commit 67bb2a4

Browse files
Work around Chromium bug with { type: "bytes" }
1 parent 2b5baf2 commit 67bb2a4

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/readable/into_underlying_byte_source.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,24 @@ impl IntoUnderlyingByteSource {
2727
}
2828
}
2929

30+
#[wasm_bindgen(inline_js = "export function bytes_literal() { return \"bytes\"; }")]
31+
extern "C" {
32+
fn bytes_literal() -> JsValue;
33+
}
34+
3035
#[allow(clippy::await_holding_refcell_ref)]
3136
#[wasm_bindgen]
3237
impl IntoUnderlyingByteSource {
38+
// Chromium has a bug where it only recognizes `new ReadableStream({ type: "bytes" })`,
39+
// not `new ReadableStream({ type: "by" + "tes" })` or any other non-literal string
40+
// that equals "bytes". Therefore, we cannot return a Rust `String` here, since
41+
// that needs to be converted to a JavaScript string at runtime.
42+
// Instead, we call a function that returns the desired string literal as a `JsValue`
43+
// and pass that value around. It looks silly, but it works.
44+
// See https://crbug.com/1187774
3345
#[wasm_bindgen(getter, js_name = type)]
34-
pub fn type_(&self) -> String {
35-
"bytes".into()
46+
pub fn type_(&self) -> JsValue {
47+
bytes_literal()
3648
}
3749

3850
#[wasm_bindgen(getter, js_name = autoAllocateChunkSize)]

0 commit comments

Comments
 (0)