Skip to content

WebContentsIpcMessageEvent ​

WebContentsIpcMessageEvent represents a message the web page sent through the message channel.

The ipc-message event of WebContents is this class. The page sends it by calling ipcRenderer.send(), and it carries a channel name and arguments.

Inheritance: Event → WebContentsIpcMessageEvent

Constructor ​

WebContentsIpcMessageEvent()

Creates a WebContentsIpcMessageEvent. The runtime creates one itself when it fires the events below; app code can use it to build an event object and fire it with dispatchEvent() to try out a listener.

Instance properties ​

Also inherits the properties of Event; the most commonly used are type and target. The properties below are read-only; assigning to them throws TypeError.

PropertyDescription
channel read-onlyThe channel name
args read-onlyThe arguments after the channel name

These properties live on the prototype, not on the event object itself: Object.keys(event) and { ...event } don't include them, so read them one by one. See Events with fields.

Events that use this class ​

ObjectEvents
WebContentsipc-message

It can't be canceled: cancelable is false, and preventDefault() has no effect.

Examples ​

js
const contents = new WebView({ webPreferences: { preload: 'JS/web/preload.js' } }).webContents;
contents.addEventListener('ipc-message', (e) => {
  console.log(e instanceof WebContentsIpcMessageEvent, e.channel, e.args.length);
});

Effect: for each message from the page, prints true, the channel name, and the number of arguments.

Corresponding iOS API ​

There is no corresponding system API. The event name and field names follow the event of the same name on Electron's webContents.

See also ​