yakit mitm config

This commit is contained in:
go0p
2026-08-06 15:11:35 +08:00
committed by go0p
parent 3166331cf3
commit 22f73e67e8
4 changed files with 94 additions and 3 deletions
+51 -1
View File
@@ -292,7 +292,54 @@ async function queueProxyLog(details, error = null) {
}
}
// 导出代理处理器设置函数
// 添加 URL 拦截处理
function setupUrlInterceptor() {
chrome.webNavigation.onBeforeNavigate.addListener(async (details) => {
try {
const url = new URL(details.url);
if (url.hostname === 'mitm') {
// 解析参数
const host = url.searchParams.get('host');
const port = parseInt(url.searchParams.get('port') || '0');
const scheme = url.searchParams.get('scheme');
if (host && port && scheme) {
// 创建新的代理配置
const newConfig = {
id: Date.now().toString(),
name: "Yakit MITM",
proxyType: 'fixed_servers',
scheme: scheme,
host: host,
port: port,
enabled: true
};
// 直接使用 proxyStore 实例的方法
const result = await proxyStore.addAndEnableProxy(newConfig);
if (result.success) {
// 重定向回 mitm 页面
chrome.tabs.update(details.tabId, {
url: "http://mitm/"
});
} else {
console.error('Failed to add and enable proxy:', result.error);
}
}
}
} catch (error) {
console.error('Error handling proxy URL:', error);
}
}, {
url: [{
hostEquals: 'mitm'
}]
});
}
// 修改 setupProxyHandlers 函数
export function setupProxyHandlers() {
// 设置代理错误处理和认证
ProxyAuth.setupErrorHandler();
@@ -300,6 +347,9 @@ export function setupProxyHandlers() {
// 设置代理请求监听器
setupProxyRequestListener();
// 设置 URL 拦截器
setupUrlInterceptor();
// 消息监听器
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {