• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.enterprise.browser (Browser Management)
2
3The **browser** module provides browser management, including setting, canceling, and obtaining browser policies.
4
5Browser policies are a collection of rules and settings that govern how a browser behaves, ensuring security, compliance, performance optimization, and a consistent user experience.
6
7> **NOTE**
8>
9> - The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
10>
11> - The APIs of this module can be used only in the stage model.
12>
13> - The APIs of this module can be called only by a device administrator application that is enabled. For details, see [MDM Kit Development](../../mdm/mdm-kit-guide.md).
14
15## Modules to Import
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
25Sets the sub-policy for a specified browser.
26
27**Required permissions**: ohos.permission.ENTERPRISE_SET_BROWSER_POLICY
28
29**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
30
31**Parameters**
32
33| Name     | Type                                                   | Mandatory| Description                                                        |
34| ----------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
35| admin       | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | EnterpriseAdminExtensionAbility.                                              |
36| appId       | string                                                  | Yes  | Application ID, which is used to specify the browser.                                    |
37| policyName  | string                                                  | Yes  | Name of the browser policy to set. If the value is an empty string, the browser policy corresponding to the application ID is set.|
38| policyValue | string                                                  | Yes  | Browser policy to set. If the value is an empty string, the policy corresponding to the policy name is removed.|
39
40**Error codes**
41
42For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
43
44| ID| Error Message                                                    |
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**Example**
52
53```ts
54import { Want } from '@kit.AbilityKit';
55
56let wantTemp: Want = {
57  bundleName: 'com.example.myapplication',
58  abilityName: 'EntryAbility',
59};
60
61// Replace the value of appId with the specified application ID of the browser.
62let appId: string = 'com.example.******_******/******5t5CoBM=';
63let policyName: string = 'InsecurePrivateNetworkRequestsAllowed';
64let policyValue: string = '{"level":"mandatory","scope":"machine","source":"platform","value":true}';
65
66try {
67  browser.setPolicySync(wantTemp, appId, policyName, policyValue);
68  console.info('Succeeded in setting browser policies.');
69} catch (err) {
70  console.error(`Failed to set browser policies. Code is ${err.code}, message is ${err.message}`);
71}
72```
73
74## browser.getPoliciesSync
75
76getPoliciesSync(admin: Want, appId: string): string
77
78Obtains the policy set for a specified browser.
79
80**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
81
82
83**Parameters**
84
85| Name| Type                                                   | Mandatory| Description                    |
86| ------ | ------------------------------------------------------- | ---- | ------------------------ |
87| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | EnterpriseAdminExtensionAbility.          |
88| appId  | string                                                  | Yes  | Application ID, which is used to specify the browser.|
89
90**Return value**
91
92| Type  | Description        |
93| ------ | ------------ |
94| string | Browser policy obtained.|
95
96**Error codes**
97
98For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
99
100| ID| Error Message                                                    |
101| -------- | ------------------------------------------------------------ |
102| 9200001  | The application is not an administrator application of the device. |
103| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
104
105**Example**
106
107```ts
108import { Want } from '@kit.AbilityKit';
109
110let wantTemp: Want = {
111  bundleName: 'com.example.myapplication',
112  abilityName: 'EntryAbility',
113};
114
115// Replace the value of appId with the specified application ID of the browser.
116let appId: string = 'com.example.******_******/******5t5CoBM=';
117
118try {
119  let result: string = browser.getPoliciesSync(wantTemp, appId);
120  console.info(`Succeeded in getting browser policies, result : ${JSON.stringify(result)}`);
121} catch(err) {
122  console.error(`Failed to get browser policies. Code is ${err.code}, message is ${err.message}`);
123}
124```
125
126## browser.setManagedBrowserPolicy<sup>15+</sup>
127
128setManagedBrowserPolicy(admin: Want, bundleName: string, policyName: string, policyValue: string): void
129
130Sets the browser policy. After the setting is successful, the system common event [BROWSER_POLICY_CHANGED_EVENT](../apis-basic-services-kit/common_event/commonEventManager-definitions.md#common_event_managed_browser_policy_changed) is released.
131
132**Required permissions**: ohos.permission.ENTERPRISE_SET_BROWSER_POLICY
133
134**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
135
136**Parameters**
137
138| Name     | Type                                                   | Mandatory| Description                                                        |
139| ----------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
140| admin       | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | EnterpriseAdminExtensionAbility.                                              |
141| bundleName  | string                                                  | Yes  | Application bundle name, which is used to specify the browser.                                    |
142| policyName  | string                                                  | Yes  | Browser policy name.|
143| policyValue | string                                                  | Yes  | Browser policy value. If the value is an empty string, the policy corresponding to the policy name is removed.|
144
145**Error codes**
146
147For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
148
149| ID| Error Message                                                    |
150| -------- | ------------------------------------------------------------ |
151| 9200001  | The application is not an administrator application of the device. |
152| 9200002  | The administrator application does not have permission to manage the device. |
153| 201      | Permission verification failed. The application does not have the permission required to call the API. |
154| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
155
156**Example**
157
158```ts
159import { Want } from '@kit.AbilityKit';
160
161let wantTemp: Want = {
162  bundleName: 'com.example.myapplication',
163  abilityName: 'EntryAbility',
164};
165let bundleName: string = 'com.example.testbrowser';
166let policyName: string = 'InsecurePrivateNetworkRequestsAllowed';
167let policyValue: string = '{"level":"mandatory","scope":"machine","source":"platform","value":true}';
168
169try {
170  browser.setManagedBrowserPolicy(wantTemp, bundleName, policyName, policyValue);
171  console.info('Succeeded in setting managed browser policy.');
172} catch (err) {
173  console.error(`Failed to set managed browser policy. Code is ${err.code}, message is ${err.message}`);
174}
175```
176
177## browser.getManagedBrowserPolicy<sup>15+</sup>
178
179getManagedBrowserPolicy(admin: Want, bundleName: string): ArrayBuffer
180
181Obtains the policy of a specified browser.
182
183**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
184
185
186**Parameters**
187
188| Name     | Type                                                   | Mandatory| Description                    |
189| ----------- | ------------------------------------------------------- | ---- | ------------------------ |
190| admin       | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | EnterpriseAdminExtensionAbility.          |
191| bundleName  | string                                                  | Yes  | Application bundle name, which is used to specify the browser.|
192
193**Return value**
194
195| Type       | Description        |
196| ----------- | ------------ |
197| ArrayBuffer | Browser policy obtained.|
198
199**Error codes**
200
201For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
202
203| ID| Error Message                                                    |
204| -------- | ------------------------------------------------------------ |
205| 9200001  | The application is not an administrator application of the device. |
206| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
207
208**Example**
209
210```ts
211import { Want } from '@kit.AbilityKit';
212import { util } from '@kit.ArkTS';
213
214let wantTemp: Want = {
215  bundleName: 'com.example.myapplication',
216  abilityName: 'EntryAbility',
217};
218let bundleName: string = 'com.example.testbrowser';
219
220try {
221  let buffer: ArrayBuffer = browser.getManagedBrowserPolicy(wantTemp, bundleName);
222  let intBuffer: Uint8Array = new Uint8Array(buffer);
223  let decoder: util.TextDecoder = util.TextDecoder.create('utf-8');
224  let stringData: string = decoder.decodeToString(intBuffer);
225  console.info(`Succeeded in getting managed browser policy, result : ${stringData}`);
226} catch(err) {
227  console.error(`Failed to get managed browser policy. Code is ${err.code}, message is ${err.message}`);
228}
229```
230
231## browser.getSelfManagedBrowserPolicyVersion<sup>15+</sup>
232
233getSelfManagedBrowserPolicyVersion(): string
234
235Obtains the policy version of a specified browser.
236
237**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
238
239
240**Return value**
241
242| Type   | Description        |
243| ------ | ------------ |
244| string | Browser policy version.|
245
246**Example**
247
248```ts
249
250try {
251  let version: string = browser.getSelfManagedBrowserPolicyVersion();
252  console.info(`Succeeded in getting self managed browser policy version, result : ${version}`);
253} catch(err) {
254  console.error(`Failed to get self managed browser policy version. Code is ${err.code}, message is ${err.message}`);
255}
256```
257
258## browser.getSelfManagedBrowserPolicy<sup>15+</sup>
259
260getSelfManagedBrowserPolicy(): ArrayBuffer
261
262Obtains the policy of a specified browser.
263
264**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
265
266
267**Return value**
268
269| Type       | Description        |
270| ----------- | ------------ |
271| ArrayBuffer | Browser policy obtained.|
272
273**Example**
274
275```ts
276import { util } from '@kit.ArkTS';
277
278try {
279  let buffer: ArrayBuffer = browser.getSelfManagedBrowserPolicy();
280  let intBuffer: Uint8Array = new Uint8Array(buffer);
281  let decoder: util.TextDecoder = util.TextDecoder.create('utf-8');
282  let stringData: string = decoder.decodeToString(intBuffer);
283  console.info(`Succeeded in getting self managed browser policy, result : ${stringData}`);
284} catch(err) {
285  console.error(`Failed to get self managed browser policy. Code is ${err.code}, message is ${err.message}`);
286}
287```
288