Class

SafariExtension

A SafariExtension instance represents your extension outside of the web content; an instance of the class is accessible as safari.extension. The counterpart class to SafariExtension for scripts running within the web content is SafariContentExtension.

Overview

Adding and removing style sheets and scripts. Adding or removing a content style sheet applies to pages immediately. Adding or removing a content script applies only to pages opened or reloaded after the change is made. Removing a style sheet or a script that is in the Info.plist file removes it only from the current browser session.

Whitelists and blacklists. A content script or style sheet may specify a blacklist and a whitelist; both are optional. For a description of the pattern format, see The Extension Builder Interface. The script or style sheet will be applied to a page only in the following cases:

  • The whitelist and blacklist are both empty.

  • The whitelist is empty, and the page’s URL does not match anything on the blacklist.

  • The page’s URL matches a pattern on the whitelist, and the blacklist is empty.

  • The page’s URL matches a pattern on the whitelist and it does not match anything on the blacklist.

Topics

Working with Extensions

bars

All of the bars provided by the target extension.

baseURI

The URI that corresponds to the root of the extension’s bundle.

globalPage

The extension’s global page, or null if the extension doesn’t have a global page.

toolbarItems

All of the toolbar items of an extension.

Accessing Extension Companions

companion

A companion object representing a connection from the extension to a companion native application.

Working with Menus

menus

All of the menus of an extension.

createMenu

Creates and returns a new menu.

removeMenu

Removes the specified menu.

Working with Popovers

popovers

All of the popovers of an extension.

createPopover

Creates and returns a new popover.

removePopover

Removes the specified popover.

Adding and Removing Scripts and Style Sheets

addContentScript

Adds a content script from a string.

addContentScriptFromURL

Adds a content script from a URL.

addContentStyleSheet

Adds a content style sheet from a string.

addContentStyleSheetFromURL

Adds a content style sheet from a URL.

removeContentScript

Removes the specified content script.

removeContentScripts

Removes all content scripts added by this extension.

removeContentStyleSheet

Removes the specified content style sheet.

removeContentStyleSheets

Removes all content style sheets added by this extension.

Loading Content-Blocking Rules

setContentBlocker

Loads content-blocking rules from an object.

Determining Version Numbers

displayVersion

The version number of the extension displayed to the user in the Extensions preference pane.

bundleVersion

The version number of the extension Safari uses to check for updates.

Storing Settings

settings

The storage object for an extension’s normal settings.

secureSettings

The storage object for an extension’s secure settings.