CefSharp won't load HTML

1.4k Views Asked by At

I know this has been asked a number of different times before, but none of the solutions suggested there have worked. I'm trying to give cefsharp custom html in the most recent release of cefsharp/offscreen via nuget. Here's a sample of the code:

        private void Start(string cachePath)//unsafe tp call twice currently
    {
        var settings = new CefSettings()
        {
            //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
            CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache")
        };
        //Now for the internals

        Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);
        Thread.Sleep(500);
        browser = new ChromiumWebBrowser("dummy:");
        Thread.Sleep(500);
    }


    private int CleanMemory()
    {
        Cef.Shutdown();
        return 1;
    }

    private async void TakePictures()
    {
        //Reduce rendering speed to one frame per second so it's easier to take screen shots
        //browserSettings.WindowlessFrameRate = 1;

        while (m_ReceivedObjects.Any() && currentImageToBeProcessed.IsRendered == false)
        {
            currentImageToBeProcessed = m_ReceivedObjects.Dequeue();

            //await LoadPageAsync(browser, currentImageToBeProcessed.filePath, currentImageToBeProcessed.rawHtml);
            currentImageToBeProcessed.IsRendered = true;
            string h = "< html >< head >< style > body { background - color: #93B874; } h1 { background - color: #00b33c; } p { background - color: #FFFFFF); } </ style >"
                + "</ head > < body >< h1 > Header with Green Background </ h1 >< p > Paragraph with white background </ p ></ body ></ html > ";

            //CefSharp.WebBrowserExtensions.LoadHtml(browser, h, "http://www.example.com/");
            //browser.LoadHtml("<html><body><h1>Hello world!</h1></body></html>", "http://example.com/");
            //browser.Load("https://www.google.com/");
            browser.Load("data:,Hello%2C%20World!");// LoadHtml("<html><body><h1>Hello world!</h1></body></html>", "http://example.com");
            //browser.Load("data:text/html," + System.Web.HttpUtility.UrlPathEncode(currentImageToBeProcessed.rawHtml));

            Thread.Sleep(2000);
            await browser.ScreenshotAsync().ContinueWith(processHTML);
        }
    }

Near the bottom, with the commented lines are where the trouble is.

I've tried loadHtml, loadString, and load with a variety of different url and data uri types. None have worked.

The google page and all 'actual' url's do work though. (the 2 sec sleep is a placeholder till I have more time.)

0

There are 0 best solutions below