I want to inject script from firefox web extension to tabId thought browser.tabs.executeScript API.
I have a file Browser.js
MyFunc.Browser = (function() {
var self;
function Browser() {
self = this;
}
Browser.getExtensionURI = function() {
return "chrome-extension://";
};
return Browser;
})();
And execute script function:
var executing = browser.tabs.executeScript(tabId, {
file: "js/contentscripts/Browser.js"
});
executing.then(function(results) {
console.log("url: " + tabUrl + ", result", results);
}, function(error) {
return console.log("Inject scripts error: " + error);
});
But script cannot inject to tab and show error.
How I can fix it?
Manifest file:
{
"name": "abc",
"background": {
"page": "background.html"
},
"browser_action": {
"default_icon": "icons/icon_19.png",
"default_popup": "login.html",
},
"content_scripts": [
{
"web_accessible_resources": [
"js/contentscripts/Browser.js",
],
"js": [
"js/contentscripts/ContentScript.js"
],
"matches": [
"file://*/*",
"http://*/*",
"https://*/*"
],
"run_at": "document_end",
"all_frames": true
},
{
"js": [
"js/contentscripts/Browser.js",
],
"matches": [
"file://*/*",
"http://*/*",
"https://*/*"
],
"run_at": "document_start",
"all_frames": true
}
],
"icons": {
"16": "icons/icon_16.png",
"19": "icons/icon_19.png"
},
"incognito": "spanning",
"permissions": [
"activeTab",
"tabs",
"http://*/*",
"https://*/*",
"<all_urls>"
],
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"version": "1.1.16"
}
manifest.json
to your post? – GuarantyMyFunc
in your Browser.js. And I get Content Security Policy errors. – Guarantycould you give a example with this same case for me?
I'm not sure what you are asking for. – Guaranty