Blog / Build with AI /
Your first Chrome extension: a ten-line example
A Chrome extension sounds like something for professional developers. It is not. The smallest working one is two files and about ten lines.
We will build one that shows an estimated reading time in the corner of any web page. Small, useful and easy to test. By the end, you will know how to load an extension, change it and see the result.
What you are building
When you open an article, a small dark badge appears in the bottom-right corner saying something like “6 min read”. That is all.
It works through a content script: a bit of JavaScript Chrome injects into pages that match a pattern you choose. Think of it as a sticky note you stick on every page you visit.
You need Chrome (or another Chromium browser), a text editor and a folder.
Step 1: make a folder and the manifest
Create a folder called reading-time. Inside it, create a file named manifest.json:
{
"manifest_version": 3,
"name": "Reading Time Badge",
"version": "1.0",
"description": "Shows an estimated reading time on every page.",
"content_scripts": [
{
"matches": ["https://*/*"],
"js": ["content.js"]
}
]
}
The manifest is the extension’s ID card. It tells Chrome the name, the version and what to run where. manifest_version: 3 is the current format; Chrome no longer accepts new extensions using the old one.
Step 2: write the content script
In the same folder, create content.js:
const words = document.body.innerText.trim().split(/\s+/).length;
const minutes = Math.max(1, Math.round(words / 230));
const badge = document.createElement("div");
badge.textContent = `${minutes} min read`;
badge.style.cssText = "position:fixed;bottom:16px;right:16px;padding:8px 12px;background:#111;color:#fff;font:14px sans-serif;border-radius:6px;z-index:99999";
document.body.appendChild(badge);
That is the ten lines, give or take. In plain words:
- Count the words in the page text.
- Divide by 230, a typical adult reading speed, and round. Never show less than one minute.
- Create a small box element.
- Put the text in it.
- Style it so it sits in the corner above everything else.
- Add it to the page.
Step 3: load it into Chrome
- Type
chrome://extensionsin the address bar. - Switch on Developer mode (top right).
- Click Load unpacked.
- Choose your
reading-timefolder.
The extension appears in the list. Open any article and you should see the badge. If you do not, refresh the page, because content scripts run when a page loads.
Step 4: change something
This is where it starts to feel real.
Change 230 to 180 in content.js and save. Go back to chrome://extensions and click the little reload icon on your extension. Refresh the article. The time goes up.
That reload-then-refresh loop is how you will work on every extension: edit, reload the extension, refresh the page.
Try changing the colour from #111 to #0a7 or moving the badge to the left by swapping right:16px for left:16px. Small changes teach you what each piece does.
Where AI helps
You can write this with an assistant, and it will usually produce something close. The skill is in asking for it well and checking it.
A useful prompt:
I want a Chrome extension using Manifest V3. It should show an estimated reading time badge in the corner of every page. Give me the full manifest.json and content.js, keep the code short, and add a comment on each line explaining what it does.
Then check three things:
- Is it Manifest V3? Some AI answers still produce the old V2 format, from older tutorials. If you see
"manifest_version": 2orbackground.persistent, ask for V3. - Are the permissions minimal? This example needs none beyond the
matchespattern. If the assistant adds"permissions": ["tabs", "history"]for no reason, remove them. Extra permissions scare users and slow review. - Does it do what you asked, and only that? Copying code from AI safely has a short checklist.
What can go wrong
- Nothing appears. Check the file names match exactly and that
manifest.jsonis valid JSON. A missing comma is enough to break it. Chrome shows an error on the extensions page. - It shows on pages you do not want. Change
matchesto specific sites, such as"https://example.com/*". - The number is odd. Pages full of menus and footers inflate the count. A better version would read only the
<article>or<main>element. That is a good first improvement to ask for. - It breaks a page’s layout. Rare here, but any extension that injects elements can clash with a site. Before you share one with anybody, try it on a few different sites.
Ideas for the next version
- Count only the main article, not the whole page.
- Hide the badge on short pages.
- Let the user click the badge to hide it.
- Add a settings page for reading speed.
- Show the word count too.
Each is a small, testable step. If you like the bookmarklet idea, you may also enjoy building a browser bookmarklet with AI in ten minutes, which does a similar job with no installation. And if the extension grows, building a reading mode extension with AI is a natural next project.
A note for people who manage websites
Extensions are a good way to build small tools for your own workflow: highlight links without alt text, show the title tag length, or flag noindex pages while you browse a site. You do the job in the browser anyway, so a tool that lives there removes a step.
Keep one rule: an extension that reads pages can see what is on them. Build only what you need and do not collect or send page content anywhere without a very good reason.
Key takeaways
- A working Chrome extension needs a manifest and, for this kind, one script.
- Load it with Developer mode and Load unpacked, then reload after each edit.
- Ask AI for Manifest V3, short code and minimal permissions.
- Start tiny, change one thing at a time, and test on more than one site.
Related reading
- Building a reading mode extension with AI
- Building a page notes extension with AI
- Building a word highlighter extension with AI
What is the one thing you wish your browser did on every page you visit?