Get started with Browser Use Cloud API using Node.js
The repository is available on GitHub
npm install browser-use-sdk
import BrowserUse from "browser-use-sdk";
const client = new BrowserUse({
apiKey: "bu_...",
});
const result = await client.tasks.run({
task: "Search for the top 10 Hacker News posts and return the title and url.",
});
console.log(result.doneOutput);
The full API of this library can be found in api.md.
import z from "zod";
const TaskOutput = z.object({
posts: z.array(
z.object({
title: z.string(),
url: z.string(),
})
),
});
const result = await client.tasks.run({
task: "Search for the top 10 Hacker News posts and return the title and url.",
schema: TaskOutput,
});
for (const post of result.parsedOutput.posts) {
console.log(`${post.title} - ${post.url}`);
}
const task = await browseruse.tasks.create({
task: "Search for the top 10 Hacker News posts and return the title and url.",
schema: TaskOutput,
});
const stream = browseruse.tasks.stream({
taskId: task.id,
schema: TaskOutput,
});
for await (const msg of stream) {
switch (msg.status) {
case "started":
console.log(`started: ${msg.data.session.liveUrl}`);
break;
case "paused":
case "stopped":
console.log(`running: ${msg}`);
break;
case "finished":
console.log(`done:`);
for (const post of msg.parsedOutput.posts) {
console.log(`${post.title} - ${post.url}`);
}
break;
}
}
We encourage you to use the SDK functions that verify and parse webhook events.
import {
verifyWebhookEventSignature,
type WebhookAgentTaskStatusUpdatePayload,
} from "browser-use-sdk/lib/webhooks";
export async function POST(req: Request) {
const signature = req.headers["x-browser-use-signature"] as string;
const timestamp = req.headers["x-browser-use-timestamp"] as string;
const event = await verifyWebhookEventSignature(
{
body,
signature,
timestamp,
},
{
secret: SECRET_KEY,
}
);
if (!event.ok) {
return;
}
switch (event.event.type) {
case "agent.task.status_update":
break;
case "test":
break;
default:
break;
}
}
Was this page helpful?