Streaming Response

Monitor task progress in real-time using two streaming methods.

Stream Agent Step Updates

The stream() method gets the latest step on every change.

1import { BrowserUseClient } from "browser-use-sdk";
2import { z } from "zod";
3
4const client = new BrowserUseClient();
5
6const TaskOutput = z.object({
7 posts: z.array(
8 z.object({
9 title: z.string(),
10 url: z.string(),
11 }),
12 ),
13});
14
15const task = await client.tasks.createTask({
16 task: "Search for the top 10 Hacker News posts and return the title and url.",
17 schema: TaskOutput,
18});
19
20for await (const step of task.stream()) {
21 console.log(step);
22}
23
24const result = await task.complete();
25
26for (const post of result.parsed.posts) {
27 console.log(`${post.title} - ${post.url}`);
28}

Watch All Updates

The watch() method lets you see the entire state of the task. The generator emits the latest state whenever the task is updated.

1import { BrowserUseClient } from "browser-use-sdk";
2import { z } from "zod";
3
4const client = new BrowserUseClient();
5
6const TaskOutput = z.object({
7 posts: z.array(
8 z.object({
9 title: z.string(),
10 url: z.string(),
11 }),
12 ),
13});
14
15const task = await client.tasks.createTask({
16 task: "Search for the top 10 Hacker News posts and return the title and url.",
17 schema: TaskOutput,
18});
19
20for await (const update of task.watch()) {
21 console.log(update);
22
23 if (update.data.status === "finished") {
24 for (const post of update.data.parsed.posts) {
25 console.log(`${post.title} - ${post.url}`);
26 }
27 }
28}

Key Differences

  • .stream(): Only streams agent steps (recommended)
  • .watch(): Streams all updates including status changes

Make sure to use .stream() for progress monitoring and .complete() for the final response.