简体   繁体   English

标签对象在chrome扩展名中未定义

[英]tab object is undefined in chrome extension

I am adding a simple listener to a tab that shows the page action in a chrome extension, but each time, tab.id is undefined. 我将一个简单的侦听器添加到一个选项卡中,该选项卡以chrome扩展名显示页面操作,但是每次tab.id都未定义。 This script runs in a background page: 该脚本在后台页面中运行:

chrome.tabs.onUpdated.addListener
(
    function(tab)
    {

        chrome.pageAction.show(tab.id);

    }
);

Each time, I get the error message that tab.id is undefined. 每次,我都会收到一条错误消息,即未定义tab.id。 Why is this happening? 为什么会这样呢? I have tabs in my permissions file: 我的权限文件中有标签:

"permissions":
    [
        "tabs"
    ]

The weirder part is that it works fine in the onCreated version when I add a listener, but the two functions are exactly the same: 奇怪的是,当我添加一个侦听器时,它在onCreated版本中可以正常工作,但是两个功能完全相同:

chrome.tabs.onCreated.addListener
(
    function(tab)
    {
            chrome.pageAction.show(tab.id);
            concole.log("added onCreated listener");
    }
);

That works fine. 很好 What could be causing this? 是什么原因造成的?

According to the documenation for chrome.tabs.onUpdated : 根据chrome.tabs.onUpdated 的文档

The callback parameter should specify a function that looks like this: callback参数应指定一个如下所示的函数:

function(integer tabId, object changeInfo, Tab tab) {...};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM