Repository navigation
Architecture
Rishap Gandhi edited this page Jun 15, 2026
·
1 revision
Context Harvester is a cross-browser extension built with WXT framework. It uses a background service worker for coordination, content scripts for text capture, and React-based UI for the side panel and popup.
User Selection → Content Script → Background Worker → Storage
↓
Side Panel / Popup / Export
| Component | Path | Purpose |
|---|---|---|
| Background | entrypoints/background.ts |
Context menu, keyboard shortcuts, message routing |
| Content Script | entrypoints/content.ts |
Captures text selection on Alt+C |
| Side Panel | entrypoints/sidepanel/ |
Main UI: snippet list, token counter, export |
| Popup | entrypoints/popup/ |
Quick status view with shortcut hints |
| Storage | shared/storage.ts |
Abstraction over browser.storage.local via WXT |
| Token Counter | shared/token-counter.ts |
Token estimation using gpt-tokenizer
|
| Export | shared/export-formats.ts |
Markdown, Prompt XML, JSON formatters |
| Types | shared/types.ts |
TypeScript interfaces for Snippet, Collection, etc. |
- Single codebase builds for Chrome MV3 and Firefox
- Auto-generates browser-specific manifests
- Hot-reload during development
- Built-in storage utilities with type-safe wrappers
- Lightweight (< 1kb) vs Redux
- Works across extension contexts
- No boilerplate
- Runs locally (no API calls)
- Accurate BPE tokenization
- Same algorithm as tiktoken
- Accessible (keyboard + screen reader support)
- Lightweight, no jQuery dependency
- Built for React
All data persisted in browser.storage.local:
// Key: "local:snippets"
Snippet[] — Array of all collected snippets
// Key: "local:targetModel"
ModelId — 'gpt-4' | 'claude' | 'gemini'| API | Purpose |
|---|---|
browser.contextMenus |
Right-click "Add to Context" |
browser.commands |
Alt+C keyboard shortcut |
browser.storage.local |
Persist snippets and settings |
browser.tabs.query |
Get active tab URL/title |
browser.tabs.sendMessage |
Trigger content script |
browser.runtime.onMessage |
Inter-component messaging |
browser.sidePanel (Chrome) |
Open side panel UI |
| Output | Size |
|---|---|
| background.js | ~1 MB (includes gpt-tokenizer BPE data) |
| sidepanel chunk | ~47 kB |
| content script | ~3.5 kB |
| Tailwind CSS | ~9 kB |