@ohos.enterprise.browser (Browser Management) (System API)
The browser module provides browser management, including setting, deleting, and obtaining browser policies.
NOTE
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.
The APIs of this module can be used only in the stage model.
The APIs of this module can be called only by a device administrator application that is enabled.
This topic describes only the system APIs provided by the module. For details about its public APIs, see @ohos.enterprise.browser.
Modules to Import
import { browser } from '@kit.MDMKit';
browser.setPolicies
setPolicies(admin: Want, appId: string, policies: string, callback: AsyncCallback<void>): void
Sets policies for a browser through the specified device administrator application. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.ENTERPRISE_SET_BROWSER_POLICY
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| admin | Want | Yes | Device administrator application. |
| appId | string | Yes | Application ID, which is used to specify the browser. |
| policies | string | Yes | Policies to set. If this parameter is set to an empty string, the policies of the specified browser will be deleted. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 202 | Permission verification failed. A non-system application calls a system API. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appId: string = 'com.example.myapplication';
let policies: string = '{"InsecurePrivateNetworkRequestsAllowed":{"level":"mandatory","scope":"machine","source":"platform","value":true},"LegacySameSiteCookieBehaviorEnabledForDomainList":{"level":"mandatory","scope":"machine","source":"platform","value":["[*.]"]}}';
browser.setPolicies(wantTemp, appId, policies, (err) => {
if (err) {
console.error(`Failed to set browser policies. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info('Succeeded in setting browser policies.');
});
browser.setPolicies
setPolicies(admin: Want, appId: string, policies: string): Promise<void>
Sets policies for a browser through the specified device administrator application. This API uses a promise to return the result.
Required permissions: ohos.permission.ENTERPRISE_SET_BROWSER_POLICY
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| admin | Want | Yes | Device administrator application. |
| appId | string | Yes | Application ID, which is used to specify the browser. |
| policies | string | Yes | Policies to set. If this parameter is set to an empty string, the policies of the specified browser will be deleted. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. If the operation fails, an error object will be thrown. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
| 201 | Permission verification failed. The application does not have the permission required to call the API. |
| 202 | Permission verification failed. A non-system application calls a system API. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appId: string = 'com.example.myapplication';
let policies: string = '{"InsecurePrivateNetworkRequestsAllowed":{"level":"mandatory","scope":"machine","source":"platform","value":true},"LegacySameSiteCookieBehaviorEnabledForDomainList":{"level":"mandatory","scope":"machine","source":"platform","value":["[*.]"]}}';
browser.setPolicies(wantTemp, appId, policies).then(() => {
console.info('Succeeded in setting browser policies.');
}).catch((err: BusinessError) => {
console.error(`Failed to set browser policies. Code is ${err.code}, message is ${err.message}`);
});
browser.getPolicies
getPolicies(admin: Want, appId: string, callback: AsyncCallback<string>): void
Obtains the policies of a browser through the specified device administrator application. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| admin | Want | Yes | Device administrator application. |
| appId | string | Yes | Application ID, which is used to specify the browser. |
| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 202 | Permission verification failed. A non-system application calls a system API. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appId: string = 'com.example.myapplication';
browser.getPolicies(wantTemp, appId, (err, result) => {
if (err) {
console.error(`Failed to get browser policies. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info(`Succeeded in getting browser policies, result : ${JSON.stringify(result)}`);
});
browser.getPolicies
getPolicies(admin: Want, appId: string): Promise<string>
Obtains the policies of a browser through the specified device administrator application. This API uses a promise to return the result.
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| admin | Want | Yes | Device administrator application. |
| appId | string | Yes | Application ID, which is used to specify the browser. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the browser policies obtained. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 9200001 | The application is not an administrator application of the device. |
| 202 | Permission verification failed. A non-system application calls a system API. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appId: string = 'com.example.myapplication';
browser.getPolicies(wantTemp, appId).then((result) => {
console.info(`Succeeded in getting browser policies, result : ${JSON.stringify(result)}`);
}).catch((err: BusinessError) => {
console.error(`Failed to get browser policies. Code is ${err.code}, message is ${err.message}`);
});