chromedp.ProxyServer is a browser-launch option. Apply it to the allocator that creates the Chromium process:

opts := append(chromedp.DefaultExecAllocatorOptions[:],
    chromedp.ProxyServer("http://proxy.example:8080"),
)
allocCtx, cancelAllocator := chromedp.NewExecAllocator(
    context.Background(), opts...,
)
defer cancelAllocator()

tabCtx, cancelTab := chromedp.NewContext(allocCtx)
defer cancelTab()
err := chromedp.Run(tabCtx,
    chromedp.Navigate("https://www.example.com/"),
)

The code belongs in the application's existing function, with normal error handling for err. NewContext inherits the allocator from allocCtx. A context made from another parent can create a different browser without that option.

The proxy URL identifies an HTTP listener, with public candidates available in the HTTP proxy list; the page remains an HTTPS destination. ProxyServer maps to Chromium's --proxy-server flag, not to Go's net/http proxy configuration.

Chromium does not accept username/password credentials embedded in a manual proxy URL. An authenticated endpoint needs a supported browser authentication or intermediary arrangement; adding user:password to this flag is not equivalent to HTTP client URL authentication. Chrome’s CDP authentication event flow is one supported path for handling the intended proxy challenge.

Keep the allocator alive until browser work completes. Its cancellation also belongs to the process cleanup, while tab cancellation scopes the associated browser context.

متعلقہ مضامین