Firecrawl
The @mastra/browser-firecrawl package provides browser automation using the Firecrawl Browser Sandbox. It provisions remote browser sessions through the Firecrawl API and drives them with the same deterministic, accessibility-first tools as AgentBrowser.
FirecrawlBrowser extends AgentBrowser, so agents get the same toolset (browser_goto, browser_snapshot, browser_click, and so on) while the browser itself runs in Firecrawl's hosted infrastructure. No local Chromium install is needed.
When to use FirecrawlWhen to use Firecrawl的直接链接
Use Firecrawl when you need:
- Hosted browser sessions without managing local Chromium binaries
- Browser automation in environments that can't launch a local browser
- Per-thread sandbox isolation with automatic session cleanup
- Named Firecrawl profiles that persist cookies and login state between sessions
QuickstartQuickstart的直接链接
Install the package:
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/browser-firecrawl
pnpm add @mastra/browser-firecrawl
yarn add @mastra/browser-firecrawl
bun add @mastra/browser-firecrawl
Set your Firecrawl API key:
FIRECRAWL_API_KEY=fc-...
Create a browser instance and assign it to an agent:
import { Agent } from '@mastra/core/agent'
import { FirecrawlBrowser } from '@mastra/browser-firecrawl'
const browser = new FirecrawlBrowser({
apiKey: process.env.FIRECRAWL_API_KEY,
})
export const firecrawlAgent = new Agent({
id: 'firecrawl-agent',
name: 'Firecrawl Agent',
model: 'openai/gpt-5.6-sol',
browser,
instructions: `You are a web automation assistant.
When interacting with pages:
1. Use browser_snapshot to get the current page state and element refs
2. Use the refs (like @e1, @e2) to target elements for clicks and typing
3. After actions, take another snapshot to verify the result`,
})
If apiKey is omitted, the provider reads FIRECRAWL_API_KEY from the environment.
Session scopeSession scope的直接链接
FirecrawlBrowser follows the same scope option as AgentBrowser:
'thread'(default): Each conversation thread gets its own Firecrawl sandbox session. Sessions are deleted when the thread's browser closes.'shared': One Firecrawl sandbox session is shared across all threads and deleted when the browser closes.
const browser = new FirecrawlBrowser({
scope: 'shared',
})
Session optionsSession options的直接链接
Pass Firecrawl-specific session options under the firecrawl key. These map to the Firecrawl browser() API:
const browser = new FirecrawlBrowser({
firecrawl: {
ttl: 600,
activityTtl: 120,
profile: {
name: 'my-profile',
saveChanges: true,
},
},
})
ttl: Maximum session lifetime in seconds.activityTtl: Idle timeout in seconds before Firecrawl recycles the session.profile: Named Firecrawl profile that persists cookies and login state. SetsaveChanges: trueto save profile changes when the session ends.
The nested firecrawl.profile option refers to a profile stored in Firecrawl's infrastructure. It's different from the top-level profile option inherited from AgentBrowser, which is a local Playwright user-data directory path.
Self-hosted FirecrawlSelf-hosted Firecrawl的直接链接
To use a self-hosted Firecrawl API, set apiUrl:
const browser = new FirecrawlBrowser({
apiUrl: 'https://firecrawl.internal.example.com',
})