| 485 | // Auto-open side panel with retry. chrome.sidePanel.open() can fail silently |
| 486 | // if the window/tab isn't fully ready yet. Retry up to 5 times with backoff. |
| 487 | async function autoOpenSidePanel() { |
| 488 | if (!chrome.sidePanel?.open) return; |
| 489 | for (let attempt = 0; attempt < 5; attempt++) { |
| 490 | try { |
| 491 | const wins = await chrome.windows.getAll({ windowTypes: ['normal'] }); |
| 492 | if (wins.length > 0) { |
| 493 | await chrome.sidePanel.open({ windowId: wins[0].id }); |
| 494 | console.log(`[gstack] Side panel opened on attempt ${attempt + 1}`); |
| 495 | return; // success |
| 496 | } |
| 497 | } catch (e) { |
| 498 | // May throw if window isn't ready or user gesture required |
| 499 | console.log(`[gstack] Side panel open attempt ${attempt + 1} failed:`, e.message); |
| 500 | } |
| 501 | // Backoff: 500ms, 1000ms, 2000ms, 3000ms, 5000ms |
| 502 | await new Promise(r => setTimeout(r, [500, 1000, 2000, 3000, 5000][attempt])); |
| 503 | } |
| 504 | console.log('[gstack] Side panel auto-open failed after 5 attempts'); |
| 505 | } |
| 506 | |
| 507 | // Fire on install/update |
| 508 | chrome.runtime.onInstalled.addListener(() => { |