Socket
Book a DemoInstallSign in
Socket

electronic-post-message

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electronic-post-message

A postMessage polyfill for electron webview

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
4
-20%
Maintainers
1
Weekly downloads
 
Created
Source

electronic-post-message

A postMessage polyfill for electron webview. Useful if you want to reuse existing postMessage libraries to talk with code inside an electron webview (e.g. secret-door).

Usage

Inside of webview

import installPostMessage from 'electronic-post-message'

installPostMessage()



// That's it!! Use postMessage as usual
window.parent.postMessage('ping')
window.addEventListener('message', function (msg) {
  if (msg.source === window.parent) {
    console.log(msg.data) // logs 'pong'
  }
})

In electron top level window

import installPostMessage from 'electronic-post-message'

var proxyIframe = installPostMessage({
  webview: document.getElementById('#some-webview')
})



// That's it!! Use postMessage as usual with proxyIframe.contentWindow as target
window.addEventListener('message', function (msg) {
  if (msg.source === proxyIframe.contentWindow) {
    console.log(msg.data) // logs 'ping'
    proxyIframe.contentWindow.postMessage('pong')
  }
})

FAQ

  • Why is proxyIframe needed? Because an electron webview is not a Window or MessagePort. Which means we can't create an instance of MessageEvent with source set to webview since the browser throws a The optional 'source' property is neither a Window nor MessagePort. exception.

Keywords

electron

FAQs

Package last updated on 24 Dec 2015

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