Convert Figma logo to code with AI

jhen0409 logoreact-chrome-extension-boilerplate

Boilerplate for Chrome Extension React.js project

2,138
388
2,138
41

Top Related Projects

Scaffold out a Chrome extension

A Chrome Extensions boilerplate using React 18 and Webpack 5.

A basic foundation boilerplate for rich Chrome Extensions using Webpack to help you write modular and modern Javascript code, load CSS easily and automatic reload the browser on code changes.

🖥🔋Web Extension starter to build "Write Once Run on Any Browser" extension

Quick Overview

React Chrome Extension Boilerplate is a comprehensive starter kit for building Chrome extensions using React. It provides a modern development environment with hot reloading, enabling developers to create extensions efficiently with popular tools and best practices.

Pros

  • Includes a pre-configured webpack setup for seamless development
  • Supports hot reloading for both the background and inject pages
  • Integrates Redux for state management
  • Comes with ESLint and Prettier for code quality and formatting

Cons

  • May have a steeper learning curve for developers new to React or Chrome extensions
  • Some included dependencies might become outdated over time
  • Limited customization options for specific extension use cases
  • Requires additional setup for more complex extension features

Code Examples

  1. Example of a simple React component for the popup:
import React from 'react';

const Popup = () => {
  return (
    <div>
      <h1>Hello, Chrome Extension!</h1>
      <p>This is a React-powered popup.</p>
    </div>
  );
};

export default Popup;
  1. Example of using Redux in the background script:
import { createStore } from 'redux';
import rootReducer from './reducers';

const store = createStore(rootReducer);

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
  if (request.type === 'GET_STATE') {
    sendResponse(store.getState());
  }
});
  1. Example of injecting a content script:
import React from 'react';
import { render } from 'react-dom';
import Injected from './Injected';

const injectElement = document.createElement('div');
injectElement.id = 'my-extension-root';
document.body.appendChild(injectElement);

render(<Injected />, injectElement);

Getting Started

  1. Clone the repository:

    git clone https://github.com/jhen0409/react-chrome-extension-boilerplate.git
    
  2. Install dependencies:

    cd react-chrome-extension-boilerplate
    npm install
    
  3. Start the development server:

    npm run dev
    
  4. Load the extension in Chrome:

    • Open chrome://extensions/
    • Enable "Developer mode"
    • Click "Load unpacked"
    • Select the dev folder in the project directory
  5. Begin developing your extension by modifying the files in the app directory.

Competitor Comparisons

Scaffold out a Chrome extension

Pros of generator-chrome-extension

  • More flexible and customizable, allowing developers to choose their preferred tools and frameworks
  • Generates a well-structured project with separate directories for scripts, styles, and assets
  • Includes a comprehensive Grunt-based build system for task automation

Cons of generator-chrome-extension

  • Lacks built-in React support, requiring additional setup for React-based projects
  • May require more initial configuration and setup compared to a pre-configured React boilerplate
  • Does not include hot-reloading functionality out of the box

Code Comparison

generator-chrome-extension:

// Gruntfile.js
grunt.initConfig({
  // ... configuration options
});
grunt.registerTask('default', ['jshint', 'test', 'build']);

react-chrome-extension-boilerplate:

// webpack.config.js
module.exports = {
  entry: {
    popup: path.join(__dirname, 'src', 'popup'),
    background: path.join(__dirname, 'src', 'background'),
  },
  // ... configuration options
};

The generator-chrome-extension uses Grunt for task automation, while react-chrome-extension-boilerplate utilizes Webpack for bundling and build processes. The react-chrome-extension-boilerplate is specifically tailored for React-based extensions, providing a more streamlined setup for React developers. However, generator-chrome-extension offers greater flexibility for developers who prefer other frameworks or vanilla JavaScript.

A Chrome Extensions boilerplate using React 18 and Webpack 5.

Pros of chrome-extension-boilerplate-react

  • More recent updates and active maintenance
  • Includes TypeScript support out of the box
  • Better documentation and setup instructions

Cons of chrome-extension-boilerplate-react

  • Slightly more complex project structure
  • Fewer stars and forks on GitHub, potentially indicating a smaller community

Code Comparison

react-chrome-extension-boilerplate:

import React from 'react';
import ReactDOM from 'react-dom';
import Root from './containers/Root';
import './assets/styles/app.scss';

ReactDOM.render(
  <Root />,
  document.querySelector('#root')
);

chrome-extension-boilerplate-react:

import React from 'react';
import { createRoot } from 'react-dom/client';
import Popup from './Popup';
import './index.css';

const container = document.getElementById('app-container');
const root = createRoot(container!);
root.render(<Popup />);

The main differences in the code snippets are:

  1. chrome-extension-boilerplate-react uses TypeScript
  2. It employs the newer createRoot API from React 18
  3. The component naming and file structure differ slightly

