@@ -80,7 +80,7 @@ async def goto(
8080 Returns:
8181 The result from the Stagehand server's navigation execution.
8282 """
83- if self ._stagehand .env == "LOCAL" :
83+ if not self ._stagehand .use_api :
8484 await self ._page .goto (
8585 url , referer = referer , timeout = timeout , wait_until = wait_until
8686 )
@@ -142,7 +142,7 @@ async def act(
142142 )
143143
144144 # TODO: Temporary until we move api based logic to client
145- if self ._stagehand .env == "LOCAL" :
145+ if not self ._stagehand .use_api :
146146 # TODO: revisit passing user_provided_instructions
147147 if not hasattr (self , "_observe_handler" ):
148148 # TODO: revisit handlers initialization on page creation
@@ -207,7 +207,7 @@ async def observe(
207207 payload = options_obj .model_dump (exclude_none = True , by_alias = True )
208208
209209 # If in LOCAL mode, use local implementation
210- if self ._stagehand .env == "LOCAL" :
210+ if not self ._stagehand .use_api :
211211 self ._stagehand .logger .debug (
212212 "observe" , category = "observe" , auxiliary = payload
213213 )
@@ -324,8 +324,7 @@ async def extract(
324324 else :
325325 schema_to_validate_with = DefaultExtractSchema
326326
327- # If in LOCAL mode, use local implementation
328- if self ._stagehand .env == "LOCAL" :
327+ if not self ._stagehand .use_api :
329328 # If we don't have an extract handler yet, create one
330329 if not hasattr (self , "_extract_handler" ):
331330 self ._extract_handler = ExtractHandler (
@@ -391,18 +390,16 @@ async def screenshot(self, options: Optional[dict] = None) -> str:
391390 Returns:
392391 str: Base64-encoded screenshot data.
393392 """
394- if self ._stagehand .env == "LOCAL" :
395- self ._stagehand .logger .info (
396- "Local execution of screenshot is not implemented"
397- )
398- return None
399393 payload = options or {}
400394
401- lock = self ._stagehand ._get_lock_for_session ()
402- async with lock :
403- result = await self ._stagehand ._execute ("screenshot" , payload )
395+ if self ._stagehand .use_api :
396+ lock = self ._stagehand ._get_lock_for_session ()
397+ async with lock :
398+ result = await self ._stagehand ._execute ("screenshot" , payload )
404399
405- return result
400+ return result
401+ else :
402+ return await self ._page .screenshot (options )
406403
407404 # Method to get or initialize the persistent CDP client
408405 async def get_cdp_client (self ) -> CDPSession :
0 commit comments