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