diff --git a/README.md b/README.md index fe4123696..a970ab0d0 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ Response: |---------|-------------| | [**Scrape**](#scraping) | Convert any URL to markdown, HTML, screenshots, or structured JSON | | [**Search**](#search) | Search the web and get full page content from results | +| [**Browse**](#browse) | Let agents safely interact with the web | | [**Map**](#map) | Discover all URLs on a website instantly | | [**Crawl**](#crawling) | Scrape all URLs of a website with a single request | | [**Agent**](#agent) | Automated data gathering, just describe what you need | @@ -257,6 +258,75 @@ results = firecrawl.search( --- +## Browse + +Give your agents a secure browser environment. Let them run code safely to gather data and take action on the web. +```bash +curl -X POST 'https://api.firecrawl.dev/v2/browser' \ + -H 'Authorization: Bearer fc-YOUR_API_KEY' \ + -H 'Content-Type: application/json' +``` + +Response: +```json +{ + "success": true, + "id": "550e8400-e29b-41d4-a716-446655440000", + "cdpUrl": "wss://cdp-proxy.firecrawl.dev/cdp/550e8400-e29b-41d4-a716-446655440000", + "liveViewUrl": "https://liveview.firecrawl.dev/550e8400-e29b-41d4-a716-446655440000" +} +``` + +### Execute Code in the Browser + +Run Playwright code, Python, or bash commands remotely: +```javascript +import Firecrawl from '@mendable/firecrawl-js'; + +const firecrawl = new Firecrawl({ apiKey: "fc-YOUR_API_KEY" }); + +// 1. Launch a session +const session = await firecrawl.browser(); + +// 2. Execute code +const result = await firecrawl.browserExecute(session.id, { + code: ` + await page.goto("https://news.ycombinator.com"); + const title = await page.title(); + console.log(title); + `, + language: "node", +}); +console.log(result.result); // "Hacker News" + +// 3. Close +await firecrawl.deleteBrowser(session.id); +``` + +### Persistent Sessions + +Save and reuse browser state (cookies, localStorage) across sessions: +```javascript +const session = await firecrawl.browser({ + ttl: 600, + profile: { + name: "my-profile", + saveChanges: true, + }, +}); +``` + +### agent-browser (Bash Mode) + +Instead of writing Playwright code, agents can send simple bash commands via [agent-browser](https://github.com/vercel-labs/agent-browser): +```bash +firecrawl browser "open https://example.com" +firecrawl browser "snapshot" +firecrawl browser "click @e5" +``` + +--- + ## Agent **The easiest way to get data from the web.** Describe what you need, and our AI agent searches, navigates, and extracts it. No URLs required. @@ -530,6 +600,56 @@ results.data.web.forEach(result => { }); ``` +### Java + +Add the dependency ([Gradle/Maven](https://docs.firecrawl.dev/sdks/java#installation)): +```groovy +repositories { + mavenCentral() + maven { url 'https://jitpack.io' } +} + +dependencies { + implementation 'com.github.firecrawl:firecrawl-java-sdk:2.0' +} +``` +```java +import dev.firecrawl.client.FirecrawlClient; +import dev.firecrawl.model.*; + +FirecrawlClient client = new FirecrawlClient( + System.getenv("FIRECRAWL_API_KEY"), null, null +); + +// Scrape a single URL +ScrapeParams scrapeParams = new ScrapeParams(); +scrapeParams.setFormats(new String[]{"markdown"}); +FirecrawlDocument doc = client.scrapeURL("https://firecrawl.dev", scrapeParams); +System.out.println(doc.getMarkdown()); + +// Use the Agent for autonomous data gathering +AgentParams agentParams = new AgentParams("Find the founders of Stripe"); +AgentResponse start = client.createAgent(agentParams); +AgentStatusResponse result = client.getAgentStatus(start.getId()); +System.out.println(result.getData()); + +// Crawl a website (polls until completion) +CrawlParams crawlParams = new CrawlParams(); +crawlParams.setLimit(50); +CrawlStatusResponse job = client.crawlURL("https://docs.firecrawl.dev", crawlParams, null, 10); +for (FirecrawlDocument page : job.getData()) { + System.out.println(page.getMetadata().get("sourceURL")); +} + +// Search the web +SearchParams searchParams = new SearchParams("best web scraping tools 2024"); +searchParams.setLimit(10); +SearchResponse results = client.search(searchParams); +for (SearchResult r : results.getResults()) { + System.out.println(r.getTitle() + ": " + r.getUrl()); +} +``` + ### Community SDKs - [Go SDK](https://github.com/mendableai/firecrawl-go)