---
title: "validateContextMenuItem(withCommand:in:userInfo:validationHandler:)"
framework: safariservices
role: symbol
role_heading: Instance Method
path: "safariservices/sfsafariextensionhandling/validatecontextmenuitem(withcommand:in:userinfo:validationhandler:)"
---

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

Validates whether a particular contextual menu item should be displayed.

## Declaration

```swift
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:

## Mentioned in

Adjusting settings for contextual menu items

## Discussion

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: To change the menu text: To use the default text:

## See Also

### Responding to Context Menu Selections

- [contextMenuItemSelected(withCommand:in:userInfo:)](safariservices/sfsafariextensionhandling/contextmenuitemselected(withcommand:in:userinfo:).md)
