Chrome扩展程序:获取引荐标签

Nes*_*Web 3 javascript google-chrome google-chrome-extension

我如何知道是否从另一个选项卡页面上的链接或内容脚本打开了一个选项卡?
如果可以的话,我也需要该标签的信息。

chrome.tabs.onCreated.addListener(function(id, info, tab){
      //  tab doesn't contain any such info
});
Run Code Online (Sandbox Code Playgroud)

Xan*_*Xan 5

您的回调格式错误。

根据文档,回调采用一个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`
    }
  );
});
Run Code Online (Sandbox Code Playgroud)