Fix browser download directory to automatically use /shared-downloads in Docker #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix browser download directory to automatically use /shared-downloads in Docker
Summary
This PR fixes a critical issue where browser downloads in Docker environments were failing to save properly to the
/shared-downloadsdirectory. The root cause was that Chrome was downloading files to temporary locations, and whensave_as()was called to copy them to/shared-downloads, the files ended up empty.The fix automatically configures Chrome's download directory to
/shared-downloadsin Docker environments by:BrowserProfilethat setsdownloads_path = '/shared-downloads'whenIN_DOCKER=Trueand no explicit path is configured--download-default-directoryChrome launch argument whendownloads_pathis setThis ensures downloads go directly to the shared directory without requiring manual
save_as()calls that were causing empty files.Review & Testing Checklist for Human
--download-default-directoryworks correctly across different Chrome versions and doesn't cause browser launch issuesdownloads_pathconfigurations still work as expectedIN_DOCKERflag is reliable in your Docker environments and activates the feature when neededRecommended test plan: Set up a Docker container with
/shared-downloadsmounted, run the original failing script, and verify downloaded files contain expected content instead of being empty.Diagram
%%{ init : { "theme" : "default" }}%% graph TB subgraph "Browser Profile System" Profile["browser_use/browser/profile.py"]:::major-edit Session["browser_use/browser/session.py"]:::context Context["browser_use/browser/context.py"]:::context end subgraph "Docker Environment" Docker["IN_DOCKER flag"]:::context SharedDir["/shared-downloads"]:::context end subgraph "Chrome Launch" ChromeArgs["Chrome Arguments"]:::minor-edit DownloadDir["--download-default-directory"]:::major-edit end Profile --> ChromeArgs Profile --> DownloadDir Docker --> Profile SharedDir --> DownloadDir Session --> Profile Context --> Profile subgraph Legend L1["Major Edit"]:::major-edit L2["Minor Edit"]:::minor-edit L3["Context/No Edit"]:::context end classDef major-edit fill:#90EE90 classDef minor-edit fill:#87CEEB classDef context fill:#F5F5F5Notes
save_as()was creating empty files due to copying from temporary Chrome download locations