我正在处理一个Chrome扩展,并且我需要在选项卡关闭时获取事件,以便我可以向服务器发送帖子。这是我所拥有的。谷歌浏览器,关闭标签事件监听器
chrome.tabs.onRemoved.addListener(function (tabId) {
alert(tabId);
});
但我不能得到它的工作。任何人有任何想法?
编辑:
当我运行它,它说
Uncaught TypeError: Cannot read property 'onRemoved' of undefined
EDIT2:manifest.json的
{
"name": "WebHistory Extension",
"version": "1.0",
"manifest_version": 2,
"description": "storing webhistory",
"content_scripts":[
{
"matches": ["http://*/*"],
"js": ["jquery-1.7.min.js","myscript.js"],
"run_at": "document_end"
}
],
"permissions" : ["tabs"]
}
看起来像正确的方式去 - [根据文档](http://code.google.com/chrome/extensions/tabs.html#event-onRemoved)有任何错误? – ManseUK
当我运行它时,它说“Uncaught TypeError:无法读取未定义的属性'onRemoved' –
因此,您的代码可能位于错误的地方。它是否在后台页面上执行?你有权设置“标签”吗?请提供您的'manifest.json'设置。 –