<!--
{
  "availability" : [
    "macOS: 10.12.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SafariServices",
  "identifier" : "/documentation/SafariServices/SFSafariExtensionHandling",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Safari Services"
    ],
    "preciseIdentifier" : "c:objc(pl)SFSafariExtensionHandling"
  },
  "title" : "SFSafariExtensionHandling"
}
-->

# SFSafariExtensionHandling

A protocol for implementing event handling in a Safari app extension.

```
protocol SFSafariExtensionHandling : NSObjectProtocol
```

## Topics

### Receiving Messages in Your App Extension

[`-  messageReceivedWithName:fromPage:userInfo:`](/documentation/SafariServices/SFSafariExtensionHandling/messageReceived(withName:from:userInfo:))

A method the system calls when the extension receives a message from an injected script.

[`-  messageReceivedFromContainingAppWithName:userInfo:`](/documentation/SafariServices/SFSafariExtensionHandling/messageReceivedFromContainingApp(withName:userInfo:))

A method the system calls when the extension receives a message from the extension’s containing app.

### Responding to Context Menu Selections

[`-  contextMenuItemSelectedWithCommand:inPage:userInfo:`](/documentation/SafariServices/SFSafariExtensionHandling/contextMenuItemSelected(withCommand:in:userInfo:))

A method the system calls when a user selects one of the app extension’s context menu items.

[`-  validateContextMenuItemWithCommand:inPage:userInfo:validationHandler:`](/documentation/SafariServices/SFSafariExtensionHandling/validateContextMenuItem(withCommand:in:userInfo:validationHandler:))

Validates whether a particular contextual menu item should be displayed.

### Working with Toolbar Items

[`-  toolbarItemClickedInWindow:`](/documentation/SafariServices/SFSafariExtensionHandling/toolbarItemClicked(in:))

A method the system calls when a user clicks a toolbar item associated with the app extension.

[`-  validateToolbarItemInWindow:validationHandler:`](/documentation/SafariServices/SFSafariExtensionHandling/validateToolbarItem(in:validationHandler:))

Determines if a toolbar menu item should be enabled or have badge text when browser state changes.

### Working with Popovers

[`-  popoverViewController`](/documentation/SafariServices/SFSafariExtensionHandling/popoverViewController())

Asks the handler to provide a popover view controller for display.

[`-  popoverWillShowInWindow:`](/documentation/SafariServices/SFSafariExtensionHandling/popoverWillShow(in:))

Tells the handler that the app extension’s popover is about to be opened.

[`-  popoverDidCloseInWindow:`](/documentation/SafariServices/SFSafariExtensionHandling/popoverDidClose(in:))

Tells the handler that the app extension’s popover was closed.

### Working with Content Blockers

[`-  contentBlockerWithIdentifier:blockedResourcesWithURLs:onPage:`](/documentation/SafariServices/SFSafariExtensionHandling/contentBlocker(withIdentifier:blockedResourcesWith:on:))

Tells the handler which resources a content blocker blocked on a webpage.

### Responding to Page Navigation

[`-  page:willNavigateToURL:`](/documentation/SafariServices/SFSafariExtensionHandling/page(_:willNavigateTo:))

A method the system calls when a webpage is about to navigate to a new URL.

### Instance Methods

[`-  additionalRequestHeadersForURL:completionHandler:`](/documentation/SafariServices/SFSafariExtensionHandling/additionalRequestHeaders(for:completionHandler:))

## See Also

[`+  dispatchMessageWithName:toExtensionWithIdentifier:userInfo:completionHandler:`](/documentation/SafariServices/SFSafariApplication/dispatchMessage(withName:toExtensionWithIdentifier:userInfo:completionHandler:))

Sends a message to a Safari app extension, launching Safari if necessary.

## Relationships

### Inherits From

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

### Conforming Types

[`SFSafariExtensionHandler`](/documentation/SafariServices/SFSafariExtensionHandler)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)