experiments in a post-browser web
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(page): apply background detection to non-canvas web pages (slides)

+46
+46
backend/electron/ipc.ts
··· 2109 2109 // Load the URL AFTER mode/context is set, so page.js can read inherited mode 2110 2110 await win.loadURL(loadUrl); 2111 2111 2112 + // Background detection for non-canvas web pages (slides, modals, quick-views). 2113 + // Canvas pages get this via the webview dom-ready handler in page.js. 2114 + // Non-canvas pages load directly in the BrowserWindow, so we detect here. 2115 + // Without this, pages that don't set a background show dark text on a dark 2116 + // BrowserWindow backgroundColor — unreadable in dark mode. 2117 + if (isWebPage && !useCanvas) { 2118 + win.webContents.on('dom-ready', async () => { 2119 + try { 2120 + const needsBackground = await win.webContents.executeJavaScript(` 2121 + (function() { 2122 + function isTransparentColor(color) { 2123 + if (!color) return true; 2124 + if (color === 'transparent') return true; 2125 + if (color === 'rgba(0, 0, 0, 0)') return true; 2126 + var rgbaMatch = color.match(/rgba\\s*\\(\\s*\\d+\\s*,\\s*\\d+\\s*,\\s*\\d+\\s*,\\s*([\\d.]+)\\s*\\)/); 2127 + if (rgbaMatch && parseFloat(rgbaMatch[1]) === 0) return true; 2128 + return false; 2129 + } 2130 + function hasBackground(el) { 2131 + if (!el) return false; 2132 + var style = window.getComputedStyle(el); 2133 + var bgColor = style.backgroundColor; 2134 + var hasColor = !isTransparentColor(bgColor); 2135 + var bgImage = style.backgroundImage; 2136 + var hasImage = bgImage && bgImage !== 'none'; 2137 + return hasColor || hasImage; 2138 + } 2139 + var html = document.documentElement; 2140 + var body = document.body; 2141 + return !(hasBackground(html) || hasBackground(body)); 2142 + })(); 2143 + `); 2144 + if (needsBackground) { 2145 + await win.webContents.executeJavaScript(` 2146 + document.documentElement.style.backgroundColor = '#ffffff'; 2147 + `); 2148 + DEBUG && console.log('[non-canvas-bg] No background detected, set default white for window:', win.id); 2149 + } else { 2150 + DEBUG && console.log('[non-canvas-bg] Page has background, skipping default for window:', win.id); 2151 + } 2152 + } catch (err) { 2153 + console.error('[non-canvas-bg] Failed to check/set background:', err); 2154 + } 2155 + }); 2156 + } 2157 + 2112 2158 // Track this load in history (skip internal peek:// URLs) 2113 2159 if (!url.startsWith('peek://')) { 2114 2160 try {