@@ -53,16 +53,14 @@ def __getattr__(self, name):
53
53
"""Delegate all attribute access to the current active page."""
54
54
stagehand = object .__getattribute__ (self , "_stagehand" )
55
55
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
61
59
else :
62
60
raise RuntimeError ("No active page available" )
63
61
64
62
# For async operations, make them wait for stability
65
- attr = getattr (active_page , name )
63
+ attr = getattr (page , name )
66
64
if callable (attr ) and asyncio .iscoroutinefunction (attr ):
67
65
# Don't wait for stability on navigation methods
68
66
if name in ["goto" , "reload" , "go_back" , "go_forward" ]:
@@ -83,38 +81,32 @@ def __setattr__(self, name, value):
83
81
else :
84
82
stagehand = object .__getattribute__ (self , "_stagehand" )
85
83
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
91
87
else :
92
88
raise RuntimeError ("No active page available" )
93
89
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 )
96
92
97
93
def __dir__ (self ):
98
94
"""Return attributes of the current active page."""
99
95
stagehand = object .__getattribute__ (self , "_stagehand" )
100
96
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
105
99
else :
106
100
return []
107
101
108
- return dir (active_page )
102
+ return dir (page )
109
103
110
104
def __repr__ (self ):
111
105
"""Return representation of the current active page."""
112
106
stagehand = object .__getattribute__ (self , "_stagehand" )
113
107
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 )} >"
118
110
else :
119
111
return "<LivePageProxy -> No active page>"
120
112
@@ -252,8 +244,7 @@ def __init__(
252
244
self ._browser = None
253
245
self ._context : Optional [BrowserContext ] = None
254
246
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
257
248
self .context : Optional [StagehandContext ] = None
258
249
self .use_api = self .config .use_api
259
250
self .experimental = self .config .experimental
@@ -496,16 +487,15 @@ async def init(self):
496
487
self ._browser ,
497
488
self ._context ,
498
489
self .context ,
499
- self ._original_page ,
490
+ self ._page ,
500
491
) = await connect_browserbase_browser (
501
492
self ._playwright ,
502
493
self .session_id ,
503
494
self .browserbase_api_key ,
504
495
self ,
505
496
self .logger ,
506
497
)
507
- self ._playwright_page = self ._original_page ._page
508
- self ._active_page = self ._original_page
498
+ self ._playwright_page = self ._page ._page
509
499
except Exception :
510
500
await self .close ()
511
501
raise
@@ -517,16 +507,15 @@ async def init(self):
517
507
self ._browser ,
518
508
self ._context ,
519
509
self .context ,
520
- self ._original_page ,
510
+ self ._page ,
521
511
self ._local_user_data_dir_temp ,
522
512
) = await connect_local_browser (
523
513
self ._playwright ,
524
514
self .local_browser_launch_options ,
525
515
self ,
526
516
self .logger ,
527
517
)
528
- self ._playwright_page = self ._original_page ._page
529
- self ._active_page = self ._original_page
518
+ self ._playwright_page = self ._page ._page
530
519
except Exception :
531
520
await self .close ()
532
521
raise
@@ -713,7 +702,7 @@ def _set_active_page(self, stagehand_page: StagehandPage):
713
702
Args:
714
703
stagehand_page: The StagehandPage to set as active
715
704
"""
716
- self ._active_page = stagehand_page
705
+ self ._page = stagehand_page
717
706
718
707
@property
719
708
def page (self ) -> Optional [StagehandPage ]:
0 commit comments