Skip to content

fix: download screenshot binary when output targets an image file#94

Open
saivedant169 wants to merge 1 commit intofirecrawl:mainfrom
saivedant169:fix/screenshot-binary-output
Open

fix: download screenshot binary when output targets an image file#94
saivedant169 wants to merge 1 commit intofirecrawl:mainfrom
saivedant169:fix/screenshot-binary-output

Conversation

@saivedant169
Copy link
Copy Markdown

Closes #82

What

firecrawl scrape --format screenshot -o output.png writes the CDN URL as plain text to the file instead of the actual PNG binary. Running file output.png shows ASCII text, not image data.

Why

handleScrapeCommand delegates to handleScrapeOutput, which calls formatScreenshotOutput() for the screenshot format. That function returns the URL as a string, and writeOutput writes it with utf-8 encoding. The binary is never fetched.

The multi-URL path (handleAllScrapeCommand, around line 598) already handles this correctly — it calls fetch() on the screenshot URL, converts to a Buffer, and writes the raw bytes. The single-URL path just didn't have this logic.

Fix

Before falling through to handleScrapeOutput, check if we have a single screenshot format going to an image file extension (.png, .jpg, .jpeg, .webp). If so, fetch the binary and write it directly. Same pattern the multi-URL path uses.

Tests

Added two tests:

  • Verifies fetch() is called and binary buffer is written when output is .png
  • Verifies fetch() is NOT called when output is .txt (falls through to existing text behavior)

All 276 tests pass. Type check and formatting clean.

When using `firecrawl scrape --format screenshot -o output.png`, the CLI
wrote the screenshot CDN URL as plain text instead of fetching the actual
image. The multi-URL code path (handleAllScrapeCommand) already handled
this correctly, but the single-URL path was missing the fetch step.

Added a check in handleScrapeCommand that detects when a single
screenshot format is being written to a .png/.jpg/.jpeg/.webp file,
fetches the binary from the CDN URL, and writes the raw buffer.

Fixes firecrawl#82
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.

Screenshot format writes URL text to file instead of downloading image binary

1 participant