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

CDP: Refactor the logic in setup method #864

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions lib/debug/server_cdp.rb
Original file line number Diff line number Diff line change
@@ -34,25 +34,26 @@ def setup_chrome addr, uuid

loop do
res = ws_client.extract_data
case
when res['id'] == 1 && target_info = res.dig('result', 'targetInfos')
case res['id']
when 1
target_info = res.dig('result', 'targetInfos')
page = target_info.find{|t| t['type'] == 'page'}
ws_client.send id: 2, method: 'Target.attachToTarget',
params: {
targetId: page['targetId'],
flatten: true
}
when res['id'] == 2
when 2
s_id = res.dig('result', 'sessionId')
# TODO: change id
ws_client.send sessionId: s_id, id: 100, method: 'Network.enable'
ws_client.send sessionId: s_id, id: 3,
method: 'Page.enable'
when res['id'] == 3
when 3
s_id = res['sessionId']
ws_client.send sessionId: s_id, id: 4,
method: 'Page.getFrameTree'
when res['id'] == 4
when 4
s_id = res['sessionId']
f_id = res.dig('result', 'frameTree', 'frame', 'id')
ws_client.send sessionId: s_id, id: 5,
@@ -61,17 +62,19 @@ def setup_chrome addr, uuid
url: "devtools://devtools/bundled/inspector.html?v8only=true&panel=sources&ws=#{addr}/#{uuid}",
frameId: f_id
}
when res['method'] == 'Network.webSocketWillSendHandshakeRequest'
s_id = res['sessionId']
# Display the console by entering ESC key
ws_client.send sessionId: s_id, id: 101, # TODO: change id
method:"Input.dispatchKeyEvent",
params: {
type:"keyDown",
windowsVirtualKeyCode:27 # ESC key
}
when res['id'] == 101
when 101
break
else
if res['method'] == 'Network.webSocketWillSendHandshakeRequest'
s_id = res['sessionId']
# Display the console by entering ESC key
ws_client.send sessionId: s_id, id: 101, # TODO: change id
method:"Input.dispatchKeyEvent",
params: {
type:"keyDown",
windowsVirtualKeyCode:27 # ESC key
}
end
end
end
pid