To get the message you will have to do the following:
1 - Insert a script tag into the head of your webbrowser containing a new implementation of the window.alert
function, this implementation should add the alert string to some element of the html.
2 - Perform the procedure so that the alert is displayed and consequently the element with the alert string is popular.
3- Retrieve the string placed on this element
First Step
Create tag script to be inserted
HtmlElement head = webBrowser1.Document.GetElementsByTagName("head")[0];
HtmlElement tagScript = webBrowser1.Document.CreateElement("script");
IHTMLScriptElement bloqAlert = (IHTMLScriptElement)tagScript.DomElement;
Now we will define the string representing the contents of the script tag:
You should implement the alert code here, knowing that you will receive the alert message as an argument
bloqAlert.text = "window.alert = function (msgAlert) {
//SE A PÁGINA UTILIZAR JQUERY UM EXEMPLO SERIA
$('#elementoUsadoParaReceberAMensagem').val(msgAlert);
}";
Second Step
Adds the created script tag to the head of the loaded document in your webbrowser
head.AppendChild(scriptEl);
If the alert is invoked on the page your message will go to this html element
Third Step
Retrieves the string placed in the element
string mensagemAlert = webBrowser1.Document.GetElementById("elementoUsadoParaReceberAMensagem").GetAttribute("value");