1# ArkWeb Process 2 3ArkWeb is a multi-process model, which consists of the application process, Web rendering process, Web GPU process, Web incubation process, and Foundation process. 4 5> **NOTE** 6> 7> The web kernel has no restriction on the request for memory size. 8 9**Figure 1** ArkWeb process model 10 11 12 13- Web-related threads in the application process (unique for the application) 14 15 - The application process is the main process, which includes the network thread, video thread, audio thread, and I/O thread. 16 17 - Processes application APIs and callbacks of the **Web** component, and provides functionalities that require interaction with other system services, such as network requests and media services. 18 19- Foundation process (unique in the system) 20 21 Receives requests from the application process to incubate processes and manages the binding relationship between the application process and Web rendering process. 22 23- Web incubation process (unique in the system) 24 25 - Receives requests from the Foundation process and incubates the Web rendering and Web GPU processes. 26 27 - Processes privilege dropping using security sandbox and pre-loads dynamic libraries after incubation to improve performance. 28 29- Web rendering process (shared or independent processes can be specified for multiple **Web** instances) 30 31 - Runs the Web rendering process engine, which implements HTML parsing, typesetting, drawing, and rendering. 32 33 - Runs the ArkWeb execution engine, which executes JavaScript and Web Assembly. 34 35 - Provides APIs for applications to choose whether to share rendering processes among multiple **Web** instances, meeting requirements on security, stability, and memory usage in different scenarios. 36 37 - Default policy: Share rendering processes on mobile devices to save memory, and use independent rendering processes on 2-in-1 devices to improve security and stability. 38 39- Web GPU process (unique for an application) 40 41 Responsible for interaction with GPU and RenderService, such as rasterization and composition for display. Improves the stability and security of the application process. 42 431. You can use [setRenderProcessMode](../reference/apis-arkweb/arkts-apis-webview-WebviewController.md#setrenderprocessmode12) to set the rendering process mode to single-process or multi-process. 44 45 By default, a mobile device uses single-process rendering, and a 2-in-1 device uses multi-process rendering. You can call [getRenderProcessMode](../reference/apis-arkweb/arkts-apis-webview-WebviewController.md#getrenderprocessmode12) to obtain the current rendering process mode. The value **0** means the single-process rendering, and the value **1** means the multi-process rendering. If the obtained value is not within the value range of [RenderProcessMode](../reference/apis-arkweb/arkts-apis-webview-e.md#renderprocessmode12), the system automatically uses the multi-process rendering mode by default. 46 47 ```ts 48 // xxx.ets 49 import { webview } from '@kit.ArkWeb'; 50 import { BusinessError } from '@kit.BasicServicesKit'; 51 52 @Entry 53 @Component 54 struct WebComponent { 55 controller: webview.WebviewController = new webview.WebviewController(); 56 57 build() { 58 Column() { 59 Button('getRenderProcessMode') 60 .onClick(() => { 61 let mode = webview.WebviewController.getRenderProcessMode(); 62 console.log("getRenderProcessMode: " + mode); 63 }) 64 Button('setRenderProcessMode') 65 .onClick(() => { 66 try { 67 webview.WebviewController.setRenderProcessMode(webview.RenderProcessMode.MULTIPLE); 68 } catch (error) { 69 console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); 70 } 71 }) 72 Web({ src: 'www.example.com', controller: this.controller }) 73 } 74 } 75 } 76 ``` 77 782. You can use [terminateRenderProcess](../reference/apis-arkweb/arkts-apis-webview-WebviewController.md#terminaterenderprocess12) to stop the rendering process. If a rendering process is not started or has been destroyed, this operation does not have any impact. However, destroying a rendering process affects all other instances associated with it. 79 80 ```ts 81 // xxx.ets 82 import { webview } from '@kit.ArkWeb'; 83 84 @Entry 85 @Component 86 struct WebComponent { 87 controller: webview.WebviewController = new webview.WebviewController(); 88 89 build() { 90 Column() { 91 Button('terminateRenderProcess') 92 .onClick(() => { 93 let result = this.controller.terminateRenderProcess(); 94 console.log("terminateRenderProcess result: " + result); 95 }) 96 Web({ src: 'www.example.com', controller: this.controller }) 97 } 98 } 99 } 100 ``` 101 1023. You can use [onRenderExited](../reference/apis-arkweb/arkts-basic-components-web-events.md#onrenderexited9) to listen for the exit event of the rendering process to obtain the specific exit cause (such as OOM, crash, or normal exit). Multiple **Web** components may share the same rendering process. Therefore, each time the rendering process exits, each affected **Web** component triggers a corresponding callback. 103 104 ```ts 105 // xxx.ets 106 import { webview } from '@kit.ArkWeb'; 107 108 @Entry 109 @Component 110 struct WebComponent { 111 controller: webview.WebviewController = new webview.WebviewController(); 112 113 build() { 114 Column() { 115 Web({ src: 'chrome://crash/', controller: this.controller }) 116 .onRenderExited((event) => { 117 if (event) { 118 console.log('reason:' + event.renderExitReason); 119 } 120 }) 121 } 122 } 123 } 124 ``` 125 1264. You can use [onRenderProcessNotResponding](../reference/apis-arkweb/arkts-basic-components-web-events.md#onrenderprocessnotresponding12) and [onRenderProcessResponding](../reference/apis-arkweb/arkts-basic-components-web-events.md#onrenderprocessresponding12) to listen for the non-response status of the rendering process. 127 128 When a **Web** component cannot process an input event or fails to navigate to a new URL within the expected time, the system determines that the web page process does not respond and triggers the **onRenderProcessNotResponding** callback. When a web page process does not respond for a long time, this callback may be triggered repeatedly until the process is restored to the normal running state. In this case, the **onRenderProcessResponding** callback is triggered. 129 130 ```ts 131 // xxx.ets 132 import { webview } from '@kit.ArkWeb'; 133 134 @Entry 135 @Component 136 struct WebComponent { 137 controller: webview.WebviewController = new webview.WebviewController(); 138 139 build() { 140 Column() { 141 Web({ src: 'www.example.com', controller: this.controller }) 142 .onRenderProcessNotResponding((data) => { 143 console.log("onRenderProcessNotResponding: [jsStack]= " + data.jsStack + 144 ", [process]=" + data.pid + ", [reason]=" + data.reason); 145 }) 146 } 147 } 148 } 149 ``` 150 151 ```ts 152 // xxx.ets 153 import { webview } from '@kit.ArkWeb'; 154 155 @Entry 156 @Component 157 struct WebComponent { 158 controller: webview.WebviewController = new webview.WebviewController(); 159 160 build() { 161 Column() { 162 Web({ src: 'www.example.com', controller: this.controller }) 163 .onRenderProcessResponding(() => { 164 console.log("onRenderProcessResponding again"); 165 }) 166 } 167 } 168 } 169 ``` 170 1715. Parameters of the [Web component](../reference/apis-arkweb/arkts-basic-components-web.md) cover the use of the multi-process model. **sharedRenderProcessToken** identifies the token of a shared rendering process specified by the current **Web** component. In multi-rendering process mode, **Web** components with the same token preferentially attempt to reuse the rendering process bound to the token. The token and the rendering process are bound in the initialization phase of the rendering process. Once a rendering process is no longer associated with any **Web** component, its binding to the token is removed. 172 173 ```ts 174 // xxx.ets 175 import { webview } from '@kit.ArkWeb'; 176 177 @Entry 178 @Component 179 struct WebComponent { 180 controller: webview.WebviewController = new webview.WebviewController(); 181 182 build() { 183 Column() { 184 Web({ src: 'www.example.com', controller: this.controller, sharedRenderProcessToken: "111" }) 185 Web({ src: 'www.w3.org', controller: this.controller, sharedRenderProcessToken: "111" }) 186 } 187 } 188 } 189 ``` 190