Safari Developer Library

Developer

SafariExtensionMenuItem Class Reference

Options
Deployment Target:

On This Page

SafariExtensionMenuItem

The SafariExtensionMenuItem class represents items in a menu.

  • command Property

    The command identifier that the menu item sends when activated.

    Declaration

    attribute DOMString command

    Discussion

    If the submenu property is null, setting the value of this property to null, undefined, or the empty string has no effect.

    If the submenu property is defined, validate events are sent using the value of this property; if this property is blank, events are sent using the menu item’s identifier.

    Changes made to the command property take effect immediately, regardless of visibility.

  • identifier Property

    The unique identifier of the menu item.

    Declaration

    readonly attribute DOMString identifier

  • separator Property

    A Boolean value that indicates whether the menu item is a separator.

    Declaration

    readonly attribute boolean separator

    Discussion

    This attribute is optional; the default value is false.

  • title Property

    The title displayed in the menu.

    Declaration

    attribute DOMString title

    Discussion

    If the separator property is true, the value of this property is ignored.

    Setting this property to the empty string, null, or undefined has no effect.

  • image Property

    The URL of the image shown next to the menu item.

    Declaration

    attribute DOMString image

    Discussion

    This attribute can be changed to the URL of an image in the extension bundle. Images larger than 16 x 16 pixels are scaled down to fit. Supported URL schemes are safari-extension, http, and https.

    On Windows, if the menu item is checked, the icon is not displayed.

    To support HiDPI, provide an image of the appropriate resolution at the same location, with the suffix @2x after its name. For example some/path/image-name@2x.png and some/path/image-name.png provide the same image at high resolution and standard resolution, respectively.

  • submenu Property

    The submenu displayed by this menu item.

    Declaration

    attribute SafariExtensionMenu submenu

    Discussion

    If the separator property is true, the value of this property is ignored.

    If the value of this property is null or undefined, no submenu is displayed.

    If the value is a menu that is already being displayed, no submenu is displayed and this menu item’s command is dispatched. This prevents recursive menus.

    If the menu item is visible, changes to this property are not reflected until the next time the menu item is displayed.

    The behavior if the submenu is removed using the SafariExtension removeMenu method while the menu item is visible is undefined.

  • visible Property

    A Boolean value that indicates whether the menu item is visible.

    Declaration

    readonly attribute boolean visible

    Discussion

    Changes made to the menu item while it is visible are not reflected until the next time it presented, except for changes made to the command property, which take effect immediately.

  • disabled Property

    A Boolean value that indicates whether a menu item is disabled.

    Declaration

    attribute boolean disabled

    Discussion

    This property is optional; the default value is false.

  • The state of the menu item.

    Declaration

    attribute short checkedState

    Discussion

    For possible values, see Menu Item States. Any other value you set is ignored.

    This property is ignored for separator items.

    This property is optional; the default state is unchecked.

Constants

  • The state of a menu item, indicated by a small icon displayed next to the title.

    Declaration

    Constants

    • UNCHECKED

      1. const short UNCHECKED = 0;
    • CHECKED

      1. const short CHECKED = 1;
    • MIXED

      1. const short MIXED = -1;