import { playwright } from '@bctrl/sdk';
import { z } from 'zod';
const session = await playwright.connect({ apiKey: '...' });
const page = session.page;
// Traditional: fast, reliable navigation
await page.goto('https://example.com');
await page.locator('#username').fill('[email protected]');
await page.locator('#password').fill('password');
await page.locator('button[type="submit"]').click();
// AI: handle dynamic content
await session.stagehand.act('Dismiss any popup or modal that appears');
// Traditional: known selectors
await page.locator('nav a[href="/products"]').click();
// AI: extract unstructured data
const products = await session.stagehand.extract(
'Get all products with name, price, and rating',
z.array(z.object({
name: z.string(),
price: z.number(),
rating: z.number()
}))
);
console.log(products);
await session.close();