worker-dom icon indicating copy to clipboard operation
worker-dom copied to clipboard

listen to message events from postMessage not supported (?)

Open massawho opened this issue 6 years ago • 2 comments

Hi I am trying to listen to events from my iframe, but it just doesn't work. Even though addEventListener is supported, when I try to listen for message events, I don't get the event from my iframe. I am not sure if it's because it is running inside a worker and it has its own virtual DOM, but I don't receive the message sent by my iframe.

        window.addEventListener('message', function(e) {
          console.log("catching event: "+e.origin); //logs "catching event:  undefined"
        }, false);

The whole code from what I am trying to achieve is this:

      <amp-script script="navi_impressions" height="24.4rem" width="">
      <amp-ad
        height="24.4rem"
        data-multi-size="fluid"
        type="doubleclick"
        data-slot="my-ad-unit">
      </amp-ad>
      </amp-script>
      <script type="text/plain" target="amp-script" id="navi_impressions">
        window.addEventListener('message', function(e) {
          console.log("catching event: "+e.origin);
        }, false);
      </script>

I have an amp-ad that generates the iframe of my ad from google ad manager. From the creative, I sent a postMessage event; however, the same code works if I run in the parent document.

massawho avatar Dec 31 '19 09:12 massawho

I’ll create a minimal repro and take a look. Thanks for reporting the issue!

kristoferbaxter avatar Jan 06 '20 04:01 kristoferbaxter

Thanks @kristoferbaxter ! Let me know if I can help in anything

massawho avatar Jan 09 '20 13:01 massawho