File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -370,6 +370,24 @@ function createWindow() {
370370 mainWindow ?. show ( ) ;
371371 } ) ;
372372
373+ // Open external links in the default browser
374+ mainWindow . webContents . setWindowOpenHandler ( ( { url } ) => {
375+ if ( url . startsWith ( 'http:' ) || url . startsWith ( 'https:' ) ) {
376+ shell . openExternal ( url ) ;
377+ }
378+ return { action : 'deny' } ;
379+ } ) ;
380+
381+ mainWindow . webContents . on ( 'will-navigate' , ( event , url ) => {
382+ if ( url !== mainWindow ?. webContents . getURL ( ) && ( url . startsWith ( 'http:' ) || url . startsWith ( 'https:' ) ) ) {
383+ const isLocalhost = url . includes ( 'localhost:' ) || url . includes ( '127.0.0.1:' ) ;
384+ if ( ! isLocalhost ) {
385+ event . preventDefault ( ) ;
386+ shell . openExternal ( url ) ;
387+ }
388+ }
389+ } ) ;
390+
373391 mainWindow . on ( 'closed' , ( ) => {
374392 mainWindow = null ;
375393 } ) ;
You can’t perform that action at this time.
0 commit comments