Browse Source

调整验证函数

torsen
453530270@qq.com 1 year ago
parent
commit
73a7b393e5
  1. 61
      douyin/background.js

61
douyin/background.js

@ -22,7 +22,7 @@ async function checkProxyAvailability(proxyConfig) {
resolve(false); resolve(false);
}, timeoutDuration); }, timeoutDuration);
xhr.onreadystatechange = function() { xhr.onreadystatechange = function () {
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
clearTimeout(timeoutHandler); clearTimeout(timeoutHandler);
if (xhr.status === 200) { if (xhr.status === 200) {
@ -35,7 +35,7 @@ async function checkProxyAvailability(proxyConfig) {
} }
}; };
xhr.onerror = function() { xhr.onerror = function () {
clearTimeout(timeoutHandler); clearTimeout(timeoutHandler);
console.log(`代理 ${proxyConfig.host}:${proxyConfig.port} 连接错误`); console.log(`代理 ${proxyConfig.host}:${proxyConfig.port} 连接错误`);
resolve(false); resolve(false);
@ -68,11 +68,13 @@ function setProxyForWindow(proxyConfig, windowId, callback) {
windowProxyMap.set(windowId, proxyConfig); windowProxyMap.set(windowId, proxyConfig);
// 设置认证监听器 // 设置认证监听器
const authHandler = function(details) { const authHandler = function (details) {
console.log("=========PROXY CONFIG===========",proxyConfig)
return { return {
authCredentials: { authCredentials: {
username: proxyConfig.username, username: "hwfq28m43",
password: proxyConfig.password password: "YW29ABi6"
} }
}; };
}; };
@ -80,11 +82,17 @@ function setProxyForWindow(proxyConfig, windowId, callback) {
// 移除之前的监听器(如果存在) // 移除之前的监听器(如果存在)
try { try {
chrome.webRequest.onAuthRequired.removeListener(authHandler); chrome.webRequest.onAuthRequired.removeListener(authHandler);
} catch (e) {} } catch (e) { }
// 添加新的监听器 // 添加新的监听器
chrome.webRequest.onAuthRequired.addListener( chrome.webRequest.onAuthRequired.addListener(
authHandler, // authHandler,
function(details,callbackFn){
console.log("onAuthRequired!", details, callbackFn);
callbackFn({
authCredentials: {username: "hwfq28m43", password: "YW29ABi6"}
});
},
{ urls: ["<all_urls>"] }, { urls: ["<all_urls>"] },
["asyncBlocking"] ["asyncBlocking"]
); );
@ -98,7 +106,16 @@ function setProxyForWindow(proxyConfig, windowId, callback) {
scheme: "http", scheme: "http",
host: proxyConfig.host, host: proxyConfig.host,
port: parseInt(proxyConfig.port) port: parseInt(proxyConfig.port)
},
httpsProxy:{
// 添加 HTTPS 代理规则
scheme: "http",
host: proxyConfig.host,
port: parseInt(proxyConfig.port),
username: proxyConfig.username,
password: proxyConfig.password
} }
} }
}, },
scope: "regular" scope: "regular"
@ -107,7 +124,7 @@ function setProxyForWindow(proxyConfig, windowId, callback) {
// 设置代理 // 设置代理
chrome.proxy.settings.set( chrome.proxy.settings.set(
config, config,
function() { function () {
if (chrome.runtime.lastError) { if (chrome.runtime.lastError) {
console.error('设置代理失败:', chrome.runtime.lastError); console.error('设置代理失败:', chrome.runtime.lastError);
callback(chrome.runtime.lastError); callback(chrome.runtime.lastError);
@ -117,15 +134,15 @@ function setProxyForWindow(proxyConfig, windowId, callback) {
console.log(`窗口 ${windowId} 代理设置成功`); console.log(`窗口 ${windowId} 代理设置成功`);
// 刷新标签页 // 刷新标签页
chrome.tabs.query({ windowId: windowId }, function(tabs) { chrome.tabs.query({ windowId: windowId }, function (tabs) {
if (tabs.length === 0) { if (tabs.length === 0) {
callback(null, true); callback(null, true);
return; return;
} }
let refreshedCount = 0; let refreshedCount = 0;
tabs.forEach(function(tab) { tabs.forEach(function (tab) {
chrome.tabs.reload(tab.id, { bypassCache: true }, function() { chrome.tabs.reload(tab.id, { bypassCache: true }, function () {
refreshedCount++; refreshedCount++;
if (refreshedCount === tabs.length) { if (refreshedCount === tabs.length) {
callback(null, true); callback(null, true);
@ -170,14 +187,14 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
chrome.windows.create({ chrome.windows.create({
incognito: true, incognito: true,
url: "https://www.douyin.com" url: "https://www.douyin.com"
}, function(window) { }, function (window) {
console.log('抖音无痕窗口已打开'); console.log('抖音无痕窗口已打开');
}); });
} else if (request.action === 'openLiveIncognito') { } else if (request.action === 'openLiveIncognito') {
chrome.windows.create({ chrome.windows.create({
incognito: true, incognito: true,
url: request.url url: request.url
}, function(window) { }, function (window) {
console.log('直播无痕窗口已打开'); console.log('直播无痕窗口已打开');
}); });
} }
@ -222,7 +239,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'checkStatus') { if (request.action === 'checkStatus') {
let status = '正常'; let status = '正常';
sendResponse({status: status}); sendResponse({ status: status });
} }
if (request.action === 'openLiveWithProxy') { if (request.action === 'openLiveWithProxy') {
@ -364,12 +381,13 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
return true; return true;
} }
// 清除代理信息
if (request.action === 'clearProxy') { if (request.action === 'clearProxy') {
try { try {
// 清除代理设置 // 清除代理设置
chrome.proxy.settings.clear( chrome.proxy.settings.clear(
{ scope: "regular" }, { scope: "regular" },
async function() { async function () {
if (chrome.runtime.lastError) { if (chrome.runtime.lastError) {
console.error('清除代理设置失败:', chrome.runtime.lastError); console.error('清除代理设置失败:', chrome.runtime.lastError);
sendResponse({ success: false, error: chrome.runtime.lastError.message }); sendResponse({ success: false, error: chrome.runtime.lastError.message });
@ -456,6 +474,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
return true; return true;
} }
// 当前代理
if (request.action === 'getCurrentProxy') { if (request.action === 'getCurrentProxy') {
try { try {
const windowId = request.windowId; const windowId = request.windowId;
@ -488,13 +507,14 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
} }
chrome.webRequest.onCompleted.addListener( chrome.webRequest.onCompleted.addListener(
function(details) { function (details) {
console.log("请求完成:", details); console.log("请求完成:", details);
}, },
{urls: ["<all_urls>"]} { urls: ["<all_urls>"] }
); );
}); });
// 新窗口监听
chrome.windows.onCreated.addListener((window) => { chrome.windows.onCreated.addListener((window) => {
console.log('新窗口创:', { console.log('新窗口创:', {
id: window.id, id: window.id,
@ -507,6 +527,7 @@ chrome.windows.onCreated.addListener((window) => {
}); });
}); });
// 新标签监听
chrome.tabs.onCreated.addListener((tab) => { chrome.tabs.onCreated.addListener((tab) => {
console.log('新标签创建:', { console.log('新标签创建:', {
id: tab.id, id: tab.id,
@ -517,7 +538,7 @@ chrome.tabs.onCreated.addListener((tab) => {
// 修改错误监听器,添加更多需要忽略的误类型 // 修改错误监听器,添加更多需要忽略的误类型
chrome.webRequest.onErrorOccurred.addListener( chrome.webRequest.onErrorOccurred.addListener(
function(details) { function (details) {
// 扩展需要忽略的错误类型列表 // 扩展需要忽略的错误类型列表
const ignoredErrors = [ const ignoredErrors = [
'net::ERR_ABORTED', // 请求中断 'net::ERR_ABORTED', // 请求中断
@ -581,7 +602,7 @@ chrome.webRequest.onErrorOccurred.addListener(
} }
} }
}, },
{urls: ["<all_urls>"]} { urls: ["<all_urls>"] }
); );
chrome.windows.onRemoved.addListener((windowId) => { chrome.windows.onRemoved.addListener((windowId) => {
@ -620,7 +641,7 @@ chrome.windows.onRemoved.addListener((windowId) => {
// 添加证书错误处理 // 添加证书错误处理
chrome.webRequest.onErrorOccurred.addListener( chrome.webRequest.onErrorOccurred.addListener(
function(details) { function (details) {
if (details.error && details.error.includes('ERR_CERT')) { if (details.error && details.error.includes('ERR_CERT')) {
console.log('忽略证书错误:', details.url); console.log('忽略证书错误:', details.url);
return { cancel: false }; return { cancel: false };

Loading…
Cancel
Save