Google chrome extension 没有弹出窗口的openerTabId属性
我得到了两个Google chrome extension 没有弹出窗口的openerTabId属性,google-chrome-extension,Google Chrome Extension,我得到了两个htmls,如下所示 index1.html 在这里,我相信弹出窗口也应该存在openerTabIdchrome.tabs.get()弹出选项卡的结果也不包含openerTabId。但是,window.opener对象在弹出窗口中不为空 从 打开此选项卡的选项卡的ID(如果有)。仅当“开启器”选项卡仍然存在时,此属性才存在 在我的例子中,opener选项卡存在。听起来像是一个bug?注意,这不是确切的解决方案,但我发现chrome.webNavigation.onCreatedNav
html
s,如下所示
index1.html
在这里,我相信弹出窗口也应该存在openerTabId
chrome.tabs.get()
弹出选项卡的结果也不包含openerTabId
。但是,window.opener
对象在弹出窗口中不为空
从
打开此选项卡的选项卡的ID(如果有)。仅当“开启器”选项卡仍然存在时,此属性才存在
在我的例子中,
opener
选项卡存在。听起来像是一个bug?注意,这不是确切的解决方案,但我发现chrome.webNavigation.onCreatedNavigationTarget
事件传递sourceTabId
属性,该属性是openerTabId
。但是,这需要webNavigation
权限。注意,这不是确切的解决方案,但我发现chrome.webNavigation.onCreatedNavigationTarget
事件通过sourceTabId
属性,该属性是openerTabId
。但是,这需要webNavigation
权限。是的,听起来像个bug。如果HTML是您自己的扩展文件,您可以尝试使用正确的扩展API chrome.windows.create而不是window.open,它可能会有opener id。是的,听起来像个bug。如果htmls是您自己的扩展文件,您可以尝试使用正确的扩展API chrome.windows.create而不是window.open,它可能会有opener id。
<html>
<body>
<button
onclick="
window.open(
'https://www.google.com',
'sample')">
click
</button>
</body>
</html>
<html>
<body>
<button
onclick="
window.open(
'https://www.google.com',
'sample',
'height=200,width=150')">
click
</button>
</body>
</html>
chrome.tabs.onCreated.addListener(tab => console.log(tab.openerTabId));
// results
//index1 >>> 42
//index2 >>> undefined