Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force Chrome to NOT open SaveAs Dialog when downloading a URL?

Chrome Build: the newest, 33+

A Chrome Extension extracts certain urls from currently viewed site and then downloads a subset of them (quite often hundreds of files).

Expected Behavior:

Files are downloaded into the default Download-Folder without questioning where and under which filename they have to be saved.

Problem:

If a user has enabled the option "Ask where to save each file before downloading" in Chrome->Settings->Advanced Settings->Downloads then when trying to download, for example, 100 files simultaniously, Chrome tries to open 100 SaveAs Dialogs and crashes.

What I tried:

  • to use chrome.downloads.download(object options, function callback) method with an option saveAs: false
  • using the following code to trigger a download through an emulated mousevent:

    function saveAs(Url,filename){
      var blob=new Blob([''], {type:'application/octet-stream'}); 
      var url = webkitURL.createObjectURL(blob);
      var a = document.createElementNS('http://www.w3.org/1999/xhtml','a');
      a.href = Url;
      a.download = filename; 
      var e = document.createEvent('MouseEvents');
      e.initMouseEvent('click', false, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
      a.dispatchEvent(e);
      webkitURL.revokeObjectURL(url);
    }
    
like image 868
QuteBits Avatar asked Jan 04 '14 18:01

QuteBits


People also ask

How do I stop Chrome from saving as dialog?

In the future, if you want to disable the “Save As” prompt in Google Chrome, turn off the toggle beside the “Ask where to save each file before downloading” option.

How do I stop files from automatically opening after downloading?

Step 1: Open the Chrome menu (click the icon with three dots to the upper-right corner of the window), and then click Settings. Step 2: Expand the Advanced section, and then click Downloads. Step 3: Under the Downloads group, click Clear next to 'Open certain file types automatically after downloading. '


1 Answers

It is impossible when "Ask where to save each file before downloading" Enabled (as of 70.0.3538.77). The corresponding Chromium bug is:

Bug 417112: chrome.downloads.download ignore saveAs

Moreover setting filename in chrome.downloads.downloads() also doesn't work.

Bug 758094: Extension can not rename downloaded file

like image 56
midenok Avatar answered Oct 23 '22 01:10

midenok