Chrome tabId在Windows中是唯一的 [英] Is chrome tabId unique across windows

查看:1382
本文介绍了Chrome tabId在Windows中是唯一的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道所有打开的窗口中的chrome tabId是否是唯一的。隐身和正常。是否可以保证所有窗口中打开的标签不会有相同的tabId?



我搜索了文档,但找不到任何可靠的答案。 是的,标签ID在浏览器会话中是唯一的。 它也在 chrome.tabs
$ b


标签

(object)

    id(整数)

       标签的ID。
标签ID在浏览器会话中是唯一的

如果您仍然不相信,请创建一个具有标签权限的扩展程序,并且有权在隐身窗口中运行。然后在后台页面中运行以下代码:

  //创建隐身窗口
chrome.windows.create({ incognito:true,url:'about:blank'},showTabId);
//创建普通窗口
chrome.windows.create({incognito:false,url:'about:blank'},showTabId);

function showTabId(_window){
console.log(_window.tabs [0] .id); //或者提醒,不管。
chrome.tabs.remove(_window.tabs [0] .id); //关闭标签&窗口,用户友好的
}

记录的数字正在增加(如果您考虑两个数字作为太小的示例,请运行 chrome.windows.create 方法,直到你相信)。

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.

解决方案

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

这篇关于Chrome tabId在Windows中是唯一的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