Both boilerplates provide a solid foundation for building Chrome extensions with React, but chrome-extension-boilerplate-react offers more modern features and better TypeScript integration, while react-chrome-extension-boilerplate has a larger community following.

A basic foundation boilerplate for rich Chrome Extensions using Webpack to help you write modular and modern Javascript code, load CSS easily and automatic reload the browser on code changes.

Pros of chrome-extension-webpack-boilerplate

  • Simpler setup with fewer dependencies, making it easier to understand and maintain
  • More lightweight, focusing solely on Webpack without React-specific configurations
  • Provides a basic structure that can be easily customized for various extension types

Cons of chrome-extension-webpack-boilerplate

  • Lacks built-in React support, requiring additional setup for React-based extensions
  • Fewer features and tooling options compared to the more comprehensive react-chrome-extension-boilerplate
  • Less active maintenance and community support

Code Comparison

react-chrome-extension-boilerplate:

import React from 'react';
import ReactDOM from 'react-dom';
import Popup from './Popup';

ReactDOM.render(<Popup />, document.getElementById('root'));

chrome-extension-webpack-boilerplate:

import './popup.css';

console.log("Hello from popup!");

The react-chrome-extension-boilerplate example shows React integration, while the chrome-extension-webpack-boilerplate example demonstrates a simpler JavaScript approach without React.

Both boilerplates offer valuable starting points for Chrome extension development, with react-chrome-extension-boilerplate providing a more feature-rich environment for React-based extensions, and chrome-extension-webpack-boilerplate offering a simpler, more flexible foundation for various extension types.

🖥🔋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 TypeScript for improved type safety and developer experience
  • Includes ESLint and Prettier for code quality and formatting

Cons of web-extension-starter

  • Less focused on React specifically, which may require more setup for React projects
  • Fewer stars and contributors compared to react-chrome-extension-boilerplate
  • May have a steeper learning curve for developers new to TypeScript

Code Comparison

react-chrome-extension-boilerplate:

import React from 'react';
import ReactDOM from 'react-dom';
import Popup from './Popup';

ReactDOM.render(<Popup />, document.getElementById('root'));

web-extension-starter:

import React from 'react';
import ReactDOM from 'react-dom';
import Popup from './Popup';

ReactDOM.render(<Popup />, document.querySelector('#popup-root'));

The code structure is similar, but web-extension-starter uses TypeScript and a different query selector for the root element.

Both projects provide a solid foundation for building browser extensions, with react-chrome-extension-boilerplate being more React-focused and web-extension-starter offering broader browser support and TypeScript integration. The choice between them depends on specific project requirements and developer preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

React Chrome Extension Boilerplate

Build Status Build status: Windows NPM version Dependency Status devDependency Status

Boilerplate for Chrome Extension React.js project.

Features

Examples

The example is edited from Redux TodoMVC example.

Popup

Popup

The todos state will be saved to chrome.storage.local.

Window

Window

The context menu is created by chrome/extension/background/contextMenus.js.

Inject page

The inject script is being run by chrome/extension/background/inject.js. A simple example will be inject bottom of page(https://github.com/*) if you visit.

If you are receiving the error message Failed to load resource: net::ERR_INSECURE_RESPONSE, you need to allow invalid certificates for resources loaded from localhost. You can do this by visiting the following URL: chrome://flags/#allow-insecure-localhost and enabling Allow invalid certificates for resources loaded from localhost.

Installation

# clone it
$ git clone https://github.com/jhen0409/react-chrome-extension-boilerplate.git

# Install dependencies
$ npm install

Development

  • Run script
# build files to './dev'
# start webpack development server
$ npm run dev
  • If you're developing Inject page, please allow https://localhost:3000 connections. (Because injectpage injected GitHub (https) pages, so webpack server procotol must be https.)
  • Load unpacked extensions with ./dev folder.

React/Redux hot reload

This boilerplate uses Webpack and react-transform, and use Redux. You can hot reload by editing related files of Popup & Window & Inject page.

Using Redux DevTools Extension

You can use redux-devtools-extension on development mode.

Build

# build files to './build'
$ npm run build

Compress

# compress build folder to {manifest.name}.zip and crx
$ npm run build
$ npm run compress -- [options]

Options

If you want to build crx file (auto update), please provide options, and add update.xml file url in [manifest.json](https://developer.chrome.com/extensions/autoupdate#update_url manifest.json).

  • --app-id: your extension id (can be get it when you first release extension)
  • --key: your private key path (default: './key.pem')
    you can use npm run compress-keygen to generate private key ./key.pem
  • --codebase: your crx file url

See autoupdate guide for more information.

Test

# lint
$ npm run lint
# test/app
$ npm test
$ npm test -- --watch  # watch files
# test/e2e
$ npm run build
$ npm run test-e2e

LICENSE

MIT