Chrome how to get the current tab's id?

前端 未结 1 401
终归单人心
终归单人心 2021-01-14 02:49
chrome.tabs.getCurrent(function(tab){
  alert(tab.id);
});

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

相关标签:
1条回答
  • 2021-01-14 03:29

    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.

    0 讨论(0)
提交回复
热议问题