recursal/MDN huggingface dataset:
browserAction.getTitle()
========================

Gets the browser action's title.

Just as you can set the title on a per-tab basis using `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`.

Syntax
------


```js
let gettingTitle = browser.browserAction.getTitle(
  details               // object
)
```

### Parameters

`details`

An object with the following properties:

`tabId` Optional

`integer`. Specify the tab to get the title from.

`windowId` Optional

`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` that will be fulfilled with a string containing the browser action's title.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

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);
});
```


**Note:** This API is based on Chromium's `chrome.browserAction` API. This documentation is derived from `browser_action.json` in the Chromium code.
browserAction.setBadgeTextColor()
=================================

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
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> 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 ``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

`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

`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
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

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,
  });
});
```


**Note:** This API is based on Chromium's `chrome.browserAction` API. This documentation is derived from `browser_action.json` in the Chromium code.
browserAction.ImageDataType
===========================

Pixel data for an image. Must be an `ImageData` object (for example, from a `<canvas>` element).

Type
----

An `ImageData` object.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

**Note:** This API is based on Chromium's `chrome.browserAction` API. This documentation is derived from `browser_action.json` in the Chromium code.
pageAction.getTitle()
=====================

Gets the title of the page action.

This is an asynchronous function that returns a `Promise`.

Syntax
------


```js
let gettingTitle = browser.pageAction.getTitle(
  details // object
)
```

### Parameters

`details`

`object`.

`tabId`

`integer`. The ID of the tab containing the page action whose title you want to get.


### Return value

A `Promise` that will be fulfilled with a string containing the page action's title.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

Examples
--------

This example logs the page action's title when the user clicks its icon:


```js
function gotTitle(title) {
  console.log(`Title ${title}`);
}

browser.pageAction.onClicked.addListener((tab) => {
  let gettingTitle = browser.pageAction.getTitle({
    tabId: tab.id,
  });
  gettingTitle.then(gotTitle);
});
```

### Example extensions

* apply-css

**Note:** This API is based on Chromium's `chrome.pageAction` API. This documentation is derived from `page_action.json` in the Chromium code.
pageAction.isShown()
====================

Returns `true` if the page action is being shown for the given tab.

This is an asynchronous function that returns a `Promise`.

Syntax
------


```js
let gettingIsShown = browser.pageAction.isShown(
  details // object
)
```

### Parameters

`details`

`object`. An object containing the `tabId` to check.

`tabId`

`integer`. ID of the tab to check.


### Return value

A `Promise` that will be fulfilled with `true` if the extension's page action is being shown for the given tab, and `false` otherwise.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

Examples
--------

Check the state of the currently active tab:


```js
async function shownInActiveTab() {
  let tabs = await browser.tabs.query({
    currentWindow: true,
    active: true,
  });
  let shown = await browser.pageAction.isShown({
    tabId: tabs[0].id,
  });
  console.log(shown);
}
```
pageAction.getPopup()
=====================

Gets the URL for the HTML document set as the popup for this page action.

This is an asynchronous function that returns a `Promise`.

Syntax
------


```js
let gettingPopup = browser.pageAction.getPopup(
  details               // object
)
```

### Parameters

`details`

`object`.

`tabId`

`integer`. ID of the tab whose popup you want to get.


### Return value

A `Promise` that will be fulfilled with a string containing the popup's URL.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

Examples
--------

Add a context menu item that logs the popup URL for the current tab. Note that you'll need the `contextMenus` permission in your manifest to create context menu items.


```js
function gotPopup(popupURL) {
  console.log(popupURL);
}

browser.contextMenus.create({
  id: "get-popup",
  title: "Get popup URL",
});

browser.contextMenus.onClicked.addListener((info, tab) => {
  if (info.menuItemId === "get-popup") {
    let gettingPopup = browser.pageAction.getPopup({ tabId: tab.id });
    gettingPopup.then(gotPopup);
  }
});
```


**Note:** This API is based on Chromium's `chrome.pageAction` API. This documentation is derived from `page_action.json` in the Chromium code.
pageAction.hide()
=================

Hides the page action for a given tab.

`hide()` overrides pattern matching, so the page action will not be shown in the specified tab even if its URL is matched by `show_matches`.

Syntax
------


