Cannot postMessage to IFrame element on Editor-X live site

Hi @yisrael-wix

My test site seems to work now. I can go back and forward using links and the iframe still responding.

However, my production site (not yet released yet) still has the problem. I put the movie here .

In the movie, you can see the following steps

  1. User log-in

  2. /users/top page shown → click on the card

  3. /users/view page shown (internally has iframe) → click back to top button

  4. /users/top page shown → click again on the card

  5. /users/view page is stuck, the error that it cannot post to the iframe shown.

If you need to try yourself, you can go here and use a testing account (test@opini-kedua.com, password: ‘abcdabcd’). I will disable the account once you finished.

@nikobarli What is the URL of your production site?

@yisrael-wix Sorry, forgot to put the link. Here it is https://opini-kedua.com/users/login.

@nikobarli Give it a try now. (you might first need to count to 100, or perhaps 200)

@yisrael-wix Hi Israel, I created a simple website just for you so you can recreate the problem easily. I get a similar error to Niko’s with a slightly different use case.

website link:
[https://hurryappnet.editorx.io/website-9](https://hurryappnet.editorx.io/website-9

wto)

In order to recreate the problem, please follow the following steps:

  1. Open the link above. make sure the developer console (debugger) is open in order to see the messages that are printed to the console.

  2. Click on the button " Open Lightbox #1 ". the lightbox will open, a message from the iframe to the page will be printed to the console (handshake, to make sure the iframe is loaded) and then a message from the page to the iframe will be printed to the console.

  3. Close the lightbox.

  4. Click on “Open Lightbox #1” again (or alternatively click the second button “Open Lightbox #2”), the message from the iframe (handshake) will be received but postMessage will throw an error:
    " Uncaught (in promise) TypeError: Cannot read property ‘postMessage’ of null "
    therefore the message from the page to the iframe won’t be received.

Here’s the website’s code:

page code:

import wixWindow from 'wix-window';

$w.onReady(function () {
   $w("#button1").onClick(function (event) {
            wixWindow.openLightbox("myLightbox", "button #1 message from page");
    });
    $w("#button2").onClick(function (event) {
            wixWindow.openLightbox("myLightbox", "button #2 message from page");
    });
});

Lightbox code:

import wixWindow from 'wix-window';

let messageFromPage;

$w.onReady(function () {
    messageFromPage = wixWindow.lightbox.getContext();

// waiting for message from iframe ("handshake") before sending a message to it
    $w("#myIframe").onMessage(function(event) {
     let messageFromIframe = event.data;
     if (messageFromIframe.type === "ready") {
            console.log("message from iframe received - iframe ready");
            $w("#myIframe").postMessage(messageFromPage);
        }
    });
});


iframe code (iframe is inside the lightbox):

<body onLoad="ready()">
<script type="text/javascript">
    function ready(){
    window.parent.postMessage({"type":"ready"}, "*");
    }
   window.onmessage = (event) => {
     if (event.data) {
        console.log("message from page received: " + event.data);
     }
   }
 </script>
</body>

In addition, I attached 2 screenshots:

  1. the console after the first time the lightbox opens (everything works)
  2. the console after the second time the lightbox opens (postMessage throws an error).

Please let me know if you were able to recreate the bug!
Thank you for your help

Hi Israel, I created a simple website just for you so you can recreate the problem easily. I get a similar error to Niko’s with a slightly different use case.

website link:
https://hurryappnet.editorx.io/website-9

In order to recreate the problem, please follow the following steps:

  1. Open the link above. make sure the developer console (debugger) is open in order to see the messages that are printed to the console.

  2. Click on the button " Open Lightbox #1 ". the lightbox will open, a message from the iframe to the page will be printed to the console (handshake, to make sure the iframe is loaded) and then a message from the page to the iframe will be printed to the console.

  3. Close the lightbox.

  4. Click on “Open Lightbox #1” again (or alternatively click the second button “Open Lightbox #2”), the message from the iframe (handshake) will be received but postMessage will throw an error: " Uncaught (in promise) TypeError: Cannot read property ‘postMessage’ of null " therefore the message from the page to the iframe won’t be received.

Here’s the website’s code:

page code:

import wixWindow from 'wix-window';

$w.onReady(function () {
   $w("#button1").onClick(function (event) {
            wixWindow.openLightbox("myLightbox", "button #1 message from page");
    });
    $w("#button2").onClick(function (event) {
            wixWindow.openLightbox("myLightbox", "button #2 message from page");
    });
});


Lightbox code:

import wixWindow from 'wix-window';

let messageFromPage;

$w.onReady(function () {
    messageFromPage = wixWindow.lightbox.getContext();

// waiting for message from iframe ("handshake") before sending a message to it
    $w("#myIframe").onMessage(function(event) {
     let messageFromIframe = event.data;
     if (messageFromIframe.type === "ready") {
            console.log("message from iframe received - iframe ready");
            $w("#myIframe").postMessage(messageFromPage);
        }
    });
});



iframe code (iframe is inside the lightbox):

<body onLoad="ready()">
<script type="text/javascript">
    function ready(){
    window.parent.postMessage({"type":"ready"}, "*");
    }
   window.onmessage = (event) => {
     if (event.data) {
        console.log("message from page received: " + event.data);
     }
   }
 </script>
</body>


In addition, I attached 2 screenshots:

  1. the console after the first time the lightbox opens (everything works)
  2. the console after the second time the lightbox opens (postMessage throws an error).

