• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.enterprise.browser(浏览器管理)
2
3本模块提供浏览器管理能力,包括设置/取消浏览器策略、获取浏览器策略等。
4
5> **说明:**
6>
7> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9> 本模块接口仅可在Stage模型下使用。
10>
11> 本模块接口仅对[设备管理应用](enterpriseDeviceManagement-overview.md#基本概念)开放,需将[设备管理应用激活](js-apis-enterprise-adminManager.md#adminmanagerenableadmin)后调用,实现相应功能。
12
13## 导入模块
14
15```ts
16import browser from '@ohos.enterprise.browser';
17```
18
19## browser.setPolicies
20
21setPolicies(admin: Want, appId: string, policies: string, callback: AsyncCallback<void>): void
22
23指定设备管理应用为指定的浏览器设置浏览策略,使用callback异步回调。
24
25**需要权限:** ohos.permission.ENTERPRISE_SET_BROWSER_POLICY
26
27**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
28
29**系统API**: 此接口为系统接口。
30
31**参数:**
32
33| 参数名      | 类型                                       | 必填   | 说明                       |
34| -------- | ---------------------------------------- | ---- | ------------------------------- |
35| admin    | [Want](js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
36| appId    | string              | 是    | 应用ID,用于指定浏览器。                  |
37| policies    | string              | 是    | 浏览器策略,当参数policies为空字符串时,表示取消指定浏览器的策略。                  |
38| callback | AsyncCallback<void>            | 是    | 回调函数。当接口调用成功,err为null,否则为错误对象。 |
39
40**错误码**:
41
42以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
43
44| 错误码ID | 错误信息                                                                       |
45| ------- | ---------------------------------------------------------------------------- |
46| 9200001 | the application is not an administrator of the device.                              |
47| 9200002 | the administrator application does not have permission to manage the device.                                          |
48
49**示例:**
50
51```ts
52import Want from '@ohos.app.ability.Want';
53let wantTemp: Want = {
54  bundleName: 'com.example.myapplication',
55  abilityName: 'EntryAbility',
56};
57let appId: string = 'com.example.myapplication';
58let policies: string = '{"InsecurePrivateNetworkRequestsAllowed":{"level":"mandatory","scope":"machine","source":"platform","value":true},"LegacySameSiteCookieBehaviorEnabledForDomainList":{"level":"mandatory","scope":"machine","source":"platform","value":["[*.]"]}}';
59browser.setPolicies(wantTemp, appId, policies, (err) => {
60  if (err) {
61    console.error(`Failed to set browser policies. Code is ${err.code}, message is ${err.message}`);
62    return;
63  }
64  console.info('Succeeded in setting browser policies');
65});
66```
67
68## browser.setPolicies
69
70setPolicies(admin: Want, appId: string, policies: string): Promise<void>
71
72指定设备管理应用为指定的浏览器设置浏览策略,使用promise异步回调。
73
74**需要权限:** ohos.permission.ENTERPRISE_SET_BROWSER_POLICY
75
76**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
77
78**系统API**: 此接口为系统接口。
79
80**参数:**
81
82| 参数名   | 类型                                  | 必填   | 说明      |
83| ----- | ----------------------------------- | ---- | ------- |
84| admin    | [Want](js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
85| appId    | string              | 是    | 应用ID,用于指定浏览器。                  |
86| policies    | string                | 是    | 浏览器策略,当参数policies为空字符串时,表示取消指定浏览器的策略。                  |
87
88**返回值:**
89
90| 类型                   | 说明                      |
91| --------------------- | ------------------------- |
92| Promise<void> | 无返回结果的Promise对象。当指定设备管理应用设置浏览器策略失败时,会抛出错误对象。  |
93
94**错误码**:
95
96以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
97
98| 错误码ID | 错误信息                                                                     |
99| ------- | ---------------------------------------------------------------------------- |
100| 9200001 | the application is not an administrator of the device.                              |
101| 9200002 | the administrator application does not have permission to manage the device.                                          |
102
103**示例:**
104
105```ts
106import Want from '@ohos.app.ability.Want';
107import { BusinessError } from '@ohos.base';
108let wantTemp: Want = {
109  bundleName: 'com.example.myapplication',
110  abilityName: 'EntryAbility',
111};
112let appId: string = 'com.example.myapplication';
113let policies: string = '{"InsecurePrivateNetworkRequestsAllowed":{"level":"mandatory","scope":"machine","source":"platform","value":true},"LegacySameSiteCookieBehaviorEnabledForDomainList":{"level":"mandatory","scope":"machine","source":"platform","value":["[*.]"]}}';
114browser.setPolicies(wantTemp, appId, policies).then(() => {
115  console.info('Succeeded in setting browser policies');
116}).catch((err: BusinessError) => {
117  console.error(`Failed to set browser policies. Code is ${err.code}, message is ${err.message}`);
118});
119```
120
121## browser.getPolicies
122
123getPolicies(admin: Want, appId: string, callback: AsyncCallback<string>): void
124
125指定管理员应用获取指定浏览器的策略,使用callback异步回调。
126
127**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
128
129**系统API**: 此接口为系统接口。
130
131**参数:**
132
133| 参数名      | 类型                                       | 必填   | 说明                       |
134| -------- | ---------------------------------------- | ---- | ------------------------------- |
135| admin    | [Want](js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
136| appId    | string              | 是    | 应用ID,用于指定浏览器。                  |
137| callback | AsyncCallback<string>       | 是    | 回调函数,当接口调用成功,err为null,否则为错误对象。       |
138
139**错误码**:
140
141以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
142
143| 错误码ID | 错误信息                                                                       |
144| ------- | ---------------------------------------------------------------------------- |
145| 9200001 | the application is not an administrator of the device.                              |
146
147**示例:**
148
149```ts
150import Want from '@ohos.app.ability.Want';
151let wantTemp: Want = {
152  bundleName: 'com.example.myapplication',
153  abilityName: 'EntryAbility',
154};
155let appId: string = 'com.example.myapplication';
156browser.getPolicies(wantTemp, appId, (err, result) => {
157  if (err) {
158    console.error(`Failed to get browser policies. Code is ${err.code}, message is ${err.message}`);
159    return;
160  }
161  console.info(`Succeeded in getting  browser policies, result : ${JSON.stringify(result)}`);
162});
163```
164
165## browser.getPolicies
166
167getPolicies(admin: Want, appId: string): Promise<string>
168
169指定管理员应用获取指定浏览器的策略,使用promise异步回调。
170
171**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
172
173**系统API**: 此接口为系统接口。
174
175**参数:**
176
177| 参数名   | 类型                                  | 必填   | 说明      |
178| ----- | ----------------------------------- | ---- | ------- |
179| admin | [Want](js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
180| appId    | string              | 是    | 应用ID,用于指定浏览器。                  |
181
182**返回值:**
183
184| 类型                   | 说明                      |
185| --------------------- | ------------------------- |
186| Promise<string> | Promise对象,返回浏览器策略。 |
187
188**错误码**:
189
190以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
191
192| 错误码ID | 错误信息                                                                     |
193| ------- | ---------------------------------------------------------------------------- |
194| 9200001 | the application is not an administrator of the device.                              |
195
196**示例:**
197
198```ts
199import Want from '@ohos.app.ability.Want';
200import { BusinessError } from '@ohos.base';
201let wantTemp: Want = {
202  bundleName: 'com.example.myapplication',
203  abilityName: 'EntryAbility',
204};
205let appId: string = 'com.example.myapplication';
206browser.getPolicies(wantTemp, appId).then((result) => {
207  console.info(`Succeeded in getting browser policies, result : ${JSON.stringify(result)}`);
208}).catch((err: BusinessError) => {
209  console.error(`Failed to get browser policies. Code is ${err.code}, message is ${err.message}`);
210});
211```
212