这篇翻译不完整。请帮忙从英语翻译这篇文章

使用 WebExtensions 获取或设置 cookies, 并且在修改时能够获得通知。

你需要在 manifest.json 文件中开启“cookies”API 权限,并且需要对应站点的 主机权限 才能设置指定站点的cookie。详细信息查看 cookie 权限.

Types

cookies.Cookie
Represents information about an HTTP cookie.
cookies.CookieStore
Represents a cookie store in the browser.
cookies.OnChangedCause
Represents the reason a cookie changed.

Methods

cookies.get()
Retrieves information about a single cookie.
cookies.getAll()
Retrieves all cookies that match a given set of filters.
cookies.set()
Sets a cookie with the given cookie data; may overwrite equivalent cookies if they exist.
cookies.remove()
Deletes a cookie by name.
cookies.getAllCookieStores()
Lists all existing cookie stores.

Event handlers

cookies.onChanged
Fired when a cookie is set or removed.

Permissions

In order to use this API, an add-on must specify the "cookies" API permission in its manifest, along with host permissions for any sites for which it wishes to access cookies. The add-on may read or write any cookies which could be read or written by a URL matching the host permissions. For example:

http://*.example.com/

An add-on with this host permission may:

  • Read a non-secure cookie for www.example.com, with any path.
  • Write a secure or non-secure cookie for www.example.com, with any path.

It may not:

  • Read a secure cookie for www.example.com.
http://www.example.com/

An add-on with this host permission may:

  • Read a non-secure cookie for www.example.com, with any path.
  • Read a non-secure cookie for .example.com, with any path.
  • Write a secure or non-secure cookie for www.example.com with any path.
  • Write a secure or non-secure cookie for .example.com with any path.

It may not:

  • Read or write a cookie for foo.example.com.
  • Read or write a cookie for foo.www.example.com.
*://*.example.com/

An add-on with this host permission may:

  • Read or write a secure or non-secure cookie for www.example.com with any path.

Browser compatibility

Chrome Edge Firefox Firefox for Android Opera
Cookie Yes Yes 45.0 48.0 33
CookieStore Yes Yes 45.0 48.0 33
OnChangedCause Yes No 45.0 48.0 33
get Yes Yes 45.0 48.0 33
getAll Yes Yes * 45.0 48.0 33
getAllCookieStores Yes Yes * 45.0 48.0 33
onChanged Yes No 45.0 48.0 33
remove Yes Yes 45.0 48.0 33
set Yes Yes 45.0 48.0 33

Edge incompatibilities

Promises are not supported in Edge. Use callbacks instead.

Chrome incompatibilities

None.

Example add-ons

Acknowledgements

This API is based on Chromium's chrome.cookies API. This documentation is derived from cookies.json in the Chromium code.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

文档标签和贡献者

 此页面的贡献者: GameXG, maicss
 最后编辑者: GameXG,