Is it possible to use CEF3 (Chromium Embedded Framework) in a unity windows project?

Is it possible to use CEF3 (Chromimum Embedded Framework) to display a browser in unity for a windows standalone project?

I have been using unity since 2008, but my knowledge of plugins and native code is practically zero. Before I start I first I wanted to ask if it’s even feasible. There are examples of how to build CEF3 for simple C++ programs and I am going through the tutorials here https://bitbucket.org/chromiumembedded/cef/wiki/Tutorial There is also a project called cefsharp which is supposed to be a .net wrapper for CEF3.

I am confused as to whether this would be a managed or native plugin given the resources available.
I would greatly appreciate any help or advice or tutorials that could help me get started.

Well, looking at the cefsharp porject page, it says at the top it is a:

WPF and Win Forms are windows specific, and aren’t available in Unity.

With that said, there could be a way to integrate such a thing into Unity. If it’s supported by Win Forms, which uses DirectDraw to render bitmaps generated in software with its component controls, this means the cefsharp could be repurposed to draw to a Texture2D instead, and than display that somewhere.

But this is FAR from trivial.

Furthermore, with that said, cefsharp is just .Net bindings to the C++ program that is actually running. So really, I’d just forego that and bind to it directly with Mono instead of consuming the bloat of cefsharp. But it’s still not trivial.

I’m looking for something more feasible. What about working with something like this
https://wiki.qt.io/QtWebEngine
I’m currently using uwebkit in unity which was made with qtwebkit – qtwebengine is the upgrade, qtwebkit has problems with some websites.

Or maybe there is another solution that someone might know about?

What about Awesomium? I’ve used the C# (.Net) bindings before. I didn’t use the WinForms control provided, I created my own class that wraps the necessary things in their libraries (starting the thing, navigating, and getting the page back). All I used it for was for display, so what I did was not interactable. I rendered the pages to a bitmap. Just be aware of their licensing though as well.

Sure, qtwebengine would also work.

Again, you’ll have to integrate it into unity by directing it to draw in the scene somehow.

If you want it to be 3d, it’ll have to be drawn in some 3d manner… which really is drawn to a Texture2d and then applying that to some surface. 2D, you could hack it with simpler things… like drawing directly over unity.

Here’s the thing… these browser kits usually hook into the OS and the graphics API available. DirectDraw, Xlib, OpenGL, something that gives it the ability to draw to the screen.

Unity uses most often OpenGL and/or DirectX (depending platform). But you don’t really get direct access to it yourself accept for in the form of shaders, textures and meshes. Unity takes care of pushing everything through the graphics api and rendering to the scene.

Now… you could always draw on top of those renders. Just like how you can place a window for one application over the other and have it draw on top. And if you did this with out a border, you could overlay one of those engines over it. But getting it to be anything other than a rect is going to be complicated maths (if even possible depending the api). And it’ll be treated as ‘always on top’, since its technically on top of the game.

But if you want it to run INSIDE the scene as if it’s part of the unity scene itself… well, you have to inject it into it. And this isn’t trivial stuff.

That’s why things like ‘uwebkit’ exist. They took the time to write all the code needed to force what is being drawn by qtwebkit or its ilk into the render pass for your unity game.

If it were trivial to do such a thing… uwebkit wouldn’t really be able to get away with selling its product. Why pay 95 bucks a seat if I could just bang, zoom, inject cef or qtwebengine into unity with no feasible effort.

detlion1643: I downloaded Awesomium and it has major problems. It won’t run in the editor if you click play more than once, and the forum has posts where many people are asking about what is going on with the unity version and no one is answering. Also the build for chromium is older.

lordofduct: Thank you for the very clear explanation about how these would operate with the unity graphics engine. I just need the overlay. The important thing for my project is a fairly new working browser that can communicate back and forth with unity. Uwebkit is cheap compared to the 2900 and 3500 license fees of Awesomium and Coherent UI, but the sofware is provided “as-is” and is based on soon to be deprecated qtwebkit that has some problems on the websites I need to have working. I guess I’ll start looking into QT’s new qtwebengine unless anybody has another better idea. I have heard that QT has a lot of overhead.

What do you need this for specifically?

Maybe we can come up with a better solution…

I’m building an automated browser for a project. It has to be able to able to navigate to specific pages, press buttons, fill in forms, etc. It is similar to how a chrome extension works. I was using uwebkit but it has problems on certain types of web pages most likely because the browser itself is outdated.

Why were you doing this in unity?

Is this part of a video game or something?

What benefits does Unity give you?

Basically because I know unity very well, and I have projects that will need to run on different platforms ios, android, windows,mac,linux.

I merely ask, because if you’re not using any of the graphics api or the sort. You could always use Mono itself, which is also cross platform.

If you have some graphical game stuff. Like sprites and/or 3d models and physics and what not… sure, Unity would make sense.

But if it’s just a simple gui with a web browser in it… something more lightweight like Mono/.Net could easily perform just as well, if not better. You still get the power of C# and all that.

True. I can look into that as well. I think unity is about 40mb and webkit is about 60. I wonder what a mono implementation would be?

Looks like this would be a problem.
The Mono Webbrowser currently lacks support for window.external, the bridge that allows Javascript code embedded in the browser to communicate with the managed world using the ObjectForScripting.

Weah, but cefsharp would work in it.

Mono is what the whole scripting engine in Unity is built on.

I’d also like to know. I don’t like Awesomium bc it’s only x86. I need my application to be x64 based.

@dansav Were you ever able to get this working?

With regards to the original post, yes this is possible.
We have a browser working inside Unity using CEF, though we used CefGlue instead of CefSharp, which we think helped avoid some headaches.

It’s not especially simple, and it isn’t a one-size fits all solution, but yes it’s possible.

CefGlue: Bitbucket | Git solution for teams using Jira

@3agle I looked at that earlier, but wasn’t sure how to (compile) build it and use it inside Unity. Do you think you could tell me the steps to get that started in Unity?

Honestly it’s not a simple task, and there are many steps to get it working (and it doesn’t work completely within the editor, that we have found so far… Though we have a workaround for that).
Essentially though, you need to ensure you have matching versions of CEF and CefGlue, build the libraries in something like Visual Studio (MonoDevelop might work for this?), then implement those inside Unity.
Inside the CefGlue repo are some tests and examples, I very much recommend using those as a baseline to get started.

1 Like

I’m also looking for this solution. There’s a working example here, but I’ve had it crash on me a few times:
https://github.com/aleab/cef-unity-sample

What are the supported platforms. I tried to take the build for WebGl and it deosn’t work. Is there any solution to show web pages in unity.