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

Can't use proxy and open multiple tabs ? #1456

Open
conku opened this issue Mar 27, 2024 · 0 comments
Open

Can't use proxy and open multiple tabs ? #1456

conku opened this issue Mar 27, 2024 · 0 comments

Comments

@conku
Copy link

conku commented Mar 27, 2024

What versions are you running?

github.com/chromedp/chromedp v0.9.5
google-chrome 123.0.6312.58
go 1.21.3

What did you do? Include clear steps.

package main

import (
	"context"

	"github.com/chromedp/cdproto/cdp"
	"github.com/chromedp/cdproto/target"
	"github.com/chromedp/chromedp"
)

func main() {
	browserCtx, cancel := chromedp.NewContext(context.Background())
	defer cancel()
	if err := chromedp.Run(browserCtx); err != nil {
		panic(err)
	}

	// Create BrowserContext with different proxies.
	var proxy1, proxy2 cdp.BrowserContextID
	if err := chromedp.Run(browserCtx,
		chromedp.ActionFunc(func(ctx context.Context) error {
			c := chromedp.FromContext(ctx)
			var err error
			proxy1, err = target.CreateBrowserContext().
				WithDisposeOnDetach(true).
				WithProxyServer("127.0.0.1:12999").
				Do(cdp.WithExecutor(ctx, c.Browser))
			if err != nil {
				return err
			}
			proxy2, err = target.CreateBrowserContext().
				WithDisposeOnDetach(true).
				WithProxyServer("127.0.0.1:13000").
				Do(cdp.WithExecutor(ctx, c.Browser))
			return err
		}),
	); err != nil {
		panic(err)
	}

	// Use proxy1:
	ctx1, cancel := chromedp.NewContext(browserCtx, chromedp.WithExistingBrowserContext(proxy1))
	defer cancel()
	if err := chromedp.Run(ctx1,
		chromedp.Navigate("http://ipinfo.io"),
	); err != nil {
		panic(err)
	}

	// Use proxy2:
	ctx2, cancel := chromedp.NewContext(browserCtx, chromedp.WithExistingBrowserContext(proxy2))
	defer cancel()
	if err := chromedp.Run(ctx2,
		chromedp.Navigate("http://google.com"),
	); err != nil {
		panic(err)
	}
}

With PR #1237

What did you expect to see?

1 browser with multiple tabs.

What did you see instead?

multiple browsers with 1 tab each.

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

1 participant