84 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			84 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| // 代理调试工具 - 测试不同的代理配置格式
 | ||
| const { session } = require('electron');
 | ||
| 
 | ||
| async function testProxyFormats() {
 | ||
|   console.log('🔧 测试代理格式修复...\n');
 | ||
| 
 | ||
|   const proxyConfigs = [
 | ||
|     {
 | ||
|       name: 'HTTP代理(带认证)',
 | ||
|       proxyRules: 'http://mNrz1aEg:3xV3dBYB@143.20.228.192:3306',
 | ||
|       expected: '✅ 应该成功'
 | ||
|     },
 | ||
|     {
 | ||
|       name: 'SOCKS5代理(不带认证)',
 | ||
|       proxyRules: 'socks5://143.20.228.192:3306',
 | ||
|       expected: '✅ 应该成功'
 | ||
|     },
 | ||
|     {
 | ||
|       name: 'SOCKS5代理(带认证-新格式)',
 | ||
|       proxyRules: 'socks5://mNrz1aEg:3xV3dBYB@143.20.228.192:3306',
 | ||
|       expected: '✅ 应该成功'
 | ||
|     },
 | ||
|     {
 | ||
|       name: 'SOCKS4代理(带认证-新格式)',
 | ||
|       proxyRules: 'socks4://mNrz1aEg:3xV3dBYB@143.20.228.192:3306',
 | ||
|       expected: '✅ 应该成功'
 | ||
|     },
 | ||
|     {
 | ||
|       name: '错误格式(修复前)',
 | ||
|       proxyRules: 'socks5=socks5://143.20.228.192:3306',
 | ||
|       expected: '❌ 应该失败'
 | ||
|     }
 | ||
|   ];
 | ||
| 
 | ||
|   for (const config of proxyConfigs) {
 | ||
|     console.log(`📡 测试: ${config.name}`);
 | ||
|     console.log(`   代理规则: ${config.proxyRules.replace(/:[^:@]+@/, ':***@')}`);
 | ||
|     console.log(`   预期结果: ${config.expected}`);
 | ||
|     
 | ||
|     try {
 | ||
|       // 创建临时会话
 | ||
|       const partition = `test-${Date.now()}-${Math.random()}`;
 | ||
|       const tmpSession = session.fromPartition(partition, { cache: false });
 | ||
|       
 | ||
|       // 尝试设置代理
 | ||
|       await tmpSession.setProxy({ 
 | ||
|         mode: "fixed_servers", 
 | ||
|         proxyRules: config.proxyRules 
 | ||
|       });
 | ||
|       
 | ||
|       console.log(`   ✅ 代理设置成功 - 格式有效\n`);
 | ||
|       
 | ||
|       // 清理临时会话
 | ||
|       tmpSession.destroy();
 | ||
|       
 | ||
|     } catch (error) {
 | ||
|       console.log(`   ❌ 代理设置失败: ${error.message}`);
 | ||
|       if (error.message.includes('ERR_NO_SUPPORTED_PROXIES')) {
 | ||
|         console.log(`      💡 ERR_NO_SUPPORTED_PROXIES - 格式不被支持`);
 | ||
|       } else if (error.message.includes('ERR_INVALID_ARGUMENT')) {
 | ||
|         console.log(`      💡 ERR_INVALID_ARGUMENT - 参数无效`);
 | ||
|       } else {
 | ||
|         console.log(`      💡 其他错误: ${error.code || 'UNKNOWN'}`);
 | ||
|       }
 | ||
|       console.log('');
 | ||
|     }
 | ||
|   }
 | ||
|   
 | ||
|   console.log('📋 修复总结:');
 | ||
|   console.log('   ✅ 移除了有问题的 electron-session-proxy 包依赖');
 | ||
|   console.log('   ✅ 使用标准的代理URL格式');
 | ||
|   console.log('   ✅ 改进了错误处理和日志记录');
 | ||
|   console.log('   🎯 这应该解决 ECONNRESET 和 ERR_NO_SUPPORTED_PROXIES 错误');
 | ||
| }
 | ||
| 
 | ||
| // 导出函数供其他模块使用
 | ||
| module.exports = { testProxyFormats };
 | ||
| 
 | ||
| // 如果直接运行此文件
 | ||
| if (require.main === module) {
 | ||
|   console.log('⚠️  这个脚本需要在Electron环境中运行');
 | ||
|   console.log('💡 修复已应用到代码中,请重启应用并测试代理功能');
 | ||
| }
 | 
