Home > OS >  Uncaught SyntaxError: Invalid or unexpected token (Chrome Extension)
Uncaught SyntaxError: Invalid or unexpected token (Chrome Extension)

Time:05-04

I'm basically trying to create an extension that finds and replaces a single image, but the background script keeps coming up with a SyntaxError no matter how much I fiddle with it.

Screenshot of error that comes up

I'm following this tutorial for the most part, except I'm looking to replace a single image instead of multiple. I have pasted the code I have so far with specific details redacted:

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 the sake of completion)

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);

}

CodePudding user response:

You're using the wrong quotation marks in your background script. You're using but you should use " or '.

  • Related