electron/docs/api/ipc-main-service-worker.md
trop[bot] e90404be7d
docs: no class inheritance (#47433)
Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Erick Zhao <ezhao@slack-corp.com>
2025-06-10 13:12:24 +02:00

2.5 KiB

Class: IpcMainServiceWorker

Communicate asynchronously from the main process to service workers.

Process: Main

Note

This API is a subtle variation of IpcMain—targeted for communicating with service workers. For communicating with web frames, consult the IpcMain documentation.

Warning

Electron's built-in classes cannot be subclassed in user code. For more information, see the FAQ.

Instance Methods

ipcMainServiceWorker.on(channel, listener)

Listens to channel, when a new message arrives listener would be called with listener(event, args...).

ipcMainServiceWorker.once(channel, listener)

Adds a one time listener function for the event. This listener is invoked only the next time a message is sent to channel, after which it is removed.

ipcMainServiceWorker.removeListener(channel, listener)

  • channel string
  • listener Function
    • ...args any[]

Removes the specified listener from the listener array for the specified channel.

ipcMainServiceWorker.removeAllListeners([channel])

  • channel string (optional)

Removes listeners of the specified channel.

ipcMainServiceWorker.handle(channel, listener)

ipcMainServiceWorker.handleOnce(channel, listener)

Handles a single invokeable IPC message, then removes the listener. See ipcMainServiceWorker.handle(channel, listener).

ipcMainServiceWorker.removeHandler(channel)

  • channel string

Removes any handler for channel, if present.