CLI: Add --user-agent flag for fetched URLs#276
Open
kleinmatic wants to merge 1 commit into
Open
Conversation
Some sites return 403/FORBIDDEN to the default Defuddle UA. Allow users to override it with --user-agent / -u. When set, the bot-UA fallback retry is skipped to respect the explicit choice. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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
--user-agent/-uflag todefuddle parseso users can override theUser-Agentsent when fetching a URL. The default UA (Mozilla/5.0 (compatible; Defuddle/1.0; +https://defuddle.md)) gets 403/FORBIDDEN from a number of sites; this gives an easy escape hatch without touching the library.Example:
npx defuddle parse https://example.com/article \ --user-agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15"The plumbing was already there —
fetchPage(targetUrl, userAgent, language?)insrc/fetch.tsalready takes a UA — this just surfaces it through the CLI.Test plan
npm run buildsucceedsnode dist/cli.js parse <url> --user-agent "<ua>"uses the supplied UA (verifiable with a request bin /httpbin.org/user-agent)node dist/cli.js parse <url>without the flag still uses the default UA (existing behavior unchanged)--helpshows the new option🤖 Generated with Claude Code