• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.enterprise.browser(浏览器管理)
2
3本模块提供浏览器管理能力,包括设置/取消浏览器策略、获取浏览器策略等。
4
5浏览器策略指通过配置或管理浏览器行为的一系列规则和设置,以确保安全性、合规性、性能优化或用户体验的一致性。
6
7> **说明:**
8>
9> 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
10>
11> 本模块接口仅可在Stage模型下使用。
12>
13> 本模块接口仅对[设备管理应用](../../mdm/mdm-kit-guide.md#功能介绍)开放,需将设备管理应用激活后调用,实现相应功能。
14
15## 导入模块
16
17```ts
18import { browser } from '@kit.MDMKit';
19```
20
21## browser.setPolicySync
22
23setPolicySync(admin: Want, appId: string, policyName: string, policyValue: string): void
24
25为指定的浏览器设置浏览器子策略。
26
27**需要权限:** ohos.permission.ENTERPRISE_SET_BROWSER_POLICY
28
29**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
30
31**参数:**
32
33| 参数名      | 类型                                                    | 必填 | 说明                                                         |
34| ----------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
35| admin       | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。                                               |
36| appId       | string                                                  | 是   | 应用ID,用于指定浏览器。                                     |
37| policyName  | string                                                  | 是   | 浏览器子策略名。当此值为空字符串时,表示设置应用ID对应的浏览器策略。 |
38| policyValue | string                                                  | 是   | 浏览器子策略值。当此值为空字符串时,表示取消浏览器策略名对应浏览器子策略。 |
39
40**错误码**:
41
42以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
43
44| 错误码ID | 错误信息                                                     |
45| -------- | ------------------------------------------------------------ |
46| 9200001  | The application is not an administrator application of the device. |
47| 9200002  | The administrator application does not have permission to manage the device. |
48| 201      | Permission verification failed. The application does not have the permission required to call the API. |
49| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
50
51**示例:**
52
53```ts
54import { Want } from '@kit.AbilityKit';
55let wantTemp: Want = {
56  bundleName: 'com.example.myapplication',
57  abilityName: 'EntryAbility',
58};
59
60// 此处参数appId的赋值应替换为开发者自己指定的浏览器的应用ID
61let appId: string = 'com.example.******_******/******5t5CoBM=';
62let policyName: string = 'InsecurePrivateNetworkRequestsAllowed';
63let policyValue: string = '{"level":"mandatory","scope":"machine","source":"platform","value":true}';
64
65try {
66  browser.setPolicySync(wantTemp, appId, policyName, policyValue);
67  console.info('Succeeded in setting browser policies.');
68} catch (err) {
69  console.error(`Failed to set browser policies. Code is ${err.code}, message is ${err.message}`);
70}
71```
72
73## browser.getPoliciesSync
74
75getPoliciesSync(admin: Want, appId: string): string
76
77指定管理员应用获取指定浏览器的策略。
78
79**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
80
81
82**参数:**
83
84| 参数名 | 类型                                                    | 必填 | 说明                     |
85| ------ | ------------------------------------------------------- | ---- | ------------------------ |
86| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。           |
87| appId  | string                                                  | 是   | 应用ID,用于指定浏览器。 |
88
89**返回值:**
90
91| 类型   | 说明         |
92| ------ | ------------ |
93| string | 浏览器策略。 |
94
95**错误码**:
96
97以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
98
99| 错误码ID | 错误信息                                                     |
100| -------- | ------------------------------------------------------------ |
101| 9200001  | The application is not an administrator application of the device. |
102| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
103
104**示例:**
105
106```ts
107import { Want } from '@kit.AbilityKit';
108let wantTemp: Want = {
109  bundleName: 'com.example.myapplication',
110  abilityName: 'EntryAbility',
111};
112
113// 此处参数appId的赋值应替换为开发者自己指定的浏览器的应用ID
114let appId: string = 'com.example.******_******/******5t5CoBM=';
115
116try {
117  let result: string = browser.getPoliciesSync(wantTemp, appId);
118  console.info(`Succeeded in getting browser policies, result : ${JSON.stringify(result)}`);
119} catch(err) {
120  console.error(`Failed to get browser policies. Code is ${err.code}, message is ${err.message}`);
121}
122```
123
124## browser.setManagedBrowserPolicy<sup>15+</sup>
125
126setManagedBrowserPolicy(admin: Want, bundleName: string, policyName: string, policyValue: string): void
127
128为指定的浏览器设置浏览器策略,成功后会发布系统公共事件[BROWSER_POLICY_CHANGED_EVENT](../apis-basic-services-kit/common_event/commonEventManager-definitions.md#common_event_managed_browser_policy_changed)。
129
130**需要权限:** ohos.permission.ENTERPRISE_SET_BROWSER_POLICY
131
132**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
133
134**参数:**
135
136| 参数名      | 类型                                                    | 必填 | 说明                                                         |
137| ----------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
138| admin       | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。                                               |
139| bundleName  | string                                                  | 是   | 应用包名,用于指定浏览器。                                     |
140| policyName  | string                                                  | 是   | 浏览器策略名。 |
141| policyValue | string                                                  | 是   | 浏览器策略值。当此值为空字符串时,表示取消浏览器策略名对应浏览器子策略。 |
142
143**错误码**:
144
145以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
146
147| 错误码ID | 错误信息                                                     |
148| -------- | ------------------------------------------------------------ |
149| 9200001  | The application is not an administrator application of the device. |
150| 9200002  | The administrator application does not have permission to manage the device. |
151| 201      | Permission verification failed. The application does not have the permission required to call the API. |
152| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
153
154**示例:**
155
156```ts
157import { Want } from '@kit.AbilityKit';
158let wantTemp: Want = {
159  bundleName: 'com.example.myapplication',
160  abilityName: 'EntryAbility',
161};
162let bundleName: string = 'com.example.testbrowser';
163let policyName: string = 'InsecurePrivateNetworkRequestsAllowed';
164let policyValue: string = '{"level":"mandatory","scope":"machine","source":"platform","value":true}';
165
166try {
167  browser.setManagedBrowserPolicy(wantTemp, bundleName, policyName, policyValue);
168  console.info('Succeeded in setting managed browser policy.');
169} catch (err) {
170  console.error(`Failed to set managed browser policy. Code is ${err.code}, message is ${err.message}`);
171}
172```
173
174## browser.getManagedBrowserPolicy<sup>15+</sup>
175
176getManagedBrowserPolicy(admin: Want, bundleName: string): ArrayBuffer
177
178获取指定浏览器的浏览器策略。
179
180**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
181
182
183**参数:**
184
185| 参数名      | 类型                                                    | 必填 | 说明                     |
186| ----------- | ------------------------------------------------------- | ---- | ------------------------ |
187| admin       | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。           |
188| bundleName  | string                                                  | 是   | 应用包名,用于指定浏览器。 |
189
190**返回值:**
191
192| 类型        | 说明         |
193| ----------- | ------------ |
194| ArrayBuffer | 浏览器策略。 |
195
196**错误码**:
197
198以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
199
200| 错误码ID | 错误信息                                                     |
201| -------- | ------------------------------------------------------------ |
202| 9200001  | The application is not an administrator application of the device. |
203| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
204
205**示例:**
206
207```ts
208import { Want } from '@kit.AbilityKit';
209import { util } from '@kit.ArkTS';
210let wantTemp: Want = {
211  bundleName: 'com.example.myapplication',
212  abilityName: 'EntryAbility',
213};
214let bundleName: string = 'com.example.testbrowser';
215
216try {
217  let buffer: ArrayBuffer = browser.getManagedBrowserPolicy(wantTemp, bundleName);
218  let intBuffer: Uint8Array = new Uint8Array(buffer);
219  let decoder: util.TextDecoder = util.TextDecoder.create('utf-8');
220  let stringData: string = decoder.decodeToString(intBuffer);
221  console.info(`Succeeded in getting managed browser policy, result : ${stringData}`);
222} catch(err) {
223  console.error(`Failed to get managed browser policy. Code is ${err.code}, message is ${err.message}`);
224}
225```
226
227## browser.getSelfManagedBrowserPolicyVersion<sup>15+</sup>
228
229getSelfManagedBrowserPolicyVersion(): string
230
231获取指定浏览器的浏览器策略版本。
232
233**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
234
235
236**返回值:**
237
238| 类型    | 说明         |
239| ------ | ------------ |
240| string | 浏览器策略版本。 |
241
242**示例:**
243
244```ts
245
246try {
247  let version: string = browser.getSelfManagedBrowserPolicyVersion();
248  console.info(`Succeeded in getting self managed browser policy version, result : ${version}`);
249} catch(err) {
250  console.error(`Failed to get self managed browser policy version. Code is ${err.code}, message is ${err.message}`);
251}
252```
253
254## browser.getSelfManagedBrowserPolicy<sup>15+</sup>
255
256getSelfManagedBrowserPolicy(): ArrayBuffer
257
258获取指定浏览器的浏览器策略。
259
260**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
261
262
263**返回值:**
264
265| 类型        | 说明         |
266| ----------- | ------------ |
267| ArrayBuffer | 浏览器策略。 |
268
269**示例:**
270
271```ts
272import { util } from '@kit.ArkTS';
273
274try {
275  let buffer: ArrayBuffer = browser.getSelfManagedBrowserPolicy();
276  let intBuffer: Uint8Array = new Uint8Array(buffer);
277  let decoder: util.TextDecoder = util.TextDecoder.create('utf-8');
278  let stringData: string = decoder.decodeToString(intBuffer);
279  console.info(`Succeeded in getting self managed browser policy, result : ${stringData}`);
280} catch(err) {
281  console.error(`Failed to get self managed browser policy. Code is ${err.code}, message is ${err.message}`);
282}
283```