Implement FireCrawl webhook signature validation and event handling.
Use when setting up webhook endpoints, implementing signature verification,
or handling FireCrawl event notifications securely.
Trigger with phrases like "firecrawl webhook", "firecrawl events",
"firecrawl webhook signature", "handle firecrawl events", "firecrawl notifications".
Handle Firecrawl webhooks for real-time notifications on async crawl and batch scrape jobs. Instead of polling checkCrawlStatus, configure a webhook URL and Firecrawl will POST events as pages are scraped and jobs complete. Signed with HMAC-SHA256 via X-Firecrawl-Signature.
// Fall back to polling if webhook delivery fails
async function pollWithFallback(jobId: string, timeoutMs = 600000) {
const deadline = Date.now() + timeoutMs;
let interval = 2000;
while (Date.now() < deadline) {
const status = await firecrawl.checkCrawlStatus(jobId);
if (status.status === "completed") {
return status.data;
}
if (status.status === "failed") {
throw new Error(`Crawl failed: ${status.error}`);
}
console.log(`Polling: ${status.completed}/${status.total} pages`);
await new Promise(r => setTimeout(r, interval));
interval = Math.min(interval * 1.5, 30000);
}
throw new Error(`Crawl timed out after ${timeoutMs}ms`);
}
Error Handling
Issue
Cause
Solution
Webhook not received
URL not publicly accessible
Use ngrok for local dev, verify HTTPS
Signature mismatch
Wrong secret or body encoding
Use raw body for HMAC, not parsed JSON
Duplicate events
Firecrawl retry on non-2xx
Make handler idempotent (dedup by job ID)
Webhook timeout
Processing takes too long
Return 200 immediately, process async
Lost events
3 failed retries
Implement polling fallback
Examples
Local Development with ngrok
set -euo pipefail
# Start ngrok tunnel for local webhook testing
ngrok http 3000
# Use the ngrok URL as your webhook endpoint
# https://abc123.ngrok.io/webhooks/firecrawl