diff --git a/files/en-us/web/api/progressevent/progressevent/index.md b/files/en-us/web/api/progressevent/progressevent/index.md index 494076a1aa2858b..853dc24b1fe8840 100644 --- a/files/en-us/web/api/progressevent/progressevent/index.md +++ b/files/en-us/web/api/progressevent/progressevent/index.md @@ -44,6 +44,28 @@ new ProgressEvent(type, options) A new {{domxref("ProgressEvent")}} object. +## Example + +The example demonstrates how a `ProgressEvent` is built using a constructor. This is particularly useful for tracking the progress of processes like file uploads, downloads, or any long-running tasks. + +```js +function updateProgress(loaded, total) { + const progressEvent = new ProgressEvent("progress", { + lengthComputable: true, + loaded: loaded, + total: total, + }); + + document.dispatchEvent(progressEvent); +} + +document.addEventListener("progress", (event) => { + console.log(`Progress: ${event.loaded}/${event.total}`); +}); + +updateProgress(50, 100); +``` + ## Specifications {{Specifications}}