@@ -12,7 +12,7 @@ import {
1212import { captureEvent , getClient , getCurrentScope } from '@sentry/node' ;
1313import { app , ipcMain , protocol , WebContents , webContents } from 'electron' ;
1414import { eventFromEnvelope } from '../common/envelope.js' ;
15- import { ipcChannelUtils , IPCMode , PROTOCOL_SCHEME , RendererStatus } from '../common/ipc.js' ;
15+ import { ipcChannelUtils , IPCMode , IpcUtils , RendererStatus } from '../common/ipc.js' ;
1616import { registerProtocol } from './electron-normalize.js' ;
1717import { createRendererEventLoopBlockStatusHandler } from './integrations/renderer-anr.js' ;
1818import { rendererProfileFromIpc } from './integrations/renderer-profiling.js' ;
@@ -24,11 +24,6 @@ import { SDK_VERSION } from './version.js';
2424let KNOWN_RENDERERS : Set < number > | undefined ;
2525let WINDOW_ID_TO_WEB_CONTENTS : Map < string , number > | undefined ;
2626
27- const SENTRY_CUSTOM_SCHEME = {
28- scheme : PROTOCOL_SCHEME ,
29- privileges : { bypassCSP : true , corsEnabled : true , supportFetchAPI : true , secure : true } ,
30- } ;
31-
3227function newProtocolRenderer ( ) : void {
3328 KNOWN_RENDERERS = KNOWN_RENDERERS || new Set ( ) ;
3429 WINDOW_ID_TO_WEB_CONTENTS = WINDOW_ID_TO_WEB_CONTENTS || new Map ( ) ;
@@ -183,20 +178,23 @@ function handleLogFromRenderer(client: Client, options: ElectronMainOptionsInter
183178}
184179
185180/** Enables Electron protocol handling */
186- function configureProtocol ( client : Client , options : ElectronMainOptionsInternal ) : void {
181+ function configureProtocol ( client : Client , ipcUtil : IpcUtils , options : ElectronMainOptionsInternal ) : void {
187182 if ( app . isReady ( ) ) {
188183 throw new Error ( "Sentry SDK should be initialized before the Electron app 'ready' event is fired" ) ;
189184 }
190185
191- const ipcUtil = ipcChannelUtils ( options . ipcNamespace ) ;
186+ const scheme = {
187+ scheme : ipcUtil . namespace ,
188+ privileges : { bypassCSP : true , corsEnabled : true , supportFetchAPI : true , secure : true } ,
189+ } ;
192190
193- protocol . registerSchemesAsPrivileged ( [ SENTRY_CUSTOM_SCHEME ] ) ;
191+ protocol . registerSchemesAsPrivileged ( [ scheme ] ) ;
194192
195193 // We Proxy this function so that later user calls to registerSchemesAsPrivileged don't overwrite our custom scheme
196194 // eslint-disable-next-line @typescript-eslint/unbound-method
197195 protocol . registerSchemesAsPrivileged = new Proxy ( protocol . registerSchemesAsPrivileged , {
198196 apply : ( target , __ , args : Parameters < typeof protocol . registerSchemesAsPrivileged > ) => {
199- target ( [ ...args [ 0 ] , SENTRY_CUSTOM_SCHEME ] ) ;
197+ target ( [ ...args [ 0 ] , scheme ] ) ;
200198 } ,
201199 } ) ;
202200
@@ -206,7 +204,7 @@ function configureProtocol(client: Client, options: ElectronMainOptionsInternal)
206204 . whenReady ( )
207205 . then ( ( ) => {
208206 for ( const sesh of options . getSessions ( ) ) {
209- registerProtocol ( sesh . protocol , PROTOCOL_SCHEME , ( request ) => {
207+ registerProtocol ( sesh . protocol , ipcUtil . namespace , ( request ) => {
210208 const getWebContents = ( ) : WebContents | undefined => {
211209 const webContentsId = request . windowId ? WINDOW_ID_TO_WEB_CONTENTS ?. get ( request . windowId ) : undefined ;
212210 return webContentsId ? webContents . fromId ( webContentsId ) : undefined ;
@@ -237,9 +235,7 @@ function configureProtocol(client: Client, options: ElectronMainOptionsInternal)
237235/**
238236 * Hooks IPC for communication with the renderer processes
239237 */
240- function configureClassic ( client : Client , options : ElectronMainOptionsInternal ) : void {
241- const ipcUtil = ipcChannelUtils ( options . ipcNamespace ) ;
242-
238+ function configureClassic ( client : Client , ipcUtil : IpcUtils , options : ElectronMainOptionsInternal ) : void {
243239 ipcMain . on ( ipcUtil . createKey ( 'start' ) , ( { sender } ) => {
244240 const id = sender . id ;
245241 // Keep track of renderers that are using IPC
@@ -276,13 +272,15 @@ function configureClassic(client: Client, options: ElectronMainOptionsInternal):
276272
277273/** Sets up communication channels with the renderer */
278274export function configureIPC ( client : Client , options : ElectronMainOptionsInternal ) : void {
275+ const ipcUtil = ipcChannelUtils ( options . ipcNamespace ) ;
276+
279277 // eslint-disable-next-line no-bitwise
280278 if ( ( options . ipcMode & IPCMode . Protocol ) > 0 ) {
281- configureProtocol ( client , options ) ;
279+ configureProtocol ( client , ipcUtil , options ) ;
282280 }
283281
284282 // eslint-disable-next-line no-bitwise
285283 if ( ( options . ipcMode & IPCMode . Classic ) > 0 ) {
286- configureClassic ( client , options ) ;
284+ configureClassic ( client , ipcUtil , options ) ;
287285 }
288286}
0 commit comments