Created
June 4, 2026 19:38
-
-
Save shrey150/38304c06e835c8fad742f29099474e60 to your computer and use it in GitHub Desktop.
Browserbase x Anthropic Opus 4.8 Webinar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Stagehand + Browserbase: an AI agent that researches SEC filings on its own. | |
| // | |
| // We give Stagehand a plain-English task, point it at SEC EDGAR, and let its | |
| // `agent` autonomously navigate, read 10-Q filings, and build a comparison | |
| // table — no selectors, no scraping code, no per-site logic. | |
| import "dotenv/config"; | |
| import { exec } from "node:child_process"; | |
| import { Stagehand } from "@browserbasehq/stagehand"; | |
| // The model that powers both the planning and the on-page actions. | |
| const MODEL = "anthropic/claude-opus-4-8"; | |
| // The whole "program" is just this instruction. Notice it's the kind of thing | |
| // you'd hand a human intern — goals and guardrails, not click-by-click steps. | |
| const TASK = `You are researching SEC filings on SEC EDGAR. For EACH of these three companies — Snowflake (ticker SNOW), Datadog (ticker DDOG), and MongoDB (ticker MDB): | |
| 1. Find the company's MOST RECENT 10-Q filing (use EDGAR full-text search at https://efts.sec.gov or company search at https://www.sec.gov/cgi-bin/browse-edgar). | |
| 2. Open the ACTUAL 10-Q document (the primary financial .htm document — NOT the filing index/cover page and NOT an exhibit). | |
| 3. From inside that document extract: (a) total revenue for the most recent quarter, with the dollar figure; (b) year-over-year revenue growth %; (c) RPO (remaining performance obligations) if disclosed; (d) the single top/most significant risk factor. | |
| Do all three companies, then output a clear 3-company comparison table (Company, filing period, total revenue, YoY growth, RPO, top risk factor). Report the verbatim numbers you actually saw. Write "N/A" if you cannot find a value — do not guess.`; | |
| // The browser runs in the cloud on Browserbase, so it has no visible window. | |
| // This pops open the Browserbase dashboard session page in your local browser. | |
| // (You must be logged into browserbase.com.) That page is a richer live view | |
| // than the raw devtools URL: embedded live screen + logs, action timeline, and | |
| // network activity — and it becomes the full session replay once the run ends. | |
| function openDashboard(url: string) { | |
| if (!url) return; | |
| const cmd = | |
| process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open"; | |
| exec(`${cmd} "${url}"`); | |
| } | |
| async function main() { | |
| // `env: "BROWSERBASE"` spins up a real, cloud-hosted Chrome session. | |
| // Swap to `env: "LOCAL"` to run the same script against a browser on your machine. | |
| // API keys (BROWSERBASE_API_KEY, BROWSERBASE_PROJECT_ID, ANTHROPIC_API_KEY) | |
| // are read automatically from your .env. | |
| const stagehand = new Stagehand({ | |
| env: "BROWSERBASE", | |
| model: MODEL, | |
| verbose: 1, // 0 = quiet, 1 = key steps, 2 = full firehose | |
| }); | |
| await stagehand.init(); | |
| // Two handy URLs every session exposes: | |
| // browserbaseSessionURL → authenticated dashboard: live view + inspector, | |
| // then the full replay once the run finishes | |
| // browserbaseDebugURL → raw devtools live view (no login required) | |
| console.log(`Stagehand session started`); | |
| console.log(`Dashboard: ${stagehand.browserbaseSessionURL}`); | |
| console.log(`Devtools: ${stagehand.browserbaseDebugURL}\n`); | |
| openDashboard(stagehand.browserbaseSessionURL ?? ""); | |
| // Drop the agent onto a starting page. It's free to navigate anywhere from here. | |
| const page = stagehand.context.pages()[0]; | |
| await page.goto("https://efts.sec.gov"); | |
| // `agent` is the autonomous loop: it looks at the page, decides the next | |
| // action, takes it, and repeats until the task is done. | |
| // mode "hybrid" → can both read the DOM and click by coordinates (vision) | |
| // executionModel → the model used to carry out each individual action | |
| const agent = stagehand.agent({ | |
| model: MODEL, | |
| mode: "hybrid", | |
| executionModel: MODEL, | |
| }); | |
| // Hand over the task and let it run. `maxSteps` is a safety budget so a | |
| // confused agent can't loop forever. | |
| const result = await agent.execute({ | |
| instruction: TASK, | |
| maxSteps: 50, | |
| }); | |
| // `result.message` is the agent's final answer — here, the comparison table. | |
| console.log(`\nResult:\n${result.message}`); | |
| // Always close the session to release the cloud browser. | |
| await stagehand.close(); | |
| } | |
| main().catch((err) => { | |
| console.error(err); | |
| process.exit(1); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment