Skip to content

kimtth/mini-chronium-mojo-ipc-cdp-protocol

Repository files navigation

Chromium IPC Demonstrations

Practical examples of Mojo IPC (Chromium's inter-process communication) and Chrome DevTools Protocol (CDP).

Overview

Mojo IPC

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

Chrome DevTools Protocol (CDP)

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.

Examples

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

Architecture

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

Comparison

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

Requirements

  • Python 3.7+, Node.js 14+
  • websockets (Python) / ws (Node.js)
  • Chrome/Chromium browser
  • No Chromium build required for examples

Key Resources

License

MIT

About

πŸ§©πŸ”— [Note] Chromium-style Mojo IPC, Chrome DevTools Protocol (CDP) for interprocess communication

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors