0

I was trying to develop a chrome extension but I occurred in a problem.

I need to list the entries of a directory inside of the extension itself, but, when I try to implement the chrome.runtime.getPackageDirectoryEntry(function(root) {} the console notifies me with a chrome.runtime.getPackageDirectoryEntry is not a function.

function getImage(callback) {
  chrome.runtime.getPackageDirectoryEntry(function(root) {
    root.getDirectory("images", {create: false}, function(localesdir) {
      var reader = localesdir.createReader();
      // Assumes that there are fewer than 100 locales; otherwise see DirectoryReader docs
      reader.readEntries(function(results) {
        callback(results.map(function(de){return de.name;}).sort());
      });
    });
  });
}

getImages(function(data){console.log(data);});

I post the manifest.json too

{
  "name": "My ext",
  "version":"1.1",
  "manifest_version":3,
  "content_scripts": [
    {
      "matches": [
        "*://mysite.dev:*/*"
      ],
      "css": ["content.css"],
      "js": ["content.js"]
    }
  ],
  "web_accessible_resources": ["images/*.png","images/*.gif"]
}

Could anyone help me?

  • 2
    You cannot access `chrome.runtime.getPackageDirectoryEntry` from a content script. Only from a background or popup script. Apart from that, you name your function `getImage` but call it using `getImages`. Another thing: `manifest_version` should be 2. – Iván Nokonoko Feb 02 '17 at 08:26
  • Possible duplicate of [chrome.tabs returns undefined in content script](http://stackoverflow.com/questions/15034859/chrome-tabs-returns-undefined-in-content-script) – Makyen Feb 02 '17 at 10:39

0 Answers0