Firecrawl is a tool for crawling websites and extracting clean markdown that’s structured in an LLM-ready format.Here are two examples of how to use Firecrawl with Trigger.dev:
This task crawls a website and returns the crawlResult object. You can set the limit parameter to control the number of URLs that are crawled.
trigger/firecrawl-url-crawl.ts
Copy
Ask AI
import FirecrawlApp from "@mendable/firecrawl-js";import { task } from "@trigger.dev/sdk/v3";// Initialize the Firecrawl client with your API keyconst firecrawlClient = new FirecrawlApp({ apiKey: process.env.FIRECRAWL_API_KEY, // Get this from your Firecrawl dashboard});export const firecrawlCrawl = task({ id: "firecrawl-crawl", run: async (payload: { url: string }) => { const { url } = payload; // Crawl: scrapes all the URLs of a web page and return content in LLM-ready format const crawlResult = await firecrawlClient.crawlUrl(url, { limit: 100, // Limit the number of URLs to crawl scrapeOptions: { formats: ["markdown", "html"], }, }); if (!crawlResult.success) { throw new Error(`Failed to crawl: ${crawlResult.error}`); } return { data: crawlResult, }; },});
This task scrapes a single URL and returns the scrapeResult object.
trigger/firecrawl-url-scrape.ts
Copy
Ask AI
import FirecrawlApp, { ScrapeResponse } from "@mendable/firecrawl-js";import { task } from "@trigger.dev/sdk/v3";// Initialize the Firecrawl client with your API keyconst firecrawlClient = new FirecrawlApp({ apiKey: process.env.FIRECRAWL_API_KEY, // Get this from your Firecrawl dashboard});export const firecrawlScrape = task({ id: "firecrawl-scrape", run: async (payload: { url: string }) => { const { url } = payload; // Scrape: scrapes a URL and get its content in LLM-ready format (markdown, structured data via LLM Extract, screenshot, html) const scrapeResult = (await firecrawlClient.scrapeUrl(url, { formats: ["markdown", "html"], })) as ScrapeResponse; if (!scrapeResult.success) { throw new Error(`Failed to scrape: ${scrapeResult.error}`); } return { data: scrapeResult, }; },});