-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zh-cn: translate for CookieStoreManager #20346
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
title: CookieStoreManager | ||
slug: Web/API/CookieStoreManager | ||
l10n: | ||
sourceCommit: 60c3843f55839380e0c0cdc293ea694fe9943158 | ||
--- | ||
|
||
{{securecontext_header}}{{APIRef("Cookie Store API")}}{{AvailableInWorkers("window_and_service")}} | ||
|
||
{{domxref("Cookie Store API", "", "", "nocode")}} 的 **`CookieStoreManager`** 接口允许 Service Worker 订阅 cookie 变更事件。调用特定的 Service Worker 注册器的 {{domxref("CookieStoreManager.subscribe()","subscribe()")}} 方法接收变更事件。 | ||
xyy94813 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
`CookieStoreManager` 关联一个的 {{domxref("ServiceWorkerRegistration", "Service Worker 注册器")}}。每个 Service Worker 注册器包含一个 cookie 变更订阅列表,每个订阅都包含名称和 URL。此接口的方法允许 Service Worker 添加和移除订阅,以及获取所有订阅。 | ||
xyy94813 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
调用 {{domxref("ServiceWorkerRegistration.cookies")}} 获取 `CookieStoreManager`。 | ||
|
||
## 实例方法 | ||
|
||
- {{domxref("CookieStoreManager.getSubscriptions()")}} | ||
- : 返回一个兑现为此 Service Worker 注册器的 cookie 变更订阅列表的 {{jsxref("Promise")}}。 | ||
xyy94813 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- {{domxref("CookieStoreManager.subscribe()")}} | ||
- : 订阅 cookie 变更。返回一个订阅后兑现为 {{jsxref("undefined")}} 的 {{jsxref("Promise")}}。 | ||
- {{domxref("CookieStoreManager.unsubscribe()")}} | ||
- : 取消订阅 cookie 变更。返回一个操作成功后兑现为 {{jsxref("undefined")}} 的 {{jsxref("Promise")}}。 | ||
|
||
## 示例 | ||
|
||
在此示例中,被 `registration` 指示的 {{domxref("ServiceWorkerRegistration")}} 订阅了 `"/path1"` 作用域下命名为 `"cookie1"` 的 cookie 的变更事件。 | ||
|
||
```js | ||
const subscriptions = [{ name: "cookie1", url: `/path1` }]; | ||
await registration.cookies.subscribe(subscriptions); | ||
``` | ||
|
||
如果 {{domxref("ServiceWorkerRegistration")}} 已经订阅了任何 cookie,{{domxref("CookieStoreManager.getSubscriptions()","getSubscriptions()")}} 将返回一个订阅时使用的对象匹配的 cookie 列表。 | ||
|
||
```js | ||
const subscriptions = await self.registration.cookies.getSubscriptions(); | ||
``` | ||
|
||
## 规范 | ||
|
||
{{Specifications}} | ||
|
||
## 浏览器兼容性 | ||
|
||
{{Compat}} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
见 #20146。后面参数可能都会改成“1”,就先统一用“1”吧