[SOLVED] How do I get Chrome's remote devtools debugging URL?

I’ve given Electron’s Chrome the --remote-debugging-port option by writing in my main process

app.commandLine.appendSwitch('remote-debugging-port', '8315')

const wsChromeEndpointurl = /* Where to get the ws:// URL? */

Now how do I get the ws:// URL from within my main process code? I see it outputted to the terminal, but it changes every time. Is it possible to get it from the Electron main process code?

The URL looks like ws://127.0.0.1:8315/devtools/browser/a96688f4-cce9-486a-9a36-9fb485a4c28a.

Figured it out. Based on this github issue, I took a look at http://localhost:8315, and discovered that it has a /json/list endpoint which lists the available WebSocket debugger URLs.

The output looks like:
[ {
   "description": "",
   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:8315/devtools/page/4B633ADBF4EDE922DE3A07F117E603CB",
   "id": "4B633ADBF4EDE922DE3A07F117E603CB",
   "title": "chrome-devtools://devtools/bundled/devtools_app.html?remoteBase=https://chrome-devtools-frontend.appspot.com/serve_file/@164c37e3f235134c88e80fac2a182cfba3f07f00/&can_dock=true&toolbarColor=rgba(223,223,223,1)&textColor=rgba(0,0,0,1)&experiments=true",
   "type": "page",
   "url": "chrome-devtools://devtools/bundled/devtools_app.html?remoteBase=https://chrome-devtools-frontend.appspot.com/serve_file/@164c37e3f235134c88e80fac2a182cfba3f07f00/&can_dock=true&toolbarColor=rgba(223,223,223,1)&textColor=rgba(0,0,0,1)&experiments=true",
   "webSocketDebuggerUrl": "ws://localhost:8315/devtools/page/4B633ADBF4EDE922DE3A07F117E603CB"
}, {
   "description": "",
   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:8315/devtools/page/55DC64A5E9A3C6A5337DD09B3557D9FE",
   "id": "55DC64A5E9A3C6A5337DD09B3557D9FE",
   "title": "Saffron",
   "type": "page",
   "url": "http://localhost:9080/#/login",
   "webSocketDebuggerUrl": "ws://localhost:8315/devtools/page/55DC64A5E9A3C6A5337DD09B3557D9FE"
}, {
   "description": "",
   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:8315/devtools/page/33615E14298A02CEDEF6D685EAEC4F82",
   "id": "33615E14298A02CEDEF6D685EAEC4F82",
   "title": "chrome-extension://_generated_background_page.html",
   "type": "page",
   "url": "chrome-extension://_generated_background_page.html/",
   "webSocketDebuggerUrl": "ws://localhost:8315/devtools/page/33615E14298A02CEDEF6D685EAEC4F82"
}, {
   "description": "",
   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:8315/devtools/page/DD7F6D86D0A74A578076B66C1507F48B",
   "id": "DD7F6D86D0A74A578076B66C1507F48B",
   "title": "chrome-extension://redux-devtools/_generated_background_page.html",
   "type": "page",
   "url": "chrome-extension://redux-devtools/_generated_background_page.html",
   "webSocketDebuggerUrl": "ws://localhost:8315/devtools/page/DD7F6D86D0A74A578076B66C1507F48B"
}, {
   "description": "",
   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:8315/devtools/page/3046A22FCED2074A89063FC0A83EADFC",
   "id": "3046A22FCED2074A89063FC0A83EADFC",
   "title": "chrome-extension://react-developer-tools/_generated_background_page.html",
   "type": "page",
   "url": "chrome-extension://react-developer-tools/_generated_background_page.html",
   "webSocketDebuggerUrl": "ws://localhost:8315/devtools/page/3046A22FCED2074A89063FC0A83EADFC"
} ]

After that I was able to connect Puppeteer to my Electron window using the WebSocket debugger URL for my window, which I found by looking at the titles of the endpoints.

To see the example code, look in the other thread: [SOLVED] Control/automate an Electron application with Puppeteer?