我正在尝试关闭扩展程序的“选项”页面。 我有一个“取消”按钮,并且正在使用以下代码:
chrome.tabs.getCurrent(null, function(tab) {
chrome.tabs.remove(tab.id, function() {});
});
当我尝试使用它时,它总是给出以下错误:
Uncaught TypeError: Cannot call method 'getCurrent' of undefined
代码有什么问题吗?
最佳答案
它对我有用,只需一个小修正:
chrome.tabs.getCurrent(function(tab) {
chrome.tabs.remove(tab.id, function() { });
});
只需确保您确实在扩展程序的选项页面中运行此代码,而不仅仅是某些 HTML 页面,因为 chrome.tabs API 仅适用于扩展程序。
关于google-chrome-extension - 如何关闭当前的扩展选项卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8104973/