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