3

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("***")
2
  • Can you please add some shows what you actually try to accomplish and allows to reproduce the problem. What Dart version are you using. What platform do you run your application on. I assume you are running the output of dart2js or pub build. Which options did you use to build your JS output? Commented May 30, 2015 at 17:29
  • Also, please don't add what is essentially tags to the title. That's what tags are for.
    – Xan
    Commented May 30, 2015 at 17:56

2 Answers 2

5

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 
1
  • Remark: window.alert and friends will fail in a Chrome App as opposed to nw.js
    – Xan
    Commented Oct 13, 2016 at 10:12
4

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

5
  • Sorry but I I tried to use this code to capture the error but does not work: <code>webview.addEventListener("confirm", (Event e){ e.preventDefault(); print("test"); });</code> Any idea?
    – MalumaDev
    Commented May 31, 2015 at 9:02
  • 1
    @maluma The event us always dialog, the type of dialog is a parameter. There is no confirm event.
    – Xan
    Commented May 31, 2015 at 9:33
  • Thank you. Add the code of the solution as soon as I finish.
    – MalumaDev
    Commented May 31, 2015 at 9:45
  • I apologize but I'm not able to go ahead. I was able to intercept the dialog but the event that returned does not give me information. 'webview.addEventListener("dialog",(Event e){ e.preventDefault(); } );'
    – MalumaDev
    Commented May 31, 2015 at 14:25
  • You may need to ask a fresh question.
    – Xan
    Commented May 31, 2015 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.