Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect to an existing chrome instance #8

Open
nielslaukens opened this issue Jun 9, 2021 · 4 comments
Open

Connect to an existing chrome instance #8

nielslaukens opened this issue Jun 9, 2021 · 4 comments

Comments

@nielslaukens
Copy link
Contributor

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

@fake-name
Copy link
Owner

fake-name commented Jun 9, 2021

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.

@nielslaukens
Copy link
Contributor Author

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.

@Dulani
Copy link

Dulani commented Jul 16, 2021

@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.

@nielslaukens
Copy link
Contributor Author

nielslaukens commented Jul 19, 2021

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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants