为什么 ProxyServer 不能在 chromedp GO 上运行

Why ProxyServer not working on chromedp GO

我想在 chromedp 上使用代理,但代理似乎不起作用,试过 chromedp.ProxyServer

ctx, cancel := chromedp.NewContext(context.Background())
defer cancel()
chromedp.ProxyServer("http://username:password@proxyserver.com: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
        }))

即使在使用代理之后,我也得到了我的 public ipe。没有error/warnings

试试这个:

o := append(chromedp.DefaultExecAllocatorOptions[:],
    //... any options here
    chromedp.ProxyServer("http://username:password@proxyserver.com:31280"), 
)

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

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