A Chrome DevTools extension for monitoring and debugging postMessage events on web pages. Built with Manifest V3.
Installation β’ Features β’ Screenshots β’ Usage β’ Developer Guide β’ Contributing
- Dedicated DevTools Panel: View postMessage events in a specialized panel within Chrome DevTools
- Real-time Monitoring: Capture and display postMessage events as they occur
- Syntax Highlighting: JSON data is nicely formatted with color-coded syntax highlighting
- Collapsible JSON: View a compact summary by default, expand to see full details
- Structured Display: View message source, origin, and data in a clean, organized format
- Preserve Log Option: Keep message history when navigating between pages
- Dark Mode Support: Automatically adapts to your browser's dark/light mode preference
- Advanced Filtering: Filter messages by origin or content to find relevant information
- Manifest V3 Compatible: Uses the latest Chrome extension format
The extension will be available in the Chrome Web Store soon.
-
Clone this repository:
git clone https://github.com/oferlmntr/post-message-devtool.git -
Open Chrome and navigate to
chrome://extensions/ -
Enable "Developer mode" by toggling the switch in the top-right corner
-
Click "Load unpacked" and select the directory containing the extension
-
The extension is now installed! Open DevTools (F12 or Cmd+Opt+I on Mac) and look for the "postMessage" tab
- Open Chrome DevTools on any webpage (F12 or Cmd+Opt+I on Mac)
- Navigate to the "postMessage" tab
- As postMessage events occur on the page, they will appear in the panel
- Use the controls at the top to:
- Clear the current messages
- Toggle "Preserve log" to keep messages when navigating
- Open the filter panel to find specific content
postMessage-DevTools/
βββ js/ # JavaScript source files
β βββ background.js # Service worker for message handling
β βββ content-script.js # Content script injected into pages
β βββ panel.js # DevTools panel functionality
β βββ devtools.js # DevTools integration
β βββ code.js # Syntax highlighting functionality
β βββ postMessage-debugger.js # Helper utilities
βββ images/ # Extension icons
βββ docs/ # Documentation assets
βββ test-page/ # Test pages for development
βββ devtools.html # DevTools page HTML
βββ panel.html # Panel UI HTML
βββ popup.html # Extension popup HTML
βββ manifest.json # Extension manifest
βββ README.md # This file
- Injected into every web page
- Overrides the native
window.postMessageandwindow.addEventListenermethods - Captures all postMessage events and sends them to the background service worker
- Handles disconnections and reconnections with the background service worker
- Maintains a message queue when the background service worker is unavailable
- Serves as the central communication hub
- Manages connections with the DevTools panel
- Maintains message history for each tab
- Persists message history to storage
- Processes and forwards messages from content scripts to relevant DevTools panels
- Implements a keep-alive mechanism to prevent service worker termination
- Creates a custom DevTools panel
- Establishes connection with the background service worker
- Displays captured postMessage events
- Implements filtering and searching functionality
- Provides controls for clearing history and toggling preserve log
- Handles formatting and display of message data
- Supports dark/light mode
- Implements syntax highlighting and collapsible JSON
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β β β β
β Web Page β β Background β β DevTools β
β (Content β β Service β β Panel β
β Script) β β Worker β β β
β β β β β β
ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ
β β β
β 1. Override native postMessage β β
β and event listeners β β
β β β
β 2. Capture postMessage event β β
β β β
β 3. Send event to background β β
β βββββββββββββββββββββββββββββββΆ β β
β β 4. Store message in history β
β β β
β β 5. Forward to DevTools panel β
β β (if connected) β
β β βββββββββββββββββββββββββββββββΆ β
β β β 6. Display message
β β β in panel UI
β β β
β β 7. Persist message history β
β β to storage β
β β β
β β β 8. User interacts with
β β β panel (filter, clear)
β β β
β β 9. Panel sends commands β
β β β βββββββββββββββββββββββββββββββ β
β β β
β β 10. Background processes β
β β commands and updates β
β β panel β
β β ββββββββββββββββββββββββββββββΆ β
βΌ βΌ βΌ
Messages are captured and stored in the following format:
{
source: "window" | "iframe", // Source of the message
sourceUrl: String, // URL of the source window/frame
targetUrl: String, // URL of the target window/frame
origin: String, // Origin specified in postMessage
data: Any, // The message data
timestamp: Number, // When the message was sent
tabId: String // ID of the tab where the message occurred
}The extension implements several resilience mechanisms:
- Message Queueing: Content scripts queue messages if the background service worker is unavailable
- Reconnection Logic: Automatic reconnection with exponential backoff
- State Persistence: Message history is saved to storage and reloaded when needed
- Keep-Alive: Background service worker implements keep-alive mechanisms to prevent termination
- Error Handling: Robust error handling throughout to manage Chrome extension lifecycle events
When adding new features, consider the following:
-
Content Script Changes: Modifications to event capturing logic
- Update
content-script.jsfor changes to how postMessage events are intercepted - Be careful with performance impact as content scripts run on every page
- Update
-
Background Logic: Enhancements to message processing or storage
- Update
background.jsfor changes to message handling, storage, or panel communication - Consider backward compatibility with existing message formats
- Update
-
Panel UI: Improvements to the user interface
- Update
panel.htmlandpanel.jsfor UI changes - Follow the existing styling patterns for consistency
- Update
-
Testing: Use the test pages in the
test-page/directory- Add new test cases for your features
- Test across different scenarios (iframes, cross-origin, etc.)
-
Inspect the Extension:
- Right-click the extension icon and select "Inspect popup"
- Use
chrome://extensionsand click "inspect views: service worker" for the background
-
Debug Content Scripts:
- Add
debugger;statements to your content script - Open the DevTools console on the page where the extension is running
- Add
-
Monitor Extension Storage:
- From the extension's service worker DevTools, use
chrome.storage.local.get(null, console.log)
- From the extension's service worker DevTools, use
-
Test in Incognito Mode:
- Enable extension in incognito for testing without other extensions interfering
The extension injects a content script that captures all postMessage events on the page. These events are sent to the background service worker, which maintains a history of messages and communicates with the DevTools panel when it's open.
- Debugging Cross-Origin Communication: Easily view messages sent between frames or windows
- Front-end Development: Understand message flow in complex applications
- Security Testing: Analyze postMessage usage for potential vulnerabilities
- API Debugging: Inspect data passed through postMessage interfaces
- Framework Development: Debug messaging systems built on top of postMessage
Contributions are welcome and appreciated! Please feel free to submit a Pull Request.
See CONTRIBUTING.md for more information on how to contribute to this project.
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions or feedback, please open an issue on the GitHub repository.

