Vinyl
    Preparing search index...

    Interface NetworkInformation

    Provides information about the system’s current network connection, such as estimated bandwidth, round-trip time, and connection type. Also exposes events for monitoring changes to the network state.

    interface NetworkInformation {
        downlink: undefined | number;
        effectiveType: NetworkInformationEffectiveType;
        rtt: number;
        saveData: boolean;
        type?: NetworkInformationType;
        addEventListener<K extends "change">(
            type: K,
            listener: (
                this: NetworkInformation,
                ev: NetworkInformationEventMap[K],
            ) => any,
            options?: boolean | AddEventListenerOptions,
        ): void;
        removeEventListener<K extends "change">(
            type: K,
            listener: (
                this: NetworkInformation,
                ev: NetworkInformationEventMap[K],
            ) => any,
            options?: boolean | EventListenerOptions,
        ): void;
    }

    Hierarchy

    • EventTarget
      • NetworkInformation
    Index

    Properties

    downlink: undefined | number

    Approximate downlink speed in megabits per second. Rounded to the nearest 25 kbps, based on recent throughput over active connections. May be undefined if no estimate is available.

    A string describing the general quality of the connection (for example, "4g", "3g"). Determined from both downlink and latency estimates.

    rtt: number

    Estimated round-trip latency of the current connection in milliseconds, rounded to the nearest multiple of 25 ms.

    saveData: boolean

    Indicates whether the user has requested reduced data usage in the user agent’s settings.

    Type of underlying network connection in use (for example, "wifi", "cellular"). May be omitted if unknown.

    Methods

    • Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

      The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

      When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

      When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

      When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

      If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

      The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.

      MDN Reference

      Type Parameters

      • K extends "change"

      Parameters

      Returns void

    • Removes the event listener in target's event listener list with the same type, callback, and options.

      MDN Reference

      Type Parameters

      • K extends "change"

      Parameters

      Returns void