# @ohos.enterprise.browser(æµè§ˆå™¨ç®¡ç†ï¼‰(系统接å£) 本模å—æä¾›æµè§ˆå™¨ç®¡ç†èƒ½åŠ›ï¼ŒåŒ…括设置/å–消æµè§ˆå™¨ç–ç•¥ã€èŽ·å–æµè§ˆå™¨ç–ç•¥ç‰ã€‚ > **说明:** > > 本模å—首批接å£ä»ŽAPI version 10开始支æŒã€‚åŽç»ç‰ˆæœ¬çš„新增接å£ï¼Œé‡‡ç”¨ä¸Šè§’æ ‡å•ç‹¬æ ‡è®°æŽ¥å£çš„起始版本。 > > 本模å—接å£ä»…å¯åœ¨Stage模型下使用。 > > 本模å—接å£ä»…对[设备管ç†åº”用](../../mdm/mdm-kit-guide.md#功能介ç»)开放,需将[设备管ç†åº”用激活](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin)åŽè°ƒç”¨ï¼Œå®žçŽ°ç›¸åº”功能。 > > 当å‰é¡µé¢ä»…包å«æœ¬æ¨¡å—的系统接å£ï¼Œå…¶ä»–公开接å£å‚è§ã€‚其他公开接å£å‚è§[@ohos.enterprise.browser](js-apis-enterprise-browser.md)。 ## å¯¼å…¥æ¨¡å— ```ts import { browser } from '@kit.MDMKit'; ``` ## browser.setPolicies setPolicies(admin: Want, appId: string, policies: string, callback: AsyncCallback<void>): void 指定设备管ç†åº”用为指定的æµè§ˆå™¨è®¾ç½®æµè§ˆç–略,使用callback异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.ENTERPRISE_SET_BROWSER_POLICY **系统能力:** SystemCapability.Customization.EnterpriseDeviceManager **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | -------- | ---------------------------------------- | ---- | ------------------------------- | | admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 设备管ç†åº”用。 | | appId | string | 是 | 应用ID,用于指定æµè§ˆå™¨ã€‚ | | policies | string | 是 | æµè§ˆå™¨ç–略,当å‚æ•°policies为空å—符串时,表示å–消指定æµè§ˆå™¨çš„ç–略。 | | callback | AsyncCallback<void> | 是 | 回调函数。当接å£è°ƒç”¨æˆåŠŸï¼Œerr为null,å¦åˆ™ä¸ºé”™è¯¯å¯¹è±¡ã€‚ | **错误ç **: 以下错误ç 的详细介ç»è¯·å‚è§[ä¼ä¸šè®¾å¤‡ç®¡ç†é”™è¯¯ç ](errorcode-enterpriseDeviceManager.md)å’Œ[通用错误ç ](../errorcode-universal.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | ------- | ---------------------------------------------------------------------------- | | 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. | **示例:** ```ts 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> 指定设备管ç†åº”用为指定的æµè§ˆå™¨è®¾ç½®æµè§ˆç–略,使用promise异æ¥å›žè°ƒã€‚ **需è¦æƒé™ï¼š** ohos.permission.ENTERPRISE_SET_BROWSER_POLICY **系统能力:** SystemCapability.Customization.EnterpriseDeviceManager **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | ----- | ----------------------------------- | ---- | ------- | | admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 设备管ç†åº”用。 | | appId | string | 是 | 应用ID,用于指定æµè§ˆå™¨ã€‚ | | policies | string | 是 | æµè§ˆå™¨ç–略,当å‚æ•°policies为空å—符串时,表示å–消指定æµè§ˆå™¨çš„ç–略。 | **返回值:** | 类型 | 说明 | | --------------------- | ------------------------- | | Promise<void> | æ— è¿”å›žç»“æžœçš„Promise对象。当指定设备管ç†åº”用设置æµè§ˆå™¨ç–略失败时,会抛出错误对象。 | **错误ç **: 以下错误ç 的详细介ç»è¯·å‚è§[ä¼ä¸šè®¾å¤‡ç®¡ç†é”™è¯¯ç ](errorcode-enterpriseDeviceManager.md)å’Œ[通用错误ç ](../errorcode-universal.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | ------- | ---------------------------------------------------------------------------- | | 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. | **示例:** ```ts 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 指定管ç†å‘˜åº”用获å–指定æµè§ˆå™¨çš„ç–略,使用callback异æ¥å›žè°ƒã€‚ **系统能力:** SystemCapability.Customization.EnterpriseDeviceManager **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | -------- | ---------------------------------------- | ---- | ------------------------------- | | admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 设备管ç†åº”用。 | | appId | string | 是 | 应用ID,用于指定æµè§ˆå™¨ã€‚ | | callback | AsyncCallback<string> | 是 | 回调函数,当接å£è°ƒç”¨æˆåŠŸï¼Œerr为null,å¦åˆ™ä¸ºé”™è¯¯å¯¹è±¡ã€‚ | **错误ç **: 以下错误ç 的详细介ç»è¯·å‚è§[ä¼ä¸šè®¾å¤‡ç®¡ç†é”™è¯¯ç ](errorcode-enterpriseDeviceManager.md)å’Œ[通用错误ç ](../errorcode-universal.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | ------- | ---------------------------------------------------------------------------- | | 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. | **示例:** ```ts 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> 指定管ç†å‘˜åº”用获å–指定æµè§ˆå™¨çš„ç–略,使用promise异æ¥å›žè°ƒã€‚ **系统能力:** SystemCapability.Customization.EnterpriseDeviceManager **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | ----- | ----------------------------------- | ---- | ------- | | admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 设备管ç†åº”用。 | | appId | string | 是 | 应用ID,用于指定æµè§ˆå™¨ã€‚ | **返回值:** | 类型 | 说明 | | --------------------- | ------------------------- | | Promise<string> | Promise对象,返回æµè§ˆå™¨ç–略。 | **错误ç **: 以下错误ç 的详细介ç»è¯·å‚è§[ä¼ä¸šè®¾å¤‡ç®¡ç†é”™è¯¯ç ](errorcode-enterpriseDeviceManager.md)å’Œ[通用错误ç ](../errorcode-universal.md)。 | 错误ç ID | é”™è¯¯ä¿¡æ¯ | | ------- | ---------------------------------------------------------------------------- | | 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. | **示例:** ```ts 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}`); }); ```