Skip to content

Commit d265e49

Browse files
committed
fix(linux): DevTools URL with the inspector's target id
The runtime only upgrades ws://127.0.0.1:<port>/<id> now; the id comes from /json/list (older runtimes without one keep the bare URL).
1 parent 93d5d27 commit d265e49

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

‎lib/services/linux-device-debug-service.ts‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as http from "http";
12
import * as net from "net";
23
import { sleep } from "../common/helpers";
34
import { performanceLog } from "../common/decorators";
@@ -48,10 +49,37 @@ export class LinuxDeviceDebugService
4849
);
4950
}
5051
this.$logger.info("# NativeScript Debugger started #");
51-
result.debugUrl = this.getChromeDebugUrl(debugOptions, port);
52+
// the runtime only upgrades its (random) target path
53+
const target = await this.targetPath(port);
54+
result.debugUrl =
55+
this.getChromeDebugUrl(debugOptions, port) + (target ?? "");
5256
return result;
5357
}
5458

59+
/** `/<id>` of the inspector's target, from `/json/list`. */
60+
private targetPath(port: number): Promise<string | null> {
61+
return new Promise((resolve) => {
62+
const request = http.get(
63+
{ host: "127.0.0.1", port, path: "/json/list", timeout: 2000 },
64+
(response) => {
65+
let body = "";
66+
response.setEncoding("utf8");
67+
response.on("data", (chunk) => (body += chunk));
68+
response.on("end", () => {
69+
try {
70+
const url = new URL(JSON.parse(body)[0].webSocketDebuggerUrl);
71+
resolve(url.pathname.length > 1 ? url.pathname : null);
72+
} catch {
73+
resolve(null);
74+
}
75+
});
76+
},
77+
);
78+
request.on("timeout", () => request.destroy());
79+
request.on("error", () => resolve(null));
80+
});
81+
}
82+
5583
public async debugStop(): Promise<void> {
5684
// the inspector lives in the app process
5785
}

‎test/services/linux-device-debug-service.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as http from "http";
12
import * as net from "net";
23
import { assert } from "chai";
34
import { LinuxDeviceDebugService } from "../../lib/services/linux-device-debug-service";
@@ -48,6 +49,32 @@ describe("linuxDeviceDebugService", () => {
4849
}
4950
});
5051

52+
it("adds the inspector's target id to the DevTools URL", async () => {
53+
const id = "fe0f450d-2279-686c-661a-6024bea0f5f0";
54+
const server = http.createServer((_request, response) => {
55+
response.end(
56+
JSON.stringify([
57+
{ webSocketDebuggerUrl: `ws://127.0.0.1:${port}/${id}` },
58+
]),
59+
);
60+
});
61+
await new Promise<void>((resolve) =>
62+
server.listen(0, "127.0.0.1", resolve),
63+
);
64+
const port = (<net.AddressInfo>server.address()).port;
65+
try {
66+
const result = await createService(port).debug(debugData, {
67+
timeout: "2",
68+
});
69+
assert.equal(
70+
result.debugUrl,
71+
`devtools://devtools/bundled/inspector.html?ws=127.0.0.1:${port}/${id}`,
72+
);
73+
} finally {
74+
server.close();
75+
}
76+
});
77+
5178
it("fails when nothing listens on the inspector port", async () => {
5279
const server = await listen();
5380
const port = (<net.AddressInfo>server.address()).port;

0 commit comments

Comments
 (0)