The mode
read-only property of the Request
interface contains the mode of the request (e.g., cors
, no-cors
, same-origin
, navigate
or websocket
.) This is used to determine if cross-origin requests lead to valid responses, and which properties of the response are readable.
Requests can be initiated in a variety of ways, and the mode for a request depends on the particular means by which it was initiated.
For example, when a Request
object is created using the Request()
constructor, the value of the mode
property for that Request
is set to cors
.
However, for requests created other than by the Request()
constructor, no-cors
is typically used as the mode; for example, for embedded resources where the request is initiated from markup, unless the crossorigin
attribute is present, the request is in most cases made using the no-cors
mode — that is, for the <link>
or <script>
elements (except when used with modules), or <img>
, <audio>
, <video>
, <object>
, <embed>
, or <iframe>
elements.
In the following snippet, we create a new request using the Request()
constructor (for an image file in the same directory as the script), then save the request mode in a variable:
const myRequest = new Request("flowers.jpg");
const myMode = myRequest.mode;