64 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| // 测试代理修复是否有效
 | ||
| const { session } = require('electron');
 | ||
| 
 | ||
| async function testProxyFormats() {
 | ||
|   console.log('🔧 测试代理格式修复...\n');
 | ||
| 
 | ||
|   const testConfigs = [
 | ||
|     {
 | ||
|       name: 'HTTP代理',
 | ||
|       proxyRules: 'http://mNrz1aEg:3xV3dBYB@143.20.228.192:3306'
 | ||
|     },
 | ||
|     {
 | ||
|       name: 'SOCKS5代理(修复前-错误格式)',
 | ||
|       proxyRules: 'socks5=socks5://143.20.228.192:3306'
 | ||
|     },
 | ||
|     {
 | ||
|       name: 'SOCKS5代理(修复后-正确格式)',
 | ||
|       proxyRules: 'socks5://143.20.228.192:3306'
 | ||
|     }
 | ||
|   ];
 | ||
| 
 | ||
|   for (const config of testConfigs) {
 | ||
|     console.log(`📡 测试 ${config.name}:`);
 | ||
|     console.log(`   代理规则: ${config.proxyRules}`);
 | ||
|     
 | ||
|     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`);
 | ||
|       
 | ||
|     } catch (error) {
 | ||
|       console.log(`   ❌ 代理设置失败: ${error.message}`);
 | ||
|       if (error.message.includes('ERR_NO_SUPPORTED_PROXIES')) {
 | ||
|         console.log(`      💡 这是 ERR_NO_SUPPORTED_PROXIES 错误 - 格式不被支持\n`);
 | ||
|       } else {
 | ||
|         console.log(`      💡 其他错误: ${error.code || error.message}\n`);
 | ||
|       }
 | ||
|     }
 | ||
|   }
 | ||
|   
 | ||
|   console.log('📋 总结:');
 | ||
|   console.log('   ✅ 修复了 socks4=socks4:// 和 socks5=socks5:// 的错误格式');
 | ||
|   console.log('   ✅ 现在使用正确的 socks4:// 和 socks5:// 格式');
 | ||
|   console.log('   🎯 这应该解决 ERR_NO_SUPPORTED_PROXIES 错误');
 | ||
| }
 | ||
| 
 | ||
| // 如果在Electron环境中运行
 | ||
| if (typeof require !== 'undefined' && require.main === module) {
 | ||
|   console.log('⚠️  这个脚本需要在Electron环境中运行');
 | ||
|   console.log('💡 修复已应用到代码中,请重启应用并测试代理功能');
 | ||
| } else {
 | ||
|   testProxyFormats().catch(console.error);
 | ||
| }
 | ||
| 
 | ||
| module.exports = { testProxyFormats };
 | 
