Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we detect when files begin to download in a Chrome Extension and can we access the local downloaded files?

I'm going to develop a Chrome Extension detecting status when files begin to download from chrome browser and read the files for certain purposes.

  • Whenever files are downloaded on Chrome browser, is it available to detect it in the Chrome Extension?
  • Can we access the downloaded files in local storage and read it in the Chrome Extension?
  • Can we drag and drop a file from desktop to the tray icon of Chrome Extension?
like image 484
isaac lee Avatar asked Oct 28 '25 08:10

isaac lee


1 Answers

  1. Store the download id.
let downloadIds = [];

chrome.downloads.onCreated.addListener(function (downloadItem) { 
    console.log("filename with absolute local path " , downloadItem.filename); // prints ""
    // Just FYI, you won't get downloadItem.filename here. So store the downloadId
    downloadIds.push(downloadItem.id);
});
  1. Get the filename by using following api. Use downloadId acquired from above step
chrome.downloads.search({id: downloadIds[0]}, function (downloadItem) {
        console.log("filename with absolute local path " , downloadItem.filename); 
        // prints "C:/user/downloads/yourfile"
    });

Now use <input type="file" > in your popup.html and access the file which match with your filename acquired from step

like image 53
Ishwar Kshirsagar Avatar answered Oct 29 '25 21:10

Ishwar Kshirsagar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!