Converting Greasemonkey Scripts

Safari extensions can inject JavaScript and CSS, so bringing Greasemonkey scripts to Safari is generally quite straightforward. You need to add your injected content to your extension’s bundle and add these files to your extension’s list of injected scripts and style sheets using the Extension Builder. You can also inject scripts and style sheets at runtime using methods on the SafariExtension object. For more information, see Injecting Scripts and Injecting Styles.

One important difference is how you access your extension’s settings. The settings API isn’t directly available to injected scripts because they are run as part of the web content layer. To access settings, dispatch a message from the injected script to the global page via the SafariContentBrowserTabProxy object. Because the global page is part of the application layer, scripts running in it can access your extension’s settings. Then dispatch a message that contains the settings information from the global page back to the injected script.

Safari extensions must be digitally signed before they can be installed. To get your signing certificate, visit the Safari Dev Center.