Skip to content
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 3 commits into from
May 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions files/zh-cn/web/api/cookiestoremanager/index.md
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()")}} 方法接收变更事件。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#20146。后面参数可能都会改成“1”,就先统一用“1”吧

Suggested change
{{domxref("Cookie Store API", "", "", "nocode")}} 的 **`CookieStoreManager`** 接口允许 Service Worker 订阅 cookie 变更事件。调用特定的 Service Worker 注册器的 {{domxref("CookieStoreManager.subscribe()","subscribe()")}} 方法接收变更事件。
{{domxref("Cookie Store API", "", "", 1)}} 的 **`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 的变更事件。
xyy94813 marked this conversation as resolved.
Show resolved Hide resolved

```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}}