I am facing an issue with my chrome extension. I am unable to call an external script, specifically the ethereum script (web3.min.js), from within my background.js file. The error message I receive is:
Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' blob: filesystem:".
Here are the steps I have taken so far:
1. I tried downloading the script and adding it to the extension folder, as well as to the manifest.json file:
"background":{"scripts":["web3.min.js", "background.js"]}
While this method added the script successfully, I still encountered the same error due to dependencies within the included file. 2. I attempted to use XMLHttpRequest to fetch the script:
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://cdn.jsdelivr.net/gh/ethereum/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="196e7c7b2a37736a592837293729347b7c6d78372a2d">[email protected]</a>/dist/web3.min.js", true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var resp = eval("(" + xhr.responseText + ")");
}
}
xhr.send();
Lastly, I tried appending the script to the DOM:
var script = document.createElement("script"); script.src = "./web3.min.js"; document.head.appendChild(script);
Unfortunately, none of these methods resolved the issue for me. While I understand the security constraints, I am still looking for a viable solution to include web3 in my extension.