13

Is there any browser I could embedd in C++ application on Windows?

I need all features typical browser has (HTTP client, cookies support, DOM style HTML parser, JavaScript engine) except rendering. Because I don't need rendering capability (and that's rather big part of a browser) I would prefer a browser with non monolithic design so I wouldn't have to include rendering stuff into my project.

It would be nice if it had C++ rather than C API.

I need this embedded browser mainly because I have much trouble finding C++ HTML parser which could handle broken HTML like browsers do.
If you know any, please answer Library Recommendation: C++ HTML Parser SO question or at least vote on it to increase a chance someone will give a good answer.

Community
  • 1
  • 1
Piotr Dobrogost
  • 41,292
  • 40
  • 236
  • 366

8 Answers8

7

Sounds like all you need is something like libcurl which is an HTTP library and will let you do GET/POST/etc.

When I think browser I generally think rendering/JavaScript and not HTTP library.

Edit

In that case I'd look at WebKit (which I think has a C++ API) and hope you don't have to pull too much in.

Edit Again

On second thought (since rendering is such a big part of what browsers do), you might be better off using a stand-alone JS engine like SpiderMonkey and a stand-alone XML parser like Xerces-C (plus maybe tidy to make your HTML into XML).

Aaron Maenpaa
  • 119,832
  • 11
  • 95
  • 108
  • 1
    I'm already using it. I need JavaScript engine and html parser and libcurl doesn't have these things. – Piotr Dobrogost May 07 '09 at 15:12
  • 4
    It would have been sensible to list those requirements in the question. –  May 07 '09 at 15:14
  • @Neil: It was easier to say what I don't need since that's only one thing and all other features I need :) – Piotr Dobrogost May 07 '09 at 16:49
  • 2
    @Piotr ... yes and no. It's kind of obvious that we were confused about what you want ;) – Aaron Maenpaa May 07 '09 at 17:16
  • @Aaron: I was looking at Tidy but the first thing I check when I look for a library is how active the project is. The last entry in News section of Tidy project is one year old... I was also amazed there isn't any component based on Xerces-C which would handle HTML. There is such - called NekoHTML - but it's only for Xerces-Java. It's very sad there's no good, stand-alone HTML parser for such a popular language as C++... – Piotr Dobrogost May 08 '09 at 15:29
6

You might also want to check out Awesomium-- it's free for non-commercial use and has all of the features you're looking for (if you don't need rendering, simply don't use it).

Adam
  • 131
  • 1
  • 3
  • Old question I know, but I was looking for the exact same thing as the OP. You answer helped me a lot. Thank you! – William Apr 02 '12 at 05:10
6

I'm a bit confused by your question regarding embedding a web browser for which you don't need rendering capabilities. A web browser is rendering web pages by definition, unless you just need HTTP and XML with JavaScript capabilities which is a subset of a browser functionalities?

If you need a web browser to embed in your C++ application, I would suggest to consider Qt that comes with the WebKit plugin. It is C++, LGPL and has a very nice IDE (Qt Creator). I tried Qt with Qt Creator on unix (Ubuntu) and it was very impressive. The debugger is a bit light but it is just the first version. The adapter of Qt into visual c++ 2008 is now free.

chmike
  • 20,922
  • 21
  • 83
  • 106
  • 1
    Yep, I need HTTP, cookies, HTML (not XML!) parser and JavaScript. I added all these to the question to make it even more clear :) – Piotr Dobrogost May 07 '09 at 17:19
  • I would then suggest to use webkit because it is quite efficient, especially the JavaScript interpretor. Just use the functionalities you are interested in. – chmike May 08 '09 at 06:52
5

There is a project called CEF = The Chromium Embedded Framework - it is:

a simple framework for embedding Chromium-based browsers in other applications. It is a BSD-licensed open source project founded by Marshall Greenblatt in 2008 and based on the Google Chromium project. Unlike the Chromium project itself, which focuses mainly on Google Chrome application development, CEF focuses on facilitating embedded browser use cases in third-party applications.

and yes:

The base CEF framework includes support for the C and C++ programming languages.

jave.web
  • 13,880
  • 12
  • 91
  • 125
3

Including javascript support and html parsing makes this non-trivial task - you have to use one of the available browsers.

  • IE is usable through its COM model - you can create instance of it in your window be it invisible or not and call its javascript/html capabilities.

It has been designed to be used like that since the beginning and certainly it is working fine.

The other options are:

  • Gecko/Mozilla - a couple of years ago it wasn't usable like this, currently I think it is.

  • WebKit/V8 - no public API has been released for chrome yet, you could use webkit itself, but it doesn't have javascript engine. Another option is to take a look at the Chrome codebase and see if you could get out of it what you need.

I would probably go for IE, since it is maybe the easiest option and I have already used it. The other options seem to me more like building a browser instead of just using it.

devdimi
  • 2,432
  • 19
  • 18
2

How about Gecko ? You may not need the entire engine but you may find some its components useful like SpiderMonkey which is a JavaScript engine written in C.

green_t
  • 2,997
  • 3
  • 21
  • 18
2

I'd recommend picking up Qt for C++ programming. It has a built-in library that embeds Webkit with all the bells'n'whistles, and Qt is a great C++ library in general.

Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
0

Old question, I know, but take a look on http://msdn.microsoft.com/en-us/library/ky29ffxd%28v=vs.94%29.aspx

IActiveScript and family COM interfaces allows script execution (not only JS, any language that registers as script interpeter, for that matter) in-memory.