Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Last active December 22, 2024 17:05
Show Gist options
  • Save vielhuber/94f1314035718d72060c40e84749b975 to your computer and use it in GitHub Desktop.
Save vielhuber/94f1314035718d72060c40e84749b975 to your computer and use it in GitHub Desktop.
stagehand browser control with ai #js

installation

  • echo "23.5.0" > ".nvmrc"
  • node --version && npm --version (at least node >=20 and npm >=9)
  • npm install @browserbasehq/stagehand zod
  • npx playwright install-deps
  • npm exec playwright install
  • echo "OPENAI_API_KEY=sk-..." > .env

usage

  • node script.js

example

import { Stagehand } from '@browserbasehq/stagehand';
const stagehand = new Stagehand({ env: "LOCAL", debugDom: true, enableCaching: true });
await stagehand.init();

await stagehand.page.goto('https://vielhuber.de');
await stagehand.act({ action: 'click on "Blog".' });
await stagehand.act({ action: 'click on the newest blog entry.' });

await stagehand.close();

//const actions = await stagehand.observe();
//console.log(actions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment