Skip to content

Commit 33cea7d

Browse files
committed
passing setDownloadBehavior in env=LOCAL setup
1 parent 1bef512 commit 33cea7d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

stagehand/main.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,30 @@ async def init(self):
531531
self.logger,
532532
)
533533
self._playwright_page = self._page._page
534+
535+
# Set up download behavior via CDP
536+
try:
537+
# Check if downloadsPath is provided in launch options, otherwise use default
538+
downloads_path = self.local_browser_launch_options.get("downloadsPath")
539+
if not downloads_path:
540+
downloads_path = str(Path.cwd() / "downloads")
541+
# Create downloads directory if it doesn't exist
542+
Path(downloads_path).mkdir(parents=True, exist_ok=True)
543+
544+
# Create CDP session for the page
545+
cdp_session = await self._context.new_cdp_session(self._playwright_page)
546+
# Enable download behavior
547+
await cdp_session.send("Browser.setDownloadBehavior", {
548+
"behavior": "allow",
549+
"downloadPath": downloads_path,
550+
"eventsEnabled": True
551+
})
552+
553+
self.logger.debug(f"Set up CDP download behavior for local browser with path: {downloads_path}")
554+
except Exception as e:
555+
self.logger.warning(f"Failed to set up CDP download behavior for local browser: {str(e)}")
556+
# Continue without download support - non-critical feature
557+
534558
except Exception:
535559
await self.close()
536560
raise

0 commit comments

Comments
 (0)