How to detect safari app extension first time install event?

Is there any event to detect the first time installation of safari app extension and extension add/remove event?


Also, Will Userdefaults will be cleared if safari app extension disabled?

Replies

Shortcuts app helps the use of the events with Apple extensions for safari. Extensions with Ui of the browser works to understand the development techniques in much more flexible way less errors or bugs when shortcuts app is used as a part of extensions

There isn't a built-in way to do it, but you could set a user default inside your app extension after it has been run for the first time.


These won't be cleared when the user disables your extension. Do you want it to be?

It would be great to be able to clear user data after removing the extension.

Oh - so you'd want your extension told when it's about to uninstall? And then be given some time to do that clearing?


One thing you could do is check your extension's state each time your app is launched. You could use:


https://developer.apple.com/documentation/safariservices/sfsafariextensionmanager/2122754-getstateofsafariextension


To check that, and then clear the extension's data through the app if you notice it was turned off.

Thanks for the idea. Should I use SFSafariExtensionState.getStateOfSafariExtension in NSApplicationDelegate.applicationDidFinishLaunching?

Regarding the events of installation / uninstallation. I think it was better to have an api to work with these events. This would save developers from such things as setting a value to user default on first launch and then clearing this value.

Yeah - SFSafariExtensionState.getStateOfSafariExtension will do what you want.


Can you please file feedback using Feedback Assistant about the desire for these events? It will make it easier for us to track. Also, please include why you want this - clearing user data is a great reason to want this functionality. Thanks!

I sent feedback using the Feedback Assistant.

Can't figure out how to clean UserDefaults. I thought of using SFSafariExtensionState.getStateOfSafariExtension in NSApplicationDelegate.applicationDidFinishLaunching, but faced with the fact that UserDefaults has different domains and in NSApplicationDelegate.applicationDidFinishLaunching there is no access to the data that I want to delete. Can you advise me another place to use getStateOfSafariExtension?