```js
browser.pageAction.hide(
  tabId // integer
)
```

### Parameters

`tabId`

`integer`. The ID of the tab for which you want to hide the page action.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

Examples
--------

Hide the page action for the current tab when the user clicks it:


```js
browser.pageAction.onClicked.addListener((tab) => {
  browser.pageAction.hide(tab.id);
});
```

### Example extensions

* chill-out

**Note:** This API is based on Chromium's `chrome.pageAction` API. This documentation is derived from `page_action.json` in the Chromium code.
pageAction.onClicked
====================

Fired when a page action icon is clicked. This event will not fire if the page action has a popup.

To define a right-click action, use the `contextMenus` API with the "page\_action" context type.

Syntax
------


```js
browser.pageAction.onClicked.addListener(listener)
browser.pageAction.onClicked.removeListener(listener)
browser.pageAction.onClicked.hasListener(listener)
```


Events have three functions:

`addListener(listener)`

Adds a listener to this event.

`removeListener(listener)`

Stop listening to this event. The `listener` argument is the listener to remove.

`hasListener(listener)`

Checks whether a `listener` is registered for this event. Returns `true` if it is listening, `false` otherwise.

addListener syntax
------------------

### Parameters

`listener`

The function called when this event occurs. The function is passed these arguments:

`tab`

A `tabs.Tab` object representing the tab whose page action was clicked.

`OnClickData`

An object containing information about the click.

`modifiers`

An `array`. The keyboard modifiers active at the time of the click, being one or more of `Shift`, `Alt`, `Command`, `Ctrl`, or `MacCtrl`.

`button`

An `integer`. Indicates the button used to click the page action icon: `0` for a left-click or a click not associated with a mouse, such as one from the keyboard and `1` for a middle button or wheel click. Note that the right-click is not supported because Firefox consumes that click to display the context menu before this event is triggered.


Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

Examples
--------

When the user clicks the page action, hide it, and navigate the active tab to "https://giphy.com/explore/cat":


```js
let CATGIFS = "https://giphy.com/explore/cat";

browser.pageAction.onClicked.addListener((tab) => {
  browser.pageAction.hide(tab.id);
  browser.tabs.update({ url: CATGIFS });
});

browser.pageAction.onClicked.addListener(() => {});
```

### Example extensions

* apply-css
* chill-out

**Note:**

This API is based on Chromium's `chrome.pageAction` API. This documentation is derived from `page_action.json` in the Chromium code.
pageAction.openPopup()
======================

Open the page action's popup.

You can only call this function from inside the handler for a user action.

Syntax
------


```js
browser.pageAction.openPopup()
```

### Parameters

None.

### Return value

A `Promise` that is resolved with no arguments.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

Examples
--------

Open the popup when the user selects a context menu item:


```js
browser.menus.create({
  id: "open-popup",
  title: "open popup",
  contexts: ["all"],
});

browser.menus.onClicked.addListener(() => {
  browser.pageAction.openPopup();
});
```

### Example extensions

* menu-remove-element
pageAction.show()
=================

Shows the `pageAction` for a given `tab`. The page action is shown whenever the given tab is the active tab.

`show()` overrides pattern matching, so the page action will be shown in the specified tab even if `show_matches` does not match the URL or `hide_matches` does.

Note that calling `show()` has no effect on a tab with no content loaded.

Syntax
------


```js
browser.pageAction.show(
  tabId // integer
)
```

### Parameters

`tabId`

`integer`. The ID of the `tab` for which you want to show the page action.

### Return value

A `Promise` that will be fulfilled with `undefined`.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

Examples
--------

This example shows the `pageAction` for the active tab when the user selects a context menu item.

**Note:** You'll need the `contextMenus` permission in your manifest to create context menu items.


```js
browser.contextMenus.create({
  id: "show",
  title: "Show page action",
});

browser.contextMenus.onClicked.addListener((info, tab) => {
  if (info.menuItemId === "show") {
    browser.pageAction.show(tab.id);
  }
});
```

### Example extensions

* apply-css
* chill-out
* history-deleter
* menu-remove-element

**Note:** This API is based on Chromium's `chrome.pageAction` API. This documentation is derived from `page_action.json` in the Chromium code.
pageAction.setTitle()
=====================

