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 script:
safari.self.browserWindow.addEventListener("activeTab", tabChanged, false);
However, that doesn't seem to work. I have tried a number of other event names as well:
- activeTab
- activeTabChanged
- onActiveTab
- onActiveTabChanged
- tab
- tabChanged
- onTab
- onTabChanged
- selectionChanged
- onSelectionChanged
Does anybody know how to detect when the active tab changes?
Not that this is in any way related, but it looks like I would do this in Chrome with:
chrome.tabs.onSelectionChanged.addListener(tabChanged);
I found this method works better than focus event, it can be managed in the background page:
I agree with @imiaou 's answer: from looking at Apple's docs there doesn't seem to be a way to do this :(.
Since I needed to detect tab changes for my extension (which I'm porting over from Chrome), I did the following polling-based workaround which seems to be working fine (in my global page):
I'm unhappy with constantly polling the browser, but I see no other way around this until Apple adds support for these tab-events. If your extension can live with a relatively relaxed tab-switch event trigger latency then this could be a reasonable workaround for now (1.5 sec. max latency is acceptable for my extension, and it doesn't feel like its slowing down the browser).
This code will help to trace the change in URL :- Write this code Inject.js , in side function
Safari 5.1 has several new events for extensions, including an "activate" event that fires when a window or tab is focused.
https://developer.apple.com/documentation/safariextensions/safariactivateevent
It seems Apple doesn't provide much API for us manipulating tabs like Chrome does. Currently, there is no way to detect tab event.
That's the event you are looking for. I'm not sure, but i think is a new addition to the extensions api. You can put in
global.html
or in thepopover.html