You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用headless_chrome crate配置带认证代理报错,如何修复?

解决headless_chrome代理认证导致的net::ERR_NO_SUPPORTED_PROXIES错误

问题原因

Chrome的--proxy-server启动参数不支持直接在代理地址中嵌入用户名和密码(即https://username:password@host:port这种格式),这种写法会被判定为无效代理配置,从而抛出ERR_NO_SUPPORTED_PROXIES错误。

解决方案

拆分代理配置流程:先设置不带认证信息的代理服务器地址,再通过Chrome DevTools协议单独注入代理认证凭据。

修改后的代码示例

use headless_chrome::Browser;
use headless_chrome::LaunchOptions;
use serde_json::json;

fn main() {
    // 仅配置代理服务器地址(不含用户名密码)
    let proxy_server = format!("{}:{}", "proxy_host", "proxy_port");
    let browser = Browser::new(LaunchOptions {
        headless: true,
        // 根据代理实际支持的协议添加前缀,如http://或https://
        proxy_server: Some(&format!("https://{}", proxy_server)),
        ..Default::default()
    }).expect("Failed to launch browser");

    let tab = browser.new_tab().unwrap();

    // 通过DevTools协议设置代理认证信息
    tab.call_method(
        "Network.setProxyAuthenticationCredentials",
        json!({
            "username": "username",
            "password": "password",
            // 可选:指定需要认证的目标域名,填"*"则对所有请求生效
            "origin": "*"
        })
    ).expect("Failed to set proxy authentication");

    // 导航至目标网站
    tab.navigate_to("https://www.semrush.com/login/?src=header&redirect_to=%2F")
        .expect("Failed to navigate");
}

额外注意事项

  • 代理地址的协议前缀(http:///https://)必须与代理服务器实际支持的协议匹配,否则会导致代理连接失败。
  • 提前确认本地网络能正常访问代理服务器,避免因网络连通性问题引发其他错误。

内容的提问来源于stack exchange,提问作者Yuki

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 12:54:57