Tutorials

How to Debug Offscreen Pages in Chrome Extension Manifest V3

Learn effective ways to debug offscreen pages in Chrome extensions using Manifest V3. Includes chrome://inspect, logging relay, and DevTools inspection methods.

Mellowtel Team

Mellowtel Team

🐞 How to Debug Offscreen Pages in Chrome Extension Manifest V3

Debugging offscreen pages in Chrome extensions using Manifest V3 can be tricky. Here are three effective methods to help you inspect and debug offscreen functionality.


1. 🔍 Use chrome://inspect/#other

Navigate to:

chrome://inspect/#other

This page lists offscreen pages created by extensions. You can directly access Chrome DevTools for your offscreen page to view console logs, inspect variables, and debug behavior.


2. 📤 Implement a Logging Relay System

If the offscreen page closes too quickly to inspect manually, use a helper function to relay logs to the background script.

In the offscreen page:

const log = async (...args) => chrome.runtime.sendMessage({
  target: 'background',
  type: 'log',
  data: args,
});

In the background script:

chrome.runtime.onMessage.addListener((message) => {
  if (message.target === 'background' && message.type === 'log') {
    console.log(...message.data);
  }
});

Usage:

log('clipboard initialized');

This method ensures you capture logs in the background console, even if the offscreen page terminates quickly.


3. 🔧 Inspect via Chrome Extensions Page

  1. Open chrome://extensions
  2. Find your extension and click Details
  3. Scroll to Inspect views
  4. Click on your offscreen page link

This opens a DevTools window tied specifically to your offscreen page for live debugging and inspection.


By using these methods, you can effectively debug your offscreen pages and overcome the challenges introduced by Manifest V3 restrictions.


If this helped you streamline Chrome extension development, share it with your fellow devs and follow the Mellowtel Team for more insights!

On this page