Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
TypeScript cross-frame communication library.
Framecast is available on npm, you can install it with either npm or yarn:
npm install framecast
# or:
yarn install framecast
Broadcasts allow you to send one-way communications. The broadcast
event is emitted when a valid broadcast is received.
You can add many listeners to the broadcast
event.
The only argument contains an object with a deserialized message.
import Framecast from 'framecast';
const target = document.querySelector('iframe').contentWindow;
const framecast = new Framecast(target);
framecast.on('broadcast', (message: any) => {
console.log(message);
});
import Framecast from 'framecast';
const target = window.parent;
const framecast = new Framecast(target);
framecast.broadcast('Hello world');
Framecast allows you to call functions across frames. The function:*
event is emitted when the call is made. The returned value of the listener is passed back to the calling frame.
Note, unlike the broadcast
event, function:*
events can only have one listener.
Create a function by adding a listener for the function:*
event where *
is the name of the function. So in the example below the function name is getElementId
so we name the event function:getElementId
.
import Framecast from 'framecast';
const target = window.parent;
const framecast = new Framecast(target);
framecast.on('function:getElementId', (selector) => {
return document.querySelector(selector).getAttribute('id');
});
To call the function from another frame, we use call
. Note, that all functions return a promise, even if the handler on the other end is a synchronous function.
import Framecast from 'framecast';
const target = document.querySelector('iframe').contentWindow;
const framecast = new Framecast(target);
const bodyId = await framecast.call('getElementId', 'body');
You handle errors the exact same way as if the function was in the same frame. Wrap the function call in a try/catch.
try {
const bodyId = await framecast.call('getElementId', 'body');
} catch (error) {
console.log('Something went wrong', error);
}
By default Framecast will throw an error if the handler take more than 10 seconds to complete. You can customize this with the config.functionTimeoutMs
option.
constructor(target: Window, config: FramecastConfig);
// broadcasts
on(type: 'broadcast', listener: (message: any) => void);
off(type: 'broadcast', listener: (message: any) => void);
broadcast(message: any);
// functions
on(type: `function:${string}`, listener: (...args: any[]) => void);
off(type: `function:${string}`, listener: (...args: any[]) => void);
call(type: `function:${string}`, ...args: any[]) => Promise<any>;
type FramecastConfig = {
origin: string | null;
channel: string | null;
self: Window | null;
functionTimeoutMs: number;
};
Inspired by Tabcast
FAQs
TypeScript cross-frame communication library.
We found that framecast demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.