Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tab switch event available for Google Chrome extension?

As a Google Chrome extension, is it possible to listen to tab switches? That is, to be notified when a tab switch has just happened?

(I want to make an extension that, in fullscreen, when switching tabs with the usual Ctrl+PageUp and Ctrl+PageDown keyboard shortcuts, gives visual feedback of the switch and other currently available tabs.)

like image 710
Kelley van Evert Avatar asked Aug 14 '13 14:08

Kelley van Evert


3 Answers

In your manifest.json file add the following:

"permissions":[
    "background",
    "tabs"
],

"background" : {
    "scripts": ["scripts/background.js"],
    "persistent": false
}

In your background.js:

chrome.tabs.onActivated.addListener(function(activeInfo) {
    console.log(activeInfo.tabId);
});
like image 117
Vaibhav Desai Avatar answered Sep 20 '22 07:09

Vaibhav Desai


It's possible, see onActivated at https://developer.chrome.com/docs/extensions/reference/tabs/#event-onActivated

like image 24
Kelley van Evert Avatar answered Sep 24 '22 07:09

Kelley van Evert


note: tab url may not be available when using chrome.tabs.onActivated so use chrome.tabs.onUpdated instead.

like image 29
GorvGoyl Avatar answered Sep 22 '22 07:09

GorvGoyl