@@ -109,6 +109,9 @@ function computeBgColor(fullConfig: FullConfigType): string {
109109const wcIdToWaveTabMap = new Map < number , WaveTabView > ( ) ;
110110
111111export function getWaveTabViewByWebContentsId ( webContentsId : number ) : WaveTabView {
112+ if ( webContentsId == null ) {
113+ return null ;
114+ }
112115 return wcIdToWaveTabMap . get ( webContentsId ) ;
113116}
114117
@@ -154,14 +157,15 @@ export class WaveTabView extends WebContentsView {
154157 this . waveReadyPromise . then ( ( ) => {
155158 this . isWaveReady = true ;
156159 } ) ;
157- wcIdToWaveTabMap . set ( this . webContents . id , this ) ;
160+ const wcId = this . webContents . id ;
161+ wcIdToWaveTabMap . set ( wcId , this ) ;
158162 if ( isDevVite ) {
159163 this . webContents . loadURL ( `${ process . env . ELECTRON_RENDERER_URL } /index.html` ) ;
160164 } else {
161165 this . webContents . loadFile ( path . join ( getElectronAppBasePath ( ) , "frontend" , "index.html" ) ) ;
162166 }
163167 this . webContents . on ( "destroyed" , ( ) => {
164- wcIdToWaveTabMap . delete ( this . webContents . id ) ;
168+ wcIdToWaveTabMap . delete ( wcId ) ;
165169 removeWaveTabView ( this . waveTabId ) ;
166170 this . isDestroyed = true ;
167171 } ) ;
@@ -283,7 +287,6 @@ function checkAndEvictCache(): void {
283287 // Otherwise, sort by lastUsedTs
284288 return a . lastUsedTs - b . lastUsedTs ;
285289 } ) ;
286- const now = Date . now ( ) ;
287290 for ( let i = 0 ; i < sorted . length - MaxCacheSize ; i ++ ) {
288291 tryEvictEntry ( sorted [ i ] . waveTabId ) ;
289292 }
@@ -313,6 +316,9 @@ export async function getOrCreateWebViewForTab(waveWindowId: string, tabId: stri
313316 tabView . webContents . on ( "will-frame-navigate" , shFrameNavHandler ) ;
314317 tabView . webContents . on ( "did-attach-webview" , ( event , wc ) => {
315318 wc . setWindowOpenHandler ( ( details ) => {
319+ if ( wc == null || wc . isDestroyed ( ) || tabView . webContents == null || tabView . webContents . isDestroyed ( ) ) {
320+ return { action : "deny" } ;
321+ }
316322 tabView . webContents . send ( "webview-new-window" , wc . id , details ) ;
317323 return { action : "deny" } ;
318324 } ) ;
0 commit comments