Practical examples of Mojo IPC (Chromium's inter-process communication) and Chrome DevTools Protocol (CDP).
Chromium's type-safe IPC system using message pipes and .mojom IDL files.
Key benefits: Type safety, zero-copy messaging, process isolation, cross-language support.
When to use: Multi-process architecture, performance-critical IPC, sandboxed processes.
Mojo IDL syntax:
interface UserService {
GetUser(int32 id) => (User user, Status status);
LogEvent(string event); // One-way
};
Common types: bool, int32/uint32, int64/uint64, float, double, string, array<T>, map<K,V>, T?
Real Chromium IPC:
- Renderer β Browser: DOM, navigation, resources
- Browser β GPU: Graphics commands
- Browser β Network Service: HTTP, cookies
- Browser β Storage: IndexedDB, Cache API
WebSocket-based debugging protocol for browser automation and inspection.
Features: JSON-RPC messages, remote debugging, tab management, network/DOM inspection.
Use cases: Puppeteer, Playwright, performance monitoring, screenshot generation.
| File | Purpose | Usage |
|---|---|---|
cdp_example.py |
Chrome DevTools Protocol (Python) | pip install websockets && python cdp_example.py |
cdp_example.js |
Chrome DevTools Protocol (Node.js) | npm install ws && node cdp_example.js |
mojo_ipc_simulation.py |
Mojo IPC simulation using multiprocessing | python mojo_ipc_simulation.py |
mojom_loader.py |
Parse & load real .mojom files, generate Python bindings | python mojom_loader.py |
browser_service.mojom |
Sample Mojo interface definition | Reference for .mojom syntax |
Mojo Code Generation Flow:
.mojom file β Build System β Generate C++ bindings β Server (Receiver) + Client (Remote)
Mojo IPC Communication:
Renderer Process Browser Process
| |
|-------[Message Pipe]-------|
|β CreateTab("http://...") β|β Execute CreateTab()
|β {tab_id} β|β Return tab_id
CDP Communication:
Client β WebSocket β Chrome Browser
β {Target.createTarget}
β {targetId, success}
Chromium Multi-Process with Mojo:
Browser Process (privileged)
ββ BrowserService impl
ββ Receiver<BrowserService>
β [Mojo Message Pipes]
ββ Renderer Process (sandboxed) β¬β GPU Process β¬β Network Service
ββ Remote<BrowserService> ββ GPUService ββ URLLoader
ββ Blink Engine ββ Graphics ββ CookieManager
| Feature | Mojo IPC | CDP |
|---|---|---|
| Purpose | Internal Chromium IPC | External debugging/automation |
| Protocol | Binary message pipes | JSON over WebSocket |
| Type Safety | Strongly typed | JSON schema |
| Performance | Optimized | Human-readable |
| Access | Requires build | Works with any Chrome |
| Language | C++/Java/JS | Any language with WebSocket |
- Python 3.7+, Node.js 14+
websockets(Python) /ws(Node.js)- Chrome/Chromium browser
- No Chromium build required for examples
MIT