GitMurf/chrome-extension-template

Chrome Extension template using TypeScript, Vite, React and Tailwind from scratch without any "framework".

โ˜… 0Forks 0TypeScriptGitHub โ†—Compare

README

Chrome Extension Template

Framework-Free: A "bleeding-edge" Chrome extension template built from the ground up using Vite 8 Beta (Rolldown) and the Oxc toolchain. Unlike many templates that rely on extension frameworks (like WXT, CRXJS, or Plasmo), this project is "hand rolled", giving you full control and maximum performance with the latest web standards and dev tooling.

A modern, production-ready "Hello World" demonstrating all 8 major extension features using a high-performance tech stack: Vite 8 (Beta w/ Rolldown), React 19, Tailwind 4, Zod 4, and Oxc dev tooling.

image

โœจ Features

This template implements every major Chrome Extension capability:

Feature Description
๐Ÿ”ฒ Action Popup Click the toolbar icon for a quick UI with greeting and click counter
๐Ÿ“ Side Panel Persistent panel that survives tab navigation with real-time state
โš™๏ธ Options Page Full settings page with theme selector, notifications toggle, custom greeting
๐Ÿง  Background Service Worker Event-driven brain handling messages, menus, and commands
๐Ÿ“ Content Scripts Injected into every page for DOM access and highlighting
๐Ÿ–ฑ๏ธ Context Menus Right-click menu items on text selections and the extension icon
โŒจ๏ธ Keyboard Shortcuts Alt+Shift+S to toggle side panel, Alt+Shift+D for Demo notifications
๐Ÿ”” Notifications System-level alerts triggered by shortcuts and context menus

๐Ÿ› ๏ธ Tech Stack

Category Tool Why
Build Vite 8 Beta + Rolldown Bleeding-edge bundler, ~10x faster builds
UI React 19 Latest stable with concurrent features
Styling Tailwind CSS 4 CSS-first config, no JS config file
Types tsgo TypeScript 7 Native Preview, 10x faster
Linting oxlint 50-100x faster than ESLint
Formatting oxfmt 30x faster than Prettier
Testing Vitest Native Vite integration
Validation Zod 4 Runtime type validation for storage

๐Ÿ“ธ Screenshots

Popup

image

Side Panel

image

Options Page

image

Dark Mode

image image

Content Script Highlight

image

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 22+
  • pnpm 9+ (configured with save-exact=true)
  • Chrome 116+

Installation

# Clone the repo
git clone https://github.com/GitMurf/chrome-extension-template.git
cd chrome-extension-template

# Install dependencies
pnpm install

# Build the extension
pnpm build

Load in Chrome

  1. Open chrome://extensions/
  2. Enable Developer mode (toggle in top-right)
  3. Click Load unpacked
  4. Select the dist/ folder
image

๐Ÿ“ Project Structure

chrome-extension-template/
โ”œโ”€โ”€ public/
โ”‚   โ”œโ”€โ”€ manifest.json       # Extension manifest (Manifest V3)
โ”‚   โ””โ”€โ”€ images/             # Extension icons (16, 48, 128px)
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ background/         # Service Worker (Feature 4)
โ”‚   โ”œโ”€โ”€ content/            # Content Script (Feature 5)
โ”‚   โ”œโ”€โ”€ popup/              # Action Popup UI (Feature 1)
โ”‚   โ”œโ”€โ”€ sidepanel/          # Side Panel UI (Feature 2)
โ”‚   โ”œโ”€โ”€ options/            # Options Page UI (Feature 3)
โ”‚   โ””โ”€โ”€ shared/             # Shared code
โ”‚       โ”œโ”€โ”€ storage/        # Zod schemas + typed helpers
โ”‚       โ”œโ”€โ”€ messaging/      # Type-safe message protocol
โ”‚       โ””โ”€โ”€ hooks/          # React hooks (useTheme)
โ”œโ”€โ”€ __tests__/              # Vitest tests with Chrome API mocks
โ”œโ”€โ”€ vite.config.ts          # Multi-entry build config
โ”œโ”€โ”€ vitest.config.ts        # Test configuration
โ”œโ”€โ”€ tsconfig.json           # Strict TypeScript
โ””โ”€โ”€ oxlint.json             # Linter rules
โ””โ”€โ”€ .oxfmtrc.json           # Formatting rules

โŒจ๏ธ Keyboard Shortcuts

Shortcut Action
Alt+Shift+E Open Popup
Alt+Shift+S Toggle Side Panel
Alt+Shift+D Show Demo Notification

Customize shortcuts at chrome://extensions/shortcuts


๐Ÿงช Development

# Watch mode (rebuilds on save)
pnpm dev

# Lint (oxlint)
pnpm lint

# Format (oxfmt)
pnpm fmt

# Type check (tsgo)
pnpm typecheck

# Run tests
pnpm test

# Build for testing in Chrome
pnpm build

After running pnpm dev, reload the extension in Chrome (Ctrl+R on the extensions page) to see changes.


๐ŸŽจ Customization

Change the Extension Name

Edit public/manifest.json:

{
  "name": "Your Extension Name",
  "description": "Your description here"
}

Add New Message Types

  1. Add to src/shared/messaging/types.ts:
export interface MessageMap {
  // ... existing messages
  YOUR_MESSAGE: { payload: { data: string }; response: { success: boolean } };
}
  1. Handle in src/background/index.ts:
case 'YOUR_MESSAGE':
  // Handle your message
  return { success: true };

Modify Storage Schema

Edit src/shared/storage/schemas.ts with Zod:

export const SettingsSchema = z.object({
  // ... existing fields
  yourNewField: z.string().default('value'),
});

๐Ÿ“ฆ Building for Production

pnpm build

The dist/ folder contains everything needed for Chrome Web Store submission:

  • manifest.json
  • background.js
  • content.js
  • src/popup/index.html
  • src/sidepanel/index.html
  • src/options/index.html
  • images/
  • assets/

๐Ÿงฉ Chrome APIs Used

API Permission Usage
chrome.storage.local storage Persistent settings
chrome.storage.session storage Session state (click count)
chrome.sidePanel sidePanel Side panel UI
chrome.contextMenus contextMenus Right-click menus
chrome.notifications notifications System alerts
chrome.commands โ€” Keyboard shortcuts
chrome.runtime โ€” Message passing
chrome.tabs activeTab Tab communication

๐Ÿ“„ License

MIT


๐Ÿ™ Acknowledgments

Contributors

GitMurf

Issues