Skip to content

About

Minimal Chrome Extension Manifest V3 starter template for injecting custom JavaScript and CSS into web pages with a service worker, popup, and DevTools setup.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic Chrome Extension

License Manifest V3 JavaScript

A lightweight, zero-dependency Chrome Extension Manifest V3 starter template for injecting custom JavaScript and CSS into HTTPS web pages, pre-configured with a background service worker, toolbar popup, DevTools page, and localization scaffolding.

Key Features

  • Manifest V3 Configuration: Ready-to-use manifest.json with a background service worker, action popup, DevTools page, Content Security Policy (default-src 'self'), and common permissions (tabs, storage, unlimitedStorage, webRequest, alarms).
  • Dynamic JS & CSS Injection: Content script (src/main.js) runs across all frames on https://*/* and provides the XXM loader (XXM.loadJS and XXM.loadStyle) using chrome.runtime.getURL() to append extension scripts and stylesheets directly into the page DOM.
  • Background Service Worker: Minimal src/background.js entry point wired to chrome.action.onClicked for background event processing.
  • Web Accessible Resources & Assets: Exposes src/* and css/* to HTTPS sites, includes English locale scaffolding (_locales/en/messages.json), and bundles standard extension icon sizes (16px to 128px) in imgs/.
  • Zero Build Step: Written in plain JavaScript, HTML, and CSS—load unpacked directly in Chrome without npm or a bundler.

Tech Stack & Project Structure

  • Runtime: Chrome Extensions API (Manifest V3)
  • Languages: Vanilla JavaScript, HTML5, CSS3
chrome-extension-basic/
├── _locales/
│   └── en/
│       └── messages.json      # Localization strings (default locale: en)
├── css/
│   └── main.css               # Custom stylesheet injected into matched pages
├── html/
│   ├── devtools.html          # Starter DevTools page
│   └── popup.html             # Starter toolbar action popup
├── imgs/                      # Extension icons (16, 19, 32, 38, 48, 128px + disabled variants)
├── src/
│   ├── background.js          # Manifest V3 background service worker
│   ├── lib.js                 # Shared helper/library script injected on DOMContentLoaded
│   └── main.js                # Content script with XXM.loadJS / XXM.loadStyle loader
├── manifest.json              # Chrome Extension Manifest V3 configuration
├── LICENSE                    # Apache License 2.0
└── README.md

Prerequisites & Getting Started

Prerequisites

  • Google Chrome or any Chromium-based browser supporting Manifest V3 (e.g., Microsoft Edge, Brave, Arc).

Load the Extension Locally

  1. Clone this repository:
    git clone https://github.com/sinhsac/chrome-extension-basic.git
  2. Open chrome://extensions/ in your browser.
  3. Enable Developer mode in the top-right corner.
  4. Click Load unpacked and select the cloned chrome-extension-basic folder.

Usage & Customization

Inject Additional JavaScript Files

On DOMContentLoaded, src/main.js loads css/main.css into document.head, loads src/lib.js into document.body, and then invokes XXM.loadMore().

To inject your own script into matched pages, create a file in src/ (for example, src/your-code.js) and register it inside XXM.loadMore in src/main.js:

XXM.loadMore = function () {
    console.log("load more js")
    XXM.loadJS("src/your-code.js", () => console.log("done"), document.body)
}

Add Styles, UI Pages, or Background Logic

  • Styles: Add CSS rules to css/main.css, or dynamically load additional files from css/ with XXM.loadStyle("css/custom.css", callback, document.head).
  • Target URLs & Permissions: Update content_scripts[].matches, web_accessible_resources[].matches, and permissions in manifest.json to restrict the extension to your target domains.
  • Popup & DevTools: Customize html/popup.html and html/devtools.html (and add the corresponding scripts/stylesheets you reference) or update src/background.js for background tasks.

After editing any file, click the Reload button on the extension card in chrome://extensions/ to apply your changes.

License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

About

Minimal Chrome Extension Manifest V3 starter template for injecting custom JavaScript and CSS into web pages with a service worker, popup, and DevTools setup.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages