how to use OnConsoleMessage?

738 views
Skip to first unread message

Michal Tsadok

unread,
Mar 4, 2015, 10:19:20 AM3/4/15
to cefs...@googlegroups.com
I'm using CefSharp1

Can someone give an example how to implement a code that invoked when OnConsoleMessage happens

I see it's not a virtual function so I wonder how this is used...

Thanks,
Michal

Alex Maitland

unread,
Mar 4, 2015, 4:47:26 PM3/4/15
to cefs...@googlegroups.com
There should be an event named `ConsoleMessage` or at least there is in `CefSharp3`. Is there a reason your still using `CefSharp1`?

Michal Tsadok

unread,
Mar 6, 2015, 3:36:40 AM3/6/15
to cefs...@googlegroups.com
Alex - You Rock!!!

I've even found an example how to use it

As for CefSharp3, we've developed our application last year when CefSharp3 wasn't yet stable
Now we need to find time for making this change :D
Have you moved from CefSharp1 to CefSharp3?
Do you have any guidelines which can shorten my migration time?

Thanks for your help and quick response
Michal

Alex Maitland

unread,
Mar 8, 2015, 8:31:19 AM3/8/15
to cefs...@googlegroups.com
I've personally been running `CefSharp3` since it's first official release. Currently running `37.0.0`. Version `39.0.0` should be out in the next few weeks.

As for upgrading it's relatively easy. A few things have been renamed. I'd suggest checking out https://github.com/cefsharp/CefSharp.MinimalExample for a working example

The key upgrade points are
  • Renamed WebView to ChromiumWebBrowser
  • Renamed LoadCompleted to FrameLoadEnd
  • Renamed CEF to Cef

If you encounter any problems then have a look at some of the previous issues https://github.com/cefsharp/CefSharp/issues?q=label%3Acef1-cef3-upgrade+is%3Aclosed

Then there's also the `FAQ`, which answers a lot of general questions https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions

I'd encourage the upgrade as there is nobody actively developing `CefSharp1`

Michal Tsadok

unread,
Mar 10, 2015, 7:52:40 AM3/10/15
to cefs...@googlegroups.com
Hi Alex,

Thanks to your guidance, I've tried to upgrade my code. 

