1# @ohos.enterprise.browser (Browser Management)
2
3The **browser** module provides browser management, including setting, deleting, and obtaining browser policies.
4
5> **NOTE**
6>
7> - 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.
8>
9> - The APIs of this module can be used only in the stage model.
10>
11> - The APIs of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is enabled.
12
13## Modules to Import
14
15```ts
16import { browser } from '@kit.MDMKit';
17```
18
19## browser.setPolicySync
20
21setPolicySync(admin: Want, appId: string, policyName: string, policyValue: string): void
22
23Sets a policy for a browser through the specified device administrator application.
24
25**Required permissions**: ohos.permission.ENTERPRISE_SET_BROWSER_POLICY
26
27**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
28
29**Parameters**
30
31| Name     | Type                                                   | Mandatory| Description                                                        |
32| ----------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
33| admin       | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | Device administrator application.                                              |
34| appId       | string                                                  | Yes  | Application ID, which is used to specify the browser.                                    |
35| 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.|
36| policyValue | string                                                  | Yes  | Browser policy to set. If the value is an empty string, the policy corresponding to the policy name is removed.|
37
38**Error codes**
39
40For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
41
42| ID| Error Message                                                    |
43| -------- | ------------------------------------------------------------ |
44| 9200001  | The application is not an administrator application of the device. |
45| 9200002  | The administrator application does not have permission to manage the device. |
46| 201      | Permission verification failed. The application does not have the permission required to call the API. |
47| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
48
49**Example**
50
51```ts
52import { Want } from '@kit.AbilityKit';
53let wantTemp: Want = {
54  bundleName: 'com.example.myapplication',
55  abilityName: 'EntryAbility',
56};
57let appId: string = 'com.example.myapplication';
58let policyName: string = 'InsecurePrivateNetworkRequestsAllowed';
59let policyValue: string = '{"level":"mandatory","scope":"machine","source":"platform","value":true}';
60
61try {
62  browser.setPolicySync(wantTemp, appId, policyName, policyValue);
63  console.info('Succeeded in setting browser policies.');
64} catch (err) {
65  console.error(`Failed to set browser policies. Code is ${err.code}, message is ${err.message}`);
66}
67```
68
69## browser.getPoliciesSync
70
71getPoliciesSync(admin: Want, appId: string): string
72
73Obtains the policies of a browser through the specified device administrator application.
74
75**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
76
77
78**Parameters**
79
80| Name| Type                                                   | Mandatory| Description                    |
81| ------ | ------------------------------------------------------- | ---- | ------------------------ |
82| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | Device administrator application.          |
83| appId  | string                                                  | Yes  | Application ID, which is used to specify the browser.|
84
85**Return value**
86
87| Type  | Description        |
88| ------ | ------------ |
89| string | Browser policies obtained.|
90
91**Error codes**
92
93For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
94
95| ID| Error Message                                                    |
96| -------- | ------------------------------------------------------------ |
97| 9200001  | The application is not an administrator application of the device. |
98| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
99
100**Example**
101
102```ts
103import { Want } from '@kit.AbilityKit';
104let wantTemp: Want = {
105  bundleName: 'com.example.myapplication',
106  abilityName: 'EntryAbility',
107};
108let appId: string = 'com.example.myapplication';
109
110try {
111  let result: string = browser.getPoliciesSync(wantTemp, appId);
112  console.info(`Succeeded in getting browser policies, result : ${JSON.stringify(result)}`);
113} catch(err) {
114  console.error(`Failed to get browser policies. Code is ${err.code}, message is ${err.message}`);
115}
116```
117