Skip to content

Sukhtumur/neurochrome

Repository files navigation

Local Web Brain 🧠

Hybrid AI cognitive extension that turns browsing history into semantic memory

A Chrome extension built for the Google Chrome Built-in AI Challenge 2025 that uses a hybrid AI strategy: Chrome Built-in AI (Gemini Nano) when available, Gemini API as reliable cloud fallback. This creates an intelligent, searchable memory of your browsing history with production-ready reliability.

Version License Chrome AI Competition

οΏ½ Hybrid AI Strategy

What makes this extension special:

  • 🎯 Production Ready: Works reliably TODAY, even in Chrome builds without AI APIs
  • πŸ”„ Automatic Fallback: Tries Chrome Built-in AI first, seamlessly falls back to Gemini API
  • πŸ”’ Privacy First: On-device processing when available, secure cloud fallback when needed
  • πŸš€ Future Proof: Gets better as Chrome AI rolls out, never breaks
  • βœ… All 6 APIs: Complete implementation of all Chrome Built-in AI capabilities

🌟 Features

  • πŸ€– Hybrid AI: Chrome Built-in AI (primary) + Gemini API (fallback) for 100% reliability
  • 🧠 Semantic Memory: Convert web pages into searchable semantic memories with AI embeddings
  • πŸ“ AI Summarization: Automatic 2-3 sentence summaries of every page you visit
  • 🌐 AI Translation: Translate memories to any language
  • ✏️ AI Rewriting: Reformat summaries with different tones, lengths, and formats
  • πŸ” Natural Language Search: Query your history using plain English via omnibox (lw <query>)
  • πŸ” AES-GCM Encryption: Summaries encrypted locally using Web Crypto API
  • ⚑ Vector Similarity Search: Find relevant pages using cosine similarity
  • 🎨 Beautiful UI: Clean, modern interface built with Svelte and TailwindCSS
  • πŸ“Š Statistics Dashboard: Track your knowledge base growth

πŸ“‹ Table of Contents

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Chrome Extension                         β”‚
β”‚                                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ Content       β”‚   β”‚ AI          β”‚   β”‚ Vector         β”‚  β”‚
β”‚  β”‚ Scraper       │───│ Summarizer  │───│ Search Engine  β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚          β”‚                  β”‚                    β”‚          β”‚
β”‚          β–Ό                  β–Ό                    β–Ό          β”‚
β”‚     Page Text         Summaries +           IndexedDB       β”‚
β”‚                       Embeddings            (Encrypted)     β”‚
β”‚          β”‚                  β”‚                    β”‚          β”‚
β”‚          └─────────► Query Handler β—„β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β”‚                          β”‚                                  β”‚
β”‚                     Omnibox & Popup                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow

  1. Capture: When you visit a page, content script extracts main text
  2. Summarize: Background worker uses Chrome AI Summarizer to compress content
  3. Embed: Text is converted to vector embeddings using Chrome AI
  4. Encrypt: Summary is encrypted with AES-GCM
  5. Store: Memory is saved to IndexedDB with embedding
  6. Query: Use omnibox to search memories semantically
  7. Answer: AI Writer composes answer from relevant memories

πŸ› οΈ Tech Stack

Core Technologies

  • TypeScript: Type-safe development
  • Vite: Lightning-fast build tool
  • Svelte: Reactive UI framework
  • TailwindCSS: Utility-first styling

Chrome APIs

  • chrome.ai.summarizer - Compress page content
  • chrome.ai.prompt - Generate embeddings
  • chrome.ai.writer - Compose answers
  • chrome.ai.translator - Multilingual support
  • chrome.ai.proofreader - Clean responses
  • chrome.tabs - Page monitoring
  • chrome.scripting - Content injection
  • chrome.omnibox - Search interface
  • chrome.storage - Configuration sync

Data Layer

  • Dexie.js: IndexedDB abstraction
  • Web Crypto API: AES-GCM encryption
  • Vector Search: Cosine similarity

Development Tools

  • ESLint + Prettier: Code quality
  • Vitest: Unit testing
  • web-ext: Development workflow

πŸ“¦ Installation

Quick Start (Works Immediately!)

The extension uses a hybrid AI strategy and works right away:

  1. Install the extension
  2. Configure Gemini API key (free from Google AI Studio)
  3. Start browsing!

Chrome Built-in AI is optional but recommended for privacy.

Prerequisites

  • Chrome Canary (v143+) or Chrome Stable (when AI APIs launch)
  • Node.js (v18+)
  • Gemini API Key (free tier available)

