W3cubDocs

/Web APIs

CookieStore: delete() method

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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

js

delete(name)
delete(options)

Parameters

This method requires one of the following:

name

A string with the name of a cookie.

Or

options

An object containing:

name

A string with the name of a cookie.

partitioned Optional

A boolean value that defaults to false. Setting it to true specifies that the cookie to delete will be a partitioned cookie. See Cookies Having Independent Partitioned State (CHIPS) for more information.

path Optional

A string containing a path.

url Optional

A string with the URL of a cookie.

Note: The url option enables the modification of a cookie scoped under a particular URL. Service workers can obtain cookies that would be sent to any URL under their scope. From a document you may only obtain the cookies at the current URL, so the only valid URL in a document context is the document's URL.

Return value

A Promise that resolves with undefined when deletion completes.

Exceptions

TypeError

Thrown if deleting the cookie represented by the given name or options fails.

Examples

In this example a cookie is deleted by passing the name to the delete() method.

js

let result = cookieStore.delete("cookie1");
console.log(result);

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
delete 87 87 No No 73 No 87 87 No 62 No 14.0
partitioned_option 114 114 No No 100 No 114 114 No No No No

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CookieStore/delete