bugzilla.mozilla.org will be intermittently unavailable on Saturday, March 24th, from 16:00 until 20:00 UTC.

Unpredictable result from downloads.search




WebExtensions: General
8 months ago
8 months ago


(Reporter: erosman, Unassigned)


55 Branch

Firefox Tracking Flags

(Not tracked)




8 months ago
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0
Build ID: 20170719160221

Steps to reproduce:

I have been testing chrome.downloads.erase() and chrome.downloads.search() but do not get any results.
I have tried with both chrome and browser.

Test Code:

chrome.downloads.search({}, (dl) => { console.log(dl); });

Actual results:

For the test:

manifest.json has "downloads" permission.
Everything is done in a single session.

- Deleted all of the entries in the download history
- Created 2 new downlands using chrome.downloads.download()
- They show up in Download History
- Downloaded Files are present (not moved/deleted)
- Run above code and it shows and empty array ... Array [ ]

- I downloaded an image using browsers "Save Image As..."
- Download History shows 3 items now
- Run above code and it shows and array with 1 item ... Array [ Object ]
- The object refers to the image that I just downloaded

chrome.downloads.search() (and all downloads API) seems to ignore items downloaded by the API itself. 
It could be that items downloaded by downloads.download are missing something.

Comment 1

8 months ago
Update: Correction:

The behaviour is unpredictable.

Yesterday it was not recognising items downloaded with download API. Today it is. 
However, the situation is that:

- There are 8 items in Download History but the above code only shows 2


8 months ago
Summary: Items downloaded by downloads API are not recognised by downloads.search → Unpredictable result from downloads.search

Comment 2

8 months ago
based on comment 1, you might be seeing the effects of bug 1255507. If this is the only issue you're still seeing, we can close as a duplicate, otherwise we may need to find out what is happening with the WebExtensions code.

I've just completed a piece of infrastructure in bug 1381411 that will make fixing the bug above easier, so it's possible the WebExtensions team will be able to give add-ons access to download history in the not so distant future.

Comment 3

8 months ago
Andrew Swan did mention bug 1255507 to me on IRC but I tried with current session and old session and it was the same. That bug states that the searches only gets it from the current session.
On my next test today, it got 2 out of 8 items from previous sessions.
I just tired it now and I get zero results ie ... Array [  ]

AFA bug 1255507 , I am not sure if I understood it correctly. Is the current state that the downloads.search can not get a list (in order to erase later)?

I am going to do some more testing to see if I can pinpoint the issue.

Comment 4

8 months ago
Test result:

After above post, one hour ago, I downloaded 3 new items, 2 with download API and one with the browser. 
I run above code, all 3 appeared.

The browser has been open since, same window (single window)... I have just run the code and I got empty array ... Array [  ]


Comment 5

8 months ago
Looks like a race condition on the WebExtensions API side. Andrew, what do you think?
Component: Downloads API → WebExtensions: General

Comment 6

8 months ago
Next test:

19:08 Delete the download history
19:08 Downloade 1 item with API + 1 item with browser
19:09 Run code Array [ Object, Object ]
19:19 Run code Array [  ]

Comment 7

8 months ago
I a running more tests... it is possible that "Download Status Bar" may have something to do with it.

Comment 8

8 months ago
More tests ....

With Download Status Bar 

19:23 Delete the download history
19:24 Downloaded 1 item with API + 1 item with browser
19:24 Run code Array [ Object, Object ]
19:25 Run code Array [ Object, Object ]
19:26 Clearing with Download Status Bar 
19:26 Run code Array [  ]

Conclusion: it seems clearing with Download Status Bar deletes something which makes the downloads inaccessible to the API, even though the Download History is displays them

Without Download Status Bar
19:28 Delete the download history
19:28 Downloaded 1 item with API + 1 item with browser
19:28 Run code Array [ Object, Object ]
19:31 Run code Array [ Object, Object ]
19:34 Run code Array [ Object, Object ]
19:36 Run code Array [ Object, Object ]
19:37 Restarted  Browser
19:37 Run code Array [  ]

Conclusion: Now, it seems more like bug 1255507 where the issue was the session

So, unless I come across anything else, you can attribute it to bug 1255507

Comment 9

8 months ago
I spoke too soon .....

While it is definitely related to bug 1255507 , there are other issues

- Cleared Download History
- Downloaded 5 items, and they show in the Download History
- Run the code: chrome.downloads.search({}, (dl) => { console.log(dl); });
- Shows Array [ Object, Object, Object, Object, Object ]

- Run the code: chrome.downloads.erase({});
- 1 out of 5 was deleted from the Download History
- 4 items are still there
- Run the code: chrome.downloads.search({}, (dl) => { console.log(dl); });
- Shows Array [ ]


I also tested with chrome.downloads.erase({state: 'complete'});
Same result, only deleted one but then Array [ ]

Comment 10

8 months ago
Hm, it seems likely that the last issue you've seen is because chrome.downloads.erase operates on session downloads, but does not always delete the history entries, that are stored separately in the Places database. So the API sees the expected result, but the browser history entries for those downloads are still visible.

I think that the work in bug 1255507 will have to handle that case as well. Thanks for testing!
Last Resolved: 8 months ago
Resolution: --- → DUPLICATE
Duplicate of bug: 1255507

Comment 11

8 months ago
Ah, and I just found bug 1306879 on file for that case.
You need to log in before you can comment on or make changes to this bug.