Skip to content

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

Merged
ko1 merged 1 commit into
ruby:masterfrom
ono-max:patch-77
Nov 15, 2022
Merged

Allow debugger to be attached from Inspector page in Chrome#772
ko1 merged 1 commit into
ruby:masterfrom
ono-max:patch-77

Conversation

@ono-max

@ono-maxono-max commented Oct 22, 2022

Copy link
Copy Markdown
Member

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-maxforce-pushed the patch-77 branch 3 times, most recently from fd75728 to 4e7c600CompareOctober 22, 2022 13:41
@ono-max
ono-max marked this pull request as draft October 22, 2022 13:48
@ono-max
ono-maxforce-pushed the patch-77 branch 19 times, most recently from 367dde6 to 4922b0cCompareOctober 23, 2022 05:52
@ono-max
ono-max marked this pull request as ready for review October 23, 2022 05:55
Comment threadlib/debug/server.rb Outdated
@ono-max
ono-maxforce-pushed the patch-77 branch 4 times, most recently from c9fbb7d to deb3208CompareOctober 24, 2022 11:45
Comment threadlib/debug/server.rb Outdated
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
Copy Markdown
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_resbody
raiseRetryConnection
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_resbody
raiseRetryConnection
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_launchg

Comment threadlib/debug/server.rb Outdated
require 'etc'
require_relative 'config'
require_relative 'version'
require 'securerandom'

@ko1ko1Oct 25, 2022

Copy link
Copy Markdown
Collaborator

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-maxforce-pushed the patch-77 branch 7 times, most recently from 053144c to 30586b7CompareOctober 30, 2022 04:13
@ono-max
ono-maxforce-pushed the patch-77 branch 2 times, most recently from 1f31fd5 to 9dba72bCompareNovember 6, 2022 14:02
@ono-max
ono-maxforce-pushed the patch-77 branch 2 times, most recently from 8ee6148 to de34cebCompareNovember 13, 2022 12:27
@ko1
ko1 merged commit 6a77070 into ruby:masterNov 15, 2022
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@ono-max@ko1