I have a Safari 5 extension that contains a toolbar. Whenever the current tab changes, that toolbar should be updated. I would like to do something like this from my bar\'s
While Safari doesn't have Chrome's specific tab-related API, it does have a perfect solution to this problem.
@Galt was 99% of the way there, with the idea to add an event listener to your injected JavaScript and to dispatchMessage
that information to your extension.
The event handler you're looking for is named focus
, and gets fired every time a tab or window gets selected.
In your injected code:
var tabInFocus = function( event )
{
safari.self.tab.dispatchMessage("tabFocusSwitched","");
}
window.addEventListener("focus", tabInFocus, false);
You can then update your extension's UI, with the data relevant to safari.application.activeBrowserWindow.activeTab