When using Impit with Bun, response.text() returns HTML with leading garbage bytes, making the response binary/unviewable. The same code running under Node.js returns clean, valid HTML.
- On
amazon.it: Response is completely corrupted, file is binary/unviewable
- On
amazon.com: Response is viewable but contains extra encoded/garbled bytes scattered throughout
When running the exact same code with Node.js, both URLs return clean UTF-8 HTML starting with <!doctype html>.
Repro steps
- Install dependencies:
npm install impit
- Create test file:
import { Impit } from "impit";
const impit = new Impit();
const res = await impit.fetch("https://www.amazon.it/dp/B00LH3DMUO", {
method: "GET",
headers: { "accept-encoding": "identity" },
});
console.log("Status:", res.status);
console.log("Content-Encoding:", res.headers.get("content-encoding"));
console.log("Content-Type:", res.headers.get("content-type"));
const html = await res.text();
console.log("Preview:", html.slice(0, 200));
- Run with Bun:
bun run test.ts → corrupted output
- Run with Node:
node test.mjs → clean HTML
Expected
res.text() returns valid HTML starting with <!doctype html> regardless of runtime.
Actual (Bun)
amazon.it: res.text() starts with non-UTF8 garbage bytes; saved file is binary/unviewable
amazon.com: Response is viewable but contains scattered encoded/garbled bytes (e.g., �Y�S=t� interspersed in HTML)
content-encoding header is null
Actual (Node.js)
- Both URLs return clean UTF-8 HTML starting with
<!doctype html>
- No garbage bytes, file is viewable and valid
Environment
- OS: Linux
- impit version: ^0.8.2
- Bun version: latest
- Node.js version: LTS
- content-type returned:
text/html;charset=UTF-8
Additional observations
- The issue only occurs when running under Bun; Node.js works correctly
- Plain Bun
fetch() (without Impit) also returns clean HTML, so the issue is specific to Impit + Bun combination
- Setting
accept-encoding: identity does not fix the issue under Bun
When using Impit with Bun,
response.text()returns HTML with leading garbage bytes, making the response binary/unviewable. The same code running under Node.js returns clean, valid HTML.amazon.it: Response is completely corrupted, file is binary/unviewableamazon.com: Response is viewable but contains extra encoded/garbled bytes scattered throughoutWhen running the exact same code with Node.js, both URLs return clean UTF-8 HTML starting with
<!doctype html>.Repro steps
npm install impitbun run test.ts→ corrupted outputnode test.mjs→ clean HTMLExpected
res.text()returns valid HTML starting with<!doctype html>regardless of runtime.Actual (Bun)
amazon.it:res.text()starts with non-UTF8 garbage bytes; saved file is binary/unviewableamazon.com: Response is viewable but contains scattered encoded/garbled bytes (e.g.,�Y�S=t�interspersed in HTML)content-encodingheader isnullActual (Node.js)
<!doctype html>Environment
text/html;charset=UTF-8Additional observations
fetch()(without Impit) also returns clean HTML, so the issue is specific to Impit + Bun combinationaccept-encoding: identitydoes not fix the issue under Bun