diff options
Diffstat (limited to 'files/zh-tw/mozilla/add-ons/webextensions/api/cookies/index.html')
-rw-r--r-- | files/zh-tw/mozilla/add-ons/webextensions/api/cookies/index.html | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/files/zh-tw/mozilla/add-ons/webextensions/api/cookies/index.html b/files/zh-tw/mozilla/add-ons/webextensions/api/cookies/index.html new file mode 100644 index 0000000000..34da08932c --- /dev/null +++ b/files/zh-tw/mozilla/add-ons/webextensions/api/cookies/index.html @@ -0,0 +1,163 @@ +--- +title: cookies +slug: Mozilla/Add-ons/WebExtensions/API/cookies +tags: + - API + - Add-ons + - Cookies + - Extensions + - Interface + - Non-standard + - Reference + - WebExtensions + - 介面 + - 參考文件 + - 擴充套件 + - 附加元件 + - 非標準 +translation_of: Mozilla/Add-ons/WebExtensions/API/cookies +--- +<div>{{AddonSidebar}}</div> + +<div>讓擴充套件可以取得、設定 cookies 資訊,並監控其變動。</div> + +<div> </div> + +<p>使用此 API 前,必須先在 <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json">manifest.json </a>檔案中加入「cookies」這項 <a href="/en-US/Add-ons/WebExtensions/manifest.json/permissions#API_permissions">API 權限宣告</a>,也必須以 <a href="/en-US/Add-ons/WebExtensions/manifest.json/permissions#Host_permissions">host 權限宣告</a>將要存取 Cookies 的網站列入。參見 <a href="/en-US/Add-ons/WebExtensions/API/cookies#Permissions">Cookie 權限</a>一節。</p> + +<h2 id="型別">型別</h2> + +<dl> + <dt>{{WebExtAPIRef("cookies.Cookie")}}</dt> + <dd>代表一個 HTTP cookie 的相關資訊。</dd> + <dt>{{WebExtAPIRef("cookies.CookieStore")}}</dt> + <dd>代表瀏覽器中的 cookie 存放空間。</dd> + <dt>{{WebExtAPIRef("cookies.OnChangedCause")}}</dt> + <dd>代表觸發 cookie 資料變動的原因。</dd> +</dl> + +<h2 id="方法">方法</h2> + +<dl> + <dt>{{WebExtAPIRef("cookies.get()")}}</dt> + <dd>取回單一 cookie 的相關資訊。</dd> + <dt>{{WebExtAPIRef("cookies.getAll()")}}</dt> + <dd>取回符合設定條件的所有 cookies 資訊。</dd> + <dt>{{WebExtAPIRef("cookies.set()")}}</dt> + <dd>為 cookie 設定資料。如果目前已有相同的 cookies,則會覆寫原本的 cookie 資料。</dd> + <dt>{{WebExtAPIRef("cookies.remove()")}}</dt> + <dd>刪除某特定名稱的 cookie。</dd> + <dt>{{WebExtAPIRef("cookies.getAllCookieStores()")}}</dt> + <dd>列出目前所有的 cookie 存放空間。</dd> +</dl> + +<h2 id="事件處理程序">事件處理程序</h2> + +<dl> + <dt>{{WebExtAPIRef("cookies.onChanged")}}</dt> + <dd>當 cookie 設定或刪除時觸發。</dd> +</dl> + +<h2 id="權限">權限</h2> + +<p>使用此 API 前,擴充套件應於 manifest.json 設定檔中指明需要「cookies」<a href="/en-US/Add-ons/WebExtensions/manifest.json/permissions#API_permissions">API 權限</a>,亦須以 <a href="/en-US/Add-ons/WebExtensions/manifest.json/permissions#Host_permissions">host 權限宣告</a>指明需要存取 cookies 的網站清單。此後,符合 host 權限宣告的 URL 所能讀寫的任何 cookies,該擴充套件即可讀取。比方說:</p> + +<dl> + <dt><code>http://*.example.com/</code></dt> + <dd> + <p>若套件有這樣的 host 權限宣告,即可:</p> + + <ul> + <li>讀取 <code>www.example.com</code> 任何路徑下的非安全 cookie。</li> + <li>寫入 <code>www.example.com</code> 任何路徑下的安全或非安全 cookie。</li> + </ul> + + <p>但<em>不能</em>:</p> + + <ul> + <li>讀取 <code>www.example.com</code> 下的安全 cookie。</li> + </ul> + </dd> + <dt><code>http://www.example.com/</code></dt> + <dd> + <p>若套件有這樣的 host 權限宣告,即可:</p> + + <ul> + <li>讀取 <code>www.example.com</code> 任何路徑下的非安全 cookie。</li> + <li>讀取 <code>.example.com</code> 任何路徑下的非安全 cookie。</li> + <li>寫入 <code>www.example.com</code> 任何路徑下的安全或非安全 cookie。</li> + <li>寫入 <code>.example.com</code> 任何路徑下的安全或非安全 cookie。</li> + </ul> + + <p>但<em>不能</em>:</p> + + <ul> + <li>寫入 <code>foo.example.com</code> 的 cookie。</li> + <li>寫入 <code>foo.www.example.com</code> 的 cookie。</li> + </ul> + </dd> + <dt><code>*://*.example.com/</code></dt> + <dd> + <p>若套件有這樣的 host 權限宣告,即可:</p> + + <ul> + <li>讀、寫 <code>www.example.com</code> 任何路徑下的安全或非安全 cookie。</li> + </ul> + </dd> +</dl> + +<h2 id="瀏覽器相容性">瀏覽器相容性</h2> + +<p>{{Compat("webextensions.api.cookies")}}</p> + +<div class="hidden note"> +<p>The "Chrome incompatibilities" section is included from <a href="https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities"> https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities</a> using the <a href="/en-US/docs/Template:WebExtChromeCompat">WebExtChromeCompat</a> macro.</p> + +<p>If you need to update this content, edit <a href="https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities">https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities</a>, then shift-refresh this page to see your changes.</p> + +<p>譯者按:該文件會持續更新,不建議翻譯。</p> +</div> + +<h3 id="Edge_不相容資訊">Edge 不相容資訊</h3> + +<p>Edge 不支援 promises,請使用回呼(callback)函式處理。</p> + +<p> {{WebExtExamples("h2")}}</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> |