The credentials
read-only property of the Request
interface indicates whether the user agent should send cookies from the other domain in the case of cross-origin requests. This is similar to XHR’s withCredentials
flag, but with three available values (instead of two):
omit
: Never send cookies.same-origin
: Send user credentials (cookies, basic http auth, etc..) if the URL is on the same origin as the calling script. This is the default value.
include
: Always send user credentials (cookies, basic http auth, etc..), even for cross-origin calls.var myCred = request.credentials;
A RequestCredentials
value representing the credentials to use for this transaction.
In the following snippet, we create a new request using the Request.Request()
constructor (for an image file in the same directory as the script), then save the request credentials in a variable:
var myRequest = new Request('flowers.jpg'); var myCred = myRequest.credentials; // returns "same-origin" by default
Specification | Status | Comment |
---|---|---|
Fetch The definition of 'credentials' in that specification. | Living Standard | Initial definition |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 42
|
Yes | 39
|
No | 29
|
No |
Default value same-origin
|
? | ? | 61 | No | ? | No |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | No | 42 — 46 | Yes | No | No | No | 4.0 |
Default value same-origin
|
? | ? | ? | No | No | No | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials