≡ menus API
≡ Add-on developer resources
≡ Guides
menus API
The part of the menus API that is available in all extension contexts, including content scripts.
Thunderbird’s menus API is similar to the Firefox menus API, but has been adapted to better suit Thunderbird’s specific needs.
Permissions
The following permissions influence the behavior of the API. Depending on which permissions are requested, additional methods might be available, or certain data may be included in responses.
Hint
Request permissions only when needed. Unnecessary requests may result in rejection during ATN review.
accountsRead
See your mail accounts, their identities and their folders.
activeTab
Grant host permission to the currently active tab, allowing to read title, url and favIconUrl properties, or to inject content scripts.
compose
Read and modify your email messages as you compose and send them.
menus
Grant access to some or all methods of the menus API.
menus.overrideContext
Grant access to the menus.overrideContext() method, hiding all default context menu entries and overriding the entire context menu.
messagesRead
Read your email messages.
tabs
Grant host permission to all active and inactive tabs, allowing to read title, url and favIconUrl properties, or to inject content scripts.
Note
The permission menus is required to use messenger.menus.*
.
Functions
create(createProperties, [callback])
– [Added in TB 66]
Creates a new context menu item. Note that if an error occurs during creation, you may not find out until the creation callback fires (the details will be in runtime.lastError).
Parameters
createProperties
checked
The initial state of a checkbox or radio item: true for selected and false for unselected. Only one radio item can be selected at a time in a given group of radio items.
command
Specifies a command to issue for the context click. Can either be a user defined command, or one of the predefined action commands.
contexts
List of contexts this menu item will appear in. Defaults to [‘page’] if not specified.
documentUrlPatterns
Lets you restrict the item to apply only to documents whose URL matches one of the given patterns. (This applies to frames as well.) For details on the format of a pattern, see Match Patterns.
enabled
Whether this context menu item is enabled or disabled. Defaults to true.
icons
Custom icons to display next to the menu item. Custom icons can only be set for items appearing in submenus.
id
The unique ID to assign to this item. Mandatory for event pages. Cannot be the same as another ID for this extension.
onclick
A function that will be called back when the menu item is clicked. Event pages cannot use this.
parentId
The ID of a parent menu item; this makes the item a child of a previously added item.
targetUrlPatterns
Similar to documentUrlPatterns, but lets you filter based on the src attribute of img/audio/video tags and the href of anchor tags.
title
The text to be displayed in the item; this is required unless type is separator. When the context is selection, you can use %s within the string to show the selected text. For example, if this parameter’s value is Translate ‘%s’ to Latin and the user selects the word cool, the context menu item for the selection is Translate ‘cool’ to Latin. To specify an access key for the new menu entry, include a & before the desired letter in the title. For example &Help.
type
viewTypes
List of view types where the menu item will be shown. Defaults to any view, including those without a viewType.
visible
Whether the item is visible in the menu.
callback
Called when the item has been created in the browser. If there were any problems creating the item, details will be available in runtime.lastError.
Required permissions
menus
getTargetElement(targetElementId)
– [Added in TB 66]
Retrieve the element that was associated with a recent contextmenu event.
Parameters
targetElementId
Required permissions
menus
overrideContext(contextOptions)
– [Added in TB 66]
Show the matching menu items from this extension instead of the default menu. This should be called during a contextmenu event handler, and only applies to the menu that opens after this event.
Parameters
contextOptions
context
ContextType to override, to allow menu items from other extensions in the menu. Currently only tab is supported. contextOptions.showDefaults cannot be used with this option.
Supported values:
tab
showDefaults
Whether to also include default menu items in the menu.
tabId
Required when context is tab. Requires the tabs permission.
Required permissions
menus
menus.overrideContext
refresh()
– [Added in TB 66]
Updates the extension items in the shown menu, including changes that have been made since the menu was shown. Has no effect if the menu is hidden. Rebuilding a shown menu is an expensive operation, only invoke this method when necessary.
Required permissions
menus
remove(menuItemId)
– [Added in TB 66]
Removes a context menu item.
Required permissions
menus
removeAll()
– [Added in TB 66]
Removes all context menu items added by this extension.
Required permissions
menus
update(id, updateProperties)
– [Added in TB 66]
Updates a previously created context menu item.
Parameters
id
The ID of the item to update.
updateProperties
The properties to update. Accepts the same values as the create function.
checked
contexts
documentUrlPatterns
enabled
icons
onclick
parentId
The hierarchical parent of the element. Updating an element to become a child of its own descendants is not supported.
targetUrlPatterns
title
type
viewTypes
visible
Whether the item is visible in the menu.
Required permissions
menus
Events
onClicked
– [Added in TB 66]
Fired when a context menu item is clicked. This is a user input event handler. For asynchronous listeners some restrictions apply.
Parameters for onClicked.addListener(listener)
listener(info, tab)
A function that will be called when this event occurs.
Parameters passed to the listener function
info
Information about the item clicked and the context where the click happened.
tab
Required permissions
menus
onHidden
– [Added in TB 66]
Fired when a menu is hidden. This event is only fired if onShown has fired before.
Parameters for onHidden.addListener(listener)
listener()
A function that will be called when this event occurs.
Required permissions
menus
onShown
– [Added in TB 66]
Fired when a menu is shown. The extension can add, modify or remove menu items and call refresh() to update the menu.
Parameters for onShown.addListener(listener)
listener(info, tab)
A function that will be called when this event occurs.
Parameters passed to the listener function
info
Information about the context of the menu action and the created menu items.
tab
Required permissions
menus
Types
ContextType
– [Added in TB 66]
The different contexts a menu can appear in. Specifying all is equivalent to the combination of all other contexts excluding tab and tools_menu. More information about each context can be found in the Supported UI Elements article on developer.thunderbird.net.
string
Supported values:
all
Equivalent to the combination of all other contexts except for tab and tools_menu.
all_message_attachments
Applies when the user context-clicks the summary of the message attachments of a displayed message with more than one attachment.
audio
Applies when the user context-clicks an audio element.
browser_action
Applies when the user context-clicks a browserAction button.
browser_action_menu
Applies when the user opened a browserAction button of type menu.
compose_action
Applies when the user context-clicks a composeAction button.
compose_action_menu
Applies when the user opened a composeAction button of type menu.
compose_attachments
Applies when the user context-clicks an attachment in the compose window.
compose_body
Applies when the user context-clicks in the compose editor.
editable
Applies when the user context-clicks an editable element, like a textarea.
folder_pane
Applies when the user context-clicks in the folder pane of the main Thunderbird window.
frame
Applies when the user context-clicks in a nested iframe.
header_pane_link
image
Applies when the user context-clicks an image.
link
Applies when the user context-clicks on a link.
message_attachments
Applies when the user context-clicks a single attachment of a displayed message.
message_display_action
Applies when the user context-clicks a messageDisplayAction button.
message_display_action_menu
Applies when the user opened a messageDisplayAction button of type menu.
message_list
Applies when the user context-clicks in the message list (a.k.a. thread pane) of the main Thunderbird window.
page
Applies when the user context-clicks in the page, but none of the other page contexts apply (for example, the click is not on an image or a nested iframe or a link).
password
Applies when the user context-clicks on a password input element.
selection
Applies when part of the page is selected.
tab
Applies when the user context-clicks on a tab (specifically, this refers to the tab-strip or other user interface element enabling the user to switch from one tab to another, not to the page itself).
tools_menu
Applies when the user opens the Tools menu of Thunderbird’s main menu.
video
Applies when the user context-clicks a video element.
ItemType
– [Added in TB 66]
The type of menu item.
MenuActionCommand
– [Added in TB 131]
A predefined command to open an action popup.
MenuIconDictionary
– [Added in TB 124]
A dictionary object to specify paths for multiple icons in different sizes, so the best matching icon can be used, instead of scaling a standard icon to fit the pixel density of the user’s display. Each entry is a name-value pair, with name being a size and value being a MenuIconPath.
Example:
{
"16": "icon16.png",
"32": "icon32.png"
}
See the MDN documentation about choosing icon sizes for more information on this topic.
object
MenuIconPath
– [Added in TB 122]
The path for a menu icon may be a relative path to an icon file, a moz-extension: URL, an image data: URL, a blob: URL, or a remote http(s): URL.
string
or
string
OnClickData
– [Added in TB 66]
Information sent when a context menu item is clicked.
object
editable
A flag indicating whether the element is editable (text input, textarea, etc.).
menuItemId
The ID of the menu item that was clicked.
modifiers
An array of keyboard modifiers that were held while the menu item was clicked.
Supported values:
Alt
Command
Ctrl
MacCtrl
Shift
attachments
The selected attachments. The compose permission is required to return attachments of a message being composed. The messagesRead permission is required to return attachments of displayed messages.
button
An integer value of button by which menu item was clicked.
checked
A flag indicating the state of a checkbox or radio item after it is clicked.
displayedFolder
The displayed folder. Only available for the message_list context. The accountsRead permission is required.
fieldId
An identifier of the clicked Thunderbird UI element, if any.
Supported values:
composeBcc
composeCc
composeNewsgroupTo
composeReplyTo
composeSubject
composeTo
frameId
The id of the frame of the element where the context menu was clicked.
frameUrl
The URL of the frame of the element where the context menu was clicked, if it was in a frame.
linkText
If the element is a link, the text of that link.
linkUrl
If the element is a link, the URL it points to.
mediaType
One of image, video, or audio if the context menu was activated on one of these types of elements.
pageUrl
The URL of the page where the menu item was clicked. This property is not set if the click occurred in a context where there is no current page, such as in a launcher context menu.
parentMenuItemId
The parent ID, if any, for the item clicked.
selectedAccount
The selected account in the folder pane, if the context menu was opened on an account entry. Only available for the folder_pane context. The accountsRead permission is required.
selectedFolder
The selected folder in the folder pane (where the context menu was opened). Only available for the folder_pane context. The accountsRead permission is required.
selectedFolders
The selected folders in the folder pane. Only available for the folder_pane context. The accountsRead permission is required. The returned selection includes the folders which would be affected by a context action through Thunderbirds UI, which may not be the actuall selected folders. For example, if the user has multiple folders selected and opens the context menu for a folder outside that selection, only the folder for which the context menu was opened, is returned.
selectedMessages
The selected message(s) in the message list (a.k.a. the thread pane). Only available for the message_list context. The messagesRead permission is required. The returned selection includes the messages which would be affected by a context action through Thunderbirds UI, which may not be the actuall selected messages. For example, if the user has multiple messages selected and opens the context menu for a message outside that selection, only the message for which the context menu was opened, is returned.
selectionText
The text for the context selection, if any.
srcUrl
Will be present for elements with a src URL.
targetElementId
An identifier of the clicked content element, if any. Use getTargetElement(targetElementId) in the page to find the corresponding element.
viewType
The type of view where the menu is clicked. May be unset if the menu is not associated with a view.
wasChecked
A flag indicating the state of a checkbox or radio item before it was clicked.
OnShowData
– [Added in TB 88]
Information sent when a context menu is being shown. Some properties are only included if the extension has host permission for the given context, for example activeTab for content tabs, compose for compose tabs and messagesRead for message display tabs.
object
contexts
A list of all contexts that apply to the menu.
editable
A flag indicating whether the element is editable (text input, textarea, etc.).
menuIds
A list of IDs of the menu items that were shown.
attachments
The selected attachments. The compose permission is required to return attachments of a message being composed. The messagesRead permission is required to return attachments of displayed messages.
displayedFolder
The displayed folder. Only available for the message_list context. The accountsRead permission is required.
fieldId
An identifier of the clicked Thunderbird UI element, if any.
Supported values:
composeBcc
composeCc
composeNewsgroupTo
composeReplyTo
composeSubject
composeTo
frameUrl
The URL of the frame of the element where the context menu was clicked, if it was in a frame.
Note
Host permission is required.
linkText
If the element is a link, the text of that link.
Note
Host permission is required.
linkUrl
If the element is a link, the URL it points to.
Note
Host permission is required.
mediaType
One of image, video, or audio if the context menu was activated on one of these types of elements.
pageUrl
The URL of the page where the menu item was clicked. This property is not set if the click occurred in a context where there is no current page, such as in a launcher context menu.
Note
Host permission is required.
selectedAccount
The selected account in the folder pane, if the context menu was opened on an account entry. Only available for the folder_pane context. The accountsRead permission is required.
selectedFolder
The selected folder in the folder pane (where the context menu was opened). Only available for the folder_pane context. The accountsRead permission is required.
selectedFolders
The selected folders in the folder pane. Only available for the folder_pane context. The accountsRead permission is required. The returned selection includes the folders which would be affected by a context action through Thunderbirds UI, which may not be the actuall selected folders. For example, if the user has multiple folders selected and opens the context menu for a folder outside that selection, only the folder for which the context menu was opened, is returned.
selectedMessages
The selected message(s) in the message list (a.k.a. the thread pane). Only available for the message_list context. The messagesRead permission is required. The returned selection includes the messages which would be affected by a context action through Thunderbirds UI, which may not be the actuall selected messages. For example, if the user has multiple messages selected and opens the context menu for a message outside that selection, only the message for which the context menu was opened, is returned.
selectionText
The text for the context selection, if any.
Note
Host permission is required.
srcUrl
Will be present for elements with a src URL.
Note
Host permission is required.
targetElementId
An identifier of the clicked content element, if any. Use getTargetElement(targetElementId) in the page to find the corresponding element.
viewType
Properties
ACTION_MENU_TOP_LEVEL_LIMIT
The maximum number of top level extension items that can be added to an extension action context menu. Any items beyond this limit will be ignored.