ampproject / ampproject/worker-dom
listen to message events from postMessage not supported (?)
- 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
Assessment
This issue has not been assessed yet.