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

make NewRemoteAllocator accept url without devtools/browser/... #817

Merged
merged 5 commits into from May 14, 2021

Conversation

ZekeLu
Copy link
Member

@ZekeLu ZekeLu commented May 11, 2021

A full websocket debugger URL is something like this:

ws://127.0.0.1:9222/devtools/browser/120e6fb7-0094-47a2-8b4c-51741797f280

And the ID part is not static, which requires extra work to get the correct URL for chromedp.NewRemoteAllocator.

This change allows the client to just pass the base URL to chromedp.NewRemoteAllocator. It will send a request to /json/version to get the full websocket debugger URL if the provided URL is not a valid websocket debugger URL.

After the change, the URL with the following formats are accepted:

  • ws://127.0.0.1:9222/
  • http://127.0.0.1:9222/

Do not use URL in the following formats because they contain /devtools/browser/ and will be considered as valid websocket debugger URLs:

  • ws://127.0.0.1:9222/devtools/browser/
  • ws://127.0.0.1:9222/devtools/browser/
  • http://127.0.0.1:9222/devtools/browser/120e6fb7-0094-47a2-8b4c-51741797f280

Fixes #438.

A full websocket debugger URL is something like this:
ws://127.0.0.1:9222/devtools/browser/120e6fb7-0094-47a2-8b4c-51741797f280
And the ID part is not static, which requires extra work to get
the correct URL for NewRemoteAllocator.

This change allows the client to just pass the base URL to
NewRemoteAllocator. It will send a request to "/json/version"
to get the full websocket debugger URL.

After the change, the URL with the following formats are accepted:
* ws://127.0.0.1:9222/
* http://127.0.0.1:9222/

But "ws://127.0.0.1:9222/devtools/browser/" are not accepted.
Because it contains "/devtools/browser/" and will be considered
as a valid websocket debugger URL.
@ZekeLu
Copy link
Member Author

ZekeLu commented May 12, 2021

This PR also takes care of #502. Tested with the following configuration:

docker-compose.yml:

version: "3.9"
services:
  browser:
    image: chromedp/headless-shell:88.0.4324.182
  app:
    image: testapp:latest
    links:
      - browser

main.go:

package main

import (
	"context"
	"log"

	"github.com/chromedp/chromedp"
)

func main() {
	// pay attention to the url below
	ctx, cancel := chromedp.NewRemoteAllocator(context.Background(), "ws://browser:9222/")
	defer cancel()

	ctx, cancel = chromedp.NewContext(ctx, chromedp.WithDebugf(log.Printf))
	defer cancel()

	if err := chromedp.Run(ctx,
		chromedp.Navigate("https://www.google.com/"),
	); err != nil {
		log.Fatal(err)
	}
}

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

Successfully merging this pull request may close these issues.

Connecting to docker chromedp/headless-shell instance via RemoteAllocator
1 participant