1010
1111const browseruse = new BrowserUseClient ( {
1212 apiKey : process . env . BROWSER_USE_API_KEY ! ,
13- environment : "https://api.browser-use.com/api/v2" ,
1413} ) ;
1514
1615// Basic ---------------------------------------------------------------------
@@ -19,16 +18,39 @@ async function basic() {
1918 console . log ( "Basic: Creating task and starting stream..." ) ;
2019
2120 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" ,
2423 } ) ;
2524
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 } ` ) ;
2843 }
2944
3045 const result = await task . complete ( ) ;
3146
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+
3254 console . log ( "Basic: Stream completed" ) ;
3355 console . log ( result . output ) ;
3456}
@@ -51,8 +73,8 @@ async function structured() {
5173
5274 const task = await browseruse . tasks . createTask ( {
5375 task : "Extract top 10 Hacker News posts and return the title, url, and score" ,
76+ llm : "gpt-4.1" ,
5477 schema : TaskOutput ,
55- agent : { llm : "gpt-4.1" } ,
5678 } ) ;
5779
5880 for await ( const msg of task . stream ( ) ) {
0 commit comments