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

Launcher with custom http.Client #1121

Open
rkuska opened this issue Oct 10, 2024 · 5 comments
Open

Launcher with custom http.Client #1121

rkuska opened this issue Oct 10, 2024 · 5 comments
Labels
enhance New feature or request

Comments

@rkuska
Copy link

rkuska commented Oct 10, 2024

Rod Version: v0.116.2

The code to demonstrate your question

I currently run headless-browser in google cloud run service using the go-rod image. From other service I connect to it via

launcher.NewManaged(browserURL)

What you got

The problem is that this request is executed by default http.Get request and it fails because it is not authorized (missing headers). So every call from my other service ends up with 403 when trying to setup the launcher and create a browser.

What you expect to see

I would expect to be able to inject a custom http.Client that would handle the authorization.

What have you tried to solve the question

I've tried navigating the code but it seems like the http.Get is hardcoded.

@rkuska rkuska added the question Questions related to rod label Oct 10, 2024
@ysmood
Copy link
Member

ysmood commented Oct 10, 2024

package main

import (
	"context"

	"github.com/go-rod/rod"
	"github.com/go-rod/rod/lib/cdp"
	"github.com/go-rod/rod/lib/launcher"
)

func main() {
	l := launcher.MustNewManaged("")

	u, h := l.ClientHeader()

	h.Set("My-Header", "my-header-value")

	client, err := cdp.StartWithURL(context.Background(), u, h)
	if err != nil {
		panic(err)
	}

	browser := rod.New().Client(client).MustConnect()

	browser.MustVersion()
}

Copy link

Please fix the format of your markdown:

7 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]

generated by check-issue

@rkuska
Copy link
Author

rkuska commented Oct 10, 2024

package main

import (
	"context"

	"github.com/go-rod/rod"
	"github.com/go-rod/rod/lib/cdp"
	"github.com/go-rod/rod/lib/launcher"
)

func main() {
	l := launcher.MustNewManaged("")

	u, h := l.ClientHeader()

	h.Set("My-Header", "my-header-value")

	client, err := cdp.StartWithURL(context.Background(), u, h)
	if err != nil {
		panic(err)
	}

	browser := rod.New().Client(client).MustConnect()

	browser.MustVersion()
}

The problem is that following code:

	res, err := http.Get(toHTTP(*u).String()) //nolint: noctx
	if err != nil {
		return nil, err
	}

Is part of the call to MustNewManaged and this will fail even before setting the headers.

https://github.com/go-rod/rod/blob/main/lib/launcher/manager.go#L54

@ysmood
Copy link
Member

ysmood commented Oct 10, 2024

I see, then we need a new method to support this requirement.

@ysmood ysmood added enhance New feature or request and removed question Questions related to rod labels Oct 10, 2024
@ysmood
Copy link
Member

ysmood commented Oct 10, 2024

Before the new version of rod, you might have to use a proxy to handle the extra http header for your service.

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

No branches or pull requests

2 participants