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

undetected_chromedriver.v2使用proxy_auth_plugin.zip代理不生效问题求助

问题原因排查
  • undetected_chromedriver默认对扩展加载做了严格限制,自定义代理插件被默认的扩展拦截规则屏蔽,没有正常加载运行
  • 代理插件使用的Manifest V2标准在Chrome 90+版本中已经被逐步废弃,部分新版本Chrome会直接禁用V2扩展,导致代理逻辑不生效
  • 代码存在语法错误:time(10)为错误写法,正确写法是time.sleep(10),该错误会直接导致程序运行中断,大概率你忽略了对应的报错信息
解决方案

1. 修复基础语法错误

将代码中所有time(10)替换为time.sleep(10),删除重复的time导入语句。

2. 添加UC扩展放行参数

在uc.ChromeOptions中添加参数放行自定义代理插件的加载和运行权限,同时指定UC启动时不要拦截扩展后台逻辑。

3. (可选适配高版本Chrome)将Manifest V2升级为Manifest V3标准

如果你的Chrome版本在100以上,建议直接更换为V3版本的代理插件配置,避免V2扩展被强制禁用。

修复后的完整可用代码

import time
import os
import zipfile
import undetected_chromedriver.v2 as uc

host = '107.23.19.8'
port = 3135
username = 'ggwp'
password = 'ggwp123'

# Manifest V2版本(Chrome 90以下可用)
manifest_json = """
{
    "version": "1.0.0",
    "manifest_version": 2,
    "name": "Chrome Proxy",
    "permissions": [
        "proxy",
        "tabs",
        "unlimitedStorage",
        "storage",
        "<all_urls>",
        "webRequest",
        "webRequestBlocking"
    ],
    "background": {
        "scripts": ["background.js"]
    },
    "minimum_chrome_version":"22.0.0"
}
"""

background_js = """
var config = {
        mode: "fixed_servers",
        rules: {
          singleProxy: {
            scheme: "http",
            host: "%s",
            port: parseInt(%s)
          },
          bypassList: ["localhost"]
        }
      };

chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});

function callbackFn(details) {
    return {
        authCredentials: {
            username: "%s",
            password: "%s"
        }
    };
}

chrome.webRequest.onAuthRequired.addListener(
            callbackFn,
            {urls: ["<all_urls>"]},
            ['blocking']
);
""" % (host, port , username, password)


def get_chromedriver(use_proxy=False, user_agent=None):
    chrome_options = uc.ChromeOptions()
    if use_proxy:
        pluginfile = 'proxy_auth_plugin.zip'

        with zipfile.ZipFile(pluginfile, 'w') as zp:
            zp.writestr("manifest.json", manifest_json)
            zp.writestr("background.js", background_js)
        # 获取插件绝对路径
        plugin_abs_path = os.path.abspath(pluginfile)
        chrome_options.add_extension(plugin_abs_path)
        # 添加扩展放行参数
        chrome_options.add_argument(f'--disable-extensions-exclude={plugin_abs_path}')
        chrome_options.add_argument('--allow-extension-background-pages')
        chrome_options.add_argument('--disable-web-security')
    if user_agent:
        chrome_options.add_argument(f'--user-agent={user_agent}')
    # 添加use_subprocess参数避免Windows环境启动异常
    driver = uc.Chrome(options=chrome_options, use_subprocess=True)
    return driver 

def main():
    driver = get_chromedriver(use_proxy=True)
    driver.get('https://ipleak.net')
    time.sleep(10)
    driver.quit()

if __name__ == '__main__':
    main()

验证生效方式

启动后访问ipleak.net查看显示的IP是否为代理IP,如果还是本地IP,可打开Chrome的扩展管理页面(chrome://extensions/),查看代理插件是否正常启用,是否有报错提示。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 11:09:04