Home  >  Q&A  >  body text

How to allow chrome extension to access his path and files

I'm making an Opera extension and I want to get some images stored in the extension's path.

What this plugin does is, on a specific web page, change the background image URL and some icons to custom icons within the extension.

However, when I run the script, everything becomes invisible, which means it cannot load the image.

Inside the logger I see chrome-extension://invalid/ net::ERR_FAILED but when I log the path it looks normal.

In the manifest.json file, I have webRequest and storage permissions, the plugin also has permissions to read user files, I have dual permissions checked.

Am I missing the permissions that would lock me out? Listing 3 Doesn't it allow changing the background image?

I also tried running the same script on Firefox and everything worked fine.

// get image folder from current plugin path.
let extFolder = chrome.runtime.getURL("images/"); // chrome
//let extFolder = extension.getURL("images/"); // firefox

// should look like: chrome-extension://<id>/images/
console.log(extFolder);

// get element to change.
let board = document.getElementById("board");

// change image.
board.style.backgroundImage = "url('" extFolder "board.png')";

The script I wrote looks like this, why doesn't it work on the opera?

I also tried embedding these images as base64, but since each image is large, not all elements will render the image.

P粉644981029P粉644981029235 days ago740

reply all(1)I'll reply

  • P粉738346380

    P粉7383463802024-02-27 14:28:05

    Okay, I figured out where the problem is...it's Listing 3.

    The reason it works on Firefox is because I'm using manifest version 2 and Opera uses version 3.

    reply
    0
  • Cancelreply