Skip to content

DOTORI-JointHackathonForSWUniv/react-chrome-extension-boilerplate

 
 

Repository files navigation

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 background script will load content script, and content script will inject page script into context of currently opened page. A open TodoApp button will be injected top of page(https://github.com/*) if you visit.

  • Content script can only manipulate DOM of current page. (It is running on different context of currently opened page)

  • If you want to interact with a javascript code running in currently opened page, you will have to inject page script into it from content script.

  • 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

Running scripts

Two seprates command are provided for developing Chrome extension.

dev-r

# build asset & html files to './dev'
# start webpack development server for background, window, popup script.
$ npm run dev-r

If you are developing Chrome extension that uses backgroun script, window, and popup, then running dev-r will be enough.

dev-s

# build content & page script and watch for their changes.
$ npm run dev-s

If you are developing Chrome extension that uses content and page script, you have to run dev-r command first, then run dev-s command from different terminal window.

How to load chrome extension?

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 and background scripts.

  • Content script & page script (injected by content script) cannot use hot reload, because many web sites use strict Content Security Policy (CSP) which allows loading resources from only specified domains. When Chrome Extension's content script & page script run on these web sites, loading from webpack-dev-server (http://localhost:3000) is not possible.

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

About

Boilerplate for Chrome Extension React.js project

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 86.4%
  • CSS 12.1%
  • Pug 1.3%
  • SCSS 0.2%