Socket
Socket
Sign inDemoInstall

electron-comlink

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-comlink

Electron compatibility layer for Comlink


Version published
Weekly downloads
91
decreased by-35%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

An adapter to allow Electron to use Comlink to communicate between the background and renderer processes.

Installation

npm install electron-comlink

Usage

Communicate from the background to the renderer

// In the renderer process
const Comlink = require("comlink");
const {ElectronMessageAdapter} = require("electron-comlink");
const endpoint = new ElectronMessageAdapter(window, electron.ipcRenderer);

const exposed = {
    doSomething() {
        return "Did something in the renderer";
    },
};

Comlink.expose(exposed, endpoint);
// In the background process
const Comlink = require("comlink");
const {ElectronMessageAdapter} = require("electron-comlink");

const win = new BrowserWindow({width: 800, height: 600});
const endpoint = new ElectronMessageAdapter(win, electron.ipcMain);

const link = Comlink.wrap(endpoint);
await link.doSomething(); // Returns "Did something in the renderer"

Communicate from the renderer to the background

// In the background process
const Comlink = require("comlink");
const {ElectronMessageAdapter} = require("electron-comlink");

const win = new BrowserWindow({width: 800, height: 600});
const endpoint = new ElectronMessageAdapter(win, electron.ipcMain);

const exposed = {
    doSomethingElse() {
        return "Did something in the background";
    },
};

Comlink.expose(exposed, endpoint);
// In the renderer process
const Comlink = require("comlink");
const {ElectronMessageAdapter} = require("electron-comlink");
const endpoint = new ElectronMessageAdapter(window, electron.ipcRenderer);

const link = Comlink.wrap(endpoint);
await link.doSomethingElse(); // Returns "Did something in the background"

Gotchas

  • The transferList argument to .postMessage() is not currently supported.
  • If you try to message the renderer before it has started up, then you could be awaiting forever

Keywords

FAQs

Package last updated on 27 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc