Skip to content

feat(browser): download files in a session's browser - #953

Merged
omartelo merged 3 commits into
mainfrom
feat/browser-downloads
Oct 27, 2026
Merged

omartelo merged 3 commits into
mainfrom
feat/browser-downloads

Conversation

@omartelo

Copy link
Copy Markdown
Collaborator

Summary

A session's browser now downloads files. Before, a headless Chrome denied every download, so an agent clicking a download button got nothing and could not fetch a file.

  • Where files land. The user's Downloads folder: XDG_DOWNLOAD_DIR (environment or user-dirs.dirs) on Linux, ~/Downloads on macOS and Windows, chosen behind a build-tag seam. Chrome writes each file under its download id (Browser.setDownloadBehavior, allowAndName, also on the Open in a window relaunch) and lich renames it to the page's suggested name, made unique with (1) so nothing is overwritten. A suggested name cannot leave the folder.
  • What the agent sees. Click and press answer with the page plus a line per download: downloaded: /home/u/Downloads/report.csv (12 KB), after waiting up to ten seconds for it; downloading: ... (3.0 MB so far) when it is still running, which the next browser_info follows up. browser_open and browser_navigate on a URL that answers with a file download it too: Chrome aborts that navigation (net::ERR_ABORTED) and leaves the page where it was, so lich takes it as a load that worked and the handle carries downloads instead of an error. lich browser open/navigate print the same line.
  • What the person sees. browser-download on /events when a file is complete; the window shows a toast naming the file and its folder, with Open folder. Strings in all 7 locales.
  • All providers. It rides on the same browser_* tools, so it reaches all eight.

The page that jumped

Chrome aborts a navigation the page starts within about a second of a download, then reloads the page. It happens with downloads on or off, so it is what made a page jump after a download click before this change. Measured on Chromium 155: the navigation right after an <a download> failed 10 times in 10; with a 1.5 s gap, 0 times in 50. An agent's click, press, open or navigate that downloaded therefore holds its answer until 1.5 s after the download began. Written down in docs/ceilings.md.

Notes for review

  • api.BrowserPageInfo and api.BrowserHandle gain downloads; api.BrowserDownloadEvent is new. Contract golden updated.
  • No browser_downloads tool: browser_info reports a download the agent has not heard end, which covers it.
  • New ceiling bullet for downloads; the browser bullet no longer lists them as left out.

Test plan

  • Backend and native gates green (gofmt, go vet, go test ./...), cross-compile for linux, darwin and windows.
  • Live Chrome tests: <a download>, an attachment link, target=_blank, location.href, window.open and a blob: download each land once in Downloads with the page left where it was; browser_open on a file launches the browser at about:blank and saves it, and a second open and a navigate do the same. Both ran 10 times in 10 green.
  • Unit tests: unique names and the rename, a name taken during the download, cancel, the XDG lookup, reporting each state once, the wait and the quiet hold, the aborted navigation that downloaded nothing staying an error, the agent text, the toast and its event.

…oads folder

A headless Chrome denies downloads, so a download button in the session's
browser did nothing. Chrome now saves them (Browser.setDownloadBehavior,
allowAndName, also in the Open in a window relaunch) into the user's
Downloads folder (XDG_DOWNLOAD_DIR on Linux, ~/Downloads elsewhere, behind a
build-tag seam), and lich renames each to the page's suggested name, made
unique with " (n)" so nothing is overwritten.

The agent learns of it in the page click and press answer: a
"downloaded: <path> (<size>)" line, waiting up to ten seconds for the file,
or "downloading:" while it runs, which the next read follows up. The answer
also holds until 1.5 s after the download began: Chrome aborts a navigation
started sooner and reloads the page (10 of 10 right after an <a download>,
0 of 50 with the gap, Chromium 155). The window hears browser-download and
shows a toast naming the file with a button that opens its folder.

A live test covers <a download>, an attachment link, target=_blank, a
location.href, a window.open and a blob: download, each landing once in
Downloads with the page left where it was.
browser_open and browser_navigate on a URL that answers with a file used to
fail with "page load error net::ERR_ABORTED", the agent never learning that
the file was saved. Chrome aborts that navigation because it became a
download and leaves the page where it was; lich now waits up to a second to
hear of the download and takes the load as one that worked. The handle the
two tools answer with carries the downloads, waited for and held through
the quiet as a click's answer is, and lich browser open/navigate print a
downloaded: line. A browser launched straight onto a file stays at
about:blank instead of closing. The pane's address bar gets the same.
The live download tests moved HOME and USERPROFILE to keep files out of the
runner's Downloads, and Chrome on Windows does not start with USERPROFILE
moved (websocket url timeout). They now point the download folder itself at
a temp dir.

An open that became a download was taken for an error on Windows: the
navigation and the download can read the same instant from its clock, and
the check wanted the download strictly after.
@omartelo
omartelo merged commit fa90124 into main Oct 27, 2026
7 checks passed
@omartelo
omartelo deleted the feat/browser-downloads branch October 27, 2026 21:07
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