How mem0ai/mem0-chrome-extension works
Project type and purpose
• This is a browser (Chrome) extension that injects code into multiple AI-assistant web pages (ChatGPT, Claude, Perplexity, etc.) to capture, store, and replay conversational context via the Mem0 API.
• Its main goal is to provide “universal memory” across different LLM chat interfaces.
High-level architecture and key components
a. Chrome Extension Host
– manifest.json: declares permissions, scripts, UI entry points.
b. Background Module
– background.js: central event handler (message routing, API calls, storage sync).
c. Content-Script Modules
– chatgpt/content.js, claude/content.js, perplexity/content.js, etc.: site-specific injectors that
• listen to page events (message sends, UI clicks)
• extract conversational context
• relay messages to the background script
d. UI Modules
– popup.html + popup.js: “one-click sync” and configuration interface.
– sidebar.js: in-page sidebar interface for memory dashboard.
e. Data Storage
– chrome.storage.local (or sync): caches user API key, user ID, cached memories.
f. External Services
– Mem0 REST API: endpoints for storing/retrieving memories.
– Google OAuth (sign-in) endpoint.
Relationships and data flows
• Content Script ↔ Background
– Uses chrome.runtime.sendMessage / onMessage listeners.
– Flow: user types → content script captures → sends “storeMemory” to background → background calls Mem0 API → response → content script injects suggestions.
• UI ↔ Background
– Popup or sidebar invokes background API (chrome.runtime.sendMessage) to perform actions (fetch all stored memories, update API key).
• Background ↔ Mem0 API
– HTTP(S) requests (fetch/XHR) using stored API key and user ID.
– Handles JSON payloads for memory extract/retrieve.
• Background ↔ chrome.storage
– Persists API credentials and optionally caches recent memories.
Architectural patterns and design principles
• Event-driven messaging: loose coupling between injectors, UI, and background.
• Single-source-of-truth: background script orchestrates all external calls and storage.
• Modular content scripts: one per supported assistant, share common messaging interface.
• Separation of concerns:
– Content scripts only handle DOM events and message passing.
– Background handles business logic & network.
– Popup/sidebar handle user interactions & configuration.