Skip to content

Reuse firecrawl-cli login: credentials.json fallback for API key - #3

Merged
rakshith48 merged 1 commit into
mainfrom
feat/cli-credential-fallback
Jun 16, 2026
Merged

rakshith48 merged 1 commit into
mainfrom
feat/cli-credential-fallback

Conversation

@rakshith48

@rakshith48 rakshith48 commented Jun 16, 2026 •

Copy link
Copy Markdown
Collaborator

Lets a user who ran firecrawl login use the plugin with no env var — the plugin reads the API key the CLI stored.

Resolution order (env always wins)

  1. FIRECRAWL_API_KEY (+ FIRECRAWL_API_URL) env
  2. firecrawl-cli credentials.json — per-OS path mirrored from cli/src/utils/credentials.ts (macOS ~/Library/Application Support/firecrawl-cli, Linux ~/.config/firecrawl-cli, Windows %AppData%/firecrawl-cli)
  3. Clear error: set FIRECRAWL_API_KEY or run firecrawl login

The CLI's browser login resolves to a real fc- API key and saves { apiKey, apiUrl }, so the same key works for both browser.provider and command.run.

Why reading the file is safe here

It's a stable, documented shape (StoredCredentials = { apiKey?, apiUrl? }), deterministic per-OS path, chmod 0600. Treated as a best-effort fallback: missing/corrupt → falls through to the env-var contract. Never logged.

Verification

  • node --test 12/12 (incl. file-fallback + env-overrides-file, isolated temp HOMEs).
  • Live: env path, credentials.json fallback (env unset → key from file → real session), no-creds error, and full agent-browser drive (open/snapshot/click/close + scrape), 0 leaked sessions.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Plugin now reads stored CLI credentials as fallback when environment variables aren't configured.
    • API credentials are resolved dynamically per API call, enabling credential changes between requests.
  • Documentation

    • Added credential resolution guide clarifying configuration priority and setup methods.
    • Improved error messages to help guide users through credential configuration.

resolveCredentials() now resolves in order: FIRECRAWL_API_KEY/URL env ->
firecrawl-cli credentials.json (the key `firecrawl login` stores, per-OS path
mirrored from cli/src/utils/credentials.ts) -> clear error. One key serves both
browser.provider and command.run. Env always wins.

Tests: +2 hermetic cases (file fallback, env-overrides-file) using isolated
temp HOMEs so the suite never reads the real machine's credentials. 12 total.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3eda527e-caac-41bc-a865-8412e3390468

📥 Commits

Reviewing files that changed from the base of the PR and between 36872cc and 6da920e.

📒 Files selected for processing (3)
  • README.md
  • bin/plugin.js
  • test/plugin.test.js
 ______________________________________________________________________________________________________________________________________________________________________________________________________________
< Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves. - Alan Kay >
 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/cli-credential-fallback

Comment @coderabbitai help to get the list of available commands and usage tips.

@rakshith48
rakshith48 merged commit c9c0c8d into main Jun 16, 2026
3 of 4 checks passed
@rakshith48
rakshith48 deleted the feat/cli-credential-fallback branch June 16, 2026 22:08
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