How to run a v8 shell standalone and inspect / debug with Chrome DevTools

1,070 views
Skip to first unread message

Joe Lewis

unread,
May 19, 2019, 2:49:32 AM5/19/19
to v8-users
I'm pretty sure that my understanding of the entire topic is fairly limited and this is not going to be easy. Here's what I'm looking for:

We're trying to re-use the product's javascript code across browser, server & devices. We've settled on running v8 with Java bindings  (J2v8) for the server and android devices.

While developing I'd like to setup a chrome devtools environment and test my JS code as if it's running on V8 directly. I understand I can spin up a chrome instance with --remore-debugging-port option and connect a devtools instance to that chrome for browser and for node --inspect does something similar. Is there an equivalent for a v8 shell?

Is there any way I can do something like

bash-$ ./d8 --remote-debugging-port=9222

and connect a chrome devtools instance to that shell?

Can somebody point me in the right direction?

joe lewis

unread,
May 19, 2019, 4:20:30 AM5/19/19
to v8-users
A bit more reading and I understood how dumb the question is. I'd like to validate if my current understanding is correct.

V8 is more than the shell binary that comes with the build. V8 provides extensive C++ APIs to compile Javascript source code from other programs (usually termed as embedding V8). 
So, to enable chrome devtools as debugging front-end I have to write a program (C++ wrapper or such) that communicates through web-sockets, debugging-protocol messages back and forth from the front-end to v8. Or did I get it completely twisted?

If it did make sense, is there a project that has already implemented such standalone program that statically links to V8 and exposes a remote-debugging session? If nothing like that exists I'd like to pursue that direction and publish a simple project that spins up a V8 instance and starts a chrome remote-debugging session.

Full-stack developer here, with almost no experience working with system software. Please let me know if I got it all completely wrong. 

Thanks,
Joe


--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/0bb21c0a-a1fa-4b70-8854-94f34061b4ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Noordhuis

unread,
May 19, 2019, 4:07:38 PM5/19/19
to v8-users
On Sun, May 19, 2019 at 10:20 AM joe lewis <lewis....@gmail.com> wrote:
>
> A bit more reading and I understood how dumb the question is. I'd like to validate if my current understanding is correct.
>
> V8 is more than the shell binary that comes with the build. V8 provides extensive C++ APIs to compile Javascript source code from other programs (usually termed as embedding V8).
> So, to enable chrome devtools as debugging front-end I have to write a program (C++ wrapper or such) that communicates through web-sockets, debugging-protocol messages back and forth from the front-end to v8. Or did I get it completely twisted?
>
> If it did make sense, is there a project that has already implemented such standalone program that statically links to V8 and exposes a remote-debugging session? If nothing like that exists I'd like to pursue that direction and publish a simple project that spins up a V8 instance and starts a chrome remote-debugging session.
>
> Full-stack developer here, with almost no experience working with system software. Please let me know if I got it all completely wrong.
>
> Thanks,
> Joe

I haven't used it myself but several people recently reported in [0]
that they had success with [1].

Your intuition about how DevTools integration works is on point, by the way. :-)

[0] https://groups.google.com/forum/#!topic/v8-users/QUHnlvab13E
[1] https://github.com/hsharsha/v8inspector

Gautham B A

unread,
May 20, 2019, 12:41:24 AM5/20/19
to v8-users
Checkout this project - https://github.com/hsharsha/v8inspector . It does exactly what you're looking for. We're using the same at Couchbase and it's working absolutely fine.

On Sunday, 19 May 2019 13:50:30 UTC+5:30, joe lewis wrote:
A bit more reading and I understood how dumb the question is. I'd like to validate if my current understanding is correct.

V8 is more than the shell binary that comes with the build. V8 provides extensive C++ APIs to compile Javascript source code from other programs (usually termed as embedding V8). 
So, to enable chrome devtools as debugging front-end I have to write a program (C++ wrapper or such) that communicates through web-sockets, debugging-protocol messages back and forth from the front-end to v8. Or did I get it completely twisted?

If it did make sense, is there a project that has already implemented such standalone program that statically links to V8 and exposes a remote-debugging session? If nothing like that exists I'd like to pursue that direction and publish a simple project that spins up a V8 instance and starts a chrome remote-debugging session.

Full-stack developer here, with almost no experience working with system software. Please let me know if I got it all completely wrong. 

Thanks,
Joe


On Sun, 19 May 2019 at 12:19, Joe Lewis <lewis...@gmail.com> wrote:
I'm pretty sure that my understanding of the entire topic is fairly limited and this is not going to be easy. Here's what I'm looking for:

We're trying to re-use the product's javascript code across browser, server & devices. We've settled on running v8 with Java bindings  (J2v8) for the server and android devices.

