I want to be able to use an extension to download a file and memorize the downloadId for later use. My original attempt at doing this was by using the callback function and assigning the downloadId as a variable like this:
chrome.downloads.download({
url: downloadURL
},
function getDownloadId(downloadId) {
var thisDownloadId = downloadId;
}
);
But this caused my Chromebook to crash, so I don't think that will work.
I attempted to use the solution from this question. However, when I attempt to use said solution, it ended up in this error:
TypeError: Cannot read property 'current' of undefined.
This is the snippet of my script that downloads the file (popup.js)
chrome.downloads.download({
url: downloadURL
});
And the snippet of where it waits for the file to download, which currently only displays the downloadId for testing (popup.js)
chrome.downloads.onChanged.addListener(function (
if(detail.state.current == "complete") { // This is where the error occurs
var downloadId = detail.id;
alert("downloadId: " + downloadId);
}
});