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