While developing I'd like to setup a chrome devtools environment and test my JS code as if it's running on V8 directly. I understand I can spin up a chrome instance with --remore-debugging-port option and connect a devtools instance to that chrome for browser and for node --inspect does something similar. Is there an equivalent for a v8 shell?

Is there any way I can do something like

bash-$ ./d8 --remote-debugging-port=9222

and connect a chrome devtools instance to that shell?

Can somebody point me in the right direction?

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-u...@googlegroups.com.

Joe Lewis

unread,
May 20, 2019, 9:55:08 AM5/20/19
to v8-users
Thanks a lot Gautham, Ben! Looks like exactly what I need. 

Being a complete C++/CMake newbie, I can't get the project to build to correctly though. 

Here's the error message I receive when I do cmake ..
 

CMake Error at FindV8.cmake:40 (MESSAGE):

  Can't build v8inspector without V8

Call Stack (most recent call first):

  CMakeLists.txt:15 (INCLUDE)



-- Configuring incomplete, errors occurred!

See also "/Users/joe-2744/v8/v8inspector/build/CMakeFiles/CMakeOutput.log".


I've cloned v8 source in a directory from which I build v8.
I've cloned https://github.com/hsharsha/v8inspector in a separate directory and I'm trying to execute cmake. 

Is there a way to tell FindV8.cmake, where to look for v8 header files and libs in my system?


Thanks,
Joe

Gautham B A

unread,
May 20, 2019, 10:06:00 AM5/20/19
to v8-users
It tries to look for libraries in /usr/local/lib and headers in /usr/local/include . So, just do a $ make install after building v8.

Joe Lewis

unread,
Sep 17, 2019, 3:03:22 AM9/17/19
to v8-users
Thanks, Gautham! 

I had trouble installing that specific version of V8 (5.9), for my platform(MacOS Mojave). I finally had to give up getting it to work. 

However, I took the hackier route and got things to work. Since NodeJS already supports Chrome DevTools integration, I forked NodeJS and tweaked it to run my JS in vanilla V8 environment. 

To folks coming from Google: here's the fork - https://github.com/joelewis/node
Build a node binary from that fork and use

$ /out/Debug/node --inspect --inspect-brk js_code.js

This will open Chrome DevTools and break on the source's first line (running in pure V8, with no NodeJS injections like require, module or exports)


Thanks
Joe

Stefan Wörthmüller

unread,
Nov 19, 2019, 7:14:30 AM11/19/19
to v8-users

Hello, i have a similar problem.
I embedded v8 in my c++ apllication and users can run small js scripts.
But this is a windows program. All ive seen so far does not work with windows.
Joe - will the approach you describe most likely work with windows?

Regards
Stefan

joe lewis

unread,
Nov 19, 2019, 7:30:34 AM11/19/19
to v8-users
Hello Stefan,

Of course, you could build a windows version of node from my fork. While I did get V8 to work with Chrome DevTools, I'm not sure if it's the best way to go about. 
You should also try Gautham's recommendation: https://github.com/hsharsha/v8inspector which seems to be a neater solution (Building V8 version required by that project was a nightmare on Mac though)

 
Cheers
Joe


Stefan Wörthmüller

unread,
Jan 7, 2020, 6:47:25 AM1/7/20
to v8-users

I finally got done a windows version of v8inspector that works well with my stand alone windows application with integrated v8.

I made a own fork including descriptions where to find/build the required 3rd party libraries (or where to find prebuilds). I also did a number of changes/additions:

In the meanwhile this has also been merged into the parent project:



Calvin Lui

unread,
Jan 8, 2020, 1:46:34 PM1/8/20
to v8-users
FWIW I found this example to be really helpful. Its more up to date than hsharsha's and only requires boost beast. https://github.com/ahmadov/v8_inspector_example

Stefan Wörthmüller

unread,
Jan 12, 2020, 11:52:30 AM1/12/20
to v8-users
Thank you much for this link! This is incredibly simple.

matias cohen

unread,
Aug 31, 2022, 9:45:54 AM8/31/22
to v8-users

Hi, I integrated v8 in my Android app. I am now trying to debug it with Chrome DevTools.
I can't understand what I need to develop to achieve it.
I also found https://github.com/ahmadov/v8_inspector_example and I am trying to implement something similar.
Can anyone help me? Thanks.

Dominic Cerisano

unread,
Aug 31, 2022, 11:16:54 AM8/31/22
to v8-u...@googlegroups.com
Inspect the V8 engine in a meaningful way requires very tight bindings. Not certain that a chromedev extension is sufficient.

You might try J2V8:


Dominic Cerisano

dcerisano@skype

NOTICE: Confidential message which may be privileged. Unauthorized use/disclosure prohibited. 
AVIS : Message confidentiel dont le contenu peut être privilégié. Utilisation/divulgation interdites sans permission. 


--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/788b5500-2d29-4571-9a19-14b8f9d253aan%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages