|
| 1 | +import * as http from "http"; |
1 | 2 | import * as net from "net"; |
2 | 3 | import { sleep } from "../common/helpers"; |
3 | 4 | import { performanceLog } from "../common/decorators"; |
@@ -48,10 +49,37 @@ export class LinuxDeviceDebugService |
48 | 49 | ); |
49 | 50 | } |
50 | 51 | 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 ?? ""); |
52 | 56 | return result; |
53 | 57 | } |
54 | 58 |
|
| 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 | + |
55 | 83 | public async debugStop(): Promise<void> { |
56 | 84 | // the inspector lives in the app process |
57 | 85 | } |
|
0 commit comments