Search Unity

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

Discussion in 'Scripting' started by dansav, Oct 14, 2015.

  1. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    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.
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    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.
     
  3. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    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?
     
  4. detlion1643

    detlion1643

    Joined:
    Jul 26, 2012
    Posts:
    13
    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.
     
  5. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    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.
     
  6. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    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.
     
  7. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    What do you need this for specifically?

    Maybe we can come up with a better solution...
     
  8. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    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.
     
  9. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    Why were you doing this in unity?

    Is this part of a video game or something?

    What benefits does Unity give you?
     
  10. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    Basically because I know unity very well, and I have projects that will need to run on different platforms ios, android, windows,mac,linux.
     
  11. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    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.
     
  12. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    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.
     
  13. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    Weah, but cefsharp would work in it.

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

    Hodgson_SDAS

    Joined:
    Apr 30, 2015
    Posts:
    123
    I'd also like to know. I don't like Awesomium bc it's only x86. I need my application to be x64 based.
     
  15. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    @dansav Were you ever able to get this working?
     
  16. 3agle

    3agle

    Joined:
    Jul 9, 2012
    Posts:
    508
    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: http://xilium.bitbucket.org/cefglue/
     
  17. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    @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?
     
  18. 3agle

    3agle

    Joined:
    Jul 9, 2012
    Posts:
    508
    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.
     
    tabulatouch likes this.
  19. deviant-dev

    deviant-dev

    Joined:
    Nov 18, 2017
    Posts:
    5
  20. Umresh

    Umresh

    Joined:
    Oct 14, 2013
    Posts:
    56
    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.
     
  21. thephox1982

    thephox1982

    Joined:
    Jan 21, 2022
    Posts:
    20
    No and there never will be it seems as this has been talked about for the past 8 years and the only solutions that do work on Windows are $75 and $130 USD respectively and therefor are out of the realm for Indie use IMO. Since there are only two options they are driven by greed knowing they can get the amount they demand.

    I been trying to get a windows forms based 2D only webbrowser working using unity-webforms but I can not get the namespace for System.Windows.Forms.Integration to work because unity-webforms overrides it and doesn't implement an adaption of it which is annoying.

    What is really sad is it is SUPPER simple in Three.js and BabylonJS to display web pages even on 3D objects with ZERO plugins.. yet a game engine the caliber of Unity can't even do a basic 2D GUI level web browser so that I can have news and announcements for my game. If it wasn't for the fact JavaScript was single threaded and locks up when loading a single texture without a way to use web workers for the image decoding process I wouldn't have ported over to Unity, because WebGL is just as powerful now as Unity and about to get even more powerful with the addition of WebGPU which allows much lower level direct access to the GPU.

    I am floored that in 2022 we can't have basic things like a webview inside of Unity since there are SOO many people seeking this, literally hundreds of forum posts and various projects which all either have no windows support, are dead projects or are expensive for a basic feature with plenty of use cases from being able to let people use a web based wiki for their games, HTML based support systems, news and announcements on login screen, etc. It's an EXTREMELY useful feature to have. What is more surprising is it isn't even available to people paying hundreds of dollars a month for the paid versions of Unity, honestly if I was a paying member and I came up to this issue and found out I had to pay MORE money to buy a plugin that may work now but may stop working in the future, I'd look at making my next games using some other engine, that is how upset this whole spending past week trying to get something to work has made me.