-
Notifications
You must be signed in to change notification settings - Fork 35
Screenshot format writes URL text to file instead of downloading image binary #82
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
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:
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:
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