Option A: Gemini API Only (Recommended for Testing)

No Chrome AI setup needed! This is the fastest way to get started:

  1. Build extension (see below)
  2. Load in Chrome
  3. Open Settings tab
  4. Get free API key: Google AI Studio
  5. Paste key and save
  6. Start browsing!

βœ… Works in: Chrome Stable, Chrome Canary, any Chrome 120+
βœ… Setup time: 5 minutes
βœ… Reliability: 100% (cloud-based)

Option B: Chrome Built-in AI + Gemini Fallback (Best of Both Worlds)

For maximum privacy and performance:

  1. Enable Chrome AI APIs (detailed guide)

    • Navigate to chrome://flags/#optimization-guide-on-device-model
    • Set to "Enabled BypassPerfRequirement"
    • Navigate to chrome://flags/#prompt-api-for-gemini-nano
    • Set to "Enabled"
    • Restart Chrome
  2. Build & configure extension

  3. Extension will automatically use Chrome AI when available

  4. Falls back to Gemini API seamlessly

βœ… Works in: Chrome Canary (143+)
βœ… Privacy: On-device processing
βœ… Performance: Instant responses
βœ… Fallback: Gemini API if Chrome AI unavailable

Build & Install Extension

# Clone repository
git clone https://github.com/Sukhtumur/neurochrome.git
cd neurochrome

# Install dependencies
npm install

# Build for production
npm run build

Load in Chrome

  1. Open chrome://extensions/
  2. Enable "Developer mode"
  3. Click "Load unpacked"
  4. Select the dist folder
  5. Click extension icon β†’ Settings tab
  6. Configure Gemini API key

Verify Setup

Open Settings tab in extension popup:

  • Provider Badge: Shows "Using Chrome AI" (green) or "Using Gemini API" (purple)
  • All 6 APIs: Should show green checkmarks βœ“
  • Status Message: Confirms active AI provider

See TESTING_GUIDE.md for detailed testing steps.

πŸš€ Usage

Auto-Capture Mode

By default, the extension automatically captures and indexes pages you visit:

  1. Browse normally
  2. Extension extracts content in background
  3. AI generates summary and embedding
  4. Memory stored locally (encrypted)

Omnibox Search

Type brain in Chrome's address bar, then your query:

brain what did I read about machine learning yesterday?
brain show me articles about climate change
brain find that recipe I saw last week

Popup Interface

Click the extension icon to:

  • Search: Manual query with detailed results
  • Memories: Browse and manage stored pages
  • Statistics: View storage stats and insights

πŸ“ Project Structure

local-web-brain/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ background/           # Service worker
β”‚   β”‚   └── background.ts
β”‚   β”œβ”€β”€ content/              # Content scripts
β”‚   β”‚   └── content-script.ts
β”‚   β”œβ”€β”€ popup/                # Popup UI
β”‚   β”‚   β”œβ”€β”€ App.svelte
β”‚   β”‚   β”œβ”€β”€ popup.ts
β”‚   β”‚   └── index.html
β”‚   β”œβ”€β”€ components/           # Svelte components
β”‚   β”‚   β”œβ”€β”€ SearchBar.svelte
β”‚   β”‚   β”œβ”€β”€ MemoryList.svelte
β”‚   β”‚   └── Stats.svelte
β”‚   β”œβ”€β”€ lib/                  # Core business logic
β”‚   β”‚   β”œβ”€β”€ ai/              # Chrome AI services
β”‚   β”‚   β”‚   └── chrome-ai.ts
β”‚   β”‚   β”œβ”€β”€ db/              # Database layer
β”‚   β”‚   β”‚   β”œβ”€β”€ database.ts
β”‚   β”‚   β”‚   └── repository.ts
β”‚   β”‚   β”œβ”€β”€ vector/          # Vector search
β”‚   β”‚   β”‚   └── index.ts
β”‚   β”‚   β”œβ”€β”€ crypto/          # Encryption
β”‚   β”‚   β”‚   └── index.ts
β”‚   β”‚   └── query/           # Query orchestration
β”‚   β”‚       └── index.ts
β”‚   β”œβ”€β”€ types/               # TypeScript definitions
β”‚   β”‚   β”œβ”€β”€ index.ts
β”‚   β”‚   └── chrome-ai.d.ts
β”‚   β”œβ”€β”€ utils/               # Utilities
β”‚   β”‚   β”œβ”€β”€ helpers.ts
β”‚   β”‚   └── logger.ts
β”‚   └── tests/               # Unit tests
β”‚       β”œβ”€β”€ setup.ts
β”‚       └── helpers.test.ts
β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ manifest.json
β”‚   └── icons/
β”œβ”€β”€ vite.config.ts
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ tailwind.config.js
└── package.json

