How to get WebSocket URL

3,774 views
Skip to first unread message

Vikram Tiwari

unread,
Jul 2, 2019, 5:34:01 PM7/2/19
to Chrome DevTools
Hey folks,

The only way (that I am aware of) to get chrome's debugging websocket url is:
- stop all running chrome processes
- start chrome with flag --remote-debugging-port=9222
- the websocket url will be printed in console with ws://127.0.0.1:9222/devtools/browser/<unique_id>


Are there any other ways to get this url? Best case would be that I don't have to stop and restart chrome with the debug flag.

Other ideas/questions:
- Can a chrome extension can get this websocket url?
- Can I always start chrome with debug flag somehow? Editing Info.plist or windows registry?
- Can I add some js code in the page which can get the websocket url?

Open to any other ideas. :)

Thanks folks!

Black-Hole

unread,
Jul 4, 2019, 3:26:24 AM7/4/19
to google-chrome-...@googlegroups.com
1. You can use http://127.0.0.1:9222/json
2. Yes
3. You can add commands to its chrome executable file. e.g:https://www.chromium.org/developers/how-tos/run-chromium-with-flags
4. 
const wsList = {};
const getWsList = () => {
return new Promise((resolve) => {
http.get('http://127.0.0.1:9222/json', res => {
res.addListener('data', data => {
try {
const result = JSON.parse(data.toString());
const tempWsList = {};

result.forEach(info => {
if (typeof wsList[info.id] === 'undefined') {
tempWsList[info.id] = info.webSocketDebuggerUrl;
wsList[info.id] = info.webSocketDebuggerUrl;
}
});

if (Object.keys(tempWsList).length !== 0) {
resolve(tempWsList);
}
} catch (e) {
console.error(e);
}
});
});
});
};

setInterval(() => {
getWsList().then(list => {
Object.values(list).forEach(wsUrl => {
const client = new WebSocket(wsUrl);
console.log(client)
})
});
}, 1000);


Vikram Tiwari <vikram...@gmail.com> 于2019年7月3日周三 上午5:34写道:
--
You received this message because you are subscribed to the Google Groups "Chrome DevTools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-chrome-develo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-chrome-developer-tools/4154fbdc-3835-433f-9a23-232fdd193eb3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

laike9m (laike9m)

unread,
Dec 30, 2022, 3:59:03 PM12/30/22
to Chrome DevTools
I think what you need is 
Reply all
Reply to author
Forward
0 new messages