wangzhibo
2026-05-09 53418655c061ac26f66058253f39200aced1ab1d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License.
 */
 
import { InProgressPerformanceEvent, Logger } from "@azure/msal-common/browser";
 
interface NetworkConnection {
    effectiveType?: string;
    rtt?: number;
}
 
/**
 * Get network information for telemetry purposes. This is only supported in Chromium-based browsers.
 * @returns Network connection information, or an empty object if not available.
 */
export function getNetworkInfo(): NetworkConnection {
    if (typeof window === "undefined" || !window.navigator) {
        return {};
    }
    const connection: NetworkConnection | undefined =
        "connection" in window.navigator
            ? (
                  window.navigator as Navigator & {
                      connection: NetworkConnection;
                  }
              ).connection
            : undefined;
    return {
        effectiveType: connection?.effectiveType,
        rtt: connection?.rtt,
    };
}
 
export function collectInstanceStats(
    currentClientId: string,
    performanceEvent: InProgressPerformanceEvent,
    logger: Logger,
    correlationId: string
): void {
    const frameInstances: string[] =
        // @ts-ignore
        window.msal?.clientIds || [];
 
    const msalInstanceCount = frameInstances.length;
 
    const sameClientIdInstanceCount = frameInstances.filter(
        (i) => i === currentClientId
    ).length;
 
    if (sameClientIdInstanceCount > 1) {
        logger.warning(
            "There is already an instance of MSAL.js in the window with the same client id.",
            correlationId
        );
    }
    performanceEvent.add({
        msalInstanceCount: msalInstanceCount,
        sameClientIdInstanceCount: sameClientIdInstanceCount,
    });
}