fix(wasm): preserve binary fetch responses (#48)

* fix wasm response handling

* fix URL inputs in fetch polyfill

* test(wasm): cover binary fetch responses
This commit is contained in:
rifuki authored and GitHub committed 2026-04-27 17:31:54 +02:00
1 parent fdec52c70f
commit 53a04fa905
6 files changed
+217 -30

No files matched your search

+6 -2
View File
@@ -6,6 +6,7 @@ use std::sync::{Arc, OnceLock};
use deno_core::op2;
use deno_core::OpState;
use deno_core::Extension;
use base64::{engine::general_purpose::STANDARD as BASE64, Engine as _};
use obscura_dom::{DomTree, NodeData, NodeId};
use obscura_net::{CookieJar, ObscuraHttpClient};
use tokio::sync::Mutex;
@@ -517,16 +518,19 @@ async fn op_fetch_url(
}
}
let resp_body = response
.text()
let resp_bytes = response
.bytes()
.await
.map_err(|e| deno_error::JsErrorBox::generic(e.to_string()))?;
let resp_body = String::from_utf8_lossy(&resp_bytes).to_string();
let resp_body_base64 = BASE64.encode(&resp_bytes);
tracing::debug!("op_fetch_url completed: {} {} ({} bytes)", method, url, resp_body.len());
Ok(serde_json::json!({
"status": status,
"body": resp_body,
"bodyBase64": resp_body_base64,
"url": url,
"headers": resp_headers,
})