···247247 console.error('[page] Load failed:', e.errorCode, e.errorDescription);
248248});
249249250250+// Set default background color on webview content if the page doesn't set one
251251+// This prevents white-text-on-transparent issues for pages that assume a background
252252+webview.addEventListener('dom-ready', async () => {
253253+ try {
254254+ // Get the current theme to determine light/dark mode
255255+ const theme = await api.theme.get();
256256+ const isDark = theme?.isDark || theme?.effectiveScheme === 'dark';
257257+ const defaultBg = isDark ? '#1a1a1a' : '#ffffff';
258258+259259+ // Inject CSS that sets a default background only if the page doesn't have one
260260+ // Uses :where() for zero specificity so any page CSS will override it
261261+ const css = `
262262+ :where(html:not([style*="background"]):not([class])),
263263+ :where(body:not([style*="background"])) {
264264+ background-color: ${defaultBg};
265265+ }
266266+ /* Fallback: if html/body have no explicit background, set on html */
267267+ html {
268268+ background-color: ${defaultBg};
269269+ }
270270+ `;
271271+272272+ // Also run JS to check computed styles and set background only if truly transparent
273273+ const js = `
274274+ (function() {
275275+ const defaultBg = '${defaultBg}';
276276+277277+ // Check if body has a background set (either directly or via CSS)
278278+ const bodyStyle = window.getComputedStyle(document.body);
279279+ const htmlStyle = window.getComputedStyle(document.documentElement);
280280+281281+ // rgba(0, 0, 0, 0) is the default "transparent" value
282282+ const isTransparent = (color) => {
283283+ if (!color) return true;
284284+ if (color === 'transparent') return true;
285285+ if (color === 'rgba(0, 0, 0, 0)') return true;
286286+ return false;
287287+ };
288288+289289+ const bodyBgTransparent = isTransparent(bodyStyle.backgroundColor);
290290+ const htmlBgTransparent = isTransparent(htmlStyle.backgroundColor);
291291+292292+ // Only set background if both html and body are transparent
293293+ if (bodyBgTransparent && htmlBgTransparent) {
294294+ document.documentElement.style.backgroundColor = defaultBg;
295295+ }
296296+ })();
297297+ `;
298298+299299+ await webview.insertCSS(css);
300300+ await webview.executeJavaScript(js);
301301+ DEBUG && console.log('[page] Injected default background color:', defaultBg);
302302+ } catch (err) {
303303+ console.error('[page] Failed to inject default background:', err);
304304+ }
305305+});
306306+250307// --- Commands ---
251308252309api.commands.register({