New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

penpal

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

penpal - npm Package Compare versions

Comparing version 2.4.3 to 2.5.0

9

dist/penpal.js

@@ -382,3 +382,4 @@ // Derived from https://github.com/umdjs/umd/blob/master/templates/amdWebGlobal.js

* @param {Object} options
* @param {string} [options.parentOrigin] A parent origin used to restrict communication.
* @param {string|Array} [options.parentOrigin] A parent origin used to restrict communication.
* An array of parent origin strings is also supported.
* @param {Object} [options.methods] Methods that may be called by the parent window.

@@ -400,5 +401,9 @@ * @return {Parent}

if (parentOrigin !== undefined && !Array.isArray(parentOrigin)) {
parentOrigin = [parentOrigin];
}
var promise = new Penpal.Promise(function (resolve, reject) {
var handleMessageEvent = function handleMessageEvent(event) {
if ((!parentOrigin || event.origin === parentOrigin) && event.data.penpal === HANDSHAKE) {
if ((parentOrigin === undefined || parentOrigin.indexOf(event.origin) !== -1) && event.data.penpal === HANDSHAKE) {
log('Child: Received handshake from Parent');

@@ -405,0 +410,0 @@

@@ -1,1 +0,1 @@

!function(e,n){var t={};n(t),"function"==typeof define&&define.amd?define("Penpal",t.default):e.Penpal=t.default}(this,function(e){"use strict";function n(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n<e.length;n++)t[n]=e[n];return t}return Array.from(e)}Object.defineProperty(e,"__esModule",{value:!0});var t="parent",r="child",o="handshake",i="handshake-reply",a="call",d="reply",c="fulfilled",u="rejected",l="message",s="load",f={"http:":"80","https:":"443"},m={Promise:function(){try{return window?window.Promise:null}catch(e){return null}}(),debug:!1},v=function(){var e=0;return function(){return++e}}(),p=function(){for(var e=arguments.length,n=Array(e),t=0;t<e;t++)n[t]=arguments[t];if(m.debug){var r;(r=console).log.apply(r,["[Penpal]"].concat(n))}},h=function(e){var n=document.location,t=document.createElement("a");t.href=e;var r=void 0;if(t.origin)r=t.origin;else{var o=t.protocol||n.protocol,i=t.hostname||n.hostname,a=t.port||n.port;r=o+"//"+i+(a&&a!==f[o]?":"+a:"")}return r},g=function(e){var n=[];return e(function(){n.forEach(function(e){e()})}),{then:function(e){n.push(e)}}},y=function(e,n,t){var r=e.localName,o=e.local,i=e.remote,u=e.remoteOrigin,s=!1;p(r+": Creating call sender");var f=function(e){return function(){for(var n=arguments.length,t=Array(n),f=0;f<n;f++)t[f]=arguments[f];return p(r+": Sending "+e+"() call"),new m.Promise(function(n,f){if(s)return void f("Unable to send "+e+"() call due to destroyed connection");var m=v(),h=function t(a){a.source===i&&a.origin===u&&a.data.penpal===d&&a.data.id===m&&(p(r+": Received "+e+"() reply"),o.removeEventListener(l,t),(a.data.resolution===c?n:f)(a.data.returnValue))};o.addEventListener(l,h),i.postMessage({penpal:a,id:m,methodName:e,args:t},u)})}};return t.then(function(){s=!0}),n.reduce(function(e,n){return e[n]=f(n),e},{})},w=function(e,t,r){var o=e.localName,i=e.local,s=e.remote,f=e.remoteOrigin,v=!1;p(o+": Connecting call receiver");var h=function(e){e.source===s&&e.origin===f&&e.data.penpal===a&&!function(){var r=e.data,i=r.methodName,a=r.args,l=r.id;if(p(o+": Received "+i+"() call"),i in t){var h=function(e){return function(n){return v?void setTimeout(function(){throw new Error("Unable to send "+i+"() reply due to destroyed connection")}):(p(o+": Sending "+i+"() reply"),void s.postMessage({penpal:d,id:l,resolution:e,returnValue:n},f))}};new m.Promise(function(e,r){try{e(t[i].apply(t,n(a)))}catch(e){r(e.toString()),setTimeout(function(){throw e})}}).then(h(c),h(u))}}()};i.addEventListener(l,h),r.then(function(){v=!0,i.removeEventListener(l,h)})};m.connectToChild=function(e){var n=e.url,r=e.appendTo,a=e.methods,d=void 0===a?{}:a,c=void 0,u=new g(function(e){return c=e}),f=window,v=document.createElement("iframe");(r||document.body).appendChild(v),u.then(function(){v.parentNode&&v.parentNode.removeChild(v)});var P=v.contentWindow||v.contentDocument.parentWindow,E=h(n),L=new m.Promise(function(e,r){var a=function n(r){if(r.source===P&&r.origin===E&&r.data.penpal===i){p("Parent: Received handshake reply from Child"),f.removeEventListener(l,n);var o={localName:t,local:f,remote:P,remoteOrigin:r.origin};w(o,d,u),e(y(o,r.data.methodNames,u))}},c=function(){p("Parent: Sending handshake"),f.addEventListener(l,a),u.then(function(){f.removeEventListener(l,a)}),P.postMessage({penpal:o,methodNames:Object.keys(d)},E)};v.addEventListener(s,c),u.then(function(){v.removeEventListener(s,c),r("Parent: Connection destroyed")}),p("Parent: Loading iframe"),v.src=n});return{promise:L,iframe:v,destroy:c}},m.connectToParent=function(e){var n=e.parentOrigin,t=e.methods,a=void 0===t?{}:t,d=void 0,c=new g(function(e){return d=e}),u=window,s=u.parent,f=new m.Promise(function(e,t){var d=function t(d){if((!n||d.origin===n)&&d.data.penpal===o){p("Child: Received handshake from Parent"),u.removeEventListener(l,t),p("Child: Sending handshake reply to Parent"),d.source.postMessage({penpal:i,methodNames:Object.keys(a)},d.origin);var f={localName:r,local:u,remote:s,remoteOrigin:d.origin};w(f,a,c),e(y(f,d.data.methodNames,c))}};u.addEventListener(l,d),c.then(function(){u.removeEventListener(l,d),t("Child: Connection destroyed")})});return{promise:f,destroy:d}},e.default=m});
!function(e,n){var t={};n(t),"function"==typeof define&&define.amd?define("Penpal",t.default):e.Penpal=t.default}(this,function(e){"use strict";function n(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n<e.length;n++)t[n]=e[n];return t}return Array.from(e)}Object.defineProperty(e,"__esModule",{value:!0});var t="parent",r="child",o="handshake",i="handshake-reply",a="call",d="reply",c="fulfilled",u="rejected",l="message",s="load",f={"http:":"80","https:":"443"},v={Promise:function(){try{return window?window.Promise:null}catch(e){return null}}(),debug:!1},m=function(){var e=0;return function(){return++e}}(),p=function(){for(var e=arguments.length,n=Array(e),t=0;t<e;t++)n[t]=arguments[t];if(v.debug){var r;(r=console).log.apply(r,["[Penpal]"].concat(n))}},h=function(e){var n=document.location,t=document.createElement("a");t.href=e;var r=void 0;if(t.origin)r=t.origin;else{var o=t.protocol||n.protocol,i=t.hostname||n.hostname,a=t.port||n.port;r=o+"//"+i+(a&&a!==f[o]?":"+a:"")}return r},g=function(e){var n=[];return e(function(){n.forEach(function(e){e()})}),{then:function(e){n.push(e)}}},y=function(e,n,t){var r=e.localName,o=e.local,i=e.remote,u=e.remoteOrigin,s=!1;p(r+": Creating call sender");var f=function(e){return function(){for(var n=arguments.length,t=Array(n),f=0;f<n;f++)t[f]=arguments[f];return p(r+": Sending "+e+"() call"),new v.Promise(function(n,f){if(s)return void f("Unable to send "+e+"() call due to destroyed connection");var v=m(),h=function t(a){a.source===i&&a.origin===u&&a.data.penpal===d&&a.data.id===v&&(p(r+": Received "+e+"() reply"),o.removeEventListener(l,t),(a.data.resolution===c?n:f)(a.data.returnValue))};o.addEventListener(l,h),i.postMessage({penpal:a,id:v,methodName:e,args:t},u)})}};return t.then(function(){s=!0}),n.reduce(function(e,n){return e[n]=f(n),e},{})},w=function(e,t,r){var o=e.localName,i=e.local,s=e.remote,f=e.remoteOrigin,m=!1;p(o+": Connecting call receiver");var h=function(e){e.source===s&&e.origin===f&&e.data.penpal===a&&!function(){var r=e.data,i=r.methodName,a=r.args,l=r.id;if(p(o+": Received "+i+"() call"),i in t){var h=function(e){return function(n){return m?void setTimeout(function(){throw new Error("Unable to send "+i+"() reply due to destroyed connection")}):(p(o+": Sending "+i+"() reply"),void s.postMessage({penpal:d,id:l,resolution:e,returnValue:n},f))}};new v.Promise(function(e,r){try{e(t[i].apply(t,n(a)))}catch(e){r(e.toString()),setTimeout(function(){throw e})}}).then(h(c),h(u))}}()};i.addEventListener(l,h),r.then(function(){m=!0,i.removeEventListener(l,h)})};v.connectToChild=function(e){var n=e.url,r=e.appendTo,a=e.methods,d=void 0===a?{}:a,c=void 0,u=new g(function(e){return c=e}),f=window,m=document.createElement("iframe");(r||document.body).appendChild(m),u.then(function(){m.parentNode&&m.parentNode.removeChild(m)});var P=m.contentWindow||m.contentDocument.parentWindow,E=h(n),L=new v.Promise(function(e,r){var a=function n(r){if(r.source===P&&r.origin===E&&r.data.penpal===i){p("Parent: Received handshake reply from Child"),f.removeEventListener(l,n);var o={localName:t,local:f,remote:P,remoteOrigin:r.origin};w(o,d,u),e(y(o,r.data.methodNames,u))}},c=function(){p("Parent: Sending handshake"),f.addEventListener(l,a),u.then(function(){f.removeEventListener(l,a)}),P.postMessage({penpal:o,methodNames:Object.keys(d)},E)};m.addEventListener(s,c),u.then(function(){m.removeEventListener(s,c),r("Parent: Connection destroyed")}),p("Parent: Loading iframe"),m.src=n});return{promise:L,iframe:m,destroy:c}},v.connectToParent=function(e){var n=e.parentOrigin,t=e.methods,a=void 0===t?{}:t,d=void 0,c=new g(function(e){return d=e}),u=window,s=u.parent;void 0===n||Array.isArray(n)||(n=[n]);var f=new v.Promise(function(e,t){var d=function t(d){if((void 0===n||n.indexOf(d.origin)!==-1)&&d.data.penpal===o){p("Child: Received handshake from Parent"),u.removeEventListener(l,t),p("Child: Sending handshake reply to Parent"),d.source.postMessage({penpal:i,methodNames:Object.keys(a)},d.origin);var f={localName:r,local:u,remote:s,remoteOrigin:d.origin};w(f,a,c),e(y(f,d.data.methodNames,c))}};u.addEventListener(l,d),c.then(function(){u.removeEventListener(l,d),t("Child: Connection destroyed")})});return{promise:f,destroy:d}},e.default=v});

@@ -368,3 +368,4 @@ 'use strict';

* @param {Object} options
* @param {string} [options.parentOrigin] A parent origin used to restrict communication.
* @param {string|Array} [options.parentOrigin] A parent origin used to restrict communication.
* An array of parent origin strings is also supported.
* @param {Object} [options.methods] Methods that may be called by the parent window.

@@ -386,5 +387,9 @@ * @return {Parent}

if (parentOrigin !== undefined && !Array.isArray(parentOrigin)) {
parentOrigin = [parentOrigin];
}
var promise = new Penpal.Promise(function (resolve, reject) {
var handleMessageEvent = function handleMessageEvent(event) {
if ((!parentOrigin || event.origin === parentOrigin) && event.data.penpal === HANDSHAKE) {
if ((parentOrigin === undefined || parentOrigin.indexOf(event.origin) !== -1) && event.data.penpal === HANDSHAKE) {
log('Child: Received handshake from Parent');

@@ -391,0 +396,0 @@

{
"name": "penpal",
"version": "2.4.3",
"version": "2.5.0",
"description": "A promise-based library for communicating with iframes via postMessage.",

@@ -5,0 +5,0 @@ "author": "Aaron Hardy <aaron@aaronhardy.com>",

@@ -108,3 +108,3 @@ [![npm version](https://badge.fury.io/js/penpal.svg)](https://badge.fury.io/js/penpal)

`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.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. This is typically a string, however an array of strings is also supported if you expect to communicate with multiple parent origins.

@@ -111,0 +111,0 @@ `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.

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