Search code examples
google-chrome-extension

Chrome Extension download empty MP3 file


So, just like the title says, I want to force a Chrome extension to download an empty MP3 file. Although I did manage to actually prompt a download, every time I download the "empty" file, I get a "Failed - Network error" error. Here is the function that handles the download:

function download(title) {
    return new Promise(resolve => chrome.downloads.download({url: "data:application/mp3", filename: `${title}.mp3`, saveAs: true}, resolve))
}

My assumption is that there aren't enough bits (or the required ones) in the data of the MP3 for it to even be classified as an mp3 file. I unfortunately have no idea how MP3 files are supposed to look like, so I sadly cannot fix it on my own. My question to you is, how would I be able to download the empty MP3 object without Chrome saying that it failed due to a "network error"?

If anyone could help me, that would be amazing. If you are wondering, the reason I am downloading an empty MP3 file is for it to be used as a location blueprint. After it is downloaded, the path will be sent to an external application which will then overwrite the file with the actual MP3. If you have any questions, do let me know. Thank you for your time and help, it is truly appreciated.


Solution

  • Answer inspired by @ThomasMueller. Like he mentioned, "data:application/mp3" is not a valid data type. That said, I was able to achieve what I wanted by instead changing the URL to data:audio/mpeg;base64,. This generates a completely empty mp3 file with 0 KB size. Big thanks to @ThomasMueller for the information.