Skip to content

Commit b7e7cd5

Browse files
zh-CN: create privacy.network (#24877)
Co-authored-by: A1lo <[email protected]>
1 parent cf546b2 commit b7e7cd5

File tree

1 file changed

+111
-0
lines changed
  • files/zh-cn/mozilla/add-ons/webextensions/api/privacy/network

1 file changed

+111
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
title: privacy.network
3+
slug: Mozilla/Add-ons/WebExtensions/API/privacy/network
4+
l10n:
5+
sourceCommit: b8a0743ca8b1e1b1b1a95cc93a4413c020f11262
6+
---
7+
8+
{{AddonSidebar}}
9+
10+
`privacy.network` 属性包含了与隐私相关的网络设置。每个属性都是一个 {{WebExtAPIRef("types.BrowserSetting")}} 对象。
11+
12+
这些属性的默认值在不同的浏览器中可能有所不同。
13+
14+
## 属性
15+
16+
- `networkPredictionEnabled`
17+
- : {{WebExtAPIRef("types.BrowserSetting")}} 对象,其底层值是布尔值。若为 `true`,则浏览器将尝试通过预解析 DNS 条目、预渲染站点(例如使用 `<link rel='prefetch' …>`)以及预先打开到服务器的 TCP 和 TLS 连接来提升 Web 浏览速度。
18+
- `peerConnectionEnabled`
19+
- : {{WebExtAPIRef("types.BrowserSetting")}} 对象,其底层值是布尔值。若为 `false`,则 [`RTCPeerConnection`](/zh-CN/docs/Web/API/RTCPeerConnection) 接口将被禁用。请注意,[`getUserMedia()`](/zh-CN/docs/Web/API/MediaDevices/getUserMedia) **受此设置影响。
20+
- `webRTCIPHandlingPolicy`
21+
22+
- : {{WebExtAPIRef("types.BrowserSetting")}} 对象,其底层值是字符串。这一设置将允许用户指定影响 WebRTC 流量路由方式以及暴露多少本地地址信息的媒体性能/隐私权衡。它可以取以下任一值,从最不私密到最私密:
23+
24+
- `default`
25+
- `default_public_and_private_interfaces`
26+
- `default_public_interface_only`
27+
- `disable_non_proxied_udp`
28+
- `proxy_only`(仅允许基于代理的 TCP 连接的 TURN 连接)
29+
30+
- `httpsOnlyMode`
31+
32+
- : 这一设置允许你的扩展程序确定用户是否启用了 [HTTPS-Only 模式](https://support.mozilla.org/zh-CN/kb/firefox-https)。该属性在所有平台上都是只读的。其底层值是一个字符串,可以取以下三个值之一:
33+
34+
- `"always"`:HTTPS-Only 模式已启用。
35+
- `"never"`:HTTPS-Only 模式已关闭。
36+
- `"private_browsing"`:仅在隐私浏览窗口中启用了 HTTPS-Only 模式。
37+
38+
- `globalPrivacyControl`
39+
40+
- : 这一设置允许你的扩展程序确定用户是否启用了[全局隐私控制](/zh-CN/docs/Web/API/Navigator/globalPrivacyControl)。该属性在所有平台上都是只读的。其底层值是一个布尔值,其中 `true` 表示浏览器发送全局隐私控制信号,`false` 表示浏览器不发送这些信号。
41+
42+
## 浏览器兼容性
43+
44+
{{Compat}}
45+
46+
## 示例
47+
48+
设置 `webRTCIPHandlingPolicy` 属性:
49+
50+
```js
51+
function onSet(result) {
52+
if (result) {
53+
console.log("成功");
54+
} else {
55+
console.log("失败");
56+
}
57+
}
58+
59+
browser.browserAction.onClicked.addListener(() => {
60+
let getting = browser.privacy.network.webRTCIPHandlingPolicy.get({});
61+
getting.then((got) => {
62+
console.log(got.value);
63+
if (
64+
got.levelOfControl === "controlled_by_this_extension" ||
65+
got.levelOfControl === "controllable_by_this_extension"
66+
) {
67+
let setting = browser.privacy.network.webRTCIPHandlingPolicy.set({
68+
value: "default_public_interface_only",
69+
});
70+
setting.then(onSet);
71+
} else {
72+
console.log("无法设置 webRTCIPHandlingPolicy");
73+
}
74+
});
75+
});
76+
```
77+
78+
{{WebExtExamples}}
79+
80+
> [!NOTE]
81+
> 该 API 基于 Chromium 的 [`chrome.privacy`](https://developer.chrome.google.cn/docs/extensions/reference/api/privacy) API。本文衍生自 Chromium 代码中的 [`privacy.json`](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/privacy.json)
82+
83+
<!--
84+
// Copyright 2015 The Chromium Authors. All rights reserved.
85+
//
86+
// Redistribution and use in source and binary forms, with or without
87+
// modification, are permitted provided that the following conditions are
88+
// met:
89+
//
90+
// * Redistributions of source code must retain the above copyright
91+
// notice, this list of conditions and the following disclaimer.
92+
// * Redistributions in binary form must reproduce the above
93+
// copyright notice, this list of conditions and the following disclaimer
94+
// in the documentation and/or other materials provided with the
95+
// distribution.
96+
// * Neither the name of Google Inc. nor the names of its
97+
// contributors may be used to endorse or promote products derived from
98+
// this software without specific prior written permission.
99+
//
100+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
101+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
102+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
103+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
104+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
105+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
106+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
107+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
108+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
109+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
110+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
111+
-->

0 commit comments

Comments
 (0)