Guides and Sample Code


Safari App Extension Programming Guide

Safari App Extensions

Safari app extensions leverage web technologies and native code to extend the web-browsing experience in Safari.

Safari app extensions are available in OS X 10.12 and later and in OS X 10.11.5 when Safari 10 is installed. Using a Safari app extension, you can add new functionality to Safari, read and modify web page content, and communicate with your native application to integrate its content into Safari or send web data to your app.

Safari app extensions are written using a combination of JavaScript, CSS, and native code written in Objective-C or Swift. Safari app extensions are built on the standard app extension model, which offers many benefits:

  • Safari app extensions are bundled inside an app and distributed through the App Store.

  • Because your app and app extension are distributed together, you never have to worry about mismatched revisions being installed on a machine.

  • Your app extension can securely communicate with your app using shared resources.

image: ../Art/safari_app_extension_intro_2x.png

Before reading this guide, you should be familiar with app extension concepts as described in App Extension Programming Guide.

A Safari app extension can do any of the following:

  • Add a toolbar item that either executes a command or displays a popover window.

  • Add contextual menu items.

  • Inject style sheets into a webpage to modify how the page is presented.

  • Inject JavaScript into a webpage to modify the page’s behavior or communicate with your app extension.

A Safari app extension consists of a native binary executable; scripts and style sheets to be injected into webpages; other resources, such as images, that are used by the app extension or its injected scripts and stylesheets; and configuration data that specifies precisely the capabilities and restrictions of your app extension.

image: ../Art/safari_app_extension.pdf

See Also

Safari Services Framework Reference provides documentation on the native classes and protocols used by your Safari app extension. In particular, to implement your app extension, you must create a subclass from the SFSafariExtensionHandler class and override its methods to respond to messages from Safari.

App Extension Programming Guide provides an overview of the app extension programming model.

SafariAppExtensionNamespace Class Reference, SafariAppExtension Class Reference, SafariAppExtensionPage Class Reference, SafariEventTarget Class Reference, and SafariExtensionMessageEvent Class Reference provide information about the JavaScript interfaces that are available to your injected scripts.

Another kind of app extension, a Content Blocker extension, can be used to block web content from being downloaded by Safari. Use the Content Blocker OS X App Extension template to bring your iOS Content Blocker app extension over to OS X. For more information on how Content Blockers work, see App Extension Programming Guide.