How do I set the badge text on a specific tab only?

Hello, I'm curious on how this can be done, I've searched on Google and the documentation on this seems to be very thin. I know how to set the badge number, the only problem is that it affects all of the tabs, and I just want it to affect the active tab, as the number varies from website to website.


This is the code I have to change the badge number, but can anyone tell me what I have to change to make it work for the current tab?


safari.extension.toolbarItems[0].badge = 2;


Thank you.

Replies

You would want to listen for the validate event: https://developer.apple.com/documentation/safariextensions/safarivalidateevent


At that point, you can look at the active tab for each window and update the badge of the window's toolbar item.


This validate event is fired whenever a tab in a window is changed, so that should be called whenever you need to update the badge.