Back to Content

options_ui

files/en-us/mozilla/add-ons/webextensions/manifest.json/options_ui/index.md

latest5.9 KB
Original Source
<table class="fullwidth-table standard-table"> <tbody> <tr> <th scope="row">Type</th> <td><code>Object</code></td> </tr> <tr> <th scope="row">Mandatory</th> <td>No</td> </tr> <tr> <th scope="row">Manifest version</th> <td>2 or higher</td> </tr> <tr> <th scope="row">Example</th> <td> <pre class="brush: json"> "options_ui": { "page": "options/options.html" }</pre > </td> </tr> </tbody> </table>

Use the options_ui key to define an options page for your extension. You use this page to enable users to modify your extension's settings.

The way the user opens the page is browser-dependent and also depends on the open_in_tab setting. Your extension can also open the page using {{WebExtAPIRef("runtime.openOptionsPage()")}}.

You specify options_ui as a path to an HTML file packaged with your extension. The HTML file can include CSS and JavaScript files, just like a normal web page. Unlike a normal page, though, the JavaScript can use all the WebExtension APIs that the extension has permissions for. However, it runs in a different scope than your background scripts.

If you want to share data or functions between the JavaScript on your options page and your background script(s), you can do so directly by obtaining a reference to the Window of your background scripts by using {{WebExtAPIRef("extension.getBackgroundPage()")}}, or a reference to the {{domxref("Window")}} of any of the pages running within your extension with {{WebExtAPIRef("extension.getViews()")}}. Alternately, you can communicate between the JavaScript for your options page and your background script(s) using {{WebExtAPIRef("runtime.sendMessage()")}}, {{WebExtAPIRef("runtime.onMessage")}}, or {{WebExtAPIRef("runtime.connect()")}}. The latter (or {{WebExtAPIRef("runtime.Port")}} equivalents) can also be used to share options between your background script(s) and your content script(s).

In general, you want to store options changed on option pages using the {{WebExtAPIRef("storage", "storage API", "", "true")}} to either {{WebExtAPIRef("storage.sync")}} (if you want the settings synchronized across all instances of that browser that the user is logged into), or {{WebExtAPIRef("storage.local")}} (if the settings are local to the current machine/profile). If you do so and your background script(s) (or content script(s)) need to know about the change, your script(s) might choose to add a listener to {{WebExtAPIRef("storage.onChanged")}}.

Syntax

The options_ui key is an object with the following contents:

<table class="fullwidth-table standard-table"> <thead> <tr> <th scope="col">Name</th> <th scope="col">Type</th> <th scope="col">Description</th> </tr> </thead> <tbody> <tr> <td> <code> <a href="/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Browser_styles"> browser_style </a> </code>

{{optional_inline}}

{{deprecated_inline}} in Manifest V3. </td> <td><code>Boolean</code></td> <td> <p>Optional, defaulting to:</p> <ul> <li><code>true</code> in Manifest V2 and prior to Firefox 115 in Manifest V3.</li> <li><code>false</code> in Manifest V3 from Firefox 115.</li> </ul> <div class="notecard warning"> <p> Do not set <code>browser_style</code> to true: it's not supported in Manifest V3, from Firefox 118. See <a href="/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Browser_styles#manifest_v3_migration">Manifest V3 migration for <code>browser_style</code></a>. </p> </div> <p> In Firefox, the stylesheet can be seen at <code>chrome://browser/content/extension.css</code> or <code>chrome://browser/content/extension-mac.css</code> on macOS. When setting dimensions, be aware that this stylesheet sets <code>box-sizing: border-box</code> (see <a href="/en-US/docs/Web/CSS/Reference/Properties/box-sizing">box-sizing</a>). </p> </td> </tr> <tr> <td><code>open_in_tab</code> {{optional_inline}}</td> <td><code>Boolean</code></td> <td> <ul> <li>If <code>false</code>, the options page opens in the browser's add-on manager.</li> <li> If <code>true</code>, the options page opens in a normal browser tab. </li> </ul> <p>Defaults to <code>false</code>.</p> </td> </tr> <tr> <td><code>page</code></td> <td><code>String</code></td> <td> <p>Mandatory.</p> <p> The path to an HTML file containing the specification of your options page. </p> <p> The path is relative to the location of <code>manifest.json</code> itself. </p> </td> </tr>

</tbody> </table>

Example

json
"options_ui": {
  "page": "options/options.html"
}

Browser compatibility

{{Compat}}

See also