@@ -53,16 +53,14 @@ def __getattr__(self, name):
5353 """Delegate all attribute access to the current active page."""
5454 stagehand = object .__getattribute__ (self , "_stagehand" )
5555
56- # Get the current active page
57- if hasattr (stagehand , "_active_page" ) and stagehand ._active_page :
58- active_page = stagehand ._active_page
59- elif hasattr (stagehand , "_original_page" ) and stagehand ._original_page :
60- active_page = stagehand ._original_page
56+ # Get the current page
57+ if hasattr (stagehand , "_page" ) and stagehand ._page :
58+ page = stagehand ._page
6159 else :
6260 raise RuntimeError ("No active page available" )
6361
6462 # For async operations, make them wait for stability
65- attr = getattr (active_page , name )
63+ attr = getattr (page , name )
6664 if callable (attr ) and asyncio .iscoroutinefunction (attr ):
6765 # Don't wait for stability on navigation methods
6866 if name in ["goto" , "reload" , "go_back" , "go_forward" ]:
@@ -83,38 +81,32 @@ def __setattr__(self, name, value):
8381 else :
8482 stagehand = object .__getattribute__ (self , "_stagehand" )
8583
86- # Get the current active page
87- if hasattr (stagehand , "_active_page" ) and stagehand ._active_page :
88- active_page = stagehand ._active_page
89- elif hasattr (stagehand , "_original_page" ) and stagehand ._original_page :
90- active_page = stagehand ._original_page
84+ # Get the current page
85+ if hasattr (stagehand , "_page" ) and stagehand ._page :
86+ page = stagehand ._page
9187 else :
9288 raise RuntimeError ("No active page available" )
9389
94- # Set the attribute on the active page
95- setattr (active_page , name , value )
90+ # Set the attribute on the page
91+ setattr (page , name , value )
9692
9793 def __dir__ (self ):
9894 """Return attributes of the current active page."""
9995 stagehand = object .__getattribute__ (self , "_stagehand" )
10096
101- if hasattr (stagehand , "_active_page" ) and stagehand ._active_page :
102- active_page = stagehand ._active_page
103- elif hasattr (stagehand , "_original_page" ) and stagehand ._original_page :
104- active_page = stagehand ._original_page
97+ if hasattr (stagehand , "_page" ) and stagehand ._page :
98+ page = stagehand ._page
10599 else :
106100 return []
107101
108- return dir (active_page )
102+ return dir (page )
109103
110104 def __repr__ (self ):
111105 """Return representation of the current active page."""
112106 stagehand = object .__getattribute__ (self , "_stagehand" )
113107
114- if hasattr (stagehand , "_active_page" ) and stagehand ._active_page :
115- return f"<LivePageProxy -> { repr (stagehand ._active_page )} >"
116- elif hasattr (stagehand , "_original_page" ) and stagehand ._original_page :
117- return f"<LivePageProxy -> { repr (stagehand ._original_page )} >"
108+ if hasattr (stagehand , "_page" ) and stagehand ._page :
109+ return f"<LivePageProxy -> { repr (stagehand ._page )} >"
118110 else :
119111 return "<LivePageProxy -> No active page>"
120112
@@ -252,8 +244,7 @@ def __init__(
252244 self ._browser = None
253245 self ._context : Optional [BrowserContext ] = None
254246 self ._playwright_page : Optional [PlaywrightPage ] = None
255- self ._original_page : Optional [StagehandPage ] = None
256- self ._active_page : Optional [StagehandPage ] = None
247+ self ._page : Optional [StagehandPage ] = None
257248 self .context : Optional [StagehandContext ] = None
258249 self .use_api = self .config .use_api
259250 self .experimental = self .config .experimental
@@ -496,16 +487,15 @@ async def init(self):
496487 self ._browser ,
497488 self ._context ,
498489 self .context ,
499- self ._original_page ,
490+ self ._page ,
500491 ) = await connect_browserbase_browser (
501492 self ._playwright ,
502493 self .session_id ,
503494 self .browserbase_api_key ,
504495 self ,
505496 self .logger ,
506497 )
507- self ._playwright_page = self ._original_page ._page
508- self ._active_page = self ._original_page
498+ self ._playwright_page = self ._page ._page
509499 except Exception :
510500 await self .close ()
511501 raise
@@ -517,16 +507,15 @@ async def init(self):
517507 self ._browser ,
518508 self ._context ,
519509 self .context ,
520- self ._original_page ,
510+ self ._page ,
521511 self ._local_user_data_dir_temp ,
522512 ) = await connect_local_browser (
523513 self ._playwright ,
524514 self .local_browser_launch_options ,
525515 self ,
526516 self .logger ,
527517 )
528- self ._playwright_page = self ._original_page ._page
529- self ._active_page = self ._original_page
518+ self ._playwright_page = self ._page ._page
530519 except Exception :
531520 await self .close ()
532521 raise
@@ -713,7 +702,7 @@ def _set_active_page(self, stagehand_page: StagehandPage):
713702 Args:
714703 stagehand_page: The StagehandPage to set as active
715704 """
716- self ._active_page = stagehand_page
705+ self ._page = stagehand_page
717706
718707 @property
719708 def page (self ) -> Optional [StagehandPage ]:
0 commit comments