Cefsharp3-WinForms x64 shows blank page but x86 works - winforms

I have issues with initializing CefSharp3. The control give a blank page after initializing.
I follow the instructions from CefSharp Wiki page (https://github.com/cefsharp/CefSharp/wiki/Quick-Start and http://ourcodeworld.com/articles/read/173/how-to-use-cefsharp-chromium-embedded-framework-csharp-in-a-winforms-application)
The problem is that when I build the application for x64 i get a blank page, but it works fine in x86.
The only code in my WinForms project is this:
public ChromiumWebBrowser chromeBrowser;
public void InitializeChromium()
{
CefSettings settings = new CefSettings();
// Initialize cef with the provided settings
Cef.Initialize(settings);
// Create a browser component
chromeBrowser = new ChromiumWebBrowser("http://ourcodeworld.com");
// Add it to the form and fill it to the form window.
this.Controls.Add(chromeBrowser);
chromeBrowser.Dock = DockStyle.Fill;
}
public Form1()
{
InitializeComponent();
// Start the browser after initialize global component
InitializeChromium();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Cef.Shutdown();
}
I also tried adding a panel, and initializing ChromiumBrowser in the panel with panel1.Controls.Add(chromeBrowser) instead of this.Controls.add(chromeBrowser), but the issue is still there.
I found this in the troubleshooting section at CefSharp wiki:
https://github.com/cefsharp/CefSharp/wiki/Trouble-Shooting
b) The developer tools. Add a button to your form and make a call to "browser.ShowDevTools()". If you can see a document has loaded and you have a DOM in there, then your problem is a display output one and your most likely problem is one of not setting 'Dock' correctly, or some other setting is causing the browser to render offscreen/headless. If you get a blank tool window, or no tool window at all, then CefSharp has failed to initialize correctly, so you have a set-up issue to troubleshoot.
This is exactly the symptoms that I experience.
I tried creating the same project on my laptop (MacBook Pro with Win7, VS2013 and .NET 4.5.2) and it worked like a charm. This means something is up with my workstation (win10, VS2015 .NET 4.5.3).
Any ideas?

This appears to be a bug in the latest build. The solution for now is to use the v51.0.0 build.
You can do this quite easily in the NuGet package manager in VS2015, or if your using VS2013, use the "--version 51.0.0" option when installing cefsharp from the package manager command line.
The issue for the problem is here:
https://github.com/cefsharp/CefSharp/issues/1870
Keep an eye on the issue for future solutions.
Update 28/11/2016
This is a bug in the current V53 release of CefSharp. It's been confirmed by the CefSharp team and is addressed in issue #1819 (https://github.com/cefsharp/CefSharp/issues/1819)
The bug has been apparently fixed, but will not be released until V55.
The solution for now, is to either go back to V51 or to build your own version from source for V55.

Related

Black screen appears when the CEF Winform Browser loads for the 1st time

