Dart doesn't show the alert dialog when I use a webview and show this error:
: An alert dialog was blocked. (extensions::webViewEvents:225)
: A confirm dialog was blocked. (extensions::webViewEvents:225)
Does anyone know how to bypass the problem or how to catch the error?
Thanks.
Sorry for my bad English.
Edit
The code used:
Element webview= querySelector("#webview");
Map<String,String> map=new Map();
map["src"]=urlWebView;
webview.attributes.addAll(map);
webview.style.visibility="visible";
DartEditor version= STABLE build 45396
The version number of the SDK= 1.10.0
The webview loads a page that works on a js not created by me.
The error occurs when using this:
alert("***")
A webview cannot show those by default.
You need to catch the dialog
event, show your own UI for it (remember, Apps can't use alert
and friends, so a <dialog>
is a good option) and then pass the response back with DialogController
more Clarification on @Xan Answer:
you need to listen to the dialog event from the webview ,Please read the comments in the code to understand better , again, I am using nwjs, so you can implement similar version in your language:
//lets listen to alert dom and enable it
webview.addEventListener('dialog',function(e){
//message type
messageType = e.messageType;
messageText = e.messageText;
DialogController = e.dialog;
//lets checki if alert
if(messageType == 'alert'){
window.alert(messageText);
}//emd if
//if confirm
else if(messageType == 'confirm'){
//confirm
var confirm = window.confirm(messageText);
//get confirm bool and send to controller
if(confirm == true){
//if true send okay to browser
DialogController.ok();
}else{
//send cancel with to send false false
DialogController.cancel();
}//end if
}//end if confirm
//lastly if its prompt
else if(messageType == 'prompt'){
//get user Input
promptInput = window.prompt(messageText);
//if null , then means the user clicked cancel
if(promptInput == null){
//tell browser to cancel
DialogController.cancel();
}else{
//feed browser with input data
DialogController.ok(promptInput);
}
}//end if prompt
});//end dialog test