ProgressEvent

BaselineWidely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers sinceJuly 2015.

TheProgressEventinterface represents events measuring progress of an underlying process, like an HTTP request (for anXMLHttpRequest,or the loading of the underlying resource of an<img>,<audio>,<video>,<style>or<link>).

Event ProgressEvent

Constructor

ProgressEvent()

Creates aProgressEventevent with the given parameters.

Instance properties

Also inherits properties from its parentEvent.

ProgressEvent.lengthComputableRead only

A boolean flag indicating if the ratio between the size of the data already transmitted or processed (loaded), and the total size of the data (total), is calculable. In other words, it tells if the progress is measurable or not.

ProgressEvent.loadedRead only

A 64-bit unsigned integer indicating the size, in bytes, of the data already transmitted or processed. The ratio can be calculated by dividingProgressEvent.totalby the value of this property. When downloading a resource using HTTP, this only counts the body of the HTTP message, and doesn't include headers and other overhead. Note that for compressed requests of unknown total size,loadedmight contain the size of the compressed, or decompressed, data, depending on the browser. As of 2024, it contains the size of the compressed data in Firefox, and the size of the uncompressed data in Chrome.

ProgressEvent.totalRead only

A 64-bit unsigned integer indicating the total size, in bytes, of the data being transmitted or processed. When downloading a resource using HTTP, this value is taken from theContent-Lengthresponse header. It only counts the body of the HTTP message, and doesn't include headers and other overhead.

Instance methods

Inherits methods from its parent,Event.

Examples

The following example adds aProgressEventto a newXMLHTTPRequestand uses it to display the status of the request.

js
constprogressBar=document.getElementById("p"),
client=newXMLHttpRequest();
client.open("GET","magical-unicorns");
client.onprogress=(pe)=>{
if(pe.lengthComputable){
progressBar.max=pe.total;
progressBar.value=pe.loaded;
}
};
client.onloadend=(pe)=>{
progressBar.value=pe.loaded;
};
client.send();

Specifications

Specification
XMLHttpRequest Standard
#interface-progressevent

Browser compatibility

BCD tables only load in the browser

See also

  • TheEventbase interface.