I Built a Fully Local Prompt Enhancer Chrome Extension with Gemini Nano
Source: Dev.to
The Problem: We Underspecify Prompts
Most people use ChatGPT (or any LLM) like a search bar: dump a half‑formed thought, hit Enter, and hope for magic. The result is usually OK, but not great.
Common issues
- Vague prompts such as “explain this topic for my exam” with no level, context, or constraints.
- Coding requests lacking input/output format, edge cases, or performance constraints.
- Writing tasks missing target audience, tone, or length.
A well‑designed prompt can:
- Save multiple back‑and‑forth iterations.
- Produce more reliable and testable outputs (especially for code and analysis).
- Make AI tools actually usable in real workflows.
The Idea
What if you could type as you usually do, then hit one button that rewrites your rough text into a high‑quality prompt?
Prompt Enhancer does exactly that on top of ChatGPT, adding a tiny bit of super‑power without changing the usual workflow.
How It Works from the User’s Perspective
- Install and enable the extension.
- Open ChatGPT in Chrome.
- Type any rough idea into the input box.
- A small “Enhance” button appears beside the textarea.
- Click Enhance (or use the keyboard shortcut) → wait a moment → the rough text is replaced with a refined, structured prompt.
The enhanced prompt typically:
- Adds missing context (audience, constraints, format).
- Clarifies the task (summarise vs critique vs generate vs explain).
- Specifies outputs (bullet list, table, code with comments, etc.).
You can review the rewritten prompt, tweak it if needed, then hit Enter as usual.
Keyboard Shortcut
A configurable shortcut lets power users keep the flow entirely on the keyboard:
Type → Enhance → Enter
Technical Architecture
Prompt Enhancer is a Manifest V3 Chrome extension composed of three main pieces:
manifest.json– declares permissions, content‑script matches, and other metadata.- Content script – interacts with the ChatGPT DOM, injects the Enhance button, and handles events.
- Prompt API integration – calls the built‑in Gemini Nano model locally.
Manifest V3 Basics
{
"manifest_version": 3,
"name": "Prompt Enhancer",
"version": "1.0",
"description": "Rewrite rough prompts into high‑quality prompts for ChatGPT using Gemini Nano.",
"permissions": ["activeTab", "scripting"],
"host_permissions": ["https://chat.openai.com/*"],
"content_scripts": [
{
"matches": ["https://chat.openai.com/*"],
"js": ["contentScript.js"]
}
]
}
- Minimal permissions keep the extension secure and simplify Chrome Web Store review.
- The content script detects the ChatGPT page, locates the main textarea, injects the floating Enhance button, and listens for click/keyboard events.
- Because ChatGPT’s UI is a frequently‑changing React app, the script uses stable selectors, fallback heuristics (e.g., “largest textarea”), and a
MutationObserverto re‑attach the button after re‑renders.
Gemini Nano Integration via Prompt API
// Example of creating a Gemini Nano model instance
if (chrome.ai && chrome.ai.languageModel) {
const model = await chrome.ai.languageModel.create({
temperature: 0.2,
topK: 40,
// other model options...
});
const metaPrompt = `
You are a prompt‑engineering assistant. Rewrite the user's text as a clear,
detailed prompt that specifies context, output format, and constraints,
without changing the core intent.
`;
const response = await model.prompt(`${metaPrompt}\nUser: ${roughText}`);
// `response` now contains the enhanced prompt
}
- Local execution means low, predictable latency and no network round‑trip.
- The extension works even with Wi‑Fi off, as long as Chrome provides Gemini Nano.
- Defensive error handling is required because Gemini Nano is still emerging; a graceful fallback message is shown if the model isn’t available.
What’s Shipped Today (v1)
- Floating “Enhance” button on the ChatGPT prompt textarea.
- On‑device prompt enhancement using Gemini Nano via Chrome’s Prompt API.
- Full local processing with no external APIs or API keys.
- Keyboard shortcut support for power users.
- Minimal, native‑looking UX that feels integrated with ChatGPT.
The extension is live on the Chrome Web Store and can be installed like any other extension.
Lessons Learned
- Permissions & privacy: Clearly explain what data is accessed and why.
- User flow matters more than the model: Keep the typing flow uninterrupted, provide quick visual feedback, and respect the original intent.
- Early adoption trade‑off: Some users need to enable flags or use Dev/Canary builds; robust fallback messaging is essential.
Prompt Enhancer demonstrates how a simple, well‑integrated UX around a local LLM can dramatically improve day‑to‑day AI usage.