react-devtools-core
Use react-devtools outside of the browser
Last updated 6 months ago by hoxyq .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install react-devtools-core 
SYNC missed versions from official npm registry.

react-devtools-core

This package provides low-level APIs to support renderers like React Native. If you're looking for the standalone React DevTools UI, we suggest using react-devtools instead of using this package directly.

This package provides two entrypoints: labeled "backend" and "standalone" (frontend). Both APIs are described below.

Backend API

Backend APIs are embedded in development builds of renderers like React Native in order to connect to the React DevTools UI.

Example

If you are building a non-browser-based React renderer, you can use the backend API like so:

if (process.env.NODE_ENV !== 'production') {
  const { connectToDevTools } = require("react-devtools-core");

  // Must be called before packages like react or react-native are imported
  connectToDevTools({
    ...config
  });
}

NOTE that this API (connectToDevTools) must be (1) run in the same context as React and (2) must be called before React packages are imported (e.g. react, react-dom, react-native).

connectToDevTools options

Prop Default Description
host "localhost" Socket connection to frontend should use this host.
isAppActive (Optional) function that returns true/false, telling DevTools when it's ready to connect to React.
port 8097 Socket connection to frontend should use this port.
resolveRNStyle (Optional) function that accepts a key (number) and returns a style (object); used by React Native.
retryConnectionDelay 200 Delay (ms) to wait between retrying a failed Websocket connection
useHttps false Socket connection to frontend should use secure protocol (wss).
websocket Custom WebSocket connection to frontend; overrides host and port settings.

connectWithCustomMessagingProtocol options

Prop Description
onSubscribe Function, which receives listener (function, with a single argument) as an argument. Called when backend subscribes to messages from the other end (frontend).
onUnsubscribe Function, which receives listener (function) as an argument. Called when backend unsubscribes to messages from the other end (frontend).
onMessage Function, which receives 2 arguments: event (string) and payload (any). Called when backend emits a message, which should be sent to the frontend.

Unlike connectToDevTools, connectWithCustomMessagingProtocol returns a callback, which can be used for unsubscribing the backend from the global DevTools hook.

Frontend API

Frontend APIs can be used to render the DevTools UI into a DOM node. One example of this is react-devtools which wraps DevTools in an Electron app.

Example

import DevtoolsUI from "react-devtools-core/standalone";

// See the full list of API methods in documentation below.
const { setContentDOMNode, startServer } = DevtoolsUI;

// Render DevTools UI into a DOM element.
setContentDOMNode(document.getElementById("container"));

// Start socket server used to communicate between backend and frontend.
startServer(
  // Port defaults to 8097
  1234,

  // Host defaults to "localhost"
  "example.devserver.com",

  // Optional config for secure socket (WSS).
  {
    key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
    cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
  }
);

Exported methods

The default export is an object defining the methods described below.

These methods support chaining for convenience. For example:

const DevtoolsUI = require("react-devtools-core/standalone");
DevtoolsUI.setContentDOMNode(element).startServer();

connectToSocket(socket: WebSocket)

This is an advanced config function that is typically not used.

Custom WebSocket connection to use for communication between DevTools frontend and backend. Calling this method automatically initializes the DevTools UI (similar to calling startServer()).

openProfiler()

Automatically select the "Profiler" tab in the DevTools UI.

setContentDOMNode(element: HTMLElement)

Set the DOM element DevTools UI should be rendered into on initialization.

setDisconnectedCallback(callback: Function)

Optional callback to be notified when DevTools WebSocket closes (or errors).

setProjectRoots(roots: Array<string>)

Optional set of root directories for source files. These roots can be used to open an inspected component's source code using an IDE.

setStatusListener(callback: Function)

Optional callback to be notified of socket server events (e.g. initialized, errored, connected).

This callback receives two parameters:

function onStatus(
  message: string,
  status: 'server-connected' | 'devtools-connected' | 'error'
): void {
  // ...
}

startServer(port?: number, host?: string, httpsOptions?: Object, loggerOptions?: Object)

Start a socket server (used to communicate between backend and frontend) and renders the DevTools UI.

