Skip to content

Conversation

sadym-chromium
Copy link
Contributor

@sadym-chromium sadym-chromium commented Jul 22, 2025

In puppeteer, there is a way to deny all the downloads, or allow for downloading to a custom folder. This PR is intended to provide a way to customize the download behavior per user context or globally.

  1. Should be followed up with HTML PR invoking new hooks.
  2. Add a new hook "WebDriver BiDi download will begin" which is intended to replace "WebDriver BiDi download started".
  3. "WebDriver BiDi download will begin" returns "download behavior struct", which instructs the user agent how to handle downloads.

Preview | Diff

@sadym-chromium sadym-chromium force-pushed the sadym/browser.setDownloadBehavior branch 2 times, most recently from c21e5f3 to fdc8565 Compare July 22, 2025 18:58
@sadym-chromium sadym-chromium force-pushed the sadym/browser.setDownloadBehavior branch 2 times, most recently from 0d841df to d5de8eb Compare July 24, 2025 12:58
Copy link
Contributor

@juliandescottes juliandescottes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is worth discussing with the working group before doing an in-depth review.

I can see most automation libraries provide ways to set a download path, so that sounds like a useful feature. Libraries could already monitor downloads and move files manually to achieve the same effect, but still having it built in sounds more practical. And there are already preferences to drive this in most browsers anyway...

Regarding the API itself, I can see CDP has this on the Browser domain, but it also has the download events there, whereas for us they are on BrowsingContext. I would have expected this on BrowsingContext, but interested to know what others think.

@whimboo whimboo added needs-discussion Issues to be discussed by the working group module-browser Browser module labels Aug 14, 2025
@sadym-chromium sadym-chromium force-pushed the sadym/browser.setDownloadBehavior branch 3 times, most recently from 865deea to 79a5bb9 Compare August 20, 2025 14:42
@sadym-chromium
Copy link
Contributor Author

I can see most automation libraries provide ways to set a download path, so that sounds like a useful feature. Libraries could already monitor downloads and move files manually to achieve the same effect, but still having it built in sounds more practical. And there are already preferences to drive this in most browsers anyway...

Testing libraries are not guaranteed to have access to the filesystem, so I would leave this logic to the browser.

Regarding the API itself, I can see CDP has this on the Browser domain, but it also has the download events there, whereas for us they are on BrowsingContext. I would have expected this on BrowsingContext, but interested to know what others think.

The Browser module was chosen as implementation-wise in CDP we cannot set the download behavior per browsing context, only per user context. So having this method in BrowsingContext module and not being able to configure per browsing context seems a bit odd.

@sadym-chromium sadym-chromium force-pushed the sadym/browser.setDownloadBehavior branch from 79a5bb9 to 438c004 Compare August 20, 2025 15:40
@sadym-chromium
Copy link
Contributor Author

@juliandescottes PTAL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module-browser Browser module needs-discussion Issues to be discussed by the working group
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants