Xilium CefGlue Async Javascript for inline C # with parameters and return values?

I recently experimented with CEFGlue in C #, especially from JS> Native integration.

I've tried 3 approaches but none of them work.

  • Via XHR and Custom SchemeHandler - generally great, but seems to block both rendering and the browser for long-running tasks.
  • Via V8 callbacks - awesome but long rendering blocks running tasks
  • Via cefQuery aka Asynchronous Bindings - does not block render or browser, but doesn't seem to support passing any parameters.

I have a trivial requirement.

  • Asynchronous execution, that is, neither the browser nor the rendering should block on long running tasks.
  • I need to pass parameters and return values ​​of a process to Javascript.

Is there a CEFGlue feature that I can experiment with that will allow me to accomplish this task?

Thank.

+3


source to share


2 answers


I have posted an answer to my question on the Google CEF group. The solution works well enough.



CEF Google Group

+4


source


The solution for this is to reuse the AJAX plumbing built into Chromium Embedded.

CEF is built from Chrome, so everything is geared towards the client application communicating with the server. If you structure your web code that interacts with your C # code to look like this, then you can reuse a lot of web development best practices.

It is possible to implement an embedded web server and use to handle both page requests and AJAX requests, which can make it easier to communicate with your C # code.

I have implemented this for a project at work that we are opening. Github



How it works is pretty simple:

  • Create an HTTP server that runs in memory. We use OWIN for this.
  • Create an implementation of IRequestHandler that intercepts any requests to your known domain and serves from the internal web server instead. See Ours here

Using OWIN allows you to lay on top of many frameworks and libraries that make it easy to build your application. Things like Web API make it trivial for a CEF-hosted application to communicate asynchronously with your C # code via JSON. We don't use this in a minute and don't use JavaScript bindings, but it's better to use AJAX for WebAPI.

+1


source







All Articles