Skip to content

fix(downloads)!: set download behavior per context over the browser session - #753

Merged
route merged 1 commit into
mainfrom
fix/download-behavior
Nov 30, 2026
Merged

route merged 1 commit into
mainfrom
fix/download-behavior

Conversation

@route

@route route commented Nov 30, 2026

Copy link
Copy Markdown
Member

Chrome applies Browser.setDownloadBehavior to a whole context, but Ferrum sent it from page sessions, so:

  • only the page that set it got download events, a sibling's downloads were saved but await_download returned nil;
  • every new page reset the path to :save_path, undoing an earlier set_behavior;
  • closing the page that set it reset the behavior for the whole context;
  • without :save_path no download was tracked at all.

Now contexts set it over the browser session when they're created, which outlives every page and receives the download events of the whole context. Each event is routed to the context and to the page whose frame started it, or to the opener of a popup we never connected to, as Playwright does. Without :save_path contexts get Chrome's default behavior with events on, so downloads show up as canceled? instead of never.

API

  • context.downloads lists and awaits the downloads of every page in the context and owns set_behavior. browser.downloads is the default context's.
  • page.downloads (Ferrum::Page::Downloads) lists and awaits only the page's own downloads, popups it opened included.
browser.downloads.set_behavior(save_path: "/tmp/downloads")
download = page.await_download { page.at_css("#download").click }
download.path # => "/tmp/downloads/attachment.pdf"

Breaking:

  • page.downloads.set_behavior is removed, use context.downloads or browser.downloads.
  • browser.downloads is the default context's, not the page's.
  • :allowAndName is :allow_and_name.
  • save_path: is required only for :allow and :allow_and_name.

…ession

Chrome applies Browser.setDownloadBehavior to a whole context, but Ferrum sent it from page sessions: only the page
that set it got download events, every new page reset the path to :save_path, closing that page reset the behavior,
and without :save_path no download was ever tracked.

Contexts now set it over the browser session when they're created, receive every download event there and route
each one to the context and the page whose frame started it, or to the opener of a popup we never connected to.
set_behavior moves to context.downloads and browser.downloads, takes :allow_and_name, and needs save_path: only to
allow downloads. page.downloads keeps the page's own downloads.
@route
route force-pushed the fix/download-behavior branch from 2a6bfed to b43ac6d Compare November 30, 2026 11:07
@route
route merged commit caae693 into main Nov 30, 2026
6 of 7 checks passed
@route
route deleted the fix/download-behavior branch November 30, 2026 11:16
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