0

I can search the others properties. eg. state, limit, danger, exists.

chrome.downloads.search({state: 'in_progress'});
chrome.downloads.search({state: 'interrupted', limit: 50});
chrome.downloads.search({exists: true});

But with the error: property, it returned all results.

chrome.downloads.search({error: 'USER_CANCELED'});
chrome.downloads.search({error: 'CRASH'});

Is it possible to search state: interrupted and all network errors at the same time?

chrome.downloads.search({state: 'interrupted', error: 'NETWORK_DISCONNECTED', error: 'NETWORK_FAILED', error: 'NETWORK_TIMEOUT'});
ted
  • 13,596
  • 9
  • 65
  • 107
Boontawee Home
  • 935
  • 7
  • 15

1 Answers1

0

Look like Chrome bugs.

  1. state: 'interrupted'. It didn't return all the interrupted items.
  2. error: property bug. It will return all download items.

I fixed this by querying all items and using .filter

// [BUG] state: 'interrupted' didn't return all the interrupted items.
// [BUG] error: property will return all download items.

// let searchInProgress  = chrome.downloads.search({state: 'in_progress'});
// let searchInterrupted = chrome.downloads.search({state: 'interrupted'});

let searchDownloads = chrome.downloads.search({});  // Fixed bugs by query all download items in one shot and using filter.

searchDownloads.then(function (results)
{
    let downloading = results.filter(log => log.state === 'in_progress');
    let interrupted = results.filter(log => log.error !== 'USER_CANCELED' && log.error !== undefined);

    let count = downloading.length;
    let error = interrupted.length;

    console.log(results);
    console.log('in_progress : ' + count);
    console.log(downloading);
    console.log('interrupted : ' + error);
    console.log(interrupted);
});
Boontawee Home
  • 935
  • 7
  • 15