Toggle current tab from notification in Google Chrome extension

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

I have an extension that, after the tab finishes loading, displays a notification and, if the loaded tab is not selected, offers the user a change to change it to the selected one. Or at least what I want him to do.

Reading the notification API I don’t see a mention of the way to access chrome.tabs.get, but there is chrome.extension.getBackgroundPage(). Does anyone know how to turn this into what I'm looking for?

Thank you very much in advance.

+5
source share
3 answers

You can make a tab selected with:

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

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

+21
source

Not sure, but can you try adding script content to an inactive tab (or only on all tabs) and then send a request to the inactive tab ( sendRequest)? The contents of the script should execute window.focus(). Again, not sure if this works.

Update inactive tab and submit { selected: true }. This should work as it is indicated as an available setting.

+2
source

@serg Chrome v33.

:

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

All Articles