Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
553 views
in Technique[技术] by (71.8m points)

downloads.onChanged won't fire before downloads complete on firefox webextension

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...