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?
ID is an identifier that allows the tab component to be referenced by other components in the page.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With