DEV Community

Cover image for Custom Chrome DevTools Panels: Build One With Manifest V3
ExtensionBooster
ExtensionBooster

Posted on Originally published at extensionbooster.net

Custom Chrome DevTools Panels: Build One With Manifest V3

Originally published on ExtensionBooster.

Custom Chrome DevTools panels let you put your own debugging UI right beside Elements, Console and Network, which is exactly how tools like React DevTools and Redux DevTools work. The tricky part is not the UI. It is understanding which piece of your extension can talk to what. This walkthrough maps out the moving parts, then gives you the minimal Manifest V3 code for a panel, an Elements sidebar, page inspection and network monitoring.

The four pieces and what each can reach

A DevTools extension is really four cooperating contexts. Getting this table straight saves hours of "why is this undefined?" debugging:

Piece What it's for Can it touch the page DOM?
DevTools page Runs whenever DevTools opens; creates panels and panes No (it uses inspectedWindow.eval instead)
Panel HTML The UI your users actually see No
Service worker Background hub that routes messages No
Content script Lives inside the inspected page Yes

The key point: the DevTools page has the DevTools APIs but no direct DOM access, while the content script has DOM access but no DevTools APIs. Everything else is plumbing between them.

Wire it up in the manifest

You only need one special key, devtools_page. Add scripting if you plan to inject content scripts from DevTools later.

{
  "manifest_version": 3,
  "name": "My Debugger",
  "version": "1.0.0",
  "devtools_page": "devtools.html",
  "permissions": ["scripting"],
  "background": { "service_worker": "background.js" },
  "content_scripts": [
    { "matches": ["<all_urls>"], "js": ["content.js"] }
  ]
}
Enter fullscreen mode Exit fullscreen mode

devtools.html is just a shell that loads devtools.js. That script is where you register your panel:

// devtools.js
chrome.devtools.panels.create(
  'My Debugger',        // tab title
  'icons/16.png',       // 16x16 icon
  'panel.html',         // your panel UI
  (panel) => {
    panel.onShown.addListener(() => { /* refresh data */ });
    panel.onHidden.addListener(() => { /* pause expensive work */ });
  }
);
Enter fullscreen mode Exit fullscreen mode

Use onShown and onHidden to avoid burning CPU while your tab isn't visible. (Chrome's devtools.panels reference also documents a promise-returning form of create.)

Add a sidebar pane to the Elements panel

Sometimes you don't need a whole tab, just extra info about the selected node. createSidebarPane gives you a pane inside Elements that can show a JSON object, the result of an expression evaluated in the page, or a full HTML page of your own.

Pair it with onSelectionChanged and $0 (the currently selected element) to keep it in sync:

chrome.devtools.panels.elements.createSidebarPane('Node Info', (pane) => {
  const update = () => {
    pane.setExpression(`(() => {
      const el = $0;
      if (!el) return null;
      return {
        tag: el.tagName,
        id: el.id,
        classes: [...el.classList],
        dataset: { ...el.dataset },
        color: getComputedStyle(el).color
      };
    })()`);
  };
  chrome.devtools.panels.elements.onSelectionChanged.addListener(update);
  update();
});
Enter fullscreen mode Exit fullscreen mode

Inspect the page and watch the network

Two APIs do most of the real work in a debugging panel.

1. Run code in the inspected page. chrome.devtools.inspectedWindow.eval() executes a string in the page and hands you the result. Console helpers like $$ and inspect work here too. A quick accessibility check, for example:

chrome.devtools.inspectedWindow.eval(
  "$$('img:not([alt])').length",
  (count) => console.log(`${count} images are missing alt text`)
);
Enter fullscreen mode Exit fullscreen mode

2. Observe finished requests. chrome.devtools.network.onRequestFinished fires for each completed request, so you can flag failures and peek at JSON bodies:

chrome.devtools.network.onRequestFinished.addListener((request) => {
  if (request.response.status >= 400) {
    console.warn('Failed:', request.request.url, request.response.status);
  }
  if (request.response.content.mimeType === 'application/json') {
    request.getContent((body) => { /* parse and render */ });
  }
});
Enter fullscreen mode Exit fullscreen mode

Messaging, injection and knowing when DevTools closes

When your panel needs live data from the page's content script, route it through the service worker:

  1. The DevTools page opens a long-lived port with chrome.runtime.connect and tells the worker which tab it is inspecting (chrome.devtools.inspectedWindow.tabId).
  2. The service worker keeps a map of tab ID to DevTools port.
  3. When a content script sends a message, the worker looks up the sender's tab and forwards it to the matching port.

If the content script isn't on the page yet, the DevTools page can inject one with chrome.scripting.executeScript, targeting the inspected tab's ID.

Detecting when DevTools closes is the classic gotcha: DevTools pages don't fire unload events reliably. Instead, treat the port connection as the session. Send a heartbeat over the port every 15 seconds and run your cleanup in the worker's onDisconnect handler.

Key takeaways

  • A DevTools extension has four contexts: the DevTools page, panel UI, service worker and content script. Only the content script touches the DOM directly.
  • devtools_page in the manifest plus chrome.devtools.panels.create() is all a basic panel needs.
  • Elements sidebar panes combined with onSelectionChanged and $0 are a lightweight alternative to a full panel.
  • inspectedWindow.eval() and network.onRequestFinished cover most inspection needs.
  • Use the service worker as a tab-to-port router, and rely on port disconnects plus a heartbeat rather than unload events.

Start with a bare panel, add page evaluation next, and grow it into a full tool from there. The original article has the complete guide to building custom Chrome DevTools panels and sidebar panes with every file in full, and once your tool is live, ExtensionBooster's growth tools for extension developers can help it find users.

What's the one debugging panel you wish existed in Chrome DevTools for your own stack?

Top comments (0)