LinguaLens is a local-first browser extension that uses WebGPU to run powerful AI models (like Phi-3 and Qwen2) directly in your browser. It translates subtitles on streaming sites (YouTube, Netflix, etc.) into English with rich context (definitions, pronunciation, usage notes) without sending data to any server.
- Local AI: Runs 100% offline using
WebLLMand WebGPU. - Privacy First: No data collection; your browsing history stays on your device.
- Smart Context: Provides meanings, key phrases, and grammar notes, not just direct translations.
- Universal Support: Works on YouTube, Netflix, Prime Video, Disney+, and Hotstar.
- Performance: High-speed inference using optimized WASM kernels.
The project is built with WXT (Web Extension Framework), React, Tailwind CSS, and TypeScript.
-
llm-engine.ts: The brain of the operation.- Wraps
@mlc-ai/web-llmto manage the AI model. - Handles model downloading, caching, and initialization.
- Key Function:
translate(text, source, target)- Generates JSON-structured translations. - Now runs in-process within the offscreen document to comply with Manifest V3.
- Wraps
-
offscreen-engine.ts: The bridge between the background script and the heavy AI model.- Runs in a hidden
offscreendocument to access full DOM/WebGPU capabilities without slowing down the browser UI. - Routes messages:
Background->Offscreen->LLM->Background.
- Runs in a hidden
-
detectors/: Subtitle extraction logic.base.ts: Abstract class for creating site-specific detectors.registry.ts: Matches the current URL to the correct detector (e.g.,YouTubeDetector,NetflixDetector).sites.ts: Implementations finding subtitle DOM elements on specific platforms.
-
ui/tooltip.ts: The visual overlay.- Built with Vanilla JS + Shadow DOM to isolate styles from the host page.
- Displays loading states, results, and errors right next to the subtitle.
-
prompt.ts: Prompt engineering.- Constructs the strict system prompts that force the LLM to return valid JSON and stick to English output.
-
background.ts: The central nervous system.- Service worker that coordinates messaging.
- Routes translation requests to the offscreen document.
- Manages the lifecycle of the offscreen document.
-
content.ts: The eyes on the page.- Injected into web pages (YouTube, etc.).
- Uses
MutationObserverto detect when subtitles appear. - Handles user clicks and sends
TRANSLATE_REQUESTto the background. - Enforces "English" as the target language.
-
popup/: The settings UI.App.tsx: React application for configuring the extension.- Allows selecting models, viewing download progress, and toggling settings.
- Styled with Tailwind CSS.
-
offscreen.ts:- Minimal HTML/JS entry point that loads
lib/offscreen-engine.ts.
- Minimal HTML/JS entry point that loads
- Chrome 113+ (or Edge/Brave)
- A GPU with support for WebGPU (most modern laptops/desktops).
- Clone the repo and run
npm install. - Run
npm run build. - Load the
.output/chrome-mv3folder inchrome://extensions(Developer Mode enabled).
- Click the extension icon and select Download Model (approx. 2GB, one-time).
- Open a video on YouTube/Netflix with captions enabled.
- Hover & Click on any subtitle line.
- Standard translations + context will appear instantly.
- Model: Switch between
Phi-3-mini(High Quality) andLlama-3-8B(Experimental) in the popup. - Cloud Fallback: Provide an OpenAI key in settings if your device is too slow for local AI.
Built with ❤️ by LinguaLens Team