Inspiration

Every day, millions of users encounter Terms of Service and Privacy Policy pop-ups on websites. Most people skip reading them entirely—not out of negligence, but out of necessity. These documents are often thousands of words of dense legal jargon that would take 30+ minutes to read carefully. We wanted to solve this problem by making legal documents instantly understandable, right in the browser, without requiring users to share their data with external servers.

We realized that with Chrome's new on-device AI capabilities (Gemini Nano), we could summarize complex legal language locally on a user's device—meaning 100% privacy and zero data sharing with third parties. LegalLens was born from the belief that users deserve transparency without the complexity.


What it does

LegalLens is a Chrome extension that automatically detects, extracts, and simplifies Terms of Service and Privacy Policy documents using Chrome's built-in Gemini Nano AI.

Key Features:

  1. Smart ToS Detection & Fetching

    • Automatically scans web pages for Terms of Service and Privacy Policy links
    • Prioritizes links by relevance (analyzes URLs, link text, metadata)
    • Intelligently fetches and verifies ToS documents to ensure accuracy
  2. AI-Powered Summarization

    • Uses Chrome's Gemini Nano Summarizer API to simplify complex legal text
    • Condenses lengthy documents into clear, understandable summaries
    • All processing happens on-device—nothing is sent to external servers
  3. Interactive Chatbot

    • Ask natural language questions about the document (e.g., "What about privacy?" or "Do they share my data?")
    • Uses Chrome's Prompt API to provide context-aware, instant answers
    • On-device processing ensures complete privacy
  4. Automatic Multilingual Support

    • Detects your browser's language preference
    • Auto-translates summaries using Chrome's Translator API
    • Supports English, Spanish, French, German, and 100+ language pairs
    • UI and content both in your preferred language
  5. Save & Compare

    • Store summaries of Terms of Service across websites
    • Compare summaries to identify changes or patterns
    • Build a personal reference library of company policies
  6. Privacy-First Design

    • 100% on-device processing—no cloud uploads
    • No external API calls or third-party data sharing
    • Operates fully offline (after initial Chrome setup)

How we built it

Technology Stack:

  • Chrome Manifest V3 - Modern extension architecture
  • Chrome APIs Used:
    • chrome.tabs - Extract page content
    • chrome.storage - Save summaries locally
    • chrome.i18n - Multilingual UI support
    • Gemini Nano Summarizer API - On-device AI summarization
    • Prompt API - On-device chatbot interactions
    • Translator API - On-device multilingual translation
    • Language Detector API - Auto-detect document language

Architecture:

  1. background.js - Service worker handling API calls and task orchestration
  2. contentScript.js - Detects ToS links on pages, fetches documents, extracts content
  3. popup.html/js/css - User interface for displaying summaries, chatbot, and options
  4. i18n system - Localization for UI in English, Spanish, French, German

Key Implementation Challenges Solved:

  1. Document Verification - Built a verification system that validates fetched content is actually a ToS document by checking for legal terminology
  2. Context Injection - Designed a system to inject full document context into the Prompt API while respecting token limits
  3. Async Flow Management - Orchestrated complex async operations: detect → fetch → verify → summarize → translate
  4. CORS Handling - Implemented solutions for fetching cross-origin ToS documents through content scripts
  5. Progressive Enhancement - Extension gracefully degrades functionality if newer APIs aren't available

Challenges we ran into

1. Chrome API Availability

Challenge: Different Chrome versions support different APIs. Gemini Nano requires Chrome 122+, Translator API requires 138+, and the Prompt API is still experimental.

Solution: Implemented feature detection and graceful fallbacks. Users get told which features require which Chrome versions, and the extension continues to work with available APIs.

2. Fetching ToS Documents Across Origins

Challenge: Content scripts have limitations with cross-origin requests. Getting ToS from different domains posed CORS issues.

Solution: Used content scripts strategically with proper host permissions and designed the fetching to work within content script constraints.

3. Document Content Extraction

Challenge: ToS documents have wildly different structures—some are plain text, others are nested divs, tables, or iframes. Generic extraction would grab navigation bars, ads, and footers.

Solution: Built a smart extractor that removes common non-content elements (script tags, navigation, footers) and validates that extracted content contains legal terminology.

