I am building a LWC with the intent to listen to an event from window.postMessage via window.addEventListner. However, after deploying the below code, I am not seeing any console logs from my LWC when I use chrome console to post the message to the window. I have tried using both this.addEventListener
and window.addEventListener
.
This is my first time building a LWC so I presume I am doing something wrong.
import { LightningElement } from 'lwc';
export default class MyEventHandler extends LightningElement {
constructor() {
super();
this.addEventListener('message', this.handleMessage);
}
handleMessage = (event) => {
console.log('event received')
console.log(event);
};
}