devtools.panels.ElementsPanel.setExpression()

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().

JSON objects and DOM nodes are displayed as an expandable tree, as in the JSON viewer 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.

Syntax

js
let evaluating = browser.devtools.panels.setExpression(
  expression,       // string
  rootTitle         // string
)

Parameters

expression

string. The expression to evaluate.

rootTitle Optional

string. The title of the root of the tree in which results are displayed.

Return value

A Promise that will be fulfilled with no arguments, once the expression has been evaluated.

Examples

This code creates a sidebar pane that displays the 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);

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
setExpression
Chrome – Full support
Chrome 18 (Release date: 2012-03-28)
footnote
footnote The expression must evaluate to a JavaScript object or a DOM node, or nothing is shown in the sidebar.
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote
footnote The expression must evaluate to a JavaScript object or a DOM node, or nothing is shown in the sidebar.
Firefox – Full support
Firefox 57 (Release date: 2017-11-14)
footnote
footnote Before Firefox 60, the expression must evaluate to an object that can be serialized to JSON, or nothing was shown in the sidebar. In particular, JavaScript cyclic objects and DOM nodes were not supported. See bug 1403130.
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote
footnote The expression must evaluate to a JavaScript object or a DOM node, or nothing is shown in the sidebar.
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

Note: This API is based on Chromium's chrome.devtools.panels API.