Table of contents
- 1. Attributes
- 2. Events
- 3. Example
- 4. Browser compatibility
- 4.1. Gecko notes
- 5. Specification
- 6. See also
The Network Information API provides information about the system's connection, such as the current bandwidth of the user's device or whether the connection is metered. This could be used to select high definition content or low definition content based on the user's connection.
Attributes
bandwidth- Read only. A double representing the estimated download bandwidth (in MB/s) of the current connection.
0if the user is currently offline andinfinityif the bandwidth is unknown. metered- Read only. A
Booleanreturningtrueif the connection is metered (e.g. pay-per-use).
Events
onchange- Fires when the connection changes.
Example
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
function updateConnectionStatus() {
alert("Connection bandwidth: " + connection.bandwidth + " MB/s");
if (connection.metered) {
alert("The connection is metered!");
}
}
connection.addEventListener("change", updateConnectionStatus);
updateConnectionStatus();
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 20? webkit | 12.0 moz (see notes) | -- | -- | -- |
| Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | -- | 12.0 moz (see notes) | -- | -- | -- |
Gecko notes
- The Network API can be disabled using the
dom.network.enabledpreference. - The
meteredattribute isfalseby default and can be set using thedom.network.meteredpreference (see bug 716943 for marking the connection as metered when roaming). - As of Gecko 12.0, the Network API is implemented for Android systems only. Support for Linux ( bug 712442 ) and Windows ( bug 721306 ) systems is in progress.
- Before Gecko 14.0,
navigator.mozConnectionwas not an instance of EventTarget and noaddEventListenercould be called. This has been fixed ( bug 735261 ).


Mozilla Developer Network