Here are more upgrade points (mark in Red are open issues that I would appreciate that you would address)
  • F12 - Open DevToolbar
    • Didn't see how to make this happen on the CefSharp.MinimalExample
  • Renamed CefSharp.Settings to CefSettings
    • What is CefSharp3 equivalence to:
      • setting.AddPluginPath (for supporting flash no matter if it's installed or not on the machine)
      • setting.AutoDetectProxySettings
  • Change BrowserSettings initialization
webView = new WebView(url, browserSettings);
to this 
webView = new ChromiumWebBrowser(url); 
webView.BrowserSettings = browserSettings;
  • Rename ExecuteScript to ExecuteScriptAsync
  • No more webView.PropertyChanged
    • This could be changed to IsBrowserInitializedChanged / IsLoadingChanged / ?
  • We also control window.open through OnBeforePopup and open the window ourselves to provide an ability to open DevToolbar
    • I've changed childView.Address = url; to childView.Load(url); but didn't test it yet

Alex Maitland

unread,
Mar 10, 2015, 8:18:24 AM3/10/15
to cefs...@googlegroups.com

There's methods for open/close dev tools now.
https://github.com/cefsharp/CefSharp/blob/master/CefSharp/IWebBrowser.cs#L303

There's a method called CefAddWebPluginPath which has yet to be implemented
http://magpcss.org/ceforum/apidocs3/projects/%28default%29/%28_globals%29.html#CefAddWebPluginPath%28constCefString&%29

For proxy all things proxy related you pass command line args, see https://code.google.com/p/chromiumembedded/wiki/GeneralUsage#Proxy_Resolution for the complete list.
Example of how to set CommandLineArgs https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Example/CefExample.cs#L30

Michal Tsadok

unread,
Mar 10, 2015, 8:30:44 AM3/10/15
to cefs...@googlegroups.com
Thanks for the quick response

I managed to open the DevToolbar - so nice to have an up-to-date DevTool (compared to CefSharp1 :D)

Do you know when CefAddWebPluginPath implementation is scheduled?

As for the proxy, we just want to use whatever was set on the machine - like Chrome/IE do
So, is it set by default to do this or should I set this
--proxy-auto-detect

Your tips are great!!
I hope more people would enjoy them

Michal

Alex Maitland

unread,
Mar 10, 2015, 9:11:17 AM3/10/15
to cefs...@googlegroups.com
Do you know when CefAddWebPluginPath implementation is scheduled?

I've quickly added that method and two others that will be required. Haven't tested them yet, so feedback is appreciated.
You can use the latest `nuget` CI builds to try it out the changes see https://github.com/cefsharp/CefSharp#nuget-packages for more information.
The changes will be in `39.0.0-CI761` and greater.

https://github.com/cefsharp/CefSharp/commit/545c63aaccfbbc477325edc6442c8582b5afd1b8
https://ci.appveyor.com/project/cefsharp/cefsharp/build/39.0.0-CI761

I'm not familiar with proxy detection personally, so it maybe trial and error. Report back if you find out anything interesting, I imagine you basically set and forget.

I've created https://github.com/cefsharp/CefSharp/wiki/Upgrading-from-CefSharp-1 (Which anyone with a github account can edit). If you think of anything else feel free to edit that wiki entry.

Michal Tsadok

unread,
Mar 15, 2015, 5:57:50 PM3/15/15
to cefs...@googlegroups.com
Hi Alex,

It's me again :D
Thanks again for being VERY responsive and sending me awesome and relevant links!!

Few more questions 

  1. CefSharp3 and Proxy - what does proxy-auto-detect do? when I set this command line flag it doesn't relate to the proxy I've set proxy through the red arrow in the screen shot. does this flag relate to the green arrow in the screen shot :-s ?


  1. CefSharp and Fiddler
CefSharp3 MinimalExample - on Fiddler I couldn't see the ChromiumWebBrowser request - why is that?
If I request the same url through c# - I see it in Fiddler with Process=cefsharp.minimalexample.winforms:4928
what is the process that is running this request and is there a way to see this in Fiddler?
 
In CefSharp1 - I do see in Fiddler the request directly from WebView or from c# 

 
Thanks again for your time
Michal

Alex Maitland

unread,
Mar 16, 2015, 4:08:25 AM3/16/15
to cefs...@googlegroups.com

I've not really played around with the proxy side of things so can't provide you with any definitive answers unfortunately. My understanding is that `Cef` supports the same proxy options as `Chromium`.
The `Chromium` doc is available at http://www.chromium.org/developers/design-documents/network-settings

If that doesn't prove useful then perhaps ask your question on the `Cef Forum`? http://magpcss.org/ceforum/

As for the network traffic requests, `Cef3` and hence `CefSharp3` now supports a multi-process model, so all requests will be made by `CefSharp.BrowserSubprocess.exe`. I'm not familiar with `Fiddler`, so can't provide a specific answer, though I'd imagine it should be able to show the requests being made by the `BrowserSubprocess`.

Background information
https://code.google.com/p/chromiumembedded/wiki/Architecture#CEF3

It's also important to note that `CefSharp` is just a wrapper around the `Chromium Embedded Framework (CEF)`, so if you can't find anything relevant when searching in the context of `CefSharp`, then try searching for `Cef` instead.

Hope that helps.
Alex

Alex Maitland

unread,
Mar 16, 2015, 5:33:57 AM3/16/15
to cefs...@googlegroups.com
Just as an FYI if you open chrome://version/ a `ChromiumWebBrowser` instance, you can see the command line args that were passed to the sub process, handy for double checking that they were passed through correctly.

Michal Tsadok

unread,
Apr 28, 2015, 11:09:36 AM4/28/15
to cefs...@googlegroups.com
Hi Alex,

Long time...
Few updates and questions
  • Upgrades issues
    Apparently switching to CefSharp3 was very gentle process.. 
    I've used simple CefSharp1 solution (taken from https://github.com/artema/WebViewBenchmark)
    To make it work, these are the steps I've done [feel free to update
    Upgrading from CefSharp1 wiki
    • Attention: Replacing references worked for me only on VS2013 (on VS2012, I couldn't make the NuGet packages to be referenced automatically)
    • Remove CefSharp1 References (CefSharp, CefSharp.WinForms)
    • Delete all libs / locales of CefSharp1
    • Close Visual Studio completely and then reopen
    • Install CefSharp3 through Nuget (I just installed CefSharp.WinForms - it installs all required libraries as well)
    • Close Visual Studio completely and then reopen
    • Specify platform (x86 / x64)
    • Change class names according to Upgrading from CefSharp1 wiki
      Add the following to the wiki page
      • Change RequestHandler
        remove RequestHandle and DownloadHandler class implementations
        add DownloadHandler
        change
        webView.RequestHandler = new RequestHandler();
        to
        webView.DownloadHandler = new DownloadHandler();
      • ILifeSpanHandler.OnBeforePopup has different parameters so Implement Interface of ILifeSpanHandler and remove the old function signature
  • Although it runs on Windows 7, I still can't switch to CefSharp3 because of the following issues:
    • On a machine without Flash player installed, I'm getting Couldn't load plug-in. after adding the following code 
      [I took CefSharp3 from NuGet on April 27th 2015]
                  Cef.AddWebPluginPath(Path.Combine(Directory.GetCurrentDirectory(), "NPSWF32_13_0_0_214.dll")); // Flash 13.0.0.214
                  Cef.AddWebPluginPath(Path.Combine(Directory.GetCurrentDirectory(), "np-mswmp(1_0_0_8).dll")); // Windows Media Player 1.0.0.8
                  Cef.RefreshWebPlugins();

      This code worked on CefSharp1
                  var settings = new CefSharp.Settings();
                  settings.AddPluginPath(@"./NPSWF32_13_0_0_214.dll"); // Flash 13.0.0.214
                  settings.AddPluginPath(@"./np-mswmp(1_0_0_8).dll"); // Windows Media Player 1.0.0.8
                  CEF.Initialize(settings);
    • Windows XP - I'm quite new in .Net - I couldn't understand how to make it work 
      Acoording to this post 37+ Crash on XP 
      On VS2013/Win7, I changed the Platform Toolset as mentioned, built CefSharp.WinForms.Example and copied the Release Folder to XP
      I couldn't run any of the exe files - Example exe mentioned it's not Win32 one, CefSharp.BrowserSubprocess.exe gave another error
      Please help... :-s
      • Do you plan to have these FAQ/guidelines steps as part of your release..?
        I understand I'm not the only one that struggle with it and the fact that CefSharp1 was supporting these OS, make us, the CefSharp1 users, to not switching to CefSharp3
  • Less urgent issue
    • Small issue when click on doc file link from Flash
      The Save As window appears, but a blank open window is left open [this is opposed to click on doc file link on a webpage]
  • As for proxy settings
    Apparently the solution we had doesn't relate to CefSharp at all
    Set this in the App.config [how-should-i-set-the-default-proxy-to-use-default-credentials
    and the default credentials will be used
      <system.net>
        <defaultProxy useDefaultCredentials="true" />
      </system.net>
Hope my findings would help other!!
Thanks a lot for your support (and that you survived this post so far :) )

Michal

Alex Maitland

unread,
Apr 28, 2015, 5:27:36 PM4/28/15
to cefs...@googlegroups.com
Hi Michal,

Anyone with a GitHub account can edit the wiki, so feel free to make whatever changes you see fit.

Can you logically group your questions and ask in a new thread(s)? Easier to discuss a single question in it's own context, also easier for others to read in the future as they may prove useful.

Alex

Michal Tsadok

unread,
Apr 29, 2015, 4:13:41 AM4/29/15
to cefs...@googlegroups.com
will do - I also felt that I asked too much in one thread...
Reply all
Reply to author
Forward
0 new messages