Instance Method


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)



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


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


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.


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


A Boolean value that indicates whether the menu item should be hidden.


The text to use for the menu item. Pass nil to use the default text from the Info.plist file.


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.

To hide the contextual menu item:

Listing 1

Hide the menu item.

validationHandler(true, nil)

To change the menu text:

Listing 2

Change the menu text.

validationHandler(false, “Updated text”)

To use the default text:

Listing 3

Use the default text.

validationHandler(false, nil)

See Also

Responding to Context Menu Selections

func contextMenuItemSelected(withCommand: String, in: SFSafariPage, userInfo: [String : Any]?)

Called when one of the app extension's context menu items is selected.