Search code examples
javascriptgoogle-chromecompilationv8

Can you compile JS code using V8 and feed that directly to Chrome?


I'm looking for a way to protect some javascript code from reading/modifying. I know many people consider that impossible, but still...

From what I see the Chrome's V8 engine does a number of optimizations when it sees JS code, probably compiles it (?) and then runs it.

So I'm wondering is it possible to use V8's C++ api to compile the JS code into machinecode/chromecode and then feed that directly into Chrome (I don't care about other browsers)? Supposedly it will not only be faster, but also non-humanly readable, something like ASM.

Is this possible?

WebAssembly is doing this thing so I don't understand why we can't do it with JS code. There's also EncloseJS and pkg that are doing a very similar thing.


Solution

  • What I ended up doing is moving some of the logic from JavaScript into C++ and compiling that into NodeJS native modules (that's possible for Electron apps).

    It works pretty good, it's very fast, the source is... as protected as it can get, but you may need to worry about cross-platform issues, also compiling/linking can be a bit of a pain, but other than that it's great.