Search code examples
javascriptgoogle-chrome-extensionweb-deployment

How to get active tab index on Google Chrome extension?


I'm trying to get the index of my active tab using Javascript for my Google Chrome extension. What should I do?


Solution

  • Does this help? It also depends on where it is executed from. This snippet is executed on a window event from popup.

    chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
        chrome.tabs.executeScript(
            tabs[0].id,
            { code: <your code> });
    });