I spent the past day or so hacking together a managed wrapper for Sirikata’s Berkelium library. Berkelium allows you to easily embed a WebKit-based browser into games and other applications. It’s based on Chrome and it’s really easy to get up and running in a C++ application. Unfortunately, if you’re using C# or VB.net, you’re out of luck – no way to link directly against a C++ .lib file in those languages. The addition of my managed wrapper – BerkeliumSharp – means that you can use the library in managed applications, and integrate it with Windows Forms, XNA, or even WPF.
I’ve released the source under the BSD license (just like Berkelium) and included two simple examples (one for Windows Forms, one for XNA). It’s not a Chrome competitor but it’s surprisingly easy to get a lot of complicated things working – you can watch Hulu videos if you have Flash installed, and Flash games like Dino Run work in the Windows Forms example since it implements keyboard input.
You can download pre-built demos to test it out, or grab the source code over at Google Code.
Have fun!
P.S. If you try out the examples, be aware that content that opens pop-up windows doesn’t seem to work. I think this is a bug in Berkelium.
Edit: Figured out how to build Chromium and Berkelium myself and fixed the bug. Open source is awesome!



#1 by benjoTLV on February 23, 2010 - 4:39 am
Quote
Hi, thanks for this. It seems very promising. I was using for now Chris Cavanagh WPF browser based on Awesomium/Chromium, but I experienced some performance issues related to the lack of multi-process capabilities so this one should actually solve my problems (and it is on BSD!!)
Still, after downloading your demo, I cannot run it… I get an unhandled exception when running BerkeliumSharp.exe (cannot load file or assembly BerkeliumSharp…) and I get a crash at start up when running BerkeliumXNATest.exe.
Any idea? anything I am doing wrong?
Thanks
#2 by Kael on February 23, 2010 - 4:41 am
Quote
Did you unzip all the files into a folder and run the test executables from there? If you don’t do that, it won’t be able to find all the assemblies and libraries.
The XNA test won’t run if you don’t have XNA Game Studio 3.1 installed, also.
I’ve updated the examples to fix some bugs so you might want to try downloading a fresh copy of the ZIP.
#3 by benjoTLV on February 23, 2010 - 5:04 am
Quote
Redownloading the package solved my problem!
Thanks
#4 by CMay on February 23, 2010 - 7:06 am
Quote
Was looking for a wrapper the other day with no luck and was just about to start work on my own when I ran into this. Posted just 2 days ago, good timing.
Your demo app works fine here, though it’s a bit sluggish at larger window sizes. Then again, it is just a demo, so slowing it down with system.drawing.graphics.drawimage is no big deal.
Thanks.
#5 by Charley on March 8, 2010 - 12:06 pm
Quote
Has anyone played with this in WPF yet? Making something like Chris Cavanagh’s chromium web browser? http://chriscavanagh.wordpress.com/2009/08/25/wpf-chromium-webbrowser-source-code/
I’ve just started playing with it, but I haven’t had any luck building this. It seems to want the entire chromium source code.
#6 by Kael on March 8, 2010 - 12:57 pm
Quote
building berkelium does require a chromium build, yes.
I recommend using the binaries from the demos zip to get started. The techniques used by the winforms demo should apply to wpf.
#7 by Charley on March 8, 2010 - 2:20 pm
Quote
Kael,
Thanks for the quick reply.
The binaries in the demos zip are older than the BerkeliumTest code from the trunk and out of date, right? I tried to just run BerkeliumTest in debug in the IDE linking to the compiled binaries, but there were a lot of unrecognized methods. (AdjustZoom for instance).
Any chance of updating the binaries so I can use them with the source code of BerkeliumTest?
#8 by Kael on March 8, 2010 - 9:03 pm
Quote
Sorry about that. I’ve updated the demos ZIP with current binaries, and I also fixed an issue with the XNA test’s source code.
#9 by CMay on April 6, 2010 - 9:46 am
Quote
I noticed you improved some of the painting/bitmap reallocation code and thought I’d mention that to take it one step further you could set ControlStyles.OptimizedDoubleBuffer (.net 2.0) on WebKitFrame for a fairly large improvement.
Also, I think it’s interesting that you’re bundling the mess of depended files inside the DLL for neatness, but I have a feeling it might be undesirable for a number of scenarios and especially when wider distribution comes into the picture. Maybe eventually it could be worth pushing it all into a subdirectory of the host application?
#10 by Kael on April 6, 2010 - 11:21 am
Quote
CMay: Thanks for the tip, I’ll try it out. I experimented before with using DIBsections or SetDIBits directly but couldn’t get it working – something to do with how GDI interacts with WoW64, I suspect. Hopefully the optimized double buffer flag will be a perf win (in my profiles, GDI+ DrawImage is the bottleneck).
As far as the dependencies go, you could definitely bundle them into a subdirectory instead. The reason I went for the embedded resource approach is that it behaves correctly in the presence of tools that copy your assemblies around, like Visual Studio. If the dependencies are stray files they don’t get copied, so for example WebKitFrame would then break the Visual Studio Forms Designer (by failing to load due to missing dependencies). This also removes the need to add all the dependencies into your solution file to get them copied to the output directory.
#11 by Tom on April 7, 2010 - 7:13 am
Quote
Thanks for releasing this – it looks like it might be just what I need! Has anyone managed to get this working in WPF yet? I’ve been playing around with the BerkeliumTest demo but haven’t had any luck trying to get it to work in WPF.
#12 by Steven Lee on May 5, 2010 - 11:32 pm
Quote
It is really a good project, but I met some problem
1. how to setup proxy
2. failed to login gmail and yahoo.
#13 by Kael on May 6, 2010 - 12:03 am
Quote
Since it’s using Chromium’s network stack, I expect it will obey Internet Explorer’s proxy configuration on Windows, since that’s Chrome’s default behavior.
#14 by Steven Lee on May 9, 2010 - 8:11 pm
Quote
Type your comment here
yes, I forgot the proxy setting problem, but I have another problem, I can login gmail and yahoo.