redux-devtools/extension
Nathan Bierema 83b2c19a11
Upgrade to Manifest V3 (#1714)
* Update Chrome manifest.json

* Remove use of window in background

* Test devpanel

* Inject pageScript using new API

* Keep connection from devpanel to background alive

* Keep connection from content script to background alive

* Replace page action with action

* Cleanup syncOptions

* Update options to not rely on background page access

* Start work on updating popup

* Updates

* Remove window

* Get opening in a separate window working

* Remove pageScriptWrap

* Add socket to panelStore

* Fix tests

* Try to use MV3 for Firefox

* Fix path

* Fix Chrome E2E tests

* Revert unintentional change

* Skip Electron tests for now

Looks like they're still working through stuff in https://github.com/electron/electron/issues/41613

* Better image centering

The Firefox popup did not like the old CSS. This is still not perfect, but it's better than it was.

* Create shaggy-taxis-cross.md
2024-08-17 19:11:46 +00:00
..
chrome Upgrade to Manifest V3 (#1714) 2024-08-17 19:11:46 +00:00
docs Add content script notes 2024-06-14 17:51:14 -04:00
edge Update extension version number 2024-08-04 15:33:29 -04:00
examples chore(deps): update dependency prettier to v3 (#1434) 2023-07-12 18:03:20 +00:00
firefox Upgrade to Manifest V3 (#1714) 2024-08-17 19:11:46 +00:00
src Upgrade to Manifest V3 (#1714) 2024-08-17 19:11:46 +00:00
test Upgrade to Manifest V3 (#1714) 2024-08-17 19:11:46 +00:00
.eslintignore Refactor extension builds (#1265) 2022-11-07 00:26:12 +00:00
.eslintrc chore(extension): upgrade gulp (#662) 2020-10-31 07:51:20 -05:00
.gitignore Refactor extension builds (#1265) 2022-11-07 00:26:12 +00:00
babel.config.json Imprrove ability to tree-shake libraries (#1050) 2022-01-24 02:11:46 +00:00
build.mjs Upgrade to Manifest V3 (#1714) 2024-08-17 19:11:46 +00:00
CHANGELOG.md Version Packages (#1717) 2024-08-14 02:38:19 +00:00
CODE_OF_CONDUCT.md chore(extension): add extension (#658) 2020-10-26 08:18:23 -04:00
jest.config.js Convert d3 packages to ESM (#1648) 2024-04-07 03:44:14 +00:00
LICENSE chore(extension): add extension (#658) 2020-10-26 08:18:23 -04:00
package.json Remove unnecessary lodash usage from bundles (#1718) 2024-08-13 23:42:16 -04:00
README.md updated documentation link that was resolving to a 404 (#1635) 2024-03-15 01:50:19 +00:00
tsconfig.json Use types in tscnofig to explicitly define global types (#1045) 2022-01-22 21:51:27 +00:00

Redux DevTools Extension

Join the chat at https://gitter.im/zalmoxisus/redux-devtools-extension PRs Welcome OpenCollective OpenCollective

Demo

Installation

1. For Chrome

2. For Firefox

3. For Electron

4. For other browsers and non-browser environment

Usage

Note that starting from v2.7, window.devToolsExtension was renamed to window.__REDUX_DEVTOOLS_EXTENSION__ / window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__.

1. With Redux

1.1 Basic store

For a basic Redux store simply add:

 const store = createStore(
   reducer, /* preloadedState, */
+  window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
 );

Note that preloadedState argument is optional in Redux's createStore.

For universal ("isomorphic") apps, prefix it with typeof window !== 'undefined' &&.

const composeEnhancers =
  (typeof window !== 'undefined' &&
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
  compose;

For TypeScript use redux-devtools-extension npm package, which contains all the definitions, or just use (window as any) (see Recipes for an example).

const composeEnhancers = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

In case ESLint is configured to not allow using the underscore dangle, wrap it like so:

+ /* eslint-disable no-underscore-dangle */
  const store = createStore(
   reducer, /* preloadedState, */
   window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
  );
+ /* eslint-enable */

Note: Passing enhancer as last argument requires redux@>=3.1.0. For older versions apply it like here or here. Don't mix the old Redux API with the new one.

You don't need to npm install redux-devtools when using the extension (that's a different lib).

1.2 Advanced store setup

If you setup your store with middleware and enhancers, change:

  import { createStore, applyMiddleware, compose } from 'redux';

+ const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
+ const store = createStore(reducer, /* preloadedState, */ composeEnhancers(
- const store = createStore(reducer, /* preloadedState, */ compose(
    applyMiddleware(...middleware)
  ));

Note that when the extension is not installed, were using Redux compose here.

To specify extensions options, use it like so:

const composeEnhancers =
  typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
    ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
        // Specify extensions options like name, actionsDenylist, actionsCreators, serialize...
      })
    : compose;

const enhancer = composeEnhancers(
  applyMiddleware(...middleware),
  // other store enhancers if any
);
const store = createStore(reducer, enhancer);

See the post for more details.

1.3 Use @redux-devtools/extension package from npm

To make things easier, there's an npm package to install:

npm install --save @redux-devtools/extension

and to use like so:

import { createStore, applyMiddleware } from 'redux';
import { composeWithDevTools } from '@redux-devtools/extension';

const store = createStore(
  reducer,
  composeWithDevTools(
    applyMiddleware(...middleware),
    // other store enhancers if any
  ),
);

To specify extensions options:

import { createStore, applyMiddleware } from 'redux';
import { composeWithDevTools } from '@redux-devtools/extension';

const composeEnhancers = composeWithDevTools({
  // Specify name here, actionsDenylist, actionsCreators and other options if needed
});
const store = createStore(
  reducer,
  /* preloadedState, */ composeEnhancers(
    applyMiddleware(...middleware),
    // other store enhancers if any
  ),
);

There are just a few lines of code added to your bundle.

In case you don't include other enhancers and middlewares, just use devToolsEnhancer:

import { createStore } from 'redux';
import { devToolsEnhancer } from '@redux-devtools/extension';

const store = createStore(
  reducer,
  /* preloadedState, */ devToolsEnhancer(),
  // Specify name here, actionsDenylist, actionsCreators and other options if needed
);

1.4 Using in production

It's useful to include the extension in production as well. Usually you can use it for development.

If you want to restrict it there, use composeWithDevToolsLogOnlyInProduction or devToolsEnhancerLogOnlyInProduction:

import { createStore } from 'redux';
import { devToolsEnhancerLogOnlyInProduction } from '@redux-devtools/extension';

const store = createStore(
  reducer,
  /* preloadedState, */ devToolsEnhancerLogOnlyInProduction(),
  // options like actionSanitizer, stateSanitizer
);

or with middlewares and enhancers:

import { createStore, applyMiddleware } from 'redux';
import { composeWithDevToolsLogOnlyInProduction } from '@redux-devtools/extension';

const composeEnhancers = composeWithDevToolsLogOnlyInProduction({
  // options like actionSanitizer, stateSanitizer
});
const store = createStore(
  reducer,
  /* preloadedState, */ composeEnhancers(
    applyMiddleware(...middleware),
    // other store enhancers if any
  ),
);

You'll have to add 'process.env.NODE_ENV': JSON.stringify('production') in your Webpack config for the production bundle (to envify). If you use create-react-app, it already does it for you.

If you're already checking process.env.NODE_ENV when creating the store, import composeWithDevToolsLogOnly or devToolsEnhancerLogOnly for production environment.

If you dont want to allow the extension in production, just use composeWithDevToolsDevelopmentOnly or devToolsEnhancerDevelopmentOnly.

See the article for more details.

1.5 For React Native, hybrid, desktop and server side Redux apps

For React Native we can use react-native-debugger, which already included the same API with Redux DevTools Extension.

For most platforms, include Remote Redux DevTools's store enhancer, and from the extension's context menu choose 'Open Remote DevTools' for remote monitoring.

2. Without Redux

See integrations and the blog post for more details on how to use the extension with any architecture.

Docs

Demo

Live demos to use the extension with:

Also see ./examples folder.

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]

License

MIT

Created By

If you like this, follow @mdiordiev on twitter.