rubyjs / therubyracer

Embed the V8 Javascript Interpreter into Ruby
1.66k stars 191 forks source link

Debugging from within Rails app? #327

Closed olance closed 9 years ago

olance commented 9 years ago

Sorry if this is covered somewhere, I really haven't found anything :\

The question is quite basic: is it possible to debug javascript code being executed within therubyracer/V8 in a Rails app?

I have seen the mention of SetFlagsFromString in #291 but from what I can tell, it's not available on V8::C anymore? Found it defined on the V8 class in the C files, but couldn't find any way to call it from my Ruby code.

Is it possible? If it is, would this then allow me to hook an external debugger on the port given in the flags and get a breakpoint on exceptions in my JS code? Bonus question: are you aware of any debugger tool that could connect to this remote debugging port?

Thanks!

ascot21 commented 9 years ago

Did you ever find a solution? I'm trying to do the same.

olance commented 9 years ago

hey @ascot21, sorry about the delay!

I finally did!

I'm using node-inspector and this initializer in my Rails project :

if ENV['EXECJS_DEBUG']
    ExecJS.runtime = ExecJS::ExternalRuntime.new(
        name: 'Node.js Debug (V8)',
        command:     ['node --debug-brk'],
        runner_path: ExecJS.root + '/support/node_runner.js',
        encoding:    'UTF-8'
    )
end

More details in the article I just published: https://medium.com/@olance/debugging-server-side-javascript-in-a-ruby-on-rails-app-e3fb467f6d41