Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow debugger to be attached from Inspector page in Chrome #772

Merged
merged 1 commit into from
Nov 15, 2022

Conversation

ono-max
Copy link
Member

@ono-max ono-max commented Oct 22, 2022

Description

Screen.Recording.2022-10-22.at.21.02.51.mov

When node.js users use Chrome DevTools debugging, they open chrome://inspect, then click the link on the page and start debugging it.

https://medium.com/@paul_irish/debugging-node-js-nightlies-with-chrome-devtools-7c4a1b95ae27

This PR supports this feature.

How to use it

  1. Execute debugger as a TCP/IP debuggee. 9229 is the default port on the Inspector page in chrome.
$ rdbg target.rb -O --port 9229
  1. Open chrome://inspect, then target will be shown up.

Screen Shot 2022-10-22 at 21 12 33

  1. Click "inspect" and the window will be opened!

@ono-max ono-max force-pushed the patch-77 branch 3 times, most recently from fd75728 to 4e7c600 Compare October 22, 2022 13:41
@ono-max ono-max marked this pull request as draft October 22, 2022 13:48
@ono-max ono-max force-pushed the patch-77 branch 19 times, most recently from 367dde6 to 4922b0c Compare October 23, 2022 05:52
@ono-max ono-max marked this pull request as ready for review October 23, 2022 05:55
lib/debug/server.rb Outdated Show resolved Hide resolved
@ono-max ono-max force-pushed the patch-77 branch 4 times, most recently from c9fbb7d to deb3208 Compare October 24, 2022 11:45
Comment on lines 164 to 169
when /^GET \/json\/version HTTP\/1.1/
require 'json'

@repl = false
body = {
Browser: "ruby/v#{RUBY_VERSION}",
'Protocol-Version': "1.1"
}
send_http_res body
raise RetryConnection

when /^GET \/json HTTP\/1.1/
require 'json'

@repl = false
addr = @local_addr.inspect_sockaddr
body = [{
description: "ruby instance",
devtoolsFrontendUrl: "devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=#{addr}/#{@uuid}",
id: @uuid,
title: $0,
type: "json",
url: "file://#{File.absolute_path($0)}",
webSocketDebuggerUrl: "ws://#{addr}/#{@uuid}"
}]
send_http_res body
raise RetryConnection

when /^GET \/#{@uuid} HTTP\/1.1/
require_relative 'server_cdp'

self.extend(UI_CDP)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
when /^GET \/json\/version HTTP\/1.1/
require 'json'
@repl = false
body = {
Browser: "ruby/v#{RUBY_VERSION}",
'Protocol-Version': "1.1"
}
send_http_res body
raise RetryConnection
when /^GET \/json HTTP\/1.1/
require 'json'
@repl = false
addr = @local_addr.inspect_sockaddr
body = [{
description: "ruby instance",
devtoolsFrontendUrl: "devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=#{addr}/#{@uuid}",
id: @uuid,
title: $0,
type: "json",
url: "file://#{File.absolute_path($0)}",
webSocketDebuggerUrl: "ws://#{addr}/#{@uuid}"
}]
send_http_res body
raise RetryConnection
when /^GET \/#{@uuid} HTTP\/1.1/
require_relative 'server_cdp'
self.extend(UI_CDP)
when /^GET \/json\/version HTTP\/1.1/, /^GET \/json HTTP\/1.1/, /^GET \/#{@uuid} HTTP\/1.1/
require_relative 'server_cdp'
self.extend(UI_CDP)
self.cdp_launch g

@@ -4,6 +4,7 @@
require 'etc'
require_relative 'config'
require_relative 'version'
require 'securerandom'
Copy link
Collaborator

@ko1 ko1 Oct 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

load only on CDP.

@ono-max ono-max force-pushed the patch-77 branch 7 times, most recently from 053144c to 30586b7 Compare October 30, 2022 04:13
@ono-max ono-max force-pushed the patch-77 branch 2 times, most recently from 1f31fd5 to 9dba72b Compare November 6, 2022 14:02
@ono-max ono-max force-pushed the patch-77 branch 2 times, most recently from 8ee6148 to de34ceb Compare November 13, 2022 12:27
@ko1 ko1 merged commit 6a77070 into ruby:master Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants