-
Notifications
You must be signed in to change notification settings - Fork 64
Closed
Description
Hello,
I'm doing a little sample application with WebView2. I try to get the source-code of the current page,
the same as you can see in e.g. view-source:https://www.bing.com/
Is this possible from within C#?
Already did this with javascript, but there is missing data in comparison to the browser variant.
try
{
string html = await webView.CoreWebView2.ExecuteScriptAsync("document.documentElement.outerHTML");
string unescaped = Regex.Unescape(html);
html = unescaped.Substring(1, unescaped.Length - 2).Replace("&", "&");
if (!html.StartsWith("<html"))
{
Debug.WriteLine("Invalid source");
return null;
}
var doc = new HtmlDocument();
doc.LoadHtml(html);
return doc;
}
catch (Exception exc)
{
Debug.WriteLine(exc.Message);
return null;
}
`
ajtruckle
Metadata
Metadata
Assignees
Labels
No labels