<!--
{
  "availability" : [
    "macOS: 10.12.4 -"
  ],
  "documentType" : "symbol",
  "framework" : "SafariServices",
  "identifier" : "/documentation/SafariServices/SFSafariExtensionHandling/validateContextMenuItem(withCommand:in:userInfo:validationHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Safari Services"
    ],
    "preciseIdentifier" : "c:objc(pl)SFSafariExtensionHandling(im)validateContextMenuItemWithCommand:inPage:userInfo:validationHandler:"
  },
  "title" : "validateContextMenuItem(withCommand:in:userInfo:validationHandler:)"
}
-->

# validateContextMenuItem(withCommand:in:userInfo:validationHandler:)

Validates whether a particular contextual menu item should be displayed.

```
optional func validateContextMenuItem(withCommand command: String, in page: SFSafariPage, userInfo: [String : Any]? = nil, validationHandler: @escaping (Bool, String?) -> Void)
```

## Parameters

`command`

The command, specified in the `Info.plist` file, for the context menu item being validated.

`page`

The page where the context menu item is going to be presented.

`userInfo`

Optional message content. If specified, the dictionary’s value objects conform to the W3C standard for safe passing of structured data, such as Boolean objects, numeric values, strings, and arrays.

`validationHandler`

A code block used to set the state of the contextual menu item. The block receives the following parameters:

- shouldHide: A Boolean value that indicates whether the menu item should be hidden.
- text: The text to use for the menu item. Pass `nil` to use the default text from the `Info.plist` file.

## Discussion

If you do not implement this method, the contextual menu item is always available. Otherwise, this method is called before the contextual menu is shown so that you can determine whether the menu item should be displayed and the text that appears in the item.

> Important:
> This method is called by Safari after the user has already clicked to display the menu and before the menu is displayed. Because this is a time-sensitive operation, your extension should call the validation handler as soon as possible after receiving the call. If an extension does not respond in a reasonable period of time, Safari will display the contextual menu item using the default text.

To hide the contextual menu item:

```swift
validationHandler(true, nil)
```

To change the menu text:

```swift
validationHandler(false, "Updated text")
```

To use the default text:

```swift
validationHandler(false, nil)
```

---

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)