> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentcard.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Browserbase

> Use Agentcard with Browserbase to let your agent make purchases with your users' cards.

[Browserbase](https://www.browserbase.com) runs the browser your agent shops in. The Agentcard SDK attaches to it through Playwright over the session's `connectUrl`, the same way it attaches to any CDP browser.

You need a user with a card in the Vault first. See [Adding a card](https://docs.agentcard.com/vault/adding-a-card.md).

## Install

```bash theme={null}
npm i @agent-cards/sdk @browserbasehq/sdk playwright-core
```

## Connect and attach

```ts theme={null}
import Browserbase from '@browserbasehq/sdk';
import { chromium } from 'playwright-core';
import { VaultClient, attachToPlaywright } from '@agent-cards/sdk';

const bb = new Browserbase({ apiKey: process.env.BROWSERBASE_API_KEY! });
const session = await bb.sessions.create({ projectId: process.env.BROWSERBASE_PROJECT_ID! });
const browser = await chromium.connectOverCDP(session.connectUrl);

// Reuse the default context and page so the session recording stays intact.
const context = browser.contexts()[0];
// Keep the store from starting a service worker, before any page loads.
await context.addInitScript(
  'try { if (navigator.serviceWorker) navigator.serviceWorker.register = async () => undefined; } catch {}',
);
const page = context.pages()[0];

const vault = new VaultClient({
  clientId: process.env.AGENTCARD_CLIENT_ID!,
  clientSecret: process.env.AGENTCARD_CLIENT_SECRET!,
});
await vault.syncRegistry();

const checkout = await attachToPlaywright(page, {
  vault,
  user: 'usr_8f3k2m',
  merchant: 'shop.example.com',
  amount: 2306,
  currency: 'usd',
  onApprovalUrl: (url) => sendToUser(url),
});

// Now let the agent shop.
await page.goto('https://shop.example.com');
```

Attach before the agent reaches the payment form.

Browserbase's default context lets a store start a service worker, and the SDK cannot pause a card request a service worker sends. The init script blocks service workers on that default context, so you keep the session recording without creating a new context. [Block service workers](https://docs.agentcard.com/vault/creating-a-cart.md#block-service-workers) explains what changes for the store.

A store that already runs a service worker when you attach makes `attachToPlaywright` throw:

```text theme={null}
Service workers are active; use a checkout context created with serviceWorkers: "block".
```

Add the init script before the session's first navigation. If you load a saved Browserbase context and attach still throws, the context carries a service worker from an earlier session. Create checkout sessions without that saved context, or attach through CDP with `serviceWorkers: 'bypass'`, as [Your own browser](https://docs.agentcard.com/vault/integrations/agent-browsers/your-own.md#level-2-you-speak-cdp-directly) shows.

After the run, the session recording is at `https://browserbase.com/sessions/${session.id}`, which is useful for reviewing a checkout that needed a human.

## Next

The rest of the flow is identical to any Vault purchase: placeholder card, passkey approval, real card swapped in, confirm with the merchant. Follow the [Vault Quickstart](https://docs.agentcard.com/vault/quickstart.md) from step 4, or read [Completing a purchase](https://docs.agentcard.com/vault/completing-a-purchase.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.