1e41f4b71Sopenharmony_ci# @ohos.enterprise.browser (Browser Management) (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **browser** module provides browser management, including setting, deleting, and obtaining browser policies.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> - The APIs of this module can be used only in the stage model.
10e41f4b71Sopenharmony_ci>
11e41f4b71Sopenharmony_ci> - The APIs of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is [enabled](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin).
12e41f4b71Sopenharmony_ci> 
13e41f4b71Sopenharmony_ci> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.enterprise.browser](js-apis-enterprise-browser.md).
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## Modules to Import
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci```ts
18e41f4b71Sopenharmony_ciimport { browser } from '@kit.MDMKit';
19e41f4b71Sopenharmony_ci```
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci## browser.setPolicies
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_cisetPolicies(admin: Want, appId: string, policies: string, callback: AsyncCallback<void>): void
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ciSets policies for a browser through the specified device administrator application. This API uses an asynchronous callback to return the result.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_SET_BROWSER_POLICY
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci**Parameters**
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci| Name     | Type                                      | Mandatory  | Description                      |
35e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- |
36e41f4b71Sopenharmony_ci| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
37e41f4b71Sopenharmony_ci| appId    | string              | Yes   | Application ID, which is used to specify the browser.                 |
38e41f4b71Sopenharmony_ci| policies    | string              | Yes   | Policies to set. If this parameter is set to an empty string, the policies of the specified browser will be deleted. |
39e41f4b71Sopenharmony_ci| callback | AsyncCallback<void>            | Yes   | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci**Error codes**
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci| ID| Error Message                                                                      |
46e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- |
47e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device.                  |
48e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device.                                          |
49e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
50e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
51e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci**Example**
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci```ts
56e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
57e41f4b71Sopenharmony_cilet wantTemp: Want = {
58e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
59e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
60e41f4b71Sopenharmony_ci};
61e41f4b71Sopenharmony_cilet appId: string = 'com.example.myapplication';
62e41f4b71Sopenharmony_cilet policies: string = '{"InsecurePrivateNetworkRequestsAllowed":{"level":"mandatory","scope":"machine","source":"platform","value":true},"LegacySameSiteCookieBehaviorEnabledForDomainList":{"level":"mandatory","scope":"machine","source":"platform","value":["[*.]"]}}';
63e41f4b71Sopenharmony_cibrowser.setPolicies(wantTemp, appId, policies, (err) => {
64e41f4b71Sopenharmony_ci  if (err) {
65e41f4b71Sopenharmony_ci    console.error(`Failed to set browser policies. Code is ${err.code}, message is ${err.message}`);
66e41f4b71Sopenharmony_ci    return;
67e41f4b71Sopenharmony_ci  }
68e41f4b71Sopenharmony_ci  console.info('Succeeded in setting browser policies.');
69e41f4b71Sopenharmony_ci});
70e41f4b71Sopenharmony_ci```
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci## browser.setPolicies
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_cisetPolicies(admin: Want, appId: string, policies: string): Promise<void>
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ciSets policies for a browser through the specified device administrator application. This API uses a promise to return the result.
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_SET_BROWSER_POLICY
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci**Parameters**
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci| Name  | Type                                 | Mandatory  | Description     |
86e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- |
87e41f4b71Sopenharmony_ci| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
88e41f4b71Sopenharmony_ci| appId    | string              | Yes   | Application ID, which is used to specify the browser.                 |
89e41f4b71Sopenharmony_ci| policies    | string                | Yes   | Policies to set. If this parameter is set to an empty string, the policies of the specified browser will be deleted.  |
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci**Return value**
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci| Type                  | Description                     |
94e41f4b71Sopenharmony_ci| --------------------- | ------------------------- |
95e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value. If the operation fails, an error object will be thrown. |
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci**Error codes**
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci| ID| Error Message                                                                    |
102e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- |
103e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device.                  |
104e41f4b71Sopenharmony_ci| 9200002 | The administrator application does not have permission to manage the device.                                          |
105e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
106e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
107e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci**Example**
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci```ts
112e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
113e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
114e41f4b71Sopenharmony_cilet wantTemp: Want = {
115e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
116e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
117e41f4b71Sopenharmony_ci};
118e41f4b71Sopenharmony_cilet appId: string = 'com.example.myapplication';
119e41f4b71Sopenharmony_cilet policies: string = '{"InsecurePrivateNetworkRequestsAllowed":{"level":"mandatory","scope":"machine","source":"platform","value":true},"LegacySameSiteCookieBehaviorEnabledForDomainList":{"level":"mandatory","scope":"machine","source":"platform","value":["[*.]"]}}';
120e41f4b71Sopenharmony_cibrowser.setPolicies(wantTemp, appId, policies).then(() => {
121e41f4b71Sopenharmony_ci  console.info('Succeeded in setting browser policies.');
122e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
123e41f4b71Sopenharmony_ci  console.error(`Failed to set browser policies. Code is ${err.code}, message is ${err.message}`);
124e41f4b71Sopenharmony_ci});
125e41f4b71Sopenharmony_ci```
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci## browser.getPolicies
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_cigetPolicies(admin: Want, appId: string, callback: AsyncCallback<string>): void
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ciObtains the policies of a browser through the specified device administrator application. This API uses an asynchronous callback to return the result.
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci**Parameters**
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci| Name     | Type                                      | Mandatory  | Description                      |
139e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------- |
140e41f4b71Sopenharmony_ci| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
141e41f4b71Sopenharmony_ci| appId    | string              | Yes   | Application ID, which is used to specify the browser.                 |
142e41f4b71Sopenharmony_ci| callback | AsyncCallback<string>       | Yes   | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.      |
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci**Error codes**
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci| ID| Error Message                                                                      |
149e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- |
150e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device.                  |
151e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
152e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci**Example**
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci```ts
157e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
158e41f4b71Sopenharmony_cilet wantTemp: Want = {
159e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
160e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
161e41f4b71Sopenharmony_ci};
162e41f4b71Sopenharmony_cilet appId: string = 'com.example.myapplication';
163e41f4b71Sopenharmony_cibrowser.getPolicies(wantTemp, appId, (err, result) => {
164e41f4b71Sopenharmony_ci  if (err) {
165e41f4b71Sopenharmony_ci    console.error(`Failed to get browser policies. Code is ${err.code}, message is ${err.message}`);
166e41f4b71Sopenharmony_ci    return;
167e41f4b71Sopenharmony_ci  }
168e41f4b71Sopenharmony_ci  console.info(`Succeeded in getting  browser policies, result : ${JSON.stringify(result)}`);
169e41f4b71Sopenharmony_ci});
170e41f4b71Sopenharmony_ci```
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci## browser.getPolicies
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_cigetPolicies(admin: Want, appId: string): Promise<string>
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ciObtains the policies of a browser through the specified device administrator application. This API uses a promise to return the result.
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci**Parameters**
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci| Name  | Type                                 | Mandatory  | Description     |
184e41f4b71Sopenharmony_ci| ----- | ----------------------------------- | ---- | ------- |
185e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes   | Device administrator application.|
186e41f4b71Sopenharmony_ci| appId    | string              | Yes   | Application ID, which is used to specify the browser.                 |
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ci**Return value**
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci| Type                  | Description                     |
191e41f4b71Sopenharmony_ci| --------------------- | ------------------------- |
192e41f4b71Sopenharmony_ci| Promise<string> | Promise used to return the browser policies obtained.|
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci**Error codes**
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci| ID| Error Message                                                                    |
199e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------------------------------- |
200e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device.                  |
201e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
202e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci**Example**
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_ci```ts
207e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit';
208e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
209e41f4b71Sopenharmony_cilet wantTemp: Want = {
210e41f4b71Sopenharmony_ci  bundleName: 'com.example.myapplication',
211e41f4b71Sopenharmony_ci  abilityName: 'EntryAbility',
212e41f4b71Sopenharmony_ci};
213e41f4b71Sopenharmony_cilet appId: string = 'com.example.myapplication';
214e41f4b71Sopenharmony_cibrowser.getPolicies(wantTemp, appId).then((result) => {
215e41f4b71Sopenharmony_ci  console.info(`Succeeded in getting browser policies, result : ${JSON.stringify(result)}`);
216e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
217e41f4b71Sopenharmony_ci  console.error(`Failed to get browser policies. Code is ${err.code}, message is ${err.message}`);
218e41f4b71Sopenharmony_ci});
219e41f4b71Sopenharmony_ci```
220