4. Context Limits for AI

Challenge: Passing full ToS documents to the Prompt API for chatbot context, while staying within token/character limits.

Solution: Implemented intelligent truncation (3000 character limits) and verified the summarized version still contains enough context for the chatbot to answer questions accurately.

5. Multilingual Detection & Translation

Challenge: The summary might be in a different language than the user's browser language. Needed to auto-detect and auto-translate without user intervention.

Solution: Leveraged the Language Detector API to detect summary language, then conditionally translate to browser language using the Translator API.

6. UI Responsiveness

Challenge: AI operations (summarization, translation) take time, but users expect instant feedback.

Solution: Implemented typing indicators, progress messages, and loading states to keep users informed during processing.


Accomplishments that we're proud of

  1. Privacy-First from Day One - Built a tool that respects user privacy by design, not as an afterthought. Every single computation happens locally.

  2. Seamless Multilingual Experience - Created a truly localized experience where UI and content are both in the user's language. No language barriers.

  3. Smart Document Detection - Our ToS detection system isn't just a keyword scanner—it scores links by confidence, fetches the right documents, and verifies content. It's intelligent.

  4. Conversational Interface - The chatbot feature transforms legal documents from read-only text into interactive Q&A. Users can ask follow-up questions and get instant answers.

  5. Robust Architecture - Despite working with experimental Chrome APIs, we built something stable that gracefully handles edge cases and API unavailability.

  6. Complete Documentation - Created comprehensive guides for users and developers, including troubleshooting, feature explanations, and testing procedures.

  7. Full Localization - Implemented i18n system supporting 4 languages out of the box, extensible to more.


What we learned

  1. Constraint-Driven Design - Working within Chrome's security model and experimental API limitations forced us to be creative and thoughtful about architecture. Constraints led to better design.

  2. On-Device AI is a Game-Changer - Local processing removes so many concerns—latency, privacy, connectivity. The future of AI assistants might be fundamentally local-first.

  3. Details Matter - Features like progress indicators, loading states, and clear error messages make the difference between a confusing tool and an intuitive one.

  4. Testing is Critical - With experimental APIs, we couldn't rely on documentation. Extensive manual testing and flag configuration was essential.

  5. User Language Preferences are Powerful - Automatically detecting and respecting browser language settings creates an immediate sense of polish and care.

  6. Iterative Problem Solving - Many challenges (CORS, document extraction, API limitations) didn't have obvious solutions. Breaking them into smaller sub-problems made them tractable.

  7. Chrome's New APIs Enable New Product Categories - The combination of Gemini Nano, Prompt API, Translator, and Language Detector opens possibilities for entirely new types of privacy-first applications.


What's next for LegalLens

Short Term (Next Release):

  • Enhanced ToS Change Detection - Notify users when a website's Terms of Service changes, and highlight what changed
  • Sidebar Integration - Add persistent sidebar for comparing multiple ToS documents side-by-side
  • Export Summaries - Allow users to export summaries as PDF or markdown
  • Custom Keywords - Let users add keywords to search for specific ToS clauses

Medium Term:

  • Privacy Score - Analyze ToS documents and assign privacy scores (e.g., "8/10 Privacy-Friendly")
  • Community Insights - Aggregate anonymized summaries to show users how websites compare on key policies
  • Risk Flagging - Automatically highlight potentially problematic clauses (data selling, unlimited liability, etc.)
  • Multi-Page Support - Handle multi-page ToS documents more intelligently

Long Term:

  • Language Model Expansion - Support other on-device AI models as they become available
  • Integration with Privacy Tools - Work with password managers, VPNs, and ad blockers for a comprehensive privacy suite
  • Cross-Browser Support - Bring LegalLens to Firefox, Edge, and Safari as their on-device AI capabilities mature
  • Enterprise Version - Help organizations review third-party ToS documents before signing

Team & Contact

LegalLens was built with passion for privacy and user empowerment. We believe complex legal language should never be a barrier to understanding your rights.

Repository: legal-lens

Current Status: Active development on the feat/chatbot branch with full multilingual and AI-powered features.


Built with ❤️ for the open web and user privacy.

Built With

  • gemini-nano
  • javascript
  • prompt-api
  • summarizer-api
  • translator-api
Share this project:

Updates