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

ChromeDPClient hangs when using a WS URL instead of HTTP #465

Open
pcarrier opened this issue Dec 6, 2024 · 4 comments
Open

ChromeDPClient hangs when using a WS URL instead of HTTP #465

pcarrier opened this issue Dec 6, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@pcarrier
Copy link

pcarrier commented Dec 6, 2024

Version

6.6.0-1391447

What happened?

This code hangs forever:

import org.hildan.chrome.devtools.protocol.ChromeDPClient

suspend fun main() {
    val client = ChromeDPClient(
        "ws://127.0.0.1:9222/devtools/browser/9e0c7e2a-72a8-4120-8047-c4487f3c1c14",
        overrideHostHeader = true
    )
    client.webSocket().browser.close()
}

Reproduction and additional details

No response

Kotlin target platforms

JVM (non-Android)

@pcarrier pcarrier added the bug Something isn't working label Dec 6, 2024
@joffrey-bion
Copy link
Owner

joffrey-bion commented Dec 6, 2024

With the ChromeDPClient you don't need the full WS URL. You just need the base HTTP URL http://127.0.0.1:9222, like this:

val client = ChromeDPClient("http://127.0.0.1:9222", overrideHostHeader = true)
val browserSession = client.webSocket()

Check the README for how to get started: https://github.com/joffrey-bion/chrome-devtools-kotlin/tree/main?tab=readme-ov-file#connecting-to-the-browser

If you want to use the WS URL directly and save one intermediate HTTP call, you can use the Ktor HttpClient directly with the chromeWebSocket extension like this:

val httpClient = HttpClient { ... }
val browserSession = httpClient.chromeWebSocket("ws://127.0.0.1:9222/devtools/browser/9e0c7e2a-72a8-4120-8047-c4487f3c1c14")

Please let me know if this fixes your issue.

@joffrey-bion
Copy link
Owner

joffrey-bion commented Dec 6, 2024

That being said, it is still a problem that your original code hangs. It should instead fail with an error message that hints towards this solution. So thanks for reporting this, I'll check.

@pcarrier
Copy link
Author

pcarrier commented Dec 6, 2024

Thanks! For reference, needed:

    val client = HttpClient {
        install(WebSockets)
        install(DefaultRequest) {
            headers["Host"] = "localhost"
        }
    }

@joffrey-bion
Copy link
Owner

joffrey-bion commented Dec 6, 2024

Oh yeah, my bad, the HttpClient needs a bit of configuration, as you can see in the ChromeDPClient implementation. But you can also avoid this hassle if you just use the HTTP URL with ChromeDPClient.

@joffrey-bion joffrey-bion changed the title ChromeDPClient hanging on trivial task? ChromeDPClient hangs when using a WS URL instead of HTTP Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants