我加载了一个处于非活动状态的选项卡,此选项卡在几秒钟后打开了弹出窗口。
当我尝试通过openerTabId
从弹出窗口中抓取chrome.tabs.onCreated
时。它总是显示活动标签tabId
。
以及如何从真实标签中获取openerTabId
(非活动标签)
在后台脚本中:
chrome.tabs.onCreated.addListener((tab)=>{
console.log("tabid: "+tab.id+ "was created");
if(typeof tab.openerTabId != "undefined") console.log("this tab open from tab: "+tab.openerTabId);
});
chrome.tabs.create({url:'http://localhost/test/test.html',active:false});
test.html
中的
<script type="text/javascript">
setTimeout(function(){
window.open("https://google.com.vn");
},3000);
</script>
和结果控制台:
tabid: 359was created
tabid: 361was created
this tab open from tab: 291
我确定tabId 291是活动标签。