DevTools panels in browser extensions: build the inspector tab you wish existed
Build a Chrome extension DevTools panel: register it with chrome.devtools.panels, count page resources with inspectedWindow, and add an Elements sidebar pane.

React DevTools. Vue Devtools. Redux DevTools. Some of the developer tools you reach for every day are browser extensions — and they do not live on the toolbar. They live inside Chrome DevTools itself, as their own tab next to Console and Network. That surface is open to any extension through chrome.devtools.*, and the manifest price is zero permissions.
Let's use it. We will build Page Diet, a DevTools panel that tallies every resource the inspected page loads — grouped by type, updating live as requests arrive. Then we will add a sidebar to the Elements panel that shows the selected node's data-* attributes, and wire up a message hop to the service worker — the portable way to reach browser APIs from DevTools, because Firefox keeps tabs out of DevTools pages entirely.
Difficulty: intermediate — you have shipped an extension before (manifest, service worker) and read async/await without pain. Time: ~30 minutes with Chrome and a text editor.
DevTools adds two more contexts
If you read my message passing tutorial, you know the usual three contexts: content script, service worker, popup. Open DevTools and two more join the extension:
- The devtools page is a headless extension page Chrome instantiates each time DevTools opens and destroys when it closes. It never renders anything — its whole job is registering UI through
chrome.devtools.panels. Chrome's extend-DevTools guide keeps the map of what lives where. - Panel and sidebar pages are real extension pages living inside the DevTools window. They get the full
chrome.devtools.*surface, and the tab they care about is the inspected one, exposed aschrome.devtools.inspectedWindow.tabId.
Two rules of this world bite everyone once. First, the devtools page lifecycle: unlike a popup, you cannot see it, and it only picks up your edits when it is created again — after editing devtools.js (or any page it loads), close DevTools and reopen it. Second, panels are created imperatively, by code that runs on every DevTools open, not declared in the manifest like action.default_popup. As Matt Frisbie explores in Building Browser Extensions (Apress, 2025), that headless page is a context of its own with its own mortality, and the devtools APIs it uses need no permissions.
One more fact completes the model: chrome.devtools.inspectedWindow.eval() runs a string in the page's context, not an isolated one, and its result must be JSON-compatible. That is the only eval you get. JavaScript's own eval() stays blocked in DevTools pages like in every other Manifest V3 extension page: in Chrome 158, eval('1+1') in both the devtools page and the panel threw the CSP error ("'unsafe-eval' is not an allowed source of script"). Running code in the inspected page without a prompt is real power — which is why the trust section near the end is not optional reading.
Three of your contexts live and die with the DevTools window (top). The service worker (orange) outlives them all, and it has
tabs in every browser.
Here is the whole extension:
page-diet/
├── manifest.json
├── devtools.html
├── devtools.js
├── panel.html
├── panel.css
├── panel.js
└── background.js (added in step 5)Step 1: the manifest — one key, zero permissions
manifest.json
{
"name": "Page Diet",
"description": "A DevTools panel that tallies every resource the inspected page loads.",
"version": "1.0",
"manifest_version": 3,
"devtools_page": "devtools.html"
}One key does it: devtools_page points at the headless page. No permissions, no host_permissions, no action. That is a large API surface that asks the user for nothing — keep it in mind for the trust section below.
Do not add the background key yet. The moment you declare a service worker, Chrome tries to load background.js, and the whole extension fails to load while that file does not exist. Step 5 introduces both together.
Step 2: the devtools page — headless and short-lived
devtools.html
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<script src="devtools.js"></script>
</head>
<body></body>
</html>devtools.js
// Page Diet — the devtools page. Created when DevTools opens, destroyed when
// it closes. Never rendered: its only job is registering UI inside DevTools.
chrome.devtools.panels.create('Page Diet', '', 'panel.html', (panel) => {
// panel.html is lazy-loaded: Chrome fetches it the first time the user
// opens the tab, not before. onShown hands us the panel's own window
// every time the user switches to it — including the first.
panel.onShown.addListener((panelWindow) => {
if (panelWindow.refreshCounts) panelWindow.refreshCounts();
});
});panels.create(title, iconPath, pagePath, callback) registers the tab; the chrome.devtools.panels reference has the full signature. The icon path can be an empty string — Google's own sample points at an icon.png that is not even in its repository, and the panel loads regardless. The callback receives the ExtensionPanel, and onShown is the hook worth wiring: it fires each time the user returns to your tab and hands over the panel's own window, so the devtools page can nudge it.
The if (panelWindow.refreshCounts) guard matters. On the very first show, panel.js may not have finished loading when onShown fires — the guard skips that call, and panel.js runs its own initial refresh at the end (step 3).
Step 3: the panel — counting what the page ate
panel.html
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="panel.css" />
</head>
<body>
<header>
<h1>Page Diet</h1>
<div class="buttons">
<button id="refresh" type="button">Refresh</button>
<button id="where" type="button">Where is this tab?</button>
</div>
</header>
<p id="summary">Counting…</p>
<table id="counts">
<thead>
<tr>
<th>Resource type</th>
<th>Count</th>
</tr>
</thead>
<tbody></tbody>
</table>
<p id="tabinfo" hidden></p>
<script src="panel.js"></script>
</body>
</html>panel.css
/* Page Diet — panel styling. Panels are wide and short; design for that
shape and your UI will look at home in every dock state. */
body {
font: 12px/1.5 system-ui, sans-serif;
margin: 0;
padding: 12px 16px;
}
header {
display: flex;
align-items: center;
gap: 12px;
}
h1 {
font-size: 14px;
margin: 0;
}
table {
border-collapse: collapse;
}
th,
td {
padding: 2px 24px 2px 0;
text-align: left;
}
#summary,
#tabinfo {
color: #5f6368;
}panel.js
// Page Diet — the panel page. It lives inside the DevTools window, so it
// gets the full chrome.devtools.* surface. Reaching the browser itself
// (chrome.tabs) is step 5's job.
// Every resource seen on the current page, keyed by URL, so a resource that
// both getResources() and onResourceAdded report is counted once.
const seen = new Map();
const tbody = document.querySelector('#counts tbody');
const summary = document.getElementById('summary');
function count(resource) {
// Every inspectedWindow.eval() call (yours or another DevTools
// extension's) is reported as a debugger:///VM… script. The page never
// loaded those, so they stay out of the tally.
if (resource.url.startsWith('debugger:')) return;
seen.set(resource.url, resource.type);
}
function render() {
const types = new Map();
for (const type of seen.values()) types.set(type, (types.get(type) ?? 0) + 1);
tbody.textContent = '';
for (const [type, n] of [...types].sort((a, b) => b[1] - a[1])) {
const row = document.createElement('tr');
const typeCell = document.createElement('td');
typeCell.textContent = type;
const countCell = document.createElement('td');
countCell.textContent = String(n);
row.append(typeCell, countCell);
tbody.append(row);
}
summary.textContent =
seen.size > 0
? `${seen.size} resources loaded on this page`
: 'Nothing counted yet — reload the inspected page with this panel open.';
}
function refreshCounts() {
chrome.devtools.inspectedWindow.getResources((resources) => {
seen.clear();
for (const resource of resources) count(resource);
render();
});
}
// Anything fetched after DevTools opened arrives one resource at a time.
chrome.devtools.inspectedWindow.onResourceAdded.addListener((resource) => {
count(resource);
render();
});
// The page changed: a reload, a new site, or a single-page app rewriting
// its URL with history.pushState(). Re-read the list instead of wiping it —
// getResources() knows what the current document holds.
chrome.devtools.network.onNavigated.addListener(refreshCounts);
document.getElementById('refresh').addEventListener('click', refreshCounts);
// Step 5's service worker answers this. Until it exists, the click falls
// into the catch branch and says so.
document.getElementById('where').addEventListener('click', async () => {
const tabId = chrome.devtools.inspectedWindow.tabId;
const tabInfo = document.getElementById('tabinfo');
tabInfo.hidden = false;
try {
const reply = await chrome.runtime.sendMessage({ action: 'tab-info', tabId });
tabInfo.textContent = reply?.ok
? `Tab ${tabId}: slot ${reply.index} of window ${reply.windowId}, ${reply.active ? 'active' : 'in the background'}, status "${reply.status}".`
: `The worker could not read the tab: ${reply?.error ?? 'unknown error'}`;
} catch (error) {
tabInfo.textContent = `No worker on the other end: ${error.message}`;
}
});
// The devtools page's onShown listener calls this whenever the user
// switches back to the panel.
window.refreshCounts = refreshCounts;
refreshCounts();getResources() hands back every Resource DevTools knows for the inspected page — including ones loaded before DevTools opened — each with a url, a type, and a getContent() method that fetches the body (your first extension of Page Diet: turn the counter into an inspector). Google's inspectedWindow sample counts resources by resource.type in about ten lines; Page Diet keeps the idea and adds the two things a real panel needs — live updates via onResourceAdded, which fires for everything requested after DevTools opened, and a re-sync on chrome.devtools.network.onNavigated, because counts spanning two different pages would be a lie. The inspectedWindow reference documents all three.
Two details in that code come from running it rather than reading the docs. onNavigated fires for same-document URL changes too: history.pushState() and history.replaceState() both trigger it. The first draft of this panel cleared its table there, and on a Next.js page — which calls replaceState() right after load — a reload ended with 25 resources on screen out of more than 240. Re-reading getResources() instead keeps the count right on single-page apps, and keying the tally by URL stops a resource reported by both paths from counting twice. The debugger: filter is the second detail: every inspectedWindow.eval() call arrives through onResourceAdded as a debugger:///VM… script, so without it any DevTools extension evaluating code in the page would inflate the count.
Two smaller notes. The "Where is this tab?" button is already wired to a service worker that does not exist yet — its catch branch prints the error until step 5 gives it a listener. And if you want the panel to follow DevTools' dark theme, chrome.devtools.panels.themeName tells you which theme is active; setThemeChangeHandler reports live changes.
Load it and try it
- Go to
chrome://extensions, enable Developer mode, click Load unpacked and choose thepage-diet/folder. - Open any substantial page — a news article, your own project — and open DevTools (
F12/Ctrl+Shift+I/Cmd+Opt+I). - Find the Page Diet tab at the end of the panel row. In a narrow DevTools window it moves behind the » chevron.
- Counts appear immediately —
getResources()sees resources from before DevTools opened. Reload the inspected page and watch the rows rebuild asonResourceAddedstreams in. Navigate to another site and the table switches to that page's resources. - Click Where is this tab? — "No worker on the other end: Could not establish connection. Receiving end does not exist." is the correct answer until step 5.
Page Diet on one of our own blog posts. The sm- rows are original source files that DevTools reconstructs from source maps; the page itself never requested them.
Step 4: a sidebar in the Elements panel
Panels are not the only real estate. chrome.devtools.panels.elements.createSidebarPane() adds a collapsible pane to the sidebar of the Elements panel — the same mechanism Google's panels sample uses to show jQuery data for the selected node. Ours does the framework-free version: every data-* attribute on whatever element is selected. Replace devtools.js in full:
devtools.js
// Page Diet — the devtools page. Created when DevTools opens, destroyed when
// it closes. Never rendered: its only job is registering UI inside DevTools.
chrome.devtools.panels.create('Page Diet', '', 'panel.html', (panel) => {
// panel.html is lazy-loaded: Chrome fetches it the first time the user
// opens the tab, not before. onShown hands us the panel's own window
// every time the user switches to it — including the first.
panel.onShown.addListener((panelWindow) => {
if (panelWindow.refreshCounts) panelWindow.refreshCounts();
});
});
// A sidebar pane inside the Elements panel showing the data-* attributes
// of whichever node is currently selected there.
chrome.devtools.panels.elements.createSidebarPane('Data attributes', (sidebar) => {
function update() {
// setExpression evaluates a string IN THE INSPECTED PAGE and renders
// the (JSON-compatible) result as an expandable tree. $0 is
// DevTools' own shorthand for the selected element.
sidebar.setExpression(
'$0 ? Object.fromEntries(Array.from($0.attributes).filter((attr) => attr.name.startsWith("data-")).map((attr) => [attr.name, attr.value])) : {}',
'data-* attributes'
);
}
update();
chrome.devtools.panels.elements.onSelectionChanged.addListener(update);
});Three moving parts. $0 is the DevTools shorthand for the currently selected element, and it is available to any expression you hand setExpression — which evaluates that string in the inspected page, the eval()-adjacent surface mentioned earlier, and renders the result under the given root title. onSelectionChanged re-runs the query whenever the user clicks a different node — the official sample's pattern, kept. And Object.fromEntries builds a plain object the tree view can expand; the ternary covers the moment when nothing is selected and $0 is undefined. In practice DevTools selects <body> when it opens, so the first thing the pane shows is usually an empty object.
Close and reopen DevTools (the headless-page rule), select any node in Elements — on a modern site, plenty carry data-* attributes — and open Data attributes in the sidebar's tab row. With the default sidebar width it sits behind the » chevron, after Styles, Computed and Layout.
Select a node, read its data-* attributes — no console incantations
Step 5: the hop to the service worker
The panel knows its tab's id — inspectedWindow.tabId — and the obvious next move is chrome.tabs.get(tabId). Whether that works depends on the browser and on which page of the docs you trust. The inspectedWindow reference says the tabs API "is not exposed to the Developer Tools extension pages" and tells you to pass the id to the background page. The extend-DevTools guide says the devtools page has access to the DevTools APIs and extension APIs. Chrome 158 sides with the guide: chrome.tabs.get(inspectedWindow.tabId) returned the tab from both the devtools page and the panel. Firefox sides with the reference: per MDN, a devtools page gets the content-script set of WebExtension APIs plus devtools.*, and nothing else.
So the portable answer is a message hop to the extension's service worker, the pattern MDN documents for anything DevTools extensions need from the browser side. One caution on that page: its example still calls the Manifest V2 tabs.executeScript. Under Manifest V3 the API is chrome.scripting.executeScript, which my scripting tutorial walks through.
Two files change. The manifest grows the worker it was missing:
manifest.json
{
"name": "Page Diet",
"description": "A DevTools panel that tallies every resource the inspected page loads.",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"devtools_page": "devtools.html"
}background.js
// Page Diet — the service worker. Firefox gives DevTools pages no tabs
// API, so the panel hands over the inspected tab's id and the worker does
// the read on its behalf — the same code works in Chrome.
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message?.action !== 'tab-info' || typeof message.tabId !== 'number') {
return; // Not ours — stay silent and let other listeners answer.
}
chrome.tabs
.get(message.tabId)
.then((tab) => {
sendResponse({
ok: true,
index: tab.index,
windowId: tab.windowId,
active: tab.active,
status: tab.status
});
})
.catch((error) => {
sendResponse({ ok: false, error: String(error) });
});
return true; // Keep the message channel open for the async reply.
});The free lunch is in which fields we read: index, windowId, active and status come back from tabs.get without the "tabs" permission — that permission only unlocks url, pendingUrl, title and favIconUrl, per the tabs reference. return true keeps the response channel open across the promise; the message passing article covers that rule in full, so I will not repeat it here. And shape-checking the message is enough trust-boundary for this worker: runtime.onMessage only hears your own extension's contexts. Messages from web pages and other extensions arrive on onMessageExternal, which this worker never listens to.
Reload the extension (the manifest changed). In Chrome 158 that also closes any DevTools window hosting the old panel, so reopen DevTools and click Where is this tab? — the line under the table fills in: Tab 992754126: slot 0 of window 992754125, active, status "complete".
The hop works — tab metadata fetched by the service worker for the panel
Debugging the debugger
You now have more consoles than usual, and knowing which one you are staring at is most of the battle:
- The devtools page and the panel: undock DevTools into its own window (⋮ → Dock side), focus that window and press the open-DevTools shortcut again (
Ctrl+Shift+I/Cmd+Opt+I) — Chrome opens DevTools on DevTools. Both of your pages are frames inside the DevTools window, so they show up in that console's JavaScript-context dropdown. - The service worker: its usual home —
chrome://extensions→ Page Diet → the service worker link. - The inspected page: the ordinary console, or the drawer (
Esc) inside DevTools.
Three consoles for one seven-file extension. Most "my panel is broken" reports are really "I was reading the wrong console."
If it doesn't work
- The Page Diet tab never appears → first check what you are inspecting: on
chrome://pages Chrome does not load extension devtools pages at all (onchrome://versionin Chrome 158, DevTools opened without one), so test on an ordinary web page. Otherwise the devtools page failed to load. Check the extension card atchrome://extensionsfor errors, then open DevTools-on-DevTools (above) and look at its console — a typo in thedevtools.htmlpath or a syntax error indevtools.jskills registration silently. - The table stays empty → confirm the callback fires in the panel's own console:
chrome.devtools.inspectedWindow.getResources((r) => console.log(r.length)). - "Could not establish connection. Receiving end does not exist." under Where is this tab? →
background.jsis not registered. The step 5 manifest must have replaced the step 1 one, and the extension must have been reloaded after: the card atchrome://extensionsshould now show a service worker link. If it does not, the manifest did not take. - The sidebar shows an empty object → the selected node has no
data-*attributes. DevTools selects<body>when it opens, and most<body>elements have none; click a node that does. - Edits that do nothing → an unpacked extension's files are read again whenever DevTools creates the devtools page, so for
devtools.js, the panel files and the sidebar, close-and-reopen DevTools is the refresh. A manifest change needs the reload button on the extension card, and in Chrome 158 that reload also closes the DevTools windows hosting your panel.
Your panel can see everything
Zero permissions is not zero power. While DevTools is open on a tab, a panel can enumerate everything the page loaded (getResources), pull each resource's response body (getContent), and run arbitrary scripts in the page's context (inspectedWindow.eval). None of it prompts the user: opening DevTools was the consent, and your extension hitched a ride. That is the design — DevTools extensions are for developers inspecting their own tabs — so ship like it:
- Say what the panel reads in the store listing and privacy policy. "A DevTools panel for developers" is not a description. "Enumerates the inspected tab's network resources while DevTools is open" is.
- Treat every
inspectedWindow.eval()result as hostile input. It was produced in the page's context, where page scripts can lie, trap getters, or hand you crafted strings. Render withtextContent, neverinnerHTML— the same rule the messaging tutorial applies to messages. - Prefer the structured APIs (
getResources,setExpression) over hand-builtinspectedWindow.eval()strings wherever they cover the job. - Resist
chrome.debugger. If you are tempted to attach for deeper access, that is a different API with an infobar, a heavier review and a bad reputation — my debugger permission explainer covers when it is and is not defensible.
Cross-browser: Chrome-first, Firefox-partial
Firefox supports the same architecture under browser.* — devtools_page, panels.create, inspectedWindow.eval (with $0 working since Firefox 55), even devtools.network. The step 4 sidebar ports too: MDN's compatibility data lists panels.elements and onSelectionChanged from Firefox 56 and createSidebarPane with setExpression from Firefox 57. Chrome also answers to the browser.* prefix, with a catch for this kind of extension: the native browser namespace arrived in Chrome 148, but Chrome kept it switched off for any extension that declares devtools_page until Chrome 152, per the extend-DevTools guide. Use browser.* in Chrome only with a 152+ floor (or keep the polyfill).
What does not port is the data surface: per MDN's devtools guide, Firefox has no inspectedWindow.getResources() and no onResourceAdded — Page Diet's counter has nothing to count there. The step 5 hop is exactly what Firefox needs, since its background scripts get the full tabs API and its devtools pages do not.
The practical read: feature-detect (if (chrome.devtools.inspectedWindow.getResources) before wiring the panel) and degrade gracefully, or treat DevTools extensions as Chrome-first and say so in your listing.
Common pitfalls, collected
- The devtools page is not a popup. It is instantiated per DevTools window, never rendered, and re-runs its whole script on every open. Nothing survives in its variables — state that must outlive a DevTools session goes to
chrome.storage, the way my cookies tutorial persists its watch target. - Panel pages die with the DevTools window. Same rule, same storage answer. Need UI that lives beside browsing instead of inside debugging? That is the side panel's pitch.
- Panels are per-window. Two DevTools windows means two devtools pages, two panels, two
tabIds. Coordinate them through the worker or storage, never through shared module state. onNavigatedis not only full navigations.history.pushState()andreplaceState()fire it too, so a single-page app fires it on every route change. Treat it as "re-read the page", not "the page is gone".- Resources are what DevTools knows, not what the network fetched. Source-mapped originals arrive as
sm-script/sm-stylesheet(230 of 269 entries on our blog page), and everyinspectedWindow.eval()call adds adebugger:///VM…script. Filter before you report a number. inspectedWindow.tabIdis a number, not a Tab. It is the one thing every browser hands you for free; for the rest — evenactive— the hop works everywhere.
Before you ship it
Page Diet asks for no permissions and touches no network of its own — but a real tool built on this surface reads response bodies and evaluates scripts in every page its users inspect. That is a security posture worth examining before the store does. Run the packaged build through the Extenshi CLI (npx @extenshi/cli scan): security findings, the manifest signals stores reject for, and a store-review prediction in one report. You get 3 scans and 10 reads free with a free account (one-time); after that, prepaid credit packs that stay in your account until you spend them.
Curious how the big inspector extensions are put together? Browse DevTools extensions in the catalog and compare their permission lists with Page Diet's zero — and before installing one to study it, check it first.
Sources
- Extend DevTools — Chrome Extensions how-to — Chrome for Developers (the architecture map: devtools page, panels, evaluated contexts; extension API access from the devtools page; the
browsernamespace fordevtools_pageextensions from Chrome 152) - chrome.devtools.panels API reference — Chrome for Developers (
panels.create,onShown,elements.createSidebarPane,setExpression,themeName) - chrome.devtools.inspectedWindow API reference — Chrome for Developers (
tabId,eval,getResources,onResourceAdded) - chrome.tabs API reference — Chrome for Developers (which Tab fields need the
"tabs"permission) - Extending the developer tools — MDN Web Docs (Firefox's
devtools_pagesupport, which APIs a Firefox devtools page gets, the worker-hop pattern, current API gaps) - browser-compat-data: webextensions/api/devtools.json — MDN (Firefox versions for
panels.elements,createSidebarPane,setExpression,$0;getResources/onResourceAddedunsupported) - Behaviour measured for this article in Chrome for Testing 158 with the finished extension:
eval()blocked by CSP in the devtools page and panel,chrome.tabs.get()working from both,onNavigatedfiring onpushState/replaceState,debugger:///VM…resources frominspectedWindow.eval(), no devtools page onchrome://URLs, DevTools closing on extension reload - api-samples/devtools/panels — GoogleChrome/chrome-extensions-samples (Apache-2.0);
createSidebarPane+setExpression+onSelectionChanged - api-samples/devtools/inspectedWindow — GoogleChrome/chrome-extensions-samples (Apache-2.0); counting resources with
getResources
Further reading
📚 Building Browser Extensions, 2nd Edition by Matt Frisbie — Amazon | Apress. Chapter 7 covers the DevTools UI surface — the headless devtools page, imperative panel creation, designing panels for their wide-and-short shape — and chapter 12 builds a DOM Tree Explorer panel end to end, including the function-serialization trick for inspectedWindow.eval() that the official samples still use.
This article is a hands-on tutorial based on the official Chrome extension documentation and Google's Apache-2.0 sample code. Code is provided as-is for educational purposes; verify API behavior against the current developer.chrome.com reference before shipping. Extenshi does not independently verify all claims made by third-party authors, and references to specific products reflect cited documentation, not accusations of wrongdoing. If you believe any information is inaccurate, contact [email protected] and we will review and update.
Related Articles

Message passing in browser extensions: how your content script, service worker and popup actually talk
Build a page highlighter and learn Chrome extension message passing: runtime.sendMessage, the return true rule, tabs.sendMessage and long-lived message ports.

Runtime script injection in Chrome extensions: ISOLATED vs MAIN world
chrome.scripting.executeScript end to end: inject on click with activeTab, pass args safely, and choose ISOLATED or MAIN world. Full MV3 code, ~25 min.

The `debugger` permission explained: what browser extensions can really do with DevTools access
The debugger permission gives an extension full Chrome DevTools Protocol access — cookies, keystrokes, any page. Here's what it allows and how to check yours.

Chrome extension side panels: build a UI that stays open while you browse
A hands-on Manifest V3 tutorial: build a Chrome extension side panel that persists across tabs, then make it per-site. Full runnable code, ~25 minutes.