使用Google Chrome远程调试协议 [英] Using Google Chrome remote debugging protocol

查看:507
本文介绍了使用Google Chrome远程调试协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Chrome获取网络事件。我发现这个:
https://developer.chrome.com/devtools / docs / debugger-protocol
https ://developer.chrome.com/devtools/docs/protocol/1.1/network#command-enable



似乎Chrome使用端口来获取消息,回答和发送事件,以进行远程调试。它说它使用JSON,所以我决定尝试它。

所以,我写了一些简单的java代码,它打开了chrome正在监听的端口(当然我也有通过在我的ubuntu机器上使用 google-chrome --remote-debugging-port = 9222 来启动它)。我有一个线程可以写入标准输出来自这个端口的任何东西,然后代码使用这一行(来自协议的示例方法)将它写入套接字的输出流:

  out.println({\id \:1,\method \:\Network.enable \}); 

我希望输入流中有一些答案(根据协议),但没有任何反应。 p>

有没有人做过类似的事情?我在网上找不到任何东西。

解决方案

最后,我明白了。请参阅 https:// www。 igvita.com/2012/04/09/driving-google-chrome-via-websocket-api/



首先,我发送一个HTTP请求到< a href =http:// localhost:9222 / json =nofollow noreferrer> http:// localhost:9222 / json 。这会返回Chrome中打开标签的JSON列表,对于每个我也会得到一个WebSocket uri(webSocketDebuggerUrl):

  [
{
description:,
devtoolsFrontendUrl:/devtools/devtools.html?ws=localhost:9222/devtools/page/C014A09F-BD0A-40BA-B23C-7B18B84942CD ,
faviconUrl:http://cdn.sstatic.net/stackoverflow/img/favicon.ico?v=00a326f96f68,
id:C014A09F-BD0A-40BA-B23C- 7B18B84942CD,
title:使用Google Chrome远程调试协议 - 堆栈溢出,
type:page,
url:https:// stackoverflow。 com / questions / 28430479 / using-google-chrome-remote-debugging-protocol,
webSocketDebuggerUrl:ws:// localhost:9222 / devtools / page / C014A09F-BD0A-40BA-B23C-7B18B84942CD






$ b然后我可以使用WebSocket发送消息来调试使用这个URI。我还发现使用WebSocket的Jetty实现: javax.websocket客户端简单示例

I need to get the network events from Chrome. I've found this: https://developer.chrome.com/devtools/docs/debugger-protocol https://developer.chrome.com/devtools/docs/protocol/1.1/network#command-enable

It seems that Chrome uses a port to get messages, answer and send events, for remote debugging. It says it uses JSON, so I decided to try it.

So, I wrote some simple java code that opens the port that chrome is listening on (ofcourse i've started it by using google-chrome --remote-debugging-port=9222 on my ubuntu machine). I have a thread that writes to stdout anything coming from this port, and then the code writes this to the outputstream of the socket using this line (a sample method from the protocol):

out.println("{\"id\": 1,\"method\": \"Network.enable\"}");

I would expect some answer (according to the protocol) in the input stream but nothing happens.

Does anyone ever done something like this? I can't find anything on the net.

解决方案

Finally I've got it. Credit goes to https://www.igvita.com/2012/04/09/driving-google-chrome-via-websocket-api/.

First I send an HTTP request to http://localhost:9222/json. This returns a JSON list of open tabs in Chrome, for each I also get a WebSocket uri (webSocketDebuggerUrl):

[
{
"description": "",
"devtoolsFrontendUrl": "/devtools/devtools.html?ws=localhost:9222/devtools/page/C014A09F-BD0A-40BA-B23C-7B18B84942CD",
"faviconUrl": "http://cdn.sstatic.net/stackoverflow/img/favicon.ico?v=00a326f96f68",
"id": "C014A09F-BD0A-40BA-B23C-7B18B84942CD",
"title": "Using Google Chrome remote debugging protocol - Stack Overflow",
"type": "page",
"url": "https://stackoverflow.com/questions/28430479/using-google-chrome-remote-debugging-protocol",
"webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/C014A09F-BD0A-40BA-B23C-7B18B84942CD"
}
]

Then I can use WebSocket to send messages for debugging a specific tab, using this URI. I also found this for using Jetty implementation of WebSocket: javax.websocket client simple example.

这篇关于使用Google Chrome远程调试协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