So I'm creating a chrome extension using manifest version 3.
Since it is prohibited to load external sources I've copied the html2canvas.min.js into a local copy in a folder named libs.
I need this library in a content script, named get-div-image.js, since it is necessary to access the DOM. This content script is then fired from a popup.js along side my declared html2canvas.js like so:
chrome.scripting.executeScript({
target: {
tabId: currentTab.id
},
files: ['html2canvas.js']
}, () => {
console.log('html2canvas injected');
chrome.scripting.executeScript({
target: {
tabId: currentTab.id
},
files: ['get-div-image.js']
}, () => console.log('Content script injected and executed.'));
});
my manifest.json looks like this:
{
"manifest_version": 3,
"name": "Images Grabber v2",
"version": "1.0",
"description": "Monitors the screen and takes screenshots.",
"permissions": ["activeTab", "storage", "tabs", "background", "scripting"],
"content_security_policy": {
"extension_pages": "script-src 'self'; object-src 'self';"
},
"background": {
"service_worker": "background.js"
},
"action": {
"default_popup": "popup.html"
},
"host_permissions": ["<all_urls>"],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["contents/get-data-urls.js", "libs/html2canvas.js", "contents/get-div-image.js"]
}
],
"icons": {
"128": "icons/icon.png"
}
}
and my folder structure is the following:
extension/
│
├── manifest.json
│
├── contents/
│ ├── get-data-urls.js
│ └── get-div-image.js
│
└── libs/
└── html2canvas.js
...
But when the extension is fired, I get this 2 errors:
Unchecked runtime.lastError: Could not load file: 'html2canvas.js'.
Unchecked runtime.lastError: Could not load file: 'get-div-image.js'.
What am I doing wrong?
EDIT Changing
files: ['html2canvas.js'] to files: ['libs/html2canvas.js']
and
files: ['get-div-image.js'] to files: ['contents/get-div-image.js']
seems to have suppressed the error, but the script doesnt seems to be injected? And also this notations is not consistent, since I have declared above files: ['get-data-urls.js'] and It works just fine