New issue
Advanced search Search tips

Issue 838952 link

Starred by 3 users

Issue metadata

Status: Untriaged
Owner: ----
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux , Windows , Mac
Pri: 2
Type: Bug



Sign in to add a comment

Save As does not default to recent directory if path-less filename specified - chrome.downloads.download

Reported by peter.m....@gmail.com, May 2 2018

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36

Steps to reproduce the problem:
1. Clone this repo and install as an unpacked extension: https://github.com/mrcoles/test-chrome-extension-downloadrecents
2. Activate the extension, which will send you to a new tab viewing /index.html in the extension
3. Follow the instructions to test the download buttons

What is the expected behavior?
I would expect scenario (B), when the filename is set to "image-name.png", that the Save As dialog would still default to the most recently used directory. I would expect that it would only not do that if a path were specified in the filename, like "./image-name.png" or "foo/image-name.png".

What went wrong?
In scenario (B) the Save As dialog defaults to the browser’s default downloads directory instead of the most recently chosen one.

Did this work before? N/A 

Does this work in other browsers? N/A

Chrome version: 66.0.3359.139  Channel: stable
OS Version: OS X 10.13.2
Flash Version:
 
Labels: Needs-Triage-M66

Comment 2 by lgrey@chromium.org, May 7 2018

Components: Platform>Extensions>API

Comment 3 by woxxom@gmail.com, May 7 2018

Not sure why you expect it to remember the last used directory.
The documentation [1] unequivocally states the path is always relative to the default downloads directory.
It was always this way since chrome.downloads API was implemented in Chrome 31 almost six years ago.

   filename	
   A file path relative to the Downloads directory to contain the downloaded file, possibly containing subdirectories.

[1]: https://developer.chrome.com/extensions/downloads#method-download
To be honest, I didn’t expect this either :D

However, Chrome does remember the last chosen directory if no filename is specified to downloads.download with Save As. This recent directory can be a directory outside of the default downloads directory, e.g., if you save to Desktop or a documents folder. It seems that lots of people using an extension I built really like this and it’s maybe the best way to quickly save files somewhere other than inside or underneath the default downloads directory.

I also tested this on Windows 7 with Chrome 49 and it’s the same as my Mac example.

Given how Save As works without specifying a filename, my intuition would have been that a filename without any slashes in it would function the same as Save As without specifying any filename and when it does have slashes, e.g., "./foo.txt" or "my-extension/foo.txt", then it defaults to underneath the default downloads directory.

I feel like that’d be better functionality, but it could lead to unexpected results for existing apps. I don’t see a good fix to this other than (a) changing the functionality to match what I outlined in the previous paragraph or (b) adding an additional boolean option like `allowRecent`. B feels sloppy. A feels more elegant, but could annoy other people?

As a workaround, I realized I could save a file to the HTML5 file system with my desired filename, then download that without specifying a filename :O

Comment 5 by woxxom@gmail.com, May 8 2018

The additional parameter is actually a plausible idea while changing the default behavior is definitely not for two reasons: it'll break all/many/most existing extensions and it's not how APIs work in general - user actions should not change the outcome of the same-parameter invocation.

Anyway, you should be able to implement what you want with the current API quite easily: chrome.downloads.download returns an ID of the DownloadItem which you can query in chrome.downloads.search which returns an array of matching items (only one here) so you can get the full local path in filename property, save it, and use in subsequent downloads.
Labels: M-68 Triaged-ET FoundIn-68 Target-68 OS-Linux OS-Windows
Status: Untriaged (was: Unconfirmed)
Able to reproduce the issue on Mac 10.13.3, Win-10 and Ubuntu 17.10 using chrome reported version #66.0.3359.139 and latest canary #68.0.3423.2.
This is a non-regression issue as it is observed from M60 old builds. 

Hence, marking it as untriaged to get more inputs from dev team.

Thanks...!!
@woxxom - I don’t follow your example of using the DownloadItem. I am looking for the saveAs dialog to both accept my custom filename and yield the most recent directory a user saved something to (which can be outside of the default downloads directory, e.g., /Users/foo/Desktop/ instead of /Users/foo/Downloads/). I’m not seeing how that can be achieved with the current APIs or DownloadItems and downloads.download.search?

Comment 8 by woxxom@gmail.com, May 11 2018

The suggested path can't be outside of the default downloads directory. This is a security restriction, which is unlikely to ever change.
Printing remembers; Saving remembers; but downloading is odd and doesn't remember.  Download behaviour is most unhelpful since you often want to download several things to the same folder, and it's a pain to have to keep navigating there.  Need another download option to choose recent download folder.  Make it a new command/API if you don't want to change the old one.  Also, would be good to remember last download location per website, like you have other settings that are remembered by website.

Sign in to add a comment