# Gemma Gem

A Chrome extension that runs Google's Gemma 4 model entirely on-device via WebGPU. No API keys, no cloud, no data leaving your machine. It acts as a browser AI assistant that can read pages, take screenshots, click elements, type into fields, and run arbitrary JavaScript.

**How it works:** three components coordinate inside the extension. An offscreen document hosts the model (loaded via `@huggingface/transformers` + WebGPU). A service worker routes messages, captures screenshots, and runs JS. A content script injects a chat UI as a shadow DOM widget (the gem icon in the bottom-right) and handles DOM manipulation tools.

**Available tools the model can call:**
- `read_page_content` — extract text/HTML via CSS selector
- `take_screenshot` — capture visible page as PNG
- `click_element` — click by CSS selector
- `type_text` — fill in form fields
- `scroll_page` — scroll by pixel amount
- `run_javascript` — execute arbitrary code with full DOM access

**Model options:** Gemma 4 E2B (~500MB) or E4B (~1.5GB), ONNX-quantized (q4f16), 128K context window. Cached after first download. Supports Gemma 4's native "thinking mode" for extended reasoning.

**Config:** model selection, thinking mode toggle, max tool call iterations per request, per-site disable list.

**Interesting detail:** the `agent/` directory has zero external dependencies and defines reusable interfaces (`ModelBackend`, `ToolExecutor`), so the agent loop could be extracted as a standalone library.

**Limitations:** Chrome-only (needs WebGPU). Gemma 4 2B/4B are small models — don't expect Claude-level output. Needs a decent GPU for reasonable speed.

**Repo:** https://github.com/kessler/gemma-gem — 79 stars, Apache-2.0.
