Repository navigation
feat(browser): download files in a session's browser - #953
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.
XDG_DOWNLOAD_DIR(environment oruser-dirs.dirs) on Linux,~/Downloadson 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.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 nextbrowser_infofollows up.browser_openandbrowser_navigateon 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 carriesdownloadsinstead of an error.lich browser open/navigateprint the same line.browser-downloadon/eventswhen a file is complete; the window shows a toast naming the file and its folder, with Open folder. Strings in all 7 locales.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 indocs/ceilings.md.Notes for review
api.BrowserPageInfoandapi.BrowserHandlegaindownloads;api.BrowserDownloadEventis new. Contract golden updated.browser_downloadstool:browser_inforeports a download the agent has not heard end, which covers it.Test plan
gofmt,go vet,go test ./...), cross-compile for linux, darwin and windows.<a download>, an attachment link,target=_blank,location.href,window.openand ablob:download each land once in Downloads with the page left where it was;browser_openon a file launches the browser atabout:blankand saves it, and a second open and a navigate do the same. Both ran 10 times in 10 green.