Possible to view-source:url in code?
daniel-rck opened this issue · comments
daniel-rck commented
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;
}
`
daniel-rck commented
Resubmitted issue in MicrosoftEdge/WebView2Feedback#296