Screenshot format writes URL text to file instead of downloading image binary
- Dominant language
- TypeScript
- Stars
- 631
- Forks
- 100
- Avg merge
- 5h 9m
- Merged PRs (30d)
- 25
Description
## Bug
When using `firecrawl scrape --format screenshot -o output.png`, the CLI writes the screenshot **URL as plain text** to the output file instead of downloading the actual PNG image. This produces a corrupt file that appears to be a PNG but is actually a small text file containing the Firecrawl CDN URL.
## Reproduction
```bash
firecrawl scrape "https://example.com" --format screenshot -o screenshot.png
file screenshot.png # Reports: ASCII text, not PNG image data
cat screenshot.png # Shows: "Screenshot: https://..."
```
## Expected behavior
The CLI should fetch the image from the screenshot URL and write the binary data to the output file (like `handleAllScrapeCommand` already does correctly for multi-URL scrapes).
## Root cause
In `src/commands/scrape.ts`, `handleScrapeCommand` delegates to `handleScrapeOutput` in `src/utils/output.ts`. For a single screenshot format, `handleScrapeOutput` calls `formatScreenshotOutput()` which returns the URL as text, then `writeOutput()` writes that text string to the file with `utf-8` encoding.
The multi-URL code path (`handleAllScrapeCommand` in the same file, ~line 470) correctly handles this by fetching the URL and writing the binary buffer:
```js
const response = await fetch(result.data.screenshot);
if (response.ok) {
const buffer = Buffer.from(await response.arrayBuffer());
fs.writeFileSync(filepath, buffer);
}
```
## Suggested fix
In `handleScrapeCommand`, before calling `handleScrapeOutput`, check if the output is a single screenshot format going to an image file extension. If so, fetch the binary and write it directly:
```js
const isScreenshotOnly = effectiveFormats.length === 1 && effectiveFormats[0] === 'screenshot';
const isImageOutput = options.output && /\.(png|jpg|jpeg|webp)$/i.test(options.output);
if (isScreenshotOnly && isImageOutput && result.success && result.data?.screenshot) {
const response = await fetch(result.data.screenshot);
const buffer = Buffer.from(await response.arrayBuffer());
fs.writeFileSync(options.output, buffer);
return;
}
```
## Environment
- firecrawl-cli 1.10.0
- Windows 11 / Node.js
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.