Ridwan
Ridwan

Reputation: 367

Uncaught SyntaxError: Unexpected identifier (Chrome extension)

I'm getting an Uncaught SyntaxError: Unexpected identifier on the first line for this snippet of code. I'm new to JavaScript so it's probably something very simple that I'm missing.

chrome.tabs.getSelected(function(Tab tab) {
    var url = tab.url;
    console.log(url);
});
console.log("test");

Upvotes: 0

Views: 2161

Answers (1)

bobince
bobince

Reputation: 536359

chrome.tabs.getSelected(function(Tab tab) {

JavaScript doesn't have static type declarations; when the Chrome docs tell you Tab tab that's just for your information, not what you'd actually write in JS.

Also you're missing an argument to the getSelected method.

chrome.tabs.getSelected(null, function(tab) {

Upvotes: 7

Related Questions