I want to connect to an existing (already opened, by the user, without any extra flags) Chrome browser using pyppeteer so I would be able to control it.
I can do almost every manual action before (for example, enabling remote debugging mode in existing chrome), but it is preferable to do it with the least actions.
In order to use browser.connect
, I need to give it browserWSEndpoint
, which is equivalent to webSocketDebuggerUrl
under 'http://localhost:9222/json/version'.
My problem is that I can get to 'http://localhost:9222/json/version' only when I run chrome with --headless
tag, otherwise I can't get this string.
I tried running from cmd:
chrome --disable-gpu --remote-debugging-port=9222 https://stackoverflow.com
which opens a new tab under the opened chrome instance, but I still can't reach 'http://localhost:9222/json/version' to get webSocketDebuggerUrl
(I get 'ERR_CONNECTION_REFUSED' when trying to reach that address).
How can I do it? I couldn't find anything on the net.
Edit (also refined the first paragraph of the question):
Thanks all for the answers, but it seems that what I originally wanted to do is not possible. You cannot connect to an existing Chrome if it wasn't first opened (the first instance of the browser) with the flag --remote-debugging-port=XXXX
that allows you to remotely control it.
As soon as a first instance of the browser was opened - it locks the user data of the browser and flags can't be added from the command line to the browser (only from inside the browser itself, by the user).