I've built a C# windows forms app in VS 2019 that includes Webview2 (latest pre-release) to create a browser. The application loads a page and checks for specific content. If the content is not there, it reloads the page. If the content is there (which has yet to happen), it fills out some fields and clicks a button.
The app was working fine for a while. Now every once in a while I get the following in the Webview2 control:
This page is having a problem. Please come back to it later
You could also: Open a new tab Refresh the page
Error Code: STATUS_ACCESS_VIOLATION
I ran the app in debug mode to try to catch the error. There is no exception to catch. And if I place a breakpoint in the ContentLoading
event of the Webview2
control, it never triggers before I see this error page. I'm not sure what's triggering it or how to stop it.
On Form_load I call the following:
async void checksites()
{
await wv2Dig.EnsureCoreWebView2Async();
wv2Dig.CoreWebView2.Navigate(strURL);
}
And ContentLoading
will call the function below that tries to check the content as the page is loading so as to make a decision before the page fully loads. Right now it is only triggering the button we don't want. Here is the code:
async Task DigPageCheck()
{
iDigCount += 1; //count of number of checks
txtDig.Text = iDigCount.ToString(); //display count
string strResult = await wv2Dig.CoreWebView2.ExecuteScriptAsync("document.documentElement.innerHTML;");
//get innerHTML
strResult = Regex.Unescape(strResult);
strResult = strResult.Remove(0, 1);
strResult = strResult.Remove(strResult.Length - 1, 1);
//check for button we want
int loc = strResult.IndexOf("btn btn-primary btn-lg btn-block btn-leading-ficon add-to-cart-button");
//check for button we want
int loc2 = strResult.IndexOf("btn btn-disabled btn-lg btn-block add-to-cart-button"); x
while (loc == -1 && loc2 == -1)
{
//while neither button exists wait and check again
await Task.Delay(200);
strResult = await wv2Dig.CoreWebView2.ExecuteScriptAsync("document.documentElement.innerHTML;");
strResult = Regex.Unescape(strResult);
strResult = strResult.Remove(0, 1);
strResult = strResult.Remove(strResult.Length - 1, 1);
loc = strResult.IndexOf("btn btn-primary btn-lg btn-block btn-leading-ficon add-to-cart-button");
loc2 = strResult.IndexOf("btn btn-disabled btn-lg btn-block add-to-cart-button");
}
//the button we want has been found
if (loc != -1)
{
iDig += 1;
string mSubj = "Found";
try
{
sendSMS(mSubj, strDigURL);
}
catch
{
label3.Text = "Email Error";
}
var functionString = string.Format(@"document.getElementsByClassName('btn btn-primary btn-lg btn-block btn-leading-ficon add-to-cart-button')[0].click();");
await wv2Dig.CoreWebView2.ExecuteScriptAsync(functionString);
}
else //button we don't want found
{
if (bRun) //app is in run state, it can be paused
wv2Dig.CoreWebView2.Reload(); //Reload the page and check again
}
}
It seems at some point while reloading, the error page comes up.
The below was solved by removing WebView2 prelease 0.9.682 and installing prerelease 0.9.579
And I have a new issue that popped up randomly. The app freezes on
await wv2Dig.EnsureCoreWebView2Async();
which is in a function called fromForm_Load
I added
wv2Dig.CoreWebView2.Stop()
before doing awv2Dig.CoreWebView2.Reload()
and I have not seen the problem since. I think that may have solved the problem. I say I think because the program ran without issue for quite some time and then started having the problem.During this process I also downgraded the pre-release version of WebView2 beauce the WebView2 stopped working completely somehow.