I need to display a webpage in webview and have certain navigations happen. Since webview does not let confirm dialogs pass through, I want to listen to the dialog events in the webview and then pass my own custom dialog and have the user action be the one that's going to be taken.
Listening to the webview for the event is easy enough:
webview.addEventListener('dialog', this.onDialogOpen);
And then I open the dialog with the said method:
private onDialogOpen (e: any): void {
this.dialogOn = true;
this.dialogEvent = e;
}
Now what I want is the user to interact with my dialog and pass its action to this dialogEvent, as this:
<button onclick="onDialogAction()">OK</button>
And run the script:
public onDialogAction() {
this.dialogEvent.dialog.ok();
}
But at this point I get the error in the title:
webview: An action has already been taken for this "dialog" event.
As I understand, for some reason, the DialogEvent gets 'outdated' once some time has passed. If I say 'this.dialogEvent.dialog.ok();' inside onDialogOpen it works. I can also call 'this.dialogEvent.dialog.ok();' from any other method if I call it from onDialogOpen. However if I say, setTimeout within that onDialogOpen, it stops working again.
What would be the cause of this and what would be the right way to get around this?