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.
- Manifest V3 Configuration: Ready-to-use
manifest.jsonwith 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 onhttps://*/*and provides theXXMloader (XXM.loadJSandXXM.loadStyle) usingchrome.runtime.getURL()to append extension scripts and stylesheets directly into the page DOM. - Background Service Worker: Minimal
src/background.jsentry point wired tochrome.action.onClickedfor background event processing. - Web Accessible Resources & Assets: Exposes
src/*andcss/*to HTTPS sites, includes English locale scaffolding (_locales/en/messages.json), and bundles standard extension icon sizes (16pxto128px) inimgs/. - Zero Build Step: Written in plain JavaScript, HTML, and CSS—load unpacked directly in Chrome without npm or a bundler.
- 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
- Google Chrome or any Chromium-based browser supporting Manifest V3 (e.g., Microsoft Edge, Brave, Arc).
- Clone this repository:
git clone https://github.com/sinhsac/chrome-extension-basic.git
- Open
chrome://extensions/in your browser. - Enable Developer mode in the top-right corner.
- Click Load unpacked and select the cloned
chrome-extension-basicfolder.
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)
}- Styles: Add CSS rules to
css/main.css, or dynamically load additional files fromcss/withXXM.loadStyle("css/custom.css", callback, document.head). - Target URLs & Permissions: Update
content_scripts[].matches,web_accessible_resources[].matches, andpermissionsinmanifest.jsonto restrict the extension to your target domains. - Popup & DevTools: Customize
html/popup.htmlandhtml/devtools.html(and add the corresponding scripts/stylesheets you reference) or updatesrc/background.jsfor background tasks.
After editing any file, click the Reload button on the extension card in chrome://extensions/ to apply your changes.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.