Skip to content

CLI: Add --user-agent flag for fetched URLs#276

Open
kleinmatic wants to merge 1 commit into
kepano:mainfrom
kleinmatic:cli-user-agent
Open

CLI: Add --user-agent flag for fetched URLs#276
kleinmatic wants to merge 1 commit into
kepano:mainfrom
kleinmatic:cli-user-agent

Conversation

@kleinmatic
Copy link
Copy Markdown

@kleinmatic kleinmatic commented Apr 30, 2026

Summary

  • Adds a --user-agent / -u flag to defuddle parse so users can override the User-Agent sent 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.
  • When the flag is set, the existing "retry with bot UA on empty result" fallback is skipped — if a user picked a UA, we should respect that choice rather than silently swap it.
  • README updated: new option in the CLI options table and a usage example.

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?) in src/fetch.ts already takes a UA — this just surfaces it through the CLI.

Test plan

  • npm run build succeeds
  • node 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)
  • --help shows the new option

🤖 Generated with Claude Code

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]>
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.

1 participant