I have been trying to make a chrome extension which uses CDN link of Sheet.js to analyse some excel data. But getting some error related to 'Content Security Policy'.
Although I have set 'script-src-elem' explicitly in my manifest.json, but still getting following error -
Analyser.js:14 Refused to load the script 'https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.13.5/xlsx.full.min.js' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
Analyser.js:19 Refused to load the script 'https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.13.5/jszip.js' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
I have also tried to make a local of this scripts and loaded them using "web_accessible_resource", that time the scripts got added to the head without any above errors. But later I found that those scripts were not even working.
Manifest.jsom
{
"name": "Extension",
"description": "Trying to Learn",
"version": "1.0",
"manifest_version": 3,
"permissions": [
"storage",
"activeTab",
"scripting"
],
"content_scripts": [
{
"matches": [
"http://www.example.com/*"
],
"js": [
"Analyser.js"
]
}
],
"content_security_policy": {
"extension_pages": "script-src-elem 'self' 'unsafe-inline' https://cdnjs.cloudflare.com; script-src 'self'; object-src 'self'"
}
}
Analyser.js
let cdnxlsx_1 = document.createElement('script');
cdnxlsx_1.src = 'https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.13.5/xlsx.full.min.js';
cdnxlsx_1.type = 'text/javascript';
document.head.appendChild(cdnxlsx_1);
let cdnxlsx_2 = document.createElement('script');
cdnxlsx_2.src = 'https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.13.5/jszip.js';
cdnxlsx_2.type = 'text/javascript';
document.head.appendChild(cdnxlsx_2);
.
.
.
.
.