1

我正在尝试为 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');
});

所以有人能弄清楚我错过了什么吗?

4

0 回答 0