Is chrome tabId unique across windows

后端 未结 1 339
囚心锁ツ
囚心锁ツ 2021-01-17 09:43

I need to know if the chrome tabId is unique across all the open windows. Incognito and normal. Is it guaranteed that non of the open tabs in all the windows will have the s

1条回答
  •  隐瞒了意图╮
    2021-01-17 10:28

    Yes, the tab ID is unique within a browser session. It's also mentioned in the documentation of chrome.tabs:

    Tab
    ( object )
        id ( integer )
           The ID of the tab. Tab IDs are unique within a browser session.

    If you still don't believe it, create an extension which has the tabs permission, and the right to run in an incognito window. Then run the following code in the background page:

    // Create incognito window
    chrome.windows.create({incognito: true, url:'about:blank'}, showTabId);
    // Create normal window
    chrome.windows.create({incognito: false, url:'about:blank'}, showTabId);
    
    function showTabId(_window) {
        console.log(_window.tabs[0].id);        // Or alert, whatever.
        chrome.tabs.remove(_window.tabs[0].id); // Closes tab & window, user-friendly
    }
    

    The logged numbers are increasing (if you consider two numbers as a too small sample, run the chrome.windows.create method in a loop, until you believe it).

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