Skip to content

Commit

Permalink
Adding details for browserAction.getUserSettings (mdn#31975)
Browse files Browse the repository at this point in the history
* Adding details for browserAction.getUserSettings

* Apply suggestions from review

Co-authored-by: Rob Wu <[email protected]>

* Linter suggestion

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: Rob Wu <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 30, 2024
1 parent 8965b36 commit 05808d3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
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}}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ With the `browserAction` API, you can:
- : 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()")}}
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/mozilla/firefox/releases/116/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ This article provides information about the changes in Firefox 116 that affect d
## Changes for add-on developers

- The URL of a page visited when an extension is uninstalled, provided in {{WebExtAPIRef("runtime.setUninstallURL")}}, can now be up to 1023 characters instead of 255 ([Firefox bug 1835723](https://bugzil.la/1835723)).
- Adds {{WebExtAPIRef("action.getUserSettings")}} providing the user-specified settings for an extension's browser action ([Firefox bug 1814905](https://bugzil.la/1814905)).
- Adds {{WebExtAPIRef("action.getUserSettings")}} and {{WebExtAPIRef("browserAction.getUserSettings")}} providing the user-specified settings for an extension's browser action ([Firefox bug 1814905](https://bugzil.la/1814905)).
- `autoDiscardable` is now supported in {{WebExtAPIRef("tabs.Tab")}}, {{WebExtAPIRef("tabs.onUpdated")}}, {{WebExtAPIRef("tabs.update")}}, and {{WebExtAPIRef("tabs.query")}} ([Firefox bug 1809094](https://bugzil.la/1809094)).

## Developer Tools
Expand Down

0 comments on commit 05808d3

Please sign in to comment.