@@ -314,7 +314,10 @@ export class StandardController implements IController {
314
314
* Initializer function to perform async startup tasks such as connecting to WAM extension
315
315
* @param request {?InitializeApplicationRequest} correlation id
316
316
*/
317
- async initialize ( request ?: InitializeApplicationRequest ) : Promise < void > {
317
+ async initialize (
318
+ request ?: InitializeApplicationRequest ,
319
+ isBroker ?: boolean
320
+ ) : Promise < void > {
318
321
this . logger . trace ( "initialize called" ) ;
319
322
if ( this . initialized ) {
320
323
this . logger . info (
@@ -339,8 +342,11 @@ export class StandardController implements IController {
339
342
) ;
340
343
this . eventHandler . emitEvent ( EventType . INITIALIZE_START ) ;
341
344
342
- if ( ! request ?. isBroker ) {
343
- this . logMultipleInstances ( initMeasurement ) ;
345
+ // Broker applications are initialized twice, so we avoid double-counting it
346
+ if ( ! isBroker ) {
347
+ try {
348
+ this . logMultipleInstances ( initMeasurement ) ;
349
+ } catch { }
344
350
}
345
351
346
352
await invokeAsync (
@@ -2397,6 +2403,7 @@ export class StandardController implements IController {
2397
2403
) : void {
2398
2404
const clientId = this . config . auth . clientId ;
2399
2405
2406
+ if ( ! window ) return ;
2400
2407
// @ts -ignore
2401
2408
window . msal = window . msal || { } ;
2402
2409
// @ts -ignore
@@ -2405,26 +2412,14 @@ export class StandardController implements IController {
2405
2412
// @ts -ignore
2406
2413
const clientIds : string [ ] = window . msal . clientIds ;
2407
2414
2408
- for ( const currentId of clientIds ) {
2409
- if ( currentId === clientId ) {
2410
- this . logger . warning (
2411
- "There is already an instance of MSAL.js in the window with the same client id."
2412
- ) ;
2413
- // @ts -ignore
2414
- window . msal . clientIds . push ( clientId ) ;
2415
- collectInstanceStats ( clientId , performanceEvent ) ;
2416
- return ;
2417
- }
2418
- }
2419
-
2420
2415
if ( clientIds . length > 0 ) {
2421
- this . logger . warning (
2416
+ this . logger . verbose (
2422
2417
"There is already an instance of MSAL.js in the window."
2423
2418
) ;
2424
2419
}
2425
2420
// @ts -ignore
2426
2421
window . msal . clientIds . push ( clientId ) ;
2427
- collectInstanceStats ( clientId , performanceEvent ) ;
2422
+ collectInstanceStats ( clientId , performanceEvent , this . logger ) ;
2428
2423
}
2429
2424
}
2430
2425
0 commit comments