Skip to content

Commit 2fd140b

Browse files
Myles BorinsFishrock123
Myles Borins
authored andcommitted
src: fix json payload from inspector
Fix the `webSocketDebuggerUrl` and `devtoolsFrontendUrl` returned by v8_inspector in /json HTTP endpoint to work with 3rd party clients. Fixes: #7227 PR-URL: #7232 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]>
1 parent f4777c7 commit 2fd140b

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/inspector_agent.cc

+13-9
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ namespace node {
2929
namespace {
3030

3131
const char DEVTOOLS_PATH[] = "/node";
32+
const char DEVTOOLS_HASH[] = "521e5b7e2b7cc66b4006a8a54cb9c4e57494a5ef";
3233

3334
void PrintDebuggerReadyMessage(int port) {
3435
fprintf(stderr, "Debugger listening on port %d.\n"
3536
"To start debugging, open the following URL in Chrome:\n"
3637
" chrome-devtools://devtools/remote/serve_file/"
37-
"@521e5b7e2b7cc66b4006a8a54cb9c4e57494a5ef/inspector.html?"
38-
"experiments=true&v8only=true&ws=localhost:%d/node\n", port, port);
38+
"@%s/inspector.html?"
39+
"experiments=true&v8only=true&ws=localhost:%d/node\n",
40+
port, DEVTOOLS_HASH, port);
3941
}
4042

4143
bool AcceptsConnection(inspector_socket_t* socket, const char* path) {
@@ -89,18 +91,19 @@ void SendVersionResponse(inspector_socket_t* socket) {
8991
SendHttpResponse(socket, buffer, len);
9092
}
9193

92-
void SendTargentsListResponse(inspector_socket_t* socket) {
94+
void SendTargentsListResponse(inspector_socket_t* socket, int port) {
9395
const char LIST_RESPONSE_TEMPLATE[] =
9496
"[ {"
9597
" \"description\": \"node.js instance\","
9698
" \"devtoolsFrontendUrl\": "
9799
"\"https://chrome-devtools-frontend.appspot.com/serve_file/"
98-
"@4604d24a75168768584760ba56d175507941852f/inspector.html\","
100+
"@%s/inspector.html?experiments=true&v8only=true"
101+
"&ws=localhost:%d%s\","
99102
" \"faviconUrl\": \"https://nodejs.org/static/favicon.ico\","
100103
" \"id\": \"%d\","
101104
" \"title\": \"%s\","
102105
" \"type\": \"node\","
103-
" \"webSocketDebuggerUrl\": \"ws://%s\""
106+
" \"webSocketDebuggerUrl\": \"ws://localhost:%d%s\""
104107
"} ]";
105108
char buffer[sizeof(LIST_RESPONSE_TEMPLATE) + 4096];
106109
char title[2048]; // uv_get_process_title trims the title if too long
@@ -114,12 +117,13 @@ void SendTargentsListResponse(inspector_socket_t* socket) {
114117
c++;
115118
}
116119
size_t len = snprintf(buffer, sizeof(buffer), LIST_RESPONSE_TEMPLATE,
117-
getpid(), title, DEVTOOLS_PATH);
120+
DEVTOOLS_HASH, port, DEVTOOLS_PATH, getpid(),
121+
title, port, DEVTOOLS_PATH);
118122
ASSERT_LT(len, sizeof(buffer));
119123
SendHttpResponse(socket, buffer, len);
120124
}
121125

122-
bool RespondToGet(inspector_socket_t* socket, const char* path) {
126+
bool RespondToGet(inspector_socket_t* socket, const char* path, int port) {
123127
const char PATH[] = "/json";
124128
const char PATH_LIST[] = "/json/list";
125129
const char PATH_VERSION[] = "/json/version";
@@ -128,7 +132,7 @@ bool RespondToGet(inspector_socket_t* socket, const char* path) {
128132
SendVersionResponse(socket);
129133
} else if (!strncmp(PATH_LIST, path, sizeof(PATH_LIST)) ||
130134
!strncmp(PATH, path, sizeof(PATH))) {
131-
SendTargentsListResponse(socket);
135+
SendTargentsListResponse(socket, port);
132136
} else if (!strncmp(path, PATH_ACTIVATE, sizeof(PATH_ACTIVATE) - 1) &&
133137
atoi(path + (sizeof(PATH_ACTIVATE) - 1)) == getpid()) {
134138
const char TARGET_ACTIVATED[] = "Target activated";
@@ -348,7 +352,7 @@ bool Agent::OnInspectorHandshakeIO(inspector_socket_t* socket,
348352
Agent* agent = static_cast<Agent*>(socket->data);
349353
switch (state) {
350354
case kInspectorHandshakeHttpGet:
351-
return RespondToGet(socket, path);
355+
return RespondToGet(socket, path, agent->port_);
352356
case kInspectorHandshakeUpgrading:
353357
return AcceptsConnection(socket, path);
354358
case kInspectorHandshakeUpgraded:

0 commit comments

Comments
 (0)