This method accepts the following parameters:

Name Default Description
port 8097 Socket connection to backend should use this port.
host "localhost" Socket connection to backend should use this host.
httpsOptions Optional object defining key and cert strings.
loggerOptions Optional object defining a surface string (to be included with DevTools logging events).

Development

Watch for changes made to the backend entry point and rebuild:

yarn start:backend

Watch for changes made to the standalone UI entry point and rebuild:

yarn start:standalone

Run the standalone UI using yarn start in the react-devtools.

Current Tags

  • 3.5.0-alpha.0                                ...           alpha (6 years ago)
  • 5.3.1                                ...           latest (4 months ago)
  • 4.0.6                                ...           next (5 years ago)
  • 4.10.4                                ...           old (3 years ago)

148 Versions

  • 5.3.1                                ...           4 months ago
  • 5.3.0                                ...           5 months ago
  • 5.2.0                                ...           6 months ago
  • 5.1.0                                ...           7 months ago
  • 5.0.2                                ...           8 months ago
  • 5.0.0                                ...           a year ago
  • 4.28.5                                ...           a year ago
  • 4.28.4                                ...           a year ago
  • 4.28.0                                ...           a year ago
  • 4.27.8                                ...           a year ago
  • 4.27.7                                ...           2 years ago
  • 4.27.6                                ...           2 years ago
  • 4.27.5                                ...           2 years ago
  • 4.27.4                                ...           2 years ago
  • 4.27.3                                ...           2 years ago
  • 4.27.2                                ...           2 years ago
  • 4.27.1                                ...           2 years ago
  • 4.27.0                                ...           2 years ago
  • 4.26.1                                ...           2 years ago
  • 4.26.0                                ...           2 years ago
  • 4.25.0                                ...           2 years ago
  • 4.24.7                                ...           2 years ago
  • 4.24.6                                ...           3 years ago
  • 4.24.5                                ...           3 years ago
  • 4.24.4                                ...           3 years ago
  • 4.24.3                                ...           3 years ago
  • 4.24.2                                ...           3 years ago
  • 4.24.1                                ...           3 years ago
  • 4.24.0                                ...           3 years ago
  • 4.23.0                                ...           3 years ago
  • 4.22.1                                ...           3 years ago
  • 4.22.0                                ...           3 years ago
  • 4.21.0                                ...           3 years ago
  • 4.20.2                                ...           3 years ago
  • 4.20.1                                ...           3 years ago
  • 4.20.0                                ...           3 years ago
  • 4.19.2                                ...           3 years ago
  • 4.19.1                                ...           3 years ago
  • 4.19.0                                ...           3 years ago
  • 4.18.0                                ...           3 years ago
  • 4.17.0                                ...           3 years ago
  • 4.16.0                                ...           3 years ago
  • 4.15.0                                ...           3 years ago
  • 4.14.0                                ...           3 years ago
  • 4.13.5                                ...           3 years ago
  • 4.13.4                                ...           3 years ago
  • 4.10.4                                ...           3 years ago
  • 4.13.3                                ...           3 years ago
  • 4.13.2                                ...           4 years ago
  • 4.13.1                                ...           4 years ago
  • 4.13.0                                ...           4 years ago
  • 4.10.3                                ...           4 years ago
  • 4.10.2                                ...           4 years ago
  • 4.12.4                                ...           4 years ago
  • 4.12.3                                ...           4 years ago
  • 4.12.2                                ...           4 years ago
  • 4.12.1                                ...           4 years ago
  • 4.12.0                                ...           4 years ago
  • 4.11.0                                ...           4 years ago
  • 4.10.1                                ...           4 years ago
  • 4.10.0                                ...           4 years ago
  • 4.9.0                                ...           4 years ago
  • 4.8.2                                ...           4 years ago
  • 4.8.1                                ...           4 years ago
  • 4.8.0                                ...           4 years ago
  • 4.7.0                                ...           4 years ago
  • 4.6.0                                ...           5 years ago
  • 4.5.0                                ...           5 years ago
  • 4.4.0                                ...           5 years ago
  • 4.3.0                                ...           5 years ago
  • 4.2.1                                ...           5 years ago
  • 4.2.0                                ...           5 years ago
  • 4.1.3                                ...           5 years ago
  • 4.1.2                                ...           5 years ago
  • 4.1.1                                ...           5 years ago
  • 4.1.0                                ...           5 years ago
  • 4.0.6                                ...           5 years ago
  • 4.0.5                                ...           5 years ago
  • 4.0.4                                ...           5 years ago
  • 4.0.3                                ...           5 years ago
  • 4.0.0                                ...           5 years ago
  • 4.0.0-alpha.10                                ...           5 years ago
  • 4.0.0-alpha.9                                ...           5 years ago
  • 4.0.0-alpha.8                                ...           5 years ago
  • 4.0.0-alpha.7                                ...           5 years ago
  • 4.0.0-alpha.6                                ...           5 years ago
  • 4.0.0-alpha.5                                ...           5 years ago
  • 3.6.3                                ...           5 years ago
  • 4.0.0-alpha.4                                ...           5 years ago
  • 4.0.0-alpha.3                                ...           5 years ago
  • 4.0.0-alpha.2                                ...           5 years ago
  • 4.0.0-alpha.1                                ...           5 years ago
  • 3.6.2                                ...           5 years ago
  • 4.0.0-alpha.0                                ...           5 years ago
  • 3.6.1                                ...           6 years ago
  • 3.6.0                                ...           6 years ago
  • 3.5.3                                ...           6 years ago
  • 3.5.2                                ...           6 years ago
  • 3.5.1                                ...           6 years ago
  • 3.5.0                                ...           6 years ago
  • 3.5.0-alpha.0                                ...           6 years ago
  • 3.4.3                                ...           6 years ago
  • 3.4.2                                ...           6 years ago
  • 3.4.1                                ...           6 years ago
  • 3.4.0                                ...           6 years ago
  • 3.3.4                                ...           6 years ago
  • 3.3.3                                ...           6 years ago
  • 3.3.2                                ...           6 years ago
  • 3.2.4-alpha.0                                ...           6 years ago
  • 3.2.3                                ...           6 years ago
  • 3.2.2                                ...           6 years ago
  • 3.2.1                                ...           7 years ago
  • 3.2.0                                ...           7 years ago
  • 3.1.0                                ...           7 years ago
  • 3.0.0                                ...           7 years ago
  • 2.5.2                                ...           7 years ago
  • 2.5.1                                ...           7 years ago
  • 2.5.0                                ...           7 years ago
  • 2.4.0                                ...           7 years ago
  • 2.3.3                                ...           7 years ago
  • 2.3.2                                ...           7 years ago
  • 2.3.1                                ...           7 years ago
  • 2.3.0                                ...           7 years ago
  • 2.2.1                                ...           7 years ago
  • 2.2.0                                ...           7 years ago
  • 2.1.9                                ...           8 years ago
  • 2.1.8                                ...           8 years ago
  • 2.1.7                                ...           8 years ago
  • 2.1.5                                ...           8 years ago
  • 2.1.4                                ...           8 years ago
  • 2.1.3                                ...           8 years ago
  • 2.1.2                                ...           8 years ago
  • 2.1.1                                ...           8 years ago
  • 2.1.0                                ...           8 years ago
  • 2.0.12                                ...           8 years ago
  • 2.0.11                                ...           8 years ago
  • 2.0.10                                ...           8 years ago
  • 2.0.9                                ...           8 years ago
  • 2.0.8                                ...           8 years ago
  • 2.0.7                                ...           8 years ago
  • 2.0.6                                ...           8 years ago
  • 2.0.5                                ...           8 years ago
  • 2.0.4                                ...           8 years ago
  • 2.0.2                                ...           8 years ago
  • 2.0.1                                ...           8 years ago
  • 2.0.0                                ...           8 years ago
  • 1.0.6                                ...           8 years ago
  • 1.0.5                                ...           8 years ago
Downloads
Total 3
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (5)

© 2010 - cnpmjs.org x YWFE | Home | YWFE