W3cubDocs

/Web Extensions

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

var 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.

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
setExpression
Yes
The expression must evaluate to a JavaScript object or a DOM node, or nothing is shown in the sidebar.
79
The expression must evaluate to a JavaScript object or a DOM node, or nothing is shown in the sidebar.
57
The expression must evaluate to an object that can be serialized to JSON, or nothing is shown in the sidebar. In particular, JavaScript cyclic objects and DOM nodes are not supported. See bug 1403130.
?
Yes
No
?
?
No
?
?
?

Examples

This code creates a sidebar pane that displays the tagName of the currently selected element:

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

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

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane/setExpression