Add files via upload

Fix: Proxy setup failure handling across scripts:
- Improved error messaging in options.js
- Added 'proxyFailed' message handler in background.js
- Updated UI toggle state in popup.js when proxy fails
This commit is contained in:
DeBros 2025-02-13 12:23:25 +02:00 committed by GitHub
parent 65190ef835
commit 2fdc9dfc08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 44 additions and 3 deletions

View File

@ -1,5 +1,4 @@
let proxies = []; // Initially empty, will be populated from local storage or fetched from the server
let currentProxyIndex = 0; // Start with the first proxy
let proxyEnabled = false;
@ -191,6 +190,7 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
sendResponse({ status: "error", message: "No public proxy available at this moment. Please configure a custom proxy in the settings." });
}
});
return true; // For async response
} else if (message.action === "disableProxy") {
console.log("Disabling proxy...");
clearProxySettings();
@ -238,6 +238,7 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
sendResponse({ status: "error", message: "No public proxy available at this moment. Please configure a custom proxy in the settings." });
}
});
return true; // For async response
} else if (message.type === "disabled") {
clearProxySettings();
chrome.storage.local.set({ proxyEnabled: false, proxyType: null });
@ -252,6 +253,19 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
}
});
}
} else if (message.action === "proxyFailed") {
console.log("Proxy setup failed:", message.error);
clearProxySettings();
chrome.storage.local.set({ proxyEnabled: false, proxyType: null });
chrome.tabs.query({}, function(tabs) {
for (let tab of tabs) {
chrome.tabs.sendMessage(tab.id, {action: "toggleOff"}, function(response) {
if (chrome.runtime.lastError) {
console.warn("Warning: Could not send message to tab " + tab.id + ". Tab might have been closed.", chrome.runtime.lastError.message);
}
});
}
});
} else if (message.action === "updateProxies") {
console.log("Attempting to update proxies...");
fetchProxies().then(() => {

View File

@ -177,8 +177,16 @@ saveSettings.addEventListener("click", () => {
statusMessage.style.fontFamily = "Arial";
statusMessage.style.fontWeight = "bold";
applyProxySettings(proxyIP.value, proxyPort.value, filteredExceptions);
chrome.runtime.sendMessage({ action: "updateProxy", type: "custom", proxy: { host: proxyIP.value, port: parseInt(proxyPort.value) }, exceptions: filteredExceptions });
// Send response to the message sender
chrome.runtime.sendMessage({ action: "updateProxy", type: "custom", proxy: { host: proxyIP.value, port: parseInt(proxyPort.value) }, exceptions: filteredExceptions }, (response) => {
if (chrome.runtime.lastError) {
console.error("Error sending message:", chrome.runtime.lastError);
} else {
console.log("Response received:", response);
}
clearStatusMessage();
});
}
});
})
@ -189,6 +197,16 @@ saveSettings.addEventListener("click", () => {
statusMessage.style.fontFamily = "Arial";
statusMessage.style.fontWeight = "bold";
chrome.proxy.settings.clear({});
// Send a message indicating proxy setup failed
chrome.runtime.sendMessage({ action: "proxyFailed", error: error }, (response) => {
if (chrome.runtime.lastError) {
console.error("Error sending message:", chrome.runtime.lastError);
} else {
console.log("Response received for proxy failure:", response);
}
clearStatusMessage();
});
})
.finally(() => {
// Re-enable the saveSettings button after the check is complete

View File

@ -158,6 +158,15 @@ document.addEventListener("DOMContentLoaded", () => {
statusMessage.style.color = "#f39c12"; // Orange for loading
} else if (message.action === "updateStatus") {
updateStatusFromBackground(message);
} else if (message.action === "toggleOff") {
// This is for when a proxy setup fails
proxyToggle.checked = false;
statusMessage.textContent = "Failed to set up proxy. Please check your settings.";
statusMessage.style.color = "#e74c3c"; // Red for error
// You might want to clear this message after some time or on interaction
setTimeout(() => {
statusMessage.textContent = "";
}, 5000); // Clear after 5 seconds
}
});