Clean Architecture Layers

  1. Presentation (components/, popup/): UI components
  2. Application (lib/query/): Business logic orchestration
  3. Domain (types/): Core entities and interfaces
  4. Infrastructure (lib/ai/, lib/db/, lib/crypto/): External services
  5. Utilities (utils/): Shared helpers

πŸ’» Development

Commands

# Development with hot reload
npm run dev

# Production build
npm run build

# Run tests
npm test

# Lint code
npm run lint

# Format code
npm run format

# Test with web-ext
npm run web-ext

Code Style

  • Clean Code: Descriptive names, single responsibility
  • SOLID Principles: Dependency injection, interface segregation
  • Type Safety: Strict TypeScript, no any
  • Error Handling: Custom error types, try-catch blocks
  • Documentation: JSDoc comments, inline explanations

Testing

# Run all tests
npm test

# Watch mode
npm test -- --watch

# Coverage
npm test -- --coverage

πŸ€– AI Implementation

Hybrid AI Service

The extension uses an intelligent hybrid approach:

// Automatically tries Chrome AI first, falls back to Gemini
const summary = await hybridAI.summarize(text)
const embedding = await hybridAI.embed(text)
const translated = await hybridAI.translate(text, 'es')

All 6 Chrome Built-in AI APIs

βœ… Summarizer: Compress page content to 2-3 sentences
βœ… Embeddings: Convert text to semantic vectors (384-dim)
βœ… Writer: Generate natural language responses
βœ… Translator: Translate to any language
βœ… Proofreader: Clean and correct text
βœ… Rewriter: Reformat with tone/length/format options

Fallback Strategy

Chrome AI Available β†’ Use on-device processing (instant, private)
Chrome AI Unavailable β†’ Use Gemini API (1-2s delay, reliable)
Both Unavailable β†’ Show helpful error message

Code Example

// Initialize hybrid service
await hybridAI.initialize({
  apiKey: userGeminiKey // from Settings
})

// Use any AI function - automatic fallback
const summary = await hybridAI.summarize(pageText)
const embedding = await hybridAI.embed(summary)
const translated = await hybridAI.translate(summary, 'spanish')
const rewritten = await hybridAI.rewrite(summary, { 
  tone: 'professional',
  length: 'short'
})

See hybrid-ai.ts for implementation.

πŸ” Privacy & Security

Privacy Guarantees

βœ… Chrome AI: 100% offline, on-device processing
βœ… Gemini API: Only summaries sent (not full page content)
βœ… Local Storage: All data in IndexedDB on your device
βœ… No Analytics: Zero tracking or user profiling
βœ… Open Source: Auditable codebase

Security Features

  • AES-GCM Encryption: Summaries encrypted with 256-bit keys
  • Secure Key Storage: Gemini API key in chrome.storage.sync
  • Content Security Policy: Strict CSP in manifest
  • HTTPS Only: Gemini API calls over secure connection
  • Input Validation: Sanitization of all user inputs
  • XSS Protection: Svelte's auto-escaping

Data Retention

  • Max 10,000 memories (configurable)
  • Auto garbage collection when limit reached
  • Manual "Clear All" option in popup

🎯 Chrome AI Challenge Alignment

Criterion Implementation
Use of Built-in AI All 5 Chrome AI APIs used natively
Innovation Semantic browser memory, offline cognitive extension
Privacy Zero network calls, local encryption, no tracking
Usability Omnibox integration, clean UI, natural language queries
Technical Depth Vector search, encryption, repository pattern, clean architecture
Scalability Efficient indexing, cosine similarity, auto GC

🀝 Contributing

Contributions welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Guidelines

  • Follow existing code style
  • Add tests for new features
  • Update documentation
  • Keep commits atomic and descriptive

πŸ“„ License

MIT License - see LICENSE file for details

πŸ™ Acknowledgments

  • Chrome Built-in AI team for Gemini Nano APIs
  • Dexie.js for excellent IndexedDB abstraction
  • Svelte team for reactive simplicity
  • TailwindCSS for utility-first styling

πŸ“ž Contact


Built with ❀️ for the Chrome Built-in AI Challenge

Turn your browser into a second brainβ€”privately and intelligently.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published