Click here to Skip to main content
15,843,319 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have opened multiple browser windows in google chrome. I want to find all the tab details in the current window browser. ie., no tab details from another browser.

So in my chrome extension, I am getting all the tab details in multiple browser windows.

When I tried, I got the extension window details (ie., popup.html)

Also, I am using Window.open() for displaying my extension (popup.html). So how I can get details of all tabs in the current browser when I clicked the extension?

Can anyone help me.?

What I have tried:

To find all tab details : -

chrome.windows.getAll({ populate: true }, function (windows) {
    for (var i = 0; i < windows.length; ++i) {
        var w = windows[i];
        for (var j = 0; j < w.tabs.length; ++j) {
            var t = w.tabs[j];
            if (isValidTab(t)) {
                tabs.push(t);
            }
        }

    }
    sendResponse({ tabs: tabs });
});


I tried :

chrome.tabs.query({ currentWindow: true }, function (tabs) {
    tabs.forEach(function (tab) {
        console.log('Tab ID: ', tab.id);
    });
});
Posted
Updated 25-Apr-22 9:56am
v2
Comments
Mehul M Thakkar 6-Dec-19 3:43am    
What was the problem? here you will examples of getting tabs https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/docs/examples/api/tabs

You could try chrome.windows.getCurrent()[^] method and see whether it fits your needs.
 
Share this answer
 
Hi. It seems as though you are looking for the tab that the extension is loaded in. Would you not be already there?

I myself would like to undertake iterating through all tams in all chrome windows to make sure that I'm at the correct one.
 
Share this answer
 
Comments
Dave Kreskowiak 25-Apr-22 16:06pm    
I seriously doubt you're going to get a response from the OP over two after the question was asked.

You posted your question as a solution to this question. DON'T.

Open your own question by going to the "Quick answers" menu and click "Ask a question".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900