Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix globals, part 11: fetch() #33643

Merged
merged 14 commits into from
Jul 16, 2024
11 changes: 5 additions & 6 deletions files/en-us/_redirects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8381,8 +8381,8 @@
/en-US/docs/Web/API/GlobalEventHandlers/ontransitioncancel /en-US/docs/Web/API/Element/transitioncancel_event
/en-US/docs/Web/API/GlobalEventHandlers/ontransitionend /en-US/docs/Web/API/Element/transitionend_event
/en-US/docs/Web/API/GlobalEventHandlers/onwheel /en-US/docs/Web/API/Element/wheel_event
/en-US/docs/Web/API/GlobalFetch/GlobalFetch.fetch() /en-US/docs/Web/API/fetch
/en-US/docs/Web/API/GlobalFetch/fetch /en-US/docs/Web/API/fetch
/en-US/docs/Web/API/GlobalFetch/GlobalFetch.fetch() /en-US/docs/Web/API/Window/fetch
/en-US/docs/Web/API/GlobalFetch/fetch /en-US/docs/Web/API/Window/fetch
/en-US/docs/Web/API/Guide/Events/Creating_and_triggering_events /en-US/docs/Web/Events/Creating_and_triggering_events
/en-US/docs/Web/API/HID/onconnect /en-US/docs/Web/API/HID/connect_event
/en-US/docs/Web/API/HID/ondisconnect /en-US/docs/Web/API/HID/disconnect_event
Expand Down Expand Up @@ -9726,7 +9726,7 @@
/en-US/docs/Web/API/ServiceWorkerGlobalScope/activate /en-US/docs/Web/API/ServiceWorkerGlobalScope/activate_event
/en-US/docs/Web/API/ServiceWorkerGlobalScope/caches /en-US/docs/Web/API/caches
/en-US/docs/Web/API/ServiceWorkerGlobalScope/claim /en-US/docs/Web/API/Clients/claim
/en-US/docs/Web/API/ServiceWorkerGlobalScope/fetch /en-US/docs/Web/API/fetch
/en-US/docs/Web/API/ServiceWorkerGlobalScope/fetch /en-US/docs/Web/API/WorkerGlobalScope/fetch
/en-US/docs/Web/API/ServiceWorkerGlobalScope/install /en-US/docs/Web/API/ServiceWorkerGlobalScope/install_event
/en-US/docs/Web/API/ServiceWorkerGlobalScope/onmessage /en-US/docs/Web/API/ServiceWorkerGlobalScope/message_event
/en-US/docs/Web/API/ServiceWorkerGlobalScope/periodicsync /en-US/docs/Web/API/ServiceWorkerGlobalScope/periodicsync_event
Expand Down Expand Up @@ -10153,7 +10153,6 @@
/en-US/docs/Web/API/Window/content /en-US/docs/Web/API/Window
/en-US/docs/Web/API/Window/convertPointFromNodeToPage /en-US/docs/Web/API/Window/webkitConvertPointFromNodeToPage
/en-US/docs/Web/API/Window/convertPointFromPageToNode /en-US/docs/Web/API/Window/webkitConvertPointFromPageToNode
/en-US/docs/Web/API/Window/fetch /en-US/docs/Web/API/fetch
/en-US/docs/Web/API/Window/minimize /en-US/docs/Web/API/Window
/en-US/docs/Web/API/Window/mozAnimationStartTime /en-US/docs/Web/API/Animation/startTime
/en-US/docs/Web/API/Window/mozPaintCount /en-US/docs/Web/API/Window
Expand Down Expand Up @@ -10259,7 +10258,7 @@
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearTimeout /en-US/docs/Web/API/clearTimeout
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/createImageBitmap /en-US/docs/Web/API/createImageBitmap
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/crossOriginIsolated /en-US/docs/Web/API/Window/crossOriginIsolated
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch /en-US/docs/Web/API/fetch
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch /en-US/docs/Web/API/Window/fetch
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/indexedDB /en-US/docs/Web/API/Window/indexedDB
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/isSecureContext /en-US/docs/Web/API/Window/isSecureContext
/en-US/docs/Web/API/WindowOrWorkerGlobalScope/origin /en-US/docs/Web/API/Window/origin
Expand Down Expand Up @@ -10313,7 +10312,6 @@
/en-US/docs/Web/API/WorkerGlobalScope/clearTimeout /en-US/docs/Web/API/clearTimeout
/en-US/docs/Web/API/WorkerGlobalScope/close /en-US/docs/Web/API/DedicatedWorkerGlobalScope/close
/en-US/docs/Web/API/WorkerGlobalScope/console /en-US/docs/Web/API/console
/en-US/docs/Web/API/WorkerGlobalScope/fetch /en-US/docs/Web/API/fetch
/en-US/docs/Web/API/WorkerGlobalScope/onclose /en-US/docs/Web/API/DedicatedWorkerGlobalScope/close
/en-US/docs/Web/API/WorkerGlobalScope/onerror /en-US/docs/Web/API/WorkerGlobalScope/error_event
/en-US/docs/Web/API/WorkerGlobalScope/onlanguagechange /en-US/docs/Web/API/WorkerGlobalScope/languagechange_event
Expand Down Expand Up @@ -10648,6 +10646,7 @@
/en-US/docs/Web/API/event.type /en-US/docs/Web/API/Event/type
/en-US/docs/Web/API/event.view /en-US/docs/Web/API/UIEvent/view
/en-US/docs/Web/API/event.which /en-US/docs/Web/API/UIEvent/which
/en-US/docs/Web/API/fetch /en-US/docs/Web/API/Window/fetch
/en-US/docs/Web/API/form.acceptCharset /en-US/docs/Web/API/HTMLFormElement/acceptCharset
/en-US/docs/Web/API/form.action /en-US/docs/Web/API/HTMLFormElement/action
/en-US/docs/Web/API/form.elements /en-US/docs/Web/API/HTMLFormElement/elements
Expand Down
86 changes: 43 additions & 43 deletions files/en-us/_wikihistory.json
Original file line number Diff line number Diff line change
Expand Up @@ -66839,6 +66839,49 @@
"modified": "2020-10-15T22:11:52.818Z",
"contributors": ["wbamberg", "JeffersonScher", "chrisdavidmills"]
},
"Web/API/Window/fetch": {
"modified": "2020-10-15T21:33:25.494Z",
"contributors": [
"mfuji09",
"Wind1808",
"Sheppy",
"Zearin_Galaurum",
"chrisdavidmills",
"TestPolygon",
"bigjilm",
"tkrotoff",
"old_morfey13",
"skellix",
"FranklinYu",
"sideshowbarker",
"tjcrowder",
"DamienCassou",
"fscholz",
"mfulton26",
"SiliconSoldier",
"satyabhimisetty",
"jakubboucek",
"AngeloKai",
"Yaffle",
"cpplearner",
"Konrud",
"BuonOmo",
"kenrick95",
"kmiyashiro",
"xfq",
"arronei",
"valtlai",
"erikadoyle",
"jpmedley",
"runn1ng",
"ysmood",
"jsx",
"Sebastianz",
"George8211",
"matiishyn",
"kscarfone"
]
},
"Web/API/Window/find": {
"modified": "2020-10-16T15:18:21.626Z",
"contributors": [
Expand Down Expand Up @@ -71538,49 +71581,6 @@
"adria"
]
},
"Web/API/fetch": {
"modified": "2020-10-15T21:33:25.494Z",
"contributors": [
"mfuji09",
"Wind1808",
"Sheppy",
"Zearin_Galaurum",
"chrisdavidmills",
"TestPolygon",
"bigjilm",
"tkrotoff",
"old_morfey13",
"skellix",
"FranklinYu",
"sideshowbarker",
"tjcrowder",
"DamienCassou",
"fscholz",
"mfulton26",
"SiliconSoldier",
"satyabhimisetty",
"jakubboucek",
"AngeloKai",
"Yaffle",
"cpplearner",
"Konrud",
"BuonOmo",
"kenrick95",
"kmiyashiro",
"xfq",
"arronei",
"valtlai",
"erikadoyle",
"jpmedley",
"runn1ng",
"ysmood",
"jsx",
"Sebastianz",
"George8211",
"matiishyn",
"kscarfone"
]
},
"Web/API/queueMicrotask": {
"modified": "2020-10-15T22:21:06.789Z",
"contributors": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
title: fetch() global function
title: "Window: fetch() method"
short-title: fetch()
slug: Web/API/fetch
page-type: web-api-global-function
slug: Web/API/Window/fetch
page-type: web-api-instance-method
browser-compat: api.fetch
---

{{APIRef("Fetch API")}}{{AvailableInWorkers}}
{{APIRef("Fetch API")}}

The global **`fetch()`** method starts the process of fetching a resource from the network, returning a promise that is fulfilled once the response is available.
The **`fetch()`** method of the {{domxref("Window")}} interface starts the process of fetching a resource from the network, returning a promise that is fulfilled once the response is available.

The promise resolves to the {{domxref("Response")}} object representing the response to your request.

Expand Down Expand Up @@ -51,7 +51,7 @@ fetch(resource, options)

- `browsingTopics` {{experimental_inline}}

- : A boolean specifying that the selected topics for the current user should be sent in a {{httpheader("Sec-Browsing-Topics")}} header with the associated request. See [Using the Topics API](/en-US/docs/Web/API/Topics_API/Using) for more details.
- : A boolean specifying that the selected topics for the current user should be sent in a {{HTTPHeader("Sec-Browsing-Topics")}} header with the associated request. See [Using the Topics API](/en-US/docs/Web/API/Topics_API/Using) for more details.

- `cache`

Expand All @@ -70,9 +70,9 @@ fetch(resource, options)
- `headers`

- : Any headers you want to add to your request, contained within a {{domxref("Headers")}} object or an object literal with {{jsxref("String")}} values.
Note that [some names are forbidden](/en-US/docs/Glossary/Forbidden_header_name).
Note that {{Glossary("forbidden header name", "some names are forbidden")}}.

> **Note:** The [`Authorization`](/en-US/docs/Web/HTTP/Headers/Authorization) HTTP header may be added to a request, but will be removed if the request is redirected cross-origin.
> **Note:** The {{HTTPHeader("Authorization")}} HTTP header may be added to a request, but will be removed if the request is redirected cross-origin.

- `integrity`

Expand All @@ -86,7 +86,7 @@ fetch(resource, options)

- : The request method, e.g., `"GET"`, `"POST"`.
The default is `"GET"`.
Note that the {{httpheader("Origin")}} header is not set on Fetch requests with a method of {{HTTPMethod("HEAD")}} or {{HTTPMethod("GET")}}.
Note that the {{HTTPHeader("Origin")}} header is not set on Fetch requests with a method of {{HTTPMethod("HEAD")}} or {{HTTPMethod("GET")}}.
(This behavior was corrected in Firefox 65 — see [Firefox bug 1508661](https://bugzil.la/1508661).)
Any string which is a case-insensitive match for one of the methods in [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110#name-overview) will be uppercased automatically.
If you want to use a custom method (like `PATCH`), you should uppercase it yourself.
Expand Down Expand Up @@ -139,7 +139,7 @@ A {{jsxref("Promise")}} that resolves to a {{domxref("Response")}} object.
- : The request was aborted due to a call to the {{domxref("AbortController")}}
{{domxref("AbortController.abort", "abort()")}} method.
- `NotAllowedError` {{domxref("DOMException")}}
- : Usage of the [Topics API](/en-US/docs/Web/API/Topics_API) is specifically disallowed by a {{httpheader('Permissions-Policy/browsing-topics','browsing-topics')}} [Permissions Policy](/en-US/docs/Web/HTTP/Permissions_Policy), and a `fetch()` request was made with `browsingTopics: true`.
- : Usage of the [Topics API](/en-US/docs/Web/API/Topics_API) is specifically disallowed by a {{HTTPHeader('Permissions-Policy/browsing-topics','browsing-topics')}} [Permissions Policy](/en-US/docs/Web/HTTP/Permissions_Policy), and a `fetch()` request was made with `browsingTopics: true`.
- {{jsxref("TypeError")}}
- : Can occur for the following reasons:

Expand Down Expand Up @@ -282,7 +282,7 @@ const myImage = document.querySelector("img");

const myRequest = new Request("flowers.jpg");

fetch(myRequest)
window.fetch(myRequest)
skyclouds2001 marked this conversation as resolved.
Show resolved Hide resolved
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
Expand All @@ -296,7 +296,7 @@ fetch(myRequest)
```

In our [Fetch Request with init example](https://github.com/mdn/dom-examples/tree/main/fetch/fetch-request-with-init) (see [Fetch Request init live](https://mdn.github.io/dom-examples/fetch/fetch-request-with-init)) we do the same thing except that we pass in an _options_ object when we invoke `fetch()`.
In this case, we can set a {{httpheader("Cache-Control")}} value to indicate what kind of cached responses we're okay with:
In this case, we can set a {{HTTPHeader("Cache-Control")}} value to indicate what kind of cached responses we're okay with:

```js
const myImage = document.querySelector("img");
Expand Down Expand Up @@ -345,6 +345,7 @@ const req = new Request("flowers.jpg", options);

## See also

- {{domxref("WorkerGlobalScope.fetch()")}}
- [Fetch API](/en-US/docs/Web/API/Fetch_API)
- [ServiceWorker API](/en-US/docs/Web/API/Service_Worker_API)
- [HTTP access control (CORS)](/en-US/docs/Web/HTTP/CORS)
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/window/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ _This interface inherits methods from the {{domxref("EventTarget")}} interface._
- : Accepts a variety of different image sources, and returns a {{jsxref("Promise")}} which resolves to an {{domxref("ImageBitmap")}}. Optionally the source is cropped to the rectangle of pixels originating at _(sx, sy)_ with width sw, and height sh.
- {{domxref("Window.dump()")}} {{Non-standard_Inline}}
- : Writes a message to the console.
- {{domxref("fetch", "Window.fetch()")}}
- {{domxref("Window.fetch()")}}
- : Starts the process of fetching a resource from the network.
- {{domxref("Window.find()")}} {{Non-standard_Inline}}
- : Searches for a given string in a window.
Expand Down
Loading
Loading