LiquidCore icon indicating copy to clipboard operation
LiquidCore copied to clipboard

Is it possible to debug device's node environment like a Webview in Chrome Inspector?

Open ilyamuromets opened this issue 7 years ago • 11 comments

ilyamuromets avatar Jun 27 '17 15:06 ilyamuromets

I tried ConsoleSurface. It's cool but uncomfortable to debug. Is it possible to debug from PC?

ilyamuromets avatar Jun 27 '17 15:06 ilyamuromets

How to run device's node with --inspect --debug-brk ? https://medium.com/@paul_irish/debugging-node-js-nightlies-with-chrome-devtools-7c4a1b95ae27

ilyamuromets avatar Jun 27 '17 15:06 ilyamuromets

At the moment, the debugging functionality of node has been disabled. There was no particular reason for that other than I was trying to get the basic functionality up and running first. If you want to try to get this working:

  1. Look at NodeInstance.cpp -- I've commented out most of the inspector initialization; you would need to uncomment it and fix any dependencies
  2. Add your flags in common.cpp in method ContextGroup::init_v8()

If you can get it running, please submit a pull request. It would be great to get this in the build.

Edit: Incidentally, this has been on my mental to-do list for some time, but I never got around to it. I think it is very important. I recently started a new job so I have not been able to devote much time to this project lately. Hopefully I will stabilize in time and be back to working on it. In the meantime, I can try to answer any questions.

ericwlange avatar Jul 02 '17 07:07 ericwlange

I had tried to build project, but every time I get the error:

Error:Execution failed for task ':LiquidCoreAndroid:ndkBuild'.
> Process 'command '/home/<user>/android-sdk-linux/ndk-bundle/ndk-build'' finished with non-zero exit value 2

ilyamuromets avatar Jul 04 '17 08:07 ilyamuromets

Any more information than that? Is there a compiler error? Can you check the other windows? You can cd to the jni directory in a terminal and execute the ndk-build command directly. Any errors will show up in the terminal.

ericwlange avatar Jul 04 '17 09:07 ericwlange

Android NDK: android-9 is unsupported. Using minimum supported version android-14.    
[armeabi-v7a] Compile++ thumb: liquidcore <= NodeInstance.cpp
/home/ilyamuromets/android_projects/LiquidExample/LiquidCoreAndroid/jni/node/NodeInstance.cpp: In member function 'int NodeInstance::StartNodeInstance(void*)':
/home/ilyamuromets/android_projects/LiquidExample/LiquidCoreAndroid/jni/node/NodeInstance.cpp:450:49: error: 'StartDebug' was not declared in this scope
         StartDebug(env, path, debug_wait_connect);
                                                 ^
/home/ilyamuromets/android_projects/LiquidExample/LiquidCoreAndroid/jni/node/NodeInstance.cpp:466:24: error: 'EnableDebug' was not declared in this scope
         EnableDebug(env);
                        ^
make: *** [/home/ilyamuromets/android_projects/LiquidExample/LiquidCoreAndroid/obj/local/armeabi-v7a/objs/liquidcore/node/NodeInstance.o] Error 1

I had added #include "node.h" into NodeInstance.cpp and uncommented code.

ilyamuromets avatar Jul 04 '17 09:07 ilyamuromets

I couldn't build project, because I haven't enough knowledge about C++. Could you help me?

ilyamuromets avatar Jul 04 '17 13:07 ilyamuromets

Apologies again for my absence. I am probably several weeks away from being able to spend any quality time on this.

The issue you are having is the reason that I commented out the code in the first place.

For a little background, node is not designed to be run as discrete instances in a single application. In stock node, when you spawn a new process, you are literally creating a new process and running a brand new instance of node in that process. If you dig in the code for process.spawn(), you will see that it runs node on the command line in a forked process! It then uses sockets to communicate between the two of them. All of the startup code is in node.cc.

For my purposes, that didn't really work. Instead, I needed to be able to manage multiple processes inside the same app. To do this, I rewrote (aka cut-and-pasted mostly) node.cc into a class-based implementation, NodeInstance.cpp. My goal was to rewrite/copy as little as is absolutely necessary, so as to be able to keep up with node updates, and to minimize errors. So what you see in NodeInstance.cpp is exactly that. Where I can call back into the node library, I do so. Where I cannot, I copied the code from node.cc to NodeInstance.cpp and massaged it where required to allow for multiple instances.

So I basically copied all the startup code and then systematically copied subroutines (mostly static functions) into the project until it compiled correctly. As the inspector was not part of my MVP requirement, when I got compilation errors because of it, I decided to just disable it for now and deal with it later.

That's why you are getting the compilation errors when you uncomment the code.

So it is not going to be quite as easy as that. You would have to do what I was doing, which is figure out which functions are missing, copy them in, rinse, repeat. As you don't have practical working knowledge of C++, this is going to be difficult for you. Unless you want to stumble your way through it (which I encourage!), just leave this issue open and I will put it on my to-do list. But I have no timeframe to give.

ericwlange avatar Jul 16 '17 10:07 ericwlange

@ericwlange I saw the code has been changed, and I see the code for inspector init but I don't see anyway on how to enable it yet. Or is some documentation missing on this?

ackava avatar Mar 11 '20 09:03 ackava

@ackava This is not yet turned on. I had planned to get it into the 0.7.0 release but it fell off the priority list. The code is all there. It is just a matter of turning it on and testing. It will likely only work on Android, though. But I won't know for sure until I can get back to the feature.

ericwlange avatar Mar 13 '20 12:03 ericwlange

@ericwlange is any news with this feature? I need to find the way how to debug background.js, that running in LiquidCore. Maybe you can orient me, what files I should look to enable debugging features?

sergeykomlach avatar Jul 05 '20 08:07 sergeykomlach