Switch current tab from notification in Google Chrome extension

后端 未结 4 2198
盖世英雄少女心
盖世英雄少女心 2021-02-09 08:31

Am I missing something in the Chrome tabs documentation or is there a way for an extension to change the currently active tab?

I have an extension which, once the tab ha

相关标签:
4条回答
  • 2021-02-09 08:52

    Not sure, but could you try adding a content script in an inactive tab (or just in all tabs), then sending a request to a non-active tab (sendRequest)? The content script should execute window.focus(). Again, not sure whether this works.

    Update the inactive tab, and pass { selected: true }. That should work, since it's listed as an available setting there.

    0 讨论(0)
  • 2021-02-09 08:54

    The answer by @serg has been deprecated since Chrome v33.

    The following is the correct way it should be done now:

    chrome.tabs.update(tabId, { highlighted: true });
    
    0 讨论(0)
  • 2021-02-09 09:04

    Use active:true to switch to tab/focus it, and highlighted:true to select one or many like when you wanna move them around.

    0 讨论(0)
  • 2021-02-09 09:09

    You can make a tab selected with:

    chrome.tabs.update(tabId, {highlighted: true});
    

    Chrome API is available inside notification html, so you can call any chrome.* method you like.

    0 讨论(0)
提交回复
热议问题