Skip to content

Conversation

@devin-ai-integration
Copy link

@devin-ai-integration devin-ai-integration bot commented Jul 3, 2025

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-downloads directory. The root cause was that Chrome was downloading files to temporary locations, and when save_as() was called to copy them to /shared-downloads, the files ended up empty.

The fix automatically configures Chrome's download directory to /shared-downloads in Docker environments by:

  1. Adding a model validator to BrowserProfile that sets downloads_path = '/shared-downloads' when IN_DOCKER=True and no explicit path is configured
  2. Adding the --download-default-directory Chrome launch argument when downloads_path is set

This ensures downloads go directly to the shared directory without requiring manual save_as() calls that were causing empty files.

Review & Testing Checklist for Human

  • Test actual downloads in Docker container: Run the user's original test script in a Docker environment to verify downloads work correctly and files have proper content
  • Verify Chrome flag compatibility: Ensure --download-default-directory works correctly across different Chrome versions and doesn't cause browser launch issues
  • Test backward compatibility: Verify existing non-Docker workflows and explicit downloads_path configurations still work as expected
  • Validate IN_DOCKER detection: Confirm the IN_DOCKER flag is reliable in your Docker environments and activates the feature when needed

Recommended test plan: Set up a Docker container with /shared-downloads mounted, 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:#F5F5F5
Loading

Notes

  • This fix addresses the specific issue reported where save_as() was creating empty files due to copying from temporary Chrome download locations
  • The implementation is conservative - it only auto-configures the download path in Docker environments when no explicit path is already set
  • All existing tests pass (118/118) confirming no regressions in core functionality
  • Link to Devin run: https://app.devin.ai/sessions/635dc9ca07984292b55d2696de0f7af9
  • Requested by: jerry@browserless.io

… in Docker

- Add model validator to BrowserProfile that sets downloads_path to /shared-downloads in Docker environments
- Add Chrome --download-default-directory flag when downloads_path is configured
- Ensures downloads go directly to shared directory without manual save_as() calls
- Fixes issue where save_as() resulted in empty files due to temp location copying

Co-Authored-By: jerry@browserless.io <jerry@browserless.io>
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@devin-ai-integration devin-ai-integration bot deleted the devin/1751579843-fix-download-directory branch July 3, 2025 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant