I have webextension that have downloads.onChanged listener. This listener should remove downloads that changed it's name. On chrome it works, but on firefox it only fires when download completed.
Example:
browser.downloads.onChanged.addListener(checkFile);
for (var i = 0; i < arg.url.length; i++) {
let name = arg.filename[i];
browser.downloads.download({
url: arg.url[i],
filename: name
}, id => {
checkdownloadList[id] = name;
downloadList[id] = name;
})
}
function checkFile (file) {
if (checkdownloadList[file.id] !== undefined) {
delete checkdownloadList[file.id];
browser.downloads.search({
id: file.id
}, function(downloadItems) {
if (downloadItems[0].filename.replace(/\/gi, "/").includes(downloadList[downloadItems[0].id])) {
browser.downloads.resume(downloadItems[0].id);
} else {
browser.downloads.erase({id: downloadItems[0].id});
}
});
I can't pause downloads, because downloads.onCeeated
event won't work too. And pausing after download id received result with error "can't pause because download interrupted". On chrome all of this methods works.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…