我正在尝试为chrome devtool协议创建伪造的调试器目标。我使用nodejs创建了一个简单的http服务器,并开始在端口9229
上列出(就像nodejs一样)。我实现了2个URL /json/version
和/json
,它们返回与nodejs inspect
完全相同的响应。也已启动到websocket服务器,但服务器正在获取的唯一请求是/json/version
和/json
,而且远程目标中也没有目标。
我的源代码如下
var WebSocket = require('ws');
var http = require('http');
function sendJson(json, response) {
response.writeHead(200, {
"Content-Type": "application/json; charset=UTF-8",
"Cache-Control": "no-cache"
})
response.write(JSON.stringify(json));
response.end();
}
var server = http.createServer(function (request, response) {
console.log((new Date()) + ' Received request for ' + request.url);
switch (request.url) {
case '/json/version':
sendJson({
"Browser": "node.js/v8.11.4",
"Protocol-Version": "1.1"
}, response);
break;
case '/json/list':
case '/json':
sendJson([
{
"description": "node.js instance",
"devtoolsFrontendUrl": "chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9229/0198dee4-3ed9-4715-854a-d70d333627f6",
"faviconUrl": "https://nodejs.org/static/favicon.ico",
"id": "0198dee4-3ed9-4715-854a-d70d333627f6",
"title": "node[15981]",
"type": "node",
"url": "file://",
"webSocketDebuggerUrl": "ws://127.0.0.1:9229/0198dee4-3ed9-4715-854a-d70d333627f6"
}
], response);
break;
default:
response.writeHead(404, {});
response.end();
}
});
wss = new WebSocket.Server({server: server});
wss.on('connection', ws => {
ws.on('message', message => {
console.log(`Received message => ${message}`)
})
})
server.listen(9229, function () {
console.log((new Date()) + ' Server is listening on port 9229');
});
任何人都可以弄清楚我在想什么吗?