我如何知道是否通过其他标签页上的链接或内容脚本打开了标签?
如果我可以,我也需要该选项卡的信息。
chrome.tabs.onCreated.addListener(function(id, info, tab){
// tab doesn't contain any such info
});
答案 0 :(得分:4)
您的回调格式错误。
根据documentation,回调需要一个Tab参数,而不是三个。
chrome.tabs.onCreated.addListener(function(tab){
// You now have things like tab.id exposed
// If you have "tabs" permission, also things like tab.url
// You also have tab.openerTabId for "referrer" tab
// If you have host permissions for the tab:
chrome.tabs.executeScript(
tab.id,
{ code: "document.referrer;" },
function(result) {
// Here, you have the "real" referrer,
// which would be empty for tabs opened via `chrome.tabs`
}
);
});