
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
This is a observable+promise wrapper around the window.postMessage.
The main reason that we created this was to make the communication between the iframe and the parent easier.
One of the issues that annoys you when dealing with the native window.addEventListener('message',callback) is that the callback function will be fired for every unrelated message that is being
posted, which is definitely not what you want.
IFCom guaranties that those messages will be delivered.rxjs streams, so you can apply all the rxjs operators and goodies.IFCom to make it more restricted, if you don't have any typing available.npm install --save ifcom / yarn add ifcom
In order to communicate between two windows, for now we're assuming that one is always the parent and one is the child.
This is how the parent would look like :
Inside your html
<iframe #id="iframe" sre="http://www.your-child-app.com"></iframe>
Inside your JS
import {IFCom} from 'ifcom';
const iframeElement = document.querySelector('#iframe');
const ifcom - new IFCom(iframeElement);
Note : The first parameter of the IFCom class is either the
iframe element(for parent page) or theparent window( for child) The second argument is the origin, which in our case ishttp://www.your-child-app.com. When instantiating the IFCom inside the parent, IFCom will extract the origin from the iframe element, if you don't want this, you could provide it yourself :
const ifcom - new IFCom(iframeElement , 'http://www.your-child-app.com');
This is how the child (the iframe's JS) would look like:
Inside your JS
import {IFCom} from 'ifcom';
const ifcom - new IFCom();
Note : Inside the child, there's no need to provide any arguments. This is because IFCom knows that we're inside an iframe and uses the
parentby default, unless overriden Also the origin is being extraced from thedocument.referrer || document.location.href; You can override it otherwise , like bellow.
const ifcom - new IFCom(parent, 'http://www.your-parent-app-url.com');
Let's say the parent is sending this message :
ifcom.post({
userInfo:{name:'Milad'}
})
.then((delivered)=>{
// post will return a promise which is resolved when the parent/child has received the message:
})
.catch(()=>{
// if message is not delivered after a timeout, you'll get an error
})
IFCom uses rxjs Observables for streaming internally, the syntax is identical in both parent or child:
So the child can subscribe to the message :
ifcom.on(['userInfo']).subscribe(({userInfo})=>{
console.log('name',userInfo.name)
})
NOTE
onmethod accepts an array which is anobject path( like['person','body','height']) to the message ( like lodash'sgetmethod), for example :
So if the parent is sending bellow object, :
ifcom.post({
context:{
user:{
name:'Milad'
}
}
});
Child can subscribe to the user part only like this :
ifcom.on(['context','user']).subscribe(({user})=>{
console.log('name',user.name);
})
Also, on can be used without providing any path, in this case, you'll receive all the messages
ifcom.on().subscribe((message)=>{
console.log('Various messages sent by parent',message);
})
We assume that there will be some messages that are frequently repeated and it would be nice to have a method for them.
For these kinda messages, there's a folder called mixins which has multiple mixins that can be applied on top of the IFCom.
To activate each of those, just import them, like below :
Let's say the child is going to pass the click events up to it's parent :
// first import the dom-event.mixins :
import 'ifcom/dist/mixins/dom-event.mixins';
// now, The IFCom class has all the methods that are available inside the dom-event mixin.
childIcom.click($clickEvent, 'some extra parameters', 'and more parameters')
And inside the parent, we should have :
import 'ifcom/dist/mixins/dom-event.mixins';
igIncom.onClick().subscribe(({event,args}) => {
console.log('click event', event);
console.log('click args', ...args);
})
// Or, we can even subscribe to all the domEvents
ifcom.onDomEvent($event).subscribe(({DOMEvent}})=>{
// event will look like:
DOMEvent === { name: 'click', event, args: ... }
})
FAQs
An Observable based wrapper around iframe postMessage
We found that ifcom demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.