Log all user-defined IPC traffic in an electron app.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
.npmrc
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
LICENSE.md
README.md
index.js
package.json

README.md

electron-ipc-log

Log all user-defined IPC traffic in an electron app.

npm travis standard downloads

Install

npm install electron-ipc-log

Usage

var electronIpcLog = require('electron-ipc-log')

electronIpcLog(event => {
  var { channel, data, sent, sync } = event
  var args = [sent ? '⬆️' : '⬇️', channel, ...data]
  if (sync) args.unshift('ipc:sync')
  else args.unshift('ipc')
  console.log(...args)
})

API

electronIpcLog(log: function)

Accepts a logging function with parameters (event: object), where event is an object { channel:string, data:object, sent:bool, sync:bool }.

  • channel - name of the channel the message was sent through.
  • data - any number of arguments passed by the user via IPC.
  • sent - true if sent via ipcRenderer.send or ipcRenderer.sendSync (ipcRenderer only)
  • sync - true if synchronous (ipcRenderer only)

Needs to be called once per process, so for example if you have one main process and two renderer windows, and you want to log IPC traffic in each process, you need to call electronIpcLog in each process.

All internal electron IPC messages (prefixed with ELECTRON or CHROME, e.g. ELECTRON_BROWSER_REQUIRE) are ignored, as they are very noisy and not useful for most use cases. I'm open to adding a config option for verbose logging if someone really needs it.

Note: this module monkey patches the emit, send, and sendSync methods of ipcRender (or just ipcMain.emit depending on the context). It's not ideal but I don't know of another way of hooking into electron IPC events at this time. This is the method devtron uses.

Contributing

Contributions welcome! Please read the contributing guidelines first.

License

ISC