I'm writing a Chrome Extension to automate one of my daily tasks, part of the task is downloading a .csv file and manipulating the data. As part of the automation I want to grab the file with Javascript and make the script manipulate it.
The problem is grabbing this file with an XMLHttpRequest would be a nightmare because they send heaps of unique IDs to verify the user and it'd be a nightmare to work out where they come from.
I can easily click the button using javascript which starts the file download, but is there a way that javascript can intercept this request and parse the CSV? I'm thinking if its not possible with plain javascript I might be able to do it with the HTML5 file API?
You might try using the webRequest.onBeforeRequest API. When the download request is you want is made you can cancel it with this method, get the complete URL being used, and make that same request from JavaScript.
You can do it by accessing the file's content with an AJAX request to file://{filepath}
once the file has been downloaded. You just need to add the file://*
permission to your manifest file.
To get the downloaded file's path in the local system, use chrome.downloads.search
and get the filename
property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With