How utkarshthedev/webpresence works
Project Type and Purpose
• Web Presence is a full‐stack application combining a browser extension (client) with a backend server.
High‐Level Components
A. Client (Browser Extension)
1. Chrome Extension (Manifest V3)
• popup.html/css/js: UI for toggle and status
• background.js: listens for tab changes, sends events to server
2. Firefox Extension (Manifest V2)
• same structure as Chrome, with Firefox APIs
B. Server (Bun/Node.js)
• websocket.ts: WebSocket server to receive client events
• discord.ts: Uses discord-rpc package to update Rich Presence
• config.ts: Holds Discord Client ID and configuration
C. Assets
D. Scripts (Offline Tools)
E. External Services
• Discord Desktop App (RPC endpoint)
Relationships and Data Flows
2. Background script
→ Captures active tab URL & favicon
→ Opens/maintains WebSocket connection to server
→ Sends “presence_on/off” and “tab_update” events
3. WebSocket server
→ Receives events, validates via config.ts
4. Discord RPC client
→ Receives event payload
→ Calls Discord’s local RPC socket to update Rich Presence
5. Scripts run separately to populate assets before deployment
Architectural Patterns & Principles
• Event‐driven: client emits events, server reacts asynchronously
• Pub/Sub style: each tab update is published via WebSocket
• Separation of Concerns:
• UI (popup) vs. background logic in extension
• WebSocket handling vs. Discord RPC logic in server