Vishnu V
Vishnu V

Reputation: 412

Why ProxyServer not working on chromedp GO

I want to use proxy on chromedp, but proxy not seems to be working, tried chromedp.ProxyServer

ctx, cancel := chromedp.NewContext(context.Background())
defer cancel()
chromedp.ProxyServer("http://username:[email protected]:31280")
chromedp.Run(ctx,
        chromedp.Navigate("http://wtfismyip.com"),
        chromedp.Sleep(3*time.Second),
        chromedp.ActionFunc(func(ctxt context.Context) error {
            _, _, contentRect, err := page.GetLayoutMetrics().Do(ctxt)
            v := page.Viewport{
                X:      contentRect.X,
                Y:      contentRect.Y,
                Width:  contentRect.Width,
                Height: contentRect.Height,
                Scale:  1,
            }
            buf, err := page.CaptureScreenshot().WithClip(&v).Do(ctxt)
            log.Printf("Write %v", "/tmp/ss.png")
            ioutil.WriteFile("/tmp/ss.png", buf, 0644)
            return err
        }))

I am getting my public ipeven after using proxy. No error/warnings

Upvotes: 2

Views: 2774

Answers (1)

Andyka
Andyka

Reputation: 36

Try this:

o := append(chromedp.DefaultExecAllocatorOptions[:],
    //... any options here
    chromedp.ProxyServer("http://username:[email protected]:31280"), 
)

cx, cancel := chromedp.NewExecAllocator(context.Background(), o...)
defer cancel()

ctx, cancel := chromedp.NewContext(cx)
defer cancel()
//... the rest of your code

Upvotes: 2

Related Questions