javascripthtmlgoogle-chrome-extensiongoogle-chrome-devtools

How do you use chrome.tabs.getCurrent to get the page object in a Chrome extension?


The code is meant to output the current tab object for the page the user is viewing to the console but it just outputs undefined. It's run from within a browser action page.

chrome.tabs.getCurrent( function(tab){
    console.log(tab);
} );

I've looked at the documentation and as far as I can tell the code seems to match what it says.


Solution

  • Try:

    chrome.tabs.getSelected(null, function(tab){
        console.log(tab);
    });