0
我正在制作一个Chrome扩展,它在加载后立即关闭某个网站,并且有一个content.js页面和一个background.js页面。该background.js页的工作,并等待来自content.js消息:如何获得运行content.js的选项卡的选项卡ID?
chrome.runtime.onMessage.addListener(function(msg, _, sendResponse) {
if (msg.closeTab) {
chrome.tabs.remove(msg.tabID);
}
});
和代码在content.js发送消息是:
addButton("Close this tab.", function() {
chrome.runtime.sendMessage({closeTab: true, tabID: tab.id});
});
,但我有问题tab
是未定义的。 我正在使用一个按钮来测试功能。
'_'究竟代表什么? – doominabox1