Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monitor the Download process in Chrome

I am trying to hack together a Python script to monitor ongoing downloads in Chrome and shut-down my PC automatically after the download process closes. I know little JavaScript and am considering using the PyJs library, if required.

1) Is this the best approach? I don't need the app to be portable, just working.

2) How would you identify the download process?

3) How would you monitor the download progress? Apparently the Chrome API doesn't provide a specific function for it.

like image 530
Shrikant Giridhar Avatar asked Nov 13 '22 07:11

Shrikant Giridhar


1 Answers

Nice question, may be because I can relate with the need of automating the shutdown. ;)

I just googled. There happens to be an experimental API but only for the dev channel as of now. I am not on a dev channel to try that out, so I just hope I am pointing you in the right direction.

One approach would be:

  • Have a Python HTTP server listening on some port XYZ
  • To your extension add the permission to the URL http://localhost:XYZ/
  • In your extension, you could use:

    chrome.downloads.search(query, function (arrayOfDownloadItem){ .. })
    
    • Where, query is an instance of DownloadQuery, and contains state property as in_progress
    • You could probably check for the length of arrayOfDownloadItem.
      • If its zero, create a new XMLHttpRequest to your HTTP server end point, and then let the server shutdown your machine.

HTH

like image 79
UltraInstinct Avatar answered Nov 14 '22 21:11

UltraInstinct