Open History to see the last commit
@tanstack/ai-computer-playwright#
Playwright browser driver for TanStack AI computer use.
Let the model see and control a browser page. Each thread gets its own page. The driver takes screenshots of the page and sends mouse and keyboard input to it.
Installation#
pnpm add @tanstack/ai-computer-playwright @tanstack/ai-computer-use playwright-core
npx playwright-core install chromium
Usage#
- Create the computer with
playwrightComputer():
import { createComputerUse } from '@tanstack/ai-computer-use'
import { playwrightComputer } from '@tanstack/ai-computer-playwright'
const computerUse = createComputerUse({
driver: playwrightComputer({ startUrl: 'https://tanstack.com' }),
})
- Give
computerUse.tools,middleware,interrupt, and the thread id tochat(). The model can now use a page.
Each thread gets its own browser context, with its own cookies and storage, and one page. Chromium starts on the first action. computerUse.close() closes it.
playwrightComputer() takes these options. All of them are optional:
startUrl: the URL that each new page opens.display: the viewport of each page in pixels. The default is 1280 x 800.browser: a PlaywrightBrowserthat makes the pages.createComputerUsenever closes it.launch: the options forchromium.launch().
Share one page#
To drive a page that you already have, use createPlaywrightComputerDriver. Every thread shares this page, so it serves one conversation at a time.
import { createComputerUse } from '@tanstack/ai-computer-use'
import { createPlaywrightComputerDriver } from '@tanstack/ai-computer-playwright'
const computerUse = createComputerUse({
driver: createPlaywrightComputerDriver({ page }),
})
- The driver accepts any object with the shape of a Playwright
Page. A page fromplaywright,playwright-core, or@playwright/testworks. - The driver reads the viewport size once, when you create it. A page with no viewport size throws an error.
- Your app owns this page.
createComputerUsenever closes it.
What the driver does#
navigateopens a URL in the page. ThencomputerUse.toolshas thenavigatetool.- The
backandforwardmouse buttons go back and forward in the page history. - Key names go to Playwright as they are.
['Control', 's']becomesControl+s. zoomtakes a screenshot of one region of the page.
Read the full guide: Computer use drivers.
Tests#
pnpm --filter @tanstack/ai-computer-playwright test:lib