Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome how to get the current tab's id?

chrome.tabs.getCurrent(function(tab){
  alert(tab.id);
});

Is tab an object? Why doesn't it have an id property?

How can I get the id of the current tab?

like image 479
woody Avatar asked May 29 '16 07:05

woody


People also ask

What is the tab ID?

ID is an identifier that allows the tab component to be referenced by other components in the page.

How do I see tab names in Chrome?

If you wish to Label your tabs, go to chrome://flags/ in a new tab. Then, search "Tab Groups" in the Search Bar at the top. Click on "Default" section in the right, on the Tab groups option. Now, select Enable and click submit.


1 Answers

chrome.tabs.getCurrent(function(tab){ console.log(JSON.stringify(tab,null, 2)); }) gives me next

{
  "active": true,
  "audible": false,
  "favIconUrl": "chrome-extension://eggkanocgddhmamlbiijnphhppkpkmkl/img/favicon.png",
  "height": 853,
  "highlighted": true,
  "id": 5280,
  "incognito": false,
  "index": 0,
  "mutedInfo": {
    "muted": false
  },
  "pinned": false,
  "selected": true,
  "status": "complete",
  "title": "Tabs Outliner",
  "url": "chrome-extension://eggkanocgddhmamlbiijnphhppkpkmkl/activesessionview.html?type=main&focusNodeId=5220&altFocusNodeId=5046&scrollToViewWinId=5046",
  "width": 400,
  "windowId": 5279
}

List of all props you can find at https://developer.chrome.com/extensions/tabs#type-Tab --- id marked as optional

The ID of the tab. Tab IDs are unique within a browser session. Under some >circumstances a Tab may not be assigned an ID, for example when querying >foreign tabs using the sessions API, in which case a session ID may be present. >Tab ID can also be set to chrome.tabs.TAB_ID_NONE for apps and devtools >windows.

That's important if you try run code from console

Tab ID can also be set to chrome.tabs.TAB_ID_NONE for apps and devtools >windows.

like image 151
Vasiliy Vanchuk Avatar answered Oct 23 '22 03:10

Vasiliy Vanchuk