'`chrome.downloads.search` is missing file results

In the context of a Chrome extension, I want to map some local downloaded files to in-storage data.

I'm having trouble understanding why a file that is clearly in the desired folder according to my OS would not be detected by chrome.downloads.search?

❯ ls ~/Downloads/PaperMemoryStore/*2101*
/Users/victor/Downloads/PaperMemoryStore/2101.02464.pdf
const allfiles = await new Promise((resolve) => {
    chrome.downloads.search(
        { filenameRegex: "PaperMemoryStore/.*" }, 
        (p) => resolve(p))
    )
});
allfiles.filter(f => f.filename.includes("2101")) // [] <- empty filter

I understand why allfiles may have more results than what the filesystem shows (because of DownloadItem.state for instance) but not why it would show fewer.

Is it possible that chrome.downloads.search would not return files that have not been downloaded but just put in a folder? I could not find any such information in the docs.

Scenario:

  1. I downloaded a pdf (2101.02464.pdf)
  2. Which I copy-pasted in a sub-folder of Downloads/ (PaperMemoryStore)
  3. I'm running Brave Version 1.36.122 Chromium: 99.0.4844.88 (Build officiel) (x86_64)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source