I am attempting to inject CSS code into the active tab from a chrome extension, yet nothing I have looked at online so far has worked for me. I am fairly new to all of this, so apologies if my question is a bit naive and I am just missing something basic. Here is what I have come up with so far:
function inject_1(){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
css = 'body { background-color = "red" !important; }';
chrome.scripting.insertCSS(
{
target: {tabId: tabs[0].id},
css: css,
}, function() {
if (chrome.runtime.lastError) {
message.innerText = 'There was an error injecting css : \n' + chrome.runtime.lastError.message;
}
});
});
}
Here is a secondary method I tried:
function inject_2(){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.scripting.executeScript(
{
target: {tabId: tabs[0].id},
files: ["inject.css"],
}, function() {
if (chrome.runtime.lastError) {
message.innerText = 'There was an error injecting css : \n' + chrome.runtime.lastError.message;
}
});
});
}
Neither function returns an error message, but they also don't change the webpage at all. I would greatly appreciate any help with this (rework of my code or something completely new to try). Thanks.