function handleSelectedElement() {
browser.devtools.inspectedWindow.eval("$0.textContent").then((result) => {
console.log(result[0]);
});
}
browser.devtools.panels.elements.onSelectionChanged.addListener(
handleSelectedElement,
);onSelectionChanged / notebook
onSelectionChanged
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.