I am developing a Chrome extension that will save files in a download folder (which is not all that it does, but in the part that I'm having problems with). Now I am focusing on PDF files. Basically, when a PDF opens in Chrome, the user can manually save it using Menu - Save File As ..., I'm just trying to automate this function with the extension, but I did not find a good way to do this.
Let's say I can determine if there is a PDF file in the current tab (based on the answers from this question).
The best thing I have guessed so far is to start the download:
chrome.downloads.download({ url: tabs[0].url, saveAs: false, filename: "my file", conflictAction: "overwrite" });
This works, but has 2 drawbacks:
- The file must be reloaded, which hurts if it is large. Also, the file is already uploaded, so I have to use it.
- For some reason this does not work with files opened locally ("file: // ..."). It issues NETWORK_INVALID_REQUEST and does not load.
Is there a better way to save the file?
source share