Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions stagehand/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,30 @@ async def init(self):
self.logger,
)
self._playwright_page = self._page._page

# Set up download behavior via CDP
try:
# Check if downloadsPath is provided in launch options, otherwise use default
downloads_path = self.local_browser_launch_options.get("downloadsPath")
if not downloads_path:
downloads_path = str(Path.cwd() / "downloads")
# Create downloads directory if it doesn't exist
Path(downloads_path).mkdir(parents=True, exist_ok=True)

# Create CDP session for the page
cdp_session = await self._context.new_cdp_session(self._playwright_page)
# Enable download behavior
await cdp_session.send("Browser.setDownloadBehavior", {
"behavior": "allow",
"downloadPath": downloads_path,
"eventsEnabled": True
})

self.logger.debug(f"Set up CDP download behavior for local browser with path: {downloads_path}")
except Exception as e:
self.logger.warning(f"Failed to set up CDP download behavior for local browser: {str(e)}")
# Continue without download support - non-critical feature

except Exception:
await self.close()
raise
Expand Down
Loading