Security error in firefox ext while fetching a file

While fetching a files contents with the following code in a background.js file:

function readFile(filename) {
    let response = fetch(`file:///${filename}`);
    console.log(response);
}

I get the following error:

Security Error: Content at moz-extension://86d386b7-2904-441f-8dbe-47f0af9b6bfb/_generated_background_page.html may not load or link to file:///C:/Users/rando/Downloads/jest-26.6.1.zip.
TypeError: NetworkError when attempting to fetch resource.

My manifest file looks like this:

  "permissions": [
    "webNavigation",
    "webRequest",
    "webRequestBlocking",
    "cookies",
    "tabs",
    "http://*/*",
    "https://*/*",
    "ws://*/*",
    "wss://*/*",
    "storage",
    "downloads",
    "sessions",
    "file://*/*"
  ],
  "background": {
    "scripts": [
      "app/scripts/background.js"
    ],
    "persistent": true
  },

How do I solve this error and fetch the contents of the file using the background.js file?

Source: Ask Javascript Questions

LEAVE A COMMENT