Lightning web component window.addEventListener local variables and HTML Dom is undefined
That is because function(message) declaration will have its own scope and this will refer to its own block in which you did not define captchaURL. You can use Arrow function to solve this (message) =>
- arrow function will take the scope of parent as it does not have its own scope.
window.addEventListener("message", (message) => {
if (message !== undefined && message.data === 'successGCP' && message.origin === window.location.origin) {
this.captchaDone = true; // not able to access this.captchaDone getting undefined while this is declared.
this.template.querySelector("lightning-button").disabled = false; // this.template is also undefined
}
}
);