Top Related Projects
Chrome Extensions Samples
A lightweight polyfill library for Promise-based WebExtension APIs in Chrome
🖥🔋Web Extension starter to build "Write Once Run on Any Browser" extension
:octocat: Browser extension that simplifies the GitHub interface and adds useful features
Quick Overview
Generator-chrome-extension is a Yeoman generator that scaffolds out a Chrome extension project. It provides a solid starting point for developers to create Chrome extensions, including boilerplate code, project structure, and build tools.
Pros
- Quickly sets up a Chrome extension project structure
- Includes build tools and automation for development and production
- Supports both ES5 and ES6+ JavaScript
- Provides options for different extension types (browser action, page action, etc.)
Cons
- May include unnecessary files or dependencies for simpler extensions
- Requires familiarity with Yeoman and its ecosystem
- Some generated code might become outdated as Chrome extension APIs evolve
- Limited customization options during initial generation
Getting Started
-
Install Yeoman and the Chrome extension generator:
npm install -g yo generator-chrome-extension
-
Create a new directory for your project and navigate to it:
mkdir my-chrome-extension && cd my-chrome-extension
-
Run the generator:
yo chrome-extension
-
Answer the prompts to customize your extension.
-
Start development:
npm run dev
-
Build for production:
npm run build
-
Load the
dist
folder as an unpacked extension in Chrome to test your extension.
Competitor Comparisons
Chrome Extensions Samples
Pros of chrome-extensions-samples
- Comprehensive collection of official examples covering various Chrome extension APIs
- Regularly updated with the latest Chrome extension features and best practices
- Includes both simple and complex examples, catering to different skill levels
Cons of chrome-extensions-samples
- Lacks a structured project generator or boilerplate setup
- May require more manual setup and configuration for new projects
- Does not provide an opinionated project structure or build process
Code Comparison
chrome-extensions-samples (manifest.json):
{
"name": "Sample Extension",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
}
}
generator-chrome-extension (generated manifest.json):
{
"name": "__MSG_appName__",
"version": "0.0.1",
"manifest_version": 2,
"background": {
"scripts": ["scripts/background.js"]
}
}
Summary
chrome-extensions-samples offers a wide range of official examples and up-to-date practices, making it an excellent resource for learning and reference. However, it lacks the project generation and opinionated structure provided by generator-chrome-extension. The code comparison shows differences in manifest versions and background script implementation, reflecting the evolving Chrome extension standards.
A lightweight polyfill library for Promise-based WebExtension APIs in Chrome
Pros of webextension-polyfill
- Provides a unified API for cross-browser extension development
- Simplifies the process of making extensions compatible with multiple browsers
- Actively maintained with regular updates and bug fixes
Cons of webextension-polyfill
- Limited to API compatibility and doesn't provide a full development environment
- May introduce a small performance overhead due to the abstraction layer
- Requires additional setup and integration into existing projects
Code Comparison
webextension-polyfill:
browser.runtime.sendMessage({ greeting: "hello" }).then((response) => {
console.log("Received response: ", response);
});
generator-chrome-extension:
chrome.runtime.sendMessage({ greeting: "hello" }, (response) => {
console.log("Received response: ", response);
});
Key Differences
generator-chrome-extension is a Yeoman generator that scaffolds a complete Chrome extension project structure, while webextension-polyfill is a compatibility library that allows developers to use a single, Promise-based API for cross-browser extension development.
generator-chrome-extension focuses on Chrome-specific development, providing boilerplate code and project setup. In contrast, webextension-polyfill aims to make extension code more portable across different browsers by providing a unified API that closely follows the WebExtensions standard.
While generator-chrome-extension offers a quick start for Chrome extension development, webextension-polyfill provides more flexibility for developers who want to create cross-browser compatible extensions with a consistent API.
🖥🔋Web Extension starter to build "Write Once Run on Any Browser" extension
Pros of web-extension-starter
- Supports multiple browsers (Chrome, Firefox, Opera, Edge) out of the box
- Uses modern technologies like TypeScript, React, and Webpack
- Includes a pre-configured ESLint and Prettier setup for code quality
Cons of web-extension-starter
- May have a steeper learning curve for beginners due to its use of advanced technologies
- Less customization options during initial setup compared to generator-chrome-extension
- Smaller community and potentially less frequent updates
Code Comparison
web-extension-starter:
import React from 'react';
import ReactDOM from 'react-dom';
import Popup from './Popup';
ReactDOM.render(<Popup />, document.getElementById('popup-root'));
generator-chrome-extension:
document.addEventListener('DOMContentLoaded', function() {
var checkPageButton = document.getElementById('checkPage');
checkPageButton.addEventListener('click', function() {
chrome.tabs.getSelected(null, function(tab) {
alert("Hello from your Chrome extension!");
});
}, false);
}, false);
The code comparison shows that web-extension-starter uses React for its popup, while generator-chrome-extension uses vanilla JavaScript. This reflects the more modern approach of web-extension-starter, which may be beneficial for developers familiar with React but could be overwhelming for beginners.
:octocat: Browser extension that simplifies the GitHub interface and adds useful features
Pros of Refined GitHub
- Actively maintained with frequent updates and new features
- Extensive set of enhancements for GitHub's web interface
- Large user base and community support
Cons of Refined GitHub
- Limited to GitHub-specific functionality
- Requires more setup and configuration compared to a generator
Code Comparison
Refined GitHub (content script):
import features from '../features';
async function init() {
await features.initialize();
features.add(import('./features/useful-not-found-page'));
features.add(import('./features/trending-menu-item'));
// ... more feature imports
}
init();
Generator Chrome Extension (Yeoman generator):
const Generator = require('yeoman-generator');
module.exports = class extends Generator {
prompting() {
return this.prompt([
{
type: 'input',
name: 'name',
message: 'What is the name of your extension?'
}
]).then(answers => {
this.answers = answers;
});
}
// ... more generator methods
};
The code snippets highlight the different purposes of these projects. Refined GitHub focuses on enhancing GitHub's functionality through feature modules, while Generator Chrome Extension provides a scaffolding tool for creating new Chrome extensions.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Chrome Extension generator
Maintainer: Jimmy Moon
Chrome Extension generator that creates everything you need to get started with extension development. You can choose Browser UI(Browser,Page Action, Omnibox) type and select into permissions what you need.
Getting Started
# Please make sure that `yo`, `gulp` and `bower` was installed on your system using this command:
npm install --global yo gulp-cli bower
# Install the generator:
npm install -g generator-chrome-extension
# Make a new directory, and `cd` get into it:
mkdir my-new-chrome-extension && cd $_
# Generate a new project
yo chrome-extension
# Transform updated source written by ES2015 (default option)
gulp babel
# or Using watch to update source continuously
gulp watch
# Make a production version extension
gulp build
Test Chrome Extension
To test, go to: chrome://extensions, enable Developer mode and load app as an unpacked extension.
Need more information about Chrome Extension? Please visit Google Chrome Extension Development
Generators
Available generators:
App
Sets up a new Chrome Extension, generating all the boilerplate you need to get started.
yo chrome-extension
gulp tasks
Babel
The generator supports ES 2015 syntax through babel transforming. You may have a source files in script.babel
if your project has been generated without --no-babel
options. While developing, When those of source has been changed, gulp babel
should be run before test and run a extension on Chrome.
gulp babel
If you would like to have a continuous transforming by babel you can use watch
task
Watch
Watch task helps you reduce your efforts during development extensions. If the task detects your changes of source files, re-compile your sources automatically or Livereload(chromereload.js) reloads your extension. If you would like to know more about Live-reload and preview of Yeoman? Please see Getting started with Yeoman and generator-webapp for your understanding.
gulp watch
You need to load/reload extension after starting gulp watch
for Live-reload to work.
For content scripts you need to refresh pages where it is used.
Build and Package
It will build your app as a result you can have a distribution version of the app in dist
. Run this command to build your Chrome Extension app.
gulp build
You can also distribute your project with compressed file using the Chrome Developer Dashboard at Chrome Web Store. This command will compress your app built by gulp build
command.
gulp package
Options
-
--no-babel
If you wouldn't use Babel ES2015 transpiler.
-
--skip-install
Skips the automatic execution of
bower
andnpm
after scaffolding has finished. -
--test-framework=[framework]
Defaults to
mocha
. Can be switched for another supported testing framework likejasmine
. -
--sass
Add support for Sass.
-
--all-permissions
All of permissions of chrome extension will be shown.
ES2015 and babel
ES2015 is the default option
in the generator that means you can use es2015 now for developing the Chrome extensions. However, at this moment, you need to execute babel
task of gulp to compile to test and run your extension on Chrome, because ES2015 is not full functionality on Chrome as yet.
The sources written by es2015 is located at scripts.babel
and runnable sources will be at script
after compiling by gulp babel
. May you don't want to use babel and ES2015 use --no-babel
option when scaffolding a new project.
yo chrome-extension --no-babel
Sass
This generator supports sass
through --sass
options and generate scss
boilerplate files at styles.scss
that those of scss
files will be compiled to styles
via gulp style
task. To do this, libsass
is featured in the generator. Please see this for further information.
yo chrome-extension --sass
All of Permissions for Chrome Extension
Need to add more permissions for chrome extension? You can get all list of permissions using --all-permissions
option when scaffolding a new project.
yo chrome-extension --all-permissions
Contribute
See the contributing docs
License
Top Related Projects
Chrome Extensions Samples
A lightweight polyfill library for Promise-based WebExtension APIs in Chrome
🖥🔋Web Extension starter to build "Write Once Run on Any Browser" extension
:octocat: Browser extension that simplifies the GitHub interface and adds useful features
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot