How to close the current extension tab?

后端 未结 5 866
陌清茗
陌清茗 2020-12-18 18:46

I\'m trying to close the Options page of the extension. I have a Cancel button and I\'m using this code:

chrome.tabs.getCurrent(null, function(tab) {
  chrom         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-18 19:40

    It works for me with one little fix:

    chrome.tabs.getCurrent(function(tab) {
        chrome.tabs.remove(tab.id, function() { });
    });
    

    Just make sure you're really running this code in options page of your extension and not just some HTML page, because chrome.tabs API is available only for extensions.

提交回复
热议问题