--- title: fetchProgress description: Observe bytes arriving from a fetch response and report incremental progress to an application callback. hide_title: true page_style: designed --- import {DocPageHeader} from '@site/src/components/docs/doc-page-header'; import {DocOrientation, ReferenceBoundary} from '@site/src/components/docs/designed-doc'; > This function is still experimental A function that tracks a fetch response object and calls `onProgress` callbacks. ## Usage ```typescript import {_fetchProgress} from '@loaders.gl/core'; function onProgress(percent, {loadedBytes, totalBytes}) { console.log(`${percent}% ${Math.round(loadedBytes/1000)} of ${Math.round(totalBytes/1000)} Kbytes`); } async function main() { const response = await _fetchProgress(fetch(PROGRESS_IMAGE_URL), onProgress); const data = await response.arrayBuffer(); // At this point, onProgress will have been called one or more times. return data; } ``` ## `_fetchProgress(response, onProgress, onDone?, onError?): Promise` `onProgress: (percent: number, {loadedBytes : number, totalBytes : number}) => void` Progress callbacks require a successful response with a readable body and a positive `Content-Length`. Without those, the original response is returned and progress is not reported. The wrapped response contains the body stream but does not preserve the original response headers, status, or URL; inspect those before wrapping if your application needs them.