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

How to launch trio-chrome fully programmatically ? #13

Open
benoitgaly opened this issue May 23, 2020 · 2 comments
Open

How to launch trio-chrome fully programmatically ? #13

benoitgaly opened this issue May 23, 2020 · 2 comments

Comments

@benoitgaly
Copy link

Hi,

In the examples it says :
"The URL that Chrome is listening on is displayed in the terminal after Chrome starts up."
This works fine, but how to do handle all this programmatically ? Copy-pasting an url is not possible in production.

Have you a way to get this url automatically ? Isn't there a way to bypass this ? I mean, other library like Pychrome (outdated), were simply asking for the url 'pychrome.Browser(url="http://127.0.0.1:9222")'

In python, Selenium is allowing : driver.execute_cdp_cmd('Target.getTargets', {}). Those libraries are not as complete as trio-chrome, but I do not need to copy paste an url by hand.

@benoitgaly benoitgaly changed the title How to launch trio-chrome programmatically ? How to launch trio-chrome fully programmatically ? May 23, 2020
@benoitgaly
Copy link
Author

benoitgaly commented May 23, 2020

Best I have found so far with Selenium is : chrome_options.add_argument(f'--remote-debugging-port={self.dev_tools_port}')
#chrome_options.add_argument("--user-data-dir=C:\Applications\profile")

    chrome = webdriver.Chrome(executable_path=self.driver_exe, chrome_options=chrome_options, service_log_path=os.devnull)
    chrome.get(f'http://127.0.0.1:{self.dev_tools_port}/json/version')
    pre = chrome.find_element_by_tag_name("pre").text
    data = json.loads(pre)
    self.webSocketDebuggerUrl = data['webSocketDebuggerUrl']

@mehaase
Copy link
Contributor

mehaase commented May 26, 2020

In our own use case, we create the browser in a separate component and pass the URL into Trio CDP, but as you point out many libraries have this feature and it would be good to add it here. I will leave this ticket open as a reminder.

In the meantime, here is some sample code for getting the chrome URL programmatically:

import asks

port = 9000
url = "http://localhost:{}/json/version".format(port)
response = await asks.get(url)
data = response.json()
debugger_url = data["webSocketDebuggerUrl"]

# Now `debugger_url` can be passed into Trio CDP

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

2 participants