1- import { Browserbase } from "@browserbasehq/sdk" ;
21import type { CDPSession , Page as PlaywrightPage , Frame } from "playwright" ;
3- import { chromium } from "playwright" ;
42import { z } from "zod" ;
53import { Page , defaultExtractSchema } from "../types/page" ;
64import {
@@ -23,7 +21,6 @@ import {
2321 StagehandNotInitializedError ,
2422 StagehandEnvironmentError ,
2523 CaptchaTimeoutError ,
26- BrowserbaseSessionNotFoundError ,
2724 MissingLLMConfigurationError ,
2825 HandlerNotInitializedError ,
2926 StagehandDefaultError ,
@@ -191,40 +188,6 @@ ${scriptContent} \
191188 }
192189 }
193190
194- private async _refreshPageFromAPI ( ) {
195- if ( ! this . api ) return ;
196-
197- const sessionId = this . stagehand . browserbaseSessionID ;
198- if ( ! sessionId ) {
199- throw new BrowserbaseSessionNotFoundError ( ) ;
200- }
201-
202- const browserbase = new Browserbase ( {
203- apiKey : this . stagehand [ "apiKey" ] ?? process . env . BROWSERBASE_API_KEY ,
204- } ) ;
205-
206- const sessionStatus = await browserbase . sessions . retrieve ( sessionId ) ;
207-
208- const connectUrl = sessionStatus . connectUrl ;
209- const browser = await chromium . connectOverCDP ( connectUrl ) ;
210- const context = browser . contexts ( ) [ 0 ] ;
211- const newPage = context . pages ( ) [ 0 ] ;
212-
213- const newStagehandPage = await new StagehandPage (
214- newPage ,
215- this . stagehand ,
216- this . intContext ,
217- this . llmClient ,
218- this . userProvidedInstructions ,
219- this . api ,
220- ) . init ( ) ;
221-
222- this . intPage = newStagehandPage . page ;
223-
224- await this . intPage . waitForLoadState ( "domcontentloaded" ) ;
225- await this . _waitForSettledDom ( ) ;
226- }
227-
228191 /**
229192 * Waits for a captcha to be solved when using Browserbase environment.
230193 *
@@ -387,20 +350,17 @@ ${scriptContent} \
387350 }
388351 }
389352
390- if ( this . api ) {
391- await this . _refreshPageFromAPI ( ) ;
392- } else {
393- if ( stagehand . debugDom ) {
394- this . stagehand . log ( {
395- category : "deprecation" ,
396- message :
397- "Warning: debugDom is not supported in this version of Stagehand" ,
398- level : 1 ,
399- } ) ;
400- }
401- await target . waitForLoadState ( "domcontentloaded" ) ;
402- await this . _waitForSettledDom ( ) ;
353+ if ( this . stagehand . debugDom ) {
354+ this . stagehand . log ( {
355+ category : "deprecation" ,
356+ message :
357+ "Warning: debugDom is not supported in this version of Stagehand" ,
358+ level : 1 ,
359+ } ) ;
403360 }
361+ await target . waitForLoadState ( "domcontentloaded" ) ;
362+ await this . _waitForSettledDom ( ) ;
363+
404364 return result ;
405365 } ;
406366 }
@@ -655,7 +615,6 @@ ${scriptContent} \
655615 ...observeResult ,
656616 frameId : this . rootFrameId ,
657617 } ) ;
658- await this . _refreshPageFromAPI ( ) ;
659618 this . stagehand . addToHistory ( "act" , observeResult , result ) ;
660619 return result ;
661620 }
@@ -688,7 +647,6 @@ ${scriptContent} \
688647 if ( this . api ) {
689648 const opts = { ...actionOrOptions , frameId : this . rootFrameId } ;
690649 const result = await this . api . act ( opts ) ;
691- await this . _refreshPageFromAPI ( ) ;
692650 this . stagehand . addToHistory ( "act" , actionOrOptions , result ) ;
693651 return result ;
694652 }
0 commit comments