aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/mozilla/add-ons/webextensions/api/cookies/onchangedcause/index.html
blob: 4a1c2f412b98c43da94dfb000d146497c7fc421c (plain)
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
70
71
72
73
74
75
76
77
78
79
80
---
title: cookies.OnChangedCause
slug: Mozilla/Add-ons/WebExtensions/API/cookies/OnChangedCause
translation_of: Mozilla/Add-ons/WebExtensions/API/cookies/OnChangedCause
---
<div>{{AddonSidebar()}}</div>

<p>{{WebExtAPIRef("cookies")}} API 的 <code>OnChangedCause</code> 型別,代表觸發 cookie 資料變動的原因。</p>

<h2 id="型別">型別</h2>

<p>此型別的所有值都是字串(string)。可用值包括:</p>

<dl>
 <dt><code>evicted</code></dt>
 <dd>由於垃圾回收(garbage collection)而被刪除的 cookie。</dd>
 <dt><code>expired</code></dt>
 <dd>由於過期而被刪除的 cookie。</dd>
 <dt><code>explicit</code></dt>
 <dd>透過顯式呼叫(explicit call){{WebExtAPIRef("cookies.remove()")}} 而被插入或刪除的 cookie。</dd>
 <dt><code>expired_overwrite</code></dt>
 <dd>被已過期(already-expired expiration date)cookie 所覆寫的 cookie。</dd>
 <dt><code>overwrite</code></dt>
 <dd>A call to {{WebExtAPIRef("cookies.set()")}} overwrote this cookie with a different one.</dd>
</dl>

<h2 id="瀏覽器相容性">瀏覽器相容性</h2>

<p>{{Compat("webextensions.api.cookies.OnChangedCause")}}</p>

<h2 id="示例">示例</h2>

<p>你可以在 cookie 變更的時候監聽被通知的 {{WebExtAPIRef("cookies.onChanged")}} 事件。此監聽器 passed 含有 <code>cause</code> 屬性,值為 <code>OnChangeCaused</code> 字串的 <code>changeInfo</code> 物件:</p>

<pre class="brush: js">browser.cookies.onChanged.addListener(function(changeInfo) {
  console.log('Cookie changed: ' +
              '\n * Cookie: ' + JSON.stringify(changeInfo.cookie) +
              '\n * Cause: ' + changeInfo.cause +
              '\n * Removed: ' + changeInfo.removed);
});</pre>

<p>{{WebExtExamples}}</p>

<div class="note"><strong>致謝</strong>

<p>此 API 基於 Chromium 的 <a href="https://developer.chrome.com/extensions/cookies"><code>chrome.cookies</code></a> API 而來,文件改作自 Chromium 程式碼裡的 <a href="https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/cookies.json"><code>cookies.json</code></a></p>

<p>Microsoft Edge 的相容資訊來自微軟公司,原文以創用 CC 姓名標示 3.0 美國版條款授權大眾使用。</p>
</div>

<div class="hidden">
<pre>// Copyright 2015 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//    * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//    * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//    * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</pre>
</div>