Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch current tab from notification in Google Chrome extension

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 has finished loading, pops up a notification and, if the loaded tab is not selected, offers the user the change to change it to selected. Or at least that's what I want it to do.

Reading the notifications API I don't see any mention of a way of accessing chrome.tabs.get, but there is chrome.extension.getBackgroundPage(). Anyone have any idea on how to turn that into what I'm looking to do?

Many thanks in advance.

like image 544
Dan Atkinson Avatar asked Aug 28 '11 20:08

Dan Atkinson


2 Answers

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.

like image 70
serg Avatar answered Sep 21 '22 13:09

serg


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.

like image 26
pimvdb Avatar answered Sep 22 '22 13:09

pimvdb