forked from mdn/content
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
69 lines (52 loc) · 2.29 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
title: CookieStore.getAll()
slug: Web/API/CookieStore/getAll
tags:
- API
- Method
- Reference
- getAll()
- CookieStore
browser-compat: api.CookieStore.getAll
---
<div>{{securecontext_header}}{{DefaultAPISidebar("Cookie Store API")}}</div>
<p>The <strong><code>getAll()</code></strong> method of the {{domxref("CookieStore")}} interface returns a list of cookies that match the name or options passed to it. Passing no parameters will return all cookies for the current context.</p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox">var <var>list</var> = cookieStore.getAll(<var>name</var>);
var <var>list</var> = cookieStore.getAll(<var>options</var>);</pre>
<h3 id="Parameters">Parameters</h3>
<dl>
<dt><code>name</code>{{Optional_Inline}}</dt>
<dd>A {{domxref("USVString")}} with the name of a cookie.</dd>
<dt><code>options</code>{{Optional_Inline}}</dt>
<dd>An object containing:
<dl>
<dt><code>name</code></dt>
<dd>A {{domxref("USVString")}} with the name of a cookie.</dd>
<dt><code>url</code></dt>
<dd>A {{domxref("USVString")}} with the url of a cookie.</dd>
</dl>
</dd>
</dl>
<div class="notecard note">
<p><strong>Note:</strong> The <code>url</code> 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.</p>
</div>
<h3 id="Returns">Return value</h3>
<p>A {{jsxref("Promise")}} that resolves with a list of cookies for the given name or options.</p>
<h3 id="Exceptions">Exceptions</h3>
<dl>
<dt>{{jsxref("TypeError")}}</dt>
<dd>Thrown if getting the cookie or cookies represented by the given <code>name</code> or <code>options</code> fails.</dd>
</dl>
<h2 id="Examples">Examples</h2>
<p>In this example we use <code>getAll()</code> with no parameters. This returns all of the cookies for this context as an array of objects.</p>
<pre class="brush:js">let cookies = cookieStore.getAll();
if (cookies) {
console.log(cookies);
} else {
console.log('Cookie not found');
}</pre>
<h2 id="Specifications">Specifications</h2>
{{Specifications}}
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat}}</p>