A stable identifier for a tab in Safari App Extensions

Hello. Is there a way to get a stable ID for tabs in the Safari App Extensions? I want to store/cache some information about each tab in the global page (namely on page load) and retrieve it later (on a tab button click), but there is no way to get a stable ID for a tab. I tried using the tab object hashValue, but it changes across interactions. With no stable tab IDs there is very few useful things you can do in the global page, since each new interaction (message) from injected scripts or button click cannot be related to previous actions on a given tab.

Accepted Reply

You can store the SFSafariTab object itself in a dictionary. Once you do that, any additional SFSafariTabs for that same tab will have different hash values (as you saw), but you can compare two tabs by using https://developer.apple.com/documentation/objectivec/1418956-nsobject/1418795-isequal?language=objc.


Hope this helps!

Replies

You can store the SFSafariTab object itself in a dictionary. Once you do that, any additional SFSafariTabs for that same tab will have different hash values (as you saw), but you can compare two tabs by using https://developer.apple.com/documentation/objectivec/1418956-nsobject/1418795-isequal?language=objc.


Hope this helps!