File tree 4 files changed +31
-4
lines changed
4 files changed +31
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @browserbasehq/stagehand " : patch
3
+ ---
4
+
5
+ Fixed new opened tab handling for CUA models
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ async function main() {
27
27
28
28
const agent = stagehand . agent ( {
29
29
provider : "openai" ,
30
- model : "computer-use-preview-2025-02-04 " ,
30
+ model : "computer-use-preview" ,
31
31
instructions : `You are a helpful assistant that can use a web browser.
32
32
You are currently on the following page: ${ page . url ( ) } .
33
33
Do not ask follow up questions, the user will trust your judgement.` ,
@@ -40,7 +40,6 @@ async function main() {
40
40
await stagehand . page . goto ( "https://www.google.com" ) ;
41
41
console . log ( `${ chalk . green ( "✓" ) } Loaded: ${ chalk . dim ( page . url ( ) ) } ` ) ;
42
42
43
- // Execute the agent again with a different instruction
44
43
const firstInstruction =
45
44
"Search for openai news on google and extract the name of the first 3 results" ;
46
45
console . log (
@@ -62,7 +61,7 @@ async function main() {
62
61
console . log ( `${ chalk . green ( "✓" ) } Loaded: ${ chalk . dim ( page . url ( ) ) } ` ) ;
63
62
64
63
const instruction =
65
- "Apply for the full-stack engineer position with mock data. Don't submit the form." ;
64
+ "Apply for the first engineer position with mock data. Don't submit the form." ;
66
65
console . log ( `${ chalk . cyan ( "↳" ) } Instruction: ${ chalk . white ( instruction ) } ` ) ;
67
66
68
67
const result = await agent . execute ( {
Original file line number Diff line number Diff line change @@ -261,7 +261,7 @@ export class StagehandPage {
261
261
}
262
262
263
263
// Handle screenshots with CDP
264
- if ( prop === "screenshot" ) {
264
+ if ( prop === "screenshot" && this . stagehand . env === "BROWSERBASE" ) {
265
265
return async (
266
266
options : {
267
267
type ?: "png" | "jpeg" ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { AgentProvider } from "../agent/AgentProvider";
3
3
import { StagehandAgent } from "../agent/StagehandAgent" ;
4
4
import { AgentClient } from "../agent/AgentClient" ;
5
5
import { LogLine } from "../../types/log" ;
6
+ import { Page } from "playwright" ;
6
7
import {
7
8
AgentExecuteOptions ,
8
9
AgentAction ,
@@ -190,6 +191,28 @@ export class StagehandAgentHandler {
190
191
await this . stagehandPage . page . mouse . click ( x as number , y as number , {
191
192
button : button as "left" | "right" ,
192
193
} ) ;
194
+ const newOpenedTab = await Promise . race ( [
195
+ new Promise < Page | null > ( ( resolve ) => {
196
+ this . stagehandPage . context . once ( "page" , ( page ) => resolve ( page ) ) ;
197
+ setTimeout ( ( ) => resolve ( null ) , 1500 ) ;
198
+ } ) ,
199
+ ] ) ;
200
+ if ( newOpenedTab ) {
201
+ this . logger ( {
202
+ category : "action" ,
203
+ message : `New page detected (new tab) with URL. Opening on current page...` ,
204
+ level : 1 ,
205
+ auxiliary : {
206
+ url : {
207
+ value : newOpenedTab . url ( ) ,
208
+ type : "string" ,
209
+ } ,
210
+ } ,
211
+ } ) ;
212
+ await newOpenedTab . close ( ) ;
213
+ await this . stagehandPage . page . goto ( newOpenedTab . url ( ) ) ;
214
+ await this . stagehandPage . page . waitForURL ( newOpenedTab . url ( ) ) ;
215
+ }
193
216
return { success : true } ;
194
217
}
195
218
You can’t perform that action at this time.
0 commit comments