Repository navigation
Conversation
Add 'headers' option to FirecrawlClientOptions to allow users to specify custom HTTP headers that will be included in all API requests. This enables self-hosted Firecrawl users to: - Pass Cloudflare Access headers (CF-Access-Client-Id, CF-Access-Client-Secret) - Use custom authorization schemes - Work with reverse proxy authentication - Add custom tracking headers Closes firecrawl#2814
This fix addresses Issue firecrawl#2809 where clicking elements in dynamic dropdowns fails with 'Element not found' because the next action executes before the DOM has updated. The fix automatically inserts a 500ms wait after each click action to allow dynamic content (dropdowns, modals, etc.) to render before the next action is executed. Without this fix, users had to manually add a screenshot action between click actions to work around the timing issue.
…irecrawl#2891) - When agent job is in progress (status=processing), creditsUsed was not being returned in the response - Now attempts to fetch real-time credits from EXTRACT_V3_BETA_URL service - Falls back to 0 if external service is unavailable - Applied same fix to extract-status.ts for agent kind requests
When a URL has .pdf extension but returns HTML content (webpage with embedded PDF), the PDF engine now detects this and throws EngineUnsuccessfulError to fall back to other engines like Playwright. This fixes Issue firecrawl#839 where URLs like https://www.gamweb.com/assets/files/lsk.pdf return HTML instead of a raw PDF file. Changes: - Add isHtmlBuffer() function to detect HTML content in pdfUtils.ts - Check for HTML content in PDF engine before attempting PDF parsing - Add unit tests for isHtmlBuffer()
This fix addresses Issue firecrawl#2964 by adding a new environment variable SELF_HOSTED_DOMAIN that allows self-hosted users to specify a custom hostname when running behind a reverse proxy. Previously, the API always returned URLs with the internal hostname (localhost:3002) regardless of the external domain being used. Changes: - Add SELF_HOSTED_DOMAIN config option - Create getHostname() helper function in host-utils.ts - Update v1 and v2 controllers to use custom hostname when set - Document the new environment variable in .env.example
There was a problem hiding this comment.
6 issues found across 17 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/api/src/config.ts">
<violation number="1" location="apps/api/src/config.ts:38">
P2: `SELF_HOSTED_DOMAIN` is accepted as an arbitrary string, but it is later used as a hostname in URL construction, allowing malformed values to generate invalid API URLs.</violation>
</file>
<file name="apps/api/src/controllers/v2/extract-status.ts">
<violation number="1" location="apps/api/src/controllers/v2/extract-status.ts:60">
P2: New outbound `fetch` in status request path lacks explicit timeout/abort, allowing upstream slowness to delay status responses.</violation>
</file>
<file name="apps/api/src/controllers/v1/crawl-status.ts">
<violation number="1" location="apps/api/src/controllers/v1/crawl-status.ts:278">
P2: `next` URL construction assumes host-only output from `getHostname`, but helper/config allow full URL strings, which can produce malformed pagination links.</violation>
</file>
<file name="apps/api/src/scraper/scrapeURL/engines/pdf/index.ts">
<violation number="1" location="apps/api/src/scraper/scrapeURL/engines/pdf/index.ts:77">
P1: HTML short-circuit now masks PDF anti-bot failures as generic engine misses, bypassing PDFAntibotError retry/prefetch handling.</violation>
</file>
<file name="apps/api/src/lib/host-utils.ts">
<violation number="1" location="apps/api/src/lib/host-utils.ts:10">
P2: Empty `SELF_HOSTED_DOMAIN` is treated as a valid hostname, which can generate malformed absolute URLs.</violation>
</file>
<file name="apps/api/src/scraper/scrapeURL/engines/fire-engine/index.ts">
<violation number="1" location="apps/api/src/scraper/scrapeURL/engines/fire-engine/index.ts:308">
P2: Chrome-CDP runtime estimate is stale: newly inserted 500ms post-click waits are not included in `fireEngineMaxReasonableTime`, underestimating expected duration for click-heavy actions.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| // downloaded content isn't a valid PDF | ||
| // Check if it's HTML (webpage with embedded PDF) - fall back to other engines | ||
| if (isHtmlBuffer(file.buffer)) { | ||
| throw new EngineUnsuccessfulError("pdf"); |
There was a problem hiding this comment.
P1: HTML short-circuit now masks PDF anti-bot failures as generic engine misses, bypassing PDFAntibotError retry/prefetch handling.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/api/src/scraper/scrapeURL/engines/pdf/index.ts, line 77:
<comment>HTML short-circuit now masks PDF anti-bot failures as generic engine misses, bypassing PDFAntibotError retry/prefetch handling.</comment>
<file context>
@@ -72,6 +72,10 @@ export async function scrapePDF(meta: Meta): Promise<EngineScrapeResult> {
// downloaded content isn't a valid PDF
+ // Check if it's HTML (webpage with embedded PDF) - fall back to other engines
+ if (isHtmlBuffer(file.buffer)) {
+ throw new EngineUnsuccessfulError("pdf");
+ }
if (meta.pdfPrefetch === undefined) {
</file context>
| FIRECRAWL_APP_HOST: z.string().default("firecrawl-app-service"), | ||
| FIRECRAWL_APP_PORT: z.string().default("3002"), | ||
| FIRECRAWL_APP_SCHEME: z.string().default("http"), | ||
| SELF_HOSTED_DOMAIN: z.string().optional(), |
There was a problem hiding this comment.
P2: SELF_HOSTED_DOMAIN is accepted as an arbitrary string, but it is later used as a hostname in URL construction, allowing malformed values to generate invalid API URLs.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/api/src/config.ts, line 38:
<comment>`SELF_HOSTED_DOMAIN` is accepted as an arbitrary string, but it is later used as a hostname in URL construction, allowing malformed values to generate invalid API URLs.</comment>
<file context>
@@ -35,6 +35,7 @@ const configSchema = z.object({
FIRECRAWL_APP_HOST: z.string().default("firecrawl-app-service"),
FIRECRAWL_APP_PORT: z.string().default("3002"),
FIRECRAWL_APP_SCHEME: z.string().default("http"),
+ SELF_HOSTED_DOMAIN: z.string().optional(),
LOGGING_LEVEL: z.string().optional(),
</file context>
| SELF_HOSTED_DOMAIN: z.string().optional(), | |
| SELF_HOSTED_DOMAIN: z | |
| .string() | |
| .trim() | |
| .regex( | |
| /^(?!.*:\/\/)(?!\s*$)([a-zA-Z0-9.-]+|\[[0-9a-fA-F:]+\])(?::\d{1,5})?$/, | |
| "SELF_HOSTED_DOMAIN must be a hostname (or host:port) without scheme/path", | |
| ) | |
| .optional(), |
| let creditsUsed: number | undefined = agent?.credits_cost; | ||
| if (!agent && config.EXTRACT_V3_BETA_URL) { | ||
| try { | ||
| const creditsRequest = await fetch( |
There was a problem hiding this comment.
P2: New outbound fetch in status request path lacks explicit timeout/abort, allowing upstream slowness to delay status responses.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/api/src/controllers/v2/extract-status.ts, line 60:
<comment>New outbound `fetch` in status request path lacks explicit timeout/abort, allowing upstream slowness to delay status responses.</comment>
<file context>
@@ -53,6 +53,37 @@ export async function extractStatusController(
+ let creditsUsed: number | undefined = agent?.credits_cost;
+ if (!agent && config.EXTRACT_V3_BETA_URL) {
+ try {
+ const creditsRequest = await fetch(
+ config.EXTRACT_V3_BETA_URL +
+ "/v2/extract/" +
</file context>
| (outputBulkA.total ?? 0) > start + iteratedOver || | ||
| outputBulkA.status !== "completed" | ||
| ? `${req.protocol}://${req.get("host")}/v1/${isBatch ? "batch/scrape" : "crawl"}/${req.params.jobId}?skip=${start + iteratedOver}${req.query.limit ? `&limit=${req.query.limit}` : ""}` | ||
| ? `${req.protocol}://${getHostname(req)}/v1/${isBatch ? "batch/scrape" : "crawl"}/${req.params.jobId}?skip=${start + iteratedOver}${req.query.limit ? `&limit=${req.query.limit}` : ""}` |
There was a problem hiding this comment.
P2: next URL construction assumes host-only output from getHostname, but helper/config allow full URL strings, which can produce malformed pagination links.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/api/src/controllers/v1/crawl-status.ts, line 278:
<comment>`next` URL construction assumes host-only output from `getHostname`, but helper/config allow full URL strings, which can produce malformed pagination links.</comment>
<file context>
@@ -274,7 +275,7 @@ export async function crawlStatusController(
(outputBulkA.total ?? 0) > start + iteratedOver ||
outputBulkA.status !== "completed"
- ? `${req.protocol}://${req.get("host")}/v1/${isBatch ? "batch/scrape" : "crawl"}/${req.params.jobId}?skip=${start + iteratedOver}${req.query.limit ? `&limit=${req.query.limit}` : ""}`
+ ? `${req.protocol}://${getHostname(req)}/v1/${isBatch ? "batch/scrape" : "crawl"}/${req.params.jobId}?skip=${start + iteratedOver}${req.query.limit ? `&limit=${req.query.limit}` : ""}`
: undefined,
};
</file context>
| * This is useful when running behind a reverse proxy. | ||
| */ | ||
| export function getHostname(req: Request): string { | ||
| return config.SELF_HOSTED_DOMAIN ?? req.get("host") ?? "localhost"; |
There was a problem hiding this comment.
P2: Empty SELF_HOSTED_DOMAIN is treated as a valid hostname, which can generate malformed absolute URLs.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/api/src/lib/host-utils.ts, line 10:
<comment>Empty `SELF_HOSTED_DOMAIN` is treated as a valid hostname, which can generate malformed absolute URLs.</comment>
<file context>
@@ -0,0 +1,11 @@
+ * This is useful when running behind a reverse proxy.
+ */
+export function getHostname(req: Request): string {
+ return config.SELF_HOSTED_DOMAIN ?? req.get("host") ?? "localhost";
+}
</file context>
| }), | ||
| // Include specified actions, with automatic waits after clicks to allow | ||
| // dynamic content (dropdowns, modals, etc.) to render | ||
| ...insertWaitsAfterClicks( |
There was a problem hiding this comment.
P2: Chrome-CDP runtime estimate is stale: newly inserted 500ms post-click waits are not included in fireEngineMaxReasonableTime, underestimating expected duration for click-heavy actions.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/api/src/scraper/scrapeURL/engines/fire-engine/index.ts, line 308:
<comment>Chrome-CDP runtime estimate is stale: newly inserted 500ms post-click waits are not included in `fireEngineMaxReasonableTime`, underestimating expected duration for click-heavy actions.</comment>
<file context>
@@ -281,11 +303,14 @@ export async function scrapeURLWithFireEngineChromeCDP(
- }),
+ // Include specified actions, with automatic waits after clicks to allow
+ // dynamic content (dropdowns, modals, etc.) to render
+ ...insertWaitsAfterClicks(
+ (meta.options.actions ?? []).map(action => {
+ const { metadata: _, ...rest } = action as InternalAction;
</file context>
This fix addresses Issue #2964 by adding a new environment variable
SELF_HOSTED_DOMAIN that allows self-hosted users to specify a custom
hostname when running behind a reverse proxy.
Previously, the API always returned URLs with the internal hostname
(localhost:3002) regardless of the external domain being used.
Changes:
Usage:
Set the environment variable SELF_HOSTED_DOMAIN to your custom domain:
This will cause the API to return URLs like:
instead of:
Summary by cubic
Add custom hostname support for self‑hosted deployments via
SELF_HOSTED_DOMAIN, so API responses return external URLs instead of internal hosts (fixes #2964). Also improves scraping reliability, PDF handling, credits reporting, and adds custom headers support in the JS SDK.New Features
SELF_HOSTED_DOMAINenv var withgetHostnamehelper; v1/v2 controllers now build URLs using your external domain. SetSELF_HOSTED_DOMAIN=firecrawl.example.com.headersoption to include custom HTTP headers in all requests (e.g., Cloudflare Access, custom auth).Bug Fixes
creditsUsedwhile processing by queryingEXTRACT_V3_BETA_URL, falling back to 0 if unavailable.Written for commit d477a16. Summary will update on new commits.