The script seems to run correctly but it doesn’t edit anything. If I put the script in the console it works, but by clicking the extension it returns an error that the innerHTML for the given element is undefined.
I’m pretty sure I have all the right permissions. I’m also quite sure it’s not because the DOM has to load.
manifest.json
{
"manifest_version": 3,
"name": "Example name",
"description": "",
"version": "1.0",
"icons": {
"16": "icon16.png",
"32": "icon32.png",
"48": "icon48.png",
"128": "icon128.png"
},
"action": {
},
"permissions": ["activeTab", "scripting"],
"background": {
"service_worker": "background.js"
}
}
background.js
chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
target: {tabId: tab.id},
files: ['content.js']
});
});
And content.js is just one line changing document.getElementById("randomID").innerHTML
to something else, which like I said works in the console, not while executed by the extension.
I’ve only tried searching for some solutions online but couldn’t find anything helpful.
skibidicwigma 123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.