Sets the title of the page action. The title is displayed in a tooltip when the user hovers over the page action.

Syntax
------


```js
browser.pageAction.setTitle(
  details // object
)
```

### Parameters

`details`

`object`.

`tabId`

`integer`. The ID of the tab whose title you want to set.

`title`

`string` or `null`. The tooltip text.

If `null` is passed here, the title is reset to the title that was specified in the `page_action` manifest key.


Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

Examples
--------

Whenever a tab is updated, show the page action for that tab, and set its title to show the tab's ID:


```js
browser.tabs.onUpdated.addListener((tabId, changeInfo, tabInfo) => {
  browser.pageAction.show(tabId);
  browser.pageAction.setTitle({
    tabId,
    title: `Tab ID: ${tabId}`,
  });
});
```

### Example extensions

* apply-css

**Note:** This API is based on Chromium's `chrome.pageAction` API. This documentation is derived from `page_action.json` in the Chromium code.
pageAction.setIcon()
====================

Sets the icon for the page action.

You can specify a single icon as either the path to an image file or a `pageAction.ImageDataType` object.

You can specify multiple icons in different sizes by supplying a dictionary containing multiple paths or `ImageData` objects. This means the icon doesn't have to be scaled for a device with a different pixel density.

This is an asynchronous function that returns a `Promise`.

Syntax
------


```js
let settingIcon = browser.pageAction.setIcon(
  details         // object
)
```

### Parameters

`details`

`object`. An object containing either `imageData` or `path` properties, and a `tabId` property.

`imageData` Optional

``pageAction.ImageDataType`` or `object`. This is either a single `ImageData` object or a dictionary object.

Use a dictionary object to specify multiple `ImageData` objects in different sizes, so the icon does not have to be scaled for a device with a different pixel density. If `imageData` is a dictionary, the value of each property is an `ImageData` object, and its name is its size, like this:


```js
let settingIcon = browser.action.setIcon({
  imageData: {
    16: image16,
    32: image32,
  },
});
```


The browser will choose the image to use depending on the screen's pixel density. See Choosing icon sizes for more information on this.

`path` Optional

`string` or `object`. This is either a relative path to an icon file or a dictionary object.

Use a dictionary object to specify multiple icon files in different sizes, so the icon does not have to be scaled for a device with a different pixel density. If `path` is a dictionary, the value of each property is a relative path, and its name is its size, like this:


```js
let settingIcon = browser.action.setIcon({
  path: {
    16: "path/to/image16.jpg",
    32: "path/to/image32.jpg",
  },
});
```


The browser will choose the image to use depending on the screen's pixel density. See Choosing icon sizes for more information on this.

If `path` is `null`, this will reset the page action's icon to the icon that was given in the `page_action` manifest key.

If `path` is `""`, this will reset the icon to the browser's global default icon (that is, the icon used if no icon is given in the `page_action` manifest key).

If `path` does not point to a valid icon, then no icon will be displayed.

`tabId`

`integer`. The ID of the tab whose icon you want to set.


### Return value

A `Promise` that will be fulfilled with no arguments once the icon has been set.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

Examples
--------

Set the icon for the page action when the user clicks it:


```js
browser.pageAction.onClicked.addListener((tab) => {
  browser.pageAction.setIcon({
    tabId: tab.id,
    path: "icons/icon-48.png",
  });
});
```

### Example extensions

* apply-css

**Note:**

This API is based on Chromium's `chrome.pageAction` API. This documentation is derived from `page_action.json` in the Chromium code.
pageAction.ImageDataType
========================

Pixel data for an image.

Type
----

An `ImageData` object, e.g. from a `<canvas>` element.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

**Note:** This API is based on Chromium's `chrome.pageAction` API. This documentation is derived from `page_action.json` in the Chromium code.
pageAction.setPopup()
=====================

Sets the HTML document to be opened as a popup when the user clicks on the page action's icon.

Syntax
------


```js
browser.pageAction.setPopup(
  details // object
)
```

### Parameters

`details`

`object`.

`tabId`

`integer`. The ID of the tab for which you want to set the popup.

`popup`

`string` or `null`. URL to the HTML file to show in a popup.

