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