I've been working on developing an extension that is meant to locate and swap out a single image, but I'm encountering a SyntaxError in the background script no matter how much I try to fix it.
Here is a screenshot showing the error message
While following this tutorial mostly, my goal differs slightly as I only need to replace one image instead of multiple. I have shared the code I currently have below:
manifest.json
{
"manifest_version" : 2,
"name" : "Test",
"version" : "0.1",
"description" : "test",
"web_accessible_resources" : [
"*.png"
],
"icons" : {
"128": "test.png"
},
"background" : {
"scripts" : ["bgp.js"]
},
"browser_action" : {
"default_icon" : "test.png"
},
"content_scripts" : [
{
"matches" : [
"https://test.com/, https://test.com/*"
],
"js" : ["content.js"]
}
]
}
bgp.js
console.log(“Background running”);
chrome.browserAction.onClicked.addListener(buttonClicked);
function buttonClicked(tab)
{
let msg = {
txt : “Hello”
}
chrome.tabs.sendMessage(tab.id,msg);
}
}
content.js (adding for completeness)
console.log('replacing image');
chrome.runtime.onMessage.addListener(replace);
function replace()
{
let imgs = document.querySelector(".example");
let url = chrome.extension.getURL("test.png");
img.src = url;
console.log(url);
}