# Response: type property



The **`type`** read-only property of the [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) interface contains the type of the response. The type determines whether scripts are able to access the response body and headers.

## Value

A string, which may be any of the following values:

- `basic`
  - : This applies in any of the following cases:
    - The request is same-origin.
    - The requested URL's scheme is [`data:`](https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data).
    - The request's [mode](https://developer.mozilla.org/en-US/docs/Web/API/Request/mode) is `navigate` or `websocket`.

    With this type, all response headers are exposed except [Set-Cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie).

- `cors`
  - : The request was cross-origin and was successfully processed using [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS). With this type, only [CORS-safelisted response headers](https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted%20response%20header) are exposed.
- `error`
  - : A network error occurred. The [status](https://developer.mozilla.org/en-US/docs/Web/API/Response/status) property is set to `0`, [body](https://developer.mozilla.org/en-US/docs/Web/API/Response/body) is `null`, headers are empty and immutable.

    This is the type of response returned by [Response.error()](https://developer.mozilla.org/en-US/docs/Web/API/Response/error_static). A response of this type is not returned by a call to [fetch()](https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch), because if a network error occurs, the promise is rejected.

- `opaque`
  - : A response to a cross-origin request whose [mode](https://developer.mozilla.org/en-US/docs/Web/API/Request/mode) was set to `no-cors`. The [status](https://developer.mozilla.org/en-US/docs/Web/API/Response/status) property is set to `0`, [body](https://developer.mozilla.org/en-US/docs/Web/API/Response/body) is `null`, headers are empty and immutable.
- `opaqueredirect`
  - : A response to a request whose [redirect](https://developer.mozilla.org/en-US/docs/Web/API/Request/redirect) option was set to `manual`, and which was redirected by the server. The [status](https://developer.mozilla.org/en-US/docs/Web/API/Response/status) property is set to `0`, [body](https://developer.mozilla.org/en-US/docs/Web/API/Response/body) is `null`, headers are empty and immutable.

## Examples

### A basic response

The following same-origin request will return a `basic` response:

```js
const response = await fetch("flowers.jpg");

console.log(response.type); // "basic"
```

### A CORS response

Assuming `https://example.org` is not the requester's origin, and that the server responds with the appropriate CORS headers, this request will return a `cors` response:

```js
const response = await fetch("https://example.org/flowers.jpg");

console.log(response.type); // "cors"
```

### An opaque response

The following request is made with the [`no-cors`](https://developer.mozilla.org/en-US/docs/Web/API/Request/mode#no-cors) option, so it returns an `opaque` response:

```js
const response = await fetch("https://example.org/flowers.jpg", {
  mode: "no-cors",
});

console.log(response.type); // "opaque"
console.log(response.body); // null
console.log(response.status); // 0
```

### An error response

The following code uses [Response.error()](https://developer.mozilla.org/en-US/docs/Web/API/Response/error_static) to create an `error` response:

```js
const response = Response.error();

console.log(response.type); // "error"
console.log(response.body); // null
console.log(response.status); // 0
```

## Specifications

## Browser compatibility

## See also

- [ServiceWorker API](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API)
- [HTTP access control (CORS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS)
- [HTTP](https://developer.mozilla.org/en-US/docs/Web/HTTP)
