|
| 1 | +## Communicate with the extension directly |
| 2 | + |
| 3 | +Use the following methods of `window.devToolsExtension`: |
| 4 | + |
| 5 | +- [open](#windowdevtoolsextensionopenposition) |
| 6 | +- [notifyErrors](#windowdevtoolsextensionnotifyerrorsonerror) |
| 7 | +- [send](#windowdevtoolsextensionlistenonmessage-instanceid) |
| 8 | +- [connect](#windowdevtoolsextensionconnectconfig) |
| 9 | +- [disconnect](#windowdevtoolsextensiondisconnect) |
| 10 | + |
| 11 | +### window.devToolsExtension.open([position]) |
| 12 | + |
| 13 | +Open monitor window. |
| 14 | + |
| 15 | +##### Arguments |
| 16 | + |
| 17 | +- [`position`] *String* - window position: `left`, `right`, `bottom`. Also can be `panel` to [open it in a Chrome panel](../docs/FAQ.md#how-to-keep-devtools-window-focused-all-the-time-in-a-chrome-panel). Or `remote` to [open remote monitor](..//docs/FAQ.md#how-to-get-it-work-with-webworkers-react-native-hybrid-desktop-and-server-side-apps). By default is `left`. |
| 18 | + |
| 19 | +### window.devToolsExtension.notifyErrors([onError]) |
| 20 | + |
| 21 | +Show notifications for uncaught exceptions. |
| 22 | + |
| 23 | +##### Arguments |
| 24 | + |
| 25 | +- [`onError`] *Function* to call when there's an exceptions. |
| 26 | + |
| 27 | +### window.devToolsExtension.send(action, state, [shouldStringify, instanceId]) |
| 28 | + |
| 29 | +Send a new action and state manually to be shown on the monitor. |
| 30 | + |
| 31 | +##### Arguments |
| 32 | + |
| 33 | +- `action` *String* (action type) or *Object* with required `type` key. |
| 34 | +- `state` *any* - usually object to expand. |
| 35 | +- [`shouldStringify`] *Boolean* - indicates whether to serialize `action` and `state`. |
| 36 | +- [`instanceId`] *String* - instance id for which to attach the log. |
| 37 | + |
| 38 | +### window.devToolsExtension.listen(onMessage, instanceId) |
| 39 | + |
| 40 | +Send a new action and state manually to be shown on the monitor. |
| 41 | + |
| 42 | +##### Arguments |
| 43 | + |
| 44 | +- `onMessage` *Function* to call when there's an action form the monitor. |
| 45 | +- `instanceId` *String* - instance id for which to handle actions. |
| 46 | + |
| 47 | +### window.devToolsExtension.connect([config]) |
| 48 | + |
| 49 | +##### Arguments |
| 50 | + |
| 51 | +- [`config`] *Object* intended to be the same as for [Redux store enhancer](Arguments.md#windowdevtoolsextensionconfig). For now only `instanceId` should be specified. |
| 52 | + |
| 53 | +##### Returns |
| 54 | +*Object* containing the following methods: |
| 55 | + |
| 56 | +- `subscribe(listener)` - adds a change listener. It will be called any time an action is dispatched form the monitor. |
| 57 | +- `unsubscribe()` - unsubscribes the change listener. You can use [window.devToolsExtension.disconnect](#windowdevtoolsextensiondisconnect) to remove all listeners. |
| 58 | +- `send(action, state)` - sends a new action and state manually to be shown on the monitor. |
| 59 | + |
| 60 | +[See the example for an example on usage](https://github.com/zalmoxisus/redux-devtools-extension/blob/master/examples/react-counter-messaging/components/Counter.js). |
| 61 | + |
| 62 | +### window.devToolsExtension.disconnect() |
| 63 | + |
| 64 | +Remove extensions listener and disconnect extensions background script connection. |
0 commit comments