lxieyang / chrome-extension-boilerplate-react

A Chrome Extensions boilerplate using React 18 and Webpack 5.
MIT License
3.47k stars 1.08k forks source link

Browser denies any resources loading from contentScript #140

Closed sbahir closed 2 years ago

sbahir commented 2 years ago

If you try to load any resources from contentScript, you will get a browser error

Denying load of chrome-extension://<EXTENSION_ID>/<IMAGE_PATH>. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.

When I open the link chrome-extension://<EXTENSION_ID>/<RESOURCE_PATH> I can access the resource (an image in my case).

I tried the solution suggested here but unfortunately it didn't work

Did anyone hit this issue?

If you have any suggestion, please let me know!

sbahir commented 2 years ago

Found the problem:

From ContentScript, you should load the image using

chrome.runtime.getURL(<RESOURCE_PATH_IN_BROWSER>) and not some import from js

Make sure that you can open the path that is displayed by the browser