got what I hopefully think is a simple issue.
I'm working on a very simple chrome extension, but for some reason, I can't get past the following error when I try to run the code in my content script:
23111634:1 Error in event handler: TypeError: Cannot read properties of undefined (reading 'insertCSS')
My code in that content script:
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(request)
if( request.command === "hideCompanies" ) {
start(request.tab);
}
}
);
function start(tab){
alert("inserting css")
chrome.scripting.insertCSS({
target: {tabId: tab},
files: ['customhs.css']
})
alert("DONE")
sendResponse({farewell: true})
}
the messaging works, just it seems to error out on chrome.scripting.insertCSS. Here is my manifest:
{
"manifest_version": 3,
"name": "",
"description": ".",
"version": "1.0",
"action": {
"default_icon": "toggle.png",
"default_popup": "popup.html"
},
"permissions": ["storage", "activeTab", "scripting", "tabs"],
"background": {
"service_worker": "toggles.js"
},
"content_scripts": [
{
"matches": ["https://*.myownwebsite.com/*"],
"js": ["toggles.js"]
}
]
}
and here is my popup js:
function popup() {
chrome.tabs.query({currentWindow: true, active: true}, function (tabs){
var activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {"command": "hideCompanies", "tab": activeTab.id});
});
}
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("companies").addEventListener("click", popup);
});
Appreciate any and all guidance!