fix: download screenshot binary when output targets an image file#94
Open
saivedant169 wants to merge 1 commit intofirecrawl:mainfrom
Open
fix: download screenshot binary when output targets an image file#94saivedant169 wants to merge 1 commit intofirecrawl:mainfrom
saivedant169 wants to merge 1 commit intofirecrawl:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #82
What
firecrawl scrape --format screenshot -o output.pngwrites the CDN URL as plain text to the file instead of the actual PNG binary. Runningfile output.pngshows ASCII text, not image data.Why
handleScrapeCommanddelegates tohandleScrapeOutput, which callsformatScreenshotOutput()for the screenshot format. That function returns the URL as a string, andwriteOutputwrites it with utf-8 encoding. The binary is never fetched.The multi-URL path (
handleAllScrapeCommand, around line 598) already handles this correctly — it callsfetch()on the screenshot URL, converts to aBuffer, 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:
fetch()is called and binary buffer is written when output is.pngfetch()is NOT called when output is.txt(falls through to existing text behavior)All 276 tests pass. Type check and formatting clean.