5

I want to write a piece of code that triggers an event when a file is getting downloaded. Lets say its a chrome extension.

Like a Download Manager intercepts the browser download process, captures the file URL and downloads it. I want to capture the URL of the files getting downloaded and avoid the browser download process.

Thanks for taking a look !

nilfalse
  • 2,380
  • 2
  • 19
  • 16
Swanidhi
  • 2,029
  • 1
  • 20
  • 21

1 Answers1

5

You can detect a downloading event with chrome.downloads.onCreated listener and perevent it with chrome.downloads.cancel method.

But chrome.downloads API is expiremental and only works on chrome dev channel version for now.

chrome.downloads.onCreated.addListener(function(DownloadItem downloadItem) {
   chrome.downloads.cancel(downloadItem.id , function() {
       console.log("Download was cancelled")
   });
});
Okan Kocyigit
  • 13,203
  • 18
  • 70
  • 129