Possible to bind devtools to multiple ports so that I can send commands to multiple tabs?

74 views
Skip to first unread message

Georgios Diamantopoulos

unread,
Mar 10, 2017, 10:53:26 AM3/10/17
to headless-dev
Hey folks :)

Is it possible to bind devtools to multiple ports so that I can send commands to multiple tabs concurrently?

If so, can you please give me a rough guide?

Thank you

Eric Seckler

unread,
Mar 10, 2017, 11:06:09 AM3/10/17
to Georgios Diamantopoulos, headless-dev
I think if you want to send a command to multiple tabs, you'll have to send it to each one individually, via multiple websocket connections. There's no reason why you couldn't do that concurrently from your client application, though.

Alternatively, you can use the commands in the Target domain, e.g. Target.sendMessageToTarget to proxy messages to individual targets via a single websocket (connected to the /devtools/browser endpoint, for example). Not sure if you gain anything by doing that for your use case though.

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.
To post to this group, send email to headle...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/headless-dev/e09463de-9d81-4a9d-8f27-a15923459f97%40chromium.org.

Georgios Diamantopoulos

unread,
Mar 10, 2017, 11:16:57 AM3/10/17
to headless-dev, geor...@gmail.com
Hm, I get what you're saying but it's not immediately clear how I would go about doing that.

Let's break it down a little bit, please.

I guess you're saying that there will be only be one DevToolsServer and multiple connections to that endpoint? 
If not, and I'd have to create a server for each tab, I only see HeadlessBrowser::Options::Builder::EnableDevToolsServer() to enable it globally

In the above case that there's one server and multiple connection, how do I select which tab the connection corresponds to?

Eric Seckler

unread,
Mar 10, 2017, 11:26:59 AM3/10/17
to Georgios Diamantopoulos, headless-dev
Every tab has its own websocket endpoint that your client can connect to.

If you run e.g.
chrome --headless --disable-gpu --remote-debugging-port=9222 http://chromium.org/

You should be able to see the tabs and their endpoints in the list at http://localhost:9222/ and via json on http://localhost:9222/json/list.

Depending on your client library, it might support getting a list of tabs or you might have to manually point it to the right endpoint.
If you're using the C++ bindings, you can attach your HeadlessDevToolsClient to each HeadlessWebContents, which corresponds to a tab.

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.
To post to this group, send email to headle...@chromium.org.

Georgios Diamantopoulos

unread,
Mar 10, 2017, 11:35:39 AM3/10/17
to headless-dev, geor...@gmail.com
Aha! Thank you, that's very illuminating. 

Is there any way to do authentication in headless right now? Especially for proxy.

Also, it's my impression that single-process means that the process can only have only one tab, can you please verify that?

Eric Seckler

unread,
Mar 10, 2017, 11:43:28 AM3/10/17
to Georgios Diamantopoulos, headless-dev
On Fri, Mar 10, 2017 at 4:35 PM Georgios Diamantopoulos <geor...@gmail.com> wrote:
Aha! Thank you, that's very illuminating. 

Is there any way to do authentication in headless right now? Especially for proxy.
Can you clarify what you mean by authentication? We've talked about proxys on headless-dev before though.
 
Also, it's my impression that single-process means that the process can only have only one tab, can you please verify that?
Single process only means that all renderers (all tabs) live within the same process together with the browser, rather than in separate processes. It doesn't restrict the number of tabs. See chromium process models.

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.
To post to this group, send email to headle...@chromium.org.

Georgios Diamantopoulos

unread,
Mar 10, 2017, 12:55:46 PM3/10/17
to headless-dev, geor...@gmail.com
I was just very surprised that memory usage in single-process didn't scale linearly like in the multi-process model!
So I thought I'd better check :)

Thank you, I'll move the proxy discussion to that thread.
Reply all
Reply to author
Forward
0 new messages