mdn / mdn/content

sessions.setTabValue: Improve example

Open Beginner friendly
#45,607 1 comment 0 reactions 0 assignees View on GitHub
Content:WebExt
Dominant language
Markdown
Stars
11k
Forks
23.2k
Avg merge
2d 9h
Merged PRs (30d)
331

Description

### MDN URL

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/sessions/setTabValue

### What specific section or headline is this issue about?

Examples

### What information was incorrect, unhelpful, or incomplete?

While the snippet in the example is not wrong, it can cause unnecessary confusion.

[menus.onClicked](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/menus/onClicked) already returns the [tabs.Tab](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/Tab) and there is no need to use `tabs.query`.

### What did you expect to see?

The example can be updated as the following:

```js
function setOnActiveTab(info, tab) {
browser.sessions.setTabValue(tab.id, "my-key", "my-value");
}

browser.menus.create({
id: "my-item",
title: "my item",
contexts: ["all"],
});

browser.menus.onClicked.addListener(setOnActiveTab);
```

Or even .... (similar to [menus.onClicked: Exmaple](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/menus/onClicked#examples))
```js
browser.menus.create({
id: "my-item",
title: "my item",
contexts: ["all"],
});

browser.menus.onClicked.addListener((info, tab) => {
browser.sessions.setTabValue(tab.id, "my-key", "my-value");
});
```

### Do you have any supporting links, references, or citations?

_No response_

### Do you have anything more you want to share?

_No response_

### MDN metadata

Page report details

* Folder: `en-us/mozilla/add-ons/webextensions/api/sessions/settabvalue`
* MDN URL: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/sessions/setTabValue
* GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/mozilla/add-ons/webextensions/api/sessions/settabvalue/index.md
* Last commit: https://github.com/mdn/content/commit/09109b6f9444d22215ba330ec1e64e73980b2a6c
* Document last modified: 2025-07-17T07:48:12.000Z

Contributor guide

Open the contributing guide

Research direction

Open files/en-us/mozilla/add-ons/webextensions/api/sessions/settabvalue/index.md and review the Examples section alongside the menus.onClicked example. Update the snippet to use the tab returned by menus.onClicked instead of tabs.query, then verify the example matches the requested behavior and formatting.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
92/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.