Node-CEF (NC.js) - Binding Node.js to your CEF projects

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

Node-CEF (NC.js) - Binding Node.js to your CEF projects

Postby gpbeta » Thu Jun 23, 2016 3:24 am

Hello CEF developers,
Today I would like to share my Node-CEF project to whom looking for a Node.js binding to theirs' CEF projects here.
I don't known whether it is suitable to post it in this forum, because Node-CEF is neither an app nor a mod of CEF but an extension library for the CEF.

It is a re-implementation of Node.js using the stable CEF dll-wrapper API, therefore Node-CEF should be compatible with most CEF3 builds without modifying the V8 engine or compiling a custom libcef.dll. Node-CEF is designed to work with general web pages, and it won't crash your render process like other Node.js-CEF glued projects do when any uncaught errors occur.


You can bind Node.js into your CEF project with just a little bit changes to your render process handler:
Code: Select all
#include <ncjs/RenderProcessHandler.h>

class MyNodeCefApp : public CefApp, public ncjs::RenderProcessHandler {
public:

    CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() { return this; }

    IMPLEMENT_REFCOUNTING(MyNodeCefApp);
};

What you need to do is just changing the inheritance from CefRenderProcessHandler to ncjs::RenderProcessHandler for your CefApp based class.

Here's the repo and docs hosted on GitHub: https://github.com/GPBeta/nc.js
Looking forward to your feedback and pull requests :)
Last edited by gpbeta on Sun Jul 10, 2016 1:07 pm, edited 3 times in total.
Joshua GPBeta
gpbeta
Newbie
 
Posts: 7
Joined: Thu Jun 23, 2016 2:47 am
Location: China

Re: Node-CEF (NC.js) - Binding Node.js for your CEF projects

Postby magreenblatt » Thu Jun 23, 2016 9:09 am

This looks like a very cool project. Do you have any plans to support platforms other than Windows? Is it much work when updating to newer Node.js versions?
magreenblatt
Site Admin
 
Posts: 10748
Joined: Fri May 29, 2009 6:57 pm

Re: Node-CEF (NC.js) - Binding Node.js for your CEF projects

Postby gpbeta » Thu Jun 23, 2016 1:43 pm

Thank you magreenblatt :)
At the beginning, I just want to make a module loading system like Node.js, but after some learning of JavaScript, I found that it is possible to run the Node.js natives modules in the CEF environment, then, the Node-CEF project is born.
I also found some deprecated Node.js-CEF glued projects before, they're not very friendly to the developers because users have to compile the specified and modified version of the Node.js as well as the huge CEF core, and codes managements become difficult when updating either Node.js or CEF.

magreenblatt wrote:Do you have any plans to support platforms other than Windows?

Yes, since Node-CEF is not using any system relative APIs, and it uses libuv just like Node.js does, I believe Node-CEF could be ported to any CEF supported platforms easily. However, I don't have too much experiences with Linux and automatic building system, and I'm not sure whether there're someone, except me, looking for a Node.js bindings for their CEF projects, I think it would be better to add supports for other systems after completing the rest Node.js binding modules.

magreenblatt wrote:Is it much work when updating to newer Node.js versions?

Yes, and no.
When binding a new version Node.js, we have to:
1.Diff the C++ code with previous version of Node.js and modify the binding implementations(libcef-node) if needed.
2.Copy the new core module files from Node.js, and recovery the changes we did on these files.
The main idea of Node-CEF is to trick the Node.js-compatible modules that they're running on Node.js, and to reuse the JS codes of core modules as many as possible from Node.js.
So the more V8 features CEF supports, the less changes we have to make for the core modules, the easier we update to a Node.js version :D
Joshua GPBeta
gpbeta
Newbie
 
Posts: 7
Joined: Thu Jun 23, 2016 2:47 am
Location: China

Re: Node-CEF (NC.js) - Binding Node.js for your CEF projects

Postby magreenblatt » Thu Jun 23, 2016 2:17 pm

gpbeta wrote:So the more V8 features CEF supports, the less changes we have to make for the core modules, the easier we update to a Node.js version :D

I notice that your page lists ArrayBuffer and Uint8Array as missing. Are there any other missing V8 features that would help you?
magreenblatt
Site Admin
 
Posts: 10748
Joined: Fri May 29, 2009 6:57 pm

Re: Node-CEF (NC.js) - Binding Node.js for your CEF projects

Postby gpbeta » Fri Jun 24, 2016 2:47 am

magreenblatt wrote:Are there any other missing V8 features that would help you?

Yes, and there is also a useful 'ArrayBuffer::Allocator' V8 feature which we can share memory directly between C++ and JavaScript lands.
Here's a list of missing V8 features from CEF that Node-CEF needs, currently:
  • v8::ArrayBuffer
    • Allocator
  • v8::TypeArray
    • Uint8Array
  • v8::String
    • NewFromOneByte()
    • WriteOneByte()
  • v8::Value
    • IsArrayBuffer()
    • IsDataView()
    • IsDate()
    • IsMap()
    • IsMapIterator()
    • IsPromIse()
    • IsRegExp()
    • IsSet()
    • IsSetIterator()
  • v8::PromiseRejectCallback
  • throw exceptions (async/out of native code callback)
Joshua GPBeta
gpbeta
Newbie
 
Posts: 7
Joined: Thu Jun 23, 2016 2:47 am
Location: China

Re: Node-CEF (NC.js) - Binding Node.js to your CEF projects

Postby hlevring » Mon Sep 12, 2016 5:55 am

This project is absolutely awesome. We got some request from our web team to support node. We have too much investment in CEF to consider other projects, so this seems like sent from above. Will look more into it
hlevring
Newbie
 
Posts: 3
Joined: Fri May 31, 2013 10:02 am


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 3 guests