Repository navigation
feat: Swap node fetch with impit - #4
Merged
Merged
Conversation
rajarsheechatterjee
left a comment
Member
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace Node.js's built-in
globalThis.fetch(undici) withimpitin@lnreader/plugin-runtimeso outbound requests use Chrome's TLS/HTTP2 fingerprint (chrome151) and context-appropriate browser headers by default.Changes
createImpitFetch()usingnew Impit({ browser: 'chrome151' })asHttpClient's defaultfetchImpl(preservingoptions.fetchinjection for tests).DEFAULT_HEADERS(Accept: */*,Sec-Fetch-Mode: cors) fromHttpClientsoimpit's Chrome navigation defaults are used for page requests.DEFAULT_USER_AGENTto Chrome151.0.0.0(Windows) to matchimpit'schrome151profile.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-HTMLAccept) requests, and to stripsec-ch-ua*when a customUser-AgentoverridesDEFAULT_USER_AGENT.Note: With the introduction of
impitas 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) andcookies.test.ts(3 tests) passed (authenticate.test.tsskipped withoutLNREADER_TEST_CHROMIUM).authenticate→CookieStore→HttpClient/impit) against a local HTTP server.200 image/webp) without auth cookies.Live Plugin Smoke Tests (
lnreader plugins test <plugin>)royalroad(2.3.4)scribblehub(1.1.0)webnovel(1.1.0)wuxiaworld(0.6.0)novelbin(3.0.1)novelupdates(0.9.11)parseNovelhit Cloudflare browser checknovelnice(2.4.0)popularNovels/searchNovelshit Cloudflare browser checklightnovelworld(1.0.2)popularNovels/searchNovelsreturned no resultsI'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.