repo_id
stringlengths
22
103
file_path
stringlengths
41
147
content
stringlengths
181
193k
__index_level_0__
int64
0
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus/refresh/index.md
--- title: menus.refresh() slug: Mozilla/Add-ons/WebExtensions/API/menus/refresh page-type: webextension-api-function browser-compat: webextensions.api.menus.refresh --- {{AddonSidebar}} Refreshes a menu that's being shown. Updates the extension's menu items in the menu that the browser is currently showing, including changes that have been made since the menu was shown. Has no effect if the menu is not being shown. Rebuilding a shown menu is an expensive operation, only invoke this method when necessary. This would typically be called from inside a {{WebExtAPIRef("menus.onShown")}} event handler, after the handler has made any updates to the menu. Firefox makes this function available via the `contextMenus` namespace as well as the `menus` namespace. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint browser.menus.refresh() ``` ### Parameters None. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that is fulfilled with no arguments. ## Browser compatibility {{Compat}} ## Examples This example listens for the context menu to be shown over a link, then updates the `openLabelledId` menu item with the link's hostname: ```js function updateMenuItem(linkHostname) { browser.menus.update(openLabelledId, { title: `Open (${linkHostname})`, }); browser.menus.refresh(); } browser.menus.onShown.addListener((info) => { if (!info.linkUrl) { return; } let linkElement = document.createElement("a"); linkElement.href = info.linkUrl; updateMenuItem(linkElement.hostname); }); ``` {{WebExtExamples}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus/gettargetelement/index.md
--- title: menus.getTargetElement() slug: Mozilla/Add-ons/WebExtensions/API/menus/getTargetElement page-type: webextension-api-function browser-compat: webextensions.api.menus.getTargetElement --- {{AddonSidebar}} Returns the element for a given `targetElementId` This method is available to all extension script contexts (content scripts, background pages and other extension pages) and returns the element for a given `info.targetElementId`, provided that the element still exists in the document where the method is invoked. The method only works in the document that includes the right-clicked element and the `targetElementId` expires when the user opens another context menu. > **Note:** `menus.getTargetElement` only return the requested element if called in the same context as the document that contains the element, for example using content scripts (as shown in the example below). An extension requires the "menus" permission to use this API. ## Syntax ```js-nolint let elem = browser.menus.getTargetElement(targetElementId); ``` ### Parameters - `targetElementId` - : The property of the `{{WebExtAPIRef("menus.OnClickData")}}` object passed to the `{{WebExtAPIRef("menus.onClicked")}}` handler or `{{WebExtAPIRef("menus.onShown")}}` event. ### Return value The element referred to by the `targetElementId` parameter. If the `targetElementId` parameter is not valid, the method returns `null`. ## Examples The following example uses the `getTargetElement` method to get the element referred to by the `info.targetElementId` property and then removes it. ```js browser.menus.create({ title: "Remove element", documentUrlPatterns: ["*://*/*"], contexts: [ "audio", "editable", "frame", "image", "link", "page", "password", "video", ], onclick(info, tab) { browser.tabs.executeScript(tab.id, { frameId: info.frameId, code: `browser.menus.getTargetElement(${info.targetElementId}).remove();`, }); }, }); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} ## See also - {{WebExtAPIRef("menus.create")}} - {{WebExtAPIRef("menus.OnClickData")}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus/onclicked/index.md
--- title: menus.onClicked slug: Mozilla/Add-ons/WebExtensions/API/menus/onClicked page-type: webextension-api-event browser-compat: webextensions.api.menus.onClicked --- {{AddonSidebar}} Fired when a menu item is clicked. For compatibility with other browsers, Firefox makes this event available via the `contextMenus` namespace as well as the `menus` namespace. ## Syntax ```js-nolint browser.menus.onClicked.addListener(listener) browser.menus.onClicked.removeListener(listener) browser.menus.onClicked.hasListener(listener) ``` Events have three functions: - `addListener(listener)` - : Adds a listener to this event. - `removeListener(listener)` - : Stop listening to this event. The `listener` argument is the listener to remove. - `hasListener(listener)` - : Check whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. ## addListener syntax ### Parameters - `listener` - : The function called when this event occurs. The function is passed these arguments: - `info` - : {{WebExtAPIRef('menus.OnClickData')}}. Information about the item clicked and the context where the click happened. - `tab` - : {{WebExtAPIRef('tabs.Tab')}}. The details of the tab where the click took place. If the click did not take place in or on a tab, this parameter will be missing. ## Browser compatibility {{Compat}} ## Examples This example listens for clicks on a menu item, then log the item's ID and the tab ID: ```js browser.menus.create({ id: "click-me", title: "Click me!", contexts: ["all"], }); browser.menus.onClicked.addListener((info, tab) => { console.log(`Item ${info.menuItemId} clicked in tab ${tab.id}`); }); ``` {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.contextMenus`](https://developer.chrome.com/docs/extensions/reference/contextMenus/#event-onClicked) API. This documentation is derived from [`context_menus.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/context_menus.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus/action_menu_top_level_limit/index.md
--- title: menus.ACTION_MENU_TOP_LEVEL_LIMIT slug: Mozilla/Add-ons/WebExtensions/API/menus/ACTION_MENU_TOP_LEVEL_LIMIT page-type: webextension-api-property browser-compat: webextensions.api.menus.ACTION_MENU_TOP_LEVEL_LIMIT --- {{AddonSidebar}} The maximum number of top level extension items that can be added to a menu item whose {{WebExtAPIRef("contextMenus.ContextType", "ContextType")}} is "browser_action" or "page_action". Any items beyond this limit will be ignored. Its value is `6` on Firefox and Chrome. For compatibility with other browsers, Firefox makes this property available via the `contextMenus` namespace as well as the `menus` namespace. ## Browser compatibility {{Compat}} {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.contextMenus`](https://developer.chrome.com/docs/extensions/reference/contextMenus/#property-ACTION_MENU_TOP_LEVEL_LIMIT) API. This documentation is derived from [`context_menus.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/context_menus.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus/removeall/index.md
--- title: menus.removeAll() slug: Mozilla/Add-ons/WebExtensions/API/menus/removeAll page-type: webextension-api-function browser-compat: webextensions.api.menus.removeAll --- {{AddonSidebar}} Removes all menu items added by the extension. For compatibility with other browsers, Firefox makes this method available via the `contextMenus` namespace as well as the `menus` namespace. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let removing = browser.menus.removeAll() ``` ### Parameters None. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with no arguments when all items have been removed. ## Browser compatibility {{Compat}} ## Examples This example adds two menu items. When the user clicks the item labeled "Remove all!", the extension removes both items using `removeAll()`. ```js function onRemoved() { console.log("items removed successfully"); } browser.menus.create({ id: "click-me", title: "Click me!", contexts: ["all"], }); browser.menus.create({ id: "remove-all", title: "Remove all!", contexts: ["all"], }); browser.menus.onClicked.addListener((info, tab) => { if (info.menuItemId === "remove-all") { let removing = browser.menus.removeAll(); removing.then(onRemoved); } }); ``` {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.contextMenus`](https://developer.chrome.com/docs/extensions/reference/contextMenus/#method-removeAll) API. This documentation is derived from [`context_menus.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/context_menus.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus/onhidden/index.md
--- title: menus.onHidden slug: Mozilla/Add-ons/WebExtensions/API/menus/onHidden page-type: webextension-api-event browser-compat: webextensions.api.menus.onHidden --- {{AddonSidebar}} Fired when the browser stops displaying a menu: for example because the user clicked outside it or selected an item. It is only triggered for menus that can be manipulated using the {{WebExtAPIRef("menus")}} API itself: this includes the context menu, the browser's tools menu, and the bookmarks menu. This is most likely to be used in combination with the {{WebExtAPIRef("menus.onShown")}} and {{WebExtAPIRef("menus.refresh()")}} APIs: an extension can update the menu when it is shown, then undo the changes when it is hidden. Firefox makes this event available via the `contextMenus` namespace as well as the `menus` namespace. ## Syntax ```js-nolint browser.menus.onHidden.addListener(listener) browser.menus.onHidden.removeListener(listener) browser.menus.onHidden.hasListener(listener) ``` Events have three functions: - `addListener(listener)` - : Adds a listener to this event. - `removeListener(listener)` - : Stop listening to this event. The `listener` argument is the listener to remove. - `hasListener(listener)` - : Check whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. ## addListener syntax ### Parameters - `listener` - : The function called when this event occurs. The function is passed no parameters. ## Browser compatibility {{Compat}} ## Examples This example just logs a message whenever a menu is hidden: ```js function hidden() { console.log("Menu was hidden"); } browser.menus.onHidden.addListener(hidden); ``` {{WebExtExamples}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus/update/index.md
--- title: menus.update() slug: Mozilla/Add-ons/WebExtensions/API/menus/update page-type: webextension-api-function browser-compat: webextensions.api.menus.update --- {{AddonSidebar}} Updates a previously created menu item. For compatibility with other browsers, Firefox makes this method available via the `contextMenus` namespace as well as the `menus` namespace. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let updating = browser.menus.update( id, // integer or string updateProperties // object ) ``` ### Parameters - `id` - : `integer` or `string`. The ID of the item to update. - `updateProperties` - : `object`. The properties to update. The same as the `createProperties` object passed to {{WebExtAPIRef("menus.create()", "menus.create()")}}, except that `id` can't be set. In addition, `icons` can only be changed on menu commands, not on the top-level context menu. The top-level icon matches the extension's primary icon as declared in the extension's manifest file. - `checked` {{optional_inline}} - : `boolean`. 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` {{optional_inline}} - : `string`. String describing an action that should be taken when the user clicks the item. The recognized values are: - `"_execute_browser_action"`: simulate a click on the extension's browser action, opening its popup if it has one (Manifest V2 only) - `"_execute_action"`: simulate a click on the extension's action, opening its popup if it has one (Manifest V3 only) - `"_execute_page_action"`: simulate a click on the extension's page action, opening its popup if it has one - `"_execute_sidebar_action"`: open the extension's sidebar See the documentation of special shortcuts in the manifest.json key [`commands`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/commands#special_shortcuts) for details. When one of the recognized values is specified, clicking the item does not trigger the {{WebExtAPIRef("menus.onClicked")}} event; instead, the default action triggers, such as opening a pop-up. Otherwise, clicking the item triggers {{WebExtAPIRef("menus.onClicked")}} and the event can be used to implement fallback behavior. - `contexts` {{optional_inline}} - : `array` of `{{WebExtAPIRef('menus.ContextType')}}`. Array of contexts in which this menu item will appear. If this option is omitted: - if the item's parent has contexts set, then this item will inherit its parent's contexts - otherwise, the item is given a context array of \["page"]. - `documentUrlPatterns` {{optional_inline}} - : `array` of `string`. Lets you restrict the item to apply only to documents whose URL matches one of the given [match patterns](/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns). This applies to frames as well. - `enabled` {{optional_inline}} - : `boolean`. Whether this menu item is enabled or disabled. Defaults to `true`. - `icons` {{optional_inline}} - : `object`. One or more custom icons to display next to the item. Custom icons can only be set for items appearing in submenus. This property is an object with one property for each supplied icon: the property's name should include the icon's size in pixels, and path is relative to the icon from the extension's root directory. The browser tries to choose a 16x16 pixel icon for a normal display or a 32x32 pixel icon for a high-density display. To avoid any scaling, you can specify icons like this: ```js browser.menus.create({ icons: { 16: "path/to/geo-16.png", 32: "path/to/geo-32.png", }, }); ``` Alternatively, you can specify a single SVG icon, and it will be scaled appropriately: ```js browser.menus.create({ icons: { 16: "path/to/geo.svg", }, }); ``` > **Note:** The top-level menu item uses the [icons](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/icons) specified in the manifest rather than what is specified with this key. - `id` {{optional_inline}} - : `string`. The unique ID to assign to this item. Mandatory for event pages. Cannot be the same as another ID for this extension. - `onclick` {{optional_inline}} - : `function`. The function called when the menu item is clicked. Event pages cannot use this: instead, they should register a listener for {{WebExtAPIRef('menus.onClicked')}}. - `parentId` {{optional_inline}} - : `integer` or `string`. The ID of a parent menu item; this makes the item a child of a previously added item. Note: If you have created more than one menu item, then the items will be placed in a submenu. The submenu's parent will be labeled with the name of the extension. - `targetUrlPatterns` {{optional_inline}} - : `array` of `string`. Similar to `documentUrlPatterns`, but lets you filter based on the `href` of anchor tags and the `src` attribute of img/audio/video tags. This parameter supports any URL scheme, even those that are usually not allowed in a match pattern. - `title` {{optional_inline}} - : `string`. The text to be displayed in the item. Mandatory unless `type` is "separator". You can use "`%s`" in the string. If you do this in a menu item, and some text is selected in the page when the menu is shown, then the selected text will be interpolated into the title. For example, if `title` is "Translate '%s' to Pig Latin" and the user selects the word "cool", then activates the menu, then the menu item's title will be: "Translate 'cool' to Pig Latin". If the title contains an ampersand "&" then the next character will be used as an access key for the item, and the ampersand will not be displayed. Exceptions to this are: - If the next character is also an ampersand: then a single ampersand will be displayed and no access key will be set. In effect, "&&" is used to display a single ampersand. - If the next characters are the interpolation directive "%s": then the ampersand will not be displayed and no access key will be set. - If the ampersand is the last character in the title: then the ampersand will not be displayed and no access key will be set. Only the first ampersand will be used to set an access key: subsequent ampersands will not be displayed but will not set keys. So "\&A and \&B" will be shown as "A and B" and set "A" as the access key. - `type` {{optional_inline}} - : `{{WebExtAPIRef('menus.ItemType')}}`. The type of menu item: "normal", "checkbox", "radio", "separator". Defaults to "normal". - `viewTypes` {{optional_inline}} - : `{{WebExtAPIRef('extension.ViewType')}}`. List of view types where the menu item will be shown. Defaults to any view, including those without a `viewType`. - `visible` {{optional_inline}} - : `boolean`. Whether the item is shown in the menu. Defaults to `true`. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with no arguments if the update was successful, or rejected with an error message if the update failed. ## Examples This example creates a menu item, then updates its title when the user clicks it: ```js function onUpdated() { console.log("item updated successfully"); } function onError() { console.log("error updating item:", browser.runtime.lastError); } browser.menus.create({ id: "do-not-click-me", title: "Do not click this button", contexts: ["all"], }); browser.menus.onClicked.addListener((info, tab) => { if (info.menuItemId === "do-not-click-me") { let updating = browser.menus.update(info.menuItemId, { title: "Do not click this button again", }); updating.then(onUpdated, onError); } }); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.contextMenus`](https://developer.chrome.com/docs/extensions/reference/contextMenus/#method-update) API. This documentation is derived from [`context_menus.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/context_menus.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus/onshown/index.md
--- title: menus.onShown slug: Mozilla/Add-ons/WebExtensions/API/menus/onShown page-type: webextension-api-event browser-compat: webextensions.api.menus.onShown --- {{AddonSidebar}} Fired when the browser has shown a menu. An extension can use this event to update its menu items using information that's only available once the menu is shown. Typically an extension will figure out the update in its `onShown` handler and then call {{WebExtAPIRef("menus.refresh()")}} to update the menu itself. The handler can add, remove, or update menu items. For example, the [menu-labelled-open](https://github.com/mdn/webextensions-examples/tree/main/menu-labelled-open) example extension adds a menu item that's shown when the user clicks a link, and that, when clicked, just opens the link. It uses `onShown` and `refresh()` to annotate the menu item with the hostname for the link, so the user can easily see where they will go before they click. Note that an extension should not take too much time before calling `refresh()`, or the update will be noticeable to the user. The handler is passed some information about the menu and its contents, and some information from the page (such as the link and/or selection text). To get access to the information from the page, your extension must have the [host permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#host_permissions) for it. If the `onShown` handler calls any asynchronous APIs, then it's possible that the menu has been closed again before the handler resumes execution. Because of this, if a handler calls any asynchronous APIs, it should check that the menu is still being displayed before it updates the menu. For example: ```js let lastMenuInstanceId = 0; let nextMenuInstanceId = 1; browser.menus.onShown.addListener(async (info, tab) => { let menuInstanceId = nextMenuInstanceId++; lastMenuInstanceId = menuInstanceId; // Call an async function await /* the function to call */ ; // After completing the async operation, check whether the menu is still shown. if (menuInstanceId !== lastMenuInstanceId) { return; // Menu was closed and shown again. } // Now use menus.create/update + menus.refresh. }); browser.menus.onHidden.addListener(() => { lastMenuInstanceId = 0; }); ``` Note that it is possible to call menus API functions synchronously, and in this case you don't have to perform this check: ```js browser.menus.onShown.addListener(async (info, tab) => { browser.menus.update(menuId /*, …*/); // Note: Not waiting for returned promise. browser.menus.refresh(); }); ``` However, if you call these APIs asynchronously, then you do have to perform the check: ```js browser.menus.onShown.addListener(async (info, tab) => { let menuInstanceId = nextMenuInstanceId++; lastMenuInstanceId = menuInstanceId; await browser.menus.update(menuId /*, …*/); // must now perform the check if (menuInstanceId !== lastMenuInstanceId) { return; } browser.menus.refresh(); }); ``` Firefox makes this event available via the `contextMenus` namespace as well as the `menus` namespace. ## Syntax ```js-nolint browser.menus.onShown.addListener(listener) browser.menus.onShown.removeListener(listener) browser.menus.onShown.hasListener(listener) ``` Events have three functions: - `addListener(listener)` - : Adds a listener to this event. - `removeListener(listener)` - : Stop listening to this event. The `listener` argument is the listener to remove. - `hasListener(listener)` - : Check whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. ## addListener syntax ### Parameters - `listener` - : The function called when this event occurs. The function is passed these arguments: - `info` - : `Object`. This is just like the {{WebExtAPIRef('menus.OnClickData')}} object, except it contains two extra properties: - `contexts`: an array of all the {{WebExtAPIRef("menus.ContextType", "contexts")}} that are applicable to this menu. - `menuIds`: an array of IDs of all menu items belonging to this extension that are being shown in this menu. Compared with `menus.OnClickData`, the `info` object also omits the `menuItemId` and `modifiers` properties, because of course these are not available until a menu item has been selected. The `contexts`, `menuIds`, `frameId`, and `editable` properties are always provided. All the other properties in `info` are only provided if the extension has the [host permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#host_permissions) for the page. - `tab` - : {{WebExtAPIRef('tabs.Tab')}}. The details of the tab where the click took place. If the click did not take place in or on a tab, this parameter will be missing. ## Examples This example listens for the context menu to be shown over a link, then updates the `openLabelledId` menu item with the link's hostname: ```js function updateMenuItem(linkHostname) { browser.menus.update(openLabelledId, { title: `Open (${linkHostname})`, }); browser.menus.refresh(); } browser.menus.onShown.addListener((info) => { if (!info.linkUrl) { return; } let linkElement = document.createElement("a"); linkElement.href = info.linkUrl; updateMenuItem(linkElement.hostname); }); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus/itemtype/index.md
--- title: menus.ItemType slug: Mozilla/Add-ons/WebExtensions/API/menus/ItemType page-type: webextension-api-type browser-compat: webextensions.api.menus.ItemType --- {{AddonSidebar}} The type of menu item. ## Type Values of this type are strings. Possible values are: - normal - : A menu item that just displays a label. - checkbox - : A menu item that represents a binary state. It displays a checkmark next to the label. Clicking the item toggles the checkmark. The {{WebExtAPIRef("menus.onClicked")}} listener will be passed two extra properties: "checked", indicating whether the item is checked now, and "wasChecked", indicating whether the item was checked before the click event. - radio - : A menu item that represents one of a group of choices. Just like a checkbox, this also displays a checkmark next to the label, and its {{WebExtAPIRef("menus.onClicked")}} listener is passed "checked" and "wasChecked". However, if you create more than one radio item, then the items function as a group of radio items: only one item in the group can be checked, and clicking an item makes it the checked item. - separator - : A line separating a group of items. ## Browser compatibility {{Compat}} {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.contextMenus`](https://developer.chrome.com/docs/extensions/reference/contextMenus/#type-ItemType) API. This documentation is derived from [`context_menus.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/context_menus.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus/contexttype/index.md
--- title: menus.ContextType slug: Mozilla/Add-ons/WebExtensions/API/menus/ContextType page-type: webextension-api-type browser-compat: webextensions.api.menus.ContextType --- {{AddonSidebar}} The different contexts a menu item can appear in. ## Type Values of this type are strings. The item is displayed when the given context applies. Possible values are: - all - : Specifying 'all' is equivalent to the combination of all other contexts except for 'bookmark', 'tab' and 'tools_menu'. - action - : Applies when the user context-clicks your browser action in a Manifest V3 extension. The maximum number of items that can be added to the top-level browser action context menu is {{WebExtAPIRef("menus.ACTION_MENU_TOP_LEVEL_LIMIT")}}, but you can add any number of items to submenus. - audio - : Applies when the user context-clicks an [audio](/en-US/docs/Web/HTML/Element/audio) element. - bookmark - : Applies when the user context-clicks a bookmark item in the bookmarks toolbar, bookmarks menu, bookmarks sidebar (<kbd>Ctrl</kbd>+<kbd>B</kbd>) and the Library window (<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>B</kbd>). The latter two are supported as of Firefox 66. Requires the "bookmarks" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#api_permissions) in the manifest. - browser_action - : Applies when the user context-clicks your browser action in a Manifest V2 extension. The maximum number of items that can be added to the top-level browser action context menu is {{WebExtAPIRef("menus.ACTION_MENU_TOP_LEVEL_LIMIT")}}, but you can add any number of items to submenus. - editable - : Applies when the user context-clicks an editable element, like a [textarea](/en-US/docs/Web/HTML/Element/textarea). - frame - : Applies when the user context-clicks in a nested [iframe](/en-US/docs/Web/HTML/Element/iframe). - image - : Applies when the user context-clicks an image. - link - : Applies when the user context-clicks on a link. - 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). - page_action - : Applies when the user context-clicks your page action. The maximum number of items that can be added to the top-level page action context menu is {{WebExtAPIRef("menus.ACTION_MENU_TOP_LEVEL_LIMIT")}}, but you can add any number of items to submenus. - password - : Applies when the user context-clicks on a [password input element](/en-US/docs/Web/HTML/Element/input/password). - 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 browser tab to another, not to the page itself). From Firefox 63, clicking the menu item on a tab grants the [activeTab](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#activetab_permission) permission for the tab clicked, even if that isn't the currently active tab. - tools_menu - : The item will be added to the browser's tools menu. Note that this is only available if you access `ContextType` through the `menus` namespace. It is not available if you access it through the `contextMenus` namespace. - video - : Applies when the user context-clicks a [video](/en-US/docs/Web/HTML/Element/video) element. Note that "launcher" is not supported. ## Browser compatibility {{Compat}} {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.contextMenus`](https://developer.chrome.com/docs/extensions/reference/contextMenus/#type-ContextType) API. This documentation is derived from [`context_menus.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/context_menus.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus/onclickdata/index.md
--- title: menus.OnClickData slug: Mozilla/Add-ons/WebExtensions/API/menus/OnClickData page-type: webextension-api-type browser-compat: webextensions.api.menus.OnClickData --- {{AddonSidebar}} Information passed to the {{WebExtAPIRef("menus.onClicked")}} event listener when a menu item is clicked. ## Type Values of this type are objects. They contain the following properties: - `bookmarkId` {{optional_inline}} - : `string`. The ID of the bookmark where the context menu was clicked. - `button` {{optional_inline}} - : `integer`. Which mouse button was pressed. The values are the same as for [`MouseEvent.button`](/en-US/docs/Web/API/MouseEvent/button). - `checked` {{optional_inline}} - : `boolean`. A flag indicating whether a checkbox or radio item was checked after it was clicked. - `editable` - : `boolean`. A flag indicating whether the element is editable: for example, if it is a [textarea](/en-US/docs/Web/HTML/Element/textarea). - `frameId` {{optional_inline}} - : `integer`. The ID of the frame in which the item was clicked. The frame ID can be used in other APIs that accept frame IDs, such as {{WebExtAPIRef("tabs.sendMessage()")}}. If the item was clicked in the top level document, `frameId` is zero. If the item was clicked outside the page entirely (for example, in the `tools_menu` or `tab` context), then `frameId` is `undefined`. - `frameUrl` {{optional_inline}} - : `string`. The URL of the frame of the element where the context menu was clicked, if it was in a frame. - `linkText` {{optional_inline}} - : `string`. If the element is a link, the text for the link. If the link contains no text, the URL itself is given here. - `linkUrl` {{optional_inline}} - : `string`. If the element is a link, the URL it points to. - `mediaType` {{optional_inline}} - : `string`. One of "image", "video", or "audio" if the context menu was activated on one of these types of elements. - `menuItemId` - : `integer` or `string`. The ID of the menu item that was clicked. - `modifiers` - : `array` of `string`. An array containing any modifier keys that were pressed when the item was clicked. Possible values are: "Alt", "Command", "Ctrl", "MacCtrl", and "Shift". On a Mac, if the user has the Control key pressed, then both "Ctrl" and "MacCtrl" are included. - `pageUrl` {{optional_inline}} - : `string`. The URL of the page in which the menu item was clicked. This property is not present if the click occurred in a context where there is no current page, such as on a browser action. - `parentMenuItemId` {{optional_inline}} - : `integer` or `string`. The parent ID, if any, for the item clicked. - `selectionText` {{optional_inline}} - : `string`. If some text was selected in the page, this contains the selected text. - `srcUrl` {{optional_inline}} - : `string`. If present, the `src` value for the media in the clicked element. - `targetElementId` {{optional_inline}} - : `integer`. An identifier of the element, if any, over which the context menu was created. Use {{WebExtAPIRef("menus.getTargetElement()")}} in the content script to locate the element. Note that this is not the [id](/en-US/docs/Web/HTML/Global_attributes/id) attribute of the page element. - `viewType` {{optional_inline}} - : {{WebExtAPIRef("extension.ViewType", "ViewType")}}. The type of extension view. - `wasChecked` {{optional_inline}} - : `boolean`. A flag indicating whether a checkbox or radio item was checked before it was clicked. ## Browser compatibility {{Compat}} {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.contextMenus`](https://developer.chrome.com/docs/extensions/reference/contextMenus/#type-OnClickData) API. This documentation is derived from [`context_menus.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/context_menus.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/menus/overridecontext/index.md
--- title: menus.overrideContext() slug: Mozilla/Add-ons/WebExtensions/API/menus/overrideContext page-type: webextension-api-function browser-compat: webextensions.api.menus.overrideContext --- {{AddonSidebar}} Hide all default Firefox menu items in favor of providing a custom context menu UI. The overrideContext method will cause the matching menu items from this extension to be shown instead of the default menu. This method should be called from a {{domxref("Element/contextmenu_event", "contextmenu")}} DOM event handler, and only applies to the menu that opens after this event. This interface requires the `menus.overrideContext` [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions). ## Syntax ```js-nolint browser.menus.overrideContext( contextOptions // object ) ``` ### Parameters - `contextOptions` - : `object`. Options for how the context menus will be overridden. - `showDefaults` {{optional_inline}} - : `boolean`. Whether to also include default menu items in the menu. - `context` {{optional_inline}} - : `string`. ContextType to override, to allow menu items from other extensions in the menu. Currently only `'bookmark'` and `'tab'` are supported. `showDefaults` cannot be used with this option. - `bookmarkId` {{optional_inline}} - : `string`. Required when context is `'bookmark'`. Requires 'bookmark' permission. - `tabId` {{optional_inline}} - : `integer`. Required when context is `'tab'`. Requires 'tabs' permission. ## Examples Open the tab context menu on your custom UI, in this case: ```js document.addEventListener( "contextmenu", (event) => { const foo = event.target.closest(".foo"); if (foo) { // When the context menu is opened on an element with the foo class // set the context to "opening a tab context menu". browser.menus.overrideContext({ context: "tab", tabId: parseInt(foo.dataset.tabId), }); } }, { capture: true }, ); ``` See [this blog post](https://blog.mozilla.org/addons/2018/11/08/extensions-in-firefox-64/#cm) for more details. ## Browser compatibility {{ Compat }}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/index.md
--- title: action slug: Mozilla/Add-ons/WebExtensions/API/action page-type: webextension-api browser-compat: webextensions.api.action --- {{AddonSidebar}} Adds a button to the browser's toolbar. > **Note:** This API is available in Manifest V3 or higher. It replaces the Manifest V2 APIs {{WebExtAPIRef("browserAction")}} and, in Chrome and Safari, {{WebExtAPIRef("pageAction")}}. A [browser action](/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Toolbar_button) is a button in the browser's toolbar. You can associate a popup with the button. Like a web page, the popup is specified using HTML, CSS, and JavaScript. JavaScript running in the popup gets access to all the same WebExtension APIs as your background scripts, but its global context is the popup, not the current page displayed in the browser. To affect web pages, you need to communicate with them via [messages](/en-US/docs/Mozilla/Add-ons/WebExtensions/Modify_a_web_page#messaging). If you specify a popup, it is shown — and the content loaded — when the user clicks the icon. If you do not specify a popup, an event is dispatched to your extension when the user clicks the icon. The button also has a context menu, and you can add items to this menu with the {{WebExtAPIRef("menus")}} API using the `action` {{WebExtAPIRef("menus.ContextType")}}. You can define most of a browser action's properties declaratively using the [`action`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/action) key in the manifest.json. With the `action` API, you can: - use {{WebExtAPIRef("action.onClicked")}} to listen for clicks on the icon. - get and set the icon's properties — icon, title, popup, and so on. You can get and set these globally across all tabs or for a tab by passing the tab ID as an additional argument. ## Types - {{WebExtAPIRef("action.ColorArray")}} - : An array of four integers in the range 0-255 defining an RGBA color. - {{WebExtAPIRef("action.ImageDataType")}} - : Pixel data for an image. Must be an [`ImageData`](/en-US/docs/Web/API/ImageData) object (for example, from a {{htmlelement("canvas")}} element). ## Functions - {{WebExtAPIRef("action.setTitle()")}} - : Sets the browser action's title. This will be displayed in a tooltip. - {{WebExtAPIRef("action.getTitle()")}} - : Gets the browser action's title. - {{WebExtAPIRef("action.setIcon()")}} - : Sets the browser action's icon. - {{WebExtAPIRef("action.setPopup()")}} - : Sets the HTML document to be opened as a popup when the user clicks on the browser action's icon. - {{WebExtAPIRef("action.getPopup()")}} - : Gets the HTML document set as the browser action's popup. - {{WebExtAPIRef("action.openPopup()")}} - : Open the browser action's popup. - {{WebExtAPIRef("action.setBadgeText()")}} - : Sets the browser action's badge text. The badge is displayed on top of the icon. - {{WebExtAPIRef("action.getBadgeText()")}} - : Gets the browser action's badge text. - {{WebExtAPIRef("action.setBadgeBackgroundColor()")}} - : Sets the badge's background color. - {{WebExtAPIRef("action.getBadgeBackgroundColor()")}} - : Gets the badge's background color. - {{WebExtAPIRef("action.setBadgeTextColor()")}} - : Sets the badge's text color. - {{WebExtAPIRef("action.getBadgeTextColor()")}} - : Gets the badge's text color. - {{WebExtAPIRef("action.getUserSettings()")}} - : Gets the user-specified settings for the browser action. - {{WebExtAPIRef("action.enable()")}} - : Enables the browser action for a tab. By default, browser actions are enabled for all tabs. - {{WebExtAPIRef("action.disable()")}} - : Disables the browser action for a tab, meaning that it cannot be clicked when that tab is active. - {{WebExtAPIRef("action.isEnabled()")}} - : Checks whether the browser action is enabled or not. ## Events - {{WebExtAPIRef("action.onClicked")}} - : Fired when a browser action icon is clicked. This event will not fire if the browser action has a popup. {{WebExtExamples("h2")}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/) API. This documentation is derived from [`action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/enable/index.md
--- title: action.enable() slug: Mozilla/Add-ons/WebExtensions/API/action/enable page-type: webextension-api-function browser-compat: webextensions.api.action.enable --- {{AddonSidebar}} Enables the browser action for a tab. By default, browser actions are enabled for all tabs. > **Note:** This API is available in Manifest V3 or higher. ## Syntax ```js-nolint browser.action.enable( tabId // optional integer ) ``` ### Parameters - `tabId` {{optional_inline}} - : `integer`. The id of the tab for which you want to enable the browser action. ## Examples Disable the browser action when clicked, and re-enable it every time a new tab is opened: ```js browser.tabs.onCreated.addListener(() => { browser.action.enable(); }); browser.action.onClicked.addListener(() => { browser.action.disable(); }); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#method-enable) API. This documentation is derived from [`browser_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/browser_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/getbadgetextcolor/index.md
--- title: action.getBadgeTextColor() slug: Mozilla/Add-ons/WebExtensions/API/action/getBadgeTextColor page-type: webextension-api-function browser-compat: webextensions.api.action.getBadgeTextColor --- {{AddonSidebar}} Gets the text color for the browser action's badge. > **Note:** This API is available in Manifest V3 or higher. In Firefox, unless the badge text color is explicitly set using {{WebExtAPIRef("action.setBadgeTextColor()")}}, the badge text color is automatically set to black or white so as to maximize contrast with the specified badge background color. For example, if you set the badge background color to white, the default badge text color is set to black, and vice versa. Other browsers always use a white text color. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint browser.action.getBadgeTextColor( details // object ) ``` ### Parameters - `details` - : `object`. - `tabId` {{optional_inline}} - : `integer`. Specifies the tab to get the badge text color from. - `windowId` {{optional_inline}} - : `integer`. Specifies the window from which to get the badge text color. <!----> - If `windowId` and `tabId` are both supplied, the function fails. - If `windowId` and `tabId` are both omitted, the global badge text color is returned. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with the retrieved color as a {{WebExtAPIRef('action.ColorArray')}}. ## Examples Log the badge's text color: ```js function onGot(color) { console.log(color); } function onFailure(error) { console.log(error); } browser.action.getBadgeTextColor({}).then(onGot, onFailure); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#method-getBadgeBackgroundColor) API. This documentation is derived from [`browser_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/browser_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/getpopup/index.md
--- title: action.getPopup() slug: Mozilla/Add-ons/WebExtensions/API/action/getPopup page-type: webextension-api-function browser-compat: webextensions.api.action.getPopup --- {{AddonSidebar}} Gets the HTML document set as the popup for this browser action. > **Note:** This API is available in Manifest V3 or higher. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let gettingPopup = browser.action.getPopup( details // object ) ``` ### Parameters - `details` - : An object with the following properties: - `tabId` {{optional_inline}} - : `integer`. The tab whose popup to get. - `windowId` {{optional_inline}} - : `integer`. The windows whose popup to get. <!----> - If `windowId` and `tabId` are both supplied, the function fails. - If `windowId` and `tabId` are both omitted, the global popup is returned. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with a string containing the URL for the popup's document. This will be a fully qualified URL, such as `moz-extension://d1d8a2eb-fe60-f646-af30-a866c5b39942/popups/popup2.html`. ## Examples Get the popup's URL: ```js function gotPopup(popupURL) { console.log(popupURL); } let gettingPopup = browser.action.getPopup({}); gettingPopup.then(gotPopup); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#method-getPopup) API. This documentation is derived from [`browser_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/browser_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/getbadgebackgroundcolor/index.md
--- title: action.getBadgeBackgroundColor() slug: Mozilla/Add-ons/WebExtensions/API/action/getBadgeBackgroundColor page-type: webextension-api-function browser-compat: webextensions.api.action.getBadgeBackgroundColor --- {{AddonSidebar}} Gets the background color of the browser action's badge. > **Note:** This API is available in Manifest V3 or higher. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint browser.action.getBadgeBackgroundColor( details // object ) ``` ### Parameters - `details` - : An object with the following properties: - `tabId` {{optional_inline}} - : `integer`. Specifies the tab to get the badge background color from. - `windowId` {{optional_inline}} - : `integer`. Specifies the window from which to get the badge background color. <!----> - If `windowId` and `tabId` are both supplied, the function fails. - If `windowId` and `tabId` are both omitted, the global badge background color is returned. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with the retrieved color as a {{WebExtAPIRef('action.ColorArray')}}. ## Examples Log the badge's background color: ```js function onGot(color) { console.log(color); } function onFailure(error) { console.log(error); } browser.action.getBadgeBackgroundColor({}).then(onGot, onFailure); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#method-getBadgeBackgroundColor) API. This documentation is derived from [`browser_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/browser_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/colorarray/index.md
--- title: action.ColorArray slug: Mozilla/Add-ons/WebExtensions/API/action/ColorArray page-type: webextension-api-type browser-compat: webextensions.api.action.ColorArray --- {{AddonSidebar}} ## Type An `array` of four integers in the range 0-255, defining an RGBA color. The four values specify the following channels: 1. Red 2. Green 3. Blue 4. Alpha (opacity). For example, opaque red is `[255, 0, 0, 255]`. {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#type-ColorArray) API. This documentation is derived from [`browser_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/browser_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/setbadgebackgroundcolor/index.md
--- title: action.setBadgeBackgroundColor() slug: Mozilla/Add-ons/WebExtensions/API/action/setBadgeBackgroundColor page-type: webextension-api-function browser-compat: webextensions.api.action.setBadgeBackgroundColor --- {{AddonSidebar}} Sets the background color for the badge. Tabs without a specific badge background color will inherit the global badge background color, which defaults to `[217, 0, 0, 255]` in Firefox. > **Note:** This API is available in Manifest V3 or higher. In Firefox, unless the badge text color is explicitly set using {{WebExtAPIRef("action.setBadgeTextColor()")}}, then the badge text color iw automatically set to black or white to maximize contrast with the specified badge background color. For example, if you set the badge background color to white, the default badge text color is set to black, and vice versa. Other browsers always use a white text color, so setting a dark background may be preferable to ensure the text is readable. ## Syntax ```js-nolint browser.action.setBadgeBackgroundColor( details // object ) ``` ### Parameters - `details` - : An object with the following properties: - `color` - : The color, specified as one of: - a string: any CSS [\<color>](/en-US/docs/Web/CSS/color_value) value, for example `"red"`, `"#FF0000"`, or `"rgb(255 0 0)"`. If the string is not a valid color, the returned promise will be rejected and the background color won't be altered. - a `{{WebExtAPIRef('action.ColorArray')}}` object. - `null`. If a `tabId` is specified, it removes the tab-specific badge background color so that the tab inherits the global badge background color. Otherwise it reverts the global badge background color to the default value. - `tabId` {{optional_inline}} - : `integer`. Sets the badge background color only for the given tab. The color is reset when the user navigates this tab to a new page. - `windowId` {{optional_inline}} - : `integer`. Sets the badge background color only for the given tab. <!----> - If `windowId` and `tabId` are both supplied, the function fails and the color is not set. - If `windowId` and `tabId` are both omitted, the global badge background color is set instead. ## Examples A background color that starts off as red, and turns green when the browser action is clicked: ```js browser.action.setBadgeText({ text: "1234" }); browser.action.setBadgeBackgroundColor({ color: "red" }); browser.action.onClicked.addListener(() => { browser.action.setBadgeBackgroundColor({ color: "green" }); }); ``` Set the badge background color only for the active tab: ```js browser.action.setBadgeText({ text: "1234" }); browser.action.setBadgeBackgroundColor({ color: "red" }); browser.action.onClicked.addListener((tab) => { browser.action.setBadgeBackgroundColor({ color: "green", tabId: tab.id, }); }); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} The default color in Firefox is: `[217, 0, 0, 255]`. > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#method-setBadgeBackgroundColor) API. This documentation is derived from [`browser_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/browser_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/settitle/index.md
--- title: action.setTitle() slug: Mozilla/Add-ons/WebExtensions/API/action/setTitle page-type: webextension-api-function browser-compat: webextensions.api.action.setTitle --- {{AddonSidebar}} Sets the browser action's title. The title is displayed in a tooltip over the browser action's icon. You can pass a `tabId` in or a `windowId` as an optional parameter — if you do this then the title is changed only for the specified tab or window. Tabs or windows without a specific title inherit the global title text, which defaults to the [`default_title`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_action) or [`name`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/name) specified in the manifest. > **Note:** This API is available in Manifest V3 or higher. ## Syntax ```js-nolint browser.action.setTitle( details // object ) ``` ### Parameters - `details` - : `object`. The new title and optionally the ID of the tab or window to target. - `title` - : `string` or `null`. The string the browser action should display when moused over. If `title` is an empty string, the used title will be the extension name, but {{WebExtAPIRef("action.getTitle")}} will still provide the empty string. If `title` is `null`: - If `tabId` is specified, and the tab has a tab-specific title set, then the tab will inherit the title from the window to which it belongs. - if `windowId` is specified, and the window has a window-specific title set, then the window will inherit the global title. - Otherwise, the global title will be reset to the manifest title. - `tabId` {{optional_inline}} - : `integer`. Sets the title only for the given tab. - `windowId` {{optional_inline}} - : `integer`. Sets the title for the given window. <!----> - If `windowId` and `tabId` are both supplied, the function fails and the title is not set. - If `windowId` and `tabId` are both omitted, the global title is set. ## Examples This code switches the title between "this" and "that" each time the user clicks the browser action: ```js function toggleTitle(title) { if (title === "this") { browser.action.setTitle({ title: "that" }); } else { browser.action.setTitle({ title: "this" }); } } browser.action.onClicked.addListener(() => { let gettingTitle = browser.action.getTitle({}); gettingTitle.then(toggleTitle); }); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#method-setTitle) API. This documentation is derived from [`browser_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/browser_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/seticon/index.md
--- title: action.setIcon() slug: Mozilla/Add-ons/WebExtensions/API/action/setIcon page-type: webextension-api-function browser-compat: webextensions.api.action.setIcon --- {{AddonSidebar}} Sets the icon for the browser action. > **Note:** This API is available in Manifest V3 or higher. You can specify a single icon as either the path to an image file or a {{WebExtAPIRef('action.ImageDataType')}} object. You can specify multiple icons in different sizes by supplying a dictionary containing multiple paths or `ImageData` objects. This means the icon doesn't have to be scaled for a device with a different pixel density. Tabs without a specific icon will inherit the global icon, which defaults to the [`default_icon`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_action) specified in the manifest. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let settingIcon = browser.action.setIcon( details // object ) ``` ### Parameters - `details` - : `object`. An object containing either `imageData` or `path` properties, and optionally a `tabId` property. - `imageData` {{optional_inline}} - : `{{WebExtAPIRef('action.ImageDataType')}}` or `object`. This is either a single `ImageData` object or a dictionary object. Use a dictionary object to specify multiple `ImageData` objects in different sizes, so the icon does not have to be scaled for a device with a different pixel density. If `imageData` is a dictionary, the value of each property is an `ImageData` object, and its name is its size, like this: ```js let settingIcon = browser.action.setIcon({ imageData: { 16: image16, 32: image32, }, }); ``` The browser will choose the image to use depending on the screen's pixel density. See [Choosing icon sizes](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_action#choosing_icon_sizes) for more information on this. - `path` {{optional_inline}} - : `string` or `object`. This is either a relative path to an icon file or it is a dictionary object. Use a dictionary object to specify multiple icon files in different sizes, so the icon does not have to be scaled for a device with a different pixel density. If `path` is a dictionary, the value of each property is a relative path, and its name is its size, like this: ```js let settingIcon = browser.action.setIcon({ path: { 16: "path/to/image16.jpg", 32: "path/to/image32.jpg", }, }); ``` The browser will choose the image to use depending on the screen's pixel density. See [Choosing icon sizes](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_action#choosing_icon_sizes) for more information on this. - `tabId` {{optional_inline}} - : `integer`. Sets the icon only for the given tab. The icon is reset when the user navigates this tab to a new page. - `windowId` {{optional_inline}} - : `integer`. Sets the icon for the given window. <!----> - If `windowId` and `tabId` are both supplied, the function fails and the icon is not set. - If `windowId` and `tabId` are both omitted, the global icon is set. If each one of `imageData` and `path` is one of `undefined`, `null` or empty object: - If `tabId` is specified, and the tab has a tab-specific icon set, then the tab will inherit the icon from the window to which it belongs. - If `windowId` is specified, and the window has a window-specific icon set, then the window will inherit the global icon. - Otherwise, the global icon will be reset to the manifest icon. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with no arguments once the icon has been set. ## Examples The code below uses a browser action to toggle a listener for {{WebExtAPIRef("webRequest.onHeadersReceived")}}, and uses `setIcon()` to indicate whether listening is on or off: ```js function logResponseHeaders(requestDetails) { console.log(requestDetails); } function startListening() { browser.webRequest.onHeadersReceived.addListener( logResponseHeaders, { urls: ["<all_urls>"] }, ["responseHeaders"], ); browser.action.setIcon({ path: "icons/listening-on.svg" }); } function stopListening() { browser.webRequest.onHeadersReceived.removeListener(logResponseHeaders); browser.action.setIcon({ path: "icons/listening-off.svg" }); } function toggleListener() { if (browser.webRequest.onHeadersReceived.hasListener(logResponseHeaders)) { stopListening(); } else { startListening(); } } browser.action.onClicked.addListener(toggleListener); ``` The code below sets the icon using an [`ImageData`](/en-US/docs/Web/API/ImageData) object: ```js function getImageData() { let canvas = document.createElement("canvas"); let ctx = canvas.getContext("2d"); ctx.fillStyle = "green"; ctx.fillRect(10, 10, 100, 100); return ctx.getImageData(50, 50, 100, 100); } browser.action.onClicked.addListener(() => { browser.action.setIcon({ imageData: getImageData() }); }); ``` The following snippet updates the icon when the user clicks it, but only for the active tab: ```js browser.action.onClicked.addListener((tab) => { browser.action.setIcon({ tabId: tab.id, path: "icons/updated-48.png", }); }); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#method-setIcon) API. This documentation is derived from [`browser_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/browser_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/onclicked/index.md
--- title: action.onClicked slug: Mozilla/Add-ons/WebExtensions/API/action/onClicked page-type: webextension-api-event browser-compat: webextensions.api.action.onClicked --- {{AddonSidebar}} Fired when a browser action icon is clicked. This event will not fire if the browser action has a popup. > **Note:** This API is available in Manifest V3 or higher. To define a right-click action, use the [`contextMenus`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/menus) API with the "browser_action" [context type](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/menus/ContextType). ## Syntax ```js-nolint browser.action.onClicked.addListener(listener) browser.action.onClicked.removeListener(listener) browser.action.onClicked.hasListener(listener) ``` Events have three functions: - `addListener(listener)` - : Adds a listener to this event. - `removeListener(listener)` - : Stop listening to this event. The `listener` argument is the listener to remove. - `hasListener(listener)` - : Check whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. ## addListener syntax ### Parameters - `listener` - : The function called when this event occurs. The function is passed these arguments: - `tab` - : {{WebExtAPIRef('tabs.Tab')}}. The tab that was active when the icon was clicked. - `OnClickData` - : An object containing information about the click. - `modifiers` - : An `array`. The keyboard modifiers active at the time of the click, being one or more of `Shift`, `Alt`, `Command`, `Ctrl`, or `MacCtrl`. - `button` - : An `integer`. Indicates the button used to click the page action icon: `0` for a left-click or a click not associated with a mouse, such as one from the keyboard and `1` for a middle button or wheel click. Note that the right-click is not supported because Firefox consumes that click to display the context menu before this event is triggered. ## Examples When the user clicks the icon, disable it for the active tab, and log the tab's URL: ```js browser.action.onClicked.addListener((tab) => { // disable the active tab browser.action.disable(tab.id); // requires the "tabs" or "activeTab" permission, or host permissions for the URL console.log(tab.url); }); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#event-onClicked) API. This documentation is derived from [`browser_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/browser_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/isenabled/index.md
--- title: action.isEnabled() slug: Mozilla/Add-ons/WebExtensions/API/action/isEnabled page-type: webextension-api-function browser-compat: webextensions.api.action.isEnabled --- {{AddonSidebar}} Returns `true` if the browser action is enabled. > **Note:** This API is available in Manifest V3 or higher. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let gettingIsEnabled = browser.action.isEnabled( details // object ) ``` ### Parameters - `details` - : `object`. An object optionally containing the `tabId` or `windowId` to check. - `tabId` {{optional_inline}} - : `integer`. ID of a tab to check. - `windowId` {{optional_inline}} - : `integer`. ID of a window to check. <!----> - If windowId and tabId are both supplied, the function fails. - If windowId and tabId are both omitted, the global enabled/disabled status is returned. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with `true` if the extension's browser action is enabled, and `false` otherwise. ## Examples Check the global state: ```js browser.action.isEnabled({}).then((result) => { console.log(result); }); ``` Check the state of the currently active tab: ```js async function enabledInActiveTab() { let tabs = await browser.tabs.query({ currentWindow: true, active: true, }); let enabled = await browser.action.isEnabled({ tabId: tabs[0].id, }); console.log(enabled); } ``` {{WebExtExamples}} ## Browser compatibility {{Compat}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/getusersettings/index.md
--- title: action.getUserSettings() slug: Mozilla/Add-ons/WebExtensions/API/action/getUserSettings page-type: webextension-api-function browser-compat: webextensions.api.action.getUserSettings --- {{AddonSidebar}} Gets the user-specified settings for the browser action. > **Note:** This API is available in Manifest V3 or higher. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let userSettings = await browser.action.getUserSettings(); ``` ### Parameters This function takes no parameters. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that fulfills with an object with these properties: - `userSettings` - : An object containing the user-specified settings for the browser action with these properties: - `isOnToolbar` {{optional_inline}} - : `boolean`. Whether the user has pinned the action's icon to the browser UI. This setting does not indicate whether the action icon is visible. The icon's visibility depends on the size of the browser window and the layout of the browser UI. ## Examples This code logs a message indicating whether the action is pinned or not: ```js function gotSettings(userSettings) { if (userSettings.isOnToolbar) { console.log("Action is pinned to toolbar."); } else { console.log("Action is not pinned to toolbar."); } } let gettingUserSettings = browser.action.getUserSettings(); gettingUserSettings.then(gotSettings); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#method-getUserSettings) API. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/gettitle/index.md
--- title: action.getTitle() slug: Mozilla/Add-ons/WebExtensions/API/action/getTitle page-type: webextension-api-function browser-compat: webextensions.api.action.getTitle --- {{AddonSidebar}} Gets the browser action's title. > **Note:** This API is available in Manifest V3 or higher. Just as you can set the title on a per-tab basis using {{WebExtAPIRef("action.setTitle()")}}, so you can retrieve a tab-specific title by passing the tab's ID into this function. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let gettingTitle = browser.action.getTitle( details // object ) ``` ### Parameters - `details` - : An object with the following properties: - `tabId` {{optional_inline}} - : `integer`. Specify the tab to get the title from. - `windowId` {{optional_inline}} - : `integer`. Specify the window to get the title from. <!----> - If `windowId` and `tabId` are both supplied, the function fails and the promise it returns is rejected. - If `windowId` and `tabId` are both omitted, the global title is returned. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with a string containing the browser action's title. ## Examples This code switches the title between "this" and "that" each time the user clicks the browser action: ```js function toggleTitle(title) { if (title === "this") { browser.action.setTitle({ title: "that" }); } else { browser.action.setTitle({ title: "this" }); } } browser.action.onClicked.addListener(() => { let gettingTitle = browser.action.getTitle({}); gettingTitle.then(toggleTitle); }); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#method-getTitle) API. This documentation is derived from [`browser_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/browser_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/openpopup/index.md
--- title: action.openPopup() slug: Mozilla/Add-ons/WebExtensions/API/action/openPopup page-type: webextension-api-function browser-compat: webextensions.api.action.openPopup --- {{AddonSidebar}} Open the browser action's popup. > **Note:** This API is available in Manifest V3 or higher. In stable versions of Firefox, you can only call this function from inside the handler for a [user action](/en-US/docs/Mozilla/Add-ons/WebExtensions/User_actions). See [Browser compatibility](#browser_compatibility) for details. ## Syntax ```js-nolint browser.action.openPopup( options // optional object ) ``` ### Parameters - `details` {{optional_inline}} - : An object with the following properties: - `windowId` {{optional_inline}} - : `integer`. Window to open the popup for. Defaults to the current window. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that is resolved with no arguments. ## Examples Open the popup when the user selects a context menu item: ```js browser.menus.create({ id: "open-popup", title: "open popup", contexts: ["all"], }); browser.menus.onClicked.addListener(() => { browser.action.openPopup(); }); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/getbadgetext/index.md
--- title: action.getBadgeText() slug: Mozilla/Add-ons/WebExtensions/API/action/getBadgeText page-type: webextension-api-function browser-compat: webextensions.api.action.getBadgeText --- {{AddonSidebar}} Gets the browser action's badge text. > **Note:** This API is available in Manifest V3 or higher. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let gettingText = browser.action.getBadgeText( details // object ) ``` ### Parameters - `details` - : An object with the following properties: - `tabId` {{optional_inline}} - : `integer`. Specifies the tab from which to get the badge text. - `windowId` {{optional_inline}} - : `integer`. Specifies the window from which to get the badge text. <!----> - If windowId and tabId are both supplied, the function fails. - If windowId and tabId are both omitted, the global badge text is returned. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with a string containing the badge text. ## Examples Log the badge text: ```js function gotBadgeText(text) { console.log(text); } let gettingBadgeText = browser.action.getBadgeText({}); gettingBadgeText.then(gotBadgeText); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#method-getBadgeText) API. This documentation is derived from [`browser_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/browser_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/setbadgetext/index.md
--- title: action.setBadgeText() slug: Mozilla/Add-ons/WebExtensions/API/action/setBadgeText page-type: webextension-api-function browser-compat: webextensions.api.action.setBadgeText --- {{AddonSidebar}} Sets the badge text for the browser action. The badge is displayed on top of the icon. > **Note:** This API is available in Manifest V3 or higher. Tabs without a specific badge text will inherit the global badge text, which is `""` by default. ## Syntax ```js-nolint browser.action.setBadgeText( details // object ) ``` This API is also available as `chrome.action.setBadgeText()`. ### Parameters - `details` - : An object with the following properties: - `text` - : `string` or `null`. Any number of characters can be passed, but only about four can fit in the space. Use an empty string - `""` - if you don't want any badge. If a `tabId` is specified, `null` removes the tab-specific badge text so that the tab inherits the global badge text. Otherwise it reverts the global badge text to `""`. If a `windowId` is specified, `null` removes the window-specific badge text so that the tab inherits the global badge text. Otherwise it reverts the global badge text to `""`. - `tabId` {{optional_inline}} - : `integer`. Set the badge text only for the given tab. The text is reset when the user navigates this tab to a new page. - `windowId` {{optional_inline}} - : `integer`. Set the badge text for the given window. <!----> - If `windowId` and `tabId` are both supplied, the function fails. - If `windowId` and `tabId` are both omitted, the global badge is set. ## Examples Add a badge indicating how many times the user clicked the button: ```js let clicks = 0; function increment() { browser.action.setBadgeText({ text: (++clicks).toString() }); } browser.action.onClicked.addListener(increment); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#method-setBadgeText) API. This documentation is derived from [`browser_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/browser_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/disable/index.md
--- title: action.disable() slug: Mozilla/Add-ons/WebExtensions/API/action/disable page-type: webextension-api-function browser-compat: webextensions.api.action.disable --- {{AddonSidebar}} Disables the browser action for a tab, meaning that it cannot be clicked when that tab is active. > **Note:** This API is available in Manifest V3 or higher. ## Syntax ```js-nolint browser.action.disable( tabId // optional integer ) ``` ### Parameters - `tabId` {{optional_inline}} - : `integer`. The id of the tab for which you want to disable the browser action. ## Examples Disable the browser action when clicked, and re-enable it every time a new tab is opened: ```js browser.tabs.onCreated.addListener(() => { browser.action.enable(); }); browser.action.onClicked.addListener(() => { browser.action.disable(); }); ``` Disable the browser action only for the active tab: ```js browser.action.onClicked.addListener((tab) => { browser.action.disable(tab.id); }); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#method-disable) API. This documentation is derived from [`browser_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/browser_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/setpopup/index.md
--- title: action.setPopup() slug: Mozilla/Add-ons/WebExtensions/API/action/setPopup page-type: webextension-api-function browser-compat: webextensions.api.action.setPopup --- {{AddonSidebar}} Sets the HTML document that is opened as a popup when the user clicks on the browser action's icon. Tabs without a specific popup will inherit the global popup, which defaults to the [`default_popup`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_action) specified in the manifest. > **Note:** This API is available in Manifest V3 or higher. ## Syntax ```js-nolint browser.action.setPopup( details // object ) ``` ### Parameters - `details` - : An object with the following properties: - `tabId` {{optional_inline}} - : `integer`. Sets the popup only for a specific tab. The popup is reset when the user navigates this tab to a new page. - `windowId` {{optional_inline}} - : `integer`. Sets the popup only for the specified window. - `popup` - : `string` or `null`. The HTML file to show in a popup, specified as a URL. This can point to a file packaged within the extension (for example, created using {{WebExtAPIRef("extension.getURL")}}), or a remote document (e.g. `https://example.org/`). If an empty string (`""`) is passed here, the popup is disabled, and the extension will receive {{WebExtAPIRef("action.onClicked")}} events. If `popup` is `null`: - If `tabId` is specified, removes the tab-specific popup so that the tab inherits the global popup. - If `windowId` is specified, removes the window-specific popup so that the window inherits the global popup. - If `tabId` and `windowId` are both omitted, reverts the global popup to the default value. <!----> - If `windowId` and `tabId` are both supplied, the function fails and the popup is not set. - If `windowId` and `tabId` are both omitted, the global popup is set. ## Examples This code adds a pair of context menu items that you can use to switch between two popups. Note that you'll need the "contextMenus" [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) set in the extension's manifest to create context menu items. ```js function onCreated() { if (browser.runtime.lastError) { console.log("error creating item:", browser.runtime.lastError); } else { console.log("item created successfully"); } } browser.contextMenus.create( { id: "popup-1", type: "radio", title: "Popup 1", contexts: ["all"], checked: true, }, onCreated, ); browser.contextMenus.create( { id: "popup-2", type: "radio", title: "Popup 2", contexts: ["all"], checked: false, }, onCreated, ); browser.contextMenus.onClicked.addListener((info, tab) => { if (info.menuItemId === "popup-1") { browser.action.setPopup({ popup: "/popup/popup1.html" }); } else if (info.menuItemId === "popup-2") { browser.action.setPopup({ popup: "/popup/popup2.html" }); } }); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#method-setPopup) API. This documentation is derived from [`browser_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/browser_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/setbadgetextcolor/index.md
--- title: action.setBadgeTextColor() slug: Mozilla/Add-ons/WebExtensions/API/action/setBadgeTextColor page-type: webextension-api-function browser-compat: webextensions.api.action.setBadgeTextColor --- {{AddonSidebar}} Sets the text color for the browser action's badge. Tabs without a specific badge text color will inherit the global badge text color. > **Note:** This API is available in Manifest V3 or higher. ## Syntax ```js-nolint browser.action.setBadgeTextColor( details // object ) ``` ### Parameters - `details` - : An object with the following properties: - `color` - : The color, specified as one of: - a string: any CSS [\<color>](/en-US/docs/Web/CSS/color_value) value, for example `"red"`, `"#FF0000"`, or `"rgb(255 0 0)"`. If the string is not a valid color, the returned promise will be rejected and the text color won't be altered. - a `{{WebExtAPIRef('action.ColorArray')}}` object. - `null`. If a `tabId` is specified, it removes the tab-specific badge text color so that the tab inherits the global badge text color. Otherwise it reverts the global badge text color to the default value. - `tabId` {{optional_inline}} - : `integer`. Sets the badge text color only for the given tab. The color is reset when the user navigates this tab to a new page. - `windowId` {{optional_inline}} - : `integer`. Sets the badge text color only for the given tab. <!----> - If `windowId` and `tabId` are both supplied, the function fails and the color is not set. - If `windowId` and `tabId` are both omitted, the global badge text color is set instead. ## Examples A badge text color that starts off as red, and turns green when the browser action is clicked: ```js browser.action.setBadgeText({ text: "1234" }); browser.action.setBadgeTextColor({ color: "red" }); browser.action.onClicked.addListener(() => { browser.action.setBadgeTextColor({ color: "green" }); }); ``` Set the badge text color only for the active tab: ```js browser.action.setBadgeText({ text: "1234" }); browser.action.setBadgeTextColor({ color: "red" }); browser.action.onClicked.addListener((tab) => { browser.action.setBadgeTextColor({ color: "green", tabId: tab.id, }); }); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#method-setBadgeBackgroundColor) API. This documentation is derived from [`browser_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/browser_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/action/imagedatatype/index.md
--- title: action.ImageDataType slug: Mozilla/Add-ons/WebExtensions/API/action/ImageDataType page-type: webextension-api-type browser-compat: webextensions.api.action.ImageDataType --- {{AddonSidebar}} Pixel data for an image. Must be an [`ImageData`](/en-US/docs/Web/API/ImageData) object (for example, from a {{htmlelement("canvas")}} element). ## Type An [`ImageData`](/en-US/docs/Web/API/ImageData) object. {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.action`](https://developer.chrome.com/docs/extensions/reference/action/#type-ImageDataType) API. This documentation is derived from [`browser_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/browser_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/theme/index.md
--- title: theme slug: Mozilla/Add-ons/WebExtensions/API/theme page-type: webextension-api browser-compat: webextensions.api.theme --- {{AddonSidebar}} Enables browser extensions to get details of the browser's theme and update the theme. You can use this API to include a theme in your extension, which you define as a {{WebExtAPIRef("theme.Theme")}} and apply using {{WebExtAPIRef("theme.update()")}}. You cannot include a static theme in your extension, defined with the ["theme"](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/theme) manifest key. The "theme" manifest key is used to define static themes only. See [Themes](https://extensionworkshop.com/documentation/themes/) on Extension Workshop for more information. ## Types - {{WebExtAPIRef("theme.Theme")}} - : Represents the content of a theme. ## Functions - {{WebExtAPIRef("theme.getCurrent()")}} - : Gets the current browser theme. - {{WebExtAPIRef("theme.update()")}} - : Updates the browser's theme. - {{WebExtAPIRef("theme.reset()")}} - : Removes any theme updates made in a call to {{WebExtAPIRef("theme.update()")}}. ## Events - {{WebExtAPIRef("theme.onUpdated")}} - : Fired when the browser theme changes. {{WebExtExamples("h2")}} ## Browser compatibility {{Compat}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/theme
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/theme/update/index.md
--- title: theme.update() slug: Mozilla/Add-ons/WebExtensions/API/theme/update page-type: webextension-api-function browser-compat: webextensions.api.theme.update --- {{AddonSidebar}} Updates the browser theme according to the content of the {{WebExtAPIRef("theme.Theme", "Theme")}} object. To use this method, an extension must request the "theme" [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) in its [manifest.json](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json) file. ## Syntax ```js-nolint browser.theme.update( windowId, // integer theme // object ) ``` ### Parameters - `windowId` {{optional_inline}} - : `integer`. The ID of a window. If this is provided, the theme is applied only to that window. If it is omitted, the theme is applied to all windows. - `theme` - : `object`. A {{WebExtAPIRef("theme.Theme", "Theme")}} object specifying values for the UI elements you want to modify. ## Examples Sets the browser theme to use a sun graphic with a complementary background color: ```js const suntheme = { images: { theme_frame: "sun.jpg", }, colors: { frame: "#CF723F", tab_background_text: "#111", }, }; browser.theme.update(suntheme); ``` Set the theme for the focused window only: ```js const day = { images: { theme_frame: "sun.jpg", }, colors: { frame: "#CF723F", tab_background_text: "#111", }, }; browser.menus.create({ id: "set-theme", title: "set theme", contexts: ["all"], }); async function updateThemeForCurrentWindow() { let currentWindow = await browser.windows.getLastFocused(); browser.theme.update(currentWindow.id, day); } browser.menus.onClicked.addListener(updateThemeForCurrentWindow); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/theme
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/theme/theme/index.md
--- title: Theme slug: Mozilla/Add-ons/WebExtensions/API/theme/Theme page-type: webextension-api-type browser-compat: webextensions.api.theme.Theme --- {{AddonSidebar}} A Theme object represents the specification of a theme. ## Type A JSON [object](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) that takes the same properties as the ["theme"](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/theme) manifest key. {{WebExtExamples}} ## Browser compatibility {{Compat}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/theme
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/theme/getcurrent/index.md
--- title: theme.getCurrent() slug: Mozilla/Add-ons/WebExtensions/API/theme/getCurrent page-type: webextension-api-function browser-compat: webextensions.api.theme.getCurrent --- {{AddonSidebar}} Gets the current theme as a {{WebExtAPIRef("theme.Theme", "Theme")}} object. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let getting = browser.theme.getCurrent( windowId // integer ) ``` ### Parameters - `windowId` {{optional_inline}} - : `integer`. The ID of a window. If this is provided, the theme resolved is the one applied to that window. If it is omitted, the theme resolved is the one applied to the most recently focused window. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). The promise is fulfilled with a {{WebExtAPIRef("theme.Theme")}} object representing the theme applied to the given window. If no extension-supplied theme has been applied to the given window, it is fulfilled with an empty object. ## Examples Gets the properties `frame` and `toolbar` colors of the current theme: ```js function getStyle(themeInfo) { if (themeInfo.colors) { console.log(`accent color: ${themeInfo.colors.frame}`); console.log(`toolbar: ${themeInfo.colors.toolbar}`); } } async function getCurrentThemeInfo() { const themeInfo = await browser.theme.getCurrent(); getStyle(themeInfo); } getCurrentThemeInfo(); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/theme
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/theme/onupdated/index.md
--- title: theme.onUpdated slug: Mozilla/Add-ons/WebExtensions/API/theme/onUpdated page-type: webextension-api-event browser-compat: webextensions.api.theme.onUpdated --- {{AddonSidebar}} Fires when a theme supplied as a browser extension is applied or removed. Specifically: - when a [static theme](https://extensionworkshop.com/documentation/themes/static-themes/) is installed - when a [dynamic theme](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/theme) calls [`theme.update()`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/theme/update) or [`theme.reset()`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/theme/reset) - when a theme gets uninstalled. This event is not fired for changes to the built-in themes. ## Syntax ```js-nolint browser.theme.onUpdated.addListener(listener) browser.theme.onUpdated.removeListener(listener) browser.theme.onUpdated.hasListener(listener) ``` Events have three functions: - `addListener(listener)` - : Adds a listener to this event. - `removeListener(listener)` - : Stop listening to this event. The `listener` argument is the listener to remove. - `hasListener(listener)` - : Check whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. ## addListener syntax ### Parameters - `listener` - : The function called when this event occurs. The function is passed these arguments: - `updateInfo` - : `object`. An object containing two properties: - `theme` - : `object`. If the event fired because an extension-supplied theme was removed, this is an empty object. If it fired because an extension-supplied theme was applied, then it is a {{WebExtAPIRef("theme.Theme")}} object representing the theme that was applied. - `windowId` {{optional_inline}} - : `integer`. The ID of the window in which the theme was updated. If this property is not present, the theme was updated in all windows. ## Examples ```js function handleUpdated(updateInfo) { if (updateInfo.theme.colors) { console.log(`Theme was applied: ${updateInfo.theme}`); } else { console.log(`Theme was removed`); } } browser.theme.onUpdated.addListener(handleUpdated); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/theme
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/theme/reset/index.md
--- title: theme.reset() slug: Mozilla/Add-ons/WebExtensions/API/theme/reset page-type: webextension-api-function browser-compat: webextensions.api.theme.reset --- {{AddonSidebar}} Resets any theme applied using the {{WebExtAPIRef("theme.update()")}} method. To use this method, an extension must request the "theme" [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) in its [manifest.json](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json) file. Note that this always reset the theme back to the original default theme, even if the user selected a different theme before this extension's theme was applied (see [bug 1415267](https://bugzil.la/1415267)). ## Syntax ```js-nolint browser.theme.reset( windowId // integer ) ``` ### Parameters - `windowId` {{optional_inline}} - : `integer`. The ID of a window. If this is provided, the theme applied to that window is reset. If it is omitted, the theme is reset on all windows. ## Examples This code applies a theme, then removes it when the user clicks a browser action: ```js browser.theme.update(themes.night); browser.browserAction.onClicked.addListener(() => { browser.theme.reset(); }); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/extensiontypes/index.md
--- title: extensionTypes slug: Mozilla/Add-ons/WebExtensions/API/extensionTypes page-type: webextension-api browser-compat: webextensions.api.extensionTypes --- {{AddonSidebar}} Some common types used in other WebExtension APIs. ## Types - {{WebExtAPIRef("extensionTypes.ImageDetails")}} - : Details about the format and quality of an image. - {{WebExtAPIRef("extensionTypes.ImageFormat")}} - : The format of an image. - {{WebExtAPIRef("extensionTypes.InjectDetails")}} - : Injects details into a page. - {{WebExtAPIRef("extensionTypes.RunAt")}} - : The soonest that the JavaScript or CSS will be injected into the tab. - `extensionTypes.CSSOrigin` - : Indicates whether a CSS stylesheet injected by [`tabs.insertCSS`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/insertCSS) should be treated as an "author" or "user" stylesheet. ## Browser compatibility {{Compat}} {{WebExtExamples("h2")}} > **Note:** This API is based on Chromium's [`chrome.extensionTypes`](https://developer.chrome.com/docs/extensions/reference/extensionTypes/) API. This documentation is derived from [`extension_types.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/extension_types.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/extensiontypes
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/extensiontypes/runat/index.md
--- title: extensionTypes.RunAt slug: Mozilla/Add-ons/WebExtensions/API/extensionTypes/RunAt page-type: webextension-api-type browser-compat: webextensions.api.extensionTypes.RunAt --- {{AddonSidebar}} The soonest that the JavaScript or CSS will be injected into the tab. ## Type Values of this type are strings. Possible values are: `"document_start"`, `"document_end"`, `"document_idle"`. - `"document_start"`: corresponds to `loading`. The DOM is still loading. - `"document_end"`: corresponds to `interactive`. The DOM has finished loading, but resources such as scripts and images may still be loading. - `"document_idle"`: corresponds to `complete`. The document and all its resources have finished loading. The default value is `"document_idle"`. ## Browser compatibility {{Compat}} {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.extensionTypes`](https://developer.chrome.com/docs/extensions/reference/extensionTypes/#type-RunAt) API. This documentation is derived from [`extension_types.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/extension_types.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/extensiontypes
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/extensiontypes/imagedetails/index.md
--- title: extensionTypes.ImageDetails slug: Mozilla/Add-ons/WebExtensions/API/extensionTypes/ImageDetails page-type: webextension-api-type browser-compat: webextensions.api.extensionTypes.ImageDetails --- {{AddonSidebar}} Details about the format, quality, area and scale of a captured image. ## Type Values of this type are objects. They contain the following properties: - `format` {{optional_inline}} - : {{WebExtAPIRef('extensionTypes.ImageFormat')}}. The format of the resulting image. Default is `"png"`. - `quality` {{optional_inline}} - : `integer`. When format is `"jpeg"`, this controls the quality of the resulting image. It is a number between 0 and 100, which is converted to a value between 0 and 1 and then used as the `encoderOptions` argument to [`HTMLCanvasElement.toDataURL()`](/en-US/docs/Web/API/HTMLCanvasElement/toDataURL). If it is omitted, 92 is used. As quality is decreased, the resulting image will have more visual artifacts, and the number of bytes needed to store it will decrease. This value is ignored for PNG images. - `rect` {{optional_inline}} - : An `object` specifying the area of the document to capture, in CSS pixels, relative to the page. All properties default to `0`. The properties are: - `x`: The coordinate of the left side of the rectangle. - `y`: The coordinate of the top side of the rectangle. - `width`: The width of the rectangle. - `height`: The height of the rectangle. This option was introduced in Firefox 82. If omitted, the currently visible viewport is captured. - `scale` {{optional_inline}} - : `number`. The scale to render at, defaults to [`devicePixelRatio`](/en-US/docs/Web/API/Window/devicePixelRatio). This option was introduced in Firefox 82. ## Browser compatibility {{Compat}} {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.extensionTypes`](https://developer.chrome.com/docs/extensions/reference/extensionTypes/#type-ImageDetails) API. This documentation is derived from [`extension_types.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/extension_types.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/extensiontypes
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/extensiontypes/imageformat/index.md
--- title: extensionTypes.ImageFormat slug: Mozilla/Add-ons/WebExtensions/API/extensionTypes/ImageFormat page-type: webextension-api-type browser-compat: webextensions.api.extensionTypes.ImageFormat --- {{AddonSidebar}} The format of an image. ## Type Values of this type are strings. Possible values are: `"jpeg"`, `"png"`. ## Browser compatibility {{Compat}} {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.extensionTypes`](https://developer.chrome.com/docs/extensions/reference/extensionTypes/#type-ImageFormat) API. This documentation is derived from [`extension_types.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/extension_types.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/extensiontypes
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/extensiontypes/injectdetails/index.md
--- title: extensionTypes.InjectDetails slug: Mozilla/Add-ons/WebExtensions/API/extensionTypes/InjectDetails page-type: webextension-api-type --- {{AddonSidebar}} This type is given as a parameter to the `tabs.executeScript()`, `tabs.insertCSS()`, and `tabs.removeCSS()` methods. For the details of its properties and what they are used for, see the documentation pages for those methods: - {{WebExtAPIRef("tabs.executeScript()")}} - {{WebExtAPIRef("tabs.insertCSS()")}} - {{WebExtAPIRef("tabs.removeCSS()")}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pkcs11/index.md
--- title: pkcs11 slug: Mozilla/Add-ons/WebExtensions/API/pkcs11 page-type: webextension-api browser-compat: webextensions.api.pkcs11 --- {{AddonSidebar}} The `pkcs11` API enables an extension to enumerate [PKCS #11](https://en.wikipedia.org/wiki/PKCS_11) security modules and to make them accessible to the browser as sources of keys and certificates. To use this API you need to have the "pkcs11" [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions). ## Using the Firefox Preferences Dialog to Install PKCS #11 Modules Perform the following steps: 1. Save the PKCS #11 module to a permanent location on your local computer 2. Select **Tools > Options** or select the **Firefox menu** and then **Options** 3. Once the Options page opens, select **Privacy & Security** 4. Scroll down to the bottom of the page and under **Certificates** click or tap on **Security Devices…** ![Security modules and devices](device_manager.png) 5. Click or tap the **Load** button ![Load PKCS#11 device driver](load_device_driver.png) 6. Enter a name for the security module, such as "_My Client Database_" > **Warning:** Be careful about using international characters as there is currently a bug in Firefox where international characters may cause problems. 7. Choose **Browse…** to find the location of the PKCS #11 module on your local computer, and then click or tap **OK** to confirm. ## Provisioning PKCS #11 modules > **Note:** Starting with Firefox 58, extensions can use this API to enumerate PKCS #11 modules and make them accessible to the browser as sources of keys and certificates. There are two environmental prerequisites for using this **API**: - One or more `PKCS #11` modules must be installed on the user's computer - For each installed `PKCS #11` module, there must be a [native manifest](/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_manifests) file that enables the browser to locate the module. Most probably, the user or device administrator would install the `PKCS #11` module, and its installer would install the native manifest file at the same time. However, the module and manifest can't be installed as part of the extension's own installation process. For details about the manifest file's contents and location, see [Native manifests](/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_manifests). ## Functions - {{WebExtAPIRef("pkcs11.getModuleSlots()")}} - : For each slot in a module, get its name and whether it contains a token. - {{WebExtAPIRef("pkcs11.installModule()")}} - : Installs the named PKCS #11 module. - {{WebExtAPIRef("pkcs11.isModuleInstalled()")}} - : Checks whether the named PKCS #11 module is installed. - {{WebExtAPIRef("pkcs11.uninstallModule()")}} - : Uninstalls the named PKCS #11 module. ## Browser compatibility {{WebExtExamples("h2")}} {{Compat}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pkcs11
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pkcs11/getmoduleslots/index.md
--- title: pkcs11.getModuleSlots() slug: Mozilla/Add-ons/WebExtensions/API/pkcs11/getModuleSlots page-type: webextension-api-function browser-compat: webextensions.api.pkcs11.getModuleSlots --- {{AddonSidebar}} Enumerate a module's slots. This function returns an array containing one entry for each slot. Each entry contains the slot's name and, if the slot contains a token, information about the token. You can only call this for a module that is installed in Firefox. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let getting = browser.pkcs11.getModuleSlots( name // string ) ``` ### Parameters - `name` - : `string`. Name of the module. This must match the `name` property in the [PKCS #11 manifest](/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_manifests#pkcs_11_manifests) for the module. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an array of objects, one for each slot that the module provides access to. Each object has two properties: - `name`: the name of the slot - `token`: if a token is present in this slot, a `Token` object. If no token is present in the slot, this property is `null`. `Token` objects have the following properties: - `name` - : `string`. Name of the token. - `manufacturer` - : `string`. Name of the token's manufacturer. - `HWVersion` - : `string`. Hardware version, as a PKCS #11 version number (two 32-bit integers separated with a dot, like "1.0". - `FWVersion` - : `string`. Firmware version, as a PKCS #11 version number (two 32-bit integers separated with a dot, like "1.0". - `serial` - : `string`. Serial number, whose format is defined by the token specification. - `isLoggedIn` - : `boolean`: `true` if the token is logged on already, `false` otherwise. If the module could not be found or some other error occurs, the promise will be rejected with an error message. ## Browser compatibility {{Compat}} ## Examples Installs a module, then lists its slots and list the tokens they contain: ```js function onInstalled() { return browser.pkcs11.getModuleSlots("my_module"); } function onGotSlots(slots) { for (const slot of slots) { console.log(`Slot: ${slot.name}`); if (slot.token) { console.log(`Contains token: ${slot.token.name}`); } else { console.log("Is empty"); } } } browser.pkcs11.installModule("my_module").then(onInstalled).then(onGotSlots); ``` {{WebExtExamples}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pkcs11
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pkcs11/ismoduleinstalled/index.md
--- title: pkcs11.isModuleInstalled() slug: Mozilla/Add-ons/WebExtensions/API/pkcs11/isModuleInstalled page-type: webextension-api-function browser-compat: webextensions.api.pkcs11.isModuleInstalled --- {{AddonSidebar}} Checks whether the named PKCS #11 module is currently installed in Firefox. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let checking = browser.pkcs11.isModuleInstalled( name // string ) ``` ### Parameters - `name` - : `string`. Name of the module to check. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with `true` if the module is installed, `false` otherwise. If the module an error occurs, the promise will be rejected with an error message. ## Browser compatibility {{Compat}} ## Examples Checks whether the module named "pkcs11_module" is installed: ```js function logIsInstalled(isInstalled) { console.log(`Module is installed: ${isInstalled}`); } browser.pkcs11.isModuleInstalled("pkcs11_module").then(logIsInstalled); ``` {{WebExtExamples}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pkcs11
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pkcs11/installmodule/index.md
--- title: pkcs11.installModule() slug: Mozilla/Add-ons/WebExtensions/API/pkcs11/installModule page-type: webextension-api-function browser-compat: webextensions.api.pkcs11.installModule --- {{AddonSidebar}} Installs the named PKCS #11 module, making it available to Firefox. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let installing = browser.pkcs11.installModule( name, // string flags // integer ) ``` ### Parameters - `name` - : `string`. Name of the module to install. This must match the `name` property in the [PKCS #11 manifest](/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_manifests#pkcs_11_manifests) for the module. - `flags` {{optional_inline}} - : `integer`. Flags to pass to the module. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with no arguments once the module is installed. If the module could not be found or some other error occurs, the promise will be rejected with an error message. ## Browser compatibility {{Compat}} ## Examples Installs a module, then lists its slots and list the tokens they contain: ```js function onInstalled() { return browser.pkcs11.getModuleSlots("my_module"); } function onGotSlots(slots) { for (const slot of slots) { console.log(`Slot: ${slot.name}`); if (slot.token) { console.log(`Contains token: ${slot.token.name}`); } else { console.log("Is empty"); } } } browser.pkcs11.installModule("my_module").then(onInstalled).then(onGotSlots); ``` {{WebExtExamples}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pkcs11
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pkcs11/uninstallmodule/index.md
--- title: pkcs11.uninstallModule() slug: Mozilla/Add-ons/WebExtensions/API/pkcs11/uninstallModule page-type: webextension-api-function browser-compat: webextensions.api.pkcs11.uninstallModule --- {{AddonSidebar}} Uninstalls the named PKCS #11 module from Firefox. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let uninstalling = browser.pkcs11.uninstallModule( name // string ) ``` ### Parameters - `name` - : `string`. Name of the module to uninstall. This must match the `name` property in the [PKCS #11 manifest](/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_manifests#pkcs_11_manifests) for the module. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with no arguments once the module is uninstalled. If the module could not be found or some other error occurs, the promise will be rejected with an error message. ## Browser compatibility {{Compat}} ## Examples Uninstalls the module named "pkcs11_module": ```js browser.pkcs11.uninstallModule("pkcs11_module"); ``` {{WebExtExamples}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/index.md
--- title: bookmarks slug: Mozilla/Add-ons/WebExtensions/API/bookmarks page-type: webextension-api browser-compat: webextensions.api.bookmarks --- {{AddonSidebar}} The [WebExtensions](/en-US/docs/Mozilla/Add-ons/WebExtensions) {{WebExtAPIRef("bookmarks")}} API lets an extension interact with and manipulate the browser's bookmarking system. You can use it to bookmark pages, retrieve existing bookmarks, and edit, remove, and organize bookmarks. To use this API, an extension must request the "bookmarks" [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) in its [`manifest.json`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json) file. Extensions cannot create, modify, or delete bookmarks in the root node of the bookmarks tree. Doing so causes an error with the message: "_The bookmark root cannot be modified_" ## Types - {{WebExtAPIRef("bookmarks.BookmarkTreeNode")}} - : Represents a bookmark or folder in the bookmarks tree. - {{WebExtAPIRef("bookmarks.BookmarkTreeNodeType")}} - : A {{jsxref("String")}} enum which describes whether a node in the tree is a bookmark, a folder, or a separator. - {{WebExtAPIRef("bookmarks.BookmarkTreeNodeUnmodifiable")}} - : A {{jsxref("String")}} enum which specifies why a bookmark or folder is unmodifiable. - {{WebExtAPIRef("bookmarks.CreateDetails")}} - : Contains information which is passed to the {{WebExtAPIRef("bookmarks.create()")}} function when creating a new bookmark. ## Functions - {{WebExtAPIRef("bookmarks.create()")}} - : Creates a bookmark or folder. - {{WebExtAPIRef("bookmarks.get()")}} - : Retrieves one or more {{WebExtAPIRef("bookmarks.BookmarkTreeNode", "BookmarkTreeNode")}}s, given a bookmark's ID or an array of bookmark IDs. - {{WebExtAPIRef("bookmarks.getChildren()")}} - : Retrieves the children of the specified {{WebExtAPIRef("bookmarks.BookmarkTreeNode", "BookmarkTreeNode")}}. - {{WebExtAPIRef("bookmarks.getRecent()")}} - : Retrieves a requested number of recently added bookmarks. - {{WebExtAPIRef("bookmarks.getSubTree()")}} - : Retrieves part of the bookmarks tree, starting at the specified node. - {{WebExtAPIRef("bookmarks.getTree()")}} - : Retrieves the entire bookmarks tree into an array of {{WebExtAPIRef("bookmarks.BookmarkTreeNode", "BookmarkTreeNode")}} objects. - {{WebExtAPIRef("bookmarks.move()")}} - : Moves the specified {{WebExtAPIRef("bookmarks.BookmarkTreeNode", "BookmarkTreeNode")}} to a new location in the bookmark tree. - {{WebExtAPIRef("bookmarks.remove()")}} - : Removes a bookmark or an empty bookmark folder, given the node's ID. - {{WebExtAPIRef("bookmarks.removeTree()")}} - : Recursively removes a bookmark folder; that is, given the ID of a folder node, removes that node and all its descendants. - {{WebExtAPIRef("bookmarks.search()")}} - : Searches for {{WebExtAPIRef("bookmarks.BookmarkTreeNode", "BookmarkTreeNode")}}s matching a specified set of criteria. - {{WebExtAPIRef("bookmarks.update()")}} - : Updates the title and/or URL of a bookmark, or the name of a bookmark folder, given the bookmark's ID. ## Events - {{WebExtAPIRef("bookmarks.onCreated")}} - : Fired when a bookmark or folder is created. - {{WebExtAPIRef("bookmarks.onRemoved")}} - : Fired when a bookmark or folder is removed. When a folder is removed recursively, a single notification is fired for the folder, and none for its contents. - {{WebExtAPIRef("bookmarks.onChanged")}} - : Fired when a bookmark or folder changes. Currently, only `title` and `url` changes trigger this. - {{WebExtAPIRef("bookmarks.onMoved")}} - : Fired when a bookmark or folder is moved to a different parent folder or to a new offset within its folder. - {{WebExtAPIRef("bookmarks.onChildrenReordered")}} - : Fired when the user has sorted the children of a folder in the browser's UI. This is not called as a result of a {{WebExtAPIRef("bookmarks.move", "move()")}}. - {{WebExtAPIRef("bookmarks.onImportBegan")}} - : Fired when a bookmark import session is begun. Expensive observers should ignore {{WebExtAPIRef("bookmarks.onCreated")}} updates until {{WebExtAPIRef("bookmarks.onImportEnded")}} is fired. Observers should still handle other notifications immediately. - {{WebExtAPIRef("bookmarks.onImportEnded")}} - : Fired when a bookmark import session has finished. ## Browser compatibility {{Compat}} {{WebExtExamples("h2")}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/remove/index.md
--- title: bookmarks.remove() slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/remove page-type: webextension-api-function browser-compat: webextensions.api.bookmarks.remove --- {{AddonSidebar}} The **`bookmarks.remove()`** method removes a single bookmark or an empty bookmark folder. > **Warning:** If your extension attempts to remove a bookmark from the bookmarks tree root node, the call will raise an error with the message: "The bookmark root cannot be modified" and the bookmark won't be removed. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let removingBookmark = browser.bookmarks.remove( id // string ) ``` ### Parameters - `id` - : A {{jsxref("string")}} specifying the ID of the bookmark or empty folder to remove. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with no arguments. If the node corresponding to the `id` parameter can't be found or was a non-empty folder, the promise is rejected with an error message. ## Examples ```js function onRemoved() { console.log("Removed!"); } function onRejected(error) { console.log(`An error: ${error}`); } let bookmarkId = "abcdefghijkl"; let removingBookmark = browser.bookmarks.remove(bookmarkId); removingBookmark.then(onRemoved, onRejected); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#method-remove) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/onchanged/index.md
--- title: bookmarks.onChanged slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/onChanged page-type: webextension-api-event browser-compat: webextensions.api.bookmarks.onChanged --- {{AddonSidebar}} Fired when there is a change to: - the title or URL of a bookmark - the name of a folder. ## Syntax ```js-nolint browser.bookmarks.onChanged.addListener(listener) browser.bookmarks.onChanged.removeListener(listener) browser.bookmarks.onChanged.hasListener(listener) ``` Events have three functions: - `addListener(listener)` - : Adds a listener to this event. - `removeListener(listener)` - : Stop listening to this event. The `listener` argument is the listener to remove. - `hasListener(listener)` - : Check whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. ## addListener syntax ### Parameters - `listener` - : The function called when this event occurs. The function is passed these arguments: - `id` - : `string`. ID of the item that changed. - `changeInfo` - : [`object`](#changeinfo). Object containing two properties: `title`, a string containing the item's title, and `url`, a string containing the item's URL. If the item is a folder, `url` is omitted. > **Note:** Multiple events may occur when a bookmark changes, and that changeInfo object may contain only the data that has changed, rather than all the data for the bookmark. In other words, if the `url` for a bookmark changes, the changeInfo may only contain the new `url` information. ## Examples ```js function handleChanged(id, changeInfo) { console.log(`Item: ${id} changed`); console.log(`Title: ${changeInfo.title}`); console.log(`Url: ${changeInfo.url}`); } function handleClick() { browser.bookmarks.onChanged.addListener(handleChanged); } browser.browserAction.onClicked.addListener(handleClick); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#event-onChanged) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/get/index.md
--- title: bookmarks.get() slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/get page-type: webextension-api-function browser-compat: webextensions.api.bookmarks.get --- {{AddonSidebar}} Given the ID of a {{WebExtAPIRef("bookmarks.BookmarkTreeNode")}} or an array of such IDs, the **`bookmarks.get()`** method retrieves the matching nodes. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let getBookmarks = browser.bookmarks.get( idOrIdList // string or string array ) ``` ### Parameters - `idOrIdList` - : `string` A {{jsxref("string")}} or {{jsxref("array")}} of strings specifying the IDs of one or more {{WebExtAPIRef("bookmarks.BookmarkTreeNode", "BookmarkTreeNode")}} objects to retrieve. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an array of [`BookmarkTreeNode`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/bookmarks/BookmarkTreeNode), one for each matching node. Separators are not included in the results. If no nodes could be found, the promise will be rejected with an error message. ## Examples This example tries to get the bookmark whose ID is `bookmarkAAAA`. If no bookmark with this ID exists, `onRejected` is called: ```js function onFulfilled(bookmarks) { console.log(bookmarks); } function onRejected(error) { console.log(`An error: ${error}`); } let gettingBookmarks = browser.bookmarks.get("bookmarkAAAA"); gettingBookmarks.then(onFulfilled, onRejected); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#method-get) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/create/index.md
--- title: bookmarks.create() slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/create page-type: webextension-api-function browser-compat: webextensions.api.bookmarks.create --- {{AddonSidebar}} Creates a bookmark or folder as a child of the {{WebExtAPIRef("bookmarks.BookmarkTreeNode", "BookmarkTreeNode")}} with the specified `parentId`. To create a folder, omit or leave empty the {{WebExtAPIRef("bookmarks.CreateDetails", "CreateDetails", "url")}} parameter. > **Warning:** If your extension tries to create a new bookmark in the bookmark tree's root node, it raises an error: "_The bookmark root cannot be modified_" and the bookmark won't be created. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let createBookmark = browser.bookmarks.create( bookmark // CreateDetails object ) ``` ### Parameters - `bookmark` - : A {{WebExtAPIRef("bookmarks.CreateDetails")}} object. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with a {{WebExtAPIRef('bookmarks.BookmarkTreeNode', 'BookmarkTreeNode')}} that describes the new bookmark node. > **Note:** If you create multiple bookmarks, because this API is asynchronous, the create calls may get processed in any order. Consequently, the value of each bookmark's index returned in {{WebExtAPIRef('bookmarks.BookmarkTreeNode', 'BookmarkTreeNode')}} may change or be unknown until all the create calls are completed. If the index associated with a bookmark matters to your extension, then – when creating multiple bookmarks – the extension should wait for each `bookmarks.create` call to complete before creating the next bookmark. Waiting ensures that the index associated with each bookmark is not affected by a create call executing concurrently while the original call is in progress. ## Examples This example creates a bookmark for this page, placing it in the default folder ("Other Bookmarks" in Firefox and Chrome). ```js function onCreated(node) { console.log(node); } let createBookmark = browser.bookmarks.create({ title: "bookmarks.create() on MDN", url: "https://developer.mozilla.org/Add-ons/WebExtensions/API/bookmarks/create", }); createBookmark.then(onCreated); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#method-create) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/onimportbegan/index.md
--- title: bookmarks.onImportBegan slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/onImportBegan page-type: webextension-api-event browser-compat: webextensions.api.bookmarks.onImportBegan --- {{AddonSidebar}} Fired when the browser has started importing a set of bookmarks. While a set of bookmarks is being imported, {{WebExtAPIRef("bookmarks.onCreated", "onCreated")}} may fire a lot of times. If your extension is listening to `onCreated`, and the listener is expensive, you should also listen for `onImportBegan` and {{WebExtAPIRef("bookmarks.onImportEnded", "onImportEnded")}}. When you receive `onImportBegan`, ignore `onCreated` until you receive `onImportEnded`. You can handle all other notifications as usual. ## Syntax ```js-nolint browser.bookmarks.onImportBegan.addListener(listener) browser.bookmarks.onImportBegan.removeListener(listener) browser.bookmarks.onImportBegan.hasListener(listener) ``` Events have three functions: - `addListener(listener)` - : Adds a listener to this event. - `removeListener(listener)` - : Stop listening to this event. The `listener` argument is the listener to remove. - `hasListener(listener)` - : Check whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. ## addListener syntax ### Parameters - `listener` - : The function called when this event occurs. It's passed no parameters. ## Browser compatibility {{Compat}} ## Examples ```js function handleImportBegan() { console.log("Importing…"); } function handleImportEnded() { console.log("Import finished."); } function handleClick() { browser.bookmarks.onImportBegan.addListener(handleImportBegan); browser.bookmarks.onImportEnded.addListener(handleImportEnded); } browser.browserAction.onClicked.addListener(handleClick); ``` {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#event-onImportBegan) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/bookmarktreenode/index.md
--- title: bookmarks.BookmarkTreeNode slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/BookmarkTreeNode page-type: webextension-api-type browser-compat: webextensions.api.bookmarks.BookmarkTreeNode --- {{AddonSidebar}} An object of type `bookmarks.BookmarkTreeNode` represents a node in the bookmark tree, where each node is a bookmark, a bookmark folder, or a separator. Child nodes are ordered by an `index` within their respective parent folders. ## Type An {{jsxref("object")}} with the following properties: - `children` {{optional_inline}} - : An {{jsxref("array")}} of {{WebExtAPIRef('bookmarks.BookmarkTreeNode')}} objects which represent the node's children. The list is ordered in the list in which the children appear in the user interface. This field is omitted if the node isn't a folder. - `dateAdded` {{optional_inline}} - : A number representing the creation date of the node in [milliseconds since the epoch](https://en.wikipedia.org/wiki/Unix_time). - `dateGroupModified` {{optional_inline}} - : A number representing the date and time the contents of this folder last changed, in [milliseconds since the epoch](https://en.wikipedia.org/wiki/Unix_time). - `id` - : A {{jsxref("string")}} which uniquely identifies the node. Each ID is unique within the user's profile and remains unchanged across browser restarts. - `index` {{optional_inline}} - : A number which represents the zero-based position of this node within its parent folder, where zero represents the first entry. > **Note:** If you create or move multiple bookmarks, because the {{WebExtAPIRef("bookmarks.create()")}} and {{WebExtAPIRef("bookmarks.move()")}} methods are asynchronous, the requests may get processed in any order. Consequently, the value of each bookmark's index may change or be unknown until all the requests are completed. If the index associated with a bookmark matters to your extension, then – when creating or moving multiple bookmarks – the extension should wait for each `bookmarks.create` or `bookmarks.move` call to complete before creating or moving the next bookmark. Waiting ensures that the index associated with each bookmark is not affected by a create or move call executing concurrently while the original call is in progress. - `parentId` {{optional_inline}} - : A {{jsxref("string")}} which specifies the ID of the parent folder. This property is not present in the root node. - `title` - : A {{jsxref("string")}} which contains the text displayed for the node in menus and lists of bookmarks. - `type` {{optional_inline}} - : A {{WebExtAPIRef("bookmarks.BookmarkTreeNodeType")}} object indicating whether this is a bookmark, a folder, or a separator. Defaults to `"bookmark"` unless `url` is omitted, in which case it defaults to `"folder"`. - `unmodifiable` {{optional_inline}} - : A {{jsxref("string")}} as described by the type {{WebExtAPIRef('bookmarks.BookmarkTreeNodeUnmodifiable')}}. Represents the reason that the node can't be changed. If the node can be changed, this is omitted. - `url` {{optional_inline}} - : A {{jsxref("string")}} which represents the URL for the bookmark. If the node represents a folder, this property is omitted. ## Browser compatibility {{Compat}} {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#type-BookmarkTreeNode) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/getsubtree/index.md
--- title: bookmarks.getSubTree() slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/getSubTree page-type: webextension-api-function browser-compat: webextensions.api.bookmarks.getSubTree --- {{AddonSidebar}} The **`bookmarks.getSubTree()`** method asynchronously retrieves a {{WebExtAPIRef("bookmarks.BookmarkTreeNode")}}, given its ID. If the item is a folder, you can access all its descendants recursively using its `children` property and the `children` property of its descendants, if they are themselves folders. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let gettingSubTree = browser.bookmarks.getSubTree( id // string ) ``` ### Parameters - `id` - : A {{jsxref("string")}} specifying the ID of the root of the subtree to retrieve. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that is fulfilled with an array containing an object, a {{WebExtAPIRef('bookmarks.BookmarkTreeNode')}} object, representing the item with the given ID. If a node corresponding to `id` could not be found, the promise will be rejected with an error message. ## Examples This example recursively prints out the subtree under a given node: ```js function makeIndent(indentLength) { return ".".repeat(indentLength); } function logItems(bookmarkItem, indent) { if (bookmarkItem.url) { console.log(makeIndent(indent) + bookmarkItem.url); } else { console.log(`${makeIndent(indent)}Folder: ${bookmarkItem.id}`); indent++; } if (bookmarkItem.children) { for (const child of bookmarkItem.children) { logItems(child, indent); } } } function logSubTree(bookmarkItems) { logItems(bookmarkItems[0], 0); } function onRejected(error) { console.log(`An error: ${error}`); } let subTreeID = "root_____"; browser.bookmarks.getSubTree(subTreeID).then(logSubTree, onRejected); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#method-getSubTree) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/gettree/index.md
--- title: bookmarks.getTree() slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/getTree page-type: webextension-api-function browser-compat: webextensions.api.bookmarks.getTree --- {{AddonSidebar}} **`bookmarks.getTree()`** returns an array containing the root of the bookmarks tree as a {{WebExtAPIRef("bookmarks.BookmarkTreeNode")}} object. You can access the entire tree recursively using its `children` property and the `children` property of its descendants, if they are themselves folders. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let gettingTree = browser.bookmarks.getTree() ``` ### Parameters None. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an array containing one object, a [`bookmarks.BookmarkTreeNode`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/bookmarks/BookmarkTreeNode) object representing the root node. ## Examples This example prints out the entire bookmarks tree: ```js function makeIndent(indentLength) { return ".".repeat(indentLength); } function logItems(bookmarkItem, indent) { if (bookmarkItem.url) { console.log(makeIndent(indent) + bookmarkItem.url); } else { console.log(`${makeIndent(indent)}Folder`); indent++; } if (bookmarkItem.children) { for (const child of bookmarkItem.children) { logItems(child, indent); } } indent--; } function logTree(bookmarkItems) { logItems(bookmarkItems[0], 0); } function onRejected(error) { console.log(`An error: ${error}`); } let gettingTree = browser.bookmarks.getTree(); gettingTree.then(logTree, onRejected); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#method-getTree) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/search/index.md
--- title: bookmarks.search() slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/search page-type: webextension-api-function browser-compat: webextensions.api.bookmarks.search --- {{AddonSidebar}} The **`bookmarks.search()`** function searches for bookmark tree nodes matching the given query. This function throws an exception if any of the input parameters are invalid or are not of an appropriate type; look in the [console](https://extensionworkshop.com/documentation/develop/debugging/) for the error message. The exceptions don't have error IDs, and the messages themselves may change, so don't write code that tries to interpret them. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let searching = browser.bookmarks.search( query // string or object ) ``` ### Parameters - `query` - : A {{jsxref("string")}} or {{jsxref("object")}} describing the query to perform. If `query` is a **string**, it consists of zero or more space-delimited search terms. Each search term matches if it is a substring in the bookmark's URL or title. Matching is case-insensitive. For a bookmark to match the query, all the query's search terms must be matched. If `query` is an **object**, it consists of zero or more of 3 properties: `query`, `title`, and `url`, which are described below. For a bookmark to match the query, all the properties' terms must be matched. - `query` {{optional_inline}} - : A {{jsxref("string")}} specifying one or more terms to match against; the format is identical to the string form of the `query` parameter. If this isn't a string, an exception is thrown. - `url` {{optional_inline}} - : A {{jsxref("string")}} that must exactly match the bookmark's URL. Matching is case-insensitive, and trailing slashes are ignored. If you pass an invalid URL, the function will throw an exception. - `title` {{optional_inline}} - : A {{jsxref("string")}} that must exactly match the bookmark tree node's title. Matching is case-sensitive. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an array of {{WebExtAPIRef('bookmarks.BookmarkTreeNode')}} objects, each representing a single matching bookmark tree node. Results are returned in the order that the nodes were created. The array is empty if no results were found. The [`BookmarkTreeNodes`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/bookmarks/BookmarkTreeNode)—even nodes of the `"folder"` type—returned by `bookmarks.search()` are missing the `children` property. To get a complete `BookmarkTreeNode` use [`bookmarks.getSubTree()`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/bookmarks/getSubTree). ## Example This example logs the IDs of all bookmarks: ```js function onFulfilled(bookmarkItems) { for (const item of bookmarkItems) { console.log(item.id); } } function onRejected(error) { console.log(`An error: ${error}`); } browser.bookmarks.search({}).then(onFulfilled, onRejected); ``` This example looks to see if the currently active tab is bookmarked: ```js function onFulfilled(bookmarkItems) { if (bookmarkItems.length) { console.log("active tab is bookmarked"); } else { console.log("active tab is not bookmarked"); } } function onRejected(error) { console.log(`An error: ${error}`); } function checkActiveTab(tab) { browser.bookmarks.search({ url: tab.url }).then(onFulfilled, onRejected); } browser.browserAction.onClicked.addListener(checkActiveTab); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#method-search) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/onimportended/index.md
--- title: bookmarks.onImportEnded slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/onImportEnded page-type: webextension-api-event browser-compat: webextensions.api.bookmarks.onImportEnded --- {{AddonSidebar}} Fired when the browser has finished importing a set of bookmarks. See {{WebExtAPIRef("bookmarks.onImportBegan")}}. ## Syntax ```js-nolint browser.bookmarks.onImportEnded.addListener(listener) browser.bookmarks.onImportEnded.removeListener(listener) browser.bookmarks.onImportEnded.hasListener(listener) ``` Events have three functions: - `addListener(listener)` - : Adds a listener to this event. - `removeListener(listener)` - : Stop listening to this event. The `listener` argument is the listener to remove. - `hasListener(listener)` - : Check whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. ## addListener syntax ### Parameters - `listener` - : The function called when this event occurs. It's passed no parameters. ## Browser compatibility {{Compat}} ## Examples ```js function handleImportBegan() { console.log("Importing…"); } function handleImportEnded() { console.log("Import finished."); } function handleClick() { browser.bookmarks.onImportBegan.addListener(handleImportBegan); browser.bookmarks.onImportEnded.addListener(handleImportEnded); } browser.browserAction.onClicked.addListener(handleClick); ``` {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#event-onImportEnded) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/getrecent/index.md
--- title: bookmarks.getRecent() slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/getRecent page-type: webextension-api-function browser-compat: webextensions.api.bookmarks.getRecent --- {{AddonSidebar}} The `bookmarks.getRecent()` method retrieves a specified number of the most recently added bookmarks as an array of {{WebExtAPIRef('bookmarks.BookmarkTreeNode', 'BookmarkTreeNode')}} objects. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let gettingRecent = browser.bookmarks.getRecent( numberOfItems // integer ) ``` ### Parameters - `numberOfItems` - : A number representing the maximum number of items to return. The returned list will contain up to this many of the most recently added items. The minimum allowed value here is 1. If you pass 0 or less, the function will throw an error. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an array of [`BookmarkTreeNode`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/bookmarks/BookmarkTreeNode) objects. ## Examples This example logs the URL for the most recently added bookmark: ```js function onFulfilled(bookmarks) { for (const bookmark of bookmarks) { console.log(bookmark.url); } } function onRejected(error) { console.log(`An error: ${error}`); } browser.bookmarks.getRecent(1).then(onFulfilled, onRejected); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#method-getRecent) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/oncreated/index.md
--- title: bookmarks.onCreated slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/onCreated page-type: webextension-api-event browser-compat: webextensions.api.bookmarks.onCreated --- {{AddonSidebar}} Fired when a bookmark item (a bookmark or a folder) is created. ## Syntax ```js-nolint browser.bookmarks.onCreated.addListener(listener) browser.bookmarks.onCreated.removeListener(listener) browser.bookmarks.onCreated.hasListener(listener) ``` Events have three functions: - `addListener(listener)` - : Adds a listener to this event. - `removeListener(listener)` - : Stop listening to this event. The `listener` argument is the listener to remove. - `hasListener(listener)` - : Check whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. ## addListener syntax ### Parameters - `listener` - : The function called when this event occurs. The function is passed these arguments: - `id` - : `string`. The new bookmark item's ID. - `bookmark` - : {{WebExtAPIRef('bookmarks.BookmarkTreeNode')}}. Information about the new bookmark item. ## Examples ```js function handleCreated(id, bookmarkInfo) { console.log(`New bookmark ID: ${id}`); console.log(`New bookmark URL: ${bookmarkInfo.url}`); } browser.bookmarks.onCreated.addListener(handleCreated); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#event-onCreated) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/update/index.md
--- title: bookmarks.update() slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/update page-type: webextension-api-function browser-compat: webextensions.api.bookmarks.update --- {{AddonSidebar}} **`bookmarks.update()`** updates the title and/or URL of a bookmark, or the name of a bookmark folder. > **Warning:** If your extension attempts to update a bookmark in the bookmarks tree root node, the call will raise an error with the message: "The bookmark root cannot be modified" and the bookmark won't be updated. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let updating = browser.bookmarks.update( id, // string changes // object ) ``` ### Parameters - `id` - : A {{jsxref("string")}} specifying the ID of the bookmark or bookmark folder to update. - `changes` - : An {{jsxref("object")}} specifying the changes to apply, with some combination of the following fields. Any items not specified aren't changed in the referenced bookmark or folder: - `title` {{optional_inline}} - : A {{jsxref("string")}} containing the new title of the bookmark, or the new name of the folder if `id` refers to a folder. - `url` {{optional_inline}} - : A {{jsxref("string")}} providing a new URL for the bookmark. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with a single [`bookmarks.BookmarkTreeNode`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/bookmarks/BookmarkTreeNode) object, representing the updated bookmark. If the bookmark item corresponding to the `id` parameter can't be found, the promise is rejected. ## Examples This example renames all folders named "MDN" to "Mozilla Developer Network (MDN)". ```js function onFulfilled(bookmarkItem) { console.log(bookmarkItem.title); } function onRejected(error) { console.error(`Error: ${error}`); } function updateFolders(items) { for (const item of items) { // only folders, so skip items with a `url` if (!item.url) { browser.bookmarks .update(item.id, { title: "Mozilla Developer Network (MDN)", }) .then(onFulfilled, onRejected); } } } browser.bookmarks.search({ title: "MDN" }).then(updateFolders, onRejected); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#method-update) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/getchildren/index.md
--- title: bookmarks.getChildren() slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/getChildren page-type: webextension-api-function browser-compat: webextensions.api.bookmarks.getChildren --- {{AddonSidebar}} **`bookmarks.getChildren()`** retrieves all the immediate children of a bookmark folder, identified as a {{WebExtAPIRef("bookmarks.BookmarkTreeNode", "BookmarkTreeNode")}} ID. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let gettingChildren = browser.bookmarks.getChildren( id // string ) ``` ### Parameters - `id` - : A {{jsxref("string")}} that specifies the ID of the folder whose children are to be retrieved. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that is fulfilled with an array of [`BookmarkTreeNode`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/bookmarks/BookmarkTreeNode) objects. Each entry represents a child node. The list is in the same order as the bookmarks appear in the user interface. Separators are included in the results. The list includes subfolders but does not include any children contained in subfolders. If the specified node has no children, the array is empty. If the node identified by `id` is not found, the promise is rejected with an error message. ## Examples ```js function onFulfilled(children) { for (child of children) { console.log(child.id); } } function onRejected(error) { console.log(`An error: ${error}`); } let gettingChildren = browser.bookmarks.getChildren("unfiled_____"); gettingChildren.then(onFulfilled, onRejected); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#method-getChildren) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/createdetails/index.md
--- title: bookmarks.CreateDetails slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/CreateDetails page-type: webextension-api-type browser-compat: webextensions.api.bookmarks.CreateDetails --- {{AddonSidebar}} The `CreateDetails` type is used to describe the properties of a new, bookmark, bookmark folder, or separator when calling the {{WebExtAPIRef("bookmarks.create()")}} method. ## Type An {{jsxref("object")}} containing some combination of the following fields: - `index` {{optional_inline}} - : An integer {{jsxref("Number")}} which specifies the position at which to place the new bookmark under its parent. A value of 0 will put it at the top of the list. - `parentId` {{optional_inline}} - : A {{jsxref("string")}} which indicates the ID of the parent folder into which to place the new bookmark or bookmark folder. On Chrome and Firefox, the default is the "Other Bookmarks" folder on the Bookmarks menu. - `title` {{optional_inline}} - : A {{jsxref("string")}} which specifies the title for the bookmark or the name of the folder to be created. If this isn't specified, the title is `""`. - `type` {{optional_inline}} - : A {{WebExtAPIRef("bookmarks.BookmarkTreeNodeType")}} object indicating whether this is a bookmark, a folder, or a separator. Defaults to `"bookmark"` unless `url` is omitted, in which case it defaults to `"folder"`. - `url` {{optional_inline}} - : `string`. A {{jsxref("string")}} which specifies the URL of the page to bookmark. If this is omitted or is `null`, a folder is created instead of a bookmark. ## Browser compatibility {{Compat}} {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#type-CreateDetails) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/bookmarktreenodeunmodifiable/index.md
--- title: bookmarks.BookmarkTreeNodeUnmodifiable slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/BookmarkTreeNodeUnmodifiable page-type: webextension-api-type browser-compat: webextensions.api.bookmarks.BookmarkTreeNodeUnmodifiable --- {{AddonSidebar}} The **`bookmarks.BookmarkTreeNodeUnmodifiable`** type is used to indicate the reason that a node in the bookmark tree (where each node is either a bookmark or a bookmark folder) cannot be changed. This is used as the value of the {{WebExtAPIRef("bookmarks.BookmarkTreeNode", "bookmarks.BookmarkTreeNode.unmodifiable", "unmodifiable")}} field on bookmark nodes. ## Type `bookmarks.BookmarkTreeNodeUnmodifiable` is a {{jsxref("string")}} which can currently have only one value: `"managed"`. This indicates that the bookmark node was configured by an administrator or by the custodian of a supervised user (such as a parent, in the case of parental controls). ## Browser compatibility {{Compat}} {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#type-BookmarkTreeNodeUnmodifiable) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/onremoved/index.md
--- title: bookmarks.onRemoved slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/onRemoved page-type: webextension-api-event browser-compat: webextensions.api.bookmarks.onRemoved --- {{AddonSidebar}} Fired when a bookmark or folder is removed. When a folder is removed recursively, a single notification is fired for the folder, and none for its contents. ## Syntax ```js-nolint browser.bookmarks.onRemoved.addListener(listener) browser.bookmarks.onRemoved.removeListener(listener) browser.bookmarks.onRemoved.hasListener(listener) ``` Events have three functions: - `addListener(listener)` - : Adds a listener to this event. - `removeListener(listener)` - : Stop listening to this event. The `listener` argument is the listener to remove. - `hasListener(listener)` - : Check whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. ## addListener syntax ### Parameters - `listener` - : The function called when this event occurs. The function is passed these arguments: - `id` - : `string`. ID of the item that was removed. - `removeInfo` - : `object`. More details about the removed item. See the [removeInfo](#removeinfo_2) section for more details. ## Additional objects ### removeInfo - `parentId` - : `string`. ID of the item's parent in the tree. - `index` - : `integer`. Zero-based index position of this item in its parent. - `node` - : {{WebExtAPIRef('bookmarks.BookmarkTreeNode')}}. Detailed information about the item that was removed. ## Examples ```js function handleRemoved(id, removeInfo) { console.log(`Item: ${id} removed`); console.log(`Title: ${removeInfo.node.title}`); console.log(`Url: ${removeInfo.node.url}`); } function handleClick() { browser.bookmarks.onRemoved.addListener(handleRemoved); } browser.browserAction.onClicked.addListener(handleClick); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#event-onRemoved) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/bookmarktreenodetype/index.md
--- title: bookmarks.BookmarkTreeNodeType slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/BookmarkTreeNodeType page-type: webextension-api-type browser-compat: webextensions.api.bookmarks.BookmarkTreeNodeType --- {{AddonSidebar}} The **`bookmarks.BookmarkTreeNodeType`** type is used to describe whether a node in the bookmark tree is a bookmark, a folder, or a separator. ## Type `bookmarks.BookmarkTreeNodeType` is a {{jsxref("string")}} which can have one of the following three values: - `"bookmark"`: the node is a bookmark. - `"folder"`: the node is a folder. - `"separator"`: the node is a separator. ## Browser compatibility {{Compat}} {{WebExtExamples}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/removetree/index.md
--- title: bookmarks.removeTree() slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/removeTree page-type: webextension-api-function browser-compat: webextensions.api.bookmarks.removeTree --- {{AddonSidebar}} The **`bookmarks.removeTree()`** method recursively removes a bookmark folder and all of its contents. > **Warning:** If your extension attempts to remove a bookmark tree from the bookmarks tree root node, the call will raise an error with the message: "The bookmark root cannot be modified" and the bookmark won't be removed. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let removingTree = browser.bookmarks.removeTree( id // string ) ``` ### Parameters - `id` - : A {{jsxref("string")}} specifying the ID of the folder node to be deleted along with its descendants. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with no arguments when the tree has been removed. If the node corresponding to the `id` parameter can't be found, the promise is rejected with an error message. ## Examples This example locates a bookmark folder named "MDN" and deletes it along with all of its contents. ```js function onRemoved() { console.log("bookmark item removed!"); } function onRejected(error) { console.log(`An error: ${error}`); } function removeMDN(searchResults) { if (searchResults.length) { let removing = browser.bookmarks.removeTree(searchResults[0].id); removing.then(onRemoved, onRejected); } } let searchingBookmarks = browser.bookmarks.search({ title: "MDN" }); searchingBookmarks.then(removeMDN, onRejected); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#method-removeTree) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/onchildrenreordered/index.md
--- title: bookmarks.onChildrenReordered slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/onChildrenReordered page-type: webextension-api-event browser-compat: webextensions.api.bookmarks.onChildrenReordered --- {{AddonSidebar}} Fired when the children of a folder have changed their order due to the order being sorted in the UI. This is not called as a result of a call to {{WebExtAPIRef("bookmarks.move()")}} or a drag operation in the UI. ## Syntax ```js-nolint browser.bookmarks.onChildrenReordered.addListener(listener) browser.bookmarks.onChildrenReordered.removeListener(listener) browser.bookmarks.onChildrenReordered.hasListener(listener) ``` Events have three functions: - `addListener(listener)` - : Adds a listener to this event. - `removeListener(listener)` - : Stop listening to this event. The `listener` argument is the listener to remove. - `hasListener(listener)` - : Check whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. ## addListener syntax ### Parameters - `listener` - : The function called when this event occurs. The function is passed these arguments: - `id` - : `string`. ID of the folder whose children were reordered. - `reorderInfo` - : `object`. Object containing Additional objects. See the [reorderInfo](#reorderinfo_2) section for more details. ## Additional objects ### reorderInfo - `childIds` - : `array` of `string`. Array containing the IDs of all the bookmark items in this folder, in the order they now appear in the UI. ## Browser compatibility {{Compat}} ## Examples ```js function handleChildrenReordered(id, reorderInfo) { console.log(`Item: ${id} children reordered`); console.log(`Children: ${reorderInfo.childIds}`); } function handleClick() { browser.bookmarks.onChildrenReordered.addListener(handleChildrenReordered); } browser.browserAction.onClicked.addListener(handleClick); ``` {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#event-onChildrenReordered) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/move/index.md
--- title: bookmarks.move() slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/move page-type: webextension-api-function browser-compat: webextensions.api.bookmarks.move --- {{AddonSidebar}} The **`bookmarks.move()`** method moves the specified {{WebExtAPIRef("bookmarks.BookmarkTreeNode", "BookmarkTreeNode")}} to the specified destination within the tree of bookmarks. This lets you move a bookmark to a new folder and/or position within the folder. > **Warning:** If your extension attempts to move a bookmark into the bookmarks tree root node, the call will raise an error with the message: "_The bookmark root cannot be modified_" and the move won't be completed. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let movingBookmark = browser.bookmarks.move( id, // string destination // object ) ``` ### Parameters - `id` - : A {{jsxref("string")}} containing the ID of the bookmark or folder to move. - `destination` - : An {{jsxref("object")}} which specifies the destination for the bookmark. This object must contain one or both of the following fields: - `parentId` {{optional_inline}} - : A {{jsxref("string")}} which specifies the ID of the destination folder. If this value is left out, the bookmark is moved to a new location within its current folder. - `index` {{optional_inline}} - : A 0-based index specifying the position within the folder to which to move the bookmark. A value of 0 moves the bookmark to the top of the folder. If this value is omitted, the bookmark is placed at the end of the new parent folder. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with a single [`bookmarks.BookmarkTreeNode`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/bookmarks/BookmarkTreeNode) object, describing the moved node. If the node corresponding to the `id` parameter can't be found, the promise is rejected with an error message. > **Note:** If you move multiple bookmarks, because this API is asynchronous, the move calls may get processed in any order. Consequently, the value of each bookmark's index returned in {{WebExtAPIRef('bookmarks.BookmarkTreeNode', 'BookmarkTreeNode')}} may change or be unknown until all the move calls are completed. If the index associated with a bookmark matters to your extension, then – when moving multiple bookmarks – the extension should wait for each `bookmarks.move` call to complete before moving the next bookmark. Waiting ensures that the index associated with each bookmark is not affected by a move call executing concurrently while the original call is in progress. ## Examples This example moves a bookmark so that it's the first bookmark in its current folder. ```js function onMoved(bookmarkItem) { console.log(bookmarkItem.index); } function onRejected(error) { console.log(`An error: ${error}`); } let bookmarkId = "abcdefghijkl"; let movingBookmark = browser.bookmarks.move(bookmarkId, { index: 0 }); movingBookmark.then(onMoved, onRejected); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#method-move) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/bookmarks/onmoved/index.md
--- title: bookmarks.onMoved slug: Mozilla/Add-ons/WebExtensions/API/bookmarks/onMoved page-type: webextension-api-event browser-compat: webextensions.api.bookmarks.onMoved --- {{AddonSidebar}} Fired when a bookmark or folder is moved to a different parent folder or position within a folder. > **Note:** If you're moving multiple bookmarks, because this API is asynchronous, the move calls may get processed in any order. Consequently, the value of each bookmark's index may change or be unknown until all the move calls are completed. If the index associated with a bookmark matters to your extension, then – when moving multiple bookmarks – the extension should wait for each `bookmarks.move` call to complete before moving the next bookmark. Waiting ensures that the index associated with each bookmark is not affected by a move call executing concurrently while the original call is in progress. ## Syntax ```js-nolint browser.bookmarks.onMoved.addListener(listener) browser.bookmarks.onMoved.removeListener(listener) browser.bookmarks.onMoved.hasListener(listener) ``` Events have three functions: - `addListener(listener)` - : Adds a listener to this event. - `removeListener(listener)` - : Stop listening to this event. The `listener` argument is the listener to remove. - `hasListener(listener)` - : Check whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. ## addListener syntax ### Parameters - `listener` - : The function called when this event occurs. The function is passed these arguments: - `id` - : `string`. ID of the item that was moved. - `moveInfo` - : `object`. Object containing more details about the move. See the [moveInfo](#moveinfo_2) section for more details. ## Additional objects ### moveInfo - `parentId` - : `string`. The new parent folder. - `index` - : `integer`. The new index of this item in its parent. - `oldParentId` - : `string`. The old parent folder. - `oldIndex` - : `integer`. The old index of the item in its parent. ## Browser compatibility {{Compat}} ## Examples ```js function handleMoved(id, moveInfo) { console.log(`Item: ${id} moved`); console.log(`Old index: ${moveInfo.oldIndex}`); console.log(`New index: ${moveInfo.index}`); console.log(`Old folder: ${moveInfo.oldParentId}`); console.log(`New folder: ${moveInfo.parentId}`); } function handleClick() { browser.bookmarks.onMoved.addListener(handleMoved); } browser.browserAction.onClicked.addListener(handleClick); ``` {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.bookmarks`](https://developer.chrome.com/docs/extensions/reference/bookmarks/#event-onMoved) API. This documentation is derived from [`bookmarks.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/bookmarks.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction/index.md
--- title: sidebarAction slug: Mozilla/Add-ons/WebExtensions/API/sidebarAction page-type: webextension-api browser-compat: webextensions.api.sidebarAction --- {{AddonSidebar}} Gets and sets properties of an extension's sidebar. A [sidebar](/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Sidebars) is a pane that is displayed at the left-hand or right-hand side of the browser window, next to the web page. The browser provides a UI that enables the user to see the currently available sidebars and to select a sidebar to display. Using the [`sidebar_action`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/sidebar_action) manifest.json key, an extension can define its own sidebar. Using the `sidebarAction` API described here, an extension can get and set the sidebar's properties. The `sidebarAction` API is closely modeled on the {{WebExtAPIRef("browserAction")}} API. The sidebarAction API is based on Opera's [sidebarAction API](https://dev.opera.com/extensions/sidebar-action-api/). However, note that the following are not yet supported: `setBadgeText()`, `getBadgeText()`, `setBadgeBackgroundColor()`, `getBadgeBackgroundColor()`, `onFocus`, `onBlur`. ## Types - {{WebExtAPIRef("sidebarAction.ImageDataType")}} - : Pixel data for an image. Must be an [`ImageData`](/en-US/docs/Web/API/ImageData) object (for example, from a {{htmlelement("canvas")}} element). ## Functions - {{WebExtAPIRef("sidebarAction.close()")}} - : Closes the sidebar. - {{WebExtAPIRef("sidebarAction.getPanel()")}} - : Gets the sidebar's panel. - {{WebExtAPIRef("sidebarAction.getTitle()")}} - : Gets the sidebar's title. - {{WebExtAPIRef("sidebarAction.isOpen()")}} - : Checks whether the sidebar is open or not. - {{WebExtAPIRef("sidebarAction.open()")}} - : Opens the sidebar. - {{WebExtAPIRef("sidebarAction.setIcon()")}} - : Sets the sidebar's icon. - {{WebExtAPIRef("sidebarAction.setPanel()")}} - : Sets the sidebar's panel. - {{WebExtAPIRef("sidebarAction.setTitle()")}} - : Sets the sidebar's title. This will be displayed in any UI provided by the browser to list sidebars, such as a menu. - {{WebExtAPIRef("sidebarAction.toggle()")}} - : Toggles the visibility of the sidebar. ## Browser compatibility {{Compat}} ## Example add-ons - [annotate-page](https://github.com/mdn/webextensions-examples/tree/main/annotate-page) > **Note:** This API is based on Opera's [`chrome.sidebarAction`](https://dev.opera.com/extensions/sidebar-action-api/) API. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction/settitle/index.md
--- title: sidebarAction.setTitle() slug: Mozilla/Add-ons/WebExtensions/API/sidebarAction/setTitle page-type: webextension-api-function browser-compat: webextensions.api.sidebarAction.setTitle --- {{AddonSidebar}} Sets the sidebar's title. The title is displayed anywhere the browser lists available sidebars. For example, Firefox will show it in the "View > Sidebar" menu. It's also shown at the top o the sidebar when the sidebar is open. ## Types of title Your extension should specify an title for the sidebar in the [sidebar_action](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/sidebar_action) manifest key. This is called the _"manifest title"_. If you don't specify the manifest title, it will default to the extension name. If you set a new title using `setTitle()`, and include the `tabId` option, then the title is set only for the given tab. This title is called the _"tab-specific title"_. If you set a new title using `setTitle()`, and include the `windowId` option, then the title is set only for the given window. This title is called the _"window-specific title"_, and will appear in all tabs of that window that do not have a tab-specific title set. If you set a new title using `setTitle()`, and omit both the `tabId` and `windowId` options, then this sets the _"global title"_. The global title will then appear in all tabs that do not have a tab-specific title set and whose window does not have a window-specific title. ## Syntax ```js-nolint browser.sidebarAction.setTitle( details // object ) ``` ### Parameters - `details` - : `object`. An object with the following properties: - `title` - : `string` or `null`. The sidebar's new title. If `title` is an empty string, the used title will be the extension name, but {{WebExtAPIRef("sidebarAction.getTitle")}} will still provide the empty string. If `title` is `null`, then a previously set title will be removed, so that: - If `tabId` is specified, and the tab has a tab-specific title set, then the tab will inherit the title from the window it belongs to. - If `windowId` is specified, and the window has a window-specific title set, then the window will inherit the global title. - Otherwise, the global title will be reset to the manifest title. - `tabId` {{optional_inline}} - : `integer`. Sets the title only for the given tab. - `windowId` {{optional_inline}} - : `integer`. Sets the title only for the given window. <!----> - If `windowId` and `tabId` are both supplied, the function fails and the title is not set. - If `windowId` and `tabId` are both omitted, the global title is set. ## Browser compatibility {{Compat}} ## Examples This code changes the title for the sidebar when the user clicks a browser action, but only for the current tab: ```js let title = "A different title"; function setTitleForTab(tab) { browser.sidebarAction.setTitle({ title, tabId: tab.id }); } browser.browserAction.onClicked.addListener(setTitleForTab); ``` {{WebExtExamples}} > **Note:** This API is based on Opera's [`chrome.sidebarAction`](https://dev.opera.com/extensions/sidebar-action-api/) API. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction/setpanel/index.md
--- title: sidebarAction.setPanel() slug: Mozilla/Add-ons/WebExtensions/API/sidebarAction/setPanel page-type: webextension-api-function browser-compat: webextensions.api.sidebarAction.setPanel --- {{AddonSidebar}} Sets the sidebar's panel: that is, the HTML document that defines the content of this sidebar. ## Types of panel Sidebars always have a _"manifest panel"_, which is the panel defined in the [`sidebar_action`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/sidebar_action) manifest key. If you set a new panel using `setPanel()`, and include the `tabId` option, then the panel is set only for the given tab. This panel is referred to as the _"tab-specific panel"_. If you set a new panel using `setPanel()`, and include the `windowId` option, then the panel is set only for the given window. This panel is referred to as the _"window-specific panel"_, and will appear in all tabs of that window that do not have a tab-specific panel set. If you set a new panel using `setPanel()`, and omit both the `tabId` and `windowId` options, then this sets the _"global panel"_. The global panel will then appear in all tabs that do not have a tab-specific panel set and whose window does not have a window-specific panel. ## Syntax ```js-nolint browser.sidebarAction.setPanel( details // object ) ``` ### Parameters - `details` - : `object`. An object with the following properties: - `panel` - : `string` or `null`. The panel to load into the sidebar, specified as a URL pointing to an HTML document, or `null`, or an empty string. This can point to a file packaged within the extension (for example, created using {{WebExtAPIRef("runtime.getURL")}}), or a remote document (e.g. `https://example.org/`). It must be a valid URL. If `panel` is `null` or `""`, then a previously set panel will be removed, so that: - If `tabId` is specified, and the tab has a tab-specific panel set, then the tab will inherit the panel from the window it belongs to. - If `windowId` is specified, and the window has a window-specific panel set, then the window will inherit the global panel. - Otherwise, the global panel will be reset to the manifest panel. - `tabId` {{optional_inline}} - : `integer`. Sets the panel only for the given tab. - `windowId` {{optional_inline}} - : `integer`. Sets the panel only for the given window. <!----> - If `windowId` and `tabId` are both specified, the function fails and the panel is not set. - If `windowId` and `tabId` are both omitted, the global panel is set. ## Examples This code toggles the sidebar document when the user clicks a browser action: ```js let thisPanel = browser.runtime.getURL("/this.html"); let thatPanel = browser.runtime.getURL("/that.html"); function toggle(panel) { if (panel === thisPanel) { browser.sidebarAction.setPanel({ panel: thatPanel }); } else { browser.sidebarAction.setPanel({ panel: thisPanel }); } } browser.browserAction.onClicked.addListener(() => { browser.sidebarAction.getPanel({}).then(toggle); }); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Opera's [`chrome.sidebarAction`](https://dev.opera.com/extensions/sidebar-action-api/) API. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction/seticon/index.md
--- title: sidebarAction.setIcon() slug: Mozilla/Add-ons/WebExtensions/API/sidebarAction/setIcon page-type: webextension-api-function browser-compat: webextensions.api.sidebarAction.setIcon --- {{AddonSidebar}} Sets the icon for the sidebar. You can specify a single icon as either the path to an image file or a {{WebExtAPIRef('sidebarAction.ImageDataType')}} object. You can specify multiple icons in different sizes by supplying a dictionary containing multiple paths or `ImageData` objects. This means the icon doesn't have to be scaled for a device with a different pixel density. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Types of icon Your extension should specify an icon for the sidebar in the [`sidebar_action`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/sidebar_action) manifest key. This is called the _"manifest icon"_. If you don't specify an icon in the `sidebar_action` key, you get the browser's default icon. This is called the _"default icon"_. If you set a new icon using `setIcon()`, and include the `tabId` option, then the icon is set only for the given tab. This icon is called the _"tab-specific icon"_. If you set a new icon using `setIcon()`, and include the `windowId` option, then the icon is set only for the given window. This icon is called the _"window-specific icon"_, and will appear in all tabs of that window that do not have a tab-specific icon set. If you set a new icon using `setIcon()`, and omit both the `tabId` and `windowId` options, then this sets the _"global icon"_. The global icon will then appear in all tabs that do not have a tab-specific icon set and whose window does not have a window-specific icon. ## Syntax ```js-nolint let settingIcon = browser.sidebarAction.setIcon( details // object ) ``` ### Parameters - `details` - : `object`. An object with the following properties: - `imageData` {{optional_inline}} - : `{{WebExtAPIRef('sidebarAction.ImageDataType')}}` or `object`. This is either a single `ImageData` object or a dictionary object. Use a dictionary object to specify multiple `ImageData` objects in different sizes, so the icon does not have to be scaled for a device with a different pixel density. If `imageData` is a dictionary, the value of each property is an `ImageData` object, and its name is its size, like this: ```js let settingIcon = browser.action.setIcon({ imageData: { 16: image16, 32: image32, }, }); ``` The browser will choose the image to use depending on the screen's pixel density. See [Choosing icon sizes](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_action#choosing_icon_sizes) for more information on this. - `path` {{optional_inline}} - : `string` or `object`. This is either a relative path to an icon file or it is a dictionary object. Use a dictionary object to specify multiple icon files in different sizes, so the icon does not have to be scaled for a device with a different pixel density. If `path` is a dictionary, the value of each property is a relative path, and its name is its size, like this: ```js let settingIcon = browser.action.setIcon({ path: { 16: "path/to/image16.jpg", 32: "path/to/image32.jpg", }, }); ``` The browser will choose the image to use depending on the screen's pixel density. See [Choosing icon sizes](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_action#choosing_icon_sizes) for more information on this. If `path` is an empty string, the browser will use the default icon. If `path` is not empty but does not point to an icon file, then the icon is hidden. If `path` is `null`, and `tabId` was specified, and the specified tab had a tab-specific icon set: then the tab-specific icon is reset to the global icon (if a global icon is set) or the manifest icon. if `path` is `null`, and `tabId` was omitted, and there was a global icon set, it will be reset to the manifest icon. - `tabId` {{optional_inline}} - : `integer`. Sets the icon only for the given tab. - `windowId` {{optional_inline}} - : `integer`. Sets the icon only for the given window. <!----> - If `windowId` and `tabId` are both specified, the function fails and the icon is not set. - If `windowId` and `tabId` are both omitted, the icon is set globally. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with no arguments once the icon has been set. ## Browser compatibility {{Compat}} ## Examples The code below toggles the sidebar icon for the active tab when the user clicks a browser action: ```js let on = false; function toggle(tab) { if (on) { browser.sidebarAction.setIcon({ path: "off.svg", tabId: tab.id, }); on = false; } else { browser.sidebarAction.setIcon({ path: "on.svg", tabId: tab.id, }); on = true; } } browser.browserAction.onClicked.addListener(toggle); ``` {{WebExtExamples}} > **Note:** This API is based on Opera's [`chrome.sidebarAction`](https://dev.opera.com/extensions/sidebar-action-api/) API.
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction/isopen/index.md
--- title: sidebarAction.isOpen() slug: Mozilla/Add-ons/WebExtensions/API/sidebarAction/isOpen page-type: webextension-api-function browser-compat: webextensions.api.sidebarAction.isOpen --- {{AddonSidebar}} Returns `true` if the extension's sidebar is open in a given window. This function accepts a `windowId` as a parameter: - If you supply `windowId`, the function will check the given browser window. - If you omit `windowId`, the function will check the topmost browser window. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let gettingIsOpen = browser.sidebarAction.isOpen( details // object ) ``` ### Parameters - `details` - : `object`. An object optionally containing the `windowId` to check. - `windowId` {{optional_inline}} - : `integer`. ID of a browser window to check. If omitted defaults to {{WebExtAPIRef("windows.WINDOW_ID_CURRENT")}}, which refers to the topmost browser window. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with `true` if the extension's sidebar is open in the given window, or `false` otherwise. ## Browser compatibility {{Compat}} ## Examples Check the topmost window: ```js browser.sidebarAction.isOpen({}).then((result) => { console.log(result); }); ``` Check all open windows: ```js async function checkWindow(windowId) { const result = await browser.sidebarAction.isOpen({ windowId }); console.log(`window: ${windowId} status: ${result}`); } browser.windows.getAll().then((all) => { for (const { id } of all) { checkWindow(id); } }); ``` {{WebExtExamples}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction/getpanel/index.md
--- title: sidebarAction.getPanel() slug: Mozilla/Add-ons/WebExtensions/API/sidebarAction/getPanel page-type: webextension-api-function browser-compat: webextensions.api.sidebarAction.getPanel --- {{AddonSidebar}} Gets a URL to the HTML document that defines the sidebar's contents. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let gettingPanel = browser.sidebarAction.getPanel( details // object ) ``` ### Parameters - `details` - : `object`. An object with the following properties: - `tabId` {{optional_inline}} - : `integer`. Get the panel for the sidebar specific to the given tab. - `windowId` {{optional_inline}} - : `integer`. Get the panel for the sidebar specific to the given window. <!----> - If `windowId` and `tabId` are both supplied, the function fails and the promise it returns is rejected. - If `windowId` and `tabId` are both omitted, the global panel is returned. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with a string containing the URL for the panel's document. This will be a fully qualified URL, such as: ```url moz-extension://d1d8a2eb-fe60-f646-af30-a866c5b39942/sidebar.html ``` ## Browser compatibility {{Compat}} ## Examples Get the panel's URL: ```js function onGot(sidebarUrl) { console.log(sidebarUrl); } let gettingPanel = browser.sidebarAction.getPanel({}); gettingPanel.then(onGot); ``` {{WebExtExamples}} > **Note:** This API is based on Opera's [`chrome.sidebarAction`](https://dev.opera.com/extensions/sidebar-action-api/) API. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction/gettitle/index.md
--- title: sidebarAction.getTitle() slug: Mozilla/Add-ons/WebExtensions/API/sidebarAction/getTitle page-type: webextension-api-function browser-compat: webextensions.api.sidebarAction.getTitle --- {{AddonSidebar}} Gets the sidebar's title. Just as you can set the title on a per-tab basis using {{WebExtAPIRef("sidebarAction.setTitle()")}}, so you can retrieve a tab-specific title by passing the tab's ID into this function. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let gettingTitle = browser.sidebarAction.getTitle( details // object ) ``` ### Parameters - `details` - : `object`. An object with the following properties: - `tabId` {{optional_inline}} - : `integer`. Get the title for the sidebar specific to the given tab. - `windowId` {{optional_inline}} - : `integer`. Get the title for the sidebar specific to the given window. <!----> - If `windowId` and `tabId` are both supplied, the function fails and the promise it returns is rejected. - If `windowId` and `tabId` are both omitted, the global title is returned. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with a string containing the sidebar's title. ## Browser compatibility {{Compat}} ## Examples This code switches the title between "this" and "that" each time the user clicks the browser action ```js function toggleTitle(title) { if (title === "this") { browser.sidebarAction.setTitle({ title: "that" }); } else { browser.sidebarAction.setTitle({ title: "this" }); } } browser.browserAction.onClicked.addListener(() => { let gettingTitle = browser.sidebarAction.getTitle({}); gettingTitle.then(toggleTitle); }); ``` {{WebExtExamples}} > **Note:** This API is based on Opera's [`chrome.sidebarAction`](https://dev.opera.com/extensions/sidebar-action-api/) API. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction/toggle/index.md
--- title: sidebarAction.toggle() slug: Mozilla/Add-ons/WebExtensions/API/sidebarAction/toggle page-type: webextension-api-function browser-compat: webextensions.api.sidebarAction.toggle --- {{AddonSidebar}} Toggles the visibility of the sidebar in the active window, if the sidebar belongs to the extension. You can only call this function from inside the handler for a [user action](/en-US/docs/Mozilla/Add-ons/WebExtensions/User_actions). This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint browser.sidebarAction.toggle() ``` ### Parameters None. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that is resolved with no arguments. ## Browser compatibility {{Compat}} ## Examples Toggles the sidebar when the user selects an item from the context menu: ```js browser.menus.create({ id: "toggle-sidebar", title: "Toggle sidebar", contexts: ["all"], }); browser.menus.onClicked.addListener(() => { browser.sidebarAction.toggle(); }); ``` {{WebExtExamples}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction/imagedatatype/index.md
--- title: sidebarAction.ImageDataType slug: Mozilla/Add-ons/WebExtensions/API/sidebarAction/ImageDataType page-type: webextension-api-type browser-compat: webextensions.api.sidebarAction.ImageDataType --- {{AddonSidebar}} Pixel data for an image. Must be an [`ImageData`](/en-US/docs/Web/API/ImageData) object (for example, from a {{htmlelement("canvas")}} element). ## Type An [`ImageData`](/en-US/docs/Web/API/ImageData) object. ## Browser compatibility {{Compat}} {{WebExtExamples}} > **Note:** This API is based on Opera's [`chrome.sidebarAction`](https://dev.opera.com/extensions/sidebar-action-api/) API. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction/close/index.md
--- title: sidebarAction.close() slug: Mozilla/Add-ons/WebExtensions/API/sidebarAction/close page-type: webextension-api-function browser-compat: webextensions.api.sidebarAction.close --- {{AddonSidebar}} Closes the sidebar in the active window, if it is the extension's own sidebar. You can only call this function from inside the handler for a [user action](/en-US/docs/Mozilla/Add-ons/WebExtensions/User_actions). This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint browser.sidebarAction.close() ``` ### Parameters None. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that is resolved with no arguments. ## Browser compatibility {{Compat}} ## Examples Close the sidebar when the user selects a context menu item: ```js browser.menus.create({ id: "close-sidebar", title: "close sidebar", contexts: ["all"], }); browser.menus.onClicked.addListener(() => { browser.sidebarAction.close(); }); ``` {{WebExtExamples}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/sidebaraction/open/index.md
--- title: sidebarAction.open() slug: Mozilla/Add-ons/WebExtensions/API/sidebarAction/open page-type: webextension-api-function browser-compat: webextensions.api.sidebarAction.open --- {{AddonSidebar}} Open the sidebar in the active window. You can only call this function from inside the handler for a [user action](/en-US/docs/Mozilla/Add-ons/WebExtensions/User_actions). This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint browser.sidebarAction.open() ``` ### Parameters None. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that is resolved with no arguments. ## Browser compatibility {{Compat}} ## Examples Open the sidebar when the user selects a context menu item: ```js browser.menus.create({ id: "open-sidebar", title: "open sidebar", contexts: ["all"], }); browser.menus.onClicked.addListener(() => { browser.sidebarAction.open(); }); ``` {{WebExtExamples}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/commands/index.md
--- title: commands slug: Mozilla/Add-ons/WebExtensions/API/commands page-type: webextension-api browser-compat: webextensions.api.commands --- {{AddonSidebar}} Listen for the user executing commands that you have registered using the [`commands` manifest.json key](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/commands). ## Types - {{WebExtAPIRef("commands.Command")}} - : Object representing a command. This contains the information specified for the command in the [`commands` manifest.json key](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/commands). ## Functions - {{WebExtAPIRef("commands.getAll")}} - : Gets all registered commands for this extension. - {{WebExtAPIRef("commands.reset")}} - : Reset the given command's description and shortcut to the values given in the manifest key. - {{WebExtAPIRef("commands.update")}} - : Change the description or shortcut for the given command. ## Events - {{WebExtAPIRef("commands.onChanged")}} - : Fired when the keyboard shortcut for a command is changed. - {{WebExtAPIRef("commands.onCommand")}} - : Fired when a command is executed using its associated keyboard shortcut. {{WebExtExamples("h2")}} ## Browser compatibility {{Compat}} > **Note:** > > This API is based on Chromium's [`chrome.commands`](https://developer.chrome.com/docs/extensions/reference/commands/) API. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/commands
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/commands/onchanged/index.md
--- title: onChanged slug: Mozilla/Add-ons/WebExtensions/API/commands/onChanged page-type: webextension-api-event browser-compat: webextensions.api.commands.onChanged --- {{AddonSidebar}} Fired when the keyboard shortcut for a command is changed. The listener is passed an object containing the name of the command, its new active shortcut, and its old shortcut. ## Syntax ```js-nolint browser.commands.onChanged.addListener(listener) browser.commands.onChanged.removeListener(listener) browser.commands.onChanged.hasListener(listener) ``` Events have three functions: - `addListener(listener)` - : Adds a listener to this event. - `removeListener(listener)` - : Stop listening to this event. The `listener` argument is the listener to remove. - `hasListener(listener)` - : Check whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. ## addListener syntax ### Parameters - `listener` - : The function called when a command's shortcut changes. The function is passed these arguments: - `changeInfo` - : `object`. An object containing the name of the command, its new active shortcut, and its old shortcut. - `name` - : `string`. Name of the command. This matches the name given to the command in its [manifest.json entry](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/commands). - `newShortcut` - : `string`. The new active shortcut for this command, or blank if no shortcut is active. - `oldShortcut` - : `string`. The shortcut that was active for this command, or blank if no shortcut was active. ## Browser compatibility {{Compat}} ## Examples You could log changes to command shortcuts like this: ```js function handleChanged(changeInfo) { console.log(`Shortcut for: ${changeInfo.name} changed`); console.log(`From: ${changeInfo.oldShortcut}`); console.log(`To: ${changeInfo.newShortcut}`); } browser.commands.onChanged.addListener(handleChanged); ``` {{WebExtExamples}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/commands
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/commands/update/index.md
--- title: commands.update() slug: Mozilla/Add-ons/WebExtensions/API/commands/update page-type: webextension-api-function browser-compat: webextensions.api.commands.update --- {{AddonSidebar}} Change the description or keyboard shortcut for the given command. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint browser.commands.update( details // object ); ``` ### Parameters - `details` - : `object`. An object with the following properties: - `name` - : `string`. The name of the command to update. This must match the name of an existing command, as given for example in the `name` property of the {{WebExtAPIRef("commands.Command")}} object. - `description` {{optional_inline}} - : `string`. A new description to set for the command. - `shortcut` {{optional_inline}} - : `string`. A new shortcut to set for the command. This can be: - an empty string to clear the shortcut. - a string matching the format of the [`commands` manifest.json key](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/commands) to set a new shortcut key. If the string does not match this format, the function throws an error. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with no arguments when the shortcut has been updated. The promise will be rejected with an error if the command could not be found. ## Browser compatibility {{Compat}} ## Examples Updates the command named "my-command" with the given shortcut value, when the user clicks "update": ```js const commandName = "my-command"; function updateShortcut() { browser.commands.update({ name: commandName, shortcut: document.querySelector("#shortcut").value, }); } document.querySelector("#update").addEventListener("click", updateShortcut); ``` {{WebExtExamples}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/commands
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/commands/reset/index.md
--- title: commands.reset() slug: Mozilla/Add-ons/WebExtensions/API/commands/reset page-type: webextension-api-function browser-compat: webextensions.api.commands.reset --- {{AddonSidebar}} Resets the given command's description and keyboard shortcut to the values given in the extension's [`commands` manifest.json key](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/commands). This effectively undoes any changes made to the command using the {{WEbExtAPIRef("commands.update()")}} function. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint browser.commands.reset( name // string ); ``` ### Parameters - `name` - : `string`. Name of the command to reset, as given by the `name` property of the {{WebExtAPIRef("commands.Command")}} object. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with no arguments when the shortcut has been reset. ## Browser compatibility {{Compat}} ## Examples Resets the command named "my-command" when the user clicks the "reset" button: ```js const commandName = "my-command"; function resetShortcut() { browser.commands.reset(commandName); } document.querySelector("#reset").addEventListener("click", resetShortcut); ``` {{WebExtExamples}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/commands
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/commands/getall/index.md
--- title: getAll() slug: Mozilla/Add-ons/WebExtensions/API/commands/getAll page-type: webextension-api-function browser-compat: webextensions.api.commands.getAll --- {{AddonSidebar}} Gets all commands for the extension that you have registered using the [`commands` manifest.json key](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/commands). The commands are returned as an array of {{WebExtAPIRef('commands.Command')}} objects. Alternately, if you are using the promise-based version of the API, `browser.commands.getAll()`, the commands are passed into the `onFulfilled` argument to [`Promise.then()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then). This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let getCommands = browser.commands.getAll(); ``` ### Parameters None. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an array of `{{WebExtAPIRef('commands.Command')}}` objects, one for each command registered for the extension. If no commands were registered, the array will be empty. ## Examples ```js function logCommands(commands) { commands.forEach((command) => { console.log(command); }); } let getCommands = browser.commands.getAll(); getCommands.then(logCommands); ``` {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.commands`](https://developer.chrome.com/docs/extensions/reference/commands/) API. ## Browser compatibility {{Compat}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/commands
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/commands/oncommand/index.md
--- title: onCommand slug: Mozilla/Add-ons/WebExtensions/API/commands/onCommand page-type: webextension-api-event browser-compat: webextensions.api.commands.onCommand --- {{AddonSidebar}} Fired when a command is executed using its associated keyboard shortcut. The listener is passed the command's name. This matches the name given to the command in its [manifest.json entry](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/commands). ## Syntax ```js-nolint browser.commands.onCommand.addListener(listener) browser.commands.onCommand.removeListener(listener) browser.commands.onCommand.hasListener(listener) ``` Events have three functions: - `addListener(listener)` - : Adds a listener to this event. - `removeListener(listener)` - : Stop listening to this event. The `listener` argument is the listener to remove. - `hasListener(listener)` - : Check whether `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. ## addListener syntax ### Parameters - `listener` - : The function called when a user enters the command's shortcut. The function is passed this argument: - `name` - : `string`. Name of the command. This matches the name given to the command in its [manifest.json entry](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/commands). - `tab` - : {{WebExtAPIRef('tabs.Tab')}}. The tab that was active when the command shortcut was entered. ## Examples Given a manifest.json entry like this: ```json "commands": { "toggle-feature": { "suggested_key": { "default": "Ctrl+Shift+Y" }, "description": "Send a 'toggle-feature' event" } } ``` You could listen for this particular command like this: ```js browser.commands.onCommand.addListener((command) => { if (command === "toggle-feature") { console.log("toggling the feature!"); } }); ``` {{WebExtExamples}} ## Browser compatibility {{Compat}} > **Note:** This API is based on Chromium's [`chrome.commands`](https://developer.chrome.com/docs/extensions/reference/commands/) API.
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/commands
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/commands/command/index.md
--- title: Command slug: Mozilla/Add-ons/WebExtensions/API/commands/Command page-type: webextension-api-type browser-compat: webextensions.api.commands.Command --- {{AddonSidebar}} Information about a command. This contains the information specified for the command in the [`commands` manifest.json key](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/commands). An array of these objects is returned from {{WebExtAPIRef('commands.getAll()')}}. ## Type Values of this type are objects. They contain the following properties: - `name` {{optional_inline}} - : `string`. Name of this command. This will be passed into the {{WebExtAPIRef('commands.onCommand')}} event listener. - `description` {{optional_inline}} - : `string`. Description of this command. This is primarily used to explain to the user what this command does. - `shortcut` {{optional_inline}} - : `string`. Key(s) used to execute this command, specified as a string like "Ctrl+Shift+Y". ## Browser compatibility {{Compat}} {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.commands`](https://developer.chrome.com/docs/extensions/reference/commands/) API.
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction/index.md
--- title: pageAction slug: Mozilla/Add-ons/WebExtensions/API/pageAction page-type: webextension-api browser-compat: webextensions.api.pageAction --- {{AddonSidebar}} The API to control [address bar button](/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Page_actions). ![Paw print icon representing a page action](page-action.png) You can listen for clicks on the icon in a background script, or specify a [popup](/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Popups) that opens when the icon is clicked. If you specify a popup, you define its contents and behavior using HTML, CSS, and JavaScript. JavaScript running in the popup gets access to all the same WebExtension APIs as your background scripts. Despite being named `pageAction`, the action code doesn't get access to web page content. To access web page DOM, you need to add a [content script](/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts) and interact with it. The button also has a context menu, and you can add items to this menu with the {{WebExtAPIRef("menus")}} API using the `page_action` {{WebExtAPIRef("menus.ContextType")}}. You can define most of a page action's properties declaratively using the [`page_action` key](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/page_action) in your [`manifest.json`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json), and redefine them programmatically using this API. Page actions are for actions that are only relevant to particular pages (such as "bookmark the current tab"). If they are relevant to the browser as a whole (such as "show all bookmarks"), use a [browser action](/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Toolbar_button) instead. ## Types - {{WebExtAPIRef("pageAction.ImageDataType")}} - : Pixel data for an image. ## Functions - {{WebExtAPIRef("pageAction.show()")}} - : Shows the page action for a given tab. - {{WebExtAPIRef("pageAction.hide()")}} - : Hides the page action for a given tab. - {{WebExtAPIRef("pageAction.isShown()")}} - : Checks whether the page action is shown or not. - {{WebExtAPIRef("pageAction.setTitle()")}} - : Sets the page action's title. This is displayed in a tooltip over the page action. - {{WebExtAPIRef("pageAction.getTitle()")}} - : Gets the page action's title. - {{WebExtAPIRef("pageAction.setIcon()")}} - : Sets the page action's icon. - {{WebExtAPIRef("pageAction.setPopup()")}} - : Sets the URL for the page action's popup. - {{WebExtAPIRef("pageAction.getPopup()")}} - : Gets the URL for the page action's popup. - {{WebExtAPIRef("pageAction.openPopup()")}} - : Opens the page action's popup. ## Events - {{WebExtAPIRef("pageAction.onClicked")}} - : Fired when a page action icon is clicked. This event will not fire if the page action has a popup. ## Browser compatibility {{Compat}} {{WebExtExamples("h2")}} > **Note:** This API is based on Chromium's [`chrome.pageAction`](https://developer.chrome.com/docs/extensions/reference/pageAction/) API. This documentation is derived from [`page_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/page_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction/getpopup/index.md
--- title: pageAction.getPopup() slug: Mozilla/Add-ons/WebExtensions/API/pageAction/getPopup page-type: webextension-api-function browser-compat: webextensions.api.pageAction.getPopup --- {{AddonSidebar}} Gets the URL for the HTML document set as the popup for this page action. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let gettingPopup = browser.pageAction.getPopup( details // object ) ``` ### Parameters - `details` - : `object`. - `tabId` - : `integer`. ID of the tab whose popup you want to get. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with a string containing the popup's URL. ## Browser compatibility {{Compat}} ## Examples Add a context menu item that logs the popup URL for the current tab. Note that you'll need the `contextMenus` [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) in your [manifest](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json) to create context menu items. ```js function gotPopup(popupURL) { console.log(popupURL); } browser.contextMenus.create({ id: "get-popup", title: "Get popup URL", }); browser.contextMenus.onClicked.addListener((info, tab) => { if (info.menuItemId === "get-popup") { let gettingPopup = browser.pageAction.getPopup({ tabId: tab.id }); gettingPopup.then(gotPopup); } }); ``` {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.pageAction`](https://developer.chrome.com/docs/extensions/reference/pageAction/#method-getPopup) API. This documentation is derived from [`page_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/page_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction/isshown/index.md
--- title: pageAction.isShown() slug: Mozilla/Add-ons/WebExtensions/API/pageAction/isShown page-type: webextension-api-function browser-compat: webextensions.api.pageAction.isShown --- {{AddonSidebar}} Returns `true` if the page action is being shown for the given tab. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let gettingIsShown = browser.pageAction.isShown( details // object ) ``` ### Parameters - `details` - : `object`. An object containing the `tabId` to check. - `tabId` - : `integer`. ID of the tab to check. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with `true` if the extension's page action is being shown for the given tab, and `false` otherwise. ## Browser compatibility {{Compat}} ## Examples Check the state of the currently active tab: ```js async function shownInActiveTab() { let tabs = await browser.tabs.query({ currentWindow: true, active: true, }); let shown = await browser.pageAction.isShown({ tabId: tabs[0].id, }); console.log(shown); } ``` {{WebExtExamples}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction/settitle/index.md
--- title: pageAction.setTitle() slug: Mozilla/Add-ons/WebExtensions/API/pageAction/setTitle page-type: webextension-api-function browser-compat: webextensions.api.pageAction.setTitle --- {{AddonSidebar}} Sets the title of the page action. The title is displayed in a tooltip when the user hovers over the page action. ## Syntax ```js-nolint browser.pageAction.setTitle( details // object ) ``` ### Parameters - `details` - : `object`. - `tabId` - : `integer`. The ID of the tab whose title you want to set. - `title` - : `string` or `null`. The tooltip text. If `null` is passed here, the title is reset to the title that was specified in the [`page_action`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/page_action) manifest key. ## Browser compatibility {{Compat}} ## Examples Whenever a tab is updated, show the page action for that tab, and set its title to show the tab's ID: ```js browser.tabs.onUpdated.addListener((tabId, changeInfo, tabInfo) => { browser.pageAction.show(tabId); browser.pageAction.setTitle({ tabId, title: `Tab ID: ${tabId}`, }); }); ``` {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.pageAction`](https://developer.chrome.com/docs/extensions/reference/pageAction/#method-setTitle) API. This documentation is derived from [`page_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/page_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction/seticon/index.md
--- title: pageAction.setIcon() slug: Mozilla/Add-ons/WebExtensions/API/pageAction/setIcon page-type: webextension-api-function browser-compat: webextensions.api.pageAction.setIcon --- {{AddonSidebar}} Sets the icon for the page action. You can specify a single icon as either the path to an image file or a {{WebExtAPIRef('pageAction.ImageDataType')}} object. You can specify multiple icons in different sizes by supplying a dictionary containing multiple paths or `ImageData` objects. This means the icon doesn't have to be scaled for a device with a different pixel density. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let settingIcon = browser.pageAction.setIcon( details // object ) ``` ### Parameters - `details` - : `object`. An object containing either `imageData` or `path` properties, and a `tabId` property. - `imageData` {{optional_inline}} - : `{{WebExtAPIRef('pageAction.ImageDataType')}}` or `object`. This is either a single `ImageData` object or a dictionary object. Use a dictionary object to specify multiple `ImageData` objects in different sizes, so the icon does not have to be scaled for a device with a different pixel density. If `imageData` is a dictionary, the value of each property is an `ImageData` object, and its name is its size, like this: ```js let settingIcon = browser.action.setIcon({ imageData: { 16: image16, 32: image32, }, }); ``` The browser will choose the image to use depending on the screen's pixel density. See [Choosing icon sizes](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_action#choosing_icon_sizes) for more information on this. - `path` {{optional_inline}} - : `string` or `object`. This is either a relative path to an icon file or a dictionary object. Use a dictionary object to specify multiple icon files in different sizes, so the icon does not have to be scaled for a device with a different pixel density. If `path` is a dictionary, the value of each property is a relative path, and its name is its size, like this: ```js let settingIcon = browser.action.setIcon({ path: { 16: "path/to/image16.jpg", 32: "path/to/image32.jpg", }, }); ``` The browser will choose the image to use depending on the screen's pixel density. See [Choosing icon sizes](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_action#choosing_icon_sizes) for more information on this. If `path` is `null`, this will reset the page action's icon to the icon that was given in the [`page_action`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/page_action) manifest key. If `path` is `""`, this will reset the icon to the browser's global default icon (that is, the icon used if no icon is given in the [`page_action`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/page_action) manifest key). If `path` does not point to a valid icon, then no icon will be displayed. - `tabId` - : `integer`. The ID of the tab whose icon you want to set. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with no arguments once the icon has been set. ## Browser compatibility {{Compat}} ## Examples Set the icon for the page action when the user clicks it: ```js browser.pageAction.onClicked.addListener((tab) => { browser.pageAction.setIcon({ tabId: tab.id, path: "icons/icon-48.png", }); }); ``` {{WebExtExamples}} > **Note:** > > This API is based on Chromium's [`chrome.pageAction`](https://developer.chrome.com/docs/extensions/reference/pageAction/#method-setIcon) API. This documentation is derived from [`page_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/page_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction/onclicked/index.md
--- title: pageAction.onClicked slug: Mozilla/Add-ons/WebExtensions/API/pageAction/onClicked page-type: webextension-api-event browser-compat: webextensions.api.pageAction.onClicked --- {{AddonSidebar}} Fired when a page action icon is clicked. This event will not fire if the page action has a popup. To define a right-click action, use the {{WebExtAPIRef('contextMenus')}} API with the "page_action" {{WebExtAPIRef('contextMenus/ContextType', 'context type', '', 'nocode')}}. ## Syntax ```js-nolint browser.pageAction.onClicked.addListener(listener) browser.pageAction.onClicked.removeListener(listener) browser.pageAction.onClicked.hasListener(listener) ``` Events have three functions: - `addListener(listener)` - : Adds a listener to this event. - `removeListener(listener)` - : Stop listening to this event. The `listener` argument is the listener to remove. - `hasListener(listener)` - : Checks whether a `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise. ## addListener syntax ### Parameters - `listener` - : The function called when this event occurs. The function is passed these arguments: - `tab` - : A {{WebExtAPIRef('tabs.Tab')}} object representing the tab whose page action was clicked. - `OnClickData` - : An object containing information about the click. - `modifiers` - : An `array`. The keyboard modifiers active at the time of the click, being one or more of `Shift`, `Alt`, `Command`, `Ctrl`, or `MacCtrl`. - `button` - : An `integer`. Indicates the button used to click the page action icon: `0` for a left-click or a click not associated with a mouse, such as one from the keyboard and `1` for a middle button or wheel click. Note that the right-click is not supported because Firefox consumes that click to display the context menu before this event is triggered. ## Browser compatibility {{Compat}} ## Examples When the user clicks the page action, hide it, and navigate the active tab to "<https://giphy.com/explore/cat>": ```js let CATGIFS = "https://giphy.com/explore/cat"; browser.pageAction.onClicked.addListener((tab) => { browser.pageAction.hide(tab.id); browser.tabs.update({ url: CATGIFS }); }); browser.pageAction.onClicked.addListener(() => {}); ``` {{WebExtExamples}} > **Note:** > > This API is based on Chromium's [`chrome.pageAction`](https://developer.chrome.com/docs/extensions/reference/pageAction/#event-onClicked) API. This documentation is derived from [`page_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/page_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction/hide/index.md
--- title: pageAction.hide() slug: Mozilla/Add-ons/WebExtensions/API/pageAction/hide page-type: webextension-api-function browser-compat: webextensions.api.pageAction.hide --- {{AddonSidebar}} Hides the page action for a given tab. `hide()` overrides pattern matching, so the page action will not be shown in the specified tab even if its URL is matched by [`show_matches`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/page_action). ## Syntax ```js-nolint browser.pageAction.hide( tabId // integer ) ``` ### Parameters - `tabId` - : `integer`. The ID of the tab for which you want to hide the page action. ## Browser compatibility {{Compat}} ## Examples Hide the page action for the current tab when the user clicks it: ```js browser.pageAction.onClicked.addListener((tab) => { browser.pageAction.hide(tab.id); }); ``` {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.pageAction`](https://developer.chrome.com/docs/extensions/reference/pageAction/#method-hide) API. This documentation is derived from [`page_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/page_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction/gettitle/index.md
--- title: pageAction.getTitle() slug: Mozilla/Add-ons/WebExtensions/API/pageAction/getTitle page-type: webextension-api-function browser-compat: webextensions.api.pageAction.getTitle --- {{AddonSidebar}} Gets the title of the page action. This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Syntax ```js-nolint let gettingTitle = browser.pageAction.getTitle( details // object ) ``` ### Parameters - `details` - : `object`. - `tabId` - : `integer`. The ID of the tab containing the page action whose title you want to get. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with a string containing the page action's title. ## Browser compatibility {{Compat}} ## Examples This example logs the page action's title when the user clicks its icon: ```js function gotTitle(title) { console.log(`Title ${title}`); } browser.pageAction.onClicked.addListener((tab) => { let gettingTitle = browser.pageAction.getTitle({ tabId: tab.id, }); gettingTitle.then(gotTitle); }); ``` {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.pageAction`](https://developer.chrome.com/docs/extensions/reference/pageAction/#method-getTitle) API. This documentation is derived from [`page_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/page_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction/openpopup/index.md
--- title: pageAction.openPopup() slug: Mozilla/Add-ons/WebExtensions/API/pageAction/openPopup page-type: webextension-api-function browser-compat: webextensions.api.pageAction.openPopup --- {{AddonSidebar}} Open the page action's popup. You can only call this function from inside the handler for a [user action](/en-US/docs/Mozilla/Add-ons/WebExtensions/User_actions). ## Syntax ```js-nolint browser.pageAction.openPopup() ``` ### Parameters None. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that is resolved with no arguments. ## Browser compatibility {{Compat}} ## Examples Open the popup when the user selects a context menu item: ```js browser.menus.create({ id: "open-popup", title: "open popup", contexts: ["all"], }); browser.menus.onClicked.addListener(() => { browser.pageAction.openPopup(); }); ``` {{WebExtExamples}}
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction/setpopup/index.md
--- title: pageAction.setPopup() slug: Mozilla/Add-ons/WebExtensions/API/pageAction/setPopup page-type: webextension-api-function browser-compat: webextensions.api.pageAction.setPopup --- {{AddonSidebar}} Sets the HTML document to be opened as a popup when the user clicks on the page action's icon. ## Syntax ```js-nolint browser.pageAction.setPopup( details // object ) ``` ### Parameters - `details` - : `object`. - `tabId` - : `integer`. The ID of the tab for which you want to set the popup. - `popup` - : `string` or `null`. URL to the HTML file to show in a popup. If an empty string (`""`) is passed here, the popup is disabled, and the extension will receive {{WebExtAPIRef("pageAction.onClicked")}} events. If `null` is passed here, the popup is reset to the popup that was specified in the [`page_action`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/page_action) manifest key. ## Browser compatibility {{Compat}} ## Examples Listen for {{WebExtAPIRef("tabs.onUpdated")}} events, and switch the popup if the loading status changes: ```js browser.tabs.onUpdated.addListener((tabId, changeInfo, tabInfo) => { if (changeInfo.status) { browser.pageAction.show(tabId); if (changeInfo.status === "loading") { browser.pageAction.setPopup({ tabId, popup: "/popup/loading.html", }); } else { browser.pageAction.setPopup({ tabId, popup: "/popup/complete.html", }); } } }); ``` {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.pageAction`](https://developer.chrome.com/docs/extensions/reference/pageAction/#method-setPopup) API. This documentation is derived from [`page_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/page_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/pageaction/show/index.md
--- title: pageAction.show() slug: Mozilla/Add-ons/WebExtensions/API/pageAction/show page-type: webextension-api-function browser-compat: webextensions.api.pageAction.show --- {{AddonSidebar}} Shows the {{WebExtAPIRef("pageAction")}} for a given {{WebExtAPIRef("tabs/Tab", "tab")}}. The page action is shown whenever the given tab is the active tab. `show()` overrides pattern matching, so the page action will be shown in the specified tab even if [`show_matches`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/page_action) does not match the URL or [`hide_matches`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/page_action) does. Note that calling `show()` has no effect on a tab with no content loaded. ## Syntax ```js-nolint browser.pageAction.show( tabId // integer ) ``` ### Parameters - `tabId` - : `integer`. The ID of the {{WebExtAPIRef("tabs/Tab", "tab")}} for which you want to show the page action. ### Return value A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with `undefined`. ## Browser compatibility {{Compat}} ## Examples This example shows the {{WebExtAPIRef("pageAction")}} for the active tab when the user selects a context menu item. > **Note:** You'll need the `contextMenus` [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) in your [manifest](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json) to create context menu items. ```js browser.contextMenus.create({ id: "show", title: "Show page action", }); browser.contextMenus.onClicked.addListener((info, tab) => { if (info.menuItemId === "show") { browser.pageAction.show(tab.id); } }); ``` {{WebExtExamples}} > **Note:** This API is based on Chromium's [`chrome.pageAction`](https://developer.chrome.com/docs/extensions/reference/pageAction/#method-show) API. This documentation is derived from [`page_action.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/page_action.json) in the Chromium code. <!-- // Copyright 2015 The Chromium Authors. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
0