c cef html,c# - CefSharp won't load HTML - Stack Overflow

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("

Hello world!

", "http://example.com/");

//browser.Load("https://www.google.com/");

browser.Load("data:,Hello%2C%20World!");// LoadHtml("

Hello world!

", "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.)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值