/** * Stagehand example: before_checkout before clicking through, after_checkout after. * * npm i @browserbasehq/stagehand * npx tsx integrations/stagehand/example.ts https://allbirds.com/products/mens-wool-runners * * This file imports Stagehand, which the ARC app does not install, so the repo's * tsconfig excludes it. checkout-guard.ts holds the ARC part and is tested. * The attempt stops at the checkout page. It never enters payment details. */ import { Stagehand } from "@browserbasehq/stagehand"; import { withArcCheckout } from "./checkout-guard.ts"; const productUrl = process.argv[2] ?? "https://allbirds.com/products/mens-wool-runners"; const stagehand = new Stagehand({ env: "LOCAL" }); await stagehand.init(); const page = stagehand.page; const result = await withArcCheckout( productUrl, async (arc, mark) => { console.log("ARC best_route:", arc.route, arc.reaches_checkout, arc.blockers); await page.goto(productUrl); await page.act("add this product to the cart"); mark("cart"); await page.act("open the cart and go to checkout"); const atCheckout = /checkout/i.test(page.url()); if (!atCheckout) { const wall = await page.extract("If a captcha, login wall or bot block is shown, name it as captcha, login_wall or bot_block. Otherwise say none."); const text = String(wall.extraction ?? "none"); const blocker = text.includes("captcha") ? "captcha" : text.includes("login") ? "login_wall" : text.includes("bot") ? "bot_block" : "none"; return { furthest_step: "cart", blocker }; } return { furthest_step: "checkout", blocker: "none" }; }, { agentName: "stagehand-example" }, ); console.log(JSON.stringify(result)); await stagehand.close();