How to close the current extension tab?

后端 未结 5 836
陌清茗
陌清茗 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:29

    Most likely you're running your code from a content script, where chrome.tabs is undefined. If this is the case, you can instead send a message to the background page and have the background page (which has access to chrome.tabs) make the call.

    Note that from a background page, you would use chrome.tabs.getSelected since getCurrent will return undefined.

提交回复
热议问题