Socket
Socket
Sign inDemoInstall

electron-preload-link

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-preload-link

Communicate between electron preload scripts and context-isolated processes.


Version published
Weekly downloads
3
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

A simple utility to send and listen for messages via the window.postMessage API. Useful for communication between electron preload scripts and sandboxed + context isolated child processes.

Example:

Child Process

const preloadLink = require('electron-preload-link')

preloadLink.on('shutdown-imminent', (timeRemaining) => {
  window.alert(
    `You have ${timeRemaining}ms before this process is shut down.`
  )
})

function handleSuccess(clipboardContents) {
  window.alert(`The contents of your clipboard are: ${clipboardContents}`)
  preloadLink.off('clipboard-request-fail', handleFail)
}

function handleFail(err) {
  console.error(err)
  window.alert('Failed to get clipboard contents!')
  preloadLink.off('clipboard-request-success', handleSuccess)
}

preloadLink.once('clipboard-request-success', handleSuccess)
preloadLink.once('clipboard-request-fail', handleFail)
preloadLink.emit('clipboard-request')

Preload Script

const preloadLink = require('electron-preload-link')
const { clipboard } = require('electron')

preloadLink.emit('shutdown-imminent', 60 * 1000)

preloadLink.on('clipboard-request', () => {
  try {
    const clipboardContent = clipboard.readText()
    preloadLink.emit('clipboard-request-success', clipboardContent)
  } catch (err) {
    preloadLink.emit('clipboard-request-fail', err)
  }
})

FAQs

Package last updated on 18 Sep 2019

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