Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView2 ExecuteScriptAsync method returns encoded HTML

Tags:

html

c#

webview2

I am using Microsoft Webview2 to load a web page and below code is used to read the HTML content

string html = await webView1.ExecuteScriptAsync("document.documentElement.outerHTML");

The resulting output html appears with all tag opening, closing and other special characters encoded like below

\u003Chtml lang=\"en\" data-mode=\"light\">\u003Chead>\n    \u003Cmeta charset=\"utf-8\">\n    \u003Cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\u003Ctitle data-argonaut-actions=\"true

Why does this happen? How do I get plain HTML?

like image 914
Extreme_Tough Avatar asked Sep 19 '25 08:09

Extreme_Tough


1 Answers

var html = await webView2.ExecuteScriptAsync("document.documentElement.outerHTML");
html = Regex.Unescape(html);
html = html.Remove(0, 1);
html = html.Remove(html.Length - 1, 1);
like image 87
DrWeather Avatar answered Sep 20 '25 23:09

DrWeather