experiments in a post-browser web
10
fork

Configure Feed

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

fix(profiles): register peek:// protocol on profile session

The peek:// protocol handler was only registered on defaultSession.
When using profile-specific sessions (persist:dev), the protocol
wasn't available, causing pages to hang on load.

- Extract protocol handler to reusable function
- Add registerProtocolOnSession() to protocol.ts
- Call it when creating profile session in session-partition.ts

+29 -8
+1 -1
backend/electron/main.ts
··· 875 875 backgroundColor: featuresMap.transparent ? undefined : getSystemThemeBackgroundColor(), 876 876 webPreferences: { 877 877 preload: preloadPath, 878 - session: profileSession, 878 + session: getProfileSession(), 879 879 } 880 880 }; 881 881
+24 -7
backend/electron/protocol.ts
··· 149 149 } 150 150 151 151 /** 152 - * Initialize the protocol handler 153 - * Must be called after app.ready 152 + * The protocol request handler - extracted so it can be registered on multiple sessions 154 153 */ 155 - export function initProtocol(appRootDir: string): void { 156 - rootDir = appRootDir; 157 - 158 - protocol.handle(APP_SCHEME, async (req) => { 154 + async function handleProtocolRequest(req: Request): Promise<Response> { 159 155 let { host, pathname } = new URL(req.url); 160 156 161 157 // trim leading slash ··· 289 285 const fileURL = pathToFileURL(absolutePath).toString(); 290 286 291 287 return net.fetch(fileURL); 292 - }); 288 + } 289 + 290 + /** 291 + * Initialize the protocol handler on the default session 292 + * Must be called after app.ready 293 + */ 294 + export function initProtocol(appRootDir: string): void { 295 + rootDir = appRootDir; 296 + protocol.handle(APP_SCHEME, handleProtocolRequest); 297 + } 298 + 299 + /** 300 + * Register the protocol handler on a specific session 301 + * Call this for profile sessions to enable peek:// URLs 302 + */ 303 + export function registerProtocolOnSession(session: Electron.Session): void { 304 + if (!rootDir) { 305 + console.error('[protocol] Cannot register on session - initProtocol not called yet'); 306 + return; 307 + } 308 + session.protocol.handle(APP_SCHEME, handleProtocolRequest); 309 + DEBUG && console.log('[protocol] Registered peek:// handler on session'); 293 310 }
+4
backend/electron/session-partition.ts
··· 19 19 import { session, Session } from 'electron'; 20 20 import fs from 'node:fs'; 21 21 import path from 'node:path'; 22 + import { registerProtocolOnSession } from './protocol.js'; 22 23 23 24 const DEBUG = !!process.env.DEBUG; 24 25 ··· 49 50 const partitionString = getPartitionString(currentProfileId); 50 51 profileSession = session.fromPartition(partitionString); 51 52 DEBUG && console.log('[session] Created profile session:', partitionString); 53 + 54 + // Register the peek:// protocol handler on the profile session 55 + registerProtocolOnSession(profileSession); 52 56 } 53 57 54 58 return profileSession;