#8303: fix(browser): enable downloads via CDP Browser.setDownloadBehavior
stale
Cluster:
Browser Enhancements and Fixes
## 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
#8282: Fix: Enable browser downloads via CDP Browser.setDownloadBehavior
by vishaltandale00 · 2026-02-03
89.1%
#19823: fix(browser): stability improvements for headless Chrome
by Milofax · 2026-02-18
76.8%
#8718: fix: sanitize download filenames to prevent path traversal (CWE-22)
by DevZenPro · 2026-02-04
76.7%
#6686: fix: clear Playwright's default colorScheme override on CDP-connect...
by Terwox · 2026-02-01
76.2%
#12378: feat: expose download and waitForDownload actions in browser agent ...
by vabole · 2026-02-09
75.8%
#9020: fix(browser): skip port ownership and WS reachability checks for re...
by yepack · 2026-02-04
74.9%
#14944: fix(browser): prefer openclaw profile in headless/noSandbox environ...
by BenediktSchackenberg · 2026-02-12
74.9%
#15595: fix(browser): avoid local port conflicts for remote cdp
by TsekaLuk · 2026-02-13
74.5%
#4663: fix: per-profile browser caching to allow parallel connections
by tsukhani · 2026-01-30
74.3%
#8517: Browser: sandbox download/trace paths
by coygeek · 2026-02-04
74.1%