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/history | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/history/addurl/index.md | ---
title: history.addUrl()
slug: Mozilla/Add-ons/WebExtensions/API/history/addUrl
page-type: webextension-api-function
browser-compat: webextensions.api.history.addUrl
---
{{AddonSidebar}}
Adds a record to the browser's history of a visit to the given URL. The visit's time is recorded as the time of the call, and the {{WebExtAPIRef("history.TransitionType", "TransitionType")}} is recorded as "link".
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let addingUrl = browser.history.addUrl(
details // object
)
```
### Parameters
- `details`
- : `object`. Object containing the URL to add.
- `url`
- : `string`. The URL to add.
- `title` {{optional_inline}}
- : string: The title of the page. If this is not supplied, the title will be recorded as `null`.
- `transition` {{optional_inline}}
- : {{WebExtAPIRef("history.TransitionType")}}. Describes how the browser navigated to the page on this occasion. If this is not supplied, a transition type of "link" will be recorded.
- `visitTime` {{optional_inline}}
- : `number` or `string` or `object`. A value indicating a date and time. This can be represented as: a [`Date`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) object, an [ISO 8601 date string](https://www.iso.org/iso-8601-date-and-time-format.html), or the number of milliseconds since the epoch. Sets the visit time to this value. If this is not supplied, the current time will be recorded.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) will be fulfilled with no parameters when the item has been added.
## Browser compatibility
{{Compat}}
## Examples
Add a record of a visit to "https\://example.org/", then check that the new visit was recorded by searching history for the most recent item and logging it:
```js
function onGot(results) {
if (results.length) {
console.log(results[0].url);
console.log(new Date(results[0].lastVisitTime));
}
}
browser.history
.addUrl({ url: "https://example.org/" })
.then(() =>
browser.history.search({
text: "https://example.org/",
startTime: 0,
maxResults: 1,
}),
)
.then(onGot);
```
Add a record of a visit to "https\://example.org", but give it a `visitTime` 24 hours in the past, and a `transition` of "typed":
```js
const DAY = 24 * 60 * 60 * 1000;
function oneDayAgo() {
return Date.now() - DAY;
}
function onGot(visits) {
for (const visit of visits) {
console.log(new Date(visit.visitTime));
console.log(visit.transition);
}
}
browser.history
.addUrl({
url: "https://example.org/",
visitTime: oneDayAgo(),
transition: "typed",
})
.then(() =>
browser.history.getVisits({
url: "https://example.org/",
}),
)
.then(onGot);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.history`](https://developer.chrome.com/docs/extensions/reference/history/#method-addUrl) API. This documentation is derived from [`history.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/history.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/history | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/history/transitiontype/index.md | ---
title: history.TransitionType
slug: Mozilla/Add-ons/WebExtensions/API/history/TransitionType
page-type: webextension-api-type
browser-compat: webextensions.api.history.TransitionType
---
{{AddonSidebar}}
This describes how the browser navigated to a particular page. For example, "link" means that the browser navigated to the page because the user clicked a link.
## Type
Values of this type are strings. Possible values are:
- "link"
- : The user clicked a link in another page.
- "typed"
- : The user typed the URL into the address bar. This is also used if the user started typing into the address bar, then selected a URL from the suggestions it offered. See also "generated".
- "auto_bookmark"
- : The user clicked a bookmark or an item in the browser history.
- "auto_subframe"
- : Any nested iframes that are automatically loaded by their parent.
- "manual_subframe"
- : Any nested iframes that are loaded as an explicit user action. Loading such an iframe will generate an entry in the back/forward navigation list.
- "generated"
- : The user started typing in the address bar, then clicked on a suggested entry that didn't contain a URL.
- "auto_toplevel"
- : The page was passed to the command line or is the start page.
- "form_submit"
- : The user submitted a form. Note that in some situations, such as when a form uses a script to submit its contents, submitting a form does not result in this transition type.
- "reload"
- : The user reloaded the page, using the Reload button or by pressing Enter in the address bar. This is also used for session restore and reopening closed tabs.
- "keyword"
- : The URL was generated using a [keyword search](https://support.mozilla.org/en-US/kb/how-search-from-address-bar) configured by the user.
- "keyword_generated"
- : Corresponds to a visit generated for a keyword.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.history`](https://developer.chrome.com/docs/extensions/reference/history/#type-TransitionType) API. This documentation is derived from [`history.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/history.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/history | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/history/deleteurl/index.md | ---
title: history.deleteUrl()
slug: Mozilla/Add-ons/WebExtensions/API/history/deleteUrl
page-type: webextension-api-function
browser-compat: webextensions.api.history.deleteUrl
---
{{AddonSidebar}}
Removes all visits to the given URL from the browser history.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let deletingUrl = browser.history.deleteUrl(
details // object
)
```
### Parameters
- `details`
- : `object`. Object containing the URL whose visits to remove.
- `url`
- : `string`. The URL whose visits should be removed.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) will be fulfilled with no parameters when the visits have been removed.
## Browser compatibility
{{Compat}}
## Examples
Remove all visits to "https\://example.org/" from history, then check that this URL no longer returned from {{WebExtAPIRef("history.search()")}}:
```js
let urlToRemove = "https://example.org/";
function onGot(results) {
if (!results.length) {
console.log(`${urlToRemove} was removed`);
} else {
console.log(`${urlToRemove} was not removed`);
}
}
function onRemoved() {
let searching = browser.history.search({
text: urlToRemove,
startTime: 0,
});
searching.then(onGot);
}
let deletingUrl = browser.history.deleteUrl({ url: urlToRemove });
deletingUrl.then(onRemoved);
```
Remove the last-visited page from history, with a listener to {{WebExtAPIRef("history.onVisitRemoved")}} to log the URL of the removed page:
```js
function onRemoved(removeInfo) {
if (removeInfo.urls.length) {
console.log(`Removed: ${removeInfo.urls[0]}`);
}
}
browser.history.onVisitRemoved.addListener(onRemoved);
function onGot(results) {
if (results.length) {
console.log(`Removing: ${results[0].url}`);
browser.history.deleteUrl({ url: results[0].url });
}
}
let searching = browser.history.search({
text: "",
startTime: 0,
maxResults: 1,
});
searching.then(onGot);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.history`](https://developer.chrome.com/docs/extensions/reference/history/#method-deleteUrl) API. This documentation is derived from [`history.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/history.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/scripting/index.md | ---
title: scripting
slug: Mozilla/Add-ons/WebExtensions/API/scripting
page-type: webextension-api
browser-compat: webextensions.api.scripting
---
{{AddonSidebar}}
Inserts JavaScript and CSS into websites. This API offers two approaches to inserting content:
- {{WebExtAPIRef("scripting.executeScript()")}}, {{WebExtAPIRef("scripting.insertCSS()")}}, and {{WebExtAPIRef("scripting.removeCSS()")}} that provide for one-off injections.
- {{WebExtAPIRef("scripting.registerContentScripts()")}} that registers content scripts dynamically, which can then be retrieved with {{WebExtAPIRef("scripting.getRegisteredContentScripts()")}} and unregistered with {{WebExtAPIRef("scripting.unregisterContentScripts()")}}).
> **Note:** Chrome restricts this API to Manifest V3. Firefox and Safari support this API in Manifest V2 and V3.
This API requires the `"scripting"` [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) and [host permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#host_permissions) for the target in the tab into which JavaScript or CSS is injected.
Alternatively, you can get permission temporarily in the active tab and only in response to an explicit user action, by asking for the [`"activeTab"` permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#activetab_permission). However, the `"scripting"` permission is still required.
## Types
- {{WebExtAPIRef("scripting.ContentScriptFilter")}}
- : Specifies the IDs of scripts to retrieve with {{WebExtAPIRef("scripting.getRegisteredContentScripts()")}} or to unregister with {{WebExtAPIRef("scripting.unregisterContentScripts()")}}.
- {{WebExtAPIRef("scripting.ExecutionWorld")}}
- : Specifies the execution environment of a script injected with {{WebExtAPIRef("scripting.executeScript()")}} or registered with {{WebExtAPIRef("scripting.registerContentScripts()")}}.
- {{WebExtAPIRef("scripting.InjectionTarget")}}
- : Details of an injection target.
- {{WebExtAPIRef("scripting.RegisteredContentScript")}}
- : Details of a content script to be registered or that is registered.
## Functions
- {{WebExtAPIRef("scripting.executeScript()")}}
- : Injects JavaScript code into a page.
- {{WebExtAPIRef("scripting.getRegisteredContentScripts()")}}
- : Gets a list of registered content scripts.
- {{WebExtAPIRef("scripting.insertCSS()")}}
- : Injects CSS into a page.
- {{WebExtAPIRef("scripting.registerContentScripts()")}}
- : Registers a content script for future page loads.
- {{WebExtAPIRef("scripting.removeCSS()")}}
- : Removes CSS which was previously injected into a page by a {{WebExtAPIRef("scripting.insertCSS()")}} call.
- {{WebExtAPIRef("scripting.updateContentScripts()")}}
- : Updates one or more content scripts already registered.
- {{WebExtAPIRef("scripting.unregisterContentScripts()")}}
- : Unregisters one or more content scripts.
## Browser compatibility
{{Compat}}
{{WebExtExamples("h2")}}
> **Note:** This API is based on Chromium's [`chrome.scripting`](https://developer.chrome.com/docs/extensions/reference/scripting/) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting/registeredcontentscript/index.md | ---
title: scripting.RegisteredContentScript
slug: Mozilla/Add-ons/WebExtensions/API/scripting/RegisteredContentScript
page-type: webextension-api-type
browser-compat: webextensions.api.scripting.RegisteredContentScript
---
{{AddonSidebar}}
This object contains details of a script to be registered or that is registered.
## Type
Values of this type are objects. They contain these properties:
- `allFrames` {{optional_inline}}
- : `boolean`. If specified `true`, the script is inject into all frames, even if the frame is not the top-most frame in the tab. Each frame is checked independently for URL requirements; it does not inject into child frames if the URL requirements are not met. Defaults to `false`, meaning that only the top frame is matched.
- `css` {{optional_inline}}
- : `array` of `string`. The list of CSS files to be injected into matching pages. These are injected in the order they appear in this array.
- `excludeMatches` {{optional_inline}}
- : `array` of `string`. Array of pages that this content script is excluded from but would otherwise be injected into.
- `id`
- : `string`. The ID of the content script, specified in the API call.
- `js` {{optional_inline}}
- : `array` of `string`. Array of path to JavaScript files in the extension package to inject into matching pages. Scripts are injected in the order they appear in this array.
- `matches` {{optional_inline}}
- : `array` of `string`. Array of the pages this content script is injected into. Must be specified for {{WebExtAPIRef("scripting.registerContentScripts()")}}.
- `persistAcrossSessions` {{optional_inline}}
- : `boolean`. Specifies if this content script persists across browser restarts and updates and extension restarts. Defaults to `true`.
- `runAt` {{optional_inline}}
- : {{WebExtAPIRef("extensionTypes.RunAt")}}. Specifies when JavaScript files are injected into the web page. The default value is `document_idle`. In Firefox, `runAt` also affects the point where the CSS is inserted. In Chrome, `runAt` does not affect the CSS insertion point.
- `world` {{optional_inline}}
- : {{WebExtAPIRef("scripting.ExecutionWorld")}}. The execution environment for a script to execute in. The default value is `ISOLATED`.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.scripting`](https://developer.chrome.com/docs/extensions/reference/scripting/#type-RegisteredContentScript) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting/contentscriptfilter/index.md | ---
title: scripting.ContentScriptFilter
slug: Mozilla/Add-ons/WebExtensions/API/scripting/ContentScriptFilter
page-type: webextension-api-type
browser-compat: webextensions.api.scripting.ContentScriptFilter
---
{{AddonSidebar}}
This object contains a list of IDs of scripts to retrieve with {{WebExtAPIRef("scripting.getRegisteredContentScripts()")}} or to unregister with {{WebExtAPIRef("scripting.unregisterContentScripts()")}}.
## Type
Values of this type are objects. They contain these properties:
- `ids`
- : `array` of `string`. Array of scripts IDs.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.scripting`](https://developer.chrome.com/docs/extensions/reference/scripting/#type-ContentScriptFilter) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting/unregistercontentscripts/index.md | ---
title: scripting.unregisterContentScripts()
slug: Mozilla/Add-ons/WebExtensions/API/scripting/unregisterContentScripts
page-type: webextension-api-function
browser-compat: webextensions.api.scripting.unregisterContentScripts
---
{{AddonSidebar}}
Unregisters one or more content scripts.
> **Note:** This method is available in Manifest V3 or higher in Chrome and Firefox 101. In Firefox 102+, this method is also available in Manifest V2.
To use this API you must have the `"scripting"` [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) and permission for the page's URL, either explicitly as a [host permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#host_permissions) or using the [activeTab permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#activetab_permission).
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
await browser.scripting.unregisterContentScripts(
scripts // object
)
```
### Parameters
- `scripts` {{optional_inline}}
- : {{WebExtAPIRef("scripting.ContentScriptFilter")}}. A filter to identify the dynamic content scripts to unregistered. If not specified, all dynamic content scripts are unregistered.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that fulfills with no arguments when all the scripts are unregistered. If any error occurs, the promise is rejected.
## Examples
This example unregisters a registered content script with ID `a-script`:
```js
try {
await browser.scripting.unregisterContentScripts({
ids: ["a-script"],
});
} catch (err) {
console.error(`failed to unregister content scripts: ${err}`);
}
```
{{WebExtExamples}}
## Browser compatibility
{{Compat}}
> **Note:** This API is based on Chromium's [`chrome.scripting`](https://developer.chrome.com/docs/extensions/reference/scripting/#method-unregisterContentScripts) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting/getregisteredcontentscripts/index.md | ---
title: scripting.getRegisteredContentScripts()
slug: Mozilla/Add-ons/WebExtensions/API/scripting/getRegisteredContentScripts
page-type: webextension-api-function
browser-compat: webextensions.api.scripting.getRegisteredContentScripts
---
{{AddonSidebar}}
Returns all the content scripts registered with {{WebExtAPIRef("scripting.registerContentScripts()")}} or a subset of the registered scripts when using a filter.
> **Note:** This method is available in Manifest V3 or higher in Chrome and Firefox 101. In Firefox 102+, this method is also available in Manifest V2.
To use this API you must have the `"scripting"` [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) and permission for the page's URL, either explicitly as a [host permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#host_permissions) or using the [activeTab permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#activetab_permission).
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let scripts = await browser.scripting.getRegisteredContentScripts(
filter // object
)
```
### Parameters
- `filter` {{optional_inline}}
- : {{WebExtAPIRef("scripting.ContentScriptFilter")}}. A filter for the registered script details to return.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that fulfills with an array of {{WebExtAPIRef("scripting.RegisteredContentScript")}}. If any error occurs, the promise is rejected.
## Examples
This example returns all the registered content scripts:
```js
// Register two content scripts.
await browser.scripting.registerContentScripts([
{
id: "script-1",
js: ["script-1.js"],
matches: ["*://example.com/*"],
},
{
id: "script-2",
js: ["script-2.js"],
matches: ["*://example.com/*"],
},
]);
// Retrieve all content scripts.
let scripts = await browser.scripting.getRegisteredContentScripts();
console.log(scripts.map((script) => script.id)); // ["script-1", "script-2"]
// Only retrieve the second script.
scripts = await browser.scripting.getRegisteredContentScripts({
ids: ["script-2"],
});
console.log(scripts.map((script) => script.id)); // ["script-2"]
```
{{WebExtExamples}}
## Browser compatibility
{{Compat}}
> **Note:** This API is based on Chromium's [`chrome.scripting`](https://developer.chrome.com/docs/extensions/reference/scripting/#method-getRegisteredContentScripts) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting/registercontentscripts/index.md | ---
title: scripting.registerContentScripts()
slug: Mozilla/Add-ons/WebExtensions/API/scripting/registerContentScripts
page-type: webextension-api-function
browser-compat: webextensions.api.scripting.registerContentScripts
---
{{AddonSidebar}}
Registers one or more content scripts.
> **Note:** This method is available in Manifest V3 or higher in Chrome and Firefox 101. In Firefox 102+, this method is also available in Manifest V2.
To use this API you must have the `"scripting"` [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) and permission for the page's URL, either explicitly as a [host permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#host_permissions) or using the [activeTab permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#activetab_permission).
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
await browser.scripting.registerContentScripts(
scripts // array
)
```
### Parameters
- `scripts`
- : `array` of {{WebExtAPIRef("scripting.RegisteredContentScript")}}. A list of scripts to register.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that fulfills with an array of {{WebExtAPIRef("scripting.RegisteredContentScript")}}. If there are errors during script parsing and file validation, or if the IDs specified do not exist, no scripts are registered and the promise is rejected.
## Examples
This example registers a content script that injects the file `"script.js"`:
```js
const aScript = {
id: "a-script",
js: ["script.js"],
matches: ["https://example.com/*"],
};
try {
await browser.scripting.registerContentScripts([aScript]);
} catch (err) {
console.error(`failed to register content scripts: ${err}`);
}
```
{{WebExtExamples}}
## Browser compatibility
{{Compat}}
> **Note:** This API is based on Chromium's [`chrome.scripting`](https://developer.chrome.com/docs/extensions/reference/scripting/#method-registerContentScripts) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting/executescript/index.md | ---
title: scripting.executeScript()
slug: Mozilla/Add-ons/WebExtensions/API/scripting/executeScript
page-type: webextension-api-function
browser-compat: webextensions.api.scripting.executeScript
---
{{AddonSidebar}}
Injects a script into a target context. The script is run at `document_idle` by default.
> **Note:** This method is available in Manifest V3 or higher in Chrome and Firefox 101. In Safari and Firefox 102+, this method is also available in Manifest V2.
To use this API you must have the `"scripting"` [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) and permission for the target's URL, either explicitly as a [host permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#host_permissions) or using the [activeTab permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#activetab_permission). Note that some special pages do not allow this permission, including reader view, view-source, and PDF viewer pages.
In Firefox and Safari, partial lack of host permissions can result in a successful execution (with the partial results in the resolved promise). In Chrome, any missing permission prevents any execution from happening (see [Issue 1325114](https://crbug.com/1325114)).
The scripts you inject are called [content scripts](/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts).
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let results = await browser.scripting.executeScript(
details // object
)
```
### Parameters
- `details`
- : An object describing the script to inject. It contains these properties:
- `args` {{optional_inline}}
- : An array of arguments to carry into the function. This is only valid if the `func` parameter is specified. The arguments must be JSON-serializable.
- `files` {{optional_inline}}
- : `array` of `string`. An array of path of the JS files to inject, relative to the extension's root directory. Exactly one of `files` and `func` must be specified.
- `func` {{optional_inline}}
- : `function`. A JavaScript function to inject. This function is serialized and then deserialized for injection. This means that any bound parameters and execution context are lost. Exactly one of `files` and `func` must be specified.
- `injectImmediately` {{optional_inline}}
- : `boolean`. Whether the injection into the target is triggered as soon as possible, but not necessarily prior to page load.
- `target`
- : {{WebExtAPIRef("scripting.InjectionTarget")}}. Details specifying the target to inject the script into.
- `world` {{optional_inline}}
- : {{WebExtAPIRef("scripting.ExecutionWorld")}}. The execution environment for a script to execute in.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that fulfills with an array of `InjectionResult` objects, which represent the result of the injected script in every injected frame.
The promise is rejected if the injection fails, such as when the injection target is invalid. When script execution has started, its result is included in the result, whether successful (as `result`) or unsuccessfully (as `error`).
Each `InjectionResult` object has these properties:
- `frameId`
- : `number`. The frame ID associated with the injection.
- `result` {{optional_inline}}
- : `any`. The result of the script execution.
- `error` {{optional_inline}}
- : `any`. If an error occurs, contains the value the script threw or rejected with. Typically this is an error object with a message property but it could be any value (including primitives and undefined).
Chrome does not support the `error` property yet (see [Issue 1271527: Propagate errors from scripting.executeScript to InjectionResult](https://crbug.com/1271527)). As an alternative, runtime errors can be caught by wrapping the code to execute in a try-catch statement. Uncaught errors are also reported to the console of the target tab.
The result of the script is the last evaluated statement, which is similar to the results seen if you executed the script in the [Web Console](https://firefox-source-docs.mozilla.org/devtools-user/web_console/index.html) (not any `console.log()` output). For example, consider a script like this:
```js
let foo = "my result";
foo;
```
Here the results array contains the string "`my result`" as an element.
The script result must be a [structured cloneable](/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) value in Firefox or a [JSON-serializable](/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description) value in Chrome. The [Chrome incompatibilities](/en-US/docs/Mozilla/Add-ons/WebExtensions/Chrome_incompatibilities) article discusses this difference in more detail in the [Data cloning algorithm](/en-US/docs/Mozilla/Add-ons/WebExtensions/Chrome_incompatibilities#data_cloning_algorithm) section.
## Examples
This example executes a one-line code snippet in the active tab:
```js
browser.action.onClicked.addListener(async (tab) => {
try {
await browser.scripting.executeScript({
target: {
tabId: tab.id,
},
func: () => {
document.body.style.border = "5px solid green";
},
});
} catch (err) {
console.error(`failed to execute script: ${err}`);
}
});
```
This example executes a script from a file (packaged with the extension) called `"content-script.js"`. The script is executed in the active tab. The script is executed in subframes and the main document:
```js
browser.action.onClicked.addListener(async (tab) => {
try {
await browser.scripting.executeScript({
target: {
tabId: tab.id,
allFrames: true,
},
files: ["content-script.js"],
});
} catch (err) {
console.error(`failed to execute script: ${err}`);
}
});
```
{{WebExtExamples}}
## Browser compatibility
{{Compat}}
> **Note:** This API is based on Chromium's [`chrome.scripting`](https://developer.chrome.com/docs/extensions/reference/scripting/#method-executeScript) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting/insertcss/index.md | ---
title: scripting.insertCSS()
slug: Mozilla/Add-ons/WebExtensions/API/scripting/insertCSS
page-type: webextension-api-function
browser-compat: webextensions.api.scripting.insertCSS
---
{{AddonSidebar}}
Injects CSS into a page.
> **Note:** This method is available in Manifest V3 or higher in Chrome and Firefox 101. In Safari and Firefox 102+, this method is also available in Manifest V2.
To use this API, you must have the `"scripting"` [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) and permission for the target's URL, either explicitly as a [host permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#host_permissions) or using the [activeTab permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#activetab_permission).
You can only inject CSS into pages whose URL can be expressed using a [match pattern](/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns): meaning its scheme must be one of "http", "https", or "file". This means you can't inject CSS into any of the browser's built-in pages, such as about:debugging, about:addons, or the page that opens when you open a new empty tab.
> **Note:** Firefox resolves URLs in injected CSS files relative to the CSS file rather than the page it's injected into.
The inserted CSS can be removed by calling {{WebExtAPIRef("scripting.removeCSS()")}}.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
await browser.scripting.insertCSS(
details // object
)
```
### Parameters
- `details`
- : An object describing the CSS to insert and where to insert it. It contains the following properties:
- `css` {{optional_inline}}
- : `string`. A string containing the CSS to inject. Either `css` or `files` must be specified.
- `files` {{optional_inline}}
- : `array` of `string`. The path of CSS files to inject relative to the extension's root directory. Either `files` or `css` must be specified.
- `origin` {{optional_inline}}
- : `string`. The style origin for the injection, either `USER`, to add the CSS as a user stylesheet, or `AUTHOR`, to add it as an author stylesheet. Defaults to `AUTHOR`.
- `USER` enables you to prevent websites from overriding the CSS you insert: see [Cascading order](/en-US/docs/Web/CSS/Cascade#cascading_order).
- `AUTHOR` stylesheets behave as if they appear after all author rules specified by the web page. This behavior includes any author stylesheets added dynamically by the page's scripts, even if that addition happens after the `insertCSS` call completes.
- `target`
- : {{WebExtAPIRef("scripting.InjectionTarget")}}. Details specifying the target to inject the CSS into.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that fulfills with no arguments when all the CSS is inserted. If any error occurs, the promise is rejected.
## Examples
This example inserts CSS taken from a string into the active tab.
```js
browser.action.onClicked.addListener(async (tab) => {
try {
await browser.scripting.insertCSS({
target: {
tabId: tab.id,
},
css: `body { border: 20px dotted pink; }`,
});
} catch (err) {
console.error(`failed to insert CSS: ${err}`);
}
});
```
This example inserts CSS loaded from a file (packaged with the extension) called `"content-style.css"`:
```js
browser.action.onClicked.addListener(async (tab) => {
try {
await browser.scripting.insertCSS({
target: {
tabId: tab.id,
},
files: ["content-style.css"],
});
} catch (err) {
console.error(`failed to insert CSS: ${err}`);
}
});
```
{{WebExtExamples}}
## Browser compatibility
{{Compat}}
> **Note:** This API is based on Chromium's [`chrome.scripting`](https://developer.chrome.com/docs/extensions/reference/scripting/#method-insertCSS) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting/updatecontentscripts/index.md | ---
title: scripting.updateContentScripts()
slug: Mozilla/Add-ons/WebExtensions/API/scripting/updateContentScripts
page-type: webextension-api-function
browser-compat: webextensions.api.scripting.updateContentScripts
---
{{AddonSidebar}}
Updates registered content scripts. If there are errors during script parsing and file validation, or if the IDs specified do not exist, no scripts are updated.
> **Note:** This method is available in Manifest V3 or higher in Chrome and Firefox 101. In Firefox 102+, this method is also available in Manifest V2.
To use this API you must have the `"scripting"` [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) and permission for the page's URL, either explicitly as a [host permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#host_permissions) or using the [activeTab permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#activetab_permission).
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
### Syntax
```js-nolint
await browser.scripting.updateContentScripts(
scripts // object
)
```
### Parameters
- `scripts`
- : `array` of {{WebExtAPIRef("scripting.RegisteredContentScript")}}. Details of a script to update. All the properties are optional except for `id`.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that fulfills with an array of {{WebExtAPIRef("scripting.RegisteredContentScript")}}. If any error occurs, the promise is rejected.
## Examples
This example updates a content script registered with ID `a-script` by setting `allFrames` to `true`:
```js
try {
await browser.scripting.registerContentScripts([
{
id: "a-script",
js: ["script.js"],
matches: ["*://example.org/*"],
},
]);
// Update content script registered before to allow execution
// in all frames:
await browser.scripting.updateContentScripts([
{
id: "a-script",
allFrames: true,
},
]);
} catch (err) {
console.error(`failed to register or update content scripts: ${err}`);
}
```
{{WebExtExamples}}
## Browser compatibility
{{Compat}}
> **Note:** This API is based on Chromium's [`chrome.scripting`](https://developer.chrome.com/docs/extensions/reference/scripting/#method-updateContentScripts) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting/removecss/index.md | ---
title: scripting.removeCSS()
slug: Mozilla/Add-ons/WebExtensions/API/scripting/removeCSS
page-type: webextension-api-function
browser-compat: webextensions.api.scripting.removeCSS
---
{{AddonSidebar}}
Removes a CSS stylesheet injected by a call to {{WebExtAPIRef("scripting.insertCSS()")}}.
> **Note:** This method is available in Manifest V3 or higher in Chrome and Firefox 101. In Safari and Firefox 102+, this method is also available in Manifest V2.
To use this API you must have the `"scripting"` [permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) and permission for the page's URL, either explicitly as a [host permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#host_permissions) or using the [activeTab permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#activetab_permission).
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
await browser.scripting.removeCSS(
details // object
)
```
### Parameters
- `details`
- : An object describing the CSS to remove and where to remove it from. It contains the following properties:
- `css` {{optional_inline}}
- : `string`. A string containing the CSS to inject. Either `css` or `files` must be specified and must match the stylesheet inserted through {{WebExtAPIRef("scripting.insertCSS()")}}.
- `files` {{optional_inline}}
- : `array` of `string`. The path of a CSS files to inject, relative to the extension's root directory. Either `files` or `css` must be specified and must match the stylesheet inserted through {{WebExtAPIRef("scripting.insertCSS()")}}.
- `origin` {{optional_inline}}
- : `string`. The style origin for the injection, either `USER` or `AUTHOR`. Defaults to `AUTHOR`. Must match the origin of the stylesheet inserted through {{WebExtAPIRef("scripting.insertCSS()")}}.
- `target`
- : {{WebExtAPIRef("scripting.InjectionTarget")}}. Details specifying the target to remove the CSS from.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that fulfills with no arguments when all the CSS is removed. If any error occurs, the promise is rejected. Attempts to remove non-existent stylesheets are ignored.
## Examples
This example adds some CSS using {{WebExtAPIRef("scripting.insertCSS")}}, then removes it again when the user clicks a browser action:
```js
// Assuming some style has been injected previously with the following code:
//
// await browser.scripting.insertCSS({
// target: {
// tabId: tab.id,
// },
// css: "* { background: #c0ffee }",
// });
//
// We can remove it when a user clicked an extension button like this:
browser.action.onClicked.addListener(async (tab) => {
try {
await browser.scripting.removeCSS({
target: {
tabId: tab.id,
},
css: "* { background: #c0ffee }",
});
} catch (err) {
console.error(`failed to remove CSS: ${err}`);
}
});
```
{{WebExtExamples}}
## Browser compatibility
{{Compat}}
> **Note:** This API is based on Chromium's [`chrome.scripting`](https://developer.chrome.com/docs/extensions/reference/scripting/#method-removeCSS) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting/injectiontarget/index.md | ---
title: scripting.InjectionTarget
slug: Mozilla/Add-ons/WebExtensions/API/scripting/InjectionTarget
page-type: webextension-api-type
browser-compat: webextensions.api.scripting.InjectionTarget
---
{{AddonSidebar}}
This object contains details specifying the injection target for CSS and JavaScript. Its used in {{WebExtAPIRef("scripting.executeScript()")}}, {{WebExtAPIRef("scripting.insertCSS()")}}, and {{WebExtAPIRef("scripting.removeCSS()")}}.
## Type
Values of this type are objects. They contain these properties:
- `allFrames` {{optional_inline}}
- : `boolean`. Whether the script or CSS is injected into all frames within the tab. Defaults to `false`. Cannot be `true` if `frameIds` is specified.
- `frameIds` {{optional_inline}}
- : `array` of `number`. Array of the IDs of the frames to inject into.
- `tabId`
- : `number`. The ID of the tab to inject into.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.scripting`](https://developer.chrome.com/docs/extensions/reference/scripting/#type-InjectionTarget) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/scripting/executionworld/index.md | ---
title: scripting.ExecutionWorld
slug: Mozilla/Add-ons/WebExtensions/API/scripting/ExecutionWorld
page-type: webextension-api-type
browser-compat: webextensions.api.scripting.ExecutionWorld
---
{{AddonSidebar}}
Specifies the execution environment of a script injected with {{WebExtAPIRef("scripting.executeScript()")}}
or registered with {{WebExtAPIRef("scripting.registerContentScripts()")}}.
## Type
Values of this type are strings. Possible values are:
- `ISOLATED`
The default execution environment of [content scripts](/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts).
This environment is isolated from the page's context: while they share the same document, the global scopes and available APIs differ.
- `MAIN`
The execution environment of the web page. This environment is shared with the web page, without isolation.
Scripts in this environment do not have any access to APIs that are only available to content scripts.
> **Warning:** Due to the lack of isolation, the web page can detect the executed code and interfere with it.
> Do not use the `MAIN` world unless it is acceptable for web pages to read, access, or modify the logic or data that flows through the executed code.
> `MAIN` is not supported in Firefox (although it is planned and the work to introduce it is tracked by [Bug 1736575](https://bugzil.la/1736575)). In the meantime, JavaScript code running in the isolated content script sandbox can use the Firefox "Xray vision" feature, as described in [Share objects with page scripts](/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts).
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.scripting`](https://developer.chrome.com/docs/extensions/reference/scripting/#type-ExecutionWorld) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/index.md | ---
title: downloads
slug: Mozilla/Add-ons/WebExtensions/API/downloads
page-type: webextension-api
browser-compat: webextensions.api.downloads
---
{{AddonSidebar}}
Enables extensions to interact with the browser's download manager. You can use this API module to download files, cancel, pause, resume downloads, and show downloaded files in the file manager.
To use this API you need to have the "downloads" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#api_permissions) specified in your [manifest.json](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json) file.
## Types
- {{WebExtAPIRef("downloads.FilenameConflictAction")}}
- : Defines options for what to do if the name of a downloaded file conflicts with an existing file.
- {{WebExtAPIRef("downloads.InterruptReason")}}
- : Defines a set of possible reasons why a download was interrupted.
- {{WebExtAPIRef("downloads.DangerType")}}
- : Defines a set of common warnings of possible dangers associated with downloadable files.
- {{WebExtAPIRef("downloads.State")}}
- : Defines different states that a current download can be in.
- {{WebExtAPIRef("downloads.DownloadItem")}}
- : Represents a downloaded file.
- {{WebExtAPIRef("downloads.StringDelta")}}
- : Represents the difference between two strings.
- {{WebExtAPIRef("downloads.DoubleDelta")}}
- : Represents the difference between two doubles.
- {{WebExtAPIRef("downloads.BooleanDelta")}}
- : Represents the difference between two booleans.
- {{WebExtAPIRef("downloads.DownloadTime")}}
- : Represents the time a download took to complete.
- {{WebExtAPIRef("downloads.DownloadQuery")}}
- : Defines a set of parameters that can be used to search the downloads manager for a specific set of downloads.
## Functions
- {{WebExtAPIRef("downloads.download()")}}
- : Downloads a file, given its URL and other optional preferences.
- {{WebExtAPIRef("downloads.search()")}}
- : Queries the {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} available in the browser's downloads manager, and returns those that match the specified search criteria.
- {{WebExtAPIRef("downloads.pause()")}}
- : Pauses a download.
- {{WebExtAPIRef("downloads.resume()")}}
- : Resumes a paused download.
- {{WebExtAPIRef("downloads.cancel()")}}
- : Cancels a download.
- {{WebExtAPIRef("downloads.getFileIcon()")}}
- : Retrieves an icon for the specified download.
- {{WebExtAPIRef("downloads.open()")}}
- : Opens the downloaded file with its associated application.
- {{WebExtAPIRef("downloads.show()")}}
- : Opens the platform's file manager application to show the downloaded file in its containing folder.
- {{WebExtAPIRef("downloads.showDefaultFolder()")}}
- : Opens the platform's file manager application to show the default downloads folder.
- {{WebExtAPIRef("downloads.erase()")}}
- : Erases matching {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} from the browser's download history, without deleting the downloaded files from disk.
- {{WebExtAPIRef("downloads.removeFile()")}}
- : Removes a downloaded file from disk, but not from the browser's download history.
- {{WebExtAPIRef("downloads.acceptDanger()")}}
- : Prompts the user to accept or cancel a dangerous download.
- {{WebExtAPIRef("downloads.setShelfEnabled()")}}
- : Enables or disables the gray shelf at the bottom of every window associated with the current browser profile. The shelf will be disabled as long as at least one extension has disabled it.
## Events
- {{WebExtAPIRef("downloads.onCreated")}}
- : Fires with the {{WebExtAPIRef("downloads.DownloadItem", "DownloadItem")}} object when a download begins.
- {{WebExtAPIRef("downloads.onErased")}}
- : Fires with the `downloadId` when a download is erased from history.
- {{WebExtAPIRef("downloads.onChanged")}}
- : When any of a {{WebExtAPIRef("downloads.DownloadItem", "DownloadItem")}}'s properties except `bytesReceived` changes, this event fires with the `downloadId` and an object containing the properties that changed.
## Browser compatibility
{{Compat}}
{{WebExtExamples("h2")}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/interruptreason/index.md | ---
title: downloads.InterruptReason
slug: Mozilla/Add-ons/WebExtensions/API/downloads/InterruptReason
page-type: webextension-api-type
browser-compat: webextensions.api.downloads.InterruptReason
---
{{AddonSidebar}}
The `InterruptReason` type of the {{WebExtAPIRef("downloads")}} API defines a set of possible reasons why a download was interrupted.
A {{WebExtAPIRef('downloads.DownloadItem')}}'s `error` property will contain a string taken from the values defined in this type.
## Type
Values of this type are strings. Possible values are split into categories, with each set having the same substring at the beginning:
File-related errors:
- `"FILE_FAILED"`
- `"FILE_ACCESS_DENIED"`
- `"FILE_NO_SPACE"`
- `"FILE_NAME_TOO_LONG"`
- `"FILE_TOO_LARGE"`
- `"FILE_VIRUS_INFECTED"`
- `"FILE_TRANSIENT_ERROR"`
- `"FILE_BLOCKED"`
- `"FILE_SECURITY_CHECK_FAILED"`
- `"FILE_TOO_SHORT"`
Network-related errors:
- `"NETWORK_FAILED"`
- `"NETWORK_TIMEOUT"`
- `"NETWORK_DISCONNECTED"`
- `"NETWORK_SERVER_DOWN"`
- `"NETWORK_INVALID_REQUEST"`
Server-related errors:
- `"SERVER_FAILED"`
- `"SERVER_NO_RANGE"`
- `"SERVER_BAD_CONTENT"`
- `"SERVER_UNAUTHORIZED"`
- `"SERVER_CERT_PROBLEM"`
- `"SERVER_FORBIDDEN"`
User-related errors:
- `"USER_CANCELED"`
- `"USER_SHUTDOWN"`
Miscellaneous:
- `"CRASH"`
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#type-InterruptReason) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/resume/index.md | ---
title: downloads.resume()
slug: Mozilla/Add-ons/WebExtensions/API/downloads/resume
page-type: webextension-api-function
browser-compat: webextensions.api.downloads.resume
---
{{AddonSidebar}}
The **`resume()`** function of the {{WebExtAPIRef("downloads")}} API resumes a paused download. If the request was successful, the download will be unpaused and progress will resume. The `resume()` call will fail if the download is not active: for example, because it has finished downloading.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let resuming = browser.downloads.resume(
downloadId // integer
)
```
### Parameters
- `downloadId`
- : An `integer` representing the `id` of the download to resume.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). If the request was successful, the promise will be fulfilled with no arguments. If the request failed, the promise will be rejected with an error message.
## Browser compatibility
{{Compat}}
## Examples
```js
let downloadId = 2;
function onResumed() {
console.log(`Resumed download`);
}
function onError(error) {
console.log(`Error: ${error}`);
}
let resuming = browser.downloads.resume(downloadId);
resuming.then(onResumed, onError);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#method-resume) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/onchanged/index.md | ---
title: downloads.onChanged
slug: Mozilla/Add-ons/WebExtensions/API/downloads/onChanged
page-type: webextension-api-event
browser-compat: webextensions.api.downloads.onChanged
---
{{AddonSidebar}}
The **`onChanged()`** event of the {{WebExtAPIRef("downloads")}} API is fired when any of a {{WebExtAPIRef('downloads.DownloadItem')}}'s properties changes (except for `bytesReceived`).
The listener is passed a `downloadDelta` as a parameter — an object containing the `downloadId` of the {{WebExtAPIRef('downloads.DownloadItem')}} object in question, plus the status of all the properties that changed.
## Syntax
```js-nolint
browser.downloads.onChanged.addListener(listener)
browser.downloads.onChanged.removeListener(listener)
browser.downloads.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 a given `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. This function will be passed this argument:
- `downloadDelta`
- : An `object` representing the {{WebExtAPIRef('downloads.DownloadItem')}} object that changed, and the status of all the properties that changed in it. See the [downloadDelta](#downloaddelta_2) section for more details.
## Additional objects
### downloadDelta
The `downloadDelta` object has the following properties available:
- `id`
- : An `integer` representing the `id` of the {{WebExtAPIRef('downloads.DownloadItem')}} that changed.
- `url` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.StringDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s `url`.
- `filename` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.StringDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s `filename`.
- `danger` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.StringDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s `danger`.
- `mime` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.StringDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s `mime`.
- `startTime` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.StringDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s `startTime`.
- `endTime` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.StringDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s `endTime`.
- `state` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.StringDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s `state`.
- `canResume` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.BooleanDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s `canResume` status.
- `paused` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.BooleanDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s `paused` status.
- `error` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.StringDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s `error` status.
- `totalBytes` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.DoubleDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s `totalBytes`.
- `fileSize` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.DoubleDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s `fileSize`.
- `exists` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.BooleanDelta')}} object describing a change in a {{WebExtAPIRef('downloads.DownloadItem')}}'s `exists` status.
## Browser compatibility
{{Compat}}
## Examples
Log a message when downloads complete:
```js
function handleChanged(delta) {
if (delta.state && delta.state.current === "complete") {
console.log(`Download ${delta.id} has completed.`);
}
}
browser.downloads.onChanged.addListener(handleChanged);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#event-onChanged) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/downloadtime/index.md | ---
title: downloads.DownloadTime
slug: Mozilla/Add-ons/WebExtensions/API/downloads/DownloadTime
page-type: webextension-api-type
browser-compat: webextensions.api.downloads.DownloadTime
---
{{AddonSidebar}}
The `DownloadTime` type of the {{WebExtAPIRef("downloads")}} API represents the time a download took to complete.
## Type
A `DownloadTime` can be one of three different types:
- a JavaScript [`Date`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) object.
- a string:
- if this contains only digits, it's interpreted as the number of milliseconds since the UNIX epoch.
- otherwise, it's interpreted as an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) string.
- a number: this is interpreted as the number of milliseconds since the UNIX epoch.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#type-DownloadTime) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/filenameconflictaction/index.md | ---
title: downloads.FilenameConflictAction
slug: Mozilla/Add-ons/WebExtensions/API/downloads/FilenameConflictAction
page-type: webextension-api-type
browser-compat: webextensions.api.downloads.FilenameConflictAction
---
{{AddonSidebar}}
The `FilenameConflictAction` type of the {{WebExtAPIRef("downloads")}} API specifies what to do if the name of a downloaded file conflicts with an existing file.
This type defines the values that can be used for the `conflictAction` property of the {{WebExtAPIRef("downloads.download")}} function's `options` parameter.
## Type
Values of this type are strings. Possible values are:
- `"uniquify"`
- : The browser will modify the filename to make it unique.
- `"overwrite"`
- : The browser will overwrite the old file with the newly-downloaded file.
- `"prompt"`
- : The browser will prompt the user, asking them to choose whether to uniquify or overwrite.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#type-FilenameConflictAction) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/removefile/index.md | ---
title: downloads.removeFile()
slug: Mozilla/Add-ons/WebExtensions/API/downloads/removeFile
page-type: webextension-api-function
browser-compat: webextensions.api.downloads.removeFile
---
{{AddonSidebar}}
The **`removeFile()`** function of the {{WebExtAPIRef("downloads")}} API removes a downloaded file from disk.
This API removes the file from disk, but does not remove it from the browser's downloads history, therefore a call to {{WebExtAPIRef("downloads.search()")}} will still return the item as a {{WebExtAPIRef("downloads.DownloadItem", "DownloadItem")}}, but its `exists` attribute will be `false`.
To remove a file from the downloads history, you need to use {{WebExtAPIRef("downloads.erase()")}}.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
> **Note:** If you want to remove a downloaded file from disk _and_ erase it from history, you have to call `removeFile()` before you call {{WebExtAPIRef("downloads.erase()")}}. If you try it the other way around you'll get an error when calling `removeFile()`, because the browser will no longer have a record of the download.
## Syntax
```js-nolint
let removing = browser.downloads.removeFile(
downloadId // integer
)
```
### Parameters
- `downloadId`
- : An `integer` representing the id of the {{WebExtAPIRef("downloads.DownloadItem", "DownloadItem")}} you want to delete from disk.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). If the request was successful, the promise will be fulfilled with no arguments. If the request failed, the promise will be rejected with an error message.
## Browser compatibility
{{Compat}}
## Examples
Remove the most recently downloaded file:
```js
function onRemoved() {
console.log(`Removed item`);
}
function onError(error) {
console.log(`Error: ${error}`);
}
function remove(downloadItems) {
if (downloadItems.length > 0) {
let removing = browser.downloads.removeFile(downloadItems[0].id);
removing.then(onRemoved, onError);
}
}
let searching = browser.downloads.search({
limit: 1,
orderBy: ["-startTime"],
});
searching.then(remove, onError);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#method-removeFile) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/erase/index.md | ---
title: downloads.erase()
slug: Mozilla/Add-ons/WebExtensions/API/downloads/erase
page-type: webextension-api-function
browser-compat: webextensions.api.downloads.erase
---
{{AddonSidebar}}
The **`erase()`** function of the {{WebExtAPIRef("downloads")}} API erases matching {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} from the browser's download history, without deleting the downloaded files from disk.
To remove the files from disk, you need to use {{WebExtAPIRef("downloads.removeFile()")}}.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
> **Note:** If you want to remove a downloaded file from disk _and_ erase it from history, you have to call {{WebExtAPIRef("downloads.removeFile()")}} before you call `erase()`. If you try it the other way around you'll get an error when calling {{WebExtAPIRef("downloads.removeFile()")}}, because it no longer exists according to the browser.
## Syntax
```js-nolint
let erasing = browser.downloads.erase(
query // DownloadQuery
)
```
### Parameters
- `query`
- : A {{WebExtAPIRef('downloads.DownloadQuery')}} object.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). If the call was successful, the promise will be fulfilled with an array of integers representing the ids of the erased {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}}. If no items matching the query parameter could be found, the array will be empty. If the call failed, the promise will be rejected with an error message.
## Browser compatibility
{{Compat}}
## Examples
Erase the most recent download:
```js
function onErased(ids) {
console.log(`Erased: ${ids}`);
}
function onError(error) {
console.log(`Error erasing item: ${error}`);
}
let erasing = browser.downloads.erase({
limit: 1,
orderBy: ["-startTime"],
});
erasing.then(onErased, onError);
```
Erase everything:
```js
function onErased(ids) {
console.log(`Erased: ${ids}`);
}
function onError(error) {
console.log(`Error erasing item: ${error}`);
}
let erasing = browser.downloads.erase({});
erasing.then(onErased, onError);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#method-erase) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/search/index.md | ---
title: downloads.search()
slug: Mozilla/Add-ons/WebExtensions/API/downloads/search
page-type: webextension-api-function
browser-compat: webextensions.api.downloads.search
---
{{AddonSidebar}}
The **`search()`** function of the {{WebExtAPIRef("downloads")}} API queries the {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} available in the browser's downloads manager, and returns those that match the specified search criteria.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let searching = browser.downloads.search(query);
```
### Parameters
- `query`
- : A {{WebExtAPIRef('downloads.DownloadQuery')}} object.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). The promise is fulfilled with an `array` of `{{WebExtAPIRef('downloads.DownloadItem')}}` objects that match the given criteria.
## Browser compatibility
{{Compat}}
## Examples
In general, you restrict the items retrieved using the `query` parameter.
### Get downloads matching "query"
```js
function logDownloads(downloads) {
for (const download of downloads) {
console.log(download.id);
console.log(download.url);
}
}
function onError(error) {
console.log(`Error: ${error}`);
}
browser.downloads
.search({
query: ["imgur"],
})
.then(logDownloads, onError);
```
### Get a specific item
To get a specific {{WebExtAPIRef("downloads.DownloadItem", "DownloadItem")}}, the easiest way is to set only the `id` field, as seen in the snippet below:
```js
function logDownloads(downloads) {
for (const download of downloads) {
console.log(download.id);
console.log(download.url);
}
}
function onError(error) {
console.log(`Error: ${error}`);
}
const id = 13;
browser.downloads.search({ id }).then(logDownloads, onError);
```
### Get all downloads
If you want to return all {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}}, set `query` to an empty object.
```js
function logDownloads(downloads) {
for (const download of downloads) {
console.log(download.id);
console.log(download.url);
}
}
function onError(error) {
console.log(`Error: ${error}`);
}
browser.downloads.search({}).then(logDownloads, onError);
```
### Get the most recent download
You can get the most recent download by specifying the following search parameters:
```js
function logDownloads(downloads) {
for (const download of downloads) {
console.log(download.id);
console.log(download.url);
}
}
function onError(error) {
console.log(`Error: ${error}`);
}
browser.downloads
.search({
limit: 1,
orderBy: ["-startTime"],
})
.then(logDownloads, onError);
```
You can see this code in action in our [latest-download](https://github.com/mdn/webextensions-examples/blob/main/latest-download/popup/latest_download.js) example.
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#method-search) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/doubledelta/index.md | ---
title: downloads.DoubleDelta
slug: Mozilla/Add-ons/WebExtensions/API/downloads/DoubleDelta
page-type: webextension-api-type
browser-compat: webextensions.api.downloads.DoubleDelta
---
{{AddonSidebar}}
The `DoubleDelta` type of the {{WebExtAPIRef("downloads")}} API represents the difference between two doubles.
## Type
Values of this type are objects. They contain the following properties:
- `current` {{optional_inline}}
- : A `number` representing the current double value.
- `previous` {{optional_inline}}
- : A `number` representing the previous double value.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#type-DoubleDelta) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/onerased/index.md | ---
title: downloads.onErased
slug: Mozilla/Add-ons/WebExtensions/API/downloads/onErased
page-type: webextension-api-event
browser-compat: webextensions.api.downloads.onErased
---
{{AddonSidebar}}
The **`onErased()`** event of the {{WebExtAPIRef("downloads")}} API fires when a download is erased from the browser history.
The listener is passed the `downloadId` of the {{WebExtAPIRef('downloads.DownloadItem')}} object in question as a parameter.
## Syntax
```js-nolint
browser.downloads.onErased.addListener(listener)
browser.downloads.onErased.removeListener(listener)
browser.downloads.onErased.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 a given `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. This function is passed this argument:
- `downloadId`
- : An `integer` representing the `id` of the {{WebExtAPIRef('downloads.DownloadItem')}} that was erased.
## Browser compatibility
{{Compat}}
## Examples
Add a listener for `onErased` events, then erase the most recent download:
```js
function handleErased(item) {
console.log(`Erased: ${item}`);
}
browser.downloads.onErased.addListener(handleErased);
let erasing = browser.downloads.erase({
limit: 1,
orderBy: ["-startTime"],
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#event-onErased) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/showdefaultfolder/index.md | ---
title: downloads.showDefaultFolder()
slug: Mozilla/Add-ons/WebExtensions/API/downloads/showDefaultFolder
page-type: webextension-api-function
browser-compat: webextensions.api.downloads.showDefaultFolder
---
{{AddonSidebar}}
The **`showDefaultFolder()`** function of the {{WebExtAPIRef("downloads")}} API opens the default downloads folder in the platform's file manager.
## Syntax
```js-nolint
browser.downloads.showDefaultFolder();
```
### Parameters
None.
## Browser compatibility
{{Compat}}
## Examples
The following snippet contains a show button, which when clicked invokes `showDefaultFolder()` to open the default downloads folder in the platform's file manager:
```js
let showBtn = document.querySelector(".show");
showBtn.onclick = () => {
browser.downloads.showDefaultFolder();
};
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#method-showDefaultFolder) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/pause/index.md | ---
title: downloads.pause()
slug: Mozilla/Add-ons/WebExtensions/API/downloads/pause
page-type: webextension-api-function
browser-compat: webextensions.api.downloads.pause
---
{{AddonSidebar}}
The **`pause()`** function of the {{WebExtAPIRef("downloads")}} API pauses a download.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let pausing = browser.downloads.pause(
downloadId // integer
)
```
### Parameters
- `downloadId`
- : An `integer` representing the `id` of the download to pause.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). If the call was successful, the download will be put in a paused state, and the promise will be fulfilled with no arguments. If the call fails, the promise will be rejected with an error message. The call will fail if the download is not active: for example, because it has finished downloading.
## Browser compatibility
{{Compat}}
## Examples
```js
function onPaused() {
console.log(`Paused download`);
}
function onError(error) {
console.log(`Error: ${error}`);
}
let pausing = browser.downloads.pause(downloadId);
pausing.then(onPaused, onError);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#method-pause) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/stringdelta/index.md | ---
title: downloads.StringDelta
slug: Mozilla/Add-ons/WebExtensions/API/downloads/StringDelta
page-type: webextension-api-type
browser-compat: webextensions.api.downloads.StringDelta
---
{{AddonSidebar}}
The `StringDelta` type of the {{WebExtAPIRef("downloads")}} API represents the difference between two strings.
## Type
Values of this type are objects. They contain the following properties:
- `current` {{optional_inline}}
- : A `string` representing the current string value.
- `previous` {{optional_inline}}
- : A `string` representing the previous string value.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#type-StringDelta) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/oncreated/index.md | ---
title: downloads.onCreated
slug: Mozilla/Add-ons/WebExtensions/API/downloads/onCreated
page-type: webextension-api-event
browser-compat: webextensions.api.downloads.onCreated
---
{{AddonSidebar}}
The **`onCreated()`** event of the {{WebExtAPIRef("downloads")}} API fires when a download begins, i.e. when {{WebExtAPIRef("downloads.download()")}} is successfully invoked.
The listener is passed the {{WebExtAPIRef('downloads.DownloadItem')}} object in question as a parameter.
## Syntax
```js-nolint
browser.downloads.onCreated.addListener(listener)
browser.downloads.onCreated.removeListener(listener)
browser.downloads.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 a given `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise.
## addListener syntax
### Parameters
- `function`
- : The function called when this event occurs. This function is passed this argument:
- `downloadItem`
- : The {{WebExtAPIRef('downloads.DownloadItem')}} object in question.
## Browser compatibility
{{Compat}}
## Examples
Log the URL of items as they are downloaded:
```js
function handleCreated(item) {
console.log(item.url);
}
browser.downloads.onCreated.addListener(handleCreated);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#event-onCreated) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/setshelfenabled/index.md | ---
title: downloads.setShelfEnabled()
slug: Mozilla/Add-ons/WebExtensions/API/downloads/setShelfEnabled
page-type: webextension-api-function
browser-compat: webextensions.api.downloads.setShelfEnabled
---
{{AddonSidebar}}
The **`setShelfEnabled()`** function of the {{WebExtAPIRef("downloads")}} API enables or disables the gray shelf at the bottom of every window associated with the current browser profile. The shelf will be disabled as long as at least one extension has disabled it.
If you try to enable the shelf when at least one other extension has already disabled it, the call will fail and {{WebExtAPIRef("runtime.lastError")}} will be set with an appropriate error message.
> **Note:** To use this function in your extension you must ask for the `"downloads.shelf"` [manifest permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions), as well as the `"downloads"` permission.
## Syntax
```js-nolint
chrome.downloads.setShelfEnabled(enabled);
```
This API is also available as `browser.downloads.setShelfEnabled()`.
### Parameters
- `enabled`
- : A `boolean` representing the state that you want to set `setShelfEnabled()` to — `true` for enable, and `false` for disable.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#method-setShelfEnabled) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/cancel/index.md | ---
title: downloads.cancel()
slug: Mozilla/Add-ons/WebExtensions/API/downloads/cancel
page-type: webextension-api-function
browser-compat: webextensions.api.downloads.cancel
---
{{AddonSidebar}}
The **`cancel()`** function of the {{WebExtAPIRef("downloads")}} API cancels a download. The call will fail if the download is not active: for example, because it has completed downloading.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let canceling = browser.downloads.cancel(
downloadId // integer
)
```
### Parameters
- `downloadId`
- : `integer`. The id of the download to cancel.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). If the request was successful, the promise will be fulfilled with no arguments. If the request failed, the promise will be rejected with an error message.
## Browser compatibility
{{Compat}}
## Examples
```js
let downloadId = 13;
function onCanceled() {
console.log(`Canceled download`);
}
function onError(error) {
console.log(`Error: ${error}`);
}
let canceling = browser.downloads.cancel(downloadId);
canceling.then(onCanceled, onError);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#method-cancel) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/download/index.md | ---
title: downloads.download()
slug: Mozilla/Add-ons/WebExtensions/API/downloads/download
page-type: webextension-api-function
browser-compat: webextensions.api.downloads.download
---
{{AddonSidebar}}
The **`download()`** function of the {{WebExtAPIRef("downloads")}} API downloads a file, given its URL and other optional preferences.
If the URL uses the HTTP or HTTPS protocol, the request includes all the relevant cookies, that is, those cookies set for the URL's hostname, secure flag, path, and so on. The default cookies, the cookies from the normal browsing session, are used unless:
- the `incognito` option is used, then the private browsing cookies are used.
- the `cookieStoreId` option is used, then the cookies from the specified store are used.
If both `filename` and `saveAs` are specified, the Save As dialog is displayed, populated with the `filename`.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let downloading = browser.downloads.download(
options // object
)
```
### Parameters
- `options`
- : An `object` specifying what file you wish to download, and any other preferences you wish to set concerning the download. It can contain the following properties:
- `allowHttpErrors` {{optional_inline}}
- : A `boolean` flag that enables downloads to continue even if they encounter HTTP errors. Using this flag, for example, enables the download of server error pages. Default value `false`. When set to:
- `false`, the download is canceled when it encounters an HTTP error.
- `true`, the download continues when an HTTP error is encountered and the HTTP server error is not reported. However, if the download fails due to file-related, network-related, user-related, or other error, that error is reported.
- `body` {{optional_inline}}
- : A `string` representing the post body of the request.
- `conflictAction` {{optional_inline}}
- : A string representing the action you want taken if there is a filename conflict, as defined in the {{WebExtAPIRef('downloads.FilenameConflictAction')}} type (defaults to "uniquify" when it is not specified).
- `cookieStoreId` {{optional_inline}}
- : The cookie store ID of the [contextual identity](/en-US/docs/Mozilla/Add-ons/WebExtensions/Work_with_contextual_identities) the download is associated with. If omitted, the default cookie store is used. Use requires the "cookies" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#api_permissions). See [Work with contextual identities](/en-US/docs/Mozilla/Add-ons/WebExtensions/Work_with_contextual_identities) for more information.
- `filename` {{optional_inline}}
- : A `string` representing a file path relative to the default downloads directory — this provides the location where you want the file to be saved, and what filename you want to use. Absolute paths, empty paths, path components that start and/or end with a dot (.), and paths containing back-references (`../`) will cause an error. If omitted, this value will default to the filename already given to the download file, and a location immediately inside the downloads directory.
- `headers` {{optional_inline}}
- : If the URL uses the HTTP or HTTPS protocols, an `array` of `objects` representing additional HTTP headers to send with the request. Each header is represented as a dictionary object containing the keys `name` and either `value` or `binaryValue`. The headers that are forbidden by `XMLHttpRequest` and `fetch` cannot be specified, however, Firefox 70 and later enables the use of the `Referer` header. Attempting to use a forbidden header throws an error.
- `incognito` {{optional_inline}}
- : A `boolean`: if present and set to true, then associate this download with a private browsing session. This means that it will only appear in the download manager for any private windows that are currently open.
- `method` {{optional_inline}}
- : A `string` representing the HTTP method to use if the `url` uses the HTTP\[S] protocol. This may be either "GET" or "POST".
- `saveAs` {{optional_inline}}
- : A `boolean` that specifies whether to provide a file chooser dialog to allow the user to select a filename (`true`), or not (`false`).
If this option is omitted, the browser will show the file chooser or not based on the general user preference for this behavior (in Firefox this preference is labeled "Always ask you where to save files" in about:preferences, or `browser.download.useDownloadDir` in about:config).
> **Note:** Firefox for Android raises an error if `saveAs` is set to `true`. The parameter is ignored when `saveAs` is `false` or not included.
- `url`
- : A `string` representing the URL to download.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). If the download started successfully, the promise will be fulfilled with the `id` of the new {{WebExtAPIRef("downloads.DownloadItem")}}. Otherwise, the promise will be rejected with an error message taken from {{WebExtAPIRef("downloads.InterruptReason")}}.
If you use [URL.createObjectURL()](/en-US/docs/Web/API/URL/createObjectURL_static) to download data created in JavaScript and you want to revoke the object URL (with [revokeObjectURL](/en-US/docs/Web/API/URL/revokeObjectURL_static)) later (as it is strongly recommended), you need to do that after the download has been completed. To do so, listen to the [downloads.onChanged](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/downloads/onChanged) event.
## Browser compatibility
{{Compat}}
## Examples
The following snippet attempts to download an example file, also specifying a filename and location to save it in, and `uniquify` as the value of the `conflictAction` option.
```js
function onStartedDownload(id) {
console.log(`Started downloading: ${id}`);
}
function onFailed(error) {
console.log(`Download failed: ${error}`);
}
let downloadUrl = "https://example.org/image.png";
let downloading = browser.downloads.download({
url: downloadUrl,
filename: "my-image-again.png",
conflictAction: "uniquify",
});
downloading.then(onStartedDownload, onFailed);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#method-download) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/dangertype/index.md | ---
title: downloads.DangerType
slug: Mozilla/Add-ons/WebExtensions/API/downloads/DangerType
page-type: webextension-api-type
browser-compat: webextensions.api.downloads.DangerType
---
{{AddonSidebar}}
The `DangerType` type of the {{WebExtAPIRef("downloads")}} API defines a set of possible reasons that a downloadable file might be considered dangerous.
A {{WebExtAPIRef('downloads.DownloadItem')}}'s `danger` property will contain a string taken from the values defined in this type.
> **Note:** These string constants will never change, however the set of DangerTypes may change.
## Type
Values of this type are strings. Possible values are:
- `file`
- : The download's filename is suspicious.
- `url`
- : The download's URL is known to be malicious.
- `content`
- : The downloaded file is known to be malicious.
- `uncommon`
- : The download's URL is not commonly downloaded.
- `host`
- : The download came from a host known to distribute malicious binaries.
- `unwanted`
- : The download is potentially unwanted or unsafe.
- `safe`
- : The download presents no known danger to the user's computer.
- `accepted`
- : The user has accepted the dangerous download.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#type-DangerType) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/booleandelta/index.md | ---
title: downloads.BooleanDelta
slug: Mozilla/Add-ons/WebExtensions/API/downloads/BooleanDelta
page-type: webextension-api-type
browser-compat: webextensions.api.downloads.BooleanDelta
---
{{AddonSidebar}}
The `BooleanDelta` type of the {{WebExtAPIRef("downloads")}} API represents the difference between two booleans.
## Type
Values of this type are objects. They contain the following properties:
- `current` {{optional_inline}}
- : A `boolean` representing the current boolean value.
- `previous` {{optional_inline}}
- : A `boolean` representing the previous boolean value.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#type-BooleanDelta) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/state/index.md | ---
title: downloads.State
slug: Mozilla/Add-ons/WebExtensions/API/downloads/State
page-type: webextension-api-type
browser-compat: webextensions.api.downloads.State
---
{{AddonSidebar}}
The `State` type of the {{WebExtAPIRef("downloads")}} API defines different states that a current download can be in.
A {{WebExtAPIRef('downloads.DownloadItem')}}'s `state` property will contain a string taken from the values defined in this type.
## Type
Values of this type are strings. Possible values are:
- `in_progress`
- : The browser is currently receiving download data from the server.
- `interrupted`
- : An error broke the connection with the server.
- `complete`
- : The download completed successfully.
> **Note:** These string constants will never change, but new constants may be added.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#type-State) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/getfileicon/index.md | ---
title: downloads.getFileIcon()
slug: Mozilla/Add-ons/WebExtensions/API/downloads/getFileIcon
page-type: webextension-api-function
browser-compat: webextensions.api.downloads.getFileIcon
---
{{AddonSidebar}}
The **`getFileIcon()`** function of the {{WebExtAPIRef("downloads")}} API retrieves an icon for the specified download.
For new downloads, file icons are available after the {{WebExtAPIRef("downloads.onCreated")}} event has been received. The image returned by this function while a download is in progress may be different from the image returned after the download is complete.
Icon retrieval is done by querying the underlying platform. The icon that is returned will therefore depend on a number of factors including state of the download, platform, registered file types and visual theme.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let gettingIcon = browser.downloads.getFileIcon(
downloadId, // integer
options // optional object
)
```
### Parameters
- `downloadId`
- : An `integer` representing the ID of the download.
- `options` {{optional_inline}}
- : An options `object` representing preferences for the icon to be retrieved. It can take the following properties:
- `size` {{optional_inline}}
- : An `integer` representing the size of the icon. The returned icon's size will be the provided size squared (in pixels). If omitted, the default size for the icon is 32x32 pixels.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). If the request succeeds, the promise will be fulfilled with a string representing the absolute URL of the icon. If the request fails, the promise will be rejected with an error message.
## Browser compatibility
{{Compat}}
## Examples
This example logs the icon URL for the most recent download:
```js
function gotIcon(iconUrl) {
console.log(iconUrl);
}
function onError(error) {
console.log(`Error: ${error}`);
}
function getIcon(downloadItems) {
if (downloadItems.length > 0) {
latestDownloadId = downloadItems[0].id;
let gettingIcon = browser.downloads.getFileIcon(latestDownloadId);
gettingIcon.then(gotIcon, onError);
}
}
let searching = browser.downloads.search({
limit: 1,
orderBy: ["-startTime"],
});
searching.then(getIcon, onError);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#method-getFileIcon) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/show/index.md | ---
title: downloads.show()
slug: Mozilla/Add-ons/WebExtensions/API/downloads/show
page-type: webextension-api-function
browser-compat: webextensions.api.downloads.show
---
{{AddonSidebar}}
The **`show()`** function of the {{WebExtAPIRef("downloads")}} API shows the downloaded file in its containing folder in the underlying platform's file manager.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let showing = browser.downloads.show(
downloadId // integer
)
```
### Parameters
- `downloadId`
- : An `integer` representing the ID of the {{WebExtAPIRef("downloads.DownloadItem", "DownloadItem")}} to show.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). If the request succeeds, the promise will be fulfilled with a boolean about whether the request was successful. If the request fails, the promise will be rejected with an error message.
## Browser compatibility
{{Compat}}
## Examples
This example shows the most recently downloaded item:
```js
function onShowing(success) {
console.log(`Showing download item: ${success}`);
}
function onError(error) {
console.log(`Error opening item: ${error}`);
}
function openDownload(downloadItems) {
if (downloadItems.length > 0) {
latestDownloadId = downloadItems[0].id;
let showing = browser.downloads.show(latestDownloadId);
showing.then(onShowing, onError);
}
}
let searching = browser.downloads.search({
limit: 1,
orderBy: ["-startTime"],
});
searching.then(openDownload, onError);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#method-show) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/downloadquery/index.md | ---
title: downloads.DownloadQuery
slug: Mozilla/Add-ons/WebExtensions/API/downloads/DownloadQuery
page-type: webextension-api-type
browser-compat: webextensions.api.downloads.DownloadQuery
---
{{AddonSidebar}}
The `DownloadQuery` type of the {{WebExtAPIRef("downloads")}} API defines a set of parameters that can be used to search the downloads manager for a specific set of downloads.
This type is used for example in {{WebExtAPIRef("downloads.search()")}} and {{WebExtAPIRef("downloads.erase()")}}, as a query object to filter the set of {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} to return or erase.
## Type
Values of this type are objects. They contain the following properties:
- `cookieStoreId` {{optional_inline}}
- : The cookie store ID of the [contextual identity](/en-US/docs/Mozilla/Add-ons/WebExtensions/Work_with_contextual_identities) in which the download took place. See [Work with contextual identities](/en-US/docs/Mozilla/Add-ons/WebExtensions/Work_with_contextual_identities) for more information.
- `query` {{optional_inline}}
- : An `array` of `string`s. Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} whose `filename` or `url` contains all of the given strings. You can also include terms beginning with a dash (-) — these terms **must not** be contained in the item's `filename` or `url` for it to be included.
- `startedBefore` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.DownloadTime', "DownloadTime")}}. Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} that started before the given time.
- `startedAfter` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.DownloadTime', "DownloadTime")}}. Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} that started after the given time.
- `endedBefore` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.DownloadTime', "DownloadTime")}}. Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} that ended before the given time.
- `endedAfter` {{optional_inline}}
- : A {{WebExtAPIRef('downloads.DownloadTime', "DownloadTime")}}. Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} that ended after the given time.
- `totalBytesGreater` {{optional_inline}}
- : A `number` representing a number of bytes. Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} whose `totalBytes` is greater than the given number.
- `totalBytesLess` {{optional_inline}}
- : A `number` representing a number of bytes. Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} whose `totalBytes` is less than the given number.
- `filenameRegex` {{optional_inline}}
- : A `string` representing a regular expression. Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} whose `filename` value matches the given regular expression.
- `urlRegex` {{optional_inline}}
- : A `string` representing a regular expression. Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} whose `url` value matches the given regular expression.
- `limit` {{optional_inline}}
- : An `integer` representing a number of results. Include only the specified number of {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}}.
- `orderBy` {{optional_inline}}
- : An `array` of `string`s representing {{WebExtAPIRef("downloads.DownloadItem", "DownloadItem")}} properties the search results should be sorted by. For example, including `startTime` then `totalBytes` in the array would sort the {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} by their start time, then total bytes — in ascending order. To specify sorting by a property in descending order, prefix it with a hyphen, for example `-startTime`.
- `id` {{optional_inline}}
- : An `integer` representing the ID of the {{WebExtAPIRef("downloads.DownloadItem")}} you want to query.
- `url` {{optional_inline}}
- : A `string` representing the absolute URL that the download was initiated from, before any redirects.
- `filename` {{optional_inline}}
- : A string representing the absolute local path of the download file you want to query.
- `danger` {{optional_inline}}
- : A string representing a {{WebExtAPIRef('downloads.DangerType')}} — include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} with this `danger` value.
- `mime` {{optional_inline}}
- : A `string` representing a MIME type. Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} with this `mime` value.
- `startTime` {{optional_inline}}
- : A `string` representing an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format time. Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} with this `startTime` value.
- `endTime` {{optional_inline}}
- : A `string` representing an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format time. Include only will limited to {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} with this `endTime` value.
- `state` {{optional_inline}}
- : A `string` representing a download {{WebExtAPIRef('downloads.State')}} (`in_progress`, `interrupted`, or `complete`). Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} with this `state` value.
- `paused` {{optional_inline}}
- : A `boolean` that indicates whether a download is paused — i.e. has stopped reading data from the host, but kept the connection open (`true`), or not (`false`). Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} with this `paused` value.
- `error` {{optional_inline}}
- : A string representing an {{WebExtAPIRef('downloads.InterruptReason')}} — a reason why a download was interrupted. Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} with this `error` value.
- `bytesReceived` {{optional_inline}}
- : A `number` representing the number of bytes received so far from the host, without considering file compression. Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} with this `bytesReceived` value.
- `totalBytes` {{optional_inline}}
- : A `number` representing the total number of bytes in the downloaded file, without considering file compression. Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} with this `totalBytes` value.
- `fileSize` {{optional_inline}}
- : `number`. Number of bytes in the whole file post-decompression, or -1 if unknown. A `number` representing the total number of bytes in the file after decompression. Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} with this `fileSize` value.
- `exists` {{optional_inline}}
- : A `boolean` indicating whether a downloaded file still exists (`true`) or not (`false`). Include only {{WebExtAPIRef("downloads.DownloadItem", "DownloadItems")}} with this `exists` value.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#type-DownloadQuery) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/downloaditem/index.md | ---
title: downloads.DownloadItem
slug: Mozilla/Add-ons/WebExtensions/API/downloads/DownloadItem
page-type: webextension-api-type
browser-compat: webextensions.api.downloads.DownloadItem
---
{{AddonSidebar}}
The `DownloadItem` type of the {{WebExtAPIRef("downloads")}} API represents a downloaded file.
## Type
Values of this type are objects. They contain the following properties:
- `byExtensionId` {{optional_inline}}
- : A `string` representing the ID of the extension that triggered the download (if it was triggered by an extension). This does not change once set. If the download was not triggered by an extension this is undefined.
- `byExtensionName` {{optional_inline}}
- : A `string` representing the name of the extension that triggered the download (if it was triggered by an extension). This may change if the extension changes its name or the user changes their locale. If the download was not triggered by an extension this is undefined.
- `bytesReceived`
- : A `number` representing the number of bytes received so far from the host during the download; this does not take file compression into consideration.
- `canResume`
- : A `boolean` indicating whether a currently-interrupted (e.g. paused) download can be resumed from the point where it was interrupted (`true`), or not (`false`).
- `cookieStoreId` {{optional_inline}}
- : The cookie store ID of the [contextual identity](/en-US/docs/Mozilla/Add-ons/WebExtensions/Work_with_contextual_identities) in which the download took place. See [Work with contextual identities](/en-US/docs/Mozilla/Add-ons/WebExtensions/Work_with_contextual_identities) for more information.
- `danger`
- : A string indicating whether this download is thought to be safe or known to be suspicious. Its possible values are defined in the {{WebExtAPIRef('downloads.DangerType')}} type.
- `endTime` {{optional_inline}}
- : A `string` (in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format) representing the number of milliseconds between the UNIX epoch and when this download ended. This is undefined if the download has not yet finished.
- `error` {{optional_inline}}
- : A string indicating why a download was interrupted. Possible values are defined in the {{WebExtAPIRef('downloads.InterruptReason')}} type. This is undefined if an error has not occurred.
- `estimatedEndTime` {{optional_inline}}
- : A `string` (in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format) representing the estimated number of milliseconds between the UNIX epoch and when this download is estimated to be completed. This is undefined if it is not known (in particular, it is undefined in the `DownloadItem` that's passed into {{WebExtAPIRef("downloads.onCreated")}}).
- `exists`
- : A `boolean` indicating whether a downloaded file still exists (`true`) or not (`false`). This information might be out-of-date, as browsers do not automatically watch for file removal — to check whether a file exists, call the {{WebExtAPIRef('downloads.search()')}} method, filtering for the file in question.
- `filename`
- : A `string` representing the file's absolute local path.
- `fileSize`
- : A `number` indicating the total number of bytes in the whole file, after decompression. A value of -1 here means that the total file size is unknown.
- `id`
- : An `integer` representing a unique identifier for the downloaded file that is persistent across browser sessions.
- `incognito`
- : A `boolean` that indicates whether the download is recorded in the browser's history (`false`), or not (`true`).
- `mime`
- : A `string` representing the downloaded file's MIME type.
- `paused`
- : A `boolean` indicating whether the download is paused, i.e. if the download has stopped reading data from the host but has kept the connection open. If so, the value is `true`, `false` if not.
- `referrer`
- : A `string` representing the downloaded file's referrer.
- `startTime`
- : A `string` (in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format) representing the number of milliseconds between the UNIX epoch and when this download began.
- `state`
- : A `string` Indicating whether the download is progressing, interrupted, or complete. Possible values are defined in the {{WebExtAPIRef('downloads.State')}} type.
- `totalBytes`
- : A `number` indicating the total number of bytes in the file being downloaded. This does not take file compression into consideration. A value of -1 here means that the total number of bytes is unknown.
- `url`
- : A `string` representing the absolute URL from which the file was downloaded.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#type-DownloadItem) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/acceptdanger/index.md | ---
title: downloads.acceptDanger()
slug: Mozilla/Add-ons/WebExtensions/API/downloads/acceptDanger
page-type: webextension-api-function
browser-compat: webextensions.api.downloads.acceptDanger
---
{{AddonSidebar}}
The **`acceptDanger()`** function of the {{WebExtAPIRef("downloads")}} API prompts the user to either accept or cancel a potentially dangerous download.
This function can't be called from background scripts, only in scripts that are running in a visible window (such as a browser or page action's popup).
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let prompting = browser.downloads.acceptDanger(
downloadId // integer
)
```
### Parameters
- `downloadId`
- : An `integer` representing the `id` of the {{WebExtAPIRef("downloads.DownloadItem", "DownloadItem")}} in question.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). When the dialog closes, the promise will be fulfilled with no arguments.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#method-acceptDanger) 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/downloads | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/downloads/open/index.md | ---
title: downloads.open()
slug: Mozilla/Add-ons/WebExtensions/API/downloads/open
page-type: webextension-api-function
browser-compat: webextensions.api.downloads.open
---
{{AddonSidebar}}
The **`open()`** function of the {{WebExtAPIRef("downloads")}} API opens the downloaded file with its associated application. A {{WebExtAPIRef("downloads.onChanged")}} event fires when the item is opened for the first time.
To use this function in your extension you must ask for the "downloads.open" [manifest permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions), as well as the "downloads" permission. Also, 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
let opening = browser.downloads.open(
downloadId // integer
)
```
### Parameters
- `downloadId`
- : An `integer` representing the `id` of the {{WebExtAPIRef("downloads.DownloadItem")}} you want to open.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). If the request is successful, the promise is fulfilled with no arguments. If the request failed, the promise is rejected with an error message.
## Browser compatibility
{{Compat}}
## Examples
This example opens the most recently downloaded item:
```js
function onOpened() {
console.log(`Opened download item`);
}
function onError(error) {
console.log(`Error opening item: ${error}`);
}
function openDownload(downloadItems) {
if (downloadItems.length > 0) {
let opening = browser.downloads.open(downloadItems[0].id);
opening.then(onOpened, onError);
}
}
let searching = browser.downloads.search({
limit: 1,
orderBy: ["-startTime"],
});
searching.then(openDownload, onError);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.downloads`](https://developer.chrome.com/docs/extensions/reference/downloads/#method-open) 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 | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/index.md | ---
title: devtools
slug: Mozilla/Add-ons/WebExtensions/API/devtools
page-type: webextension-api
browser-compat: webextensions.api.devtools
---
{{AddonSidebar}}
Enables extensions to interact with the browser's {{Glossary("Developer Tools")}}. You use this API to create Developer Tools pages, interact with the window that is being inspected, inspect the page network usage.
To use this API, you must specify the [`devtools_page`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/devtools_page) manifest key. The use of this manifest key triggers [an install-time permission warning about devtools](https://support.mozilla.org/en-US/kb/permission-request-messages-firefox-extensions#w_extend-developer-tools-to-access-your-data-in-open-tabs). To avoid an install-time permission warning, mark the feature as optional by listing the `"devtools"` permission in the [`optional_permissions`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/optional_permissions) manifest key.
> NOTE: The "devtools" optional permission is only supported by Firefox and not Chrome ([Chromium issue 1143015](https://crbug.com/1143015)).
## Properties
- {{WebExtAPIRef("devtools.inspectedWindow")}}
- : Interact with the window that Developer tools are attached to (inspected window). This includes obtaining the tab ID for the inspected page, evaluate the code in the context of the inspected window, reload the page, or obtain the list of resources within the page.
- {{WebExtAPIRef("devtools.network")}}
- : Obtain information about network requests associated with the window that the Developer Tools are attached to (the inspected window).
- {{WebExtAPIRef("devtools.panels")}}
- : Create User Interface panels that will be displayed inside User Agent Developer Tools.
## Browser compatibility
{{Compat}}
> **Note:** This API is based on Chromium's [`chrome.devtools`](https://developer.chrome.com/docs/extensions/mv2/devtools/) 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/devtools | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/network/index.md | ---
title: devtools.network
slug: Mozilla/Add-ons/WebExtensions/API/devtools/network
page-type: webextension-api-property
browser-compat: webextensions.api.devtools.network
---
{{AddonSidebar}}
The `devtools.network` API lets a devtools extension get information about network requests associated with the window that the devtools are attached to (the inspected window).
Like all the `devtools` APIs, this API is only available to code running in the document defined in the [devtools_page](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/devtools_page) manifest.json key, or in other devtools documents created by the extension (such as the panel's own document). See [Extending the developer tools](/en-US/docs/Mozilla/Add-ons/WebExtensions/Extending_the_developer_tools) for more.
## Functions
- [`devtools.network.getHAR()`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/network/getHAR)
- : Get a [HAR log](http://www.softwareishard.com/blog/har-12-spec/#log) for the page loaded in the current tab.
## Events
- [`devtools.network.onNavigated`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/network/onNavigated)
- : Fired when the user navigates the inspected window to a new page.
- [`devtools.network.onRequestFinished`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/network/onRequestFinished)
- : Fired when the network request has finished and its details are available to the extension.
## Browser compatibility
{{Compat}}
{{WebExtExamples("h2")}}
> **Note:** This API is based on Chromium's [`chrome.devtools.network`](https://developer.chrome.com/docs/extensions/reference/devtools_network/) 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/devtools/network | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/network/onnavigated/index.md | ---
title: devtools.network.onNavigated
slug: Mozilla/Add-ons/WebExtensions/API/devtools/network/onNavigated
page-type: webextension-api-event
browser-compat: webextensions.api.devtools.network.onNavigated
---
{{AddonSidebar}}
Fired when the user navigates the inspected window to a new page.
## Syntax
```js-nolint
browser.devtools.network.onNavigated.addListener(listener)
browser.devtools.network.onNavigated.removeListener(listener)
browser.devtools.network.onNavigated.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 this argument:
- `url`
- : `string`. The new URL for the window.
## Browser compatibility
{{Compat}}
## Examples
```js
function handleNavigated(url) {
console.log(url);
}
browser.devtools.network.onNavigated.addListener(handleNavigated);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools`](https://developer.chrome.com/docs/extensions/mv3/devtools/) 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/devtools/network | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/network/gethar/index.md | ---
title: devtools.network.getHAR()
slug: Mozilla/Add-ons/WebExtensions/API/devtools/network/getHAR
page-type: webextension-api-function
browser-compat: webextensions.api.devtools.network.getHAR
---
{{AddonSidebar}}
Get a [HAR log](http://www.softwareishard.com/blog/har-12-spec/#log) for the page loaded in the current tab.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let getting = browser.devtools.network.getHAR()
```
### Parameters
None.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an object containing the HAR log for the current tab. For details of what the log object contains, refer to the [HAR specification](http://www.softwareishard.com/blog/har-12-spec/#log).
## Browser compatibility
{{Compat}}
## Examples
Log the URLs of requests contained in the HAR log:
```js
async function logRequests() {
let harLog = await browser.devtools.network.getHAR();
console.log(`HAR version: ${harLog.version}`);
for (const entry of harLog.entries) {
console.log(entry.request.url);
}
}
logRequestsButton.addEventListener("click", logRequests);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools.network`](https://developer.chrome.com/docs/extensions/reference/devtools_network/) 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/devtools/network | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/network/onrequestfinished/index.md | ---
title: devtools.network.onRequestFinished
slug: Mozilla/Add-ons/WebExtensions/API/devtools/network/onRequestFinished
page-type: webextension-api-event
browser-compat: webextensions.api.devtools.network.onRequestFinished
---
{{AddonSidebar}}
Fired when a network request has finished and its details are available to the extension.
The request is given as a [HAR entry object](http://www.softwareishard.com/blog/har-12-spec/#entries), which is also given an asynchronous `getContent()` method that gets the response body content.
Note that although your extension can add a listener at any time, it will only start firing after the user has activated the browser's [network panel](https://firefox-source-docs.mozilla.org/devtools-user/network_monitor/index.html) at least once.
## Syntax
```js-nolint
browser.devtools.network.onRequestFinished.addListener(listener)
browser.devtools.network.onRequestFinished.removeListener(listener)
browser.devtools.network.onRequestFinished.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 this argument:
- `request`
- : `object`. An object representing the request. This object is a single [HAR entry](http://www.softwareishard.com/blog/har-12-spec/#entries) object. It also defines an asynchronous `getContent()` method, which returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that resolves with an array of two elements. The first element is the HTTP response body as a string, while the second element is the [MIME type](/en-US/docs/Glossary/MIME_type) of the HTTP response also as a string.
## Browser compatibility
{{Compat}}
## Examples
Add a listener that logs the server IP address and response body for every network request.
```js
function handleRequestFinished(request) {
console.log("Server IP: ", request.serverIPAddress);
request.getContent().then(([content, mimeType]) => {
console.log("Content: ", content);
console.log("MIME type: ", mimeType);
});
}
browser.devtools.network.onRequestFinished.addListener(handleRequestFinished);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools`](https://developer.chrome.com/docs/extensions/mv3/devtools/) 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/devtools | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/index.md | ---
title: devtools.panels
slug: Mozilla/Add-ons/WebExtensions/API/devtools/panels
page-type: webextension-api-property
browser-compat: webextensions.api.devtools.panels
---
{{AddonSidebar}}
> **Note:** Although the APIs are based on the [Chrome devtools APIs](https://developer.chrome.com/docs/extensions/mv3/devtools/), there are still many features that are not yet implemented in Firefox, and therefore are not documented here. To see which features are currently missing please see [Limitations of the devtools APIs](/en-US/docs/Mozilla/Add-ons/WebExtensions/Extending_the_developer_tools#limitations_of_the_devtools_apis).
The `devtools.panels` API lets a devtools extension define its user interface inside the devtools window.
The devtools window hosts a number of separate tools - the JavaScript Debugger, Network Monitor, and so on. A row of tabs across the top lets the user switch between the different tools. The window hosting each tool's user interface is called a "panel".
With the `devtools.panels` API you can create new panels in the devtools window.
Like all the `devtools` APIs, this API is only available to code running in the document defined in the [devtools_page](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/devtools_page) manifest.json key, or in other devtools documents created by the extension (such as the panel's own document). See [Extending the developer tools](/en-US/docs/Mozilla/Add-ons/WebExtensions/Extending_the_developer_tools) for more.
## Types
- [`devtools.panels.ElementsPanel`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ElementsPanel)
- : Represents the HTML/CSS inspector in the browser's devtools.
- [`devtools.panels.ExtensionPanel`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionPanel)
- : Represents a devtools panel created by the extension.
- [`devtools.panels.ExtensionSidebarPane`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane)
- : Represents a pane that an extension has added to the HTML/CSS inspector in the browser's devtools.
## Properties
- [`devtools.panels.elements`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/elements)
- : A reference to an [`ElementsPanel`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ElementsPanel) object.
- [`devtools.panels.themeName`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/themeName)
- : The name of the current devtools theme.
## Functions
- [`devtools.panels.create()`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/create)
- : Creates a new devtools panel.
## Events
- [`devtools.panels.onThemeChanged`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/onThemeChanged)
- : Fired when the devtools theme changes.
## Example extensions
- [devtools-panels](https://github.com/mdn/webextensions-examples/tree/main/devtools-panels)
## Browser compatibility
{{Compat}}
{{WebExtExamples("h2")}}
> **Note:** This API is based on Chromium's [`chrome.devtools.panels`](https://developer.chrome.com/docs/extensions/reference/devtools_panels/) 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/devtools/panels | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/elements/index.md | ---
title: devtools.panels.elements
slug: Mozilla/Add-ons/WebExtensions/API/devtools/panels/elements
page-type: webextension-api-property
browser-compat: webextensions.api.devtools.panels.elements
---
{{AddonSidebar}}
An [`ElementsPanel`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ElementsPanel) object, which represents the browser's HTML/CSS inspector.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools.panels`](https://developer.chrome.com/docs/extensions/reference/devtools_panels/) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/create/index.md | ---
title: devtools.panels.create()
slug: Mozilla/Add-ons/WebExtensions/API/devtools/panels/create
page-type: webextension-api-function
browser-compat: webextensions.api.devtools.panels.create
---
{{AddonSidebar}}
Adds a new panel to the devtools.
This function takes: a title, a URL to an icon file, and a URL to an HTML file. It creates a new panel in the devtools, whose content is specified by the HTML file. It returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that resolves to an [`ExtensionPanel`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionPanel) object representing the new panel.
## Syntax
```js-nolint
let creating = browser.devtools.panels.create(
title, // string
iconPath, // string
pagePath // string
)
```
### Parameters
- `title`
- : `string`. The panel's title. This will appear in the row of tabs along the top of the devtools window, and is the main way the user will be able to identify your panel.
- `iconPath`
- : `string`. Specifies an icon which will be shown next to the title. It's provided as a URL to an image file that's been bundled with your extension. Chromium-based browsers and Safari resolve this URL as absolute, while Firefox resolves this URL as relative to the current extension page (unless expressed as an absolute URL, e.g. "/icons/panel.png").
- `pagePath`
- : string. Specifies an HTML file that defines the content of the panel. It's provided as a URL to an HTML file bundled with your extension. The URL may be resolved as an absolute URL or relative to the current extension page. See the browser compatibility data for more information. The HTML file can include CSS and JavaScript files, just like a normal web page. The JavaScript running in the panel can use the devtools APIs. See [Extending the developer tools](/en-US/docs/Mozilla/Add-ons/WebExtensions/Extending_the_developer_tools).
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an [`ExtensionPanel`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionPanel) object representing the new panel.
## Browser compatibility
{{Compat}}
## Examples
Create a new panel, and add listeners to its onShown and onHidden events:
```js
function handleShown() {
console.log("panel is being shown");
}
function handleHidden() {
console.log("panel is being hidden");
}
browser.devtools.panels
.create(
"My Panel", // title
"/icons/star.png", // icon
"/devtools/panel/panel.html", // content
)
.then((newPanel) => {
newPanel.onShown.addListener(handleShown);
newPanel.onHidden.addListener(handleHidden);
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools.panels`](https://developer.chrome.com/docs/extensions/reference/devtools_panels/) 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/devtools/panels | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/onthemechanged/index.md | ---
title: devtools.panels.onThemeChanged
slug: Mozilla/Add-ons/WebExtensions/API/devtools/panels/onThemeChanged
page-type: webextension-api-event
browser-compat: webextensions.api.devtools.panels.onThemeChanged
---
{{AddonSidebar}}
Fired when the devtools theme changes.
## Syntax
```js-nolint
browser.devtools.panels.onThemeChanged.addListener(listener)
browser.devtools.panels.onThemeChanged.removeListener(listener)
browser.devtools.panels.onThemeChanged.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 this argument:
- `themeName`
- : `string`. Name of the new theme: this will be one of the permitted values for [`devtools.panels.themeName`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/themeName).
## Browser compatibility
{{Compat}}
## Examples
```js
browser.devtools.panels.onThemeChanged.addListener((newThemeName) => {
console.log(`New theme: ${newThemeName}`);
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools.panels`](https://developer.chrome.com/docs/extensions/reference/devtools_panels/) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/themename/index.md | ---
title: devtools.panels.themeName
slug: Mozilla/Add-ons/WebExtensions/API/devtools/panels/themeName
page-type: webextension-api-property
browser-compat: webextensions.api.devtools.panels.themeName
---
{{AddonSidebar}}
The name of the currently selected devtools theme.
This is a string whose possible values are:
- "light"
- "dark"
- "firebug"
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools.panels`](https://developer.chrome.com/docs/extensions/reference/devtools_panels/) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/elementspanel/index.md | ---
title: devtools.panels.ElementsPanel
slug: Mozilla/Add-ons/WebExtensions/API/devtools/panels/ElementsPanel
page-type: webextension-api-type
browser-compat: webextensions.api.devtools.panels.ElementsPanel
---
{{AddonSidebar}}
An `ElementsPanel` represents the HTML/CSS inspector in the browser's devtools. This is called the Page Inspector in Firefox and the Elements panel in Chrome.
## Functions
- [`devtools.panels.ElementsPanel.createSidebarPane()`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ElementsPanel/createSidebarPane)
- : Creates a pane in the inspector's sidebar.
## Events
- [`devtools.panels.ElementsPanel.onSelectionChanged`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ElementsPanel/onSelectionChanged)
- : Fired when the user selects a different element in the page, for example using the "Inspect element" context menu item.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools`](https://developer.chrome.com/docs/extensions/mv3/devtools/) 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/devtools/panels/elementspanel | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/elementspanel/onselectionchanged/index.md | ---
title: onSelectionChanged
slug: Mozilla/Add-ons/WebExtensions/API/devtools/panels/ElementsPanel/onSelectionChanged
page-type: webextension-api-event
browser-compat: webextensions.api.devtools.panels.ElementsPanel.onSelectionChanged
---
{{AddonSidebar}}
Fires when the user selects a different page element for inspection with the browser's developer tools, for example by selecting the "Inspect Element" context menu item in Firefox.
## Syntax
```js-nolint
browser.devtools.panels.elements.onSelectionChanged.addListener(listener)
browser.devtools.panels.elements.onSelectionChanged.removeListener(listener)
browser.devtools.panels.elements.onSelectionChanged.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 arguments.
## Browser compatibility
{{Compat}}
## Examples
Listen for selection changed events, and log the text content of the newly selected element:
```js
function handleSelectedElement() {
browser.devtools.inspectedWindow.eval("$0.textContent").then((result) => {
console.log(result[0]);
});
}
browser.devtools.panels.elements.onSelectionChanged.addListener(
handleSelectedElement,
);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools`](https://developer.chrome.com/docs/extensions/mv3/devtools/) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/elementspanel | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/elementspanel/createsidebarpane/index.md | ---
title: devtools.panels.ElementsPanel.createSidebarPane()
slug: Mozilla/Add-ons/WebExtensions/API/devtools/panels/ElementsPanel/createSidebarPane
page-type: webextension-api-function
browser-compat: webextensions.api.devtools.panels.ElementsPanel.createSidebarPane
---
{{AddonSidebar}}
Adds a new pane to the sidebar in the HTML/CSS inspector.
The HTML/CSS inspector, called the [Page Inspector](https://firefox-source-docs.mozilla.org/devtools-user/page_inspector/index.html) in Firefox and the [Elements panel](https://developer.chrome.com/docs/devtools/css/) in Chrome, displays the page DOM in the main part of its window, and has a sidebar that displays various other aspects of the page HTML/CSS in a tabbed interface. For example, in Firefox, the sidebar can display the CSS rules for the selected element, or its fonts, or its box model.
The `createSidebarPane()` function adds a new pane to the sidebar. For example, the screenshot below shows a new pane titled "My pane", that displays a JSON object:
![Image showing a new pane titled "My pane", that displays a JSON object](inspector-sidebar.png)
This function takes one argument, which is a string representing the pane's title. It returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that resolves to an [`ExtensionSidebarPane`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane) object representing the new pane. You can use that object to define the pane's content and behavior.
## Syntax
```js-nolint
let creating = browser.devtools.panels.elements.createSidebarPane(
title // string
)
```
### Parameters
- `title`
- : `string`. The pane's title. This will appear in the row of tabs along the top of the sidebar, and is the main way the user will be able to identify your pane.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an [`ExtensionSidebarPane`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane) object representing the new pane.
## Browser compatibility
{{Compat}}
## Examples
Create a new pane, and populate it with a JSON object. You could run this code in a script loaded by your extension's [devtools page](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/devtools_page).
```js
function onCreated(sidebarPane) {
sidebarPane.setObject({
someBool: true,
someString: "hello there",
someObject: {
someNumber: 42,
someOtherString: "this is my pane's content",
},
});
}
browser.devtools.panels.elements.createSidebarPane("My pane").then(onCreated);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools.panels`](https://developer.chrome.com/docs/extensions/reference/devtools_panels/) 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/devtools/panels | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/extensionpanel/index.md | ---
title: devtools.panels.ExtensionPanel
slug: Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionPanel
page-type: webextension-api-type
browser-compat: webextensions.api.devtools.panels.ExtensionPanel
---
{{AddonSidebar}}
An `ExtensionPanel` represents a panel added to the devtools. It's the resolution of the [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) returned by [`browser.devtools.panels.create()`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/create).
## Type
Values of this type are objects. The define two events, `onShown` and `onHidden`.
- `onShown` is emitted when the panel is shown in the devtools (for example, because the user clicked on the panel's tab in the devtools window).
- `onHidden` is emitted when the panel is hidden (for example, because the user switched to a different tab in the devtools window).
## Browser compatibility
{{Compat}}
## Examples
This code creates a new panel, then adds handlers for its `onShown` and `onHidden` events.
```js
function handleShown(e) {
console.log(e);
console.log("panel is being shown");
}
function handleHidden(e) {
console.log(e);
console.log("panel is being hidden");
}
browser.devtools.panels
.create(
"My Panel", // title
"icons/star.png", // icon
"devtools/panel/panel.html", // content
)
.then((newPanel) => {
newPanel.onShown.addListener(handleShown);
newPanel.onHidden.addListener(handleHidden);
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools.panels`](https://developer.chrome.com/docs/extensions/reference/devtools_panels/) 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/devtools/panels | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/extensionsidebarpane/index.md | ---
title: devtools.panels.ExtensionSidebarPane
slug: Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane
page-type: webextension-api-type
browser-compat: webextensions.api.devtools.panels.ExtensionSidebarPane
---
{{AddonSidebar}}
The `ExtensionSidebarPane` object represents a pane that an extension has added to the sidebar in the browser's HTML/CSS inspector.
![new pane titled "My pane" that displays a JSON object](inspector-sidebar.png)
To create an `ExtensionSidebarPane`, call the [`browser.devtools.panels.elements.createSidebarPane()`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ElementsPanel/createSidebarPane) function.
## Functions
- [`devtools.panels.ExtensionSidebarPane.setExpression()`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane/setExpression)
- : Evaluate a JavaScript expression in the web page that the inspector is inspecting. The result is displayed in the sidebar pane.
- [`devtools.panels.ExtensionSidebarPane.setObject()`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane/setObject)
- : Sets a JSON object that will be displayed in the sidebar pane.
- [`devtools.panels.ExtensionSidebarPane.setPage()`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane/setPage)
- : Loads the page pointed to by the supplied URL.
## Events
- [`devtools.panels.ExtensionSidebarPane.onShown`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane/onShown)
- : Fired when the sidebar pane is shown.
- [`devtools.panels.ExtensionSidebarPane.onHidden`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane/onHidden)
- : Fired when the sidebar pane is hidden.
## Browser compatibility
{{Compat}}
{{WebExtExamples("h2")}}
> **Note:** This API is based on Chromium's [`chrome.devtools.panels`](https://developer.chrome.com/docs/extensions/reference/devtools_panels/) 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/devtools/panels/extensionsidebarpane | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/extensionsidebarpane/setobject/index.md | ---
title: devtools.panels.ExtensionSidebarPane.setObject()
slug: Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane/setObject
page-type: webextension-api-function
browser-compat: webextensions.api.devtools.panels.ExtensionSidebarPane.setObject
---
{{AddonSidebar}}
Displays a JSON object in the extension's sidebar pane.
The object is displayed as an expandable tree, as in the [JSON viewer](https://firefox-source-docs.mozilla.org/devtools-user/json_viewer/index.html) in Firefox. You can optionally specify a `rootTitle` string: this will be displayed as the title of the tree's root.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let setting = browser.devtools.panels.setObject(
jsonObject, // string, array, or JSON object
rootTitle // string
)
```
### Parameters
- `jsonObject`
- : `String` or `Array` or `Object`. The object to display. If this is an object it is JSON-serialized, so properties like functions will be omitted.
- `rootTitle` {{optional_inline}}
- : `String`. The title of the root of the tree in which the object is displayed.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with no arguments, once the object has been set.
## Browser compatibility
{{Compat}}
## Examples
Create a new pane, and populate it with a JSON object. You could run this code in a script loaded by your extension's [devtools page](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/devtools_page).
```js
function onCreated(sidebarPane) {
sidebarPane.setObject({
someBool: true,
someString: "hello there",
someObject: {
someNumber: 42,
someOtherString: "this is my pane's content",
},
});
}
browser.devtools.panels.elements.createSidebarPane("My pane").then(onCreated);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools.panels`](https://developer.chrome.com/docs/extensions/reference/devtools_panels/) 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/devtools/panels/extensionsidebarpane | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/extensionsidebarpane/setexpression/index.md | ---
title: devtools.panels.ElementsPanel.setExpression()
slug: Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane/setExpression
page-type: webextension-api-function
browser-compat: webextensions.api.devtools.panels.ExtensionSidebarPane.setExpression
---
{{AddonSidebar}}
Evaluates an expression in the context of the inspected page, and displays the result in the extension sidebar pane.
The expression's execution context is the same as that for [`inspectedWindow.eval()`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/inspectedWindow/eval).
JSON objects and DOM nodes are displayed as an expandable tree, as in the [JSON viewer](https://firefox-source-docs.mozilla.org/devtools-user/json_viewer/index.html) in Firefox. You can optionally specify a `rootTitle` string: this will be displayed as the title of the tree's root.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let evaluating = browser.devtools.panels.setExpression(
expression, // string
rootTitle // string
)
```
### Parameters
- `expression`
- : `string`. The expression to evaluate.
- `rootTitle` {{optional_inline}}
- : string. The title of the root of the tree in which results are displayed.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with no arguments, once the expression has been evaluated.
## Browser compatibility
{{Compat}}
## Examples
This code creates a sidebar pane that displays the [`tagName`](/en-US/docs/Web/API/Element/tagName) of the currently selected element:
```js
function onCreated(sidebarPane) {
browser.devtools.panels.elements.onSelectionChanged.addListener(() => {
const exp = "$0 && $0.tagName";
const title = "Selected Element tagName";
sidebarPane.setExpression(exp, title);
});
}
browser.devtools.panels.elements.createSidebarPane("My pane").then(onCreated);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools.panels`](https://developer.chrome.com/docs/extensions/reference/devtools_panels/) 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/devtools/panels/extensionsidebarpane | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/extensionsidebarpane/setpage/index.md | ---
title: devtools.panels.ExtensionSidebarPane.setPage()
slug: Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane/setPage
page-type: webextension-api-function
browser-compat: webextensions.api.devtools.panels.ExtensionSidebarPane.setPage
---
{{AddonSidebar}}
Sets an HTML page to be displayed in the sidebar pane.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
browser.devtools.panels.setPage(
path // string containing relative path to page
)
```
### Parameters
- extensionPageURL
- : `string`. The relative path of an HTML page to display within the sidebar.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with no arguments, once the URL has been set.
The selected page will not be loaded until the user selects the devtools sidebar.
## Examples
Create a new pane, and populate it with an HTML page. You could run this code in a script loaded by your extension's [devtools page](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/devtools_page).
```js
function onCreated(sidebarPane) {
sidebarPane.setPage("sidebar/sidebar.html");
}
```
{{WebExtExamples}}
## Browser compatibility
{{Compat}}
> **Note:** This API is based on Chromium's [`chrome.devtools.panels`](https://developer.chrome.com/docs/extensions/reference/devtools_panels/) 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/devtools/panels/extensionsidebarpane | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/extensionsidebarpane/onhidden/index.md | ---
title: devtools.panels.ExtensionSidebarPane.onHidden
slug: Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane/onHidden
page-type: webextension-api-event
browser-compat: webextensions.api.devtools.panels.ExtensionSidebarPane.onHidden
---
{{AddonSidebar}}
Called when the sidebar pane becomes hidden, as a result of the user switching away from it.
## Syntax
```js-nolint
browser.devtools.panels.onHidden.addListener(listener)
browser.devtools.panels.onHidden.removeListener(listener)
browser.devtools.panels.onHidden.hasListener(listener)
```
Events have three functions:
- `addListener(listener)`
- : Adds a listener to this event.
- `removeListener(listener)`
- : Stops listening to this event. The `listener` argument is the listener to remove.
- `hasListener(listener)`
- : Checks whether `listener` is registered for this event. Returns `true` if it is listening, and `false` otherwise.
## addListener syntax
### Parameters
- `listener`
- : Function called when this event occurs. This function will be passed no arguments.
## Browser compatibility
{{Compat}}
## Examples
Create a sidebar pane, and log show and hide events.
```js
function onCreated(sidebarPane) {
sidebarPane.onShown.addListener(() => {
console.log("Shown");
});
sidebarPane.onHidden.addListener(() => {
console.log("Hidden");
});
}
browser.devtools.panels.elements.createSidebarPane("My pane").then(onCreated);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools.panels`](https://developer.chrome.com/docs/extensions/reference/devtools_panels/) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/extensionsidebarpane | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/panels/extensionsidebarpane/onshown/index.md | ---
title: devtools.panels.ExtensionSidebarPane.onShown
slug: Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane/onShown
page-type: webextension-api-event
browser-compat: webextensions.api.devtools.panels.ExtensionSidebarPane.onShown
---
{{AddonSidebar}}
Fired when the sidebar pane becomes visible as a result of the user switching to it.
## Syntax
```js-nolint
browser.devtools.panels.onShown.addListener(listener)
browser.devtools.panels.onShown.removeListener(listener)
browser.devtools.panels.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 this argument:
- `window`
- : `object`. The {{DOMxRef("window")}} object of the sidebar page, if a page was set with {{WebExtAPIRef("devtools.panels.ExtensionSidebarPane.setPage()","setPage()")}}.
## Browser compatibility
{{Compat}}
## Examples
Create a sidebar pane, and log show and hide events.
```js
function onCreated(sidebarPane) {
sidebarPane.onShown.addListener(() => {
console.log("Shown");
});
sidebarPane.onHidden.addListener(() => {
console.log("Hidden");
});
}
browser.devtools.panels.elements.createSidebarPane("My pane").then(onCreated);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools.panels`](https://developer.chrome.com/docs/extensions/reference/devtools_panels/) API.
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/inspectedwindow/index.md | ---
title: devtools.inspectedWindow
slug: Mozilla/Add-ons/WebExtensions/API/devtools/inspectedWindow
page-type: webextension-api-property
browser-compat: webextensions.api.devtools.inspectedWindow
---
{{AddonSidebar}}
> **Note:** This page describes the WebExtensions devtools APIs as they exist in Firefox 54. Although the APIs are based on the [Chrome devtools APIs](https://developer.chrome.com/docs/extensions/mv3/devtools/), there are still many features that are not yet implemented in Firefox, and therefore are not documented here. To see which features are currently missing please see [Limitations of the devtools APIs](/en-US/docs/Mozilla/Add-ons/WebExtensions/Extending_the_developer_tools#limitations_of_the_devtools_apis).
The `devtools.inspectedWindow` API lets a devtools extension interact with the window that the developer tools are attached to.
Like all the `devtools` APIs, this API is only available to code running in the document defined in the [devtools_page](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/devtools_page) manifest.json key, or in other devtools documents created by the extension (such as the document hosted by a panel the extension created). See [Extending the developer tools](/en-US/docs/Mozilla/Add-ons/WebExtensions/Extending_the_developer_tools) for more.
## Properties
- [`devtools.inspectedWindow.tabId`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/inspectedWindow/tabId)
- : The ID of the window that the developer tools are attached to.
## Functions
- [`devtools.inspectedWindow.eval()`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/inspectedWindow/eval)
- : Evaluate some JavaScript in the target window.
- [`devtools.inspectedWindow.reload()`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/inspectedWindow/reload)
- : Reload the target window's document.
{{WebExtExamples("h2")}}
## Browser compatibility
{{Compat}}
> **Note:** This API is based on Chromium's [`chrome.devtools.inspectedWindow`](https://developer.chrome.com/docs/extensions/reference/devtools_inspectedWindow/) 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/devtools/inspectedwindow | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/inspectedwindow/reload/index.md | ---
title: devtools.inspectedWindow.reload()
slug: Mozilla/Add-ons/WebExtensions/API/devtools/inspectedWindow/reload
page-type: webextension-api-function
browser-compat: webextensions.api.devtools.inspectedWindow.reload
---
{{AddonSidebar}}
Reloads the window that the devtools are attached to.
## Syntax
```js-nolint
browser.devtools.inspectedWindow.reload(
reloadOptions // object
)
```
### Parameters
- `reloadOptions` {{optional_inline}}
- : `object`. Options for the function, as follows:
- `ignoreCache` {{optional_inline}}
- : `boolean`. If true, this makes the reload ignore the browser cache (as if the user had pressed Shift+Ctrl+R).
- `userAgent` {{optional_inline}}
- : `string`. Set a custom user agent for the page. The string supplied here will be sent in the browser's [User-Agent](/en-US/docs/Web/HTTP/Headers/User-Agent) header, and will be returned by calls to [`navigator.userAgent`](/en-US/docs/Web/API/Navigator/userAgent) made by scripts running in the page.
- `injectedScript` {{optional_inline}}
- : `string`. Inject the given JavaScript expression into all frames in the page, before any other scripts.
## Browser compatibility
{{Compat}}
## Examples
Reload the inspected window, setting the user agent and injecting a script:
```js
const reloadButton = document.querySelector("#reload-button");
reloadButton.addEventListener("click", () => {
browser.devtools.inspectedWindow.reload({
injectedScript: "alert(navigator.userAgent);",
userAgent: "Not a real UA",
});
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools`](https://developer.chrome.com/docs/extensions/mv3/devtools/) 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/devtools/inspectedwindow | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/inspectedwindow/eval/index.md | ---
title: devtools.inspectedWindow.eval()
slug: Mozilla/Add-ons/WebExtensions/API/devtools/inspectedWindow/eval
page-type: webextension-api-function
browser-compat: webextensions.api.devtools.inspectedWindow.eval
---
{{AddonSidebar}}
Executes JavaScript in the window that the devtools are attached to.
This is somewhat like using {{WebExtAPIRef("tabs.executeScript()")}} to attach a content script, but with two main differences:
First, the JavaScript can use a set of [special commands that browsers typically provide in their devtools console implementation](#helpers): for example, using "$0" to refer to the element currently selected in the Inspector.
Second, the JavaScript you execute can see any changes made to the page by scripts that the page loaded. This is in contrast to content scripts, which see the page [as it would exist if no page scripts were loaded](/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts#dom_access). However, note that the isolation provided by content scripts is a deliberate security feature, intended to make it harder for malicious or uncooperative web pages to confuse or subvert WebExtensions APIs by redefining DOM functions and properties. This means you need to be very careful if you waive this protection by using `eval()`, and should use content scripts unless you need to use `eval()`.
The script is evaluated by default in the main frame of the page. The script must evaluate to a value that can be represented as JSON (meaning that, for example, it may not evaluate to a function or an object that contains any functions). By default, the script does not see any content scripts attached to the page.
You can't call `eval()` on privileged browser windows such as "about:addons".
You can optionally provide an `options` parameter, which includes options to evaluate the script in a different frame or in the context of attached content scripts. Note that Firefox does not yet support the `options` parameter.
The `eval()` function returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that resolves to the evaluated result of the script or to an error.
## Helpers
The script gets access to a number of objects that help the injected script interact with the developer tools. The following helpers are currently supported:
- `$0`
- : Contains a reference to the element that's currently selected in the devtools Inspector.
- `inspect()`
- : Given an object, if it is an DOM element in the page, selects it in the devtools Inspector, otherwise it creates an object preview in the webconsole.
[See some examples.](#examples)
## Syntax
```js-nolint
let evaluating = browser.devtools.inspectedWindow.eval(
expression, // string
options // object
)
```
### Parameters
- `expression`
- : `string`. The JavaScript expression to evaluate. The string must evaluate to an object that can be represented as JSON, or an exception will be thrown. For example, `expression` must not evaluate to a function.
- `options` {{optional_inline}}
- : `object`. Options for the function (Note that Firefox does not yet support this options), as follows:
- `frameURL` {{optional_inline}}
- : `string`. The URL of the frame in which to evaluate the expression. If this is omitted, the expression is evaluated in the main frame of the window.
- `useContentScriptContext` {{optional_inline}}
- : `boolean`. If `true`, evaluate the expression in the context of any content scripts that this extension has attached to the page. If you set this option, then you must have actually attached some content scripts to the page, or a Devtools error will be thrown.
- `contextSecurityOrigin` {{optional_inline}}
- : `string`. Evaluate the expression in the context of a content script attached by a different extension, whose origin matches the value given here. This overrides `useContentScriptContext`.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an `array` containing two elements.
If no error occurred, element 0 will contain the result of evaluating the expression, and element 1 will be `undefined`.
If an error occurred, element 0 will be `undefined`, and element 1 will contain an object giving details about the error. Two different sorts of errors are distinguished:
- errors encountered evaluating the JavaScript (for example, syntax errors in the expression). In this case, element 1 will contain:
- a boolean property `isException`, set to `true`
- a string property `value`, giving more details.
- other errors (for example, an expression that evaluates to an object that can't be represented as JSON). In this case, element 1 will contain:
- a boolean property `isError`, set to `true`
- a string property `code` containing an error code.
## Browser compatibility
{{Compat}}
## Examples
This tests whether jQuery is defined in the inspected window, and logs the result. Note that this wouldn't work in a content script, because even if jQuery were defined, the content script would not see it.
```js
function handleError(error) {
if (error.isError) {
console.log(`Devtools error: ${error.code}`);
} else {
console.log(`JavaScript error: ${error.value}`);
}
}
function handleResult(result) {
console.log(result);
if (result[0] !== undefined) {
console.log(`jQuery: ${result[0]}`);
} else if (result[1]) {
handleError(result[1]);
}
}
const checkjQuery = "typeof jQuery !== 'undefined'";
evalButton.addEventListener("click", () => {
browser.devtools.inspectedWindow.eval(checkjQuery).then(handleResult);
});
```
### Helper examples
This uses the `$0` helper to set the background color of the element that's currently selected in the Inspector:
```js
const evalButton = document.querySelector("#reddinate");
const evalString = "$0.style.backgroundColor = 'red'";
function handleError(error) {
if (error.isError) {
console.log(`Devtools error: ${error.code}`);
} else {
console.log(`JavaScript error: ${error.value}`);
}
}
function handleResult(result) {
if (result[1]) {
handleError(result[1]);
}
}
evalButton.addEventListener("click", () => {
browser.devtools.inspectedWindow.eval(evalString).then(handleResult);
});
```
This uses the `inspect()` helper to select the first \<h1> element in the page:
```js
const inspectButton = document.querySelector("#inspect");
const inspectString = "inspect(document.querySelector('h1'))";
function handleError(error) {
if (error.isError) {
console.log(`Devtools error: ${error.code}`);
} else {
console.log(`JavaScript error: ${error.value}`);
}
}
function handleResult(result) {
if (result[1]) {
handleError(result[1]);
}
}
inspectButton.addEventListener("click", () => {
browser.devtools.inspectedWindow.eval(inspectString).then(handleResult);
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools`](https://developer.chrome.com/docs/extensions/mv3/devtools/) 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/devtools/inspectedwindow | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/devtools/inspectedwindow/tabid/index.md | ---
title: devtools.inspectedWindow.tabId
slug: Mozilla/Add-ons/WebExtensions/API/devtools/inspectedWindow/tabId
page-type: webextension-api-property
browser-compat: webextensions.api.devtools.inspectedWindow.tabId
---
{{AddonSidebar}}
The ID of the {{WebExtAPIRef("tabs.Tab", "tab")}} that this instance of the devtools is attached to, represented as a number.
This can be sent to the extension's background page, so that background page can use the {{WebExtAPIRef("tabs")}} API to interact with the tab:
```js
// devtools-panel.js
const scriptToAttach = "document.body.innerHTML = 'Hi from the devtools';";
attachContentScriptButton.addEventListener("click", () => {
browser.runtime.sendMessage({
tabId: browser.devtools.inspectedWindow.tabId,
script: scriptToAttach,
});
});
```
```js
// background.js
function handleMessage(request, sender, sendResponse) {
browser.tabs.executeScript(request.tabId, {
code: request.script,
});
}
browser.runtime.onMessage.addListener(handleMessage);
```
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.devtools`](https://developer.chrome.com/docs/extensions/mv3/devtools/) 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 | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/management/index.md | ---
title: management
slug: Mozilla/Add-ons/WebExtensions/API/management
page-type: webextension-api
browser-compat: webextensions.api.management
---
{{AddonSidebar}}
Get information about installed add-ons.
With the `management` API you can:
- get information about installed add-ons
- enable/disable add-ons
- uninstall add-ons
- find out which permission warnings are given for particular add-ons or manifests
- get notifications of add-ons being installed, uninstalled, enabled, or disabled.
Most of these operations require the "management" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions). Operations that don't provide access to other add-ons don't require this permission.
## Types
- {{WebExtAPIRef("management.ExtensionInfo")}}
- : An object that contains information about an installed add-on.
## Functions
- {{WebExtAPIRef("management.getAll()")}}
- : Returns information about all installed add-ons.
- {{WebExtAPIRef("management.get()")}}
- : Returns information about a particular add-on, given its ID.
- {{WebExtAPIRef("management.getSelf()")}}
- : Returns information about the calling add-on.
- {{WebExtAPIRef("management.install()")}}
- : Installs a particular theme, given its URL at [addons.mozilla.org](https://addons.mozilla.org).
- {{WebExtAPIRef("management.uninstall()")}}
- : Uninstalls a particular add-on, given its ID.
- {{WebExtAPIRef("management.uninstallSelf()")}}
- : Uninstalls the calling add-on.
- {{WebExtAPIRef("management.getPermissionWarningsById()")}}
- : Get the set of permission warnings for a particular add-on, given its ID.
- {{WebExtAPIRef("management.getPermissionWarningsByManifest()")}}
- : Get the set of permission warnings that would be displayed for the given manifest string.
- {{WebExtAPIRef("management.setEnabled()")}}
- : Enable/disable a particular add-on, given its ID.
## Events
- {{WebExtAPIRef("management.onInstalled")}}
- : Fired when an add-on is installed.
- {{WebExtAPIRef("management.onUninstalled")}}
- : Fired when an add-on is uninstalled.
- {{WebExtAPIRef("management.onEnabled")}}
- : Fired when an add-on is enabled.
- {{WebExtAPIRef("management.onDisabled")}}
- : Fired when an add-on is disabled.
## Browser compatibility
{{Compat}}
{{WebExtExamples("h2")}}
> **Note:** This API is based on Chromium's [`chrome.management`](https://developer.chrome.com/docs/extensions/reference/management/) API. This documentation is derived from [`management.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/management.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/management | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/management/onuninstalled/index.md | ---
title: management.onUninstalled()
slug: Mozilla/Add-ons/WebExtensions/API/management/onUninstalled
page-type: webextension-api-event
browser-compat: webextensions.api.management.onUninstalled
---
{{AddonSidebar}}
Fired when an add-on is uninstalled.
This API requires the "management" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions).
## Syntax
```js-nolint
browser.management.onUninstalled.addListener(listener)
browser.management.onUninstalled.removeListener(listener)
browser.management.onUninstalled.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 this argument:
- `info`
- : [`ExtensionInfo`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/management/ExtensionInfo): info about the add-on that was uninstalled.
## Browser compatibility
{{Compat}}
## Examples
Log the names of add-ons when they are uninstalled:
```js
browser.management.onUninstalled.addListener((info) => {
console.log(`${info.name} was uninstalled`);
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.management`](https://developer.chrome.com/docs/extensions/reference/management/#event-onUninstalled) API. This documentation is derived from [`management.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/management.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/management | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/management/oninstalled/index.md | ---
title: management.onInstalled()
slug: Mozilla/Add-ons/WebExtensions/API/management/onInstalled
page-type: webextension-api-event
browser-compat: webextensions.api.management.onInstalled
---
{{AddonSidebar}}
Fired when an add-on is installed.
This API requires the "management" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions).
## Syntax
```js-nolint
browser.management.onInstalled.addListener(listener)
browser.management.onInstalled.removeListener(listener)
browser.management.onInstalled.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 this argument:
- `info`
- : [`ExtensionInfo`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/management/ExtensionInfo): info about the add-on that was installed.
## Browser compatibility
{{Compat}}
## Examples
Log the names of add-ons when they are installed:
```js
browser.management.onInstalled.addListener((info) => {
console.log(`${info.name} was installed`);
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.management`](https://developer.chrome.com/docs/extensions/reference/management/#event-onInstalled) API. This documentation is derived from [`management.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/management.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/management | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/management/get/index.md | ---
title: management.get()
slug: Mozilla/Add-ons/WebExtensions/API/management/get
page-type: webextension-api-function
browser-compat: webextensions.api.management.get
---
{{AddonSidebar}}
Retrieves an {{WebExtAPIRef("management.ExtensionInfo", "ExtensionInfo")}} object containing information about the specified add-on.
This API requires the "management" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions).
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let gettingInfo = browser.management.get(
id // string
)
```
### Parameters
- `id`
- : `string`. ID of the add-on whose info you want to retrieve.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an {{WebExtAPIRef("management.ExtensionInfo", "ExtensionInfo")}} object, containing information about the add-on. The promise will be rejected if no extension with the given ID is installed or the extension is not allowed to be accessed by the caller.
## Browser compatibility
{{Compat}}
## Examples
Log the name of the add-on whose ID is "my-add-on":
```js
let id = "my-add-on";
function got(info) {
console.log(info.name);
}
let getting = browser.management.get(id);
getting.then(got);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.management`](https://developer.chrome.com/docs/extensions/reference/management/#method-get) API. This documentation is derived from [`management.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/management.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/management | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/management/install/index.md | ---
title: management.install()
slug: Mozilla/Add-ons/WebExtensions/API/management/install
page-type: webextension-api-function
browser-compat: webextensions.api.management.install
---
{{AddonSidebar}}
Installs and enables a theme extension from the given URL.
This API requires the "management" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) and will only work with signed themes.
This is an asynchronous function that returns a [Promise](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
browser.management.install(options)
```
### Parameters
- options
- : An object that includes the URL of the XPI file of the theme at [addons.mozilla.org](https://addons.mozilla.org) and an optional a hash of the XPI file, using sha256 or stronger.
### Return value
A [Promise](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an object, containing the `ExtensionID` defined for the theme in manifest.json.
## Browser compatibility
{{Compat}}
## Examples
Cycle through a list of themes:
```js
"use strict";
const themes = [
"https://addons.mozilla.org/firefox/downloads/file/1063216/insightscare-1.0-fx.xpi",
"https://addons.mozilla.org/firefox/downloads/file/1063419/orange_roses-1.0-fx.xpi",
"https://addons.mozilla.org/firefox/downloads/file/1062647/sticktoyourguns-2.0-fx.xpi",
"https://addons.mozilla.org/firefox/downloads/file/0/bad_url.xpi",
];
let current;
async function install(url) {
try {
current = url;
const { id } = await browser.management.install({ url });
console.log(`Theme installed: ${id}`);
} catch (e) {
console.error(`Installation failed: ${e}`);
}
}
browser.browserAction.onClicked.addListener(() => {
const id = themes.indexOf(current);
install(themes[(id + 1) % themes.length]);
});
for (const url of themes) {
browser.menus.create({
title: url,
onclick: () => install(url),
contexts: ["browser_action"],
});
}
```
{{WebExtExamples}}
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/management | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/management/uninstall/index.md | ---
title: management.uninstall()
slug: Mozilla/Add-ons/WebExtensions/API/management/uninstall
page-type: webextension-api-function
browser-compat: webextensions.api.management.uninstall
---
{{AddonSidebar}}
Uninstalls an add-on, given its ID.
This API requires the "management" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions).
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let uninstalling = browser.management.uninstall(
id, // string
options // object
)
```
### Parameters
- `id`
- : `string`. ID of the add-on to uninstall.
- `options` {{optional_inline}}
- : `object`. Object which may contain a single property, `showConfirmDialog`. If `showConfirmDialog` is `true`, the browser will show a dialog asking the user to confirm that the add-on should be uninstalled.
<!---->
- If `id` is the calling add-on's ID, `showConfirmDialog` defaults to `false`.
- If `id` is a the ID of a different add-on, the `showConfirmDialog` option is ignored and the confirmation dialog is always shown.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be rejected with an error message if the user canceled uninstall.
## Browser compatibility
{{Compat}}
## Examples
Uninstall the add-on whose ID is "my-addon-id", asking the user to confirm. In the callback, check whether the user canceled uninstallation.
Note that we haven't passed a fulfillment handler because if uninstallation succeeds, the add-on is no longer around to handle it.
```js
let id = "my-addon-id";
function onCanceled(error) {
console.log(`Uninstall canceled: ${error}`);
}
let uninstalling = browser.management.uninstall(id);
uninstalling.then(null, onCanceled);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.management`](https://developer.chrome.com/docs/extensions/reference/management/#method-uninstall) API. This documentation is derived from [`management.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/management.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/management | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/management/setenabled/index.md | ---
title: management.setEnabled()
slug: Mozilla/Add-ons/WebExtensions/API/management/setEnabled
page-type: webextension-api-function
browser-compat: webextensions.api.management.setEnabled
---
{{AddonSidebar}}
Enables or disables the given add-on.
This function must usually be called in the context of a user action, such as the click handler for a button. The browser may also ask the user to confirm the change.
This API requires the "management" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions).
It is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
The function allows enabling/disabling of theme addons, but will return an error if used to enable or disable other types of web extension.
## Syntax
```js-nolint
let settingEnabled = browser.management.setEnabled(
id, // string
enabled // boolean
)
```
### Parameters
- `id`
- : `string`. ID of the add-on to enable/disable.
- `enabled`
- : `boolean`. Whether to enable or disable the add-on.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with no arguments when the add-on has been disabled or enabled.
## Browser compatibility
{{Compat}}
## Examples
Toggle enable/disable for the add-on whose ID is "my-add-on":
```js
let id = "my-add-on";
function toggleEnabled(id) {
let getting = browser.management.get(id);
getting.then((info) => {
browser.management.setEnabled(id, !info.enabled);
});
}
toggleEnabled(id);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.management`](https://developer.chrome.com/docs/extensions/reference/management/#method-setEnabled) API. This documentation is derived from [`management.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/management.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/management | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/management/getself/index.md | ---
title: management.getSelf()
slug: Mozilla/Add-ons/WebExtensions/API/management/getSelf
page-type: webextension-api-function
browser-compat: webextensions.api.management.getSelf
---
{{AddonSidebar}}
Retrieves an {{WebExtAPIRef("management.ExtensionInfo", "ExtensionInfo")}} object containing information about the calling add-on.
This API _does not_ require the "management" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions).
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let gettingSelf = browser.management.getSelf()
```
### Parameters
None.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an {{WebExtAPIRef("management.ExtensionInfo", "ExtensionInfo")}} object, containing information about the add-on.
## Browser compatibility
{{Compat}}
## Examples
Log the add-on's name:
```js
function gotSelf(info) {
console.log(`Add-on name: ${info.name}`);
}
const gettingSelf = browser.management.getSelf();
gettingSelf.then(gotSelf);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.management`](https://developer.chrome.com/docs/extensions/reference/management/#method-getSelf) API. This documentation is derived from [`management.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/management.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/management | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/management/getpermissionwarningsbyid/index.md | ---
title: management.getPermissionWarningsById()
slug: Mozilla/Add-ons/WebExtensions/API/management/getPermissionWarningsById
page-type: webextension-api-function
browser-compat: webextensions.api.management.getPermissionWarningsById
---
{{AddonSidebar}}
When the user installs or upgrades an add-on, the browser may warn the user about any particularly powerful [permissions](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) that the add-on has requested. Not all permissions result in warnings, and this behavior is not standardized across browsers.
Given the ID of an add-on, this function returns the permission warnings for it as an array of strings.
This API requires the "management" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions).
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let gettingWarnings = browser.management.getPermissionWarningsById(
id // string
)
```
### Parameters
- `id`
- : `string`. ID of the add-on whose permission warnings you want to retrieve.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an array of strings, each of which contains the text of a permission warning.
## Browser compatibility
{{Compat}}
## Examples
Log the permission warnings for the add-on whose ID is "my-add-on":
```js
let id = "my-add-on";
function gotWarnings(warnings) {
for (const warning of warnings) {
console.log(warning);
}
}
browser.management.getPermissionWarningsById(id).then(gotWarnings);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.management`](https://developer.chrome.com/docs/extensions/reference/management/#method-getPermissionWarningsById) API. This documentation is derived from [`management.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/management.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/management | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/management/uninstallself/index.md | ---
title: management.uninstallSelf()
slug: Mozilla/Add-ons/WebExtensions/API/management/uninstallSelf
page-type: webextension-api-function
browser-compat: webextensions.api.management.uninstallSelf
---
{{AddonSidebar}}
Uninstalls the calling add-on.
This API _does not_ require the "management" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions).
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let uninstallingSelf = browser.management.uninstallSelf(
options // object
)
```
### Parameters
- `options` {{optional_inline}}
- : `object`. Object which may two properties, both optional:
- `showConfirmDialog` {{optional_inline}}
- : Boolean. If `showConfirmDialog` is `true`, the browser will show a dialog asking the user to confirm that the add-on should be uninstalled. Defaults to `false`.
- `dialogMessage` {{optional_inline}}
- : String. An extra message that will be displayed in the confirmation dialog.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be rejected with an error message if the user canceled uninstall.
## Browser compatibility
{{Compat}}
## Examples
Uninstall the add-on, asking the user to confirm. In the callback, check whether the user canceled uninstallation.
Note that we haven't passed a fulfillment handler because if uninstallation succeeds, the add-on is no longer around to handle it.
```js
function onCanceled(error) {
console.log(`Canceled: ${error}`);
}
let uninstalling = browser.management.uninstallSelf({
showConfirmDialog: true,
});
uninstalling.then(null, onCanceled);
```
The same, but also adding a custom message to the dialog:
```js
function onCanceled(error) {
console.log(`Canceled: ${error}`);
}
let uninstalling = browser.management.uninstallSelf({
showConfirmDialog: true,
dialogMessage: "Testing self-uninstall",
});
uninstalling.then(null, onCanceled);
```
{{WebExtExamples}}
> **Note:**
>
> This API is based on Chromium's [`chrome.management`](https://developer.chrome.com/docs/extensions/reference/management/#method-uninstallSelf) API. This documentation is derived from [`management.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/management.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/management | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/management/ondisabled/index.md | ---
title: management.onDisabled()
slug: Mozilla/Add-ons/WebExtensions/API/management/onDisabled
page-type: webextension-api-event
browser-compat: webextensions.api.management.onDisabled
---
{{AddonSidebar}}
Fired when an add-on is disabled.
This API requires the "management" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions).
## Syntax
```js-nolint
browser.management.onDisabled.addListener(listener)
browser.management.onDisabled.removeListener(listener)
browser.management.onDisabled.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 this argument:
- `info`
- : [`ExtensionInfo`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/management/ExtensionInfo): info about the add-on that was disabled.
## Browser compatibility
{{Compat}}
## Examples
Log the names of add-ons when they are disabled:
```js
browser.management.onDisabled.addListener((info) => {
console.log(`${info.name} was disabled`);
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.management`](https://developer.chrome.com/docs/extensions/reference/management/#event-onDisabled) API. This documentation is derived from [`management.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/management.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/management | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/management/getall/index.md | ---
title: management.getAll()
slug: Mozilla/Add-ons/WebExtensions/API/management/getAll
page-type: webextension-api-function
browser-compat: webextensions.api.management.getAll
---
{{AddonSidebar}}
Retrieves an array of {{WebExtAPIRef("management.ExtensionInfo", "ExtensionInfo")}} objects, one for each installed add-on.
Note that Google Chrome retrieves apps as well as add-ons. In Chrome you can distinguish apps from add-ons using the `type` property of {{WebExtAPIRef("management.ExtensionInfo", "ExtensionInfo")}}.
This API requires the "management" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions).
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let gettingAll = browser.management.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("management.ExtensionInfo", "ExtensionInfo")}} objects, one for each installed add-on.
## Browser compatibility
{{Compat}}
## Examples
Log the name of all installed add-ons:
```js
function gotAll(infoArray) {
for (const info of infoArray) {
if (info.type === "extension") {
console.log(info.name);
}
}
}
let gettingAll = browser.management.getAll();
gettingAll.then(gotAll);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.management`](https://developer.chrome.com/docs/extensions/reference/management/#method-getAll) API. This documentation is derived from [`management.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/management.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/management | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/management/extensioninfo/index.md | ---
title: ExtensionInfo
slug: Mozilla/Add-ons/WebExtensions/API/management/ExtensionInfo
page-type: webextension-api-type
browser-compat: webextensions.api.management.ExtensionInfo
---
{{AddonSidebar}}
An `ExtensionInfo` object contains information about an add-on.
## Type
It is an object with the following properties:
- `description`
- : `string`. The add-on's description, taken from the manifest.json [description](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/description) key.
- `disabledReason`
- : `string`. If the add-on is disabled, the reason it was disabled. One of "unknown" or "permissions_increase".
- `enabled`
- : `boolean`. Whether or not the add-on is currently enabled.
- `homepageUrl`
- : `string`. The add-on's homepage URL, taken from the manifest.json [homepage_url](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/homepage_url) key.
- `hostPermissions`
- : `array` of `string`. The add-on's [host permissions](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#host_permissions).
- `icons`
- : `array` of `object`. Information about the add-on's icons. An array of objects, one for each icon. Each object contains two properties:
- `size`: an integer representing the icon's width and height in pixels.
- `url`: a string containing a relative URL to the icon, starting at the add-on's root.
- `id`
- : `string`. The add-on's ID.
- `installType`
- : `string`. String describing how the add-on was installed. One of the following:
- "admin": the add-on was installed because of an administrative policy.
- "development": the add-on was installed unpacked from disk.
- "normal": the add-on was installed normally from an install package.
- "sideload": the add-on was installed by some other software on the user's computer.
- "other": the add-on was installed in some other way.
- `mayDisable`
- : `boolean`. Whether this add-on can be disabled or uninstalled by the user.
- `name`
- : `string`. The add-on's name, taken from the manifest.json [name](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/name) key.
- `offlineEnabled`
- : `boolean`. Whether the add-on claims to support offline.
- `optionsUrl`
- : `string`. URL for the item's [options page](/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Options_pages), if it has one. This is a relative URL, starting at the add-on's root.
- `permissions`
- : `array` of `string`. The add-on's [API permissions](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#api_permissions).
- `shortName`
- : `string`. A short version of the add-on's name, taken from the manifest.json [short_name](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/short_name) key.
- `type`
- : `string`. String describing the type of add-on. This is used to distinguish extensions from apps and themes. It may take any of the following values:
- "extension": most common type of add-on.
- "hosted_app"
- "packaged_app"
- "legacy_packaged_app"
- "theme"
- `updateUrl`
- : `string`. URL for updates to this add-on, taken from the manifest.json [browser_specific_settings](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_specific_settings) key.
- `version`
- : `string`. Version of this add-on, taken from the manifest.json [version](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/version) key.
- `versionName`
- : `string`. Descriptive name for this add-on's version, taken from the manifest.json [version_name](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/version_name) key.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.management`](https://developer.chrome.com/docs/extensions/reference/management/#type-ExtensionInfo) API. This documentation is derived from [`management.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/management.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/management | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/management/getpermissionwarningsbymanifest/index.md | ---
title: management.getPermissionWarningsByManifest()
slug: Mozilla/Add-ons/WebExtensions/API/management/getPermissionWarningsByManifest
page-type: webextension-api-function
browser-compat: webextensions.api.management.getPermissionWarningsByManifest
---
{{AddonSidebar}}
When the user installs or upgrades an add-on, the browser may warn the user about any particularly powerful [permissions](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) that the add-on has requested. Not all permissions result in warnings, and this behavior is not standardized across browsers.
Given the text of a [manifest.json](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json) file, this function returns the permission warnings that would be given for the resulting add-on, as an array of strings.
This API _does not_ require the "management" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions).
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let gettingWarnings = browser.management.getPermissionWarningsByManifest(
manifestString // string
)
```
### Parameters
- `manifestString`
- : `string`. String containing the manifest file. This must be a valid manifest: for example, it must contain all the mandatory manifest keys.
### Return value
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an array of strings, each of which contains the text of a permission warning.
## Browser compatibility
{{Compat}}
## Examples
Log the permission warnings for the given manifest file:
```js
let manifest = {
manifest_version: 2,
name: "test",
version: "1.0",
permissions: ["management", "<all_urls>"],
};
let manifestString = JSON.stringify(manifest);
function gotWarnings(warnings) {
console.log(warnings);
}
function gotError(error) {
console.log(`Error: ${error}`);
}
let gettingWarnings =
browser.management.getPermissionWarningsByManifest(manifestString);
gettingWarnings.then(gotWarnings, gotError);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.management`](https://developer.chrome.com/docs/extensions/reference/management/#method-getPermissionWarningsByManifest) API. This documentation is derived from [`management.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/management.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/management | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/management/onenabled/index.md | ---
title: management.onEnabled()
slug: Mozilla/Add-ons/WebExtensions/API/management/onEnabled
page-type: webextension-api-event
browser-compat: webextensions.api.management.onEnabled
---
{{AddonSidebar}}
The event listener called when the `enabled` event is fired, indicating that an add-on is now enabled.
This API requires the "management" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions).
## Syntax
```js-nolint
browser.management.onEnabled.addListener(listener)
browser.management.onEnabled.removeListener(listener)
browser.management.onEnabled.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 this argument:
- `info`
- : [`ExtensionInfo`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/management/ExtensionInfo): info about the add-on that was enabled.
## Browser compatibility
{{Compat}}
## Examples
Log the names of add-ons when they are enabled:
```js
browser.management.onEnabled.addListener((info) => {
console.log(`${info.name} was enabled`);
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.management`](https://developer.chrome.com/docs/extensions/reference/management/#event-onEnabled) API. This documentation is derived from [`management.json`](https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/management.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/browseraction/index.md | ---
title: browserAction
slug: Mozilla/Add-ons/WebExtensions/API/browserAction
page-type: webextension-api
browser-compat: webextensions.api.browserAction
---
{{AddonSidebar}}
Adds a button to the browser's toolbar.
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 `browser_action` {{WebExtAPIRef("menus.ContextType")}}.
You can define most of a browser action's properties declaratively using the [`browser_action`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_action) key in the manifest.json.
With the `browserAction` API, you can:
- use {{WebExtAPIRef("browserAction.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("browserAction.ColorArray")}}
- : An array of four integers in the range 0-255 defining an RGBA color.
- {{WebExtAPIRef("browserAction.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("browserAction.setTitle()")}}
- : Sets the browser action's title. This will be displayed in a tooltip.
- {{WebExtAPIRef("browserAction.getTitle()")}}
- : Gets the browser action's title.
- {{WebExtAPIRef("browserAction.setIcon()")}}
- : Sets the browser action's icon.
- {{WebExtAPIRef("browserAction.setPopup()")}}
- : Sets the HTML document to be opened as a popup when the user clicks on the browser action's icon.
- {{WebExtAPIRef("browserAction.getPopup()")}}
- : Gets the HTML document set as the browser action's popup.
- {{WebExtAPIRef("browserAction.openPopup()")}}
- : Open the browser action's popup.
- {{WebExtAPIRef("browserAction.setBadgeText()")}}
- : Sets the browser action's badge text. The badge is displayed on top of the icon.
- {{WebExtAPIRef("browserAction.getBadgeText()")}}
- : Gets the browser action's badge text.
- {{WebExtAPIRef("browserAction.setBadgeBackgroundColor()")}}
- : Sets the badge's background color.
- {{WebExtAPIRef("browserAction.getBadgeBackgroundColor()")}}
- : Gets the badge's background color.
- {{WebExtAPIRef("browserAction.setBadgeTextColor()")}}
- : Sets the badge's text color.
- {{WebExtAPIRef("browserAction.getBadgeTextColor()")}}
- : Gets the badge's text color.
- {{WebExtAPIRef("browserAction.getUserSettings()")}}
- : Gets the user-specified settings for the browser action.
- {{WebExtAPIRef("browserAction.enable()")}}
- : Enables the browser action for a tab. By default, browser actions are enabled for all tabs.
- {{WebExtAPIRef("browserAction.disable()")}}
- : Disables the browser action for a tab, meaning that it cannot be clicked when that tab is active.
- {{WebExtAPIRef("browserAction.isEnabled()")}}
- : Checks whether the browser action is enabled or not.
## Events
- {{WebExtAPIRef("browserAction.onClicked")}}
- : Fired when a browser action icon is clicked. This event will not fire if the browser action has a popup.
## Browser compatibility
{{Compat}}
{{WebExtExamples("h2")}}
> **Note:** This API is based on Chromium's [`chrome.browserAction`](https://developer.chrome.com/docs/extensions/reference/browserAction/) 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/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/enable/index.md | ---
title: browserAction.enable()
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/enable
page-type: webextension-api-function
browser-compat: webextensions.api.browserAction.enable
---
{{AddonSidebar}}
Enables the browser action for a tab. By default, browser actions are enabled for all tabs.
## Syntax
```js-nolint
browser.browserAction.enable(
tabId // optional integer
)
```
### Parameters
- `tabId` {{optional_inline}}
- : `integer`. The id of the tab for which you want to enable the browser action.
## Browser compatibility
{{Compat}}
## Examples
Disable the browser action when clicked, and re-enable it every time a new tab is opened:
```js
browser.tabs.onCreated.addListener(() => {
browser.browserAction.enable();
});
browser.browserAction.onClicked.addListener(() => {
browser.browserAction.disable();
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.browserAction`](https://developer.chrome.com/docs/extensions/reference/browserAction/#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/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/getbadgetextcolor/index.md | ---
title: browserAction.getBadgeTextColor()
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/getBadgeTextColor
page-type: webextension-api-function
browser-compat: webextensions.api.browserAction.getBadgeTextColor
---
{{AddonSidebar}}
Gets the text color for the browser action's badge.
From Firefox 63, unless the badge text color is explicitly set using {{WebExtAPIRef("browserAction.setBadgeTextColor()")}}, then the badge text color will be 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 will be 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.browserAction.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('browserAction.ColorArray')}}.
## Browser compatibility
{{Compat}}
## Examples
Log the badge's text color:
```js
function onGot(color) {
console.log(color);
}
function onFailure(error) {
console.log(error);
}
browser.browserAction.getBadgeTextColor({}).then(onGot, onFailure);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.browserAction`](https://developer.chrome.com/docs/extensions/reference/browserAction/#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/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/getpopup/index.md | ---
title: browserAction.getPopup()
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/getPopup
page-type: webextension-api-function
browser-compat: webextensions.api.browserAction.getPopup
---
{{AddonSidebar}}
Gets the HTML document set as the popup for this browser 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.browserAction.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`.
## Browser compatibility
{{Compat}}
## Examples
Get the popup's URL:
```js
function gotPopup(popupURL) {
console.log(popupURL);
}
let gettingPopup = browser.browserAction.getPopup({});
gettingPopup.then(gotPopup);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.browserAction`](https://developer.chrome.com/docs/extensions/reference/browserAction/#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/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/getbadgebackgroundcolor/index.md | ---
title: browserAction.getBadgeBackgroundColor()
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/getBadgeBackgroundColor
page-type: webextension-api-function
browser-compat: webextensions.api.browserAction.getBadgeBackgroundColor
---
{{AddonSidebar}}
Gets the background color of the browser action's badge.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
browser.browserAction.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('browserAction.ColorArray')}}.
## Browser compatibility
{{Compat}}
## Examples
Log the badge's background color:
```js
function onGot(color) {
console.log(color);
}
function onFailure(error) {
console.log(error);
}
browser.browserAction.getBadgeBackgroundColor({}).then(onGot, onFailure);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.browserAction`](https://developer.chrome.com/docs/extensions/reference/browserAction/#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/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/colorarray/index.md | ---
title: browserAction.ColorArray
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/ColorArray
page-type: webextension-api-type
browser-compat: webextensions.api.browserAction.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]`.
## Browser compatibility
{{Compat}}
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.browserAction`](https://developer.chrome.com/docs/extensions/reference/browserAction/#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/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/setbadgebackgroundcolor/index.md | ---
title: browserAction.setBadgeBackgroundColor()
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/setBadgeBackgroundColor
page-type: webextension-api-function
browser-compat: webextensions.api.browserAction.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.
From Firefox 63, unless the badge text color is explicitly set using {{WebExtAPIRef("browserAction.setBadgeTextColor()")}}, then the badge text color will be 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 will be 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.browserAction.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('browserAction.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.
## Browser compatibility
{{Compat}}
The default color in Firefox is: `[217, 0, 0, 255]`.
## Examples
A background color that starts off as red, and turns green when the browser action is clicked:
```js
browser.browserAction.setBadgeText({ text: "1234" });
browser.browserAction.setBadgeBackgroundColor({ color: "red" });
browser.browserAction.onClicked.addListener(() => {
browser.browserAction.setBadgeBackgroundColor({ color: "green" });
});
```
Set the badge background color only for the active tab:
```js
browser.browserAction.setBadgeText({ text: "1234" });
browser.browserAction.setBadgeBackgroundColor({ color: "red" });
browser.browserAction.onClicked.addListener((tab) => {
browser.browserAction.setBadgeBackgroundColor({
color: "green",
tabId: tab.id,
});
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.browserAction`](https://developer.chrome.com/docs/extensions/reference/browserAction/#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/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/settitle/index.md | ---
title: browserAction.setTitle()
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/setTitle
page-type: webextension-api-function
browser-compat: webextensions.api.browserAction.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 given tab or the given window. Tabs or windows without a specific title will 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.
## Syntax
```js-nolint
browser.browserAction.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("browserAction.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.
## 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.browserAction.setTitle({ title: "that" });
} else {
browser.browserAction.setTitle({ title: "this" });
}
}
browser.browserAction.onClicked.addListener(() => {
let gettingTitle = browser.browserAction.getTitle({});
gettingTitle.then(toggleTitle);
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.browserAction`](https://developer.chrome.com/docs/extensions/reference/browserAction/#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/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/seticon/index.md | ---
title: browserAction.setIcon()
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/setIcon
page-type: webextension-api-function
browser-compat: webextensions.api.browserAction.setIcon
---
{{AddonSidebar}}
Sets the icon for the browser action.
You can specify a single icon as either the path to an image file or a {{WebExtAPIRef('browserAction.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.browserAction.setIcon(
details // object
)
```
### Parameters
- `details`
- : `object`. An object containing either `imageData` or `path` properties, and optionally a `tabId` property.
- `imageData` {{optional_inline}}
- : `{{WebExtAPIRef('browserAction.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.
## Browser compatibility
{{Compat}}
## 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.browserAction.setIcon({ path: "icons/listening-on.svg" });
}
function stopListening() {
browser.webRequest.onHeadersReceived.removeListener(logResponseHeaders);
browser.browserAction.setIcon({ path: "icons/listening-off.svg" });
}
function toggleListener() {
if (browser.webRequest.onHeadersReceived.hasListener(logResponseHeaders)) {
stopListening();
} else {
startListening();
}
}
browser.browserAction.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.browserAction.onClicked.addListener(() => {
browser.browserAction.setIcon({ imageData: getImageData() });
});
```
The following snippet updates the icon when the user clicks it, but only for the active tab:
```js
browser.browserAction.onClicked.addListener((tab) => {
browser.browserAction.setIcon({
tabId: tab.id,
path: "icons/updated-48.png",
});
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.browserAction`](https://developer.chrome.com/docs/extensions/reference/browserAction/#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/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/onclicked/index.md | ---
title: browserAction.onClicked
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/onClicked
page-type: webextension-api-event
browser-compat: webextensions.api.browserAction.onClicked
---
{{AddonSidebar}}
Fired when a browser action icon is clicked. This event will not fire if the browser action has a popup.
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.browserAction.onClicked.addListener(listener)
browser.browserAction.onClicked.removeListener(listener)
browser.browserAction.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.
## Browser compatibility
{{Compat}}
## Examples
When the user clicks the icon, disable it for the active tab, and log the tab's URL:
```js
browser.browserAction.onClicked.addListener((tab) => {
// disable the active tab
browser.browserAction.disable(tab.id);
// requires the "tabs" or "activeTab" permission, or host permissions for the URL
console.log(tab.url);
});
```
{{WebExtExamples}}
> **Note:**
>
> This API is based on Chromium's [`chrome.browserAction`](https://developer.chrome.com/docs/extensions/reference/browserAction/#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/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/isenabled/index.md | ---
title: browserAction.isEnabled()
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/isEnabled
page-type: webextension-api-function
browser-compat: webextensions.api.browserAction.isEnabled
---
{{AddonSidebar}}
Returns `true` if the browser action is enabled.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let gettingIsEnabled = browser.browserAction.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.
## Browser compatibility
{{Compat}}
## Examples
Check the global state:
```js
browser.browserAction.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.browserAction.isEnabled({
tabId: tabs[0].id,
});
console.log(enabled);
}
```
{{WebExtExamples}}
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/getusersettings/index.md | ---
title: browserAction.getUserSettings()
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/getUserSettings
page-type: webextension-api-function
browser-compat: webextensions.api.browserAction.getUserSettings
---
{{AddonSidebar}}
Gets the user-specified settings for the browser action.
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.browserAction.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 browser action is pinned or not:
```js
function gotSettings(userSettings) {
if (userSettings.isOnToolbar) {
console.log("Browser action is pinned to toolbar.");
} else {
console.log("Browser action is not pinned to toolbar.");
}
}
let gettingUserSettings = browser.browserAction.getUserSettings();
gettingUserSettings.then(gotSettings);
```
{{WebExtExamples}}
## Browser compatibility
{{Compat}}
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/gettitle/index.md | ---
title: browserAction.getTitle()
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/getTitle
page-type: webextension-api-function
browser-compat: webextensions.api.browserAction.getTitle
---
{{AddonSidebar}}
Gets the browser action's title.
Just as you can set the title on a per-tab basis using {{WebExtAPIRef("browserAction.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.browserAction.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.
## 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.browserAction.setTitle({ title: "that" });
} else {
browser.browserAction.setTitle({ title: "this" });
}
}
browser.browserAction.onClicked.addListener(() => {
let gettingTitle = browser.browserAction.getTitle({});
gettingTitle.then(toggleTitle);
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.browserAction`](https://developer.chrome.com/docs/extensions/reference/browserAction/#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/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/openpopup/index.md | ---
title: browserAction.openPopup()
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/openPopup
page-type: webextension-api-function
browser-compat: webextensions.api.browserAction.openPopup
---
{{AddonSidebar}}
Open the browser action's popup.
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.browserAction.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.
## 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.browserAction.openPopup();
});
```
{{WebExtExamples}}
| 0 |
data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/getbadgetext/index.md | ---
title: browserAction.getBadgeText()
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/getBadgeText
page-type: webextension-api-function
browser-compat: webextensions.api.browserAction.getBadgeText
---
{{AddonSidebar}}
Gets the browser action's badge text.
This is an asynchronous function that returns a [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
let gettingText = browser.browserAction.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.
## Browser compatibility
{{Compat}}
## Examples
Log the badge text:
```js
function gotBadgeText(text) {
console.log(text);
}
let gettingBadgeText = browser.browserAction.getBadgeText({});
gettingBadgeText.then(gotBadgeText);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.browserAction`](https://developer.chrome.com/docs/extensions/reference/browserAction/#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/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/setbadgetext/index.md | ---
title: browserAction.setBadgeText()
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/setBadgeText
page-type: webextension-api-function
browser-compat: webextensions.api.browserAction.setBadgeText
---
{{AddonSidebar}}
Sets the badge text for the browser action. The badge is displayed on top of the icon.
Tabs without a specific badge text will inherit the global badge text, which is `""` by default.
## Syntax
```js-nolint
browser.browserAction.setBadgeText(
details // object
)
```
This API is also available as `chrome.browserAction.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.
## Browser compatibility
{{Compat}}
## Examples
Add a badge indicating how many times the user clicked the button:
```js
let clicks = 0;
function increment() {
browser.browserAction.setBadgeText({ text: (++clicks).toString() });
}
browser.browserAction.onClicked.addListener(increment);
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.browserAction`](https://developer.chrome.com/docs/extensions/reference/browserAction/#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/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/disable/index.md | ---
title: browserAction.disable()
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/disable
page-type: webextension-api-function
browser-compat: webextensions.api.browserAction.disable
---
{{AddonSidebar}}
Disables the browser action for a tab, meaning that it cannot be clicked when that tab is active.
## Syntax
```js-nolint
browser.browserAction.disable(
tabId // optional integer
)
```
### Parameters
- `tabId` {{optional_inline}}
- : `integer`. The id of the tab for which you want to disable the browser action.
## Browser compatibility
{{Compat}}
## Examples
Disable the browser action when clicked, and re-enable it every time a new tab is opened:
```js
browser.tabs.onCreated.addListener(() => {
browser.browserAction.enable();
});
browser.browserAction.onClicked.addListener(() => {
browser.browserAction.disable();
});
```
Disable the browser action only for the active tab:
```js
browser.browserAction.onClicked.addListener((tab) => {
browser.browserAction.disable(tab.id);
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.browserAction`](https://developer.chrome.com/docs/extensions/reference/browserAction/#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/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/setpopup/index.md | ---
title: browserAction.setPopup()
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/setPopup
page-type: webextension-api-function
browser-compat: webextensions.api.browserAction.setPopup
---
{{AddonSidebar}}
Sets the HTML document that will be 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.
## Syntax
```js-nolint
browser.browserAction.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("browserAction.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.
## Browser compatibility
{{Compat}}
## 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.browserAction.setPopup({ popup: "/popup/popup1.html" });
} else if (info.menuItemId === "popup-2") {
browser.browserAction.setPopup({ popup: "/popup/popup2.html" });
}
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.browserAction`](https://developer.chrome.com/docs/extensions/reference/browserAction/#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/browseraction | data/mdn-content/files/en-us/mozilla/add-ons/webextensions/api/browseraction/setbadgetextcolor/index.md | ---
title: browserAction.setBadgeTextColor()
slug: Mozilla/Add-ons/WebExtensions/API/browserAction/setBadgeTextColor
page-type: webextension-api-function
browser-compat: webextensions.api.browserAction.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.
## Syntax
```js-nolint
browser.browserAction.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('browserAction.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.
## Browser compatibility
{{Compat}}
## Examples
A badge text color that starts off as red, and turns green when the browser action is clicked:
```js
browser.browserAction.setBadgeText({ text: "1234" });
browser.browserAction.setBadgeTextColor({ color: "red" });
browser.browserAction.onClicked.addListener(() => {
browser.browserAction.setBadgeTextColor({ color: "green" });
});
```
Set the badge text color only for the active tab:
```js
browser.browserAction.setBadgeText({ text: "1234" });
browser.browserAction.setBadgeTextColor({ color: "red" });
browser.browserAction.onClicked.addListener((tab) => {
browser.browserAction.setBadgeTextColor({
color: "green",
tabId: tab.id,
});
});
```
{{WebExtExamples}}
> **Note:** This API is based on Chromium's [`chrome.browserAction`](https://developer.chrome.com/docs/extensions/reference/browserAction/#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 |