ampproject / ampproject/worker-dom

listen to message events from postMessage not supported (?)

Open
#747 2 comments 0 reactions 1 assignee Claimed by @kristoferbaxter View on GitHub
amp-script API
Dominant language
TypeScript
Stars
3.3k
Forks
154
PR merge metrics
No merged PRs in 30d

Description

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:

```





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

```
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.