← Back to PRs

#8303: fix(browser): enable downloads via CDP Browser.setDownloadBehavior

by gavinbmoore open 2026-02-03 21:26 View on GitHub →
stale
## Summary Fixes #8268 Browser downloads weren't working because the `Browser.setDownloadBehavior` CDP call was missing. This call is required for downloads to work in headless mode or when connecting via CDP. ## Changes ### `src/browser/cdp.ts` - Added `DEFAULT_BROWSER_DOWNLOAD_PATH` constant (`/tmp/openclaw-downloads`) - Added `enableBrowserDownloads()` function that: - Creates the download directory if it doesn't exist - Calls `Browser.setDownloadBehavior` via CDP with: - `behavior: 'allow'` - `downloadPath`: configurable, defaults to temp folder - `eventsEnabled`: optional, defaults to false ### `src/browser/pw-session.ts` - After successful browser connection, calls `enableBrowserDownloads()` - Uses the WebSocket URL from the connection - Best-effort: silently handles browsers that don't support this CDP method (e.g., extension relay) ## Testing - CDP tests pass (6 tests) - Typecheck passes - Lint passes on modified files ## CDP Reference [`Browser.setDownloadBehavior`](https://chromedevtools.github.io/devtools-protocol/tot/Browser/#method-setDownloadBehavior) <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR fixes browser downloads over CDP by adding a helper to call the `Browser.setDownloadBehavior` DevTools protocol method and wiring it into the Playwright CDP connection path. - `src/browser/cdp.ts` adds `DEFAULT_BROWSER_DOWNLOAD_PATH` (OS temp + `openclaw-downloads`) and `enableBrowserDownloads()` which ensures the directory exists and sends `Browser.setDownloadBehavior` with `behavior: "allow"`. - `src/browser/pw-session.ts` invokes `enableBrowserDownloads()` after `chromium.connectOverCDP()` using the discovered `wsUrl`, treating it as best-effort for environments that don’t support that CDP method. Overall direction looks correct for headless/CDP download enablement, with minor robustness/observability nits noted in comments. <h3>Confidence Score: 4/5</h3> - This PR is likely safe to merge and should restore downloads over CDP, with low functional risk. - Changes are small and localized (one new helper + one call site) and use the standard CDP `Browser.setDownloadBehavior` method. The main remaining concern is limited error visibility (silent catch) and potential mkdir/path failures in other call sites if the helper is reused without wrapping. - src/browser/pw-session.ts; src/browser/cdp.ts <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs