Search code examples
javascriptc++chromium-embedded

Sending information from Chromium Embedded (Javascript) to a containing C++ application


After checking out the Chromium Embedded Framework example I have a question. I need native interaction with the embedded part of my window. However, in the CEF example, all I saw was the c++ sending messages to the browser, not the other way around. I was wondering if there is any way to send a message from JavaScript from c++, like in the way of a function.

What I am looking for is something like this. I have a button in my webpage that when clicked. I would like to minimize the window. Is there any way to call some c++ from JavaScript in CEF?


Solution

  • Easiest way: 1. In main process (UI process) - you can create own custom scheme handler (it can be bounded to http protocol too, and distinct handlers by domain). 2. From JS side, you can use XMLHttpRequest to call you scheme handler. It is standard mechanism to IPC between JS<>Main process.

    Other way: Use V8 bindings, but in this case you will need make own IPC between renderer and main process. Or use built-in IPC, but note that it is sends messages only in async way.