If an empty string (`""`) is passed here, the popup is disabled, and the extension will receive `pageAction.onClicked` events.

If `null` is passed here, the popup is reset to the popup that was specified in the `page_action` manifest key.


Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

Examples
--------

Listen for `tabs.onUpdated` events, and switch the popup if the loading status changes:


```js
browser.tabs.onUpdated.addListener((tabId, changeInfo, tabInfo) => {
  if (changeInfo.status) {
    browser.pageAction.show(tabId);
    if (changeInfo.status === "loading") {
      browser.pageAction.setPopup({
        tabId,
        popup: "/popup/loading.html",
      });
    } else {
      browser.pageAction.setPopup({
        tabId,
        popup: "/popup/complete.html",
      });
    }
  }
});
```


**Note:** This API is based on Chromium's `chrome.pageAction` API. This documentation is derived from `page_action.json` in the Chromium code.
pkcs11.getModuleSlots()
=======================

Enumerate a module's slots. This function returns an array containing one entry for each slot. Each entry contains the slot's name and, if the slot contains a token, information about the token.

You can only call this for a module that is installed in Firefox.

This is an asynchronous function that returns a `Promise`.

Syntax
------


```js
let getting = browser.pkcs11.getModuleSlots(
  name              // string
)
```

### Parameters

`name`

`string`. Name of the module. This must match the `name` property in the PKCS #11 manifest for the module.

### Return value

A `Promise` that will be fulfilled with an array of objects, one for each slot that the module provides access to. Each object has two properties:

* `name`: the name of the slot
* `token`: if a token is present in this slot, a `Token` object. If no token is present in the slot, this property is `null`.

`Token` objects have the following properties:

`name`

`string`. Name of the token.

`manufacturer`

`string`. Name of the token's manufacturer.

`HWVersion`

`string`. Hardware version, as a PKCS #11 version number (two 32-bit integers separated with a dot, like "1.0".

`FWVersion`

`string`. Firmware version, as a PKCS #11 version number (two 32-bit integers separated with a dot, like "1.0".

`serial`

`string`. Serial number, whose format is defined by the token specification.

`isLoggedIn`

`boolean`: `true` if the token is logged on already, `false` otherwise.

If the module could not be found or some other error occurs, the promise will be rejected with an error message.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

Examples
--------

Installs a module, then lists its slots and list the tokens they contain:


```js
function onInstalled() {
  return browser.pkcs11.getModuleSlots("my\_module");
}

function onGotSlots(slots) {
  for (const slot of slots) {
    console.log(`Slot: ${slot.name}`);
    if (slot.token) {
      console.log(`Contains token: ${slot.token.name}`);
    } else {
      console.log("Is empty");
    }
  }
}

browser.pkcs11.installModule("my\_module").then(onInstalled).then(onGotSlots);
```
pkcs11.uninstallModule()
========================

Uninstalls the named PKCS #11 module from Firefox.

This is an asynchronous function that returns a `Promise`.

Syntax
------


```js
let uninstalling = browser.pkcs11.uninstallModule(
  name              // string
)
```

### Parameters

`name`

`string`. Name of the module to uninstall. This must match the `name` property in the PKCS #11 manifest for the module.

### Return value

A `Promise` that will be fulfilled with no arguments once the module is uninstalled.

If the module could not be found or some other error occurs, the promise will be rejected with an error message.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

Examples
--------

Uninstalls the module named "pkcs11\_module":


```js
browser.pkcs11.uninstallModule("pkcs11\_module");
```
pkcs11.isModuleInstalled()
==========================

Checks whether the named PKCS #11 module is currently installed in Firefox.

This is an asynchronous function that returns a `Promise`.

Syntax
------


```js
let checking = browser.pkcs11.isModuleInstalled(
  name              // string
)
```

### Parameters

`name`

`string`. Name of the module to check.

### Return value

A `Promise` that will be fulfilled with `true` if the module is installed, `false` otherwise.

If the module an error occurs, the promise will be rejected with an error message.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

Examples
--------

Checks whether the module named "pkcs11\_module" is installed:


```js
function logIsInstalled(isInstalled) {
  console.log(`Module is installed: ${isInstalled}`);
}

browser.pkcs11.isModuleInstalled("pkcs11\_module").then(logIsInstalled);
```