DEV Community

Discussion on: Reading files in a Chrome Extension

Collapse
 
sebastianmcarreira profile image
Sebastián Matías Carreira • Edited

Hi Anthony, It was a really good and concise article. But I'm left with a small question: If the extension doesn't knows the exact filename (maybe because the files are created by another program with filenames corresponding to timestamps or something like that), it can clearly make it available with the wildcard, but how does it makes the GET? Is there a way for the extension to receive the list of files available in the directory and then make the extension choose a file to send the GET?

Collapse
 
aussieguy profile image
Anthony Bruno • Edited

Hey Sebastian!

I haven't needed to do this yet, so I did a bit of research. Turns out that this is a rather hard problem! It seems impossible to get it from a content script directly (source). You can potentially chrome.runtime.getManifest() to get the list of web_accessible_resources, but you run into problems if there's wildcard entries.

It may be possible to get the list of possible files with chrome.runtime.getPackageDirectoryEntry(function callback), which is only callable from a background script. I haven't tried it though.