Skip to content

Commit

Permalink
Merge pull request mdn#425 from nchevobbe/devtools-inspector-toolbar
Browse files Browse the repository at this point in the history
Adds an example for devtools inspector sidebar
  • Loading branch information
caitmuenster authored Nov 12, 2020
2 parents 60ce50b + 8eebc58 commit 2184fee
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
12 changes: 12 additions & 0 deletions devtools-inspector-sidebar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# devtools-panels

**Adds a new sidebar to the developer tools inspector.**

## What it does

This extension adds a new sidebar to the inspector panel.
It displays the properties of the current selected node in the markup view, using
`sidebar.setExpression($0)` each time a new node is selected (listener added via
`browser.devtools.panels.elements.onSelectionChanged`).

To learn more about the devtools APIs, see [Extending the developer tools](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Extending_the_developer_tools).
9 changes: 9 additions & 0 deletions devtools-inspector-sidebar/devtools/devtools-page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script src="devtools.js"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions devtools-inspector-sidebar/devtools/devtools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
This script is run whenever the devtools are open.
In here, we can create our sidebar, and when the selected node in the inspector
change, we evaluate it and display its properties in the sidebar.
*/

browser.devtools.panels.elements.createSidebarPane("DOM").then(sidebar => {
browser.devtools.panels.elements.onSelectionChanged.addListener(() => {
sidebar.setExpression(`$0`);
});
});
12 changes: 12 additions & 0 deletions devtools-inspector-sidebar/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"description": "Adds a new sidebar to the developer tools inspector panel. The sidebar displays the page document as an inspectable object.",
"manifest_version": 2,
"name": "devtools-inspector-sidebar",
"version": "1.0",
"author": "Nicolas Chevobbe",
"homepage_url": "https://github.com/mdn/webextensions-examples/tree/master/devtools-inspector-sidebar",

"permissions": ["<all_urls>"],

"devtools_page": "devtools/devtools-page.html"
}

0 comments on commit 2184fee

Please sign in to comment.