![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
PenPal is a promise-based library for securely communicating with iframes via postMessage. The parent window can call methods exposed by iframes, pass arguments, and receive a return value. Similarly, iframes can call methods exposed by the parent window, pass arguments, and receive a return value. Easy peasy.
The total size of the library is about 3 KB minified.
npm install penpal --save
const { connectToChild } from 'penpal';
connectToChild({
// URL of page to load into iframe.
url: 'http://example.com/iframe.html',
// Container to which the iframe should be appended.
appendTo: document.getElementById('iframeContainer'),
// Methods parent is exposing to child
methods: {
add(num1, num2) {
return num1 + num2;
}
}
}).then(child => {
child.multiply(2, 6).then(total => console.log(total));
child.divide(12, 4).then(total => console.log(total));
});
const { connectToParent } from 'penpal';
connectToParent({
// Methods child is exposing to parent
methods: {
multiply(num1, num2) {
return num1 * num2;
},
divide(num1, num2) {
// Return a promise if the value being returned requires asynchronous processing.
return new Promise(resolve => {
setTimeout(() => {
resolve(num1 / num2);
}, 1000);
});
}
}
}).then(parent => {
parent.add(3, 1).then(total => console.log(total));
});
connectToChild(options:Object) => Promise
options.url
(required) The URL of the webpage that should be loaded into the iframe that PenPal will create.
options.appendTo
(optional) The element to which the created iframe should be appended. If not provided, the iframe will be appended to document.body
.
options.methods
(optional) An object containing methods which should be exposed for the child iframe to call. The keys of the object are the method names and the values are the functions. If a function requires asynchronous processing to determine its return value, make the function immediately return a promise and resolve the promise once the value has been determined.
The return value of connectToChild
is a Promise which will be resolved once communication has been established. The promise will be resolved with a child
object containing the methods which the child has exposed. The child
object will also contain two other special properties:
child.iframe
The child iframe element.
child.destroy
A method that, when called, will remove the iframe element from the DOM and clean up event listeners.
connectToParent(options:Object) => Promise
options.parentOrigin
(optional) The origin of the parent window which your iframe will be communicating with. If this is not provided, communication will not be restricted to any particular parent origin resulting in any webpage being able to load your webpage into an iframe and communicate with it.
options.methods
(optional) An object containing methods which should be exposed for the parent window to call. The keys of the object are the method names and the values are the functions. If a function requires asynchronous processing to determine its return value, make the function immediately return a promise and resolve the promise once the value has been determined.
The return value of connectToParent
is a Promise which will be resolved once communication has been established. The promise will be resolved with a parent
object containing the methods which the parent has exposed.
setPromise(value:Constructor)
Provides a promise implementation that PenPal will use. If a promise implementation is not provided through this function, PenPal will attempt to use window.Promise
.
setDebug(value:boolean)
Enables or disables debug logging. Debug logging is disabled by default.
This library is inspired by:
MIT
FAQs
A promise-based library for communicating with iframes via postMessage.
The npm package penpal receives a total of 0 weekly downloads. As such, penpal popularity was classified as not popular.
We found that penpal 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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.