I am creating an extension that will download a mp3 file off a website. I am trying to do this by creating a new tab with the link to the mp3 file, but chrome keeps opening it inside the player instead of downloading it. Is there any way I can create a pop-up to ask the user to "save-as" the file?
In the Chrome Web Store, go to the page for the extension you want. In the address bar, copy the extension's URL. Open the Chrome Extension Downloader in a browser by visiting https://chrome-extension-downloader.com/. Paste the URL into the text box and select Download extension.
In the Privacy and security section, select Content settings. Select Automatic downloads, and then turn on Do not allow any site to download multiple files automatically. Chrome will now ask your permission before downloading multiple files.
Once you have downloaded a file, you can quickly and easily move it to another location by dragging and dropping it from the “Downloads” list in Chrome to a folder in File Explorer or any other file browser you are using.
Fast-forward 3 years, and now Google Chrome offers chrome.downloads
API (since Chrome 31).
After declaring "downloads"
permission in the manifest, one can initiate a download with this call:
chrome.downloads.download({ url: "http://your.url/to/download", filename: "suggested/filename/with/relative.path" // Optional });
If you want to generate the file content in the script, you can use Blob
and URL
APIs, e.g.:
var blob = new Blob(["array of", " parts of ", "text file"], {type: "text/plain"}); var url = URL.createObjectURL(blob); chrome.downloads.download({ url: url // The object URL can be used as download URL //... });
For more options (i.e. Save As dialog, overwriting existing files, etc.), see the documentation.
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