Skip to content

Commit

Permalink
Simplify retrieval of iframe window.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronius committed Mar 6, 2019
1 parent 843476f commit 59c7231
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,15 @@ Penpal.connectToChild = ({ url, appendTo, iframe, methods = {}, timeout }) => {
let destroyCallReceiver;

const handleMessage = event => {
const child = iframe.contentWindow || iframe.contentDocument.parentWindow;
const child = iframe.contentWindow;
if (
event.source === child &&
event.origin === childOrigin &&
event.data.penpal === HANDSHAKE
) {
log('Parent: Received handshake, sending reply');

// If event.origin is "null", the remote protocol is file:
// If event.origin is "null", the remote protocol is file:
// and we must post messages with "*" as targetOrigin [1]
// [1] https://developer.mozilla.org/fr/docs/Web/API/Window/postMessage#Utiliser_window.postMessage_dans_les_extensions
const remoteOrigin = event.origin === "null" ? "*" : event.origin;
Expand Down

0 comments on commit 59c7231

Please sign in to comment.