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,16 +18,39 @@ 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
}
@@ -51,8 +73,8 @@ async function structured() {
51
73
52
74
const task = await browseruse . tasks . createTask ( {
53
75
task : "Extract top 10 Hacker News posts and return the title, url, and score" ,
76
+ llm : "gpt-4.1" ,
54
77
schema : TaskOutput ,
55
- agent : { llm : "gpt-4.1" } ,
56
78
} ) ;
57
79
58
80
for await ( const msg of task . stream ( ) ) {
0 commit comments