1e41f4b71Sopenharmony_ci# Intelligent Tracking Prevention 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ciThe **Web** component supports the intelligent tracking prevention. That is, when a tracking website is inserted into another web page as a third party, the network request sent by the website cannot carry cookies. 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci- Invoke the [enableIntelligentTrackingPrevention](../reference/apis-arkweb/js-apis-webview.md#enableintelligenttrackingprevention12) API to enable or disable the intelligent tracking prevention of a **Web** component. By default, this prevention is disabled. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci ```ts 9e41f4b71Sopenharmony_ci // xxx.ets 10e41f4b71Sopenharmony_ci import { webview } from '@kit.ArkWeb'; 11e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci @Entry 14e41f4b71Sopenharmony_ci @Component 15e41f4b71Sopenharmony_ci struct WebComponent { 16e41f4b71Sopenharmony_ci controller: webview.WebviewController = new webview.WebviewController(); 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci build() { 19e41f4b71Sopenharmony_ci Column() { 20e41f4b71Sopenharmony_ci Button('enableIntelligentTrackingPrevention') 21e41f4b71Sopenharmony_ci .onClick(() => { 22e41f4b71Sopenharmony_ci try { 23e41f4b71Sopenharmony_ci this.controller.enableIntelligentTrackingPrevention(true); 24e41f4b71Sopenharmony_ci console.log("enableIntelligentTrackingPrevention: true"); 25e41f4b71Sopenharmony_ci } catch (error) { 26e41f4b71Sopenharmony_ci console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); 27e41f4b71Sopenharmony_ci } 28e41f4b71Sopenharmony_ci }) 29e41f4b71Sopenharmony_ci Web({ src: 'www.example.com', controller: this.controller }) 30e41f4b71Sopenharmony_ci } 31e41f4b71Sopenharmony_ci } 32e41f4b71Sopenharmony_ci } 33e41f4b71Sopenharmony_ci ``` 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci- Invoke the [isIntelligentTrackingPreventionEnabled](../reference/apis-arkweb/js-apis-webview.md#isintelligenttrackingpreventionenabled12) API to check whether the intelligent tracking prevention is enabled for the **Web** component. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci ```ts 38e41f4b71Sopenharmony_ci // xxx.ets 39e41f4b71Sopenharmony_ci import { webview } from '@kit.ArkWeb'; 40e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci @Entry 43e41f4b71Sopenharmony_ci @Component 44e41f4b71Sopenharmony_ci struct WebComponent { 45e41f4b71Sopenharmony_ci controller: webview.WebviewController = new webview.WebviewController(); 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci build() { 48e41f4b71Sopenharmony_ci Column() { 49e41f4b71Sopenharmony_ci Button('isIntelligentTrackingPreventionEnabled') 50e41f4b71Sopenharmony_ci .onClick(() => { 51e41f4b71Sopenharmony_ci try { 52e41f4b71Sopenharmony_ci let result = this.controller.isIntelligentTrackingPreventionEnabled(); 53e41f4b71Sopenharmony_ci console.log("result: " + result); 54e41f4b71Sopenharmony_ci } catch (error) { 55e41f4b71Sopenharmony_ci console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); 56e41f4b71Sopenharmony_ci } 57e41f4b71Sopenharmony_ci }) 58e41f4b71Sopenharmony_ci Web({ src: 'www.example.com', controller: this.controller }) 59e41f4b71Sopenharmony_ci } 60e41f4b71Sopenharmony_ci } 61e41f4b71Sopenharmony_ci } 62e41f4b71Sopenharmony_ci ``` 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci- You can call the [onIntelligentTrackingPreventionResult](../reference/apis-arkweb/ts-basic-components-web.md#onintelligenttrackingpreventionresult12) API to asynchronously obtain the domain names of intercepted tracking websites and accessed websites. 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci ```ts 67e41f4b71Sopenharmony_ci // xxx.ets 68e41f4b71Sopenharmony_ci import { webview } from '@kit.ArkWeb'; 69e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci @Entry 72e41f4b71Sopenharmony_ci @Component 73e41f4b71Sopenharmony_ci struct WebComponent { 74e41f4b71Sopenharmony_ci controller: webview.WebviewController = new webview.WebviewController(); 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci build() { 77e41f4b71Sopenharmony_ci Column() { 78e41f4b71Sopenharmony_ci // The onIntelligentTrackingPreventionResult callback is triggered only when the intelligent tracking prenvention is enabled. 79e41f4b71Sopenharmony_ci Button('enableIntelligentTrackingPrevention') 80e41f4b71Sopenharmony_ci .onClick(() => { 81e41f4b71Sopenharmony_ci try { 82e41f4b71Sopenharmony_ci this.controller.enableIntelligentTrackingPrevention(true); 83e41f4b71Sopenharmony_ci } catch (error) { 84e41f4b71Sopenharmony_ci console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); 85e41f4b71Sopenharmony_ci } 86e41f4b71Sopenharmony_ci }) 87e41f4b71Sopenharmony_ci Web({ src: 'www.example.com', controller: this.controller }) 88e41f4b71Sopenharmony_ci .onIntelligentTrackingPreventionResult((details) => { 89e41f4b71Sopenharmony_ci console.log("onIntelligentTrackingPreventionResult: [websiteHost]= " + details.host + 90e41f4b71Sopenharmony_ci ", [trackerHost]=" + details.trackerHost); 91e41f4b71Sopenharmony_ci }) 92e41f4b71Sopenharmony_ci } 93e41f4b71Sopenharmony_ci } 94e41f4b71Sopenharmony_ci } 95e41f4b71Sopenharmony_ci ``` 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ciIn addition, the intelligent tracking prevention functionality provides APIs for setting the list of domain names that need to bypass the intelligent tracking prevention. The domain name list set by these APIs applies to the entire application instead of a single **Web** component. 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci- Invoke the [addIntelligentTrackingPreventionBypassingList](../reference/apis-arkweb/js-apis-webview.md#addintelligenttrackingpreventionbypassinglist12) API to set the list of domain names that need to bypass the intelligent tracking prevention. 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci ```ts 102e41f4b71Sopenharmony_ci // xxx.ets 103e41f4b71Sopenharmony_ci import { webview } from '@kit.ArkWeb'; 104e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci @Entry 107e41f4b71Sopenharmony_ci @Component 108e41f4b71Sopenharmony_ci struct WebComponent { 109e41f4b71Sopenharmony_ci controller: webview.WebviewController = new webview.WebviewController(); 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci build() { 112e41f4b71Sopenharmony_ci Column() { 113e41f4b71Sopenharmony_ci Button('addIntelligentTrackingPreventionBypassingList') 114e41f4b71Sopenharmony_ci .onClick(() => { 115e41f4b71Sopenharmony_ci try { 116e41f4b71Sopenharmony_ci let hostList = ["www.test1.com", "www.test2.com", "www.test3.com"]; 117e41f4b71Sopenharmony_ci webview.WebviewController.addIntelligentTrackingPreventionBypassingList(hostList); 118e41f4b71Sopenharmony_ci } catch (error) { 119e41f4b71Sopenharmony_ci console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); 120e41f4b71Sopenharmony_ci } 121e41f4b71Sopenharmony_ci }) 122e41f4b71Sopenharmony_ci Web({ src: 'www.example.com', controller: this.controller }) 123e41f4b71Sopenharmony_ci } 124e41f4b71Sopenharmony_ci } 125e41f4b71Sopenharmony_ci } 126e41f4b71Sopenharmony_ci ``` 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci- Invoke the [removeIntelligentTrackingPreventionBypassingList](../reference/apis-arkweb/js-apis-webview.md#removeintelligenttrackingpreventionbypassinglist12) API to remove the partial domain name list set using the [addIntelligentTrackingPreventionBypassingList](../reference/apis-arkweb/js-apis-webview.md#addintelligenttrackingpreventionbypassinglist12) API. 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci ```ts 131e41f4b71Sopenharmony_ci // xxx.ets 132e41f4b71Sopenharmony_ci import { webview } from '@kit.ArkWeb'; 133e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci @Entry 136e41f4b71Sopenharmony_ci @Component 137e41f4b71Sopenharmony_ci struct WebComponent { 138e41f4b71Sopenharmony_ci controller: webview.WebviewController = new webview.WebviewController(); 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci build() { 141e41f4b71Sopenharmony_ci Column() { 142e41f4b71Sopenharmony_ci Button('removeIntelligentTrackingPreventionBypassingList') 143e41f4b71Sopenharmony_ci .onClick(() => { 144e41f4b71Sopenharmony_ci try { 145e41f4b71Sopenharmony_ci let hostList = [ "www.test1.com", "www.test2.com" ]; 146e41f4b71Sopenharmony_ci webview.WebviewController.removeIntelligentTrackingPreventionBypassingList(hostList); 147e41f4b71Sopenharmony_ci } catch (error) { 148e41f4b71Sopenharmony_ci console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); 149e41f4b71Sopenharmony_ci } 150e41f4b71Sopenharmony_ci }) 151e41f4b71Sopenharmony_ci Web({ src: 'www.example.com', controller: this.controller }) 152e41f4b71Sopenharmony_ci } 153e41f4b71Sopenharmony_ci } 154e41f4b71Sopenharmony_ci } 155e41f4b71Sopenharmony_ci ``` 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci- Invoke the [clearIntelligentTrackingPreventionBypassingList](../reference/apis-arkweb/js-apis-webview.md#clearintelligenttrackingpreventionbypassinglist12) API to clear all domain names set using the [addIntelligentTrackingPreventionBypassingList](../reference/apis-arkweb/js-apis-webview.md#addintelligenttrackingpreventionbypassinglist12) API. 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci ```ts 160e41f4b71Sopenharmony_ci // xxx.ets 161e41f4b71Sopenharmony_ci import { webview } from '@kit.ArkWeb'; 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci @Entry 164e41f4b71Sopenharmony_ci @Component 165e41f4b71Sopenharmony_ci struct WebComponent { 166e41f4b71Sopenharmony_ci controller: webview.WebviewController = new webview.WebviewController(); 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci build() { 169e41f4b71Sopenharmony_ci Column() { 170e41f4b71Sopenharmony_ci Button('clearIntelligentTrackingPreventionBypassingList') 171e41f4b71Sopenharmony_ci .onClick(() => { 172e41f4b71Sopenharmony_ci webview.WebviewController.clearIntelligentTrackingPreventionBypassingList(); 173e41f4b71Sopenharmony_ci }) 174e41f4b71Sopenharmony_ci Web({ src: 'www.example.com', controller: this.controller }) 175e41f4b71Sopenharmony_ci } 176e41f4b71Sopenharmony_ci } 177e41f4b71Sopenharmony_ci } 178e41f4b71Sopenharmony_ci ``` 179