GoogleChrome / chrome-launcher

Launch Google Chrome with ease from node.
https://www.npmjs.com/package/chrome-launcher
Apache License 2.0
1.25k stars 188 forks source link

Request: Expose the browser ID when launching #10

Open devtools-bot opened 7 years ago

devtools-bot commented 7 years ago

From @joelgriffith on August 7, 2017 17:40

When launching Chrome (at 62) it prints the special "browser" target to connect to:

DevTools listening on ws://127.0.0.1:9222/devtools/browser/dce23e24-5a5b-4f89-a3f4-749d3ef70ea9

This target isn't exposed/discoverable anywhere else in the protocol due to this merge: https://chromium-review.googlesource.com/c/596719

It might be a good thing to expose to consumers so that they can attach to this special target and do commands at the browser-level

Copied from original issue: GoogleChrome/lighthouse#2865

devtools-bot commented 7 years ago

From @paulirish on August 7, 2017 18:12

Thanks for filing this. I looked into it and found that we have two options:

  1. Chrome will now log this target to stderr on launch. Previous to this CL, we'd see something like this:
DevTools listening on 127.0.0.1:56296

and it now prints:

DevTools listening on ws://127.0.0.1:63126/devtools/browser/c07d6691-cfb8-4a88-9bff-a03ce85848ea
  1. If chrome is launched with the remote-debugging-port=0, then it creates a DevToolsActivePort file in the user profile directory. (This doesn't happen if port is non-zero). It's contents are now both the port and the browser WS target URL:
56778
/devtools/browser/7ef11f4e-5c38-4111-8a7c-979703b95d00

We had plans to use Chrome's magic port=0 resolution already, so I'm thinking we'll do adopt the first option.

@joelgriffith As for exposing to users, how about the instance object (with the kill() method) gets a property called browserWs with this url?

devtools-bot commented 7 years ago

From @joelgriffith on August 7, 2017 18:20

browserWs would be fantastic! Thanks!

devtools-bot commented 7 years ago

From @paulirish on August 16, 2017 0:40

I have an impl nearly ready for this in https://github.com/GoogleChrome/lighthouse/compare/browserws

joelgriffith commented 7 years ago

I think this has become more desirable with the puppet release as it (I'm assuming) can connect to the browser-level target via puppeteer.connect({ 'browserWSEndpoint': 'ws://localhost:51378/devtools/browser/id' })