|
12 | 12 |
|
13 | 13 | module DEBUGGER__ |
14 | 14 | module UI_CDP |
15 | | - SHOW_PROTOCOL = ENV['RUBY_DEBUG_CDP_SHOW_PROTOCOL'] == '1' |
| 15 | + SHOW_PROTOCOL = true |
16 | 16 |
|
17 | 17 | class UnsupportedError < StandardError; end |
18 | 18 | class NotFoundChromeEndpointError < StandardError; end |
@@ -558,35 +558,31 @@ def process |
558 | 558 | when 'Debugger.setBreakpointByUrl' |
559 | 559 | line = req.dig('params', 'lineNumber') |
560 | 560 | if regexp = req.dig('params', 'urlRegex') |
561 | | - path = regexp.match(/(.*)\|/)[1].gsub("\\", "") |
562 | | - cond = req.dig('params', 'condition') |
563 | | - src = get_source_code path |
564 | | - end_line = src.lines.count |
565 | | - line = end_line if line > end_line |
566 | 561 | b_id = "1:#{line}:#{regexp}" |
567 | | - if cond != '' |
568 | | - SESSION.add_line_breakpoint(path, line + 1, cond: cond) |
569 | | - else |
570 | | - SESSION.add_line_breakpoint(path, line + 1) |
571 | | - end |
572 | 562 | bps[b_id] = bps.size |
573 | | - # Because we need to return scriptId, responses are returned in SESSION thread. |
574 | | - req['params']['scriptId'] = path |
575 | | - req['params']['lineNumber'] = line |
576 | | - req['params']['breakpointId'] = b_id |
577 | | - @q_msg << req |
| 563 | + path = regexp.match(/(.*)\|/)[1].gsub("\\", "") |
| 564 | + add_line_breakpoint(req, b_id, path) |
578 | 565 | elsif url = req.dig('params', 'url') |
579 | 566 | b_id = "#{line}:#{url}" |
580 | | - send_response req, |
581 | | - breakpointId: b_id, |
582 | | - locations: [] |
583 | | - elsif hash = req.dig('params', 'scriptHash') |
584 | | - b_id = "#{line}:#{hash}" |
585 | | - send_response req, |
586 | | - breakpointId: b_id, |
587 | | - locations: [] |
| 567 | + # When breakpoints are set in Script snippet, non-existent path such as "snippet:///Script%20snippet%20%231" sent. |
| 568 | + # That's why we need to check it here. |
| 569 | + if File.exist? url |
| 570 | + bps[b_id] = bps.size |
| 571 | + add_line_breakpoint(req, b_id, url) |
| 572 | + else |
| 573 | + send_response req, |
| 574 | + breakpointId: b_id, |
| 575 | + locations: [] |
| 576 | + end |
588 | 577 | else |
589 | | - raise 'Unsupported' |
| 578 | + if hash = req.dig('params', 'scriptHash') |
| 579 | + b_id = "#{line}:#{hash}" |
| 580 | + send_response req, |
| 581 | + breakpointId: b_id, |
| 582 | + locations: [] |
| 583 | + else |
| 584 | + raise 'Unsupported' |
| 585 | + end |
590 | 586 | end |
591 | 587 | when 'Debugger.removeBreakpoint' |
592 | 588 | b_id = req.dig('params', 'breakpointId') |
@@ -625,6 +621,24 @@ def process |
625 | 621 | @q_msg << 'continue' |
626 | 622 | end |
627 | 623 |
|
| 624 | + def add_line_breakpoint req, b_id, path |
| 625 | + cond = req.dig('params', 'condition') |
| 626 | + line = req.dig('params', 'lineNumber') |
| 627 | + src = get_source_code path |
| 628 | + end_line = src.lines.count |
| 629 | + line = end_line if line > end_line |
| 630 | + if cond != '' |
| 631 | + SESSION.add_line_breakpoint(path, line + 1, cond: cond) |
| 632 | + else |
| 633 | + SESSION.add_line_breakpoint(path, line + 1) |
| 634 | + end |
| 635 | + # Because we need to return scriptId, responses are returned in SESSION thread. |
| 636 | + req['params']['scriptId'] = path |
| 637 | + req['params']['lineNumber'] = line |
| 638 | + req['params']['breakpointId'] = b_id |
| 639 | + @q_msg << req |
| 640 | + end |
| 641 | + |
628 | 642 | def del_bp bps, k |
629 | 643 | return bps unless idx = bps[k] |
630 | 644 |
|
|
0 commit comments