10
10
11
11
const browseruse = new BrowserUseClient ( {
12
12
apiKey : process . env . BROWSER_USE_API_KEY ! ,
13
- environment : "https://api.browser-use.com/api/v2" ,
14
13
} ) ;
15
14
16
15
// Basic ---------------------------------------------------------------------
@@ -19,20 +18,45 @@ async function basic() {
19
18
console . log ( "Basic: Creating task and starting stream..." ) ;
20
19
21
20
const task = await browseruse . tasks . createTask ( {
22
- task : "What's the weather in SF and what's the temperature ?" ,
23
- agent : { llm : "gemini-2.5-flash" } ,
21
+ task : "What's the weather and temperature in SF, NY, and LA ?" ,
22
+ llm : "gemini-2.5-flash" ,
24
23
} ) ;
25
24
26
- for await ( const msg of task . stream ( ) ) {
27
- console . log ( msg ) ;
25
+ console . log ( `task.id: ${ task . id } ` ) ;
26
+
27
+ const counter = { current : 0 } ;
28
+
29
+ for await ( const step of task . stream ( ) ) {
30
+ console . log ( `STREAM 1: ${ step . number } ` ) ;
31
+
32
+ counter . current ++ ;
33
+
34
+ if ( counter . current === 2 ) {
35
+ break ;
36
+ }
37
+ }
38
+
39
+ for await ( const step of task . stream ( ) ) {
40
+ counter . current ++ ;
41
+
42
+ console . log ( `STREAM 2: ${ step . number } ` ) ;
28
43
}
29
44
30
45
const result = await task . complete ( ) ;
31
46
47
+ if ( counter . current <= result . steps . length || counter . current !== result . steps . length + 2 ) {
48
+ console . log ( `counter.current: ${ counter . current } , result.steps.length: ${ result . steps . length } ` ) ;
49
+ throw new Error (
50
+ "Basic: Stream does not run as expected! Each step should be relogged whenever stream restarts!" ,
51
+ ) ;
52
+ }
53
+
32
54
console . log ( "Basic: Stream completed" ) ;
33
55
console . log ( result . output ) ;
34
56
}
35
57
58
+ basic ( ) . catch ( console . error ) ;
59
+
36
60
// Structured ----------------------------------------------------------------
37
61
38
62
// Define Structured Output Schema
@@ -51,8 +75,8 @@ async function structured() {
51
75
52
76
const task = await browseruse . tasks . createTask ( {
53
77
task : "Extract top 10 Hacker News posts and return the title, url, and score" ,
78
+ llm : "gpt-4.1" ,
54
79
schema : TaskOutput ,
55
- agent : { llm : "gpt-4.1" } ,
56
80
} ) ;
57
81
58
82
for await ( const msg of task . stream ( ) ) {
@@ -68,6 +92,6 @@ async function structured() {
68
92
}
69
93
}
70
94
71
- basic ( )
72
- . then ( ( ) => structured ( ) )
73
- . catch ( console . error ) ;
95
+ // basic()
96
+ // .then(() => structured())
97
+ // .catch(console.error);
0 commit comments