Favorites

DOM Window.fetch() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Window.fetch()
DOM Window MethodThis method is supported by all modern browsers.
Updated 28th November 2026

The fetch() method makes a network request and returns a promise for the response. It's the modern way to load data from a server or API.

Description

The fetch() method starts a network request and returns a promise that fulfills with a Response. Read the body with response.json(), text(), blob() or arrayBuffer(), each of which returns another promise. To send data, pass an options object with method: 'POST', headers and a body, such as JSON.stringify(data).

The promise only rejects on network failure. HTTP errors such as 404 or 500 still fulfill, so check response.ok or response.status. Requests to other origins are subject to CORS, and an AbortController can cancel a request or add a timeout.

By default, cookies are sent only with requests to the same origin; set credentials: 'include' to send them to other origins too. Responses can only be read once, so call res.clone() if you need the body twice, for example to log it and parse it.

Syntax

fetch(resource)
fetch(resource, options)

Parameters

  • resourceThe URL to request, or a Request object.
  • optionsOptional. Settings such as method, headers, body, signal and credentials.

Return Value

A promise that fulfills with a Response object once the response headers arrive.

Example

async function load() {
  try {
    const res = await fetch('data:application/json,{"users":["Sam","Alex"]}');
    if (!res.ok) throw new Error('HTTP ' + res.status);
    const data = await res.json();
    console.log(data.users);
  } catch (err) {
    console.error('Request failed:', err.message);
  }
}
load();

Browser Support

The following information will show you the current browser support for the Window.fetch() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee