window.navigator.connection

« Gecko DOM Reference

This is an experimental feature
Because this feature is still in development in some browsers, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental feature is subject to change in future version of browsers as the spec changes.

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. 0 if the user is currently offline and infinity if the bandwidth is unknown.
metered
Read only. A Boolean returning true if 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

  • Desktop
  • Mobile

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.enabled preference.
  • The metered attribute is false by default and can be set using the dom.network.metered preference (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.mozConnection was not an instance of EventTarget and no addEventListener could be called. This has been fixed ( bug 735261 ).

Tags (4)

Edit tags

Attachments (0)

 

Attach file