Connect to an existing chrome instance
Hi,
I stumbled upon this project, and it looks pretty much what I need. Thank you for sharing your work!
I'm trying to figure out if/how I can connect to an already-running Chrome instance. From what I see in the code, it will always start a new chrome-instance itself.
(The Chrome-instance will be running on a different machine, so it's easier to start it first and connect later)
Thank you, Niels
Hmmm, that's an interesting use-case I hadn't considered. Currently the transport manager is very heavily bound to running the chrome binary internally.
Let me see if I can separate the section responsible for running the chrome binary, and the websocket communications. That's a logical division anyways, and the fact that the current implementation kind of smears the two together isn't great.
I currently worked around the problem by having ChromeController run a script that connects the given --remote-debugging-port=#### to the actual remote port.
And thinking about it, that isn't a too bad solution after all.
@nielslaukens - Any chance you could share your implementation either in a fork or as code pasted here in the issue? I started to follow your recommendation but figured it might be less error prone to merely ask for your code.
I use the script below as follows:
chrome_args = [f"--remote={ip}:{args.port}"]
with ChromeController.ChromeContext(binary="./remote-chrome.sh", additional_options=chrome_args) as cr:
...
The script itself is pretty simple: It parses out the --remote and --remote-debugging-port arguments (and ignores the rest) and uses socat (netcat would also work) to patch the connection through.
#!/bin/bash
while [ $# -gt 0 ]; do
case "$1" in
--remote-debugging-port=*) PORT=${1##--remote-debugging-port=};;
--remote=*) REMOTE=${1##--remote=};;
esac;
shift;
done
exec socat TCP-LISTEN:${PORT},fork,reuseaddr TCP:${REMOTE}