mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-07 14:06:42 +02:00
feat: sidebar debug visibility + auth race tests
- Show attempt count in loading screen ("Connecting... attempt 3")
- After 5 failed attempts, show debug details (port, connected, token)
so stuck users can see exactly what's failing
- Add 4 tests: getPort includes token, tryConnect uses token,
dead state exists with MAX_RECONNECT_ATTEMPTS, reconnectAttempts visible
This commit is contained in:
@@ -1392,12 +1392,31 @@ document.getElementById('conn-copy').addEventListener('click', () => {
|
||||
});
|
||||
|
||||
// Try to connect immediately, retry every 2s until connected
|
||||
let connectAttempts = 0;
|
||||
function tryConnect() {
|
||||
connectAttempts++;
|
||||
const loadingEl = document.getElementById('chat-loading');
|
||||
if (loadingEl) {
|
||||
const detail = connectAttempts <= 1 ? 'Connecting...'
|
||||
: `Connecting... (attempt ${connectAttempts})`;
|
||||
const p = loadingEl.querySelector('p');
|
||||
if (p) p.textContent = detail;
|
||||
}
|
||||
chrome.runtime.sendMessage({ type: 'getPort' }, (resp) => {
|
||||
if (resp && resp.port && resp.connected) {
|
||||
const url = `http://127.0.0.1:${resp.port}`;
|
||||
updateConnection(url, resp.token || null);
|
||||
} else {
|
||||
// Show debug info after 5 failed attempts
|
||||
if (connectAttempts >= 5 && loadingEl) {
|
||||
const p = loadingEl.querySelector('p');
|
||||
if (p) {
|
||||
const port = resp?.port || '?';
|
||||
const connected = resp?.connected || false;
|
||||
const hasToken = !!(resp?.token);
|
||||
p.textContent = `Waiting for server... port:${port} connected:${connected} token:${hasToken} (attempt ${connectAttempts})`;
|
||||
}
|
||||
}
|
||||
setTimeout(tryConnect, 2000);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user