Please let me know if you were able to recreate the bug!
Thank you for your help

@yisrael-wix @hurryappnet

Yesterday, my site was completely broken, but seems due to other reasons: it uses router, and if the router call redirect it somehow stucked and the page is never redirected. It happened for the whole day.

 if(!user.loggedIn) {
   // if user not logged-in, redirect to login or signup user
   if(page === loginPage || page === signupPage) return next();
   console.log(`redirect to login page: ${loginPage}`);
   return redirect(loginPage);
 }

This morning everything works again. And the iframe problem I mentioned also disappears. However, when I checked the test site @hurryapp.net provided, the problem is still there.

So I am not sure what’s going on. Probably wix is pushing some changes and when it slowly propagates, things are broken temporarily. But imagine if your service is already running, and suddenly it is broken for the whole day without notifications…

I can also confirm that the bug on my website persists. So please check it out Israel.

thanks!

@nikobarli Please post this issue (which is not related to the original topic) in a new post. Explain what you are trying to do, what works, and what doesn’t. Share relevant code in a code block.

Further, indicate when this problem started and if you are still encountering this issue.

@hurryappnet What bug are you still encountering?

Data is passed to a Lightbox using an object (not just a string):

   $w("#button1").onClick(function (event) {
            wixWindow.openLightbox("myLightbox", {"msg": "button #1 message from page"});
    });
    $w("#button2").onClick(function (event) {
            wixWindow.openLightbox("myLightbox", {"msg": "button #2 message from page"});
    });

In the Lightbox, you get your message like this:

let received = wixWindow.lightbox.getContext();
let messageFromPage = received.msg;

This is a different issue from the HtmlComponent.

I hope this helps.

@yisrael-wix Hi israel,
I updated the code to pass an object to the lightbox (I copied and pasted the code you suggested) and the bug persists. same error:
" comlink.ts:265 Uncaught (in promise) TypeError: Cannot read property ‘postMessage’ of null "

I published it so you can check it out on the same link:
https://hurryappnet.editorx.io/website-9

I still think it has something to do with the iframe and not the lightbox, simply because when passing data to the lightbox without using an iframe postMessage it works flawlessly.

the updated code is the exact code you suggested.

thanks!

Hi Israel,this issue is still not solved. please check out my response and let me know if you can successfully recreate the bug.

Hi israel, I described the bug in detail in the upper part of this thread. I’ll re-write it here:

I encounter the same bug I mentioned with the lightboxes, even after updating the code to the code you suggested-

"I updated the code to pass an object to the lightbox (copied and pasted the code you suggested) and the bug persists. same error: " comlink.ts:265 Uncaught (in promise) TypeError: Cannot read property ‘postMessage’ of null " I published it so you can check it out on the same link: https://hurryappnet.editorx.io/website-9

I still think it has something to do with the iframe and not the lightbox, simply because when passing data to the lightbox without using an iframe postMessage it works flawlessly. the updated code is the exact code you suggested.
thanks!"

Here’s a description original problem that persists in detail-

In order to recreate the problem, please follow the following steps:

  1. Open the link above. make sure the developer console (debugger) is open in order to see the messages that are printed to the console.

  2. Click on the button " Open Lightbox #1 ". the lightbox will open, a message from the iframe to the page will be printed to the console (handshake, to make sure the iframe is loaded) and then a message from the page to the iframe will be printed to the console.

  3. Close the lightbox.

  4. Click on “Open Lightbox #1” again (or alternatively click the second button “Open Lightbox #2”), the message from the iframe (handshake) will be received but postMessage will throw an error: " Uncaught (in promise) TypeError: Cannot read property ‘postMessage’ of null " therefore the message from the page to the iframe won’t be received.
    Here’s the website’s code:

    page code:

import wixWindow from 'wix-window';

$w.onReady(function () {
   $w("#button1").onClick(function (event) {
            wixWindow.openLightbox("myLightbox", {"msg": "button #1 message from page"});
    });
    $w("#button2").onClick(function (event) {
            wixWindow.openLightbox("myLightbox", {"msg": "button #2 message from page"});
    });
});

Lightbox code:

import wixWindow from 'wix-window';

$w.onReady(function () {
let received = wixWindow.lightbox.getContext();
let messageFromPage = received.msg;

// waiting for message from iframe ("handshake") before sending a message to it
    $w("#myIframe").onMessage(function(event) {
     let messageFromIframe = event.data;
     if (messageFromIframe.type === "ready") {
            console.log("message from iframe received - iframe ready");
            $w("#myIframe").postMessage(messageFromPage);
        }
    });
});




iframe code (iframe is inside the lightbox):

<body onLoad="ready()">
<script type="text/javascript">
    function ready(){
    window.parent.postMessage({"type":"ready"}, "*");
    }
   window.onmessage = (event) => {
     if (event.data) {
        console.log("message from page received: " + event.data);
     }
   }
 </script>
</body>



In addition, I attached 2 screenshots: 1. the console after the first time the lightbox opens (everything works) 2. the console after the second time the lightbox opens (postMessage throws an error).

so right now this bug persists!
thank you for your help.

@hurryappnet Hello, we identified the bug and have resolved the issue. Can you please confirm? Thanks.

@marlowe-shaeffer Yes ma’am! it works.

Great job there, I truly appreciate the support and the quick bug fixes.
I personally enjoy editor x very much and I think it’s an amazing product, a total upgrade to the original editor.

Thank you !