Amila
Amila

Reputation: 2819

Is chrome tabId unique across windows

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 same tabId ?

I searched the documentation but could not find any reliable answer.

Upvotes: 19

Views: 3770

Answers (1)

Rob W
Rob W

Reputation: 348972

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).

Upvotes: 24

Related Questions