I am developing a chrome extension, and I want to allow my users to add their own assets to an assets folder. However I can't figure out how to access the files if I don't know their exact name.
In manifest.json I have
"web_accessible_resources": [
{
"resources": [
"assets/*"
],
"matches": ["https://example.com"]
}
and I was able to produce my desired behavior by using
chrome.runtime.getPackageDirectoryEntry(function(dir) {
dir.createReader().readEntries(function (fr) {
fr.find(e => e.name == "assets" && e.isDirectory).createReader().readEntries(function (fr) {
for(i of fr) {
console.log(chrome.runtime.getURL(i.name))
}
})
})
})
in the developer console, but I discovered after the fact that getPackageDirectoryEntry is foreground only and thus I couldn't run it in my contentScript. I was not able to find an equivalent in the file system api. Another approach I tried was including a txt document which the user would then add the file paths of any files they wanted, however this seems needlessly unintuitive.