CookieStore: delete() method
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Service Workers.
The delete() method of the CookieStore interface deletes a cookie with the given name or options object. The delete() method expires the cookie by changing the date to one in the past.
Syntax
delete(name)
delete(options)
Parameters
This method requires one of the following:
nameOptional-
A string with the name of a cookie.
Or
optionsOptional-
An object containing:
name-
A string with the name of a cookie.
domainOptional-
A string with the domain of a cookie. Defaults to
null. pathOptional-
A string containing a path. Defaults to
/. partitionedOptional-
A boolean value that defaults to
false. Setting it totruespecifies that the cookie to delete will be a partitioned cookie. See Cookies Having Independent Partitioned State (CHIPS) for more information.
Return value
Exceptions
SecurityErrorDOMException-
Thrown if the origin can not be serialized to a URL.
TypeError-
Thrown if deleting the cookie represented by the given
nameoroptionsfails.
Examples
In this example, a cookie is deleted by passing the name to the delete() method.
const result = cookieStore.delete("cookie1");
console.log(result);
Specifications
| Specification |
|---|
| Cookie Store API # dom-cookiestore-delete |
Browser compatibility
BCD tables only load in the browser