penpal 6.2.1 → 6.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -125,7 +125,7 @@ An object containing methods which should be exposed for the child iframe to cal
125
125
 
126
126
  `options.childOrigin: string` (optional)
127
127
 
128
- In the vast majority of cases, Penpal can automatically determine the child origin based on the `src` or `srcdoc` property that you have set on the iframe. This will automatically restrict communication to that origin.
128
+ In the vast majority of cases, Penpal can automatically determine the child origin based on the `src` or `srcdoc` property that you have set on the iframe. Communication will automatically be restricted to that origin.
129
129
 
130
130
  In some rare cases, particularly when using the `file://` protocol on various devices, browsers are inconsistent in how they report and handle origins. If you receive an error saying that the parent received a handshake from an unexpected origin, you may need to manually pass the child origin using this option.
131
131
 
@@ -249,6 +249,10 @@ The following TypeScript types are also exported as named constants for your use
249
249
  - `CallSender`
250
250
  - `PenpalError`
251
251
 
252
+ ## React
253
+
254
+ If you're using Penpal within a React app, please check out [react-penpal](https://github.com/Lunuy/react-penpal).
255
+
252
256
  ## Supported Browsers
253
257
 
254
258
  Penpal is designed to run successfully on the most recent versions of Chrome, Firefox, Safari, and Edge. If you need to support Internet Explorer 11, feel free to use version 3.x of Penpal. See the [3.x README](https://github.com/Aaronius/penpal/tree/3.x) for documentation.
package/dist/penpal.js CHANGED
@@ -45,7 +45,7 @@ var Penpal = (function () {
45
45
  destroy(error) {
46
46
  if (!destroyed) {
47
47
  destroyed = true;
48
- log("".concat(localName, ": Destroying connection"));
48
+ log(`${localName}: Destroying connection`);
49
49
  callbacks.forEach(callback => {
50
50
  callback(error);
51
51
  });
@@ -112,8 +112,8 @@ var Penpal = (function () {
112
112
  // or it won't match the message's event.origin.
113
113
 
114
114
 
115
- const portSuffix = port && port !== DEFAULT_PORT_BY_PROTOCOL[protocol] ? ":".concat(port) : '';
116
- return "".concat(protocol, "//").concat(hostname).concat(portSuffix);
115
+ const portSuffix = port && port !== DEFAULT_PORT_BY_PROTOCOL[protocol] ? `:${port}` : '';
116
+ return `${protocol}//${hostname}${portSuffix}`;
117
117
  });
118
118
 
119
119
  /**
@@ -160,7 +160,7 @@ var Penpal = (function () {
160
160
  }
161
161
 
162
162
  if (originForReceiving !== '*' && event.origin !== originForReceiving) {
163
- log("".concat(localName, " received message from origin ").concat(event.origin, " which did not match expected origin ").concat(originForReceiving));
163
+ log(`${localName} received message from origin ${event.origin} which did not match expected origin ${originForReceiving}`);
164
164
  return;
165
165
  }
166
166
 
@@ -170,11 +170,11 @@ var Penpal = (function () {
170
170
  args,
171
171
  id
172
172
  } = callMessage;
173
- log("".concat(localName, ": Received ").concat(methodName, "() call"));
173
+ log(`${localName}: Received ${methodName}() call`);
174
174
 
175
175
  const createPromiseHandler = resolution => {
176
176
  return returnValue => {
177
- log("".concat(localName, ": Sending ").concat(methodName, "() reply"));
177
+ log(`${localName}: Sending ${methodName}() reply`);
178
178
 
179
179
  if (destroyed) {
180
180
  // It's possible to throw an error here, but it would need to be thrown asynchronously
@@ -182,7 +182,7 @@ var Penpal = (function () {
182
182
  // is merely returning a value from their method and not calling any function
183
183
  // that they could wrap in a try-catch. Even if the consumer were to catch the error,
184
184
  // the value of doing so is questionable. Instead, we'll just log a message.
185
- log("".concat(localName, ": Unable to send ").concat(methodName, "() reply due to destroyed connection"));
185
+ log(`${localName}: Unable to send ${methodName}() reply due to destroyed connection`);
186
186
  return;
187
187
  }
188
188
 
@@ -338,11 +338,11 @@ var Penpal = (function () {
338
338
  originForReceiving
339
339
  } = info;
340
340
  let destroyed = false;
341
- log("".concat(localName, ": Connecting call sender"));
341
+ log(`${localName}: Connecting call sender`);
342
342
 
343
343
  const createMethodProxy = methodName => {
344
344
  return (...args) => {
345
- log("".concat(localName, ": Sending ").concat(methodName, "() call")); // This handles the case where the iframe has been removed from the DOM
345
+ log(`${localName}: Sending ${methodName}() call`); // This handles the case where the iframe has been removed from the DOM
346
346
  // (and therefore its window closed), the consumer has not yet
347
347
  // called destroy(), and the user calls a method exposed by
348
348
  // the remote. We detect the iframe has been removed and force
@@ -367,7 +367,7 @@ var Penpal = (function () {
367
367
  }
368
368
 
369
369
  if (destroyed) {
370
- const error = new Error("Unable to send ".concat(methodName, "() call due ") + "to destroyed connection");
370
+ const error = new Error(`Unable to send ${methodName}() call due ` + `to destroyed connection`);
371
371
  error.code = ErrorCode.ConnectionDestroyed;
372
372
  throw error;
373
373
  }
@@ -381,12 +381,12 @@ var Penpal = (function () {
381
381
  }
382
382
 
383
383
  if (originForReceiving !== '*' && event.origin !== originForReceiving) {
384
- log("".concat(localName, " received message from origin ").concat(event.origin, " which did not match expected origin ").concat(originForReceiving));
384
+ log(`${localName} received message from origin ${event.origin} which did not match expected origin ${originForReceiving}`);
385
385
  return;
386
386
  }
387
387
 
388
388
  const replyMessage = event.data;
389
- log("".concat(localName, ": Received ").concat(methodName, "() reply"));
389
+ log(`${localName}: Received ${methodName}() reply`);
390
390
  local.removeEventListener(NativeEventType.Message, handleMessageEvent);
391
391
  let returnValue = replyMessage.returnValue;
392
392
 
@@ -440,7 +440,7 @@ var Penpal = (function () {
440
440
  const callSender = {};
441
441
  return event => {
442
442
  if (childOrigin !== '*' && event.origin !== childOrigin) {
443
- log("Parent: Handshake - Received ACK message from origin ".concat(event.origin, " which did not match expected origin ").concat(childOrigin));
443
+ log(`Parent: Handshake - Received ACK message from origin ${event.origin} which did not match expected origin ${childOrigin}`);
444
444
  return;
445
445
  }
446
446
 
@@ -481,8 +481,16 @@ var Penpal = (function () {
481
481
 
482
482
  var handleSynMessageFactory = ((log, serializedMethods, childOrigin, originForSending) => {
483
483
  return event => {
484
+ // Under specific timing circumstances, we can receive an event
485
+ // whose source is null. This seems to happen when the child iframe is
486
+ // removed from the DOM about the same time it has sent the SYN event.
487
+ // https://github.com/Aaronius/penpal/issues/85
488
+ if (!event.source) {
489
+ return;
490
+ }
491
+
484
492
  if (childOrigin !== '*' && event.origin !== childOrigin) {
485
- log("Parent: Handshake - Received SYN message from origin ".concat(event.origin, " which did not match expected origin ").concat(childOrigin));
493
+ log(`Parent: Handshake - Received SYN message from origin ${event.origin} which did not match expected origin ${childOrigin}`);
486
494
  return;
487
495
  }
488
496
 
@@ -532,7 +540,7 @@ var Penpal = (function () {
532
540
 
533
541
  if (timeout !== undefined) {
534
542
  timeoutId = window.setTimeout(() => {
535
- const error = new Error("Connection timed out after ".concat(timeout, "ms"));
543
+ const error = new Error(`Connection timed out after ${timeout}ms`);
536
544
  error.code = ErrorCode.ConnectionTimeout;
537
545
  callback(error);
538
546
  }, timeout);
@@ -642,7 +650,7 @@ var Penpal = (function () {
642
650
  let originQualifies = parentOrigin instanceof RegExp ? parentOrigin.test(event.origin) : parentOrigin === '*' || parentOrigin === event.origin;
643
651
 
644
652
  if (!originQualifies) {
645
- log("Child: Handshake - Received SYN-ACK from origin ".concat(event.origin, " which did not match expected origin ").concat(parentOrigin));
653
+ log(`Child: Handshake - Received SYN-ACK from origin ${event.origin} which did not match expected origin ${parentOrigin}`);
646
654
  return;
647
655
  }
648
656
 
@@ -1 +1 @@
1
- var Penpal=function(){"use strict";var e;(function(e){e["Call"]="call";e["Reply"]="reply";e["Syn"]="syn";e["SynAck"]="synAck";e["Ack"]="ack"})(e||(e={}));var n;(function(e){e["Fulfilled"]="fulfilled";e["Rejected"]="rejected"})(n||(n={}));var t;(function(e){e["ConnectionDestroyed"]="ConnectionDestroyed";e["ConnectionTimeout"]="ConnectionTimeout";e["NoIframeSrc"]="NoIframeSrc"})(t||(t={}));var o;(function(e){e["DataCloneError"]="DataCloneError"})(o||(o={}));var r;(function(e){e["Message"]="message"})(r||(r={}));var c=(e,n)=>{const t=[];let o=false;return{destroy(r){if(!o){o=true;n("".concat(e,": Destroying connection"));t.forEach(e=>{e(r)})}},onDestroy(e){o?e():t.push(e)}}};var s=e=>(...n)=>{if(e){console.log("[Penpal]",...n)}};const i={"http:":"80","https:":"443"};const a=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/;const d=["file:","data:"];var l=e=>{if(e&&d.find(n=>e.startsWith(n))){return"null"}const n=document.location;const t=a.exec(e);let o;let r;let c;if(t){o=t[1]?t[1]:n.protocol;r=t[2];c=t[4]}else{o=n.protocol;r=n.hostname;c=n.port}const s=c&&c!==i[o]?":".concat(c):"";return"".concat(o,"//").concat(r).concat(s)};const u=({name:e,message:n,stack:t})=>({name:e,message:n,stack:t});const f=e=>{const n=new Error;Object.keys(e).forEach(t=>n[t]=e[t]);return n};var g=(t,c,s)=>{const{localName:i,local:a,remote:d,originForSending:l,originForReceiving:f}=t;let g=false;const m=t=>{if(t.source!==d||t.data.penpal!==e.Call){return}if(f!=="*"&&t.origin!==f){s("".concat(i," received message from origin ").concat(t.origin," which did not match expected origin ").concat(f));return}const r=t.data;const{methodName:a,args:m,id:p}=r;s("".concat(i,": Received ").concat(a,"() call"));const h=t=>r=>{s("".concat(i,": Sending ").concat(a,"() reply"));if(g){s("".concat(i,": Unable to send ").concat(a,"() reply due to destroyed connection"));return}const c={penpal:e.Reply,id:p,resolution:t,returnValue:r};if(t===n.Rejected&&r instanceof Error){c.returnValue=u(r);c.returnValueIsError=true}try{d.postMessage(c,l)}catch(t){if(t.name===o.DataCloneError){const o={penpal:e.Reply,id:p,resolution:n.Rejected,returnValue:u(t),returnValueIsError:true};d.postMessage(o,l)}throw t}};new Promise(e=>e(c[a].apply(c,m))).then(h(n.Fulfilled),h(n.Rejected))};a.addEventListener(r.Message,m);return()=>{g=true;a.removeEventListener(r.Message,m)}};let m=0;var p=()=>++m;const h=".";const v=e=>e?e.split(h):[];const y=e=>e.join(h);const w=(e,n)=>{const t=v(n||"");t.push(e);return y(t)};const C=(e,n,t)=>{const o=v(n);o.reduce((e,n,r)=>{if(typeof e[n]==="undefined"){e[n]={}}if(r===o.length-1){e[n]=t}return e[n]},e);return e};const E=(e,n)=>{const t={};Object.keys(e).forEach(o=>{const r=e[o];const c=w(o,n);if(typeof r==="object"){Object.assign(t,E(r,c))}if(typeof r==="function"){t[c]=r}});return t};const k=e=>{const n={};for(const t in e){C(n,t,e[t])}return n};var R=(o,c,s,i,a)=>{const{localName:d,local:l,remote:u,originForSending:g,originForReceiving:m}=c;let h=false;a("".concat(d,": Connecting call sender"));const v=o=>(...c)=>{a("".concat(d,": Sending ").concat(o,"() call"));let s;try{if(u.closed){s=true}}catch(e){s=true}if(s){i()}if(h){const e=new Error("Unable to send ".concat(o,"() call due ")+"to destroyed connection");e.code=t.ConnectionDestroyed;throw e}return new Promise((t,s)=>{const i=p();const h=c=>{if(c.source!==u||c.data.penpal!==e.Reply||c.data.id!==i){return}if(m!=="*"&&c.origin!==m){a("".concat(d," received message from origin ").concat(c.origin," which did not match expected origin ").concat(m));return}const g=c.data;a("".concat(d,": Received ").concat(o,"() reply"));l.removeEventListener(r.Message,h);let p=g.returnValue;if(g.returnValueIsError){p=f(p)}(g.resolution===n.Fulfilled?t:s)(p)};l.addEventListener(r.Message,h);const v={penpal:e.Call,id:i,methodName:o,args:c};u.postMessage(v,g)})};const y=s.reduce((e,n)=>{e[n]=v(n);return e},{});Object.assign(o,k(y));return()=>{h=true}};var S=(e,n,t,o,r)=>{const{destroy:c,onDestroy:s}=o;let i;let a;const d={};return o=>{if(n!=="*"&&o.origin!==n){r("Parent: Handshake - Received ACK message from origin ".concat(o.origin," which did not match expected origin ").concat(n));return}r("Parent: Handshake - Received ACK");const l={localName:"Parent",local:window,remote:o.source,originForSending:t,originForReceiving:n};if(i){i()}i=g(l,e,r);s(i);if(a){a.forEach(e=>{delete d[e]})}a=o.data.methodNames;const u=R(d,l,a,c,r);s(u);return d}};var N=(n,t,o,r)=>c=>{if(o!=="*"&&c.origin!==o){n("Parent: Handshake - Received SYN message from origin ".concat(c.origin," which did not match expected origin ").concat(o));return}n("Parent: Handshake - Received SYN, responding with SYN-ACK");const s={penpal:e.SynAck,methodNames:Object.keys(t)};c.source.postMessage(s,r)};const M=6e4;var A=(e,n)=>{const{destroy:t,onDestroy:o}=n;const r=setInterval(()=>{if(!e.isConnected){clearInterval(r);t()}},M);o(()=>{clearInterval(r)})};var P=(e,n)=>{let o;if(e!==undefined){o=window.setTimeout(()=>{const o=new Error("Connection timed out after ".concat(e,"ms"));o.code=t.ConnectionTimeout;n(o)},e)}return()=>{clearTimeout(o)}};var j=e=>{if(!e.src&&!e.srcdoc){const e=new Error("Iframe must have src or srcdoc property defined.");e.code=t.NoIframeSrc;throw e}};var D=n=>{let{iframe:t,methods:o={},childOrigin:i,timeout:a,debug:d=false}=n;const u=s(d);const f=c("Parent",u);const{onDestroy:g,destroy:m}=f;if(!i){j(t);i=l(t.src)}const p=i==="null"?"*":i;const h=E(o);const v=N(u,h,i,p);const y=S(h,i,p,f,u);const w=new Promise((n,o)=>{const c=P(a,m);const s=o=>{if(o.source!==t.contentWindow||!o.data){return}if(o.data.penpal===e.Syn){v(o);return}if(o.data.penpal===e.Ack){const e=y(o);if(e){c();n(e)}return}};window.addEventListener(r.Message,s);u("Parent: Awaiting handshake");A(t,f);g(e=>{window.removeEventListener(r.Message,s);if(e){o(e)}})});return{promise:w,destroy(){m()}}};var b=(n,t,o,r)=>{const{destroy:c,onDestroy:s}=o;return o=>{let i=n instanceof RegExp?n.test(o.origin):n==="*"||n===o.origin;if(!i){r("Child: Handshake - Received SYN-ACK from origin ".concat(o.origin," which did not match expected origin ").concat(n));return}r("Child: Handshake - Received SYN-ACK, responding with ACK");const a=o.origin==="null"?"*":o.origin;const d={penpal:e.Ack,methodNames:Object.keys(t)};window.parent.postMessage(d,a);const l={localName:"Child",local:window,remote:window.parent,originForSending:a,originForReceiving:o.origin};const u=g(l,t,r);s(u);const f={};const m=R(f,l,o.data.methodNames,c,r);s(m);return f}};const F=()=>{try{clearTimeout()}catch(e){return false}return true};var I=(n={})=>{const{parentOrigin:t="*",methods:o={},timeout:i,debug:a=false}=n;const d=s(a);const l=c("Child",d);const{destroy:u,onDestroy:f}=l;const g=E(o);const m=b(t,g,l,d);const p=()=>{d("Child: Handshake - Sending SYN");const n={penpal:e.Syn};const o=t instanceof RegExp?"*":t;window.parent.postMessage(n,o)};const h=new Promise((n,t)=>{const o=P(i,u);const c=t=>{if(!F()){return}if(t.source!==parent||!t.data){return}if(t.data.penpal===e.SynAck){const e=m(t);if(e){window.removeEventListener(r.Message,c);o();n(e)}}};window.addEventListener(r.Message,c);p();f(e=>{window.removeEventListener(r.Message,c);if(e){t(e)}})});return{promise:h,destroy(){u()}}};var L={connectToChild:D,connectToParent:I,ErrorCode:t};return L}();
1
+ var Penpal=function(){"use strict";var e;(function(e){e["Call"]="call";e["Reply"]="reply";e["Syn"]="syn";e["SynAck"]="synAck";e["Ack"]="ack"})(e||(e={}));var n;(function(e){e["Fulfilled"]="fulfilled";e["Rejected"]="rejected"})(n||(n={}));var t;(function(e){e["ConnectionDestroyed"]="ConnectionDestroyed";e["ConnectionTimeout"]="ConnectionTimeout";e["NoIframeSrc"]="NoIframeSrc"})(t||(t={}));var o;(function(e){e["DataCloneError"]="DataCloneError"})(o||(o={}));var r;(function(e){e["Message"]="message"})(r||(r={}));var s=(e,n)=>{const t=[];let o=false;return{destroy(r){if(!o){o=true;n(`${e}: Destroying connection`);t.forEach(e=>{e(r)})}},onDestroy(e){o?e():t.push(e)}}};var i=e=>(...n)=>{if(e){console.log("[Penpal]",...n)}};const c={"http:":"80","https:":"443"};const a=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/;const d=["file:","data:"];var l=e=>{if(e&&d.find(n=>e.startsWith(n))){return"null"}const n=document.location;const t=a.exec(e);let o;let r;let s;if(t){o=t[1]?t[1]:n.protocol;r=t[2];s=t[4]}else{o=n.protocol;r=n.hostname;s=n.port}const i=s&&s!==c[o]?`:${s}`:"";return`${o}//${r}${i}`};const u=({name:e,message:n,stack:t})=>({name:e,message:n,stack:t});const f=e=>{const n=new Error;Object.keys(e).forEach(t=>n[t]=e[t]);return n};var g=(t,s,i)=>{const{localName:c,local:a,remote:d,originForSending:l,originForReceiving:f}=t;let g=false;const m=t=>{if(t.source!==d||t.data.penpal!==e.Call){return}if(f!=="*"&&t.origin!==f){i(`${c} received message from origin ${t.origin} which did not match expected origin ${f}`);return}const r=t.data;const{methodName:a,args:m,id:p}=r;i(`${c}: Received ${a}() call`);const h=t=>r=>{i(`${c}: Sending ${a}() reply`);if(g){i(`${c}: Unable to send ${a}() reply due to destroyed connection`);return}const s={penpal:e.Reply,id:p,resolution:t,returnValue:r};if(t===n.Rejected&&r instanceof Error){s.returnValue=u(r);s.returnValueIsError=true}try{d.postMessage(s,l)}catch(t){if(t.name===o.DataCloneError){const o={penpal:e.Reply,id:p,resolution:n.Rejected,returnValue:u(t),returnValueIsError:true};d.postMessage(o,l)}throw t}};new Promise(e=>e(s[a].apply(s,m))).then(h(n.Fulfilled),h(n.Rejected))};a.addEventListener(r.Message,m);return()=>{g=true;a.removeEventListener(r.Message,m)}};let m=0;var p=()=>++m;const h=".";const v=e=>e?e.split(h):[];const y=e=>e.join(h);const w=(e,n)=>{const t=v(n||"");t.push(e);return y(t)};const $=(e,n,t)=>{const o=v(n);o.reduce((e,n,r)=>{if(typeof e[n]==="undefined"){e[n]={}}if(r===o.length-1){e[n]=t}return e[n]},e);return e};const C=(e,n)=>{const t={};Object.keys(e).forEach(o=>{const r=e[o];const s=w(o,n);if(typeof r==="object"){Object.assign(t,C(r,s))}if(typeof r==="function"){t[s]=r}});return t};const E=e=>{const n={};for(const t in e){$(n,t,e[t])}return n};var k=(o,s,i,c,a)=>{const{localName:d,local:l,remote:u,originForSending:g,originForReceiving:m}=s;let h=false;a(`${d}: Connecting call sender`);const v=o=>(...s)=>{a(`${d}: Sending ${o}() call`);let i;try{if(u.closed){i=true}}catch(e){i=true}if(i){c()}if(h){const e=new Error(`Unable to send ${o}() call due `+`to destroyed connection`);e.code=t.ConnectionDestroyed;throw e}return new Promise((t,i)=>{const c=p();const h=s=>{if(s.source!==u||s.data.penpal!==e.Reply||s.data.id!==c){return}if(m!=="*"&&s.origin!==m){a(`${d} received message from origin ${s.origin} which did not match expected origin ${m}`);return}const g=s.data;a(`${d}: Received ${o}() reply`);l.removeEventListener(r.Message,h);let p=g.returnValue;if(g.returnValueIsError){p=f(p)}(g.resolution===n.Fulfilled?t:i)(p)};l.addEventListener(r.Message,h);const v={penpal:e.Call,id:c,methodName:o,args:s};u.postMessage(v,g)})};const y=i.reduce((e,n)=>{e[n]=v(n);return e},{});Object.assign(o,E(y));return()=>{h=true}};var R=(e,n,t,o,r)=>{const{destroy:s,onDestroy:i}=o;let c;let a;const d={};return o=>{if(n!=="*"&&o.origin!==n){r(`Parent: Handshake - Received ACK message from origin ${o.origin} which did not match expected origin ${n}`);return}r("Parent: Handshake - Received ACK");const l={localName:"Parent",local:window,remote:o.source,originForSending:t,originForReceiving:n};if(c){c()}c=g(l,e,r);i(c);if(a){a.forEach(e=>{delete d[e]})}a=o.data.methodNames;const u=k(d,l,a,s,r);i(u);return d}};var S=(n,t,o,r)=>s=>{if(!s.source){return}if(o!=="*"&&s.origin!==o){n(`Parent: Handshake - Received SYN message from origin ${s.origin} which did not match expected origin ${o}`);return}n("Parent: Handshake - Received SYN, responding with SYN-ACK");const i={penpal:e.SynAck,methodNames:Object.keys(t)};s.source.postMessage(i,r)};const N=6e4;var M=(e,n)=>{const{destroy:t,onDestroy:o}=n;const r=setInterval(()=>{if(!e.isConnected){clearInterval(r);t()}},N);o(()=>{clearInterval(r)})};var A=(e,n)=>{let o;if(e!==undefined){o=window.setTimeout(()=>{const o=new Error(`Connection timed out after ${e}ms`);o.code=t.ConnectionTimeout;n(o)},e)}return()=>{clearTimeout(o)}};var P=e=>{if(!e.src&&!e.srcdoc){const e=new Error("Iframe must have src or srcdoc property defined.");e.code=t.NoIframeSrc;throw e}};var j=n=>{let{iframe:t,methods:o={},childOrigin:c,timeout:a,debug:d=false}=n;const u=i(d);const f=s("Parent",u);const{onDestroy:g,destroy:m}=f;if(!c){P(t);c=l(t.src)}const p=c==="null"?"*":c;const h=C(o);const v=S(u,h,c,p);const y=R(h,c,p,f,u);const w=new Promise((n,o)=>{const s=A(a,m);const i=o=>{if(o.source!==t.contentWindow||!o.data){return}if(o.data.penpal===e.Syn){v(o);return}if(o.data.penpal===e.Ack){const e=y(o);if(e){s();n(e)}return}};window.addEventListener(r.Message,i);u("Parent: Awaiting handshake");M(t,f);g(e=>{window.removeEventListener(r.Message,i);if(e){o(e)}})});return{promise:w,destroy(){m()}}};var D=(n,t,o,r)=>{const{destroy:s,onDestroy:i}=o;return o=>{let c=n instanceof RegExp?n.test(o.origin):n==="*"||n===o.origin;if(!c){r(`Child: Handshake - Received SYN-ACK from origin ${o.origin} which did not match expected origin ${n}`);return}r("Child: Handshake - Received SYN-ACK, responding with ACK");const a=o.origin==="null"?"*":o.origin;const d={penpal:e.Ack,methodNames:Object.keys(t)};window.parent.postMessage(d,a);const l={localName:"Child",local:window,remote:window.parent,originForSending:a,originForReceiving:o.origin};const u=g(l,t,r);i(u);const f={};const m=k(f,l,o.data.methodNames,s,r);i(m);return f}};const b=()=>{try{clearTimeout()}catch(e){return false}return true};var F=(n={})=>{const{parentOrigin:t="*",methods:o={},timeout:c,debug:a=false}=n;const d=i(a);const l=s("Child",d);const{destroy:u,onDestroy:f}=l;const g=C(o);const m=D(t,g,l,d);const p=()=>{d("Child: Handshake - Sending SYN");const n={penpal:e.Syn};const o=t instanceof RegExp?"*":t;window.parent.postMessage(n,o)};const h=new Promise((n,t)=>{const o=A(c,u);const s=t=>{if(!b()){return}if(t.source!==parent||!t.data){return}if(t.data.penpal===e.SynAck){const e=m(t);if(e){window.removeEventListener(r.Message,s);o();n(e)}}};window.addEventListener(r.Message,s);p();f(e=>{window.removeEventListener(r.Message,s);if(e){t(e)}})});return{promise:h,destroy(){u()}}};var I={connectToChild:j,connectToParent:F,ErrorCode:t};return I}();
@@ -1 +1 @@
1
- {"version":3,"sources":["dist/penpal.js"],"names":["Penpal","MessageType","Resolution","ErrorCode","NativeErrorName","NativeEventType","createDestructor","localName","log","callbacks","destroyed","[object Object]","error","concat","forEach","callback","push","createLogger","debug","args","console","DEFAULT_PORT_BY_PROTOCOL","http:","https:","URL_REGEX","opaqueOriginSchemes","getOriginFromSrc","src","find","scheme","startsWith","location","document","regexResult","exec","protocol","hostname","port","portSuffix","serializeError","name","message","stack","deserializeError","obj","deserializedError","Error","Object","keys","key","connectCallReceiver","info","serializedMethods","local","remote","originForSending","originForReceiving","handleMessageEvent","event","source","data","penpal","Call","origin","callMessage","methodName","id","createPromiseHandler","resolution","returnValue","Reply","Rejected","returnValueIsError","postMessage","err","DataCloneError","errorReplyMessage","Promise","resolve","apply","then","Fulfilled","addEventListener","Message","removeEventListener","generateId","KEY_PATH_DELIMITER","keyPathToSegments","keyPath","split","segmentsToKeyPath","segments","join","createKeyPath","prefix","setAtKeyPath","subject","value","reduce","prevSubject","idx","length","serializeMethods","methods","flattenedMethods","assign","deserializeMethods","connectCallSender","callSender","methodKeyPaths","destroyConnection","createMethodProxy","iframeRemoved","closed","e","code","ConnectionDestroyed","reject","replyMessage","api","handleAckMessageFactory","childOrigin","destructor","destroy","onDestroy","destroyCallReceiver","receiverMethodNames","window","receiverMethodName","methodNames","destroyCallSender","handleSynMessageFactory","synAckMessage","SynAck","CHECK_IFRAME_IN_DOC_INTERVAL","monitorIframeRemoval","iframe","checkIframeInDocIntervalId","setInterval","isConnected","clearInterval","startConnectionTimeout","timeout","timeoutId","undefined","setTimeout","ConnectionTimeout","clearTimeout","validateIframeHasSrcOrSrcDoc","srcdoc","NoIframeSrc","connectToChild","options","handleSynMessage","handleAckMessage","promise","stopConnectionTimeout","handleMessage","contentWindow","Syn","Ack","handleSynAckMessageFactory","parentOrigin","originQualifies","RegExp","test","ackMessage","parent","areGlobalsAccessible","connectToParent","handleSynAckMessage","sendSynMessage","synMessage","parentOriginForSyn","indexForBundle"],"mappings":"AAAA,IAAIA,OAAU,WACZ,aAEA,IAAIC,GAEJ,SAAWA,GACTA,EAAY,QAAU,OACtBA,EAAY,SAAW,QACvBA,EAAY,OAAS,MACrBA,EAAY,UAAY,SACxBA,EAAY,OAAS,OALvB,CAMGA,IAAgBA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,CAC5C,MAAMzB,EAAa8D,EAAoBhH,GAEvC,GAAIkD,EAAY,CACdmB,OAAO3C,oBAAoB/E,EAAgB8E,QAAS0E,GACpDD,IACA9E,EAAQ8B,MAKdmB,OAAO7C,iBAAiB7E,EAAgB8E,QAAS0E,GACjDc,IACA/C,EAAUhH,IACRmH,OAAO3C,oBAAoB/E,EAAgB8E,QAAS0E,GAEpD,GAAIjJ,EAAO,CACTyG,EAAOzG,QAIb,MAAO,CACL+I,QAAAA,EAEAhJ,UAEEgH,OAMN,IAAImD,EAAiB,CACnBvB,eAAAA,EACAkB,gBAAAA,EACAtK,UAAAA,GAGF,OAAO2K,EAlwBI"}
1
+ {"version":3,"sources":["dist/penpal.js"],"names":["Penpal","MessageType","Resolution","ErrorCode","NativeErrorName","NativeEventType","createDestructor","localName","log","callbacks","destroyed","[object Object]","error","forEach","callback","push","createLogger","debug","args","console","DEFAULT_PORT_BY_PROTOCOL","http:","https:","URL_REGEX","opaqueOriginSchemes","getOriginFromSrc","src","find","scheme","startsWith","location","document","regexResult","exec","protocol","hostname","port","portSuffix","serializeError","name","message","stack","deserializeError","obj","deserializedError","Error","Object","keys","key","connectCallReceiver","info","serializedMethods","local","remote","originForSending","originForReceiving","handleMessageEvent","event","source","data","penpal","Call","origin","callMessage","methodName","id","createPromiseHandler","resolution","returnValue","Reply","Rejected","returnValueIsError","postMessage","err","DataCloneError","errorReplyMessage","Promise","resolve","apply","then","Fulfilled","addEventListener","Message","removeEventListener","generateId","KEY_PATH_DELIMITER","keyPathToSegments","keyPath","split","segmentsToKeyPath","segments","join","createKeyPath","prefix","setAtKeyPath","subject","value","reduce","prevSubject","idx","length","serializeMethods","methods","flattenedMethods","assign","deserializeMethods","connectCallSender","callSender","methodKeyPaths","destroyConnection","createMethodProxy","iframeRemoved","closed","e","code","ConnectionDestroyed","reject","replyMessage","api","handleAckMessageFactory","childOrigin","destructor","destroy","onDestroy","destroyCallReceiver","receiverMethodNames","window","receiverMethodName","methodNames","destroyCallSender","handleSynMessageFactory","synAckMessage","SynAck","CHECK_IFRAME_IN_DOC_INTERVAL","monitorIframeRemoval","iframe","checkIframeInDocIntervalId","setInterval","isConnected","clearInterval","startConnectionTimeout","timeout","timeoutId","undefined","setTimeout","ConnectionTimeout","clearTimeout","validateIframeHasSrcOrSrcDoc","srcdoc","NoIframeSrc","connectToChild","options","handleSynMessage","handleAckMessage","promise","stopConnectionTimeout","handleMessage","contentWindow","Syn","Ack","handleSynAckMessageFactory","parentOrigin","originQualifies","RegExp","test","ackMessage","parent","areGlobalsAccessible","connectToParent","handleSynAckMessage","sendSynMessage","synMessage","parentOriginForSyn","indexForBundle"],"mappings":"AAAA,IAAIA,OAAU,WACZ,aAEA,IAAIC,GAEJ,SAAWA,GACTA,EAAY,QAAU,OACtBA,EAAY,SAAW,QACvBA,EAAY,OAAS,MACrBA,EAAY,UAAY,SACxBA,EAAY,OAAS,OALvB,CAMGA,IAAgBA,EAAc,KAEjC,IAAIC,GAEJ,SAAWA,GACTA,EAAW,aAAe,YAC1BA,EAAW,YAAc,YAF3B,CAGGA,IAAeA,EAAa,KAE/B,IAAIC,GAEJ,SAAWA,GACTA,EAAU,uBAAyB,sBACnCA,EAAU,qBAAuB,oBACjCA,EAAU,eAAiB,eAH7B,CAIGA,IAAcA,EAAY,KAE7B,IAAIC,GAEJ,SAAWA,GACTA,EAAgB,kBAAoB,kBADtC,CAEGA,IAAoBA,EAAkB,KAEzC,IAAIC,GAEJ,SAAWA,GACTA,EAAgB,WAAa,WAD/B,CAEGA,IAAoBA,EAAkB,KAEzC,IAAIC,EAAmB,CAAEC,EAAWC,KAClC,MAAMC,EAAY,GAClB,IAAIC,EAAY,MAChB,MAAO,CACLC,QAAQC,GACN,IAAKF,EAAW,CACdA,EAAY,KACZF,EAAI,GAAGD,4BACPE,EAAUI,QAAQC,IAChBA,EAASF,OAKfD,UAAUG,GACRJ,EAAYI,IAAaL,EAAUM,KAAKD,MAM9C,IAAIE,EAAgBC,GAIX,IAAIC,K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C,MAAMlB,EAAU,IAAI9E,QAAQ,CAACC,EAASuC,KACpC,MAAMuC,EAAwBf,EAAuBC,EAASnB,GAE9D,MAAMkC,EAAgBnG,IAQpB,IAAK8G,IAAwB,CAC3B,OAGF,GAAI9G,EAAMC,SAAW4G,SAAW7G,EAAME,KAAM,CAC1C,OAGF,GAAIF,EAAME,KAAKC,SAAW3D,EAAYmI,OAAQ,CAC5C,MAAMzB,EAAa8D,EAAoBhH,GAEvC,GAAIkD,EAAY,CACdmB,OAAO3C,oBAAoB9E,EAAgB6E,QAAS0E,GACpDD,IACA9E,EAAQ8B,MAKdmB,OAAO7C,iBAAiB5E,EAAgB6E,QAAS0E,GACjDc,IACA/C,EAAU/G,IACRkH,OAAO3C,oBAAoB9E,EAAgB6E,QAAS0E,GAEpD,GAAIhJ,EAAO,CACTwG,EAAOxG,QAIb,MAAO,CACL8I,QAAAA,EAEA/I,UAEE+G,OAMN,IAAImD,EAAiB,CACnBvB,eAAAA,EACAkB,gBAAAA,EACArK,UAAAA,GAGF,OAAO0K,EA1wBI"}
@@ -25,7 +25,7 @@ var _default = (parentOrigin, serializedMethods, destructor, log) => {
25
25
  let originQualifies = parentOrigin instanceof RegExp ? parentOrigin.test(event.origin) : parentOrigin === '*' || parentOrigin === event.origin;
26
26
 
27
27
  if (!originQualifies) {
28
- log("Child: Handshake - Received SYN-ACK from origin ".concat(event.origin, " which did not match expected origin ").concat(parentOrigin));
28
+ log(`Child: Handshake - Received SYN-ACK from origin ${event.origin} which did not match expected origin ${parentOrigin}`);
29
29
  return;
30
30
  }
31
31
 
@@ -29,7 +29,7 @@ var _default = (info, serializedMethods, log) => {
29
29
  }
30
30
 
31
31
  if (originForReceiving !== '*' && event.origin !== originForReceiving) {
32
- log("".concat(localName, " received message from origin ").concat(event.origin, " which did not match expected origin ").concat(originForReceiving));
32
+ log(`${localName} received message from origin ${event.origin} which did not match expected origin ${originForReceiving}`);
33
33
  return;
34
34
  }
35
35
 
@@ -39,11 +39,11 @@ var _default = (info, serializedMethods, log) => {
39
39
  args,
40
40
  id
41
41
  } = callMessage;
42
- log("".concat(localName, ": Received ").concat(methodName, "() call"));
42
+ log(`${localName}: Received ${methodName}() call`);
43
43
 
44
44
  const createPromiseHandler = resolution => {
45
45
  return returnValue => {
46
- log("".concat(localName, ": Sending ").concat(methodName, "() reply"));
46
+ log(`${localName}: Sending ${methodName}() reply`);
47
47
 
48
48
  if (destroyed) {
49
49
  // It's possible to throw an error here, but it would need to be thrown asynchronously
@@ -51,7 +51,7 @@ var _default = (info, serializedMethods, log) => {
51
51
  // is merely returning a value from their method and not calling any function
52
52
  // that they could wrap in a try-catch. Even if the consumer were to catch the error,
53
53
  // the value of doing so is questionable. Instead, we'll just log a message.
54
- log("".concat(localName, ": Unable to send ").concat(methodName, "() reply due to destroyed connection"));
54
+ log(`${localName}: Unable to send ${methodName}() reply due to destroyed connection`);
55
55
  return;
56
56
  }
57
57
 
@@ -35,11 +35,11 @@ var _default = (callSender, info, methodKeyPaths, destroyConnection, log) => {
35
35
  originForReceiving
36
36
  } = info;
37
37
  let destroyed = false;
38
- log("".concat(localName, ": Connecting call sender"));
38
+ log(`${localName}: Connecting call sender`);
39
39
 
40
40
  const createMethodProxy = methodName => {
41
41
  return (...args) => {
42
- log("".concat(localName, ": Sending ").concat(methodName, "() call")); // This handles the case where the iframe has been removed from the DOM
42
+ log(`${localName}: Sending ${methodName}() call`); // This handles the case where the iframe has been removed from the DOM
43
43
  // (and therefore its window closed), the consumer has not yet
44
44
  // called destroy(), and the user calls a method exposed by
45
45
  // the remote. We detect the iframe has been removed and force
@@ -64,7 +64,7 @@ var _default = (callSender, info, methodKeyPaths, destroyConnection, log) => {
64
64
  }
65
65
 
66
66
  if (destroyed) {
67
- const error = new Error("Unable to send ".concat(methodName, "() call due ") + "to destroyed connection");
67
+ const error = new Error(`Unable to send ${methodName}() call due ` + `to destroyed connection`);
68
68
  error.code = _enums.ErrorCode.ConnectionDestroyed;
69
69
  throw error;
70
70
  }
@@ -78,12 +78,12 @@ var _default = (callSender, info, methodKeyPaths, destroyConnection, log) => {
78
78
  }
79
79
 
80
80
  if (originForReceiving !== '*' && event.origin !== originForReceiving) {
81
- log("".concat(localName, " received message from origin ").concat(event.origin, " which did not match expected origin ").concat(originForReceiving));
81
+ log(`${localName} received message from origin ${event.origin} which did not match expected origin ${originForReceiving}`);
82
82
  return;
83
83
  }
84
84
 
85
85
  const replyMessage = event.data;
86
- log("".concat(localName, ": Received ").concat(methodName, "() reply"));
86
+ log(`${localName}: Received ${methodName}() reply`);
87
87
  local.removeEventListener(_enums.NativeEventType.Message, handleMessageEvent);
88
88
  let returnValue = replyMessage.returnValue;
89
89
 
@@ -12,7 +12,7 @@ var _default = (localName, log) => {
12
12
  destroy(error) {
13
13
  if (!destroyed) {
14
14
  destroyed = true;
15
- log("".concat(localName, ": Destroying connection"));
15
+ log(`${localName}: Destroying connection`);
16
16
  callbacks.forEach(callback => {
17
17
  callback(error);
18
18
  });
@@ -46,8 +46,8 @@ var _default = src => {
46
46
  // or it won't match the message's event.origin.
47
47
 
48
48
 
49
- const portSuffix = port && port !== DEFAULT_PORT_BY_PROTOCOL[protocol] ? ":".concat(port) : '';
50
- return "".concat(protocol, "//").concat(hostname).concat(portSuffix);
49
+ const portSuffix = port && port !== DEFAULT_PORT_BY_PROTOCOL[protocol] ? `:${port}` : '';
50
+ return `${protocol}//${hostname}${portSuffix}`;
51
51
  };
52
52
 
53
53
  exports.default = _default;
@@ -28,7 +28,7 @@ var _default = (serializedMethods, childOrigin, originForSending, destructor, lo
28
28
  const callSender = {};
29
29
  return event => {
30
30
  if (childOrigin !== '*' && event.origin !== childOrigin) {
31
- log("Parent: Handshake - Received ACK message from origin ".concat(event.origin, " which did not match expected origin ").concat(childOrigin));
31
+ log(`Parent: Handshake - Received ACK message from origin ${event.origin} which did not match expected origin ${childOrigin}`);
32
32
  return;
33
33
  }
34
34
 
@@ -12,8 +12,16 @@ var _enums = require("../enums");
12
12
  */
13
13
  var _default = (log, serializedMethods, childOrigin, originForSending) => {
14
14
  return event => {
15
+ // Under specific timing circumstances, we can receive an event
16
+ // whose source is null. This seems to happen when the child iframe is
17
+ // removed from the DOM about the same time it has sent the SYN event.
18
+ // https://github.com/Aaronius/penpal/issues/85
19
+ if (!event.source) {
20
+ return;
21
+ }
22
+
15
23
  if (childOrigin !== '*' && event.origin !== childOrigin) {
16
- log("Parent: Handshake - Received SYN message from origin ".concat(event.origin, " which did not match expected origin ").concat(childOrigin));
24
+ log(`Parent: Handshake - Received SYN message from origin ${event.origin} which did not match expected origin ${childOrigin}`);
17
25
  return;
18
26
  }
19
27
 
@@ -16,7 +16,7 @@ var _default = (timeout, callback) => {
16
16
 
17
17
  if (timeout !== undefined) {
18
18
  timeoutId = window.setTimeout(() => {
19
- const error = new Error("Connection timed out after ".concat(timeout, "ms"));
19
+ const error = new Error(`Connection timed out after ${timeout}ms`);
20
20
  error.code = _enums.ErrorCode.ConnectionTimeout;
21
21
  callback(error);
22
22
  }, timeout);
@@ -4,6 +4,13 @@ import { MessageType } from '../enums';
4
4
  */
5
5
  export default (log, serializedMethods, childOrigin, originForSending) => {
6
6
  return (event) => {
7
+ // Under specific timing circumstances, we can receive an event
8
+ // whose source is null. This seems to happen when the child iframe is
9
+ // removed from the DOM about the same time it has sent the SYN event.
10
+ // https://github.com/Aaronius/penpal/issues/85
11
+ if (!event.source) {
12
+ return;
13
+ }
7
14
  if (childOrigin !== '*' && event.origin !== childOrigin) {
8
15
  log(`Parent: Handshake - Received SYN message from origin ${event.origin} which did not match expected origin ${childOrigin}`);
9
16
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "penpal",
3
- "version": "6.2.1",
3
+ "version": "6.2.2",
4
4
  "description": "A promise-based library for communicating with iframes via postMessage.",
5
5
  "author": "Aaron Hardy <aaron@aaronhardy.com>",
6
6
  "license": "MIT",