Skip to content

feat: Swap node fetch with impit - #4

Merged
rajarsheechatterjee merged 2 commits into
lnreader:mainfrom
trietng:feat/impit
Nov 27, 2026
Merged

rajarsheechatterjee merged 2 commits into
lnreader:mainfrom
trietng:feat/impit

Conversation

@trietng

@trietng trietng commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace Node.js's built-in globalThis.fetch (undici) with impit in @lnreader/plugin-runtime so outbound requests use Chrome's TLS/HTTP2 fingerprint (chrome151) and context-appropriate browser headers by default.

Changes

  • Added createImpitFetch() using new Impit({ browser: 'chrome151' }) as HttpClient's default fetchImpl (preserving options.fetch injection for tests).
  • Removed the static DEFAULT_HEADERS (Accept: */*, Sec-Fetch-Mode: cors) from HttpClient so impit's Chrome navigation defaults are used for page requests.
  • Updated DEFAULT_USER_AGENT to Chrome 151.0.0.0 (Windows) to match impit's chrome151 profile.
  • Added adaptHeaders() to adjust context-dependent headers (Referer, Sec-Fetch-Site, Sec-Fetch-Mode, Sec-Fetch-Dest, Sec-Fetch-User, Upgrade-Insecure-Requests) for navigation (GET), image (accept: image/*), and XHR/CORS (POST, X-Requested-With, Origin, Content-Type, non-HTML Accept) requests, and to strip sec-ch-ua* when a custom User-Agent overrides DEFAULT_USER_AGENT.

Note: With the introduction of impit as a dependency, it requires regular update as the library bump its Chrome implementation. Authentication is kept as is for logins.

Verification

  • pnpm test packages/plugin-runtime/test/client.test.ts packages/plugin-runtime/test/cookies.test.ts packages/cli-browser/test/authenticate.test.ts: client.test.ts (7 tests) and cookies.test.ts (3 tests) passed (authenticate.test.ts skipped without LNREADER_TEST_CHROMIUM).
  • Verified login session cookie capture/replay (authenticate → CookieStore → HttpClient/impit) against a local HTTP server.
  • Verified Royal Road cover image fetch (200 image/webp) without auth cookies.

Live Plugin Smoke Tests (lnreader plugins test <plugin>)

Plugin Load Popular Search Novel Chapter Notes
royalroad (2.3.4) ✔ ✔ ✔ ✔ ✔ 109 chapters, 43,344 chars
scribblehub (1.1.0) ✔ ✔ ✔ ✔ ✔ 554 chapters, 9,223 chars
webnovel (1.1.0) ✔ ✔ ✔ ✔ ✔ 3,233 chapters, 7,967 chars
wuxiaworld (0.6.0) ✔ ✔ ✔ ✔ ✔ 357 chapters, 8,035 chars
novelbin (3.0.1) ✔ ✔ ✔ ✔ ✔ 44 chapters, 3,726 chars
novelupdates (0.9.11) ✔ ✔ ✔ ✖ - parseNovel hit Cloudflare browser check
novelnice (2.4.0) ✔ ✖ ✖ - - popularNovels / searchNovels hit Cloudflare browser check
lightnovelworld (1.0.2) ✔ ✖ ✖ - - popularNovels / searchNovels returned no results

I'm not sure what to do to solve the 3 failed checks (there would probably be more, can't test all of them unless I want my IP blocked), but at least some of them should be working for now.

@rajarsheechatterjee rajarsheechatterjee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work: TLS impersonation is a clear improvement, and build, typecheck, lint, tests and pack-check all pass locally. Two blockers: the hard native dependency (comments on impit.ts:1 / errors.ts:1) and the implicit 30 s timeout (impit.ts:91). The other two are minor. CI hasn't run on this PR yet, so a maintainer needs to approve the workflow.


Generated by Claude Code

Comment thread packages/plugin-runtime/src/errors.ts Resolved
@rajarsheechatterjee
rajarsheechatterjee merged commit ea3fd1e into lnreader:main Nov 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants