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

使用 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

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaFirefox for Android
CookieChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 48
CookieStoreChrome Full support YesEdge Full support 14Firefox Full support 45Opera Full support YesFirefox Android Full support 48
OnChangedCauseChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android Full support 48
getChrome Full support YesEdge Full support 14Firefox Full support 45
Notes
Full support 45
Notes
Notes Provides access to cookies from private browsing mode and container tabs since version 52.
Opera Full support YesFirefox Android Full support 48
getAllChrome Full support YesEdge Full support 14
Notes
Full support 14
Notes
Notes If no URL is provided, cookies are retrieved only for URLs in currently opened tabs. In Chrome, this gets all cookies on a user's machine.
Firefox Full support 45
Notes
Full support 45
Notes
Notes Before version 52, the 'tabIds' list was empty and only cookies from the default cookie store were returned. From version 52 onwards, this has been fixed and the result includes cookies from private browsing mode and container tabs.
Opera Full support YesFirefox Android Full support 48
getAllCookieStoresChrome Full support YesEdge Full support 14
Notes
Full support 14
Notes
Notes Always returns the same default cookie store with ID 0. All cookies belong to this store.
Firefox Full support 45
Notes
Full support 45
Notes
Notes Before version 52, only the default cookie store was visible. From version 52 onwards, the cookie stores for private browsing mode and container tabs are also readable.
Opera Full support YesFirefox Android Full support 48
onChangedChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android Full support 48
removeChrome Full support YesEdge Full support 14Firefox Full support 45
Notes
Full support 45
Notes
Notes Before version 56, this function did not remove cookies from private browsing mode. From version 56 onwards this is fixed.
Opera Full support YesFirefox Android Full support 48
Notes
Full support 48
Notes
Notes Before version 56, this function did not remove cookies from private browsing mode. From version 56 onwards this is fixed.
setChrome Full support YesEdge Full support 14Firefox Full support 45
Notes
Full support 45
Notes
Notes Before version 56, this function did not modify cookies in private browsing mode. From version 56 onwards this is fixed.
Opera Full support YesFirefox Android Full support 48
Notes
Full support 48
Notes
Notes Before version 56, this function did not modify cookies in private browsing mode. From version 56 onwards this is fixed.

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

Edge incompatibilities

Promises are not supported in Edge. Use callbacks instead.

Chrome incompatibilities

None.

Example extensions

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,