This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.
Deprecated
This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.
The context
read-only property of the Request
interface contains the context of the Request (e.g., audio
, image
, iframe
). This defines what sort of resource is being fetched.
The context of a request is only relevant in the ServiceWorker API; a service worker can make decisions based on whether the URL is for an image, or an embeddable object such as a <video>
, iframe
, etc.
Note: You can find a full list of the different available contexts including associated context frame types, CSP directives, and platform feature examples in the Fetch spec request context section.
Syntax
var myContext = request.context;
Value
A RequestContext
value.
Example
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 context in a variable:
var myRequest = new Request('flowers.jpg'); var myContext = myRequest.context; // returns the empty string by default
Specifications
Specification | Status | Comment |
---|---|---|
Fetch The definition of 'context' in that specification. |
Living Standard | Initial definition |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 42[1] | 42 (42)[2] 39 (39) 34[1] |
Not supported |
29 |
Not supported |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | Firefox OS (Gecko) | IE Phone | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | Not supported | 42[1] | Not supported | Not supported | Not supported | Not supported | Not supported | 42[1] |
[1] Removed in Chrome 46.
[2] Removed from Firefox as of version 42, until the spec is agreed upon (see bug 1188062 for more information.)