Safari Extension: "on install" event?

966 views Asked by At

I am developing an extension for Safari 6 and I want to set some default values for my settings. These default values depend on window.navigator.language, so setting them in Settings.plist does not the trick – I need to run some JS code to set them.

Obviously, this code should only run once right after install. And it shouldn't run after simply reenabling the extension.

Is there an "official" event that I can attach a function with addEventlistener to? Or do I really need the trick with setting a helper variable?

1

There are 1 answers

2
Matt Swain On BEST ANSWER

There is no official event that I know of. But it's pretty easy to do something like this in your global page:

if (!safari.extension.settings.hasRun) {
    safari.extension.settings.hasRun = true;
    safari.extension.settings.lang = window.navigator.language;
}