I am using CEF Sharp - V86
I am getting this strange issue and our users have starting complaining about it.
When the cefsharp winform browser loads for the first time, it shows the black window for few mili-seconds and then it disappears.
If we reload or refresh the webpage, it does not happens.
We have recently upgraded from V79 to V86 and we did not had any issue in earlier version.
What i have tried so far is, tried setting below command line arguements but it didn't work.
settings.CefCommandLineArgs.Add("disable-gpu");
settings.CefCommandLineArgs.Add("disable-gpu-compositing");
I have also tried setting
Cef.EnableHighDPISupport()
But it didn't work.
Additional Info :
Checked with Latest Version - CefSharp V88
When we load CefSharp winform browser in wpf application using winform host, a black screen appears on load for the first time for few miliseconds and then disappears.
This was not happening in earlier version.(i checked with V79 till V83).
Steps to reproduce.
Create a sample wpf application ,use windowsformhost to load cefsharp winform browser.
In constructor of winform browser, use any url. I tested with www.google.com.
Run the application.
Notice the initial black screen appears for few miliseconds and then disappears.
Please note this happens only for the first time when the chrome winform load.
his seems to have broken from CEFSharp v84.
Any help will be appreciated. :)
I was able to get rid of the black flash. Once I removed it from the VS Form Designer, things got better. Define it as a form level object:
private ChromiumWebBrowser cwbPage;
Then in the form constructor, instantiate it and add it to a panel in the form:
cwbPage= new ChromiumWebBrowser("");
cwbPage.Dock = DockStyle.Fill;
this.pnlPanel.Controls.Add(cwbPage);
cwbPage.BringToFront();
//...add any event handlers
Finally, pass it the string of Html or navigate to the url:
cwbPage.LoadHtml("<html><body>This is a test.</body></html>");
//OR
cwbPage.LoadUrlAsync("https://www.google.com");
Notes:
It still takes about 3 seconds to load the content, but at least there is no black flash.
I experimented and tried going back to using the VS Form Designer, and the black flash came back. I stripped almost all of the properties away from it in the VS Form generated code, but it still flashed blackly. So it does not like using the Form Designer.

Cefsharp Chrominumwebbrowser not working in WPF

Hi I am new to cefsharp and tried using Cefsharp chromium web browser .
when ever i tried to call the webbrowser it throws an exception like below
Could not load file or assembly 'CefSharp.Wpf, PublicKeyToken=40c4b6fc221f4138' or one of its dependencies. The system cannot find the file specified.'
But i have added the reference cefsharp.wpf in project
What do i miss here ?
And if i tried from codebehinf too the same issue occurs.
I just had the below piece of code next to InnitializeComponent.
ChromiumWebBrowser browser = new ChromiumWebBrowser();
Manually i counldn't resolve the issue in my working solution.
As a work around what i did is as #amaitland suggested i cloned a copy of CefSharp Minimal Example from here and used the Minimal Example for WPF solution.
I just copied all the logic from my solution tand pasted it in the minimal expansion and updated it .
Now ChromiumWebBrowser works fine for me ( Only after using that Minimal example provided by cefsharp )..
In Application > Properties > Build
Change Check "Prefer 32-bits"

Debugging JavaScript in Chromium Embedded Framework

I have a WPF application which uses CEF to display web content. My question is, is there a way to debug the Javascript/Web parts inside a WPF application?
You may also use ShowDevTools() extension method (source)
ChromiumWebBrowser browser = new ChromiumWebBrowser();
browser.ShowDevTools(); // Opens Chrome Developer tools window
Enable remote debugging in your application:
C# (CefSharp)
CefSettings.RemoteDebuggingPort = 8088;
C++
CefSettings settings;
settings.remote_debugging_port = 8088;
then run your app and point your browser to http://localhost:8088/ to access the Chromium developer console (the same you have in Chrome with Ctrl+Shift+j)
While the accepted answer is correct, it doesn't really have enough detail.
I got this working in CefSharp using the WinForms control in a WPF application. (the WinForms control seems to have better performance). The code for remote debugging will probably be very similar for the WPF control though.
var settings = new CefSettings { RemoteDebuggingPort = 8088 };
Cef.Initialize(settings);
WindowsFormsHost.Child = new ChromiumWebBrowser(url);
Then go to http://localhost:8088/ in your browser.
To use 'ShowDevTools()' you will need first verify if the browser is initialized.
An example solution:
//Add an event to check
ChromeBrowser.IsBrowserInitializedChanged += ChromeBrowser_IsBrowserInitializedChanged;
//Declare the event method to be called
private void ChromeBrowser_IsBrowserInitializedChanged(object sender, IsBrowserInitializedChangedEventArgs e)
{
if (e.IsBrowserInitialized)
{
ChromeBrowser.ShowDevTools();
}
}
To open the Chromium Dev-Tools window you can do the following:
CefBrowser.GetBrowser().GetHost().ShowDevTools();
This is similar to Eido95's answer, but it doesn't require the extension methods, which essentially just wrap these method calls.
NOTE: The control needs to be initialized before calling this method can be called. If you're wiring-up and F12-like functionality this shouldn't be a problem. If you're trying to do this when the app is starting you will need to listen for the ChromiumWebBrowser.IsBrowserInitializedChanged event
An alternative can be to launch cef with --enable-chrome-runtime.
You'll have the fully featured debugger (link files on disk and edit them from the debugger)

Xilium.CefGlue in Winforms application not working properly with ogg

I'm trying to integrate the Xilium.CefGlue browser into an existing project, but i don't seem to get it working with ogg. I'm using the latest versions of the Xilium.CefGlue(xilium-xilium.cefglue-3caa551bd830) and the Cef binary (cef_binary_3.1384.1045). Everything works great when running the projects in the Xilium.CefGlue solution.
To make sure the problem is not caused by my other project, i started a new Winforms project, added references to Xilium.CefGlue.dll, Xilium.CefGlue.Demo.dll and Xilium.CefGlue.WindowsForms.dll. I use the same code in my Program.cs file as used in CefGlue.Client project in the examples, and in my form i create a new CefBrowser and add it directly to my controls. I also placed the needed ceflib files in the correct location.
Now, when running the application and loading a webpage, everything seems to hang unless i change the SingleProcess to true in the CefSettings in my Program.cs. However, when loading another page which contains html5 video (ogg), the page is not getting rendered. I do notice that the interaction is there, because i can start the video by clicking in the center of the page where a button should be located. I can hear the video playing, but the page simply stays blank.
Loading the same page in the CefGlue.Client does work like it should. Now, when i change the setting SingleProcess to true in the example project CefGlue.client, the same thing occurs, so i guess it must have something to do with this.
Anyone got any ideas on what is going wrong?
Thanks,
Andy
Found the answer somewhere else by Sébastien Frippiat:
it seems that using SingleProcess=false doesn't work when debugging with Visual Studio (should be related to Visual Studio using a executable called project_exe.vshost.exe instead of project_exe.exe).
So i changed my CefSettings to this:
var settings = new CefSettings
{
BrowserSubprocessPath = #"C:\CefGlueBrowser\CefGlueBrowser\bin\x86\Debug\CefGlueBrowser.exe",
SingleProcess = false,
MultiThreadedMessageLoop = true,
LogSeverity = CefLogSeverity.Default,
LogFile = "CefGlue.log",
};
That seems to fix it for debugging.
Just disable Visual Studio Hosting Process and you wont have problem for debugging
http://msdn.microsoft.com/en-us/library/ms185330(v=vs.80).aspx

Navigation xBap problem with frames

I have a problem in navigation in xBap
I created two pages (Page1 and Page2)
Page1 have one button for navigation to Page 2
<Button Height="23" Width="76" Name="button1" Click="button1_Click">Page2</Button>
private void button1_Click(object sender, RoutedEventArgs e)
{
NavigationService n = NavigationService.GetNavigationService(sender as Button);
n.Navigate(new Uri("Page2.xaml", UriKind.Relative));
}
in Page2 there is a frame without any source
<Frame Margin="0,90,0,0"/>
After running application, and navigating to page2, the navigation will work normally,
but when I press Go Back in browser, then press button1 again
The browser will show this message
image
Note: in some cases you need to repeat trying
Any help !!
thanks in advance
since your Browser crashes, i suggest this is some bug in one of the following Components:
Browser (IE in this Case)
XBAP Addon/Plugin (yes, there is some kind of plugin which is installed silently within browsers on .NET Framework installation)
I bet, this cannot be solved programmatically... I'd suggest the following:
try to reproduce in different environment (different IE Version, OS etc.)
reinstall .NET Framework and ensure you have the latest, stable final version
do same with Internet Explorer
Firefox has XBAP support as well - try in firefox
If it works in other environments, your users should have no problems with this setup.
Hope this helps,
Best regards
Thomas

Resources