htmlwinformscefsharp

CefSharp html loaded exceeds 2097152 characters


I am using CefSharp in winform to show an html page, where I have some data to pass and show. here is the code:

private CefSharp.WinForms.ChromiumWebBrowser chromiumWebBrowser1;

string html = Utils.GetEmbeddedResource(htmlFilePath);
html = html.Replace("/*NODES*/", nodesJson);

BrowserSettings settings = new BrowserSettings {
    DefaultEncoding = "utf-8"
};
chromiumWebBrowser1.BrowserSettings = settings;
chromiumWebBrowser1.LoadHtml(html, base64Encode: true);

When it tried to load the html, an error occurred:

[0901/180248.815:WARNING:navigation_controller_impl.cc(283)] Refusing to load URL as it exceeds 2097152 characters.

I printed the length of html, which is 2250120. How to handle long html data? Please help me, thanks!


Solution

  • When no Url is provided then a Data URI is used. This has a hard limit on the size of a Data URI.

    If you provide a Url as the second param then a different under then a ResourceHandler is used to load your URL.

    Example

    chromiumWebBrowser1.LoadHtml(html, "http://myapp.test/index.html");
    

    https://cefsharp.github.io/api/113.1.x/html/M_CefSharp_WebBrowserExtensions_LoadHtml_2.htm