1# Web 2 3The **Web** component can be used to display web pages. It can be used with the [@ohos.web.webview](js-apis-webview.md) module, which provides APIs for web control. 4 5> **NOTE** 6> 7> - This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. 8> - You can preview how this component looks on a real device, but not in DevEco Studio Previewer. 9 10## Required Permissions 11To use online resources, the application must have the **ohos.permission.INTERNET** permission. For details about how to apply for a permission, see [Declaring Permissions](../../security/AccessToken/declare-permissions.md). 12 13## Child Components 14 15Not supported 16 17## APIs 18 19Web(options: { src: ResourceStr, controller: WebviewController | WebController, renderMode? : RenderMode, incognitoMode? : boolean, sharedRenderProcessToken? : string}) 20 21> **NOTE** 22> 23> Transition animation is not supported. 24> **Web** components on the same page must be bound to different **WebviewController** instances. 25 26**Parameters** 27 28| Name | Type | Mandatory | Description | 29| ---------- | ---------------------------------------- | ---- | ---------------------------------------- | 30| src | [ResourceStr](../apis-arkui/arkui-ts/ts-types.md#resourcestr) | Yes | Address of a web page resource. To access local resource files, use the **$rawfile** or **resource** protocol. To load a local resource file (in HTML or TXT format) in the sandbox outside of the application package, use **file://** to specify the path of the sandbox.<br>**src** cannot be dynamically changed through a state variable (for example, @State). To change the value, call [loadUrl()](js-apis-webview.md#loadurl).| 31| controller | [WebviewController<sup>9+</sup>](js-apis-webview.md#webviewcontroller) \| [WebController](#webcontroller) | Yes | Controller. This API is deprecated since API version 9. You are advised to use **WebviewController** instead.| 32| renderMode<sup>12+</sup> | [RenderMode](#rendermode12)| No | Rendering mode.<br>**RenderMode.ASYNC_RENDER** (default, cannot be dynamically adjusted): The **Web** component is rendered asynchronously.<br>**RenderMode.SYNC_RENDER**: The **Web** component is rendered synchronously within the current execution context.| 33| incognitoMode<sup>11+</sup> | boolean | No| Whether to enable incognito mode. The value **true** means to enable incognito mode, and **false** means the opposite.<br> Default value: **false**| 34| sharedRenderProcessToken<sup>12+</sup> | string | No| The token of the shared rendering process specified by the **Web** component. In multi-rendering process mode, the **Web** component with the same token preferentially attempts to reuse the rendering process bound to the token. The token is bound to the rendering process when the rendering process is initialized. When the rendering process is not associated with a **Web** component, its binding to the token is removed.<br> Default value: **""** | 35**Example** 36 37Example of loading online web pages: 38 39 ```ts 40 // xxx.ets 41 import { webview } from '@kit.ArkWeb'; 42 43 @Entry 44 @Component 45 struct WebComponent { 46 controller: webview.WebviewController = new webview.WebviewController(); 47 48 build() { 49 Column() { 50 Web({ src: 'www.example.com', controller: this.controller }) 51 } 52 } 53 } 54 ``` 55 56Example of loading online web pages in incognito mode: 57 58 ```ts 59 // xxx.ets 60 import { webview } from '@kit.ArkWeb'; 61 62 @Entry 63 @Component 64 struct WebComponent { 65 controller: webview.WebviewController = new webview.WebviewController(); 66 67 build() { 68 Column() { 69 Web({ src: 'www.example.com', controller: this.controller, incognitoMode: true }) 70 } 71 } 72 } 73 ``` 74 75Example of rendering the **Web** component synchronously within the current execution context: 76 77 ```ts 78 // xxx.ets 79 import { webview } from '@kit.ArkWeb'; 80 81 @Entry 82 @Component 83 struct WebComponent { 84 controller: webview.WebviewController = new webview.WebviewController(); 85 86 build() { 87 Column() { 88 Web({ src: 'www.example.com', controller: this.controller, renderMode: RenderMode.SYNC_RENDER }) 89 } 90 } 91 } 92 ``` 93 94Example of using the **Web** component to specify the shared rendering process. 95 96 ```ts 97 // xxx.ets 98 import { webview } from '@kit.ArkWeb'; 99 100 @Entry 101 @Component 102 struct WebComponent { 103 controller: webview.WebviewController = new webview.WebviewController(); 104 105 build() { 106 Column() { 107 Web({ src: 'www.example.com', controller: this.controller, sharedRenderProcessToken: "111" }) 108 Web({ src: 'www.w3.org', controller: this.controller, sharedRenderProcessToken: "111" }) 109 } 110 } 111 } 112 ``` 113 114Example of loading local web pages: 115 116 ```ts 117 // xxx.ets 118 import { webview } from '@kit.ArkWeb'; 119 120 @Entry 121 @Component 122 struct WebComponent { 123 controller: webview.WebviewController = new webview.WebviewController(); 124 125 build() { 126 Column() { 127 // Load a local resource file through $rawfile. 128 Web({ src: $rawfile("index.html"), controller: this.controller }) 129 } 130 } 131 } 132 ``` 133 134 ```ts 135 // xxx.ets 136 import { webview } from '@kit.ArkWeb'; 137 138 @Entry 139 @Component 140 struct WebComponent { 141 controller: webview.WebviewController = new webview.WebviewController(); 142 143 build() { 144 Column() { 145 // Load a local resource file through the resource protocol. 146 Web({ src: "resource://rawfile/index.html", controller: this.controller }) 147 } 148 } 149 } 150 ``` 151 152Example of loading local resource files in the sandbox: 153 1541. Obtain the sandbox path through the constructed singleton object **GlobalContext**. 155 156 ```ts 157 // GlobalContext.ets 158 export class GlobalContext { 159 private constructor() {} 160 private static instance: GlobalContext; 161 private _objects = new Map<string, Object>(); 162 163 public static getContext(): GlobalContext { 164 if (!GlobalContext.instance) { 165 GlobalContext.instance = new GlobalContext(); 166 } 167 return GlobalContext.instance; 168 } 169 170 getObject(value: string): Object | undefined { 171 return this._objects.get(value); 172 } 173 174 setObject(key: string, objectClass: Object): void { 175 this._objects.set(key, objectClass); 176 } 177 } 178 ``` 179 180 ```ts 181 // xxx.ets 182 import { webview } from '@kit.ArkWeb'; 183 import { GlobalContext } from '../GlobalContext'; 184 185 let url = 'file://' + GlobalContext.getContext().getObject("filesDir") + '/index.html'; 186 187 @Entry 188 @Component 189 struct WebComponent { 190 controller: webview.WebviewController = new webview.WebviewController(); 191 192 build() { 193 Column() { 194 // Load the files in the sandbox. 195 Web({ src: url, controller: this.controller }) 196 } 197 } 198 } 199 ``` 200 2012. Modify the **EntryAbility.ets** file. 202 203 The following uses **filesDir** as an example to describe how to obtain the path of the sandbox. For details about how to obtain other paths, see [Obtaining Application File Paths](../../application-models/application-context-stage.md#obtaining-application-file-paths). 204 205 ```ts 206 // xxx.ets 207 import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; 208 import { webview } from '@kit.ArkWeb'; 209 import { GlobalContext } from '../GlobalContext'; 210 211 export default class EntryAbility extends UIAbility { 212 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 213 // Data synchronization between the UIAbility component and UI can be implemented by binding filesDir to the GlobalContext object. 214 GlobalContext.getContext().setObject("filesDir", this.context.filesDir); 215 console.log("Sandbox path is " + GlobalContext.getContext().getObject("filesDir")); 216 } 217 } 218 ``` 219 220 HTML file to be loaded: 221 222 ```html 223 <!-- index.html --> 224 <!DOCTYPE html> 225 <html> 226 <body> 227 <p>Hello World</p> 228 </body> 229 </html> 230 ``` 231 232## Attributes 233 234The following universal attributes are supported: [aspectRatio](../apis-arkui/arkui-ts/ts-universal-attributes-layout-constraints.md#aspectratio), [backdropBlur](../apis-arkui/arkui-ts/ts-universal-attributes-image-effect.md#backdropblur), [backgroundColor](../apis-arkui/arkui-ts/ts-universal-attributes-background.md#backgroundcolor), [bindContentCover](../apis-arkui/arkui-ts/ts-universal-attributes-modal-transition.md#bindcontentcover), [bindContextMenu](../apis-arkui/arkui-ts/ts-universal-attributes-menu.md#bindcontextmenu8), [bindMenu](../apis-arkui/arkui-ts/ts-universal-attributes-menu.md#bindmenu), [bindSheet](../apis-arkui/arkui-ts/ts-universal-attributes-sheet-transition.md#bindsheet), [borderColor](../apis-arkui/arkui-ts/ts-universal-attributes-border.md#bordercolor), [borderRadius](../apis-arkui/arkui-ts/ts-universal-attributes-border.md#borderradius), [borderStyle](../apis-arkui/arkui-ts/ts-universal-attributes-border.md#borderstyle), [borderWidth](../apis-arkui/arkui-ts/ts-universal-attributes-border.md#borderwidth), [clip](../apis-arkui/arkui-ts/ts-universal-attributes-sharp-clipping.md#clip), [constraintSize](../apis-arkui/arkui-ts/ts-universal-attributes-size.md#constraintsize), [defaultFocus](../apis-arkui/arkui-ts/ts-universal-attributes-focus.md#defaultfocus9), [focusable](../apis-arkui/arkui-ts/ts-universal-attributes-focus.md#focusable), [tabIndex](../apis-arkui/arkui-ts/ts-universal-attributes-focus.md#tabindex9), [groupDefaultFocus](../apis-arkui/arkui-ts/ts-universal-attributes-focus.md#groupdefaultfocus9), [focusOnTouch](../apis-arkui/arkui-ts/ts-universal-attributes-focus.md#focusontouch9), [displayPriority](../apis-arkui/arkui-ts/ts-universal-attributes-layout-constraints.md#displaypriority), [enabled](../apis-arkui/arkui-ts/ts-universal-attributes-enable.md#enabled), [flexBasis](../apis-arkui/arkui-ts/ts-universal-attributes-flex-layout.md#flexbasis), [flexGrow](../apis-arkui/arkui-ts/ts-universal-attributes-flex-layout.md#flexgrow), [flexShrink](../apis-arkui/arkui-ts/ts-universal-attributes-flex-layout.md#flexshrink), [layoutWeight](../apis-arkui/arkui-ts/ts-universal-attributes-size.md#layoutweight), [id](../apis-arkui/arkui-ts/ts-universal-attributes-component-id.md), [gridOffset](../apis-arkui/arkui-ts/ts-universal-attributes-grid.md), [gridSpan](../apis-arkui/arkui-ts/ts-universal-attributes-grid.md), [useSizeType](../apis-arkui/arkui-ts/ts-universal-attributes-grid.md), [height](../apis-arkui/arkui-ts/ts-universal-attributes-size.md#height), [touchable](../apis-arkui/arkui-ts/ts-universal-attributes-click.md), [margin](../apis-arkui/arkui-ts/ts-universal-attributes-size.md#margin), [markAnchor](../apis-arkui/arkui-ts/ts-universal-attributes-location.md#markanchor), [offset](../apis-arkui/arkui-ts/ts-universal-attributes-location.md#offset), [width](../apis-arkui/arkui-ts/ts-universal-attributes-size.md#width), [zIndex](../apis-arkui/arkui-ts/ts-universal-attributes-z-order.md#zindex), [visibility](../apis-arkui/arkui-ts/ts-universal-attributes-visibility.md#visibility), [scale](../apis-arkui/arkui-ts/ts-universal-attributes-transformation.md#scale), [translate](../apis-arkui/arkui-ts/ts-universal-attributes-transformation.md#translate), [responseRegion](../apis-arkui/arkui-ts/ts-universal-attributes-touch-target.md#responseregion), [size](../apis-arkui/arkui-ts/ts-universal-attributes-size.md#size), [stateStyles](../apis-arkui/arkui-ts/ts-universal-attributes-polymorphic-style.md#statestyles), [opacity](../apis-arkui/arkui-ts/ts-universal-attributes-opacity.md#opacity), [shadow](../apis-arkui/arkui-ts/ts-universal-attributes-image-effect.md#shadow), [sharedTransition](../apis-arkui/arkui-ts/ts-transition-animation-shared-elements.md), [transition](../apis-arkui/arkui-ts/ts-transition-animation-component.md) 235 236### domStorageAccess 237 238domStorageAccess(domStorageAccess: boolean) 239 240Sets whether to enable the DOM Storage API. By default, this feature is disabled. 241 242**System capability**: SystemCapability.Web.Webview.Core 243 244**Parameters** 245 246| Name | Type | Mandatory | Default Value | Description | 247| ---------------- | ------- | ---- | ----- | ------------------------------------ | 248| domStorageAccess | boolean | Yes | false | Whether to enable the DOM Storage API.| 249 250**Example** 251 252 ```ts 253 // xxx.ets 254 import { webview } from '@kit.ArkWeb'; 255 256 @Entry 257 @Component 258 struct WebComponent { 259 controller: webview.WebviewController = new webview.WebviewController(); 260 261 build() { 262 Column() { 263 Web({ src: 'www.example.com', controller: this.controller }) 264 .domStorageAccess(true) 265 } 266 } 267 } 268 ``` 269 270### fileAccess 271 272fileAccess(fileAccess: boolean) 273 274Sets whether to enable access to the file system in the application. This setting does not affect the access to the files specified through [$rawfile(filepath/filename)](../../quick-start/resource-categories-and-access.md). 275 276**fileAccess** is disabled by default since API version 12. When **fileAccess** is set to **false**, files in the read-only **/data/storage/el1/bundle/entry/resources/resfile** directory can still be accessed through the **file** protocol. 277 278**Parameters** 279 280| Name | Type | Mandatory | Default Value | Description | 281| ---------- | ------- | ---- | ---- | ---------------------- | 282| fileAccess | boolean | Yes | false | Whether to enable access to the file system in the application.<br>Default value:<br>API version 11 and earlier: **true**<br> API version 12 and later: **false**| 283 284**Example** 285 286 ```ts 287 // xxx.ets 288 import { webview } from '@kit.ArkWeb'; 289 290 @Entry 291 @Component 292 struct WebComponent { 293 controller: webview.WebviewController = new webview.WebviewController(); 294 295 build() { 296 Column() { 297 Web({ src: 'www.example.com', controller: this.controller }) 298 .fileAccess(true) 299 } 300 } 301 } 302 ``` 303 304### imageAccess 305 306imageAccess(imageAccess: boolean) 307 308Sets whether to enable automatic image loading. By default, this feature is enabled. 309 310**Parameters** 311 312| Name | Type | Mandatory | Default Value | Description | 313| ----------- | ------- | ---- | ---- | --------------- | 314| imageAccess | boolean | Yes | true | Whether to enable automatic image loading.| 315 316**Example** 317 ```ts 318 // xxx.ets 319 import { webview } from '@kit.ArkWeb'; 320 321 @Entry 322 @Component 323 struct WebComponent { 324 controller: webview.WebviewController = new webview.WebviewController(); 325 326 build() { 327 Column() { 328 Web({ src: 'www.example.com', controller: this.controller }) 329 .imageAccess(true) 330 } 331 } 332 } 333 ``` 334 335### javaScriptProxy 336 337javaScriptProxy(javaScriptProxy: JavaScriptProxy) 338 339Registers a JavaScript object with the window. APIs of this object can then be invoked in the window. The parameters cannot be updated. This API can be used in synchronous or asynchronous mode, or in both modes. If the API can be used in both synchronous and asynchronous modes, it is called asynchronously by default. Only one object can be registered through this API. To register multiple objects, use [registerJavaScriptProxy<sup>9+</sup>](js-apis-webview.md#registerjavascriptproxy). 340 341**Parameters** 342 343| Name | Type | Mandatory | Description | 344| ---------- | ---------------------------------------- | ---- |---------------------------------------- | 345| javaScriptProxy | [JavaScriptProxy](#javascriptproxy12) | Yes | Object to be registered. Methods can be declared, but attributes cannot. | 346 347**Example** 348 349 ```ts 350 // xxx.ets 351 import { webview } from '@kit.ArkWeb'; 352 353 class TestObj { 354 constructor() { 355 } 356 357 test(data1: string, data2: string, data3: string): string { 358 console.log("data1:" + data1); 359 console.log("data2:" + data2); 360 console.log("data3:" + data3); 361 return "AceString"; 362 } 363 364 asyncTest(data: string): void { 365 console.log("async data:" + data); 366 } 367 368 toString(): void { 369 console.log('toString' + "interface instead."); 370 } 371 } 372 373 @Entry 374 @Component 375 struct WebComponent { 376 controller: webview.WebviewController = new webview.WebviewController(); 377 testObj = new TestObj(); 378 build() { 379 Column() { 380 Web({ src: 'www.example.com', controller: this.controller }) 381 .javaScriptAccess(true) 382 .javaScriptProxy({ 383 object: this.testObj, 384 name: "objName", 385 methodList: ["test", "toString"], 386 asyncMethodList: ["asyncTest"], 387 controller: this.controller, 388 }) 389 } 390 } 391 } 392 ``` 393 394### javaScriptAccess 395 396javaScriptAccess(javaScriptAccess: boolean) 397 398Sets whether JavaScript scripts can be executed. By default, JavaScript scripts can be executed. 399 400**Parameters** 401 402| Name | Type | Mandatory | Default Value | Description | 403| ---------------- | ------- | ---- | ---- | ------------------- | 404| javaScriptAccess | boolean | Yes | true | Whether JavaScript scripts can be executed.| 405 406**Example** 407 408 ```ts 409 // xxx.ets 410 import { webview } from '@kit.ArkWeb'; 411 412 @Entry 413 @Component 414 struct WebComponent { 415 controller: webview.WebviewController = new webview.WebviewController(); 416 build() { 417 Column() { 418 Web({ src: 'www.example.com', controller: this.controller }) 419 .javaScriptAccess(true) 420 } 421 } 422 } 423 ``` 424 425### overScrollMode<sup>11+</sup> 426 427overScrollMode(mode: OverScrollMode) 428 429Sets the overscroll mode, which is disabled by default. When the overscroll mode is enabled and the boundary of the scrolling area is reached, the **Web** component plays a bounce effect animation. 430 431**Parameters** 432 433| Name | Type | Mandatory | Default Value | Description | 434| ---- | --------------------------------------- | ---- | -------------------- | ------------------ | 435| mode | [OverScrollMode](#overscrollmode11) | Yes | OverScrollMode.NEVER | Whether to enable the overscroll mode.| 436 437**Example** 438 439 ```ts 440 // xxx.ets 441 import { webview } from '@kit.ArkWeb'; 442 443 @Entry 444 @Component 445 struct WebComponent { 446 controller: webview.WebviewController = new webview.WebviewController(); 447 @State mode: OverScrollMode = OverScrollMode.ALWAYS; 448 build() { 449 Column() { 450 Web({ src: 'www.example.com', controller: this.controller }) 451 .overScrollMode(this.mode) 452 } 453 } 454 } 455 ``` 456 457### mixedMode 458 459mixedMode(mixedMode: MixedMode) 460 461Sets whether to enable loading of HTTP and HTTPS hybrid content can be loaded. By default, this feature is disabled. 462 463**Parameters** 464 465| Name | Type | Mandatory | Default Value | Description | 466| --------- | --------------------------- | ---- | -------------- | --------- | 467| mixedMode | [MixedMode](#mixedmode)| Yes | MixedMode.None | Mixed content to load.| 468 469**Example** 470 471 ```ts 472 // xxx.ets 473 import { webview } from '@kit.ArkWeb'; 474 475 @Entry 476 @Component 477 struct WebComponent { 478 controller: webview.WebviewController = new webview.WebviewController(); 479 @State mode: MixedMode = MixedMode.All; 480 build() { 481 Column() { 482 Web({ src: 'www.example.com', controller: this.controller }) 483 .mixedMode(this.mode) 484 } 485 } 486 } 487 ``` 488 489### onlineImageAccess 490 491onlineImageAccess(onlineImageAccess: boolean) 492 493Sets whether to enable access to online images through HTTP and HTTPS. By default, this feature is enabled. 494 495**Parameters** 496 497| Name | Type | Mandatory | Default Value | Description | 498| ----------------- | ------- | ---- | ---- | ---------------- | 499| onlineImageAccess | boolean | Yes | true | Whether to enable access to online images through HTTP and HTTPS.| 500 501**Example** 502 503 ```ts 504 // xxx.ets 505 import { webview } from '@kit.ArkWeb'; 506 507 @Entry 508 @Component 509 struct WebComponent { 510 controller: webview.WebviewController = new webview.WebviewController(); 511 512 build() { 513 Column() { 514 Web({ src: 'www.example.com', controller: this.controller }) 515 .onlineImageAccess(true) 516 } 517 } 518 } 519 ``` 520 521### zoomAccess 522 523zoomAccess(zoomAccess: boolean) 524 525Sets whether to enable zoom gestures. By default, this feature is enabled. 526 527**Parameters** 528 529| Name | Type | Mandatory | Default Value | Description | 530| ---------- | ------- | ---- | ---- | ------------- | 531| zoomAccess | boolean | Yes | true | Whether to enable zoom gestures.| 532 533**Example** 534 535 ```ts 536 // xxx.ets 537 import { webview } from '@kit.ArkWeb'; 538 539 @Entry 540 @Component 541 struct WebComponent { 542 controller: webview.WebviewController = new webview.WebviewController(); 543 544 build() { 545 Column() { 546 Web({ src: 'www.example.com', controller: this.controller }) 547 .zoomAccess(true) 548 } 549 } 550 } 551 ``` 552 553### overviewModeAccess 554 555overviewModeAccess(overviewModeAccess: boolean) 556 557Sets whether to load web pages by using the overview mode. By default, this feature is enabled. Currently, only mobile devices are supported. 558 559**Parameters** 560 561| Name | Type | Mandatory | Default Value | Description | 562| ------------------ | ------- | ---- | ---- | --------------- | 563| overviewModeAccess | boolean | Yes | true | Whether to load web pages by using the overview mode.| 564 565**Example** 566 567 ```ts 568 // xxx.ets 569 import { webview } from '@kit.ArkWeb'; 570 571 @Entry 572 @Component 573 struct WebComponent { 574 controller: webview.WebviewController = new webview.WebviewController(); 575 576 build() { 577 Column() { 578 Web({ src: 'www.example.com', controller: this.controller }) 579 .overviewModeAccess(true) 580 } 581 } 582 } 583 ``` 584 585### databaseAccess 586 587databaseAccess(databaseAccess: boolean) 588 589Sets whether to enable database access. By default, this feature is disabled. 590 591**Parameters** 592 593| Name | Type | Mandatory | Default Value | Description | 594| -------------- | ------- | ---- | ----- | ----------------- | 595| databaseAccess | boolean | Yes | false | Whether to enable database access.| 596 597**Example** 598 599 ```ts 600 // xxx.ets 601 import { webview } from '@kit.ArkWeb'; 602 603 @Entry 604 @Component 605 struct WebComponent { 606 controller: webview.WebviewController = new webview.WebviewController(); 607 608 build() { 609 Column() { 610 Web({ src: 'www.example.com', controller: this.controller }) 611 .databaseAccess(true) 612 } 613 } 614 } 615 ``` 616 617### geolocationAccess 618 619geolocationAccess(geolocationAccess: boolean) 620 621Sets whether to enable geolocation access. By default, this feature is enabled. For details, see [Managing Location Permissions](../../web/web-geolocation-permission.md). 622 623**Parameters** 624 625| Name | Type | Mandatory | Default Value | Description | 626| ----------------- | ------- | ---- | ---- | --------------- | 627| geolocationAccess | boolean | Yes | true | Whether to enable geolocation access.| 628 629**Example** 630 631 ```ts 632 // xxx.ets 633 import { webview } from '@kit.ArkWeb'; 634 635 @Entry 636 @Component 637 struct WebComponent { 638 controller: webview.WebviewController = new webview.WebviewController(); 639 640 build() { 641 Column() { 642 Web({ src: 'www.example.com', controller: this.controller }) 643 .geolocationAccess(true) 644 } 645 } 646 } 647 ``` 648 649### mediaPlayGestureAccess 650 651mediaPlayGestureAccess(access: boolean) 652 653Sets whether video playback must be started by user gestures. This API is not applicable to videos that do not have an audio track or whose audio track is muted. 654 655**Parameters** 656 657| Name | Type | Mandatory | Default Value | Description | 658| ------ | ------- | ---- | ---- | ------------------- | 659| access | boolean | Yes | true | Whether video playback must be started by user gestures.| 660 661**Example** 662 663 ```ts 664 // xxx.ets 665 import { webview } from '@kit.ArkWeb'; 666 667 @Entry 668 @Component 669 struct WebComponent { 670 controller: webview.WebviewController = new webview.WebviewController(); 671 @State access: boolean = true; 672 673 build() { 674 Column() { 675 Web({ src: 'www.example.com', controller: this.controller }) 676 .mediaPlayGestureAccess(this.access) 677 } 678 } 679 } 680 ``` 681 682### multiWindowAccess<sup>9+</sup> 683 684multiWindowAccess(multiWindow: boolean) 685 686Sets whether to enable the multi-window permission. By default, this feature is disabled. 687Enabling the multi-window permission requires implementation of the **onWindowNew** event. For the sample code, see [onWindowNew](#onwindownew9). 688 689**Parameters** 690 691| Name | Type | Mandatory | Default Value | Description | 692| ----------- | ------- | ---- | ----- | ------------ | 693| multiWindow | boolean | Yes | false | Whether to enable the multi-window permission.| 694 695**Example** 696 697 ```ts 698 // xxx.ets 699 import { webview } from '@kit.ArkWeb'; 700 701 @Entry 702 @Component 703 struct WebComponent { 704 controller: webview.WebviewController = new webview.WebviewController(); 705 706 build() { 707 Column() { 708 Web({ src: 'www.example.com', controller: this.controller }) 709 .multiWindowAccess(false) 710 } 711 } 712 } 713 ``` 714 715### horizontalScrollBarAccess<sup>9+</sup> 716 717horizontalScrollBarAccess(horizontalScrollBar: boolean) 718 719Sets whether to display the horizontal scrollbar, including the default system scrollbar and custom scrollbar. By default, the horizontal scrollbar is displayed. 720> **NOTE** 721> 722> - If an @State decorated variable is used to control the horizontal scrollbar visibility, **controller.refresh()** must be called for the settings to take effect. 723> - If the horizontal scrollbar visibility changes frequently through an @State decorated variable, it is recommended that the variable correspond to the **Web** component one by one. 724 725**Parameters** 726 727| Name | Type | Mandatory | Default Value | Description | 728| ------------------- | ------- | ---- | ---- | ------------ | 729| horizontalScrollBar | boolean | Yes | true | Whether to display the horizontal scrollbar.| 730 731**Example** 732 733 ```ts 734 // xxx.ets 735 import { webview } from '@kit.ArkWeb'; 736 import { BusinessError } from '@kit.BasicServicesKit'; 737 738 @Entry 739 @Component 740 struct WebComponent { 741 controller: webview.WebviewController = new webview.WebviewController(); 742 @State isShow: boolean = false; 743 744 build() { 745 Column() { 746 // If an @State decorated variable is used to control the horizontal scrollbar visibility, controller.refresh() must be called for the settings to take effect. 747 Button('refresh') 748 .onClick(() => { 749 this.isShow = true; 750 try { 751 this.controller.refresh(); 752 } catch (error) { 753 console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); 754 } 755 }) 756 Web({ src: $rawfile('index.html'), controller: this.controller }) 757 .horizontalScrollBarAccess(this.isShow) 758 } 759 } 760 } 761 ``` 762 763 HTML file to be loaded: 764 ```html 765 <!--index.html--> 766 <!DOCTYPE html> 767 <html> 768 <head> 769 <title>Demo</title> 770 <style> 771 body { 772 width:3000px; 773 height:3000px; 774 padding-right:170px; 775 padding-left:170px; 776 border:5px solid blueviolet 777 } 778 </style> 779 </head> 780 <body> 781 Scroll Test 782 </body> 783 </html> 784 ``` 785 786### verticalScrollBarAccess<sup>9+</sup> 787 788verticalScrollBarAccess(verticalScrollBar: boolean) 789 790Sets whether to display the vertical scrollbar, including the default system scrollbar and custom scrollbar. By default, the vertical scrollbar is displayed. 791 792> **NOTE** 793> 794> - If an @State decorated variable is used to control the vertical scrollbar visibility, **controller.refresh()** must be called for the settings to take effect. 795> - If the vertical scrollbar visibility changes frequently through an @State decorated variable, it is recommended that the variable correspond to the **Web** component one by one. 796 797**Parameters** 798 799| Name | Type | Mandatory | Default Value | Description | 800| ----------------- | ------- | ---- | ---- | ------------ | 801| verticalScrollBar | boolean | Yes | true | Whether to display the vertical scrollbar.| 802 803**Example** 804 805 ```ts 806 // xxx.ets 807 import { webview } from '@kit.ArkWeb'; 808 import { BusinessError } from '@kit.BasicServicesKit'; 809 810 @Entry 811 @Component 812 struct WebComponent { 813 controller: webview.WebviewController = new webview.WebviewController(); 814 @State isShow: boolean = false; 815 816 build() { 817 Column() { 818 // If an @State decorated variable is used to control the vertical scrollbar visibility, controller.refresh() must be called for the settings to take effect. 819 Button('refresh') 820 .onClick(() => { 821 this.isShow = true; 822 try { 823 this.controller.refresh(); 824 } catch (error) { 825 console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); 826 } 827 }) 828 Web({ src: $rawfile('index.html'), controller: this.controller }) 829 .verticalScrollBarAccess(this.isShow) 830 } 831 } 832 } 833 ``` 834 835 HTML file to be loaded: 836 ```html 837 <!--index.html--> 838 <!DOCTYPE html> 839 <html> 840 <head> 841 <title>Demo</title> 842 <style> 843 body { 844 width:3000px; 845 height:3000px; 846 padding-right:170px; 847 padding-left:170px; 848 border:5px solid blueviolet 849 } 850 </style> 851 </head> 852 <body> 853 Scroll Test 854 </body> 855 </html> 856 ``` 857 858### password<sup>(deprecated)</sup> 859 860password(password: boolean) 861 862Sets whether the password should be saved. This API is a void API. 863 864> **NOTE** 865> 866> This API is deprecated since API version 10, and no new API is provided as a substitute. 867 868### cacheMode 869 870cacheMode(cacheMode: CacheMode) 871 872Sets the cache mode. 873 874**Parameters** 875 876| Name | Type | Mandatory | Default Value | Description | 877| --------- | --------------------------- | ---- | ----------------- | --------- | 878| cacheMode | [CacheMode](#cachemode9) | Yes | CacheMode.Default | Cache mode to set.| 879 880**Example** 881 882 ```ts 883 // xxx.ets 884 import { webview } from '@kit.ArkWeb'; 885 886 @Entry 887 @Component 888 struct WebComponent { 889 controller: webview.WebviewController = new webview.WebviewController(); 890 @State mode: CacheMode = CacheMode.None; 891 892 build() { 893 Column() { 894 Web({ src: 'www.example.com', controller: this.controller }) 895 .cacheMode(this.mode) 896 } 897 } 898 } 899 ``` 900 901### copyOptions<sup>11+</sup> 902 903copyOptions(value: CopyOptions) 904 905Sets the pasteboard copy options. 906 907**Parameters** 908 909| Name | Type | Mandatory | Default Value | Description | 910| --------- | --------------------------- | ---- | ----------------- | --------- | 911| value | [CopyOptions](../apis-arkui/arkui-ts/ts-appendix-enums.md#copyoptions9) | Yes | CopyOptions.LocalDevice | Pasteboard copy options.| 912 913**Example** 914 915 ```ts 916import { webview } from '@kit.ArkWeb'; 917 918@Entry 919@Component 920struct WebComponent { 921 controller: webview.WebviewController = new webview.WebviewController(); 922 923 build() { 924 Column() { 925 Web({ src: 'www.example.com', controller: this.controller }) 926 .copyOptions(CopyOptions.None) 927 } 928 } 929} 930 ``` 931 932### textZoomAtio<sup>(deprecated)</sup> 933 934textZoomAtio(textZoomAtio: number) 935 936Sets the text zoom ratio of the page. The default value is **100**, which indicates 100%. 937 938This API is deprecated since API version 9. You are advised to use [textZoomRatio<sup>9+</sup>](#textzoomratio9) instead. 939 940**Parameters** 941 942| Name | Type | Mandatory | Default Value | Description | 943| ------------ | ------ | ---- | ---- | -------------------------------- | 944| textZoomAtio | number | Yes | 100 | Text zoom ratio to set. The value is an integer. The value range is (0, +∞).| 945 946**Example** 947 948 ```ts 949 // xxx.ets 950 @Entry 951 @Component 952 struct WebComponent { 953 controller: WebController = new WebController() 954 @State atio: number = 150 955 build() { 956 Column() { 957 Web({ src: 'www.example.com', controller: this.controller }) 958 .textZoomAtio(this.atio) 959 } 960 } 961 } 962 ``` 963 964### textZoomRatio<sup>9+</sup> 965 966textZoomRatio(textZoomRatio: number) 967 968Sets the text zoom ratio of the page. The default value is **100**, which indicates 100%. 969 970**Parameters** 971 972| Name | Type | Mandatory | Default Value | Description | 973| ------------- | ------ | ---- | ---- | -------------------------------- | 974| textZoomRatio | number | Yes | 100 | Text zoom ratio to set. The value is an integer. The value range is (0, +∞).| 975 976**Example** 977 978 ```ts 979 // xxx.ets 980 import { webview } from '@kit.ArkWeb'; 981 982 @Entry 983 @Component 984 struct WebComponent { 985 controller: webview.WebviewController = new webview.WebviewController(); 986 @State atio: number = 150; 987 988 build() { 989 Column() { 990 Web({ src: 'www.example.com', controller: this.controller }) 991 .textZoomRatio(this.atio) 992 } 993 } 994 } 995 ``` 996 997### initialScale<sup>9+</sup> 998 999initialScale(percent: number) 1000 1001Sets the scale factor of the entire page. The default value is 100%. 1002 1003**Parameters** 1004 1005| Name | Type | Mandatory | Default Value | Description | 1006| ------- | ------ | ---- | ---- | ----------------------------- | 1007| percent | number | Yes | 100 | Scale factor of the entire page.| 1008 1009**Example** 1010 1011 ```ts 1012 // xxx.ets 1013 import { webview } from '@kit.ArkWeb'; 1014 1015 @Entry 1016 @Component 1017 struct WebComponent { 1018 controller: webview.WebviewController = new webview.WebviewController(); 1019 @State percent: number = 100; 1020 1021 build() { 1022 Column() { 1023 Web({ src: 'www.example.com', controller: this.controller }) 1024 .initialScale(this.percent) 1025 } 1026 } 1027 } 1028 ``` 1029 1030### userAgent<sup>(deprecated)</sup> 1031 1032userAgent(userAgent: string) 1033 1034Sets the user agent. 1035 1036> **NOTE** 1037> 1038> This API is supported since API version 8 and deprecated since API version 10. You are advised to use [setCustomUserAgent](js-apis-webview.md#setcustomuseragent10)<sup>10+</sup> instead. 1039 1040**Parameters** 1041 1042| Name | Type | Mandatory | Default Value | Description | 1043| --------- | ------ | ---- | ---- | --------- | 1044| userAgent | string | Yes | - | User agent to set.| 1045 1046**Example** 1047 1048 ```ts 1049 // xxx.ets 1050 import { webview } from '@kit.ArkWeb'; 1051 1052 @Entry 1053 @Component 1054 struct WebComponent { 1055 controller: webview.WebviewController = new webview.WebviewController(); 1056 @State userAgent:string = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36'; 1057 1058 build() { 1059 Column() { 1060 Web({ src: 'www.example.com', controller: this.controller }) 1061 .userAgent(this.userAgent) 1062 } 1063 } 1064 } 1065 ``` 1066 1067### blockNetwork<sup>9+</sup> 1068 1069blockNetwork(block: boolean) 1070 1071Sets whether to block online downloads. 1072 1073**Parameters** 1074 1075| Name | Type | Mandatory | Default Value | Description | 1076| ----- | ------- | ---- | ----- | ------------------- | 1077| block | boolean | Yes | false | Whether to block online downloads.| 1078 1079**Example** 1080 1081 ```ts 1082 // xxx.ets 1083 import { webview } from '@kit.ArkWeb'; 1084 1085 @Entry 1086 @Component 1087 struct WebComponent { 1088 controller: webview.WebviewController = new webview.WebviewController(); 1089 @State block: boolean = true; 1090 1091 build() { 1092 Column() { 1093 Web({ src: 'www.example.com', controller: this.controller }) 1094 .blockNetwork(this.block) 1095 } 1096 } 1097 } 1098 ``` 1099 1100### defaultFixedFontSize<sup>9+</sup> 1101 1102defaultFixedFontSize(size: number) 1103 1104Sets the default fixed font size for the web page. 1105 1106**Parameters** 1107 1108| Name | Type | Mandatory | Default Value | Description | 1109| ---- | ------ | ---- | ---- | ---------------------------------------- | 1110| size | number | Yes | 13 | Default fixed font size to set, in px. The value ranges from -2^31 to 2^31-1. In actual rendering, values greater than 72 are handled as 72, and values less than 1 are handled as 1.| 1111 1112**Example** 1113 1114 ```ts 1115 // xxx.ets 1116 import { webview } from '@kit.ArkWeb'; 1117 1118 @Entry 1119 @Component 1120 struct WebComponent { 1121 controller: webview.WebviewController = new webview.WebviewController(); 1122 @State fontSize: number = 16; 1123 1124 build() { 1125 Column() { 1126 Web({ src: 'www.example.com', controller: this.controller }) 1127 .defaultFixedFontSize(this.fontSize) 1128 } 1129 } 1130 } 1131 ``` 1132 1133### defaultFontSize<sup>9+</sup> 1134 1135defaultFontSize(size: number) 1136 1137Sets the default font size for the web page. 1138 1139**Parameters** 1140 1141| Name | Type | Mandatory | Default Value | Description | 1142| ---- | ------ | ---- | ---- | ---------------------------------------- | 1143| size | number | Yes | 16 | Default font size to set, in px. The value ranges from -2^31 to 2^31-1. In actual rendering, values greater than 72 are handled as 72, and values less than 1 are handled as 1.| 1144 1145**Example** 1146 1147 ```ts 1148 // xxx.ets 1149 import { webview } from '@kit.ArkWeb'; 1150 1151 @Entry 1152 @Component 1153 struct WebComponent { 1154 controller: webview.WebviewController = new webview.WebviewController(); 1155 @State fontSize: number = 13; 1156 1157 build() { 1158 Column() { 1159 Web({ src: 'www.example.com', controller: this.controller }) 1160 .defaultFontSize(this.fontSize) 1161 } 1162 } 1163 } 1164 ``` 1165 1166### minFontSize<sup>9+</sup> 1167 1168minFontSize(size: number) 1169 1170Sets the minimum font size for the web page. 1171 1172**Parameters** 1173 1174| Name | Type | Mandatory | Default Value | Description | 1175| ---- | ------ | ---- | ---- | ---------------------------------------- | 1176| size | number | Yes | 8 | Minimum font size to set, in px. The value ranges from -2^31 to 2^31-1. In actual rendering, values greater than 72 are handled as 72, and values less than 1 are handled as 1.| 1177 1178**Example** 1179 1180 ```ts 1181 // xxx.ets 1182 import { webview } from '@kit.ArkWeb'; 1183 1184 @Entry 1185 @Component 1186 struct WebComponent { 1187 controller: webview.WebviewController = new webview.WebviewController(); 1188 @State fontSize: number = 13; 1189 1190 build() { 1191 Column() { 1192 Web({ src: 'www.example.com', controller: this.controller }) 1193 .minFontSize(this.fontSize) 1194 } 1195 } 1196 } 1197 ``` 1198 1199### minLogicalFontSize<sup>9+</sup> 1200 1201minLogicalFontSize(size: number) 1202 1203Sets the minimum logical font size for the web page. 1204 1205**Parameters** 1206 1207| Name | Type | Mandatory | Default Value | Description | 1208| ---- | ------ | ---- | ---- | ---------------------------------------- | 1209| size | number | Yes | 8 | Minimum logical font size to set, in px. The value ranges from -2^31 to 2^31-1. In actual rendering, values greater than 72 are handled as 72, and values less than 1 are handled as 1.| 1210 1211**Example** 1212 1213 ```ts 1214 // xxx.ets 1215 import { webview } from '@kit.ArkWeb'; 1216 1217 @Entry 1218 @Component 1219 struct WebComponent { 1220 controller: webview.WebviewController = new webview.WebviewController(); 1221 @State fontSize: number = 13; 1222 1223 build() { 1224 Column() { 1225 Web({ src: 'www.example.com', controller: this.controller }) 1226 .minLogicalFontSize(this.fontSize) 1227 } 1228 } 1229 } 1230 ``` 1231 1232### webFixedFont<sup>9+</sup> 1233 1234webFixedFont(family: string) 1235 1236Sets the fixed font family for the web page. 1237 1238**Parameters** 1239 1240| Name | Type | Mandatory | Default Value | Description | 1241| ------ | ------ | ---- | --------- | ------------------- | 1242| family | string | Yes | monospace | Fixed font family to set.| 1243 1244**Example** 1245 1246 ```ts 1247 // xxx.ets 1248 import { webview } from '@kit.ArkWeb'; 1249 1250 @Entry 1251 @Component 1252 struct WebComponent { 1253 controller: webview.WebviewController = new webview.WebviewController(); 1254 @State family: string = "monospace"; 1255 1256 build() { 1257 Column() { 1258 Web({ src: 'www.example.com', controller: this.controller }) 1259 .webFixedFont(this.family) 1260 } 1261 } 1262 } 1263 ``` 1264 1265### webSansSerifFont<sup>9+</sup> 1266 1267webSansSerifFont(family: string) 1268 1269Sets the sans serif font family for the web page. 1270 1271**Parameters** 1272 1273| Name | Type | Mandatory | Default Value | Description | 1274| ------ | ------ | ---- | ---------- | ------------------------ | 1275| family | string | Yes | sans-serif | Sans serif font family to set.| 1276 1277**Example** 1278 1279 ```ts 1280 // xxx.ets 1281 import { webview } from '@kit.ArkWeb'; 1282 1283 @Entry 1284 @Component 1285 struct WebComponent { 1286 controller: webview.WebviewController = new webview.WebviewController(); 1287 @State family: string = "sans-serif"; 1288 1289 build() { 1290 Column() { 1291 Web({ src: 'www.example.com', controller: this.controller }) 1292 .webSansSerifFont(this.family) 1293 } 1294 } 1295 } 1296 ``` 1297 1298### webSerifFont<sup>9+</sup> 1299 1300webSerifFont(family: string) 1301 1302Sets the serif font family for the web page. 1303 1304**Parameters** 1305 1306| Name | Type | Mandatory | Default Value | Description | 1307| ------ | ------ | ---- | ----- | ------------------- | 1308| family | string | Yes | serif | Serif font family to set.| 1309 1310**Example** 1311 1312 ```ts 1313 // xxx.ets 1314 import { webview } from '@kit.ArkWeb'; 1315 1316 @Entry 1317 @Component 1318 struct WebComponent { 1319 controller: webview.WebviewController = new webview.WebviewController(); 1320 @State family: string = "serif"; 1321 1322 build() { 1323 Column() { 1324 Web({ src: 'www.example.com', controller: this.controller }) 1325 .webSerifFont(this.family) 1326 } 1327 } 1328 } 1329 ``` 1330 1331### webStandardFont<sup>9+</sup> 1332 1333webStandardFont(family: string) 1334 1335Sets the standard font family for the web page. 1336 1337**Parameters** 1338 1339| Name | Type | Mandatory | Default Value | Description | 1340| ------ | ------ | ---- | ---------- | ---------------------- | 1341| family | string | Yes | sans serif | Standard font family to set.| 1342 1343**Example** 1344 1345 ```ts 1346 // xxx.ets 1347 import { webview } from '@kit.ArkWeb'; 1348 1349 @Entry 1350 @Component 1351 struct WebComponent { 1352 controller: webview.WebviewController = new webview.WebviewController(); 1353 @State family: string = "sans-serif"; 1354 1355 build() { 1356 Column() { 1357 Web({ src: 'www.example.com', controller: this.controller }) 1358 .webStandardFont(this.family) 1359 } 1360 } 1361 } 1362 ``` 1363 1364### webFantasyFont<sup>9+</sup> 1365 1366webFantasyFont(family: string) 1367 1368Sets the fantasy font family for the web page. 1369 1370**Parameters** 1371 1372| Name | Type | Mandatory | Default Value | Description | 1373| ------ | ------ | ---- | ------- | --------------------- | 1374| family | string | Yes | fantasy | Fantasy font family to set.| 1375 1376**Example** 1377 1378 ```ts 1379 // xxx.ets 1380 import { webview } from '@kit.ArkWeb'; 1381 @Entry 1382 @Component 1383 struct WebComponent { 1384 controller: webview.WebviewController = new webview.WebviewController(); 1385 @State family: string = "fantasy"; 1386 1387 build() { 1388 Column() { 1389 Web({ src: 'www.example.com', controller: this.controller }) 1390 .webFantasyFont(this.family) 1391 } 1392 } 1393 } 1394 ``` 1395 1396### webCursiveFont<sup>9+</sup> 1397 1398webCursiveFont(family: string) 1399 1400Sets the cursive font family for the web page. 1401 1402**Parameters** 1403 1404| Name | Type | Mandatory | Default Value | Description | 1405| ------ | ------ | ---- | ------- | --------------------- | 1406| family | string | Yes | cursive | Cursive font family to set.| 1407 1408**Example** 1409 1410 ```ts 1411 // xxx.ets 1412 import { webview } from '@kit.ArkWeb'; 1413 1414 @Entry 1415 @Component 1416 struct WebComponent { 1417 controller: webview.WebviewController = new webview.WebviewController(); 1418 @State family: string = "cursive"; 1419 1420 build() { 1421 Column() { 1422 Web({ src: 'www.example.com', controller: this.controller }) 1423 .webCursiveFont(this.family) 1424 } 1425 } 1426 } 1427 ``` 1428 1429### darkMode<sup>9+</sup> 1430 1431darkMode(mode: WebDarkMode) 1432 1433Sets the web dark mode. By default, web dark mode is disabled. When it is enabled, the **Web** component enables the dark theme defined for web pages if the theme has been defined in **prefers-color-scheme** of a media query, and remains unchanged otherwise. To enable the forcible dark mode, use this API with [forceDarkAccess](#forcedarkaccess9). 1434 1435**Parameters** 1436 1437| Name | Type | Mandatory | Default Value | Description | 1438| ---- | -------------------------------- | ---- | --------------- | ---------------------- | 1439| mode | [WebDarkMode](#webdarkmode9) | Yes | WebDarkMode.Off | Web dark mode to set.| 1440 1441**Example** 1442 1443 ```ts 1444 // xxx.ets 1445 import { webview } from '@kit.ArkWeb'; 1446 1447 @Entry 1448 @Component 1449 struct WebComponent { 1450 controller: webview.WebviewController = new webview.WebviewController(); 1451 @State mode: WebDarkMode = WebDarkMode.On; 1452 1453 build() { 1454 Column() { 1455 Web({ src: 'www.example.com', controller: this.controller }) 1456 .darkMode(this.mode) 1457 } 1458 } 1459 } 1460 ``` 1461 1462### forceDarkAccess<sup>9+</sup> 1463 1464forceDarkAccess(access: boolean) 1465 1466Sets whether to enable forcible dark mode for the web page. By default, this feature is turned off. This API is applicable only when dark mode is enabled in [darkMode](#darkmode9). 1467 1468**Parameters** 1469 1470| Name | Type | Mandatory | Default Value | Description | 1471| ------ | ------- | ---- | ----- | --------------- | 1472| access | boolean | Yes | false | Whether to enable forcible dark mode for the web page.| 1473 1474**Example** 1475 1476 ```ts 1477 // xxx.ets 1478 import { webview } from '@kit.ArkWeb'; 1479 1480 @Entry 1481 @Component 1482 struct WebComponent { 1483 controller: webview.WebviewController = new webview.WebviewController(); 1484 @State mode: WebDarkMode = WebDarkMode.On; 1485 @State access: boolean = true; 1486 1487 build() { 1488 Column() { 1489 Web({ src: 'www.example.com', controller: this.controller }) 1490 .darkMode(this.mode) 1491 .forceDarkAccess(this.access) 1492 } 1493 } 1494 } 1495 ``` 1496 1497### tableData<sup>(deprecated)</sup> 1498 1499tableData(tableData: boolean) 1500 1501Sets whether form data should be saved. This API is a void API. 1502 1503> **NOTE** 1504> 1505> This API is deprecated since API version 10, and no new API is provided as a substitute. 1506 1507### wideViewModeAccess<sup>(deprecated)</sup> 1508 1509wideViewModeAccess(wideViewModeAccess: boolean) 1510 1511Sets whether to support the viewport attribute of the HTML **\<meta>** tag. This API is a void API. 1512 1513> **NOTE** 1514> 1515> This API is deprecated since API version 10, and no new API is provided as a substitute. 1516 1517### pinchSmooth<sup>9+</sup> 1518 1519pinchSmooth(isEnabled: boolean) 1520 1521Sets whether to enable smooth pinch mode for the web page. 1522 1523**Parameters** 1524 1525| Name | Type | Mandatory | Default Value | Description | 1526| --------- | ------- | ---- | ----- | ------------- | 1527| isEnabled | boolean | Yes | false | Whether to enable smooth pinch mode for the web page.| 1528 1529**Example** 1530 1531 ```ts 1532 // xxx.ets 1533 import { webview } from '@kit.ArkWeb'; 1534 1535 @Entry 1536 @Component 1537 struct WebComponent { 1538 controller: webview.WebviewController = new webview.WebviewController(); 1539 1540 build() { 1541 Column() { 1542 Web({ src: 'www.example.com', controller: this.controller }) 1543 .pinchSmooth(true) 1544 } 1545 } 1546 } 1547 ``` 1548 1549### allowWindowOpenMethod<sup>10+</sup> 1550 1551allowWindowOpenMethod(flag: boolean) 1552 1553Sets whether to allow a new window to automatically open through JavaScript. 1554 1555When **flag** is set to **true**, a new window can automatically open through JavaScript. When **flag** is set to **false**, a new window can still automatically open through JavaScript for user behavior, but cannot for non-user behavior. The user behavior here refers to that a user requests to open a new window (**window.open**) within 5 seconds of operating the **Web** component. 1556 1557This API takes effect only when [javaScriptAccess](#javascriptaccess) is enabled. 1558 1559This API opens a new window when [multiWindowAccess](#multiwindowaccess9) is enabled and opens a local window when [multiWindowAccess](#multiwindowaccess9) is disabled. 1560 1561The default value of **flag** is subject to the settings of the **persist.web.allowWindowOpenMethod.enabled** system attribute. If this attribute is not set, the default value of **flag** is **false**. 1562 1563To check the settings of **persist.web.allowWindowOpenMethod.enabled**, 1564 1565run the **hdc shell param get persist.web.allowWindowOpenMethod.enabled** command. If the attribute is set to 0 or does not exist, 1566you can run the **hdc shell param set persist.web.allowWindowOpenMethod.enabled 1** command to enable it. 1567 1568**Parameters** 1569 1570| Name | Type | Mandatory | Default Value | Description | 1571| ---- | ------- | ---- | ---------------------------------------- | ------------------------- | 1572| flag | boolean | Yes | Subject to the settings of the **persist.web.allowWindowOpenMethod.enabled** system attribute. If this attribute is set, the default value of **flag** is **true**. Otherwise, the default value of **flag** is **false**.| Whether to allow a new window to automatically open through JavaScript.| 1573 1574**Example** 1575 1576 ```ts 1577 // xxx.ets 1578 import { webview } from '@kit.ArkWeb'; 1579 1580 // There are two Web components on the same page. When the Web Component object opens a new window, the NewWebViewComp object is displayed. 1581 @CustomDialog 1582 struct NewWebViewComp { 1583 controller?: CustomDialogController; 1584 webviewController1: webview.WebviewController = new webview.WebviewController(); 1585 1586 build() { 1587 Column() { 1588 Web({ src: "", controller: this.webviewController1 }) 1589 .javaScriptAccess(true) 1590 .multiWindowAccess(false) 1591 .onWindowExit(() => { 1592 console.info("NewWebViewComp onWindowExit"); 1593 if (this.controller) { 1594 this.controller.close(); 1595 } 1596 }) 1597 } 1598 } 1599 } 1600 1601 @Entry 1602 @Component 1603 struct WebComponent { 1604 controller: webview.WebviewController = new webview.WebviewController(); 1605 dialogController: CustomDialogController | null = null; 1606 1607 build() { 1608 Column() { 1609 Web({ src: 'www.example.com', controller: this.controller }) 1610 .javaScriptAccess(true) 1611 // MultiWindowAccess needs to be enabled. 1612 .multiWindowAccess(true) 1613 .allowWindowOpenMethod(true) 1614 .onWindowNew((event) => { 1615 if (this.dialogController) { 1616 this.dialogController.close(); 1617 } 1618 let popController: webview.WebviewController = new webview.WebviewController(); 1619 this.dialogController = new CustomDialogController({ 1620 builder: NewWebViewComp({ webviewController1: popController }) 1621 }) 1622 this.dialogController.open(); 1623 // Return the WebviewController object corresponding to the new window to the <Web> kernel. 1624 // If opening a new window is not needed, set the parameter to null when calling the event.handler.setWebController API. 1625 // If the event.handler.setWebController API is not called, the render process will be blocked. 1626 event.handler.setWebController(popController); 1627 }) 1628 } 1629 } 1630 } 1631 ``` 1632 1633### mediaOptions<sup>10+</sup> 1634 1635mediaOptions(options: WebMediaOptions) 1636 1637Sets the web-based media playback policy, including the validity period for automatically resuming a paused web audio, and whether the audio of multiple **Web** instances in an application is exclusive. 1638 1639> **NOTE** 1640> 1641> - Audios in the same **Web** instance are considered as the same audio. 1642> - The media playback policy controls videos with an audio track. 1643> - After the parameter settings are updated, the playback must be started again for the settings to take effect. 1644> - It is recommended that you set the same **audioExclusive** value for all **Web** components. 1645> - Audio and video interruption takes effect within an app and between apps, and playback resumption takes effect only between apps. 1646 1647**Parameters** 1648 1649| Name | Type | Mandatory | Default Value | Description | 1650| ------- | ------------------------------------- | ---- | ---------------------------------------- | ---------------------------------------- | 1651| options | [WebMediaOptions](#webmediaoptions10) | Yes | {resumeInterval: 0, audioExclusive: true} | Web-based media playback policy. The default value of **resumeInterval** is **0**, indicating that the playback is not automatically resumed.| 1652 1653**Example** 1654 1655 ```ts 1656 // xxx.ets 1657 import { webview } from '@kit.ArkWeb'; 1658 1659 @Entry 1660 @Component 1661 struct WebComponent { 1662 controller: webview.WebviewController = new webview.WebviewController(); 1663 @State options: WebMediaOptions = {resumeInterval: 10, audioExclusive: true}; 1664 1665 build() { 1666 Column() { 1667 Web({ src: 'www.example.com', controller: this.controller }) 1668 .mediaOptions(this.options) 1669 } 1670 } 1671 } 1672 ``` 1673 1674### javaScriptOnDocumentStart<sup>11+</sup> 1675 1676javaScriptOnDocumentStart(scripts: Array\<ScriptItem>) 1677 1678Injects a JavaScript script into the **Web** component. When the specified page or document starts to be loaded, the script is executed on any page whose source matches **scriptRules**. 1679 1680> **NOTE** 1681> 1682> - The script runs before any JavaScript code of the page, when the DOM tree may not have been loaded or rendered. 1683 1684**Parameters** 1685 1686| Name | Type | Mandatory | Default Value | Description | 1687| ------- | ----------------------------------- | ---- | ---- | ------------------ | 1688| scripts | Array\<[ScriptItem](#scriptitem11)> | Yes | - | Script item array to be injected.| 1689 1690**Example in the .ets file** 1691 1692 ```ts 1693 // xxx.ets 1694 import { webview } from '@kit.ArkWeb'; 1695 1696 @Entry 1697 @Component 1698 struct Index { 1699 controller: webview.WebviewController = new webview.WebviewController(); 1700 private localStorage: string = 1701 "if (typeof(Storage) !== 'undefined') {" + 1702 " localStorage.setItem('color', 'Red');" + 1703 "}"; 1704 @State scripts: Array<ScriptItem> = [ 1705 { script: this.localStorage, scriptRules: ["*"] } 1706 ]; 1707 1708 build() { 1709 Column({ space: 20 }) { 1710 Web({ src: $rawfile('index.html'), controller: this.controller }) 1711 .javaScriptAccess(true) 1712 .domStorageAccess(true) 1713 .backgroundColor(Color.Grey) 1714 .javaScriptOnDocumentStart(this.scripts) 1715 .width('100%') 1716 .height('100%') 1717 } 1718 } 1719 } 1720 ``` 1721**Example in the HTML file** 1722 1723```html 1724<!-- index.html --> 1725<!DOCTYPE html> 1726<html> 1727 <head> 1728 <meta charset="utf-8"> 1729 </head> 1730 <body style="font-size: 30px;" onload='bodyOnLoadLocalStorage()'> 1731 Hello world! 1732 <div id="result"></div> 1733 </body> 1734 <script type="text/javascript"> 1735 function bodyOnLoadLocalStorage() { 1736 if (typeof(Storage) !== 'undefined') { 1737 document.getElementById('result').innerHTML = localStorage.getItem('color'); 1738 } else { 1739 document.getElementById('result').innerHTML = 'Your browser does not support localStorage.'; 1740 } 1741 } 1742 </script> 1743</html> 1744``` 1745 1746### javaScriptOnDocumentEnd<sup>11+</sup> 1747 1748javaScriptOnDocumentEnd(scripts: Array\<ScriptItem>) 1749 1750Injects a JavaScript script into the **Web** component. When the specified page or document has been loaded, the script is executed on any page whose source matches **scriptRules**. 1751 1752> **NOTE** 1753> 1754> - The script runs before any JavaScript code of the page, when the DOM tree has been loaded and rendered. 1755 1756**Parameters** 1757 1758| Name | Type | Mandatory | Default Value | Description | 1759| ------- | ----------------------------------- | ---- | ---- | ------------------ | 1760| scripts | Array\<[ScriptItem](#scriptitem11)> | Yes | - | Script item array to be injected.| 1761 1762**Example** 1763 1764 ```ts 1765// xxx.ets 1766import { webview } from '@kit.ArkWeb'; 1767 1768@Entry 1769@Component 1770struct Index { 1771 controller: webview.WebviewController = new webview.WebviewController(); 1772 private jsStr: string = 1773 "window.document.getElementById(\"result\").innerHTML = 'this is msg from javaScriptOnDocumentEnd'"; 1774 @State scripts: Array<ScriptItem> = [ 1775 { script: this.jsStr, scriptRules: ["*"] } 1776 ]; 1777 1778 build() { 1779 Column({ space: 20 }) { 1780 Web({ src: $rawfile('index.html'), controller: this.controller }) 1781 .javaScriptAccess(true) 1782 .domStorageAccess(true) 1783 .backgroundColor(Color.Grey) 1784 .javaScriptOnDocumentEnd(this.scripts) 1785 .width('100%') 1786 .height('100%') 1787 } 1788 } 1789} 1790 ``` 1791 1792```html 1793<!DOCTYPE html> 1794<html> 1795<head> 1796 <meta charset="utf-8"> 1797</head> 1798<body style="font-size: 30px;"> 1799Hello world! 1800<div id="result">test msg</div> 1801</body> 1802</html> 1803``` 1804 1805### layoutMode<sup>11+</sup> 1806 1807layoutMode(mode: WebLayoutMode) 1808 1809Sets the web layout mode. 1810 1811> **NOTE** 1812> 1813> Currently, only two web layout modes are supported: **WebLayoutMode.NONE** and **WebLayoutMode.FIT_CONTENT**. 1814> 1815> The following restrictions apply with the usage of **WebLayoutMode.FIT_CONTENT**: 1816> - If the web content is wider or longer than 8000 px, specify the **RenderMode.SYNC_RENDER** mode when creating the **Web** component; otherwise, the screen may be blank. 1817> - After the **Web** component is created, dynamic switching of the **layoutMode** is not supported. 1818> - The width and height of the **Web** component cannot exceed 500,000 px each. 1819> - Frequent changes to the page width and height will trigger a re-layout of the **Web** component, which can affect the user experience. 1820 1821**Parameters** 1822 1823| Name | Type | Mandatory | Default Value | Description | 1824| ---- | ------------------------------------- | ---- | ------------------ | --------------------- | 1825| mode | [WebLayoutMode](#weblayoutmode11) | Yes | WebLayoutMode.NONE | Web layout mode.| 1826 1827**Example** 1828 1829 1. After specifying the **layoutMode** as **WebLayoutMode.FIT_CONTENT**, you must explicitly specify **renderMode** as **RenderMode.SYNC_RENDER**. 1830 ```ts 1831 // xxx.ets 1832 import { webview } from '@kit.ArkWeb'; 1833 1834 @Entry 1835 @Component 1836 struct WebComponent { 1837 controller: webview.WebviewController = new webview.WebviewController(); 1838 @State mode: WebLayoutMode = WebLayoutMode.FIT_CONTENT; 1839 1840 build() { 1841 Column() { 1842 Web({ src: 'www.example.com', controller: this.controller, renderMode: RenderMode.SYNC_RENDER }) 1843 .layoutMode(this.mode) 1844 } 1845 } 1846 } 1847 ``` 1848 1849 2. After specifying the **layoutMode** as **WebLayoutMode.FIT_CONTENT**, you are advised to specify **overScrollMode** as **OverScrollMode.NEVER**. 1850 ```ts 1851 // xxx.ets 1852 import { webview } from '@kit.ArkWeb'; 1853 1854 @Entry 1855 @Component 1856 struct WebComponent { 1857 controller: webview.WebviewController = new webview.WebviewController(); 1858 @State layoutMode: WebLayoutMode = WebLayoutMode.FIT_CONTENT; 1859 @State overScrollMode: OverScrollMode = OverScrollMode.NEVER; 1860 1861 build() { 1862 Column() { 1863 Web({ src: 'www.example.com', controller: this.controller, renderMode: RenderMode.SYNC_RENDER }) 1864 .layoutMode(this.layoutMode) 1865 .overScrollMode(this.overScrollMode) 1866 } 1867 } 1868 } 1869 ``` 1870 1871### nestedScroll<sup>11+</sup> 1872 1873nestedScroll(value: NestedScrollOptions) 1874 1875Sets nested scrolling options. 1876 1877> **NOTE** 1878> 1879> - You can set the nested scrolling mode in both forward and backward directions to implement scrolling linkage with the parent component. 1880> - You can set separate nested scrolling modes for the forward and backward directions. 1881> - The default mode for **scrollForward** and **scrollBackward** is **NestedScrollMode.SELF_FIRST**. 1882> - Containers that support nested scrolling: **\<Grid>**, **\<List>**, **\<Scroll>**, **\<Swiper>**, **\<Tabs>**, **\<WaterFlow>**. 1883> - Input sources that support nested scrolling: gestures, mouse device, and touchpad. 1884> - In nested scrolling scenarios, since the **Web** component's over-scrolling to the edge will trigger the over-scroll bounce effect first, it is recommended that you set **overScrollMode** to **OverScrollMode.NEVER** to avoid undermining the user experience. 1885 1886**Parameters** 1887 1888| Name | Type | Mandatory | Description | 1889| ----- | ---------------------------------------- | ---- | ---------------- | 1890| value | [NestedScrollOptions](#nestedscrolloptions11) | Yes | Nested scrolling options.| 1891 1892**Example** 1893 1894 ```ts 1895 // xxx.ets 1896 import { webview } from '@kit.ArkWeb'; 1897 @Entry 1898 @Component 1899 struct WebComponent { 1900 controller: webview.WebviewController = new webview.WebviewController(); 1901 1902 build() { 1903 Column() { 1904 Web({ src: 'www.example.com', controller: this.controller }) 1905 .nestedScroll({ 1906 scrollForward: NestedScrollMode.SELF_FIRST, 1907 scrollBackward: NestedScrollMode.SELF_FIRST, 1908 }) 1909 } 1910 } 1911 } 1912 ``` 1913### enableNativeEmbedMode<sup>11+</sup> 1914enableNativeEmbedMode(mode: boolean) 1915 1916Specifies whether to enable the same-layer rendering feature. By default, this feature is disabled. 1917 1918 1919**Parameters** 1920 1921| Name | Type | Mandatory | Default Value | Description | 1922| ----- | ---------------------------------------- | ---- | ------------------| ---------------- | 1923| mode | boolean | Yes | false | Whether to enable the same-layer rendering feature.| 1924 1925**Example** 1926 1927 ```ts 1928 // xxx.ets 1929 import { webview } from '@kit.ArkWeb'; 1930 @Entry 1931 @Component 1932 struct WebComponent { 1933 controller: webview.WebviewController = new webview.WebviewController(); 1934 1935 build() { 1936 Column() { 1937 Web({ src: 'www.example.com', controller: this.controller }) 1938 .enableNativeEmbedMode(true) 1939 } 1940 } 1941 } 1942 ``` 1943### forceDisplayScrollBar<sup>14+</sup> 1944 1945forceDisplayScrollBar(enabled: boolean) 1946 1947 1948Sets whether the scroll bar is always visible. By default, it is not always visible. Under the always-visible settings, when the page size exceeds one page, the scroll bar appears and remains visible. 1949 1950 1951**Parameters** 1952 1953| Name | Type| Mandatory| Default Value| Description | 1954| ------- | -------- | ---- | ------ | ------------------ | 1955| enabled | boolean | Yes | false | Whether the scroll bar is always visible.| 1956 1957 1958**Example** 1959 1960 ```ts 1961 // xxx.ets 1962 import { webview } from '@kit.ArkWeb'; 1963 1964 @Entry 1965 @Component 1966 struct WebComponent { 1967 controller: webview.WebviewController = new webview.WebviewController() 1968 1969 build() { 1970 Column() { 1971 Web({ src: $rawfile('index.html'), controller: this.controller }) 1972 .forceDisplayScrollBar(true) 1973 } 1974 } 1975 } 1976 ``` 1977 1978 HTML file to be loaded: 1979 ```html 1980 <!--index.html--> 1981 <!DOCTYPE html> 1982 <html> 1983 <head> 1984 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 1985 <title>Demo</title> 1986 <style> 1987 body { 1988 width:2560px; 1989 height:2560px; 1990 padding-right:170px; 1991 padding-left:170px; 1992 border:5px solid blueviolet 1993 } 1994 </style> 1995 </head> 1996 <body> 1997 Scroll Test 1998 </body> 1999 </html> 2000 ``` 2001### registerNativeEmbedRule<sup>12+</sup> 2002registerNativeEmbedRule(tag: string, type: string) 2003 2004Registers the HTML tag name and type for same-layer rendering. The tag name only supports **object** and **embed**. The tag type can be any non-empty string, case-insensitive. If the standard type is the same as the standard type of **object** or **embed**, the ArkWeb engine will recognize it as a non-same-layer tag. This API is also controlled by the **enableNativeEmbedMode** API and does not take effect if same-layer rendering is not enabled. When this API is not used, the ArkWeb engine recognizes the **embed** tags with the "native/" prefix as same-layer tags. 2005 2006**Parameters** 2007 2008| Name | Type | Mandatory | Default Value | Description | 2009|------|--------| ---- |------|------------------| 2010| tag | string | Yes | "" | Tag name. | 2011| type | string | Yes | "" | Tag type. It is used by the ArkWeb engine for prefix matching.| 2012 2013**Example** 2014 2015 ```ts 2016 // xxx.ets 2017 import { webview } from '@kit.ArkWeb'; 2018 2019 @Entry 2020 @Component 2021 struct WebComponent { 2022 controller: webview.WebviewController = new webview.WebviewController(); 2023 2024 build() { 2025 Column() { 2026 Web({ src: 'www.example.com', controller: this.controller }) 2027 .enableNativeEmbedMode(true) 2028 .registerNativeEmbedRule("object", "application/view") 2029 } 2030 } 2031 } 2032 ``` 2033### defaultTextEncodingFormat<sup>12+</sup> 2034 2035defaultTextEncodingFormat(textEncodingFormat: string) 2036 2037Sets the default character encoding for web pages. 2038 2039**Parameters** 2040 2041| Name | Type | Mandatory | Default Value | Description | 2042| ---- | ------ | ---- | ---- | ---------------------------------------- | 2043| textEncodingFormat | string | Yes | "UTF-8" | Default character encoding.| 2044 2045 **Example** 2046 2047 ```ts 2048 // xxx.ets 2049 import { webview } from '@kit.ArkWeb'; 2050 2051 @Entry 2052 @Component 2053 struct WebComponent { 2054 controller: webview.WebviewController = new webview.WebviewController(); 2055 2056 build() { 2057 Column() { 2058 Web({ src: $rawfile('index.html'), controller: this.controller }) 2059 // Set the height. 2060 .height(500) 2061 .defaultTextEncodingFormat("UTF-8") 2062 .javaScriptAccess(true) 2063 } 2064 } 2065 } 2066 ``` 2067 2068```html 2069 2070<!doctype html> 2071<html> 2072<head> 2073 <meta name="viewport" content="width=device-width" /> 2074 <title>My test html5 page</title> 2075</head> 2076<body> 2077 Hello world! 2078</body> 2079</html> 2080``` 2081### metaViewport<sup>12+</sup> 2082 2083metaViewport(enable: boolean) 2084 2085Sets whether the **viewport** property of the **meta** tag is enabled. 2086 2087> **NOTE** 2088> 2089> - If this parameter is set to **false**, the **viewport** property of the **meta** tag is not enabled. This means that the property will not be parsed and a default layout will be used. 2090> - If this parameter is set to **true**, the **viewport** property of the **meta** tag is enabled. This means that the property will be parsed and used for the layout. 2091> - If set to an invalid value, this parameter does not take effect. 2092> - If the device is 2-in-1, the **viewport** property is not supported. This means that, regardless of whether this parameter is set to **true** or **false**, the **viewport** property will not be parsed and a default layout will be used. 2093 2094**Parameters** 2095 2096| Name| Type| Mandatory| Default Value| Description | 2097| ------ | -------- | ---- | ------ | -------------------------------- | 2098| enable | boolean | Yes | true | Whether the **viewport** property of the **meta** tag is enabled.| 2099 2100**Example** 2101 2102 ```ts 2103// xxx.ets 2104import { webview } from '@kit.ArkWeb'; 2105 2106@Entry 2107@Component 2108struct WebComponent { 2109 controller: webview.WebviewController = new webview.WebviewController(); 2110 2111 build() { 2112 Column() { 2113 Web({ src: $rawfile('index.html'), controller: this.controller }) 2114 .metaViewport(true) 2115 } 2116 } 2117} 2118 ``` 2119 2120```html 2121<!doctype html> 2122<html> 2123<head> 2124 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 2125</head> 2126<body> 2127 <p>Hello world! </p> 2128</body> 2129</html> 2130``` 2131### textAutosizing<sup>12+</sup> 2132 2133textAutosizing(textAutosizing: boolean) 2134 2135Sets whether automatic text resizing is enabled. 2136 2137**Parameters** 2138 2139| Name | Type | Mandatory | Default Value | Description | 2140| ---- | ------ | ---- | ---- | ---------------------------------------- | 2141| textAutosizing | boolean | Yes | true | Whether automatic text resizing is enabled.| 2142 2143 **Example** 2144 2145 ```ts 2146 // xxx.ets 2147 import { webview } from '@kit.ArkWeb'; 2148 2149 @Entry 2150 @Component 2151 struct WebComponent { 2152 controller: webview.WebviewController = new webview.WebviewController(); 2153 2154 build() { 2155 Column() { 2156 Web({ src: 'www.example.com', controller: this.controller }) 2157 .textAutosizing(false) 2158 } 2159 } 2160 } 2161 ``` 2162### enableNativeMediaPlayer<sup>12+</sup> 2163 2164enableNativeMediaPlayer(config: NativeMediaPlayerConfig) 2165 2166Enable the [application takeover of web media playback feature](../../web/app-takeovers-web-media.md). 2167 2168**System capability**: SystemCapability.Web.Webview.Core 2169 2170**Parameters** 2171 2172| Name | Type | Mandatory | Default Value | Description| 2173| ---- | ------ | ---- | ---- | ---------------------| 2174| config | [NativeMediaPlayerConfig](#nativemediaplayerconfig12) | Yes | {enable: false, shouldOverlay: false} | **enable**: whether to enable the feature.<br> **shouldOverlay**: whether the image of the video player taken over by the application will overlay the web page content, if this feature is enabled.| 2175 2176 **Example** 2177 2178 ```ts 2179 // xxx.ets 2180 import { webview } from '@kit.ArkWeb'; 2181 2182 @Entry 2183 @Component 2184 struct WebComponent { 2185 controller: webview.WebviewController = new webview.WebviewController(); 2186 2187 build() { 2188 Column() { 2189 Web({ src: 'www.example.com', controller: this.controller }) 2190 .enableNativeMediaPlayer({enable: true, shouldOverlay: false}) 2191 } 2192 } 2193 } 2194 ``` 2195 2196### selectionMenuOptions<sup>12+</sup> 2197 2198selectionMenuOptions(expandedMenuOptions: Array\<ExpandedMenuItemOptions>) 2199 2200Sets the extended options of the custom context menu on selection, including the text content, icon, and callback. 2201 2202The API only supports the selection of plain text; if the selected content contains images or other non-text elements, the **action** information may display garbled content. 2203 2204**Parameters** 2205 2206| Name | Type | Description | 2207| ------------------- | ---------------------------------------------------------- | ------------- | 2208| expandedMenuOptions | Array<[ExpandedMenuItemOptions](#expandedmenuitemoptions12)> | Extended options of the custom context menu on selection.<br>The number of menu options, menu content size, and start icon size must be the same as those of the ArkUI [\<Menu>](../apis-arkui/arkui-ts/ts-basic-components-menu.md) component.| 2209 2210**Example** 2211 2212 ```ts 2213 // xxx.ets 2214 import { webview } from '@kit.ArkWeb'; 2215 2216 @Entry 2217 @Component 2218 struct WebComponent { 2219 controller: webview.WebviewController = new webview.WebviewController(); 2220 @State menuOptionArray: Array<ExpandedMenuItemOptions> = [ 2221 {content: 'Apple', startIcon: $r('app.media.icon'), action: (selectedText) => { 2222 console.info('select info ' + selectedText.toString()); 2223 }}, 2224 {content: 'Banana', startIcon: $r('app.media.icon'), action: (selectedText) => { 2225 console.info('select info ' + selectedText.toString()); 2226 }} 2227 ]; 2228 2229 build() { 2230 Column() { 2231 Web({ src: $rawfile("index.html"), controller: this.controller }) 2232 .selectionMenuOptions(this.menuOptionArray) 2233 } 2234 } 2235 } 2236 ``` 2237 2238 HTML file to be loaded: 2239 ```html 2240 <!--index.html--> 2241 <!DOCTYPE html> 2242 <html> 2243 <head> 2244 <title>Test Web Page</title> 2245 </head> 2246 <body> 2247 <h1>selectionMenuOptions Demo</h1> 2248 <span>selection menu options</span> 2249 </body> 2250 </html> 2251 ``` 2252 2253### keyboardAvoidMode<sup>12+</sup> 2254 2255keyboardAvoidMode(mode: WebKeyboardAvoidMode) 2256 2257Sets the custom soft keyboard avoidance mode. 2258 2259If the keyboard avoidance mode set in **UIContext** is [KeyboardAvoidMode.RESIZE](../apis-arkui/js-apis-arkui-UIContext.md#keyboardavoidmode11), this API does not take effect. 2260 2261**Parameters** 2262 2263| Name | Type | Mandatory | Description | 2264| ------------------- | ------------------------------ | ------ | ------------- | 2265| mode | [WebKeyboardAvoidMode](#webkeyboardavoidmode12) | Yes | Web soft keyboard avoidance mode.<br>Default value: **WebKeyboardAvoidMode.RESIZE_CONTENT**| 2266 2267**Example** 2268 2269 ```ts 2270 // xxx.ets 2271 import { webview } from '@kit.ArkWeb'; 2272 2273 @Entry 2274 @Component 2275 struct WebComponent { 2276 controller: webview.WebviewController = new webview.WebviewController(); 2277 @State avoidMode: WebKeyboardAvoidMode = WebKeyboardAvoidMode.RESIZE_VISUAL; 2278 2279 build() { 2280 Column() { 2281 Web({ src: $rawfile("index.html"), controller: this.controller }) 2282 .keyboardAvoidMode(this.avoidMode) 2283 } 2284 } 2285 } 2286 ``` 2287 2288 HTML file to be loaded: 2289 ```html 2290 <!--index.html--> 2291 <!DOCTYPE html> 2292 <html> 2293 <head> 2294 <title>Test Web Page</title> 2295 </head> 2296 <body> 2297 <input type="text" placeholder="Text"> 2298 </body> 2299 </html> 2300 ``` 2301 2302### editMenuOptions<sup>12+</sup> 2303editMenuOptions(editMenu: EditMenuOptions) 2304 2305Sets the custom menu options of the **Web** component. 2306 2307You can use this property to customize a text menu. 2308 2309You can use [onCreateMenu](../apis-arkui/arkui-ts/ts-text-common.md#oncreatemenu) to modify, add, and delete menu options. If you do not want to display text menus, return an empty array. 2310 2311You can use [onMenuItemClick](../apis-arkui/arkui-ts/ts-text-common.md#onmenuitemclick) to customize the callback for menu options. This function is triggered after a menu option is clicked and determines whether to execute the default callback based on the return value. If **true** is returned, the system callback is not executed. If **false** is returned, the system callback is executed. 2312 2313If this API is used together with [selectionMenuOptions](#selectionmenuoptions12), **selectionMenuOptions** does not take effect. 2314 2315**Parameters** 2316| Name | Type | Mandatory | Description | 2317| ------------------- | ------------------------------ | ------ | ------------- | 2318| editMenu | [EditMenuOptions](../apis-arkui/arkui-ts/ts-text-common.md#editmenuoptions)| Yes | Custom menu options of the **Web** component.<br>The number of menu options, menu content size, and icon size must be the same as those of the ArkUI [\<Menu>](../apis-arkui/arkui-ts/ts-basic-components-menu.md) component.<br>The values of ([TextMenuItemId](../apis-arkui/arkui-ts/ts-text-common.md#textmenuitemid12)) supported by the **Web** component are **CUT**, **COPY**, **PASTE**, and **SELECT_ALL**.<br>**textRange** in **onMenuItemClick()** is useless in the **Web** component. The input value is **-1**.| 2319 2320**Example** 2321 2322```ts 2323// xxx.ets 2324import { webview } from '@kit.ArkWeb'; 2325 2326@Entry 2327@Component 2328struct WebComponent { 2329 controller: webview.WebviewController = new webview.WebviewController(); 2330 2331 onCreateMenu(menuItems: Array<TextMenuItem>): Array<TextMenuItem> { 2332 let items = menuItems.filter((menuItem) => { 2333 // Filter the menu items as required. 2334 return ( 2335 menuItem.id.equals(TextMenuItemId.CUT) || 2336 menuItem.id.equals(TextMenuItemId.COPY) || 2337 menuItem.id.equals((TextMenuItemId.PASTE)) 2338 ) 2339 }); 2340 let customItem1: TextMenuItem = { 2341 content: 'customItem1', 2342 id: TextMenuItemId.of('customItem1'), 2343 icon: $r('app.media.icon') 2344 }; 2345 let customItem2: TextMenuItem = { 2346 content: $r('app.string.customItem2'), 2347 id: TextMenuItemId.of('customItem2'), 2348 icon: $r('app.media.icon') 2349 }; 2350 items.push(customItem1);// Add an option to the end of the option list. 2351 items.unshift(customItem2);// Add an option to the beginning of the option list. 2352 2353 return items; 2354 } 2355 2356 onMenuItemClick(menuItem: TextMenuItem, textRange: TextRange): boolean { 2357 if (menuItem.id.equals(TextMenuItemId.CUT)) { 2358 // User-defined behavior. 2359 console.log ("Intercept ID: CUT") 2360 return true; // Return true to not execute the system callback. 2361 } else if (menuItem.id.equals(TextMenuItemId.COPY)) { 2362 // User-defined behavior. 2363 console.log ("Do not intercept ID: COPY") 2364 return false; // Return false to execute the system callback. 2365 } else if (menuItem.id.equals(TextMenuItemId.of('customItem1'))) { 2366 // User-defined behavior. 2367 console.log ("Intercept ID: customItem1") 2368 return true;// Return true. There is no difference between true and false to the custom menu option, but true is recommended. 2369 } else if (menuItem.id.equals((TextMenuItemId.of($r('app.string.customItem2'))))){ 2370 // User-defined behavior. 2371 console.log ("Intercept ID: app.string.customItem2") 2372 return true; 2373 } 2374 return false;// Return the default value false. 2375 } 2376 2377 @State EditMenuOptions: EditMenuOptions = { onCreateMenu: this.onCreateMenu, onMenuItemClick: this.onMenuItemClick } 2378 2379 build() { 2380 Column() { 2381 Web({ src: $rawfile("index.html"), controller: this.controller }) 2382 .editMenuOptions(this.EditMenuOptions) 2383 } 2384 } 2385} 2386``` 2387 2388 HTML file to be loaded: 2389```html 2390<!--index.html--> 2391<!DOCTYPE html> 2392<html> 2393 <head> 2394 <title>Test Web Page</title> 2395 </head> 2396 <body> 2397 <h1>editMenuOptions Demo</h1> 2398 <span>edit menu options</span> 2399 </body> 2400</html> 2401``` 2402 2403## Events 2404 2405The following universal events are supported: [onAppear](../apis-arkui/arkui-ts/ts-universal-events-show-hide.md#onappear), [onDisAppear](../apis-arkui/arkui-ts/ts-universal-events-show-hide.md#ondisappear), [onBlur](../apis-arkui/arkui-ts/ts-universal-focus-event.md#onblur), [onFocus](../apis-arkui/arkui-ts/ts-universal-focus-event.md#onfocus), [onDragEnd](../apis-arkui/arkui-ts/ts-universal-events-drag-drop.md#ondragend), [onDragEnter](../apis-arkui/arkui-ts/ts-universal-events-drag-drop.md#ondragenter), [onDragStart](../apis-arkui/arkui-ts/ts-universal-events-drag-drop.md#ondragstart), [onDragMove](../apis-arkui/arkui-ts/ts-universal-events-drag-drop.md#ondragmove), [onDragLeave](../apis-arkui/arkui-ts/ts-universal-events-drag-drop.md#ondragleave), [onDrop](../apis-arkui/arkui-ts/ts-universal-events-drag-drop.md#ondrop), [onHover](../apis-arkui/arkui-ts/ts-universal-mouse-key.md#onhover), [onMouse](../apis-arkui/arkui-ts/ts-universal-mouse-key.md#onmouse), [onKeyEvent](../apis-arkui/arkui-ts/ts-universal-events-key.md#onkeyevent), [onTouch](../apis-arkui/arkui-ts/ts-universal-events-touch.md#ontouch), [onVisibleAreaChange](../apis-arkui/arkui-ts/ts-universal-component-visible-area-change-event.md#onvisibleareachange) 2406 2407### onAlert 2408 2409onAlert(callback: Callback\<OnAlertEvent, boolean\>) 2410 2411Called when **alert()** is invoked to display an alert dialog box on the web page. 2412 2413**Parameters** 2414 2415| Name | Type | Description | 2416| ------- | --------------------- | --------------- | 2417| callback | Callback\<[OnAlertEvent](#onalertevent12), boolean\> | Callback used when **alert()** is invoked to display an alert dialog box on the web page.<br>Return value: boolean<br> If the callback returns **true**, the application can use the custom dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to instruct the **Web** component to exit the current page based on the user operation. The value **false** means that the custom dialog box drawn in the function is ineffective.| 2418 2419**Example** 2420 2421 ```ts 2422 // xxx.ets 2423 import { webview } from '@kit.ArkWeb'; 2424 2425 @Entry 2426 @Component 2427 struct WebComponent { 2428 controller: webview.WebviewController = new webview.WebviewController(); 2429 2430 build() { 2431 Column() { 2432 Web({ src: $rawfile("index.html"), controller: this.controller }) 2433 .onAlert((event) => { 2434 if (event) { 2435 console.log("event.url:" + event.url); 2436 console.log("event.message:" + event.message); 2437 AlertDialog.show({ 2438 title: 'onAlert', 2439 message: 'text', 2440 primaryButton: { 2441 value: 'cancel', 2442 action: () => { 2443 event.result.handleCancel(); 2444 } 2445 }, 2446 secondaryButton: { 2447 value: 'ok', 2448 action: () => { 2449 event.result.handleConfirm(); 2450 } 2451 }, 2452 cancel: () => { 2453 event.result.handleCancel(); 2454 } 2455 }) 2456 } 2457 return true; 2458 }) 2459 } 2460 } 2461 } 2462 ``` 2463 2464 HTML file to be loaded: 2465 ```html 2466 <!--index.html--> 2467 <!DOCTYPE html> 2468 <html> 2469 <head> 2470 <meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8"> 2471 </head> 2472 <body> 2473 <h1>WebView onAlert Demo</h1> 2474 <button onclick="myFunction()">Click here</button> 2475 <script> 2476 function myFunction() { 2477 alert("Hello World"); 2478 } 2479 </script> 2480 </body> 2481 </html> 2482 ``` 2483 2484### onBeforeUnload 2485 2486onBeforeUnload(callback: Callback\<OnBeforeUnloadEvent, boolean\>) 2487 2488Called when this page is about to exit after the user refreshes or closes the page. This API takes effect only when the page has obtained focus. 2489 2490**Parameters** 2491 2492| Name | Type | Description | 2493| ------- | --------------------- | --------------- | 2494| callback | Callback\<[OnBeforeUnloadEvent](#onbeforeunloadevent12), boolean\> | Callback used when this page is about to exit after the user refreshes or closes the page.<br>Return value: boolean<br> If the callback returns **true**, the application can use the custom dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to instruct the **Web** component to exit the current page based on the user operation. The value **false** means that the custom dialog box drawn in the function is ineffective.| 2495 2496**Example** 2497 2498 ```ts 2499 // xxx.ets 2500 import { webview } from '@kit.ArkWeb'; 2501 2502 @Entry 2503 @Component 2504 struct WebComponent { 2505 controller: webview.WebviewController = new webview.WebviewController(); 2506 2507 build() { 2508 Column() { 2509 Web({ src: $rawfile("index.html"), controller: this.controller }) 2510 .onBeforeUnload((event) => { 2511 if (event) { 2512 console.log("event.url:" + event.url); 2513 console.log("event.message:" + event.message); 2514 AlertDialog.show({ 2515 title: 'onBeforeUnload', 2516 message: 'text', 2517 primaryButton: { 2518 value: 'cancel', 2519 action: () => { 2520 event.result.handleCancel(); 2521 } 2522 }, 2523 secondaryButton: { 2524 value: 'ok', 2525 action: () => { 2526 event.result.handleConfirm(); 2527 } 2528 }, 2529 cancel: () => { 2530 event.result.handleCancel(); 2531 } 2532 }) 2533 } 2534 return true; 2535 }) 2536 } 2537 } 2538 } 2539 ``` 2540 2541 HTML file to be loaded: 2542 ```html 2543 <!--index.html--> 2544 <!DOCTYPE html> 2545 <html> 2546 <head> 2547 <meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8"> 2548 </head> 2549 <body onbeforeunload="return myFunction()"> 2550 <h1>WebView onBeforeUnload Demo</h1> 2551 <a href="https://www.example.com">Click here</a> 2552 <script> 2553 function myFunction() { 2554 return "onBeforeUnload Event"; 2555 } 2556 </script> 2557 </body> 2558 </html> 2559 ``` 2560 2561### onConfirm 2562 2563onConfirm(callback: Callback\<OnConfirmEvent, boolean\>) 2564 2565Called when **confirm()** is invoked by the web page. 2566 2567**Parameters** 2568 2569| Name | Type | Description | 2570| ------- | --------------------- | --------------- | 2571| callback | Callback\<[OnConfirmEvent](#onconfirmevent12), boolean\> | Callback used when **confirm()** is invoked by the web page.<br>Return value: boolean<br> If the callback returns **true**, the application can use the custom dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to instruct the **Web** component to exit the current page based on the user operation. The value **false** means that the custom dialog box drawn in the function is ineffective.| 2572 2573**Example** 2574 2575 ```ts 2576 // xxx.ets 2577 import { webview } from '@kit.ArkWeb'; 2578 2579 @Entry 2580 @Component 2581 struct WebComponent { 2582 controller: webview.WebviewController = new webview.WebviewController(); 2583 2584 build() { 2585 Column() { 2586 Web({ src: $rawfile("index.html"), controller: this.controller }) 2587 .onConfirm((event) => { 2588 if (event) { 2589 console.log("event.url:" + event.url); 2590 console.log("event.message:" + event.message); 2591 AlertDialog.show({ 2592 title: 'onConfirm', 2593 message: 'text', 2594 primaryButton: { 2595 value: 'cancel', 2596 action: () => { 2597 event.result.handleCancel(); 2598 } 2599 }, 2600 secondaryButton: { 2601 value: 'ok', 2602 action: () => { 2603 event.result.handleConfirm(); 2604 } 2605 }, 2606 cancel: () => { 2607 event.result.handleCancel(); 2608 } 2609 }) 2610 } 2611 return true; 2612 }) 2613 } 2614 } 2615 } 2616 ``` 2617 2618 HTML file to be loaded: 2619 ```html 2620 <!--index.html--> 2621 <!DOCTYPE html> 2622 <html> 2623 <head> 2624 <meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8"> 2625 </head> 2626 2627 <body> 2628 <h1>WebView onConfirm Demo</h1> 2629 <button onclick="myFunction()">Click here</button> 2630 <p id="demo"></p> 2631 <script> 2632 function myFunction() { 2633 let x; 2634 let r = confirm("click button!"); 2635 if (r == true) { 2636 x = "ok"; 2637 } else { 2638 x = "cancel"; 2639 } 2640 document.getElementById("demo").innerHTML = x; 2641 } 2642 </script> 2643 </body> 2644 </html> 2645 ``` 2646 2647### onPrompt<sup>9+</sup> 2648 2649onPrompt(callback: Callback\<OnPromptEvent, boolean\>) 2650 2651Called when **prompt()** is invoked by the web page. 2652 2653**Parameters** 2654 2655| Name | Type | Description | 2656| ------- | --------------------- | --------------- | 2657| callback | Callback\<[OnPromptEvent](#onpromptevent12), boolean\> | Callback used when **prompt()** is invoked by the web page.<br>Return value: boolean<br> If the callback returns **true**, the application can use the custom dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to instruct the **Web** component to exit the current page based on the user operation. The value **false** means that the custom dialog box drawn in the function is ineffective.| 2658 2659**Example** 2660 2661 ```ts 2662 // xxx.ets 2663 import { webview } from '@kit.ArkWeb'; 2664 2665 @Entry 2666 @Component 2667 struct WebComponent { 2668 controller: webview.WebviewController = new webview.WebviewController(); 2669 2670 build() { 2671 Column() { 2672 Web({ src: $rawfile("index.html"), controller: this.controller }) 2673 .onPrompt((event) => { 2674 if (event) { 2675 console.log("url:" + event.url); 2676 console.log("message:" + event.message); 2677 console.log("value:" + event.value); 2678 AlertDialog.show({ 2679 title: 'onPrompt', 2680 message: 'text', 2681 primaryButton: { 2682 value: 'cancel', 2683 action: () => { 2684 event.result.handleCancel(); 2685 } 2686 }, 2687 secondaryButton: { 2688 value: 'ok', 2689 action: () => { 2690 event.result.handlePromptConfirm(event.value); 2691 } 2692 }, 2693 cancel: () => { 2694 event.result.handleCancel(); 2695 } 2696 }) 2697 } 2698 return true; 2699 }) 2700 } 2701 } 2702 } 2703 ``` 2704 2705 HTML file to be loaded: 2706 ```html 2707 <!--index.html--> 2708 <!DOCTYPE html> 2709 <html> 2710 <head> 2711 <meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8"> 2712 </head> 2713 2714 <body> 2715 <h1>WebView onPrompt Demo</h1> 2716 <button onclick="myFunction()">Click here</button> 2717 <p id="demo"></p> 2718 <script> 2719 function myFunction() { 2720 let message = prompt("Message info", "Hello World"); 2721 if (message != null && message != "") { 2722 document.getElementById("demo").innerHTML = message; 2723 } 2724 } 2725 </script> 2726 </body> 2727 </html> 2728 ``` 2729 2730### onConsole 2731 2732onConsole(callback: Callback\<OnConsoleEvent, boolean\>) 2733 2734Called to notify the host application of a JavaScript console message. 2735 2736**Parameters** 2737 2738| Name | Type | Description | 2739| ------- | --------------------------------- | --------- | 2740| callback | Callback\<[OnConsoleEvent](#onconsoleevent12), boolean\> | Called when the web page receives a JavaScript console message.<br>Return value: boolean<br> Returns **true** if the message will not be printed to the console; returns **false** otherwise.| 2741 2742**Example** 2743 2744 ```ts 2745 // xxx.ets 2746 import { webview } from '@kit.ArkWeb'; 2747 2748 @Entry 2749 @Component 2750 struct WebComponent { 2751 controller: webview.WebviewController = new webview.WebviewController(); 2752 2753 build() { 2754 Column() { 2755 Button('onconsole message') 2756 .onClick(() => { 2757 this.controller.runJavaScript('myFunction()'); 2758 }) 2759 Web({ src: $rawfile('index.html'), controller: this.controller }) 2760 .onConsole((event) => { 2761 if (event) { 2762 console.log('getMessage:' + event.message.getMessage()); 2763 console.log('getSourceId:' + event.message.getSourceId()); 2764 console.log('getLineNumber:' + event.message.getLineNumber()); 2765 console.log('getMessageLevel:' + event.message.getMessageLevel()); 2766 } 2767 return false; 2768 }) 2769 } 2770 } 2771 } 2772 ``` 2773 2774 HTML file to be loaded: 2775 ```html 2776 <!-- index.html --> 2777 <!DOCTYPE html> 2778 <html> 2779 <body> 2780 <script> 2781 function myFunction() { 2782 console.log("onconsole printf"); 2783 } 2784 </script> 2785 </body> 2786 </html> 2787 ``` 2788 2789### onDownloadStart 2790 2791onDownloadStart(callback: Callback\<OnDownloadStartEvent\>) 2792 2793Instructs the main application to start downloading a file. 2794 2795**Parameters** 2796 2797| Name | Type | Description | 2798| ------------------ | ------ | ----------------------------------- | 2799| callback | Callback\<[OnDownloadStartEvent](#ondownloadstartevent12)\> | Called when the download starts. | 2800 2801**Example** 2802 2803 ```ts 2804 // xxx.ets 2805 import { webview } from '@kit.ArkWeb'; 2806 2807 @Entry 2808 @Component 2809 struct WebComponent { 2810 controller: webview.WebviewController = new webview.WebviewController(); 2811 2812 build() { 2813 Column() { 2814 Web({ src: 'www.example.com', controller: this.controller }) 2815 .onDownloadStart((event) => { 2816 if (event) { 2817 console.log('url:' + event.url) 2818 console.log('userAgent:' + event.userAgent) 2819 console.log('contentDisposition:' + event.contentDisposition) 2820 console.log('contentLength:' + event.contentLength) 2821 console.log('mimetype:' + event.mimetype) 2822 } 2823 }) 2824 } 2825 } 2826 } 2827 ``` 2828 2829### onErrorReceive 2830 2831onErrorReceive(callback: Callback\<OnErrorReceiveEvent\>) 2832 2833Called when an error occurs during web page loading. For better results, simplify the implementation logic in the callback. This API is called when there is no network connection. 2834 2835**Parameters** 2836 2837| Name | Type | Description | 2838| ------- | ---------------------------------------- | --------------- | 2839| callback | Callback\<[OnErrorReceiveEvent](#onerrorreceiveevent12)\> | Called when an error occurs during web page loading. | 2840 2841**Example** 2842 2843 ```ts 2844 // xxx.ets 2845 import { webview } from '@kit.ArkWeb'; 2846 2847 @Entry 2848 @Component 2849 struct WebComponent { 2850 controller: webview.WebviewController = new webview.WebviewController(); 2851 2852 build() { 2853 Column() { 2854 Web({ src: 'www.example.com', controller: this.controller }) 2855 .onErrorReceive((event) => { 2856 if (event) { 2857 console.log('getErrorInfo:' + event.error.getErrorInfo()); 2858 console.log('getErrorCode:' + event.error.getErrorCode()); 2859 console.log('url:' + event.request.getRequestUrl()); 2860 console.log('isMainFrame:' + event.request.isMainFrame()); 2861 console.log('isRedirect:' + event.request.isRedirect()); 2862 console.log('isRequestGesture:' + event.request.isRequestGesture()); 2863 console.log('getRequestHeader_headerKey:' + event.request.getRequestHeader().toString()); 2864 let result = event.request.getRequestHeader(); 2865 console.log('The request header result size is ' + result.length); 2866 for (let i of result) { 2867 console.log('The request header key is : ' + i.headerKey + ', value is : ' + i.headerValue); 2868 } 2869 } 2870 }) 2871 } 2872 } 2873 } 2874 ``` 2875 2876### onHttpErrorReceive 2877 2878onHttpErrorReceive(callback: Callback\<OnHttpErrorReceiveEvent\>) 2879 2880Called when an HTTP error (the response code is greater than or equal to 400) occurs during web page resource loading. 2881 2882**Parameters** 2883 2884| Name | Type | Description | 2885| -------- | ---------------------------------------- | ---------- | 2886| callback | Callback\<[OnHttpErrorReceiveEvent](#onhttperrorreceiveevent12)\> | Called when an HTTP error occurs during web page resource loading.| 2887 2888**Example** 2889 2890 ```ts 2891 // xxx.ets 2892 import { webview } from '@kit.ArkWeb'; 2893 2894 @Entry 2895 @Component 2896 struct WebComponent { 2897 controller: webview.WebviewController = new webview.WebviewController(); 2898 2899 build() { 2900 Column() { 2901 Web({ src: 'www.example.com', controller: this.controller }) 2902 .onHttpErrorReceive((event) => { 2903 if (event) { 2904 console.log('url:' + event.request.getRequestUrl()); 2905 console.log('isMainFrame:' + event.request.isMainFrame()); 2906 console.log('isRedirect:' + event.request.isRedirect()); 2907 console.log('isRequestGesture:' + event.request.isRequestGesture()); 2908 console.log('getResponseData:' + event.response.getResponseData()); 2909 console.log('getResponseEncoding:' + event.response.getResponseEncoding()); 2910 console.log('getResponseMimeType:' + event.response.getResponseMimeType()); 2911 console.log('getResponseCode:' + event.response.getResponseCode()); 2912 console.log('getReasonMessage:' + event.response.getReasonMessage()); 2913 let result = event.request.getRequestHeader(); 2914 console.log('The request header result size is ' + result.length); 2915 for (let i of result) { 2916 console.log('The request header key is : ' + i.headerKey + ' , value is : ' + i.headerValue); 2917 } 2918 let resph = event.response.getResponseHeader(); 2919 console.log('The response header result size is ' + resph.length); 2920 for (let i of resph) { 2921 console.log('The response header key is : ' + i.headerKey + ' , value is : ' + i.headerValue); 2922 } 2923 } 2924 }) 2925 } 2926 } 2927 } 2928 ``` 2929 2930### onPageBegin 2931 2932onPageBegin(callback: Callback\<OnPageBeginEvent\>) 2933 2934Called when the web page starts to be loaded. This API is called only for the main frame content, and not for the iframe or frameset content. 2935 2936For details about the component lifecycle, see [Lifecycle of Web Components](../../web/web-event-sequence.md). 2937 2938**Parameters** 2939 2940| Name | Type | Description | 2941| ---- | ------ | --------- | 2942| callback | Callback\<[OnPageBeginEvent](#onpagebeginevent12)\> | Called when the web page starts to be loaded.| 2943 2944**Example** 2945 2946 ```ts 2947 // xxx.ets 2948 import { webview } from '@kit.ArkWeb'; 2949 2950 @Entry 2951 @Component 2952 struct WebComponent { 2953 controller: webview.WebviewController = new webview.WebviewController(); 2954 2955 build() { 2956 Column() { 2957 Web({ src: 'www.example.com', controller: this.controller }) 2958 .onPageBegin((event) => { 2959 if (event) { 2960 console.log('url:' + event.url); 2961 } 2962 }) 2963 } 2964 } 2965 } 2966 ``` 2967 2968### onPageEnd 2969 2970onPageEnd(callback: Callback\<OnPageEndEvent\>) 2971 2972Called when the web page loading is complete. This API takes effect only for the main frame content. 2973 2974For details about the component lifecycle, see [Lifecycle of Web Components](../../web/web-event-sequence.md). 2975 2976**Parameters** 2977 2978| Name | Type | Description | 2979| ---- | ------ | --------- | 2980| callback | Callback\<[OnPageEndEvent](#onpageendevent12)\> | Called when the web page loading is complete.| 2981 2982**Example** 2983 2984 ```ts 2985 // xxx.ets 2986 import { webview } from '@kit.ArkWeb'; 2987 2988 @Entry 2989 @Component 2990 struct WebComponent { 2991 controller: webview.WebviewController = new webview.WebviewController(); 2992 2993 build() { 2994 Column() { 2995 Web({ src: 'www.example.com', controller: this.controller }) 2996 .onPageEnd((event) => { 2997 if (event) { 2998 console.log('url:' + event.url); 2999 } 3000 }) 3001 } 3002 } 3003 } 3004 ``` 3005 3006### onProgressChange 3007 3008onProgressChange(callback: Callback\<OnProgressChangeEvent\>) 3009 3010Called when the web page loading progress changes. 3011 3012**Parameters** 3013 3014| Name | Type | Description | 3015| ----------- | ------ | --------------------- | 3016| callback | Callback\<[OnProgressChangeEvent](#onprogresschangeevent12)\> | Called when the web page loading progress changes.| 3017 3018**Example** 3019 3020 ```ts 3021 // xxx.ets 3022 import { webview } from '@kit.ArkWeb'; 3023 @Entry 3024 @Component 3025 struct WebComponent { 3026 controller: webview.WebviewController = new webview.WebviewController(); 3027 3028 build() { 3029 Column() { 3030 Web({ src: 'www.example.com', controller: this.controller }) 3031 .onProgressChange((event) => { 3032 if (event) { 3033 console.log('newProgress:' + event.newProgress); 3034 } 3035 }) 3036 } 3037 } 3038 } 3039 ``` 3040 3041### onTitleReceive 3042 3043onTitleReceive(callback: Callback\<OnTitleReceiveEvent\>) 3044 3045Called when the document title of a web page is changed. If the <title\> element is not set for an HTML5 page, the corresponding URL is returned. 3046 3047**Parameters** 3048 3049| Name | Type | Description | 3050| ----- | ------ | ------------- | 3051| callback | Callback\<[OnTitleReceiveEvent](#ontitlereceiveevent12)\> | Called when the document title of the web page is changed.| 3052 3053**Example** 3054 3055 ```ts 3056 // xxx.ets 3057 import { webview } from '@kit.ArkWeb'; 3058 3059 @Entry 3060 @Component 3061 struct WebComponent { 3062 controller: webview.WebviewController = new webview.WebviewController(); 3063 3064 build() { 3065 Column() { 3066 Web({ src: 'www.example.com', controller: this.controller }) 3067 .onTitleReceive((event) => { 3068 if (event) { 3069 console.log('title:' + event.title); 3070 } 3071 }) 3072 } 3073 } 3074 } 3075 ``` 3076 3077### onRefreshAccessedHistory 3078 3079onRefreshAccessedHistory(callback: Callback\<OnRefreshAccessedHistoryEvent\>) 3080 3081Called when loading of the web page is complete and the access history of a web page is refreshed. 3082 3083**Parameters** 3084 3085| Name | Type | Description | 3086| ----------- | ------- | ---------------------------------------- | 3087| callback | Callback\<[OnRefreshAccessedHistoryEvent](#onrefreshaccessedhistoryevent12)\> | Called when the access history of the web page is refreshed. | 3088 3089**Example** 3090 3091 ```ts 3092 // xxx.ets 3093 import { webview } from '@kit.ArkWeb'; 3094 3095 @Entry 3096 @Component 3097 struct WebComponent { 3098 controller: webview.WebviewController = new webview.WebviewController(); 3099 3100 build() { 3101 Column() { 3102 Web({ src: 'www.example.com', controller: this.controller }) 3103 .onRefreshAccessedHistory((event) => { 3104 if (event) { 3105 console.log('url:' + event.url + ' isReload:' + event.isRefreshed); 3106 } 3107 }) 3108 } 3109 } 3110 } 3111 ``` 3112 3113### onSslErrorReceive<sup>(deprecated)</sup> 3114 3115onSslErrorReceive(callback: (event?: { handler: Function, error: object }) => void) 3116 3117Called when an SSL error occurs during resource loading. 3118 3119> **NOTE** 3120> 3121> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [onSslErrorEventReceive<sup>9+</sup>](#onsslerroreventreceive9) instead. 3122 3123### onFileSelectorShow<sup>(deprecated)</sup> 3124 3125onFileSelectorShow(callback: (event?: { callback: Function, fileSelector: object }) => void) 3126 3127Called to process an HTML form whose input type is **file**, in response to the tapping of the **Select File** button. 3128 3129> **NOTE** 3130> 3131> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [onShowFileSelector<sup>9+</sup>](#onshowfileselector9) instead. 3132 3133### onRenderExited<sup>9+</sup> 3134 3135onRenderExited(callback: Callback\<OnRenderExitedEvent\>) 3136 3137Called when the rendering process exits abnormally. 3138 3139A rendering process may shared by multiple Web components. Each affected Web component triggers this callback. 3140 3141You call the bound **webviewContoller** APIs to restore the web page when this callback is triggered. For example, [refresh](js-apis-webview.md#refresh) and [loadUrl](js-apis-webview.md#loadurl). 3142 3143For details about the component lifecycle, see [Lifecycle of Web Components](../../web/web-event-sequence.md). 3144 3145**Parameters** 3146 3147| Name | Type | Description | 3148| ---------------- | ---------------------------------------- | ---------------- | 3149| callback | Callback\<[OnRenderExitedEvent](#onrenderexitedevent12)\> | Called when the rendering process exits abnormally.| 3150 3151**Example** 3152 3153 ```ts 3154 // xxx.ets 3155 import { webview } from '@kit.ArkWeb'; 3156 3157 @Entry 3158 @Component 3159 struct WebComponent { 3160 controller: webview.WebviewController = new webview.WebviewController(); 3161 3162 build() { 3163 Column() { 3164 Web({ src: 'chrome://crash/', controller: this.controller }) 3165 .onRenderExited((event) => { 3166 if (event) { 3167 console.log('reason:' + event.renderExitReason); 3168 } 3169 }) 3170 } 3171 } 3172 } 3173 ``` 3174### onRenderProcessNotResponding<sup>12+</sup> 3175 3176onRenderProcessNotResponding(callback: OnRenderProcessNotRespondingCallback) 3177 3178Called when the rendering process does not respond. If the **Web** component cannot process the input event or navigate to a new URL within a proper time range, the web page process is considered unresponsive and the callback is triggered. 3179 3180If the web page process does not respond, this callback may be triggered until the web page process responds again. In this case, [onRenderProcessResponding](#onrenderprocessresponding12) is triggered. 3181 3182You can terminate the associated rendering process through [terminateRenderProcess](js-apis-webview.md#terminaterenderprocess12), which may affect other Web components in the same rendering process. 3183 3184**Parameters** 3185 3186| Name | Type | Description | 3187| -------- | ------------------------------------------------------------ | -------------------------------------- | 3188| callback | [OnRenderProcessNotRespondingCallback](#onrenderprocessnotrespondingcallback12) | Callback triggered when the rendering process does not respond.| 3189 3190**Example** 3191 3192 ```ts 3193 // xxx.ets 3194 import { webview } from '@kit.ArkWeb'; 3195 3196 @Entry 3197 @Component 3198 struct WebComponent { 3199 controller: webview.WebviewController = new webview.WebviewController(); 3200 3201 build() { 3202 Column() { 3203 Web({ src: 'www.example.com', controller: this.controller }) 3204 .onRenderProcessNotResponding((data) => { 3205 console.log("onRenderProcessNotResponding: [jsStack]= " + data.jsStack + 3206 ", [process]=" + data.pid + ", [reason]=" + data.reason); 3207 }) 3208 } 3209 } 3210 } 3211 ``` 3212 3213### onRenderProcessResponding<sup>12+</sup> 3214 3215onRenderProcessResponding(callback: OnRenderProcessRespondingCallback) 3216 3217Called when the rendering process transitions back to a normal operating state from an unresponsive state. This callback indicates that the web page was not actually frozen. 3218 3219**Parameters** 3220 3221| Name | Type | Description | 3222| -------- | ------------------------------------------------------------ | -------------------------------------- | 3223| callback | [OnRenderProcessRespondingCallback](#onrenderprocessrespondingcallback12) | Callback triggered when the rendering process transitions back to a normal operating state from an unresponsive state.| 3224 3225**Example** 3226 3227 ```ts 3228 // xxx.ets 3229 import { webview } from '@kit.ArkWeb'; 3230 3231 @Entry 3232 @Component 3233 struct WebComponent { 3234 controller: webview.WebviewController = new webview.WebviewController(); 3235 3236 build() { 3237 Column() { 3238 Web({ src: 'www.example.com', controller: this.controller }) 3239 .onRenderProcessResponding(() => { 3240 console.log("onRenderProcessResponding again"); 3241 }) 3242 } 3243 } 3244 } 3245 ``` 3246 3247### onShowFileSelector<sup>9+</sup> 3248 3249onShowFileSelector(callback: Callback\<OnShowFileSelectorEvent, boolean\>) 3250 3251Called to process an HTML form whose input type is **file**. If this function is not called or returns **false**, the **Web** component provides the default **Select File** handling UI. If it returns **true**, the application can customize the response behavior for **Select File**. 3252 3253**Parameters** 3254 3255| Name | Type | Description | 3256| ------------ | ---------------------------------------- | ----------------- | 3257| callback | Callback\<[OnShowFileSelectorEvent](#onshowfileselectorevent12), boolean\> | File selection result to be sent to the **Web** component.<br>Return value: boolean<br> The value **true** means that you can invoke the system-provided popup capability. The value **false** means that the custom dialog box drawn in the function is ineffective.| 3258 3259**Example** 3260 32611. Start the file selector. 3262 3263 ```ts 3264 // xxx.ets 3265 import { webview } from '@kit.ArkWeb'; 3266 import { picker } from '@kit.CoreFileKit'; 3267 import { BusinessError } from '@kit.BasicServicesKit'; 3268 3269 @Entry 3270 @Component 3271 struct WebComponent { 3272 controller: webview.WebviewController = new webview.WebviewController() 3273 3274 build() { 3275 Column() { 3276 Web({ src: $rawfile('index.html'), controller: this.controller }) 3277 .onShowFileSelector((event) => { 3278 console.log('MyFileUploader onShowFileSelector invoked') 3279 const documentSelectOptions = new picker.DocumentSelectOptions(); 3280 let uri: string | null = null; 3281 const documentViewPicker = new picker.DocumentViewPicker(); 3282 documentViewPicker.select(documentSelectOptions).then((documentSelectResult) => { 3283 uri = documentSelectResult[0]; 3284 console.info('documentViewPicker.select to file succeed and uri is:' + uri); 3285 if (event) { 3286 event.result.handleFileList([uri]); 3287 } 3288 }).catch((err: BusinessError) => { 3289 console.error(`Invoke documentViewPicker.select failed, code is ${err.code}, message is ${err.message}`); 3290 }) 3291 return true; 3292 }) 3293 } 3294 } 3295 } 3296 ``` 3297 32982. Start the photo selector. 3299 3300 ```ts 3301 // xxx.ets 3302 import { webview } from '@kit.ArkWeb'; 3303 import { picker } from '@kit.CoreFileKit'; 3304 import { photoAccessHelper } from '@kit.MediaLibraryKit'; 3305 3306 @Entry 3307 @Component 3308 export struct WebComponent { 3309 controller: webview.WebviewController = new webview.WebviewController() 3310 3311 async selectFile(result: FileSelectorResult): Promise<void> { 3312 let photoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); 3313 let photoPicker = new photoAccessHelper.PhotoViewPicker(); 3314 // Set the MIME file type to IMAGE. 3315 photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_VIDEO_TYPE; 3316 // Set the maximum number of media files that can be selected. 3317 photoSelectOptions.maxSelectNumber = 5; 3318 let chooseFile: picker.PhotoSelectResult = await photoPicker.select(photoSelectOptions); 3319 // Obtain the list of selected files. 3320 result.handleFileList(chooseFile.photoUris); 3321 } 3322 3323 build() { 3324 Column() { 3325 Web({ src: $rawfile('index.html'), controller: this.controller }) 3326 .onShowFileSelector((event) => { 3327 if (event) { 3328 this.selectFile(event.result); 3329 } 3330 return true; 3331 }) 3332 } 3333 } 3334 } 3335 ``` 3336 3337 HTML file to be loaded: 3338 ```html 3339 <!DOCTYPE html> 3340 <html> 3341 <head> 3342 <meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8"> 3343 </head> 3344 <body> 3345 <form id="upload-form" enctype="multipart/form-data"> 3346 <input type="file" id="upload" name="upload"/> 3347 </form> 3348 </body> 3349 </html> 3350 ``` 3351 3352### onResourceLoad<sup>9+</sup> 3353 3354onResourceLoad(callback: Callback\<OnResourceLoadEvent\>) 3355 3356Called to notify the **Web** component of the URL of the loaded resource file. 3357 3358**Parameters** 3359 3360| Name | Type | Description | 3361| ---- | ------ | -------------- | 3362| callback | Callback\<[OnResourceLoadEvent](#onresourceloadevent12)\> | Callback invoked when a URL is loaded.| 3363 3364**Example** 3365 3366 ```ts 3367 // xxx.ets 3368 import { webview } from '@kit.ArkWeb'; 3369 3370 @Entry 3371 @Component 3372 struct WebComponent { 3373 controller: webview.WebviewController = new webview.WebviewController(); 3374 3375 build() { 3376 Column() { 3377 Web({ src: 'www.example.com', controller: this.controller }) 3378 .onResourceLoad((event) => { 3379 console.log('onResourceLoad: ' + event.url); 3380 }) 3381 } 3382 } 3383 } 3384 ``` 3385 3386### onScaleChange<sup>9+</sup> 3387 3388onScaleChange(callback: Callback\<OnScaleChangeEvent\>) 3389 3390Called when the display ratio of this page changes. 3391 3392**Parameters** 3393 3394| Name | Type | Description | 3395| -------- | ------ | ------------ | 3396| callback | Callback\<[OnScaleChangeEvent](#onscalechangeevent12)\> | Callback invoked when the display ratio of the page changes.| 3397 3398**Example** 3399 3400 ```ts 3401 // xxx.ets 3402 import { webview } from '@kit.ArkWeb'; 3403 3404 @Entry 3405 @Component 3406 struct WebComponent { 3407 controller: webview.WebviewController = new webview.WebviewController(); 3408 3409 build() { 3410 Column() { 3411 Web({ src: 'www.example.com', controller: this.controller }) 3412 .onScaleChange((event) => { 3413 console.log('onScaleChange changed from ' + event.oldScale + ' to ' + event.newScale); 3414 }) 3415 } 3416 } 3417 } 3418 ``` 3419 3420### onUrlLoadIntercept<sup>(deprecated)</sup> 3421 3422onUrlLoadIntercept(callback: (event?: { data:string | WebResourceRequest }) => boolean) 3423 3424Called when the **Web** component is about to access a URL. This API is used to determine whether to block the access, which is allowed by default. 3425This API is deprecated since API version 10. You are advised to use [onLoadIntercept<sup>10+</sup>](#onloadintercept10) instead. 3426 3427**Parameters** 3428 3429| Name | Type | Description | 3430| ---- | ---------------------------------------- | --------- | 3431| data | string \| [WebResourceRequest](#webresourcerequest) | URL information.| 3432 3433**Return value** 3434 3435| Type | Description | 3436| ------- | ------------------------ | 3437| boolean | Returns **true** if the access is blocked; returns **false** otherwise.| 3438 3439**Example** 3440 3441 ```ts 3442 // xxx.ets 3443 import { webview } from '@kit.ArkWeb'; 3444 3445 @Entry 3446 @Component 3447 struct WebComponent { 3448 controller: webview.WebviewController = new webview.WebviewController(); 3449 3450 build() { 3451 Column() { 3452 Web({ src: 'www.example.com', controller: this.controller }) 3453 .onUrlLoadIntercept((event) => { 3454 if (event) { 3455 console.log('onUrlLoadIntercept ' + event.data.toString()); 3456 } 3457 return true 3458 }) 3459 } 3460 } 3461 } 3462 ``` 3463 3464### onInterceptRequest<sup>9+</sup> 3465 3466onInterceptRequest(callback: Callback<OnInterceptRequestEvent, WebResourceResponse>) 3467 3468Called when the **Web** component is about to access a URL. This API is used to block the URL and return the response data. 3469 3470**Parameters** 3471 3472| Name | Type | Description | 3473| ------- | ---------------------------------------- | ----------- | 3474| callback | Callback\<[OnInterceptRequestEvent](#oninterceptrequestevent12)\> | Callback invoked when the **Web** component is about to load a URL.<br>The return value is [WebResourceResponse](#webresourceresponse). If response data is returned, the data is loaded based on the response data. If no response data is returned, null is returned, indicating that the data is loaded in the original mode.| 3475 3476**Example** 3477 3478 ```ts 3479 // xxx.ets 3480 import { webview } from '@kit.ArkWeb'; 3481 3482 @Entry 3483 @Component 3484 struct WebComponent { 3485 controller: webview.WebviewController = new webview.WebviewController(); 3486 responseWeb: WebResourceResponse = new WebResourceResponse(); 3487 heads: Header[] = new Array(); 3488 @State webData: string = "<!DOCTYPE html>\n" + 3489 "<html>\n" + 3490 "<head>\n" + 3491 "<title>intercept test</title>\n" + 3492 "</head>\n" + 3493 "<body>\n" + 3494 "<h1>intercept test</h1>\n" + 3495 "</body>\n" + 3496 "</html>"; 3497 3498 build() { 3499 Column() { 3500 Web({ src: 'www.example.com', controller: this.controller }) 3501 .onInterceptRequest((event) => { 3502 if (event) { 3503 console.log('url:' + event.request.getRequestUrl()); 3504 } 3505 let head1: Header = { 3506 headerKey: "Connection", 3507 headerValue: "keep-alive" 3508 } 3509 let head2: Header = { 3510 headerKey: "Cache-Control", 3511 headerValue: "no-cache" 3512 } 3513 let length = this.heads.push(head1); 3514 length = this.heads.push(head2); 3515 const promise: Promise<String> = new Promise((resolve: Function, reject: Function) => { 3516 this.responseWeb.setResponseHeader(this.heads); 3517 this.responseWeb.setResponseData(this.webData); 3518 this.responseWeb.setResponseEncoding('utf-8'); 3519 this.responseWeb.setResponseMimeType('text/html'); 3520 this.responseWeb.setResponseCode(200); 3521 this.responseWeb.setReasonMessage('OK'); 3522 resolve("success"); 3523 }) 3524 promise.then(() => { 3525 console.log("prepare response ready"); 3526 this.responseWeb.setResponseIsReady(true); 3527 }) 3528 this.responseWeb.setResponseIsReady(false); 3529 return this.responseWeb; 3530 }) 3531 } 3532 } 3533 } 3534 ``` 3535 3536### onHttpAuthRequest<sup>9+</sup> 3537 3538onHttpAuthRequest(callback: Callback\<OnHttpAuthRequestEvent, boolean\>) 3539 3540Called when an HTTP authentication request is received. 3541 3542**Parameters** 3543 3544| Name | Type | Description | 3545| ------- | ------------------------------------ | ---------------- | 3546| callback | Callback\<[OnHttpAuthRequestEvent](#onhttpauthrequestevent12), boolean\> | Callback invoked when the browser requires user credentials.<br>Return value: boolean<br> Returns **true** if the authentication is successful; returns **false** otherwise. | 3547 3548**Example** 3549 3550 ```ts 3551 // xxx.ets 3552 import { webview } from '@kit.ArkWeb'; 3553 3554 @Entry 3555 @Component 3556 struct WebComponent { 3557 controller: webview.WebviewController = new webview.WebviewController(); 3558 httpAuth: boolean = false; 3559 3560 build() { 3561 Column() { 3562 Web({ src: 'www.example.com', controller: this.controller }) 3563 .onHttpAuthRequest((event) => { 3564 if (event) { 3565 AlertDialog.show({ 3566 title: 'onHttpAuthRequest', 3567 message: 'text', 3568 primaryButton: { 3569 value: 'cancel', 3570 action: () => { 3571 event.handler.cancel(); 3572 } 3573 }, 3574 secondaryButton: { 3575 value: 'ok', 3576 action: () => { 3577 this.httpAuth = event.handler.isHttpAuthInfoSaved(); 3578 if (this.httpAuth == false) { 3579 webview.WebDataBase.saveHttpAuthCredentials( 3580 event.host, 3581 event.realm, 3582 "2222", 3583 "2222" 3584 ) 3585 event.handler.cancel(); 3586 } 3587 } 3588 }, 3589 cancel: () => { 3590 event.handler.cancel(); 3591 } 3592 }) 3593 } 3594 return true; 3595 }) 3596 } 3597 } 3598 } 3599 ``` 3600### onSslErrorEventReceive<sup>9+</sup> 3601 3602onSslErrorEventReceive(callback: Callback\<OnSslErrorEventReceiveEvent\>) 3603 3604Called to notify users when an SSL error occurs with a request for the main frame. 3605To include errors with requests for subframes, use the [OnSslErrorEvent](#onsslerrorevent12) API. 3606 3607**Parameters** 3608 3609| Name | Type | Description | 3610| ------- | ------------------------------------ | -------------- | 3611| callback | Callback\<[OnSslErrorEventReceiveEvent](#onsslerroreventreceiveevent12)\> | Callback invoked when the web page receives an SSL error.| 3612 3613**Example** 3614 3615 ```ts 3616 // xxx.ets 3617 import { webview } from '@kit.ArkWeb'; 3618 3619 @Entry 3620 @Component 3621 struct WebComponent { 3622 controller: webview.WebviewController = new webview.WebviewController(); 3623 3624 build() { 3625 Column() { 3626 Web({ src: 'www.example.com', controller: this.controller }) 3627 .onSslErrorEventReceive((event) => { 3628 AlertDialog.show({ 3629 title: 'onSslErrorEventReceive', 3630 message: 'text', 3631 primaryButton: { 3632 value: 'confirm', 3633 action: () => { 3634 event.handler.handleConfirm(); 3635 } 3636 }, 3637 secondaryButton: { 3638 value: 'cancel', 3639 action: () => { 3640 event.handler.handleCancel(); 3641 } 3642 }, 3643 cancel: () => { 3644 event.handler.handleCancel(); 3645 } 3646 }) 3647 }) 3648 } 3649 } 3650 } 3651 ``` 3652 3653### onSslErrorEvent<sup>12+</sup> 3654 3655onSslErrorEvent(callback: OnSslErrorEventCallback) 3656 3657Called to notify users when an SSL error occurs during the loading of resources (for the main frame and subframes). To handle SSL errors for requests for the main frame, use the **isMainFrame** field to distinguish. 3658 3659**Parameters** 3660 3661| Name | Type | Description | 3662| ------- | ------------------------------------ | -------------- | 3663| callback | [OnSslErrorEventCallback](#onsslerroreventcallback12) | Callback invoked when an SSL error occurs during resource loading.| 3664 3665**Example** 3666 3667 ```ts 3668 // xxx.ets 3669 import { webview } from '@kit.ArkWeb'; 3670 3671 @Entry 3672 @Component 3673 struct WebComponent { 3674 controller: webview.WebviewController = new webview.WebviewController(); 3675 3676 build() { 3677 Column() { 3678 Web({ src: 'www.example.com', controller: this.controller }) 3679 .onSslErrorEvent((event: SslErrorEvent) => { 3680 console.log("onSslErrorEvent url: " + event.url); 3681 console.log("onSslErrorEvent error: " + event.error); 3682 console.log("onSslErrorEvent originalUrl: " + event.originalUrl); 3683 console.log("onSslErrorEvent referrer: " + event.referrer); 3684 console.log("onSslErrorEvent isFatalError: " + event.isFatalError); 3685 console.log("onSslErrorEvent isMainFrame: " + event.isMainFrame); 3686 AlertDialog.show({ 3687 title: 'onSslErrorEvent', 3688 message: 'text', 3689 primaryButton: { 3690 value: 'confirm', 3691 action: () => { 3692 event.handler.handleConfirm(); 3693 } 3694 }, 3695 secondaryButton: { 3696 value: 'cancel', 3697 action: () => { 3698 event.handler.handleCancel(); 3699 } 3700 }, 3701 cancel: () => { 3702 event.handler.handleCancel(); 3703 } 3704 }) 3705 }) 3706 } 3707 } 3708 } 3709 ``` 3710 3711### onClientAuthenticationRequest<sup>9+</sup> 3712 3713onClientAuthenticationRequest(callback: Callback\<OnClientAuthenticationEvent\>) 3714 3715Called when an SSL client certificate request is received. 3716 3717**Parameters** 3718 3719| Name | Type | Description | 3720| -------- | ---------------------------------------- | --------------- | 3721| callback | Callback\<[OnClientAuthenticationEvent](#onclientauthenticationrequestevent12)\> | Callback invoked when an SSL client certificate is required from the user. | 3722 3723 **Example** 3724 3725 This example shows two-way authentication when interconnection with certificate management is not supported. 3726 3727 ```ts 3728 // xxx.ets API9 3729 import { webview } from '@kit.ArkWeb'; 3730 3731 @Entry 3732 @Component 3733 struct WebComponent { 3734 controller: webview.WebviewController = new webview.WebviewController(); 3735 3736 build() { 3737 Column() { 3738 Web({ src: 'www.example.com', controller: this.controller }) 3739 .onClientAuthenticationRequest((event) => { 3740 AlertDialog.show({ 3741 title: 'onClientAuthenticationRequest', 3742 message: 'text', 3743 primaryButton: { 3744 value: 'confirm', 3745 action: () => { 3746 event.handler.confirm("/system/etc/user.pk8", "/system/etc/chain-user.pem"); 3747 } 3748 }, 3749 secondaryButton: { 3750 value: 'cancel', 3751 action: () => { 3752 event.handler.cancel(); 3753 } 3754 }, 3755 cancel: () => { 3756 event.handler.ignore(); 3757 } 3758 }) 3759 }) 3760 } 3761 } 3762 } 3763 ``` 3764 3765 This example shows two-way authentication when interconnection with certificate management is supported. 3766 3767 1. Construct the singleton object **GlobalContext**. 3768 3769 ```ts 3770 // GlobalContext.ets 3771 export class GlobalContext { 3772 private constructor() {} 3773 private static instance: GlobalContext; 3774 private _objects = new Map<string, Object>(); 3775 3776 public static getContext(): GlobalContext { 3777 if (!GlobalContext.instance) { 3778 GlobalContext.instance = new GlobalContext(); 3779 } 3780 return GlobalContext.instance; 3781 } 3782 3783 getObject(value: string): Object | undefined { 3784 return this._objects.get(value); 3785 } 3786 3787 setObject(key: string, objectClass: Object): void { 3788 this._objects.set(key, objectClass); 3789 } 3790 } 3791 ``` 3792 3793 3794 2. Implement two-way authentication. 3795 3796 ```ts 3797 // xxx.ets API10 3798 import { webview } from '@kit.ArkWeb'; 3799 import { common, Want, bundleManager } from '@kit.AbilityKit'; 3800 import { BusinessError } from '@kit.BasicServicesKit'; 3801 import { GlobalContext } from '../GlobalContext'; 3802 3803 let uri = ""; 3804 3805 export default class CertManagerService { 3806 private static sInstance: CertManagerService; 3807 private authUri = ""; 3808 private appUid = ""; 3809 3810 public static getInstance(): CertManagerService { 3811 if (CertManagerService.sInstance == null) { 3812 CertManagerService.sInstance = new CertManagerService(); 3813 } 3814 return CertManagerService.sInstance; 3815 } 3816 3817 async grantAppPm(callback: (message: string) => void) { 3818 let message = ''; 3819 let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION; 3820 // Note: Replace com.example.myapplication with the actual application name. 3821 try { 3822 bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => { 3823 console.info('getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data)); 3824 this.appUid = data.appInfo.uid.toString(); 3825 }).catch((err: BusinessError) => { 3826 console.error('getBundleInfoForSelf failed. Cause: %{public}s', err.message); 3827 }); 3828 } catch (err) { 3829 let message = (err as BusinessError).message; 3830 console.error('getBundleInfoForSelf failed: %{public}s', message); 3831 } 3832 3833 // Note: Add GlobalContext.getContext().setObject("AbilityContext", this.context) to the onCreate function in the MainAbility.ts file. 3834 let abilityContext = GlobalContext.getContext().getObject("AbilityContext") as common.UIAbilityContext 3835 await abilityContext.startAbilityForResult( 3836 { 3837 bundleName: "com.ohos.certmanager", 3838 abilityName: "MainAbility", 3839 uri: "requestAuthorize", 3840 parameters: { 3841 appUid: this.appUid, // Pass the UID of the requesting application. 3842 } 3843 } as Want) 3844 .then((data: common.AbilityResult) => { 3845 if (!data.resultCode && data.want) { 3846 if (data.want.parameters) { 3847 this.authUri = data.want.parameters.authUri as string; // Obtain the returned authUri after successful authorization. 3848 } 3849 } 3850 }) 3851 message += "after grantAppPm authUri: " + this.authUri; 3852 uri = this.authUri; 3853 callback(message) 3854 } 3855 } 3856 3857 @Entry 3858 @Component 3859 struct WebComponent { 3860 controller: webview.WebviewController = new webview.WebviewController(); 3861 @State message: string ='Hello World' // message is used for debugging and observation. 3862 certManager = CertManagerService.getInstance(); 3863 3864 build() { 3865 Row() { 3866 Column() { 3867 Row() { 3868 // Step 1: Perform authorization to obtain the URI. 3869 Button('GrantApp') 3870 .onClick(() => { 3871 this.certManager.grantAppPm((data) => { 3872 this.message = data; 3873 }); 3874 }) 3875 // Step 2: After the authorization, in two-way authentication, the onClientAuthenticationRequest callback is used to send the URI to the web server for authentication. 3876 Button("ClientCertAuth") 3877 .onClick(() => { 3878 this.controller.loadUrl('https://www.example2.com'); // Server website that supports two-way authentication. 3879 }) 3880 } 3881 3882 Web({ src: 'https://www.example1.com', controller: this.controller }) 3883 .fileAccess(true) 3884 .javaScriptAccess(true) 3885 .domStorageAccess(true) 3886 .onlineImageAccess(true) 3887 3888 .onClientAuthenticationRequest((event) => { 3889 AlertDialog.show({ 3890 title: 'ClientAuth', 3891 message: 'Text', 3892 confirm: { 3893 value: 'Confirm', 3894 action: () => { 3895 event.handler.confirm(uri); 3896 } 3897 }, 3898 cancel: () => { 3899 event.handler.cancel(); 3900 } 3901 }) 3902 }) 3903 } 3904 } 3905 .width('100%') 3906 .height('100%') 3907 } 3908 } 3909 ``` 3910 3911### onPermissionRequest<sup>9+</sup> 3912 3913onPermissionRequest(callback: Callback\<OnPermissionRequestEvent\>) 3914 3915Called when a permission request is received. To call this API, you need to declare the **ohos.permission.CAMERA** and **ohos.permission.MICROPHONE** permissions. 3916 3917**Parameters** 3918 3919| Name | Type | Description | 3920| ------- | ---------------------------------------- | -------------- | 3921| callback | Callback\<[OnPermissionRequestEvent](#onpermissionrequestevent12)\> | Callback invoked when a permission request is received.| 3922 3923**Example** 3924 3925 ```ts 3926 // xxx.ets 3927 import { webview } from '@kit.ArkWeb'; 3928 import { BusinessError } from '@kit.BasicServicesKit'; 3929 import { abilityAccessCtrl } from '@kit.AbilityKit'; 3930 3931 @Entry 3932 @Component 3933 struct WebComponent { 3934 controller: webview.WebviewController = new webview.WebviewController(); 3935 3936 aboutToAppear() { 3937 // Enable web frontend page debugging. 3938 webview.WebviewController.setWebDebuggingAccess(true); 3939 let atManager = abilityAccessCtrl.createAtManager(); 3940 atManager.requestPermissionsFromUser(getContext(this), ['ohos.permission.CAMERA', 'ohos.permission.MICROPHONE']) 3941 .then((data) => { 3942 console.info('data:' + JSON.stringify(data)); 3943 console.info('data permissions:' + data.permissions); 3944 console.info('data authResults:' + data.authResults); 3945 }).catch((error: BusinessError) => { 3946 console.error(`Failed to request permissions from user. Code is ${error.code}, message is ${error.message}`); 3947 }) 3948 } 3949 3950 build() { 3951 Column() { 3952 Web({ src: $rawfile('index.html'), controller: this.controller }) 3953 .onPermissionRequest((event) => { 3954 if (event) { 3955 AlertDialog.show({ 3956 title: 'title', 3957 message: 'text', 3958 primaryButton: { 3959 value: 'deny', 3960 action: () => { 3961 event.request.deny(); 3962 } 3963 }, 3964 secondaryButton: { 3965 value: 'onConfirm', 3966 action: () => { 3967 event.request.grant(event.request.getAccessibleResource()); 3968 } 3969 }, 3970 cancel: () => { 3971 event.request.deny(); 3972 } 3973 }) 3974 } 3975 }) 3976 } 3977 } 3978 } 3979 ``` 3980 3981 HTML file to be loaded: 3982 ```html 3983 <!-- index.html --> 3984 <!DOCTYPE html> 3985 <html> 3986 <head> 3987 <meta charset="UTF-8"> 3988 </head> 3989 <body> 3990 <video id="video" width="500px" height="500px" autoplay="autoplay"></video> 3991 <canvas id="canvas" width="500px" height="500px"></canvas> 3992 <br> 3993 <input type="button" title="HTML5 Camera" value="Enable Camera" onclick="getMedia()"/> 3994 <script> 3995 function getMedia() 3996 { 3997 let constraints = { 3998 video: {width: 500, height: 500}, 3999 audio: true 4000 }; 4001 // Obtain the video camera area. 4002 let video = document.getElementById("video"); 4003 // Returned Promise object 4004 let promise = navigator.mediaDevices.getUserMedia(constraints); 4005 // then() is asynchronous. Invoke the MediaStream object as a parameter. 4006 promise.then(function (MediaStream) { 4007 video.srcObject = MediaStream; 4008 video.play(); 4009 }); 4010 } 4011 </script> 4012 </body> 4013 </html> 4014 ``` 4015 4016### onContextMenuShow<sup>9+</sup> 4017 4018onContextMenuShow(callback: Callback\<OnContextMenuShowEvent, boolean\>) 4019 4020Called when a context menu is displayed after the user clicks the right mouse button or long presses a specific element, such as an image or a link. 4021 4022**Parameters** 4023 4024| Name | Type | Description | 4025| ------ | ---------------------------------------- | ----------- | 4026| callback | Callback\<[OnContextMenuShowEvent](#oncontextmenushowevent12), boolean\> | Callback invoked during a call to allow for the display of a custom context menu.<br>Return value: boolean<br> The value **true** means a valid custom menu, and **false** means an invalid custom menu. | 4027 4028**Example** 4029 4030 ```ts 4031 // xxx.ets 4032 import { webview } from '@kit.ArkWeb'; 4033 import { pasteboard } from '@kit.BasicServicesKit'; 4034 4035 const TAG = 'ContextMenu'; 4036 4037 @Entry 4038 @Component 4039 struct WebComponent { 4040 controller: webview.WebviewController = new webview.WebviewController(); 4041 private result: WebContextMenuResult | undefined = undefined; 4042 @State linkUrl: string = ''; 4043 @State offsetX: number = 0; 4044 @State offsetY: number = 0; 4045 @State showMenu: boolean = false; 4046 4047 @Builder 4048 // Build and trigger a custom menu. 4049 MenuBuilder() { 4050 // A component that is used to present a vertical list of items to the user. 4051 Menu() { 4052 // A component that is used to represent an item in a menu. 4053 MenuItem({ 4054 content: 'Copy Image', 4055 }) 4056 .width(100) 4057 .height(50) 4058 .onClick(() => { 4059 this.result?.copyImage(); 4060 this.showMenu = false; 4061 }) 4062 MenuItem({ 4063 content: 'Cut', 4064 }) 4065 .width(100) 4066 .height(50) 4067 .onClick(() => { 4068 this.result?.cut(); 4069 this.showMenu = false; 4070 }) 4071 MenuItem({ 4072 content: 'Copy', 4073 }) 4074 .width(100) 4075 .height(50) 4076 .onClick(() => { 4077 this.result?.copy(); 4078 this.showMenu = false; 4079 }) 4080 MenuItem({ 4081 content: 'Paste', 4082 }) 4083 .width(100) 4084 .height(50) 4085 .onClick(() => { 4086 this.result?.paste(); 4087 this.showMenu = false; 4088 }) 4089 MenuItem({ 4090 content: 'Copy Link', 4091 }) 4092 .width(100) 4093 .height(50) 4094 .onClick(() => { 4095 let pasteData = pasteboard.createData('text/plain', this.linkUrl); 4096 pasteboard.getSystemPasteboard().setData(pasteData, (error) => { 4097 if (error) { 4098 return; 4099 } 4100 }) 4101 this.showMenu = false; 4102 }) 4103 MenuItem({ 4104 content: 'Select All', 4105 }) 4106 .width(100) 4107 .height(50) 4108 .onClick(() => { 4109 this.result?.selectAll(); 4110 this.showMenu = false; 4111 }) 4112 } 4113 .width(150) 4114 .height(300) 4115 } 4116 4117 build() { 4118 Column() { 4119 Web({ src: $rawfile("index.html"), controller: this.controller }) 4120 // Trigger a custom dialog box. 4121 .onContextMenuShow((event) => { 4122 if (event) { 4123 this.result = event.result 4124 console.info("x coord = " + event.param.x()); 4125 console.info("link url = " + event.param.getLinkUrl()); 4126 this.linkUrl = event.param.getLinkUrl(); 4127 } 4128 console.info(TAG, `x: ${this.offsetX}, y: ${this.offsetY}`); 4129 this.showMenu = true; 4130 this.offsetX = 250; 4131 this.offsetY = Math.max(px2vp(event?.param.y() ?? 0) - 0, 0); 4132 return true; 4133 }) 4134 .bindPopup(this.showMenu, 4135 { 4136 builder: this.MenuBuilder(), 4137 enableArrow: false, 4138 placement: Placement.LeftTop, 4139 offset: { x: this.offsetX, y: this.offsetY }, 4140 mask: false, 4141 onStateChange: (e) => { 4142 if (!e.isVisible) { 4143 this.showMenu = false; 4144 this.result!.closeContextMenu(); 4145 } 4146 } 4147 }) 4148 } 4149 } 4150 } 4151 ``` 4152 4153 HTML file to be loaded: 4154 ```html 4155 <!-- index.html --> 4156 <!DOCTYPE html> 4157 <html lang="en"> 4158 <body> 4159 <h1>onContextMenuShow</h1> 4160 <a href="http://www.example.com" style="font-size:27px">URL www.example.com</a> 4161 // Place any image in the rawfile directory and name it example.png. 4162 <div><img src="example.png"></div> 4163 <p>Right-click text to display the context menu</p> 4164 </body> 4165 </html> 4166 ``` 4167 4168### onContextMenuHide<sup>11+</sup> 4169 4170onContextMenuHide(callback: OnContextMenuHideCallback) 4171 4172Called when a context menu is hidden after the user clicks the right mouse button or long presses a specific element, such as an image or a link. 4173 4174**Parameters** 4175 4176| Name | Type | Description | 4177| ------ | ---------------------------------------- | ----------- | 4178| callback | [OnContextMenuHideCallback](#oncontextmenuhidecallback11) | Parameters related to the context menu. | 4179 4180**Example** 4181 4182 ```ts 4183 // xxx.ets 4184 import { webview } from '@kit.ArkWeb'; 4185 4186 @Entry 4187 @Component 4188 struct WebComponent { 4189 controller: webview.WebviewController = new webview.WebviewController(); 4190 4191 build() { 4192 Column() { 4193 Web({ src: 'www.example.com', controller: this.controller }) 4194 .onContextMenuHide(() => { 4195 console.log("onContextMenuHide callback"); 4196 }) 4197 } 4198 } 4199 } 4200 ``` 4201 4202### onScroll<sup>9+</sup> 4203 4204onScroll(callback: Callback\<OnScrollEvent\>): WebAttribute; 4205 4206Called when the scrollbar of the page scrolls. 4207 4208**Parameters** 4209 4210| Name | Type | Description | 4211| ------- | ------ | ---------------------- | 4212| callback | Callback\<[OnScrollEvent](#onscrollevent12)\> | Callback invoked when the scrollbar scrolls to a specified position.| 4213 4214**Example** 4215 4216 ```ts 4217 // xxx.ets 4218 import { webview } from '@kit.ArkWeb'; 4219 4220 @Entry 4221 @Component 4222 struct WebComponent { 4223 controller: webview.WebviewController = new webview.WebviewController(); 4224 4225 build() { 4226 Column() { 4227 Web({ src: 'www.example.com', controller: this.controller }) 4228 .onScroll((event) => { 4229 console.info("x = " + event.xOffset); 4230 console.info("y = " + event.yOffset); 4231 }) 4232 } 4233 } 4234 } 4235 ``` 4236 4237### onGeolocationShow 4238 4239onGeolocationShow(callback: Callback\<OnGeolocationShowEvent\>) 4240 4241Called when a request to obtain the geolocation information is received. 4242 4243**Parameters** 4244 4245| Name | Type | Description | 4246| ----------- | ------------------------------- | -------------- | 4247| callback | Callback\<[OnGeolocationShowEvent](#ongeolocationshowevent12)\> | Callback invoked when a request to obtain the geolocation information is received. | 4248 4249**Example** 4250 4251 ```ts 4252 // xxx.ets 4253 import { webview } from '@kit.ArkWeb'; 4254 4255 @Entry 4256 @Component 4257 struct WebComponent { 4258 controller: webview.WebviewController = new webview.WebviewController(); 4259 4260 build() { 4261 Column() { 4262 Web({ src: $rawfile('index.html'), controller: this.controller }) 4263 .geolocationAccess(true) 4264 .onGeolocationShow((event) => { 4265 if (event) { 4266 AlertDialog.show({ 4267 title: 'title', 4268 message: 'text', 4269 confirm: { 4270 value: 'onConfirm', 4271 action: () => { 4272 event.geolocation.invoke(event.origin, true, true); 4273 } 4274 }, 4275 cancel: () => { 4276 event.geolocation.invoke(event.origin, false, true); 4277 } 4278 }) 4279 } 4280 }) 4281 } 4282 } 4283 } 4284 ``` 4285 4286 HTML file to be loaded: 4287 ```html 4288 <!DOCTYPE html> 4289 <html> 4290 <body> 4291 <p id="locationInfo">Location information</p> 4292 <button onclick="getLocation()">Get Location</button> 4293 <script> 4294 var locationInfo=document.getElementById("locationInfo"); 4295 function getLocation(){ 4296 if (navigator.geolocation) { 4297 <!-- Access to the device location by the frontend page --> 4298 navigator.geolocation.getCurrentPosition(showPosition); 4299 } 4300 } 4301 function showPosition(position){ 4302 locationInfo.innerHTML="Latitude: " + position.coords.latitude + "<br />Longitude: " + position.coords.longitude; 4303 } 4304 </script> 4305 </body> 4306 </html> 4307 ``` 4308 4309### onGeolocationHide 4310 4311onGeolocationHide(callback: () => void) 4312 4313Called to notify the user that the request for obtaining the geolocation information received when [onGeolocationShow](#ongeolocationshow) is called has been canceled. 4314 4315**Parameters** 4316 4317| Name | Type | Description | 4318| -------- | ---------- | -------------------- | 4319| callback | () => void | Callback invoked when the request for obtaining geolocation information has been canceled. | 4320 4321**Example** 4322 4323 ```ts 4324 // xxx.ets 4325 import { webview } from '@kit.ArkWeb'; 4326 4327 @Entry 4328 @Component 4329 struct WebComponent { 4330 controller: webview.WebviewController = new webview.WebviewController(); 4331 4332 build() { 4333 Column() { 4334 Web({ src: 'www.example.com', controller: this.controller }) 4335 .geolocationAccess(true) 4336 .onGeolocationHide(() => { 4337 console.log("onGeolocationHide..."); 4338 }) 4339 } 4340 } 4341 } 4342 ``` 4343 4344### onFullScreenEnter<sup>9+</sup> 4345 4346onFullScreenEnter(callback: OnFullScreenEnterCallback) 4347 4348Called when the **Web** component enters full screen mode. 4349 4350**Parameters** 4351 4352| Name | Type | Description | 4353| ------- | ---------------------------------------- | -------------- | 4354| callback | [OnFullScreenEnterCallback](#onfullscreenentercallback12) | Callback invoked when the **Web** component enters full screen mode.| 4355 4356**Example** 4357 4358 ```ts 4359 // xxx.ets 4360 import { webview } from '@kit.ArkWeb'; 4361 4362 @Entry 4363 @Component 4364 struct WebComponent { 4365 controller: webview.WebviewController = new webview.WebviewController(); 4366 handler: FullScreenExitHandler | null = null; 4367 4368 build() { 4369 Column() { 4370 Web({ src: 'www.example.com', controller: this.controller }) 4371 .onFullScreenEnter((event) => { 4372 console.log("onFullScreenEnter videoWidth: " + event.videoWidth + 4373 ", videoHeight: " + event.videoHeight); 4374 // The application can proactively exit fullscreen mode by calling this.handler.exitFullScreen(). 4375 this.handler = event.handler; 4376 }) 4377 } 4378 } 4379 } 4380 ``` 4381 4382### onFullScreenExit<sup>9+</sup> 4383 4384onFullScreenExit(callback: () => void) 4385 4386Called when the **Web** component exits full screen mode. 4387 4388**Parameters** 4389 4390| Name | Type | Description | 4391| -------- | ---------- | ------------- | 4392| callback | () => void | Callback invoked when the component exits full screen mode.| 4393 4394**Example** 4395 4396 ```ts 4397 // xxx.ets 4398 import { webview } from '@kit.ArkWeb'; 4399 4400 @Entry 4401 @Component 4402 struct WebComponent { 4403 controller: webview.WebviewController = new webview.WebviewController(); 4404 handler: FullScreenExitHandler | null = null; 4405 4406 build() { 4407 Column() { 4408 Web({ src: 'www.example.com', controller: this.controller }) 4409 .onFullScreenExit(() => { 4410 console.log("onFullScreenExit...") 4411 if (this.handler) { 4412 this.handler.exitFullScreen(); 4413 } 4414 }) 4415 .onFullScreenEnter((event) => { 4416 this.handler = event.handler; 4417 }) 4418 } 4419 } 4420 } 4421 ``` 4422 4423### onWindowNew<sup>9+</sup> 4424 4425onWindowNew(callback: Callback\<OnWindowNewEvent\>) 4426 4427Called to notify the user of a new window creation request, when **multiWindowAccess** is enabled. 4428If the **event.handler.setWebController** API is not called, the render process will be blocked. 4429If opening a new window is not needed, set the parameter to **null** when calling the **event.handler.setWebController** API. 4430 4431The new window should not cover the original **Web** component, otherwise, users may be misled to other websites. If the application displays the URL of the home page, ensure that the URL of the new window is displayed in a similar way. Otherwise, new windows should be prohibited. 4432 4433Note that there is no reliable method to determine which page requests a new window. The request may be from a third-party iframe. 4434 4435**Parameters** 4436 4437| Name | Type | Description | 4438| ------------- | ---------------------------------------- | ----------------------------- | 4439| callback | Callback\<[OnWindowNewEvent](#onwindownewevent12)\> | Callback invoked when the web page requests the user to create a new window. | 4440 4441**Example** 4442 4443 ```ts 4444 // xxx.ets 4445 import { webview } from '@kit.ArkWeb'; 4446 4447 // There are two **Web** components on the same page. When the **Web** component opens a new window, **NewWebViewComp** is displayed. 4448 @CustomDialog 4449 struct NewWebViewComp { 4450 controller?: CustomDialogController; 4451 webviewController1: webview.WebviewController = new webview.WebviewController(); 4452 4453 build() { 4454 Column() { 4455 Web({ src: "", controller: this.webviewController1 }) 4456 .javaScriptAccess(true) 4457 .multiWindowAccess(false) 4458 .onWindowExit(() => { 4459 console.info("NewWebViewComp onWindowExit"); 4460 if (this.controller) { 4461 this.controller.close(); 4462 } 4463 }) 4464 } 4465 } 4466 } 4467 4468 @Entry 4469 @Component 4470 struct WebComponent { 4471 controller: webview.WebviewController = new webview.WebviewController(); 4472 dialogController: CustomDialogController | null = null; 4473 4474 build() { 4475 Column() { 4476 Web({ src: 'www.example.com', controller: this.controller }) 4477 .javaScriptAccess(true) 4478 // MultiWindowAccess needs to be enabled. 4479 .multiWindowAccess(true) 4480 .allowWindowOpenMethod(true) 4481 .onWindowNew((event) => { 4482 if (this.dialogController) { 4483 this.dialogController.close(); 4484 } 4485 let popController: webview.WebviewController = new webview.WebviewController(); 4486 this.dialogController = new CustomDialogController({ 4487 builder: NewWebViewComp({ webviewController1: popController }) 4488 }) 4489 this.dialogController.open(); 4490 // Return the WebviewController object corresponding to the new window to the <Web> kernel. 4491 // If opening a new window is not needed, set the parameter to null when calling the event.handler.setWebController API. 4492 // If the event.handler.setWebController API is not called, the render process will be blocked. 4493 event.handler.setWebController(popController); 4494 }) 4495 } 4496 } 4497 } 4498 ``` 4499 4500### onWindowExit<sup>9+</sup> 4501 4502onWindowExit(callback: () => void) 4503 4504Called when this window is closed. This API works in the same way as [onWindowNew](#onwindownew9). For security, applications should notify users that the pages they interact with are closed. 4505 4506**Parameters** 4507 4508| Name | Type | Description | 4509| -------- | ---------- | ------------ | 4510| callback | () => void | Callback invoked when the window is closed.| 4511 4512**Example** 4513 4514 ```ts 4515 // xxx.ets 4516 import { webview } from '@kit.ArkWeb'; 4517 4518 @Entry 4519 @Component 4520 struct WebComponent { 4521 controller: webview.WebviewController = new webview.WebviewController(); 4522 4523 build() { 4524 Column() { 4525 Web({ src: 'www.example.com', controller: this.controller }) 4526 .onWindowExit(() => { 4527 console.log("onWindowExit..."); 4528 }) 4529 } 4530 } 4531 } 4532 ``` 4533 4534### onSearchResultReceive<sup>9+</sup> 4535 4536onSearchResultReceive(callback: Callback\<OnSearchResultReceiveEvent\>) 4537 4538Called to notify the caller of the search result on the web page. 4539 4540**Parameters** 4541 4542| Name | Type | Description | 4543| ------------------ | ------- | ---------------------------------------- | 4544| callback | Callback\<[OnSearchResultReceiveEvent](#onsearchresultreceiveevent12)\> | Callback invoked to notify the caller of the search result on the web page. | 4545 4546**Example** 4547 4548 ```ts 4549 // xxx.ets 4550 import { webview } from '@kit.ArkWeb'; 4551 4552 @Entry 4553 @Component 4554 struct WebComponent { 4555 controller: webview.WebviewController = new webview.WebviewController(); 4556 4557 build() { 4558 Column() { 4559 Web({ src: 'www.example.com', controller: this.controller }) 4560 .onSearchResultReceive(ret => { 4561 if (ret) { 4562 console.log("on search result receive:" + "[cur]" + ret.activeMatchOrdinal + 4563 "[total]" + ret.numberOfMatches + "[isDone]" + ret.isDoneCounting); 4564 } 4565 }) 4566 } 4567 } 4568 } 4569 ``` 4570 4571### onDataResubmitted<sup>9+</sup> 4572 4573onDataResubmitted(callback: Callback\<OnDataResubmittedEvent\>) 4574 4575Called when the web form data can be resubmitted. 4576 4577**Parameters** 4578 4579| Name | Type | Description | 4580| ------- | ---------------------------------------- | ----------- | 4581| callback | Callback\<[OnDataResubmittedEvent](#ondataresubmittedevent12)\> | Callback invoked when the web form data can be resubmitted.| 4582 4583**Example** 4584 4585 ```ts 4586 // xxx.ets 4587 import { webview } from '@kit.ArkWeb'; 4588 import { BusinessError } from '@kit.BasicServicesKit'; 4589 4590 @Entry 4591 @Component 4592 struct WebComponent { 4593 controller: webview.WebviewController = new webview.WebviewController(); 4594 4595 build() { 4596 Column() { 4597 // After you click Submit on the web page, you can click Refresh to trigger the function again. 4598 Button('refresh') 4599 .onClick(() => { 4600 try { 4601 this.controller.refresh(); 4602 } catch (error) { 4603 console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); 4604 } 4605 }) 4606 Web({ src: $rawfile('index.html'), controller: this.controller }) 4607 .onDataResubmitted((event) => { 4608 console.log('onDataResubmitted'); 4609 event.handler.resend(); 4610 }) 4611 } 4612 } 4613 } 4614 ``` 4615 4616 HTML file to be loaded: 4617 ```html 4618 <!-- index.html --> 4619 <!DOCTYPE html> 4620 <html> 4621 <head> 4622 <meta charset="utf-8"> 4623 </head> 4624 <body> 4625 <form action="http://httpbin.org/post" method="post"> 4626 <input type="text" name="username"> 4627 <input type="submit" name="Submit"> 4628 </form> 4629 </body> 4630 </html> 4631 ``` 4632 4633### onPageVisible<sup>9+</sup> 4634 4635onPageVisible(callback: Callback\<OnPageVisibleEvent\>) 4636 4637Called when the old page is not displayed and the new page is about to be visible. 4638 4639For details about the component lifecycle, see [Lifecycle of Web Components](../../web/web-event-sequence.md). 4640 4641**Parameters** 4642 4643| Name | Type | Description | 4644| ---- | ------ | -------------------------- | 4645| callback | Callback\<[OnPageVisibleEvent](#onpagevisibleevent12)\> | Callback invoked when the old page is not displayed and the new page is about to be visible.| 4646 4647**Example** 4648 4649 ```ts 4650 // xxx.ets 4651 import { webview } from '@kit.ArkWeb'; 4652 4653 @Entry 4654 @Component 4655 struct WebComponent { 4656 controller: webview.WebviewController = new webview.WebviewController(); 4657 4658 build() { 4659 Column() { 4660 Web({ src: 'www.example.com', controller: this.controller }) 4661 .onPageVisible((event) => { 4662 console.log('onPageVisible url:' + event.url); 4663 }) 4664 } 4665 } 4666 } 4667 ``` 4668 4669### onInterceptKeyEvent<sup>9+</sup> 4670 4671onInterceptKeyEvent(callback: (event: KeyEvent) => boolean) 4672 4673Called when the key event is intercepted and before it is consumed by the webview. 4674 4675**Parameters** 4676 4677| Name | Type | Description | 4678| ----- | ---------------------------------------- | -------------- | 4679| event | [KeyEvent](../apis-arkui/arkui-ts/ts-universal-events-key.md#keyevent) | Key event that is triggered.| 4680 4681**Return value** 4682 4683| Type | Description | 4684| ------- | ---------------------------------------- | 4685| boolean | Whether to continue to transfer the key event to the webview kernel.| 4686 4687**Example** 4688 4689 ```ts 4690 // xxx.ets 4691 import { webview } from '@kit.ArkWeb'; 4692 4693 @Entry 4694 @Component 4695 struct WebComponent { 4696 controller: webview.WebviewController = new webview.WebviewController(); 4697 4698 build() { 4699 Column() { 4700 Web({ src: 'www.example.com', controller: this.controller }) 4701 .onInterceptKeyEvent((event) => { 4702 if (event.keyCode == 2017 || event.keyCode == 2018) { 4703 console.info(`onInterceptKeyEvent get event.keyCode ${event.keyCode}`); 4704 return true; 4705 } 4706 return false; 4707 }) 4708 } 4709 } 4710 } 4711 ``` 4712 4713### onTouchIconUrlReceived<sup>9+</sup> 4714 4715onTouchIconUrlReceived(callback: Callback\<OnTouchIconUrlReceivedEvent\>) 4716 4717Called when an apple-touch-icon URL is received. 4718 4719**Parameters** 4720 4721| Name | Type | Description | 4722| ----------- | ------- | --------------------------- | 4723| callback | Callback\<[OnTouchIconUrlReceivedEvent](#ontouchiconurlreceivedevent12)\> | Callback invoked when an apple-touch-icon URL is received.| 4724 4725**Example** 4726 4727 ```ts 4728 // xxx.ets 4729 import { webview } from '@kit.ArkWeb'; 4730 4731 @Entry 4732 @Component 4733 struct WebComponent { 4734 controller: webview.WebviewController = new webview.WebviewController(); 4735 4736 build() { 4737 Column() { 4738 Web({ src: 'www.baidu.com', controller: this.controller }) 4739 .onTouchIconUrlReceived((event) => { 4740 console.log('onTouchIconUrlReceived:' + JSON.stringify(event)); 4741 }) 4742 } 4743 } 4744 } 4745 ``` 4746 4747### onFaviconReceived<sup>9+</sup> 4748 4749onFaviconReceived(callback: Callback\<OnFaviconReceivedEvent\>) 4750 4751Called when this web page receives a new favicon. 4752 4753**Parameters** 4754 4755| Name | Type | Description | 4756| ------- | ---------------------------------------- | ------------------------- | 4757| callback | Callback\<[OnFaviconReceivedEvent](#onfaviconreceivedevent12)\> | Callback invoked when the current web page receives a new favicon.| 4758 4759**Example** 4760 4761 ```ts 4762 // xxx.ets 4763 import { webview } from '@kit.ArkWeb'; 4764 import { image } from '@kit.ImageKit'; 4765 4766 @Entry 4767 @Component 4768 struct WebComponent { 4769 controller: webview.WebviewController = new webview.WebviewController(); 4770 @State icon: image.PixelMap | undefined = undefined; 4771 4772 build() { 4773 Column() { 4774 Web({ src: 'www.example.com', controller: this.controller }) 4775 .onFaviconReceived((event) => { 4776 console.log('onFaviconReceived'); 4777 this.icon = event.favicon; 4778 }) 4779 } 4780 } 4781 } 4782 ``` 4783 4784### onAudioStateChanged<sup>10+</sup> 4785 4786onAudioStateChanged(callback: Callback\<OnAudioStateChangedEvent\>) 4787 4788Called when the audio playback status on the web page changes. 4789 4790**Parameters** 4791 4792| Name | Type | Description | 4793| ------- | ------- | ---------------------------------- | 4794| callback | Callback\<[OnAudioStateChangedEvent](#onaudiostatechangedevent12)\> | Callback invoked when the audio playback status on the web page changes.| 4795 4796**Example** 4797 4798 ```ts 4799 // xxx.ets 4800 import { webview } from '@kit.ArkWeb'; 4801 4802 @Entry 4803 @Component 4804 struct WebComponent { 4805 controller: webview.WebviewController = new webview.WebviewController(); 4806 @State playing: boolean = false; 4807 4808 build() { 4809 Column() { 4810 Web({ src: 'www.example.com', controller: this.controller }) 4811 .onAudioStateChanged(event => { 4812 this.playing = event.playing; 4813 console.debug('onAudioStateChanged playing: ' + this.playing); 4814 }) 4815 } 4816 } 4817 } 4818 ``` 4819 4820### onFirstContentfulPaint<sup>10+</sup> 4821 4822 onFirstContentfulPaint(callback: Callback\<OnFirstContentfulPaintEvent\>) 4823 4824Called when the first content paint occurs on the web page. 4825 4826**Parameters** 4827 4828| Name | Type | Description | 4829| ---------------------- | ------ | --------------------------------- | 4830| callback | Callback\<[OnFirstContentfulPaintEvent](#onfirstcontentfulpaintevent12)\> | Callback invoked when the first content paint occurs on the web page. | 4831 4832**Example** 4833 4834 ```ts 4835 // xxx.ets 4836 import { webview } from '@kit.ArkWeb'; 4837 4838 @Entry 4839 @Component 4840 struct WebComponent { 4841 controller: webview.WebviewController = new webview.WebviewController(); 4842 4843 build() { 4844 Column() { 4845 Web({ src: 'www.example.com', controller: this.controller }) 4846 .onFirstContentfulPaint(event => { 4847 if (event) { 4848 console.log("onFirstContentfulPaint:" + "[navigationStartTick]:" + 4849 event.navigationStartTick + ", [firstContentfulPaintMs]:" + 4850 event.firstContentfulPaintMs); 4851 } 4852 }) 4853 } 4854 } 4855 } 4856 ``` 4857 4858### onFirstMeaningfulPaint<sup>12+</sup> 4859 4860onFirstMeaningfulPaint(callback: [OnFirstMeaningfulPaintCallback](#onfirstmeaningfulpaintcallback12)) 4861 4862Called when the first meaningful paint occurs on the web page. 4863 4864**Parameters** 4865 4866| Name | Type | Description | 4867| -------- | ------------------------------------------------------------ | -------------------------------------- | 4868| callback | [OnFirstMeaningfulPaintCallback](#onfirstmeaningfulpaintcallback12) | Callback invoked when the First Meaningful Paint occurs on the web page.| 4869 4870**Example** 4871 4872 ```ts 4873 // xxx.ets 4874 import { webview } from '@kit.ArkWeb'; 4875 4876 @Entry 4877 @Component 4878 struct WebComponent { 4879 controller: webview.WebviewController = new webview.WebviewController(); 4880 4881 build() { 4882 Column() { 4883 Web({ src: 'www.example.com', controller: this.controller }) 4884 .onFirstMeaningfulPaint((details) => { 4885 console.log("onFirstMeaningfulPaint: [navigationStartTime]= " + details.navigationStartTime + 4886 ", [firstMeaningfulPaintTime]=" + details.firstMeaningfulPaintTime); 4887 }) 4888 } 4889 } 4890 } 4891 ``` 4892 4893### onLargestContentfulPaint<sup>12+</sup> 4894 4895onLargestContentfulPaint(callback: [OnLargestContentfulPaintCallback](#onlargestcontentfulpaintcallback12)) 4896 4897Called when the largest content paint occurs on the web page. 4898 4899**Parameters** 4900 4901| Name | Type | Description | 4902| -------- | ------------------------------------------------------------ | ------------------------------------ | 4903| callback | [OnLargestContentfulPaintCallback](#onlargestcontentfulpaintcallback12) | Callback invoked when the largest content paint occurs on the web page.| 4904 4905**Example** 4906 4907 ```ts 4908 // xxx.ets 4909 import { webview } from '@kit.ArkWeb'; 4910 4911 @Entry 4912 @Component 4913 struct WebComponent { 4914 controller: webview.WebviewController = new webview.WebviewController(); 4915 4916 build() { 4917 Column() { 4918 Web({ src: 'www.example.com', controller: this.controller }) 4919 .onLargestContentfulPaint((details) => { 4920 console.log("onLargestContentfulPaint: [navigationStartTime]= " + details.navigationStartTime + 4921 ", [largestImagePaintTime]=" + details.largestImagePaintTime + 4922 ", [largestTextPaintTime]=" + details.largestTextPaintTime + 4923 ", [largestImageLoadStartTime]=" + details.largestImageLoadStartTime + 4924 ", [largestImageLoadEndTime]=" + details.largestImageLoadEndTime + 4925 ", [imageBPP]=" + details.imageBPP); 4926 }) 4927 } 4928 } 4929 } 4930 ``` 4931 4932### onLoadIntercept<sup>10+</sup> 4933 4934onLoadIntercept(callback: Callback\<OnLoadInterceptEvent, boolean\>) 4935 4936Called when the **Web** component is about to access a URL. This API is used to determine whether to block the access, which is allowed by default. 4937 4938**Parameters** 4939 4940| Name | Type | Description | 4941| ------- | ---------------------------------------- | ----------- | 4942| callback | Callback\<[OnLoadInterceptEvent](#onloadinterceptevent12), boolean\> | Callback invoked when the **Web** component is about to access a URL.<br>Return value: boolean<br> Returns **true** if the access is blocked; returns **false** otherwise.| 4943 4944**Example** 4945 4946 ```ts 4947 // xxx.ets 4948 import { webview } from '@kit.ArkWeb'; 4949 4950 @Entry 4951 @Component 4952 struct WebComponent { 4953 controller: webview.WebviewController = new webview.WebviewController(); 4954 4955 build() { 4956 Column() { 4957 Web({ src: 'www.example.com', controller: this.controller }) 4958 .onLoadIntercept((event) => { 4959 console.log('url:' + event.data.getRequestUrl()); 4960 console.log('isMainFrame:' + event.data.isMainFrame()); 4961 console.log('isRedirect:' + event.data.isRedirect()); 4962 console.log('isRequestGesture:' + event.data.isRequestGesture()); 4963 return true; 4964 }) 4965 } 4966 } 4967 } 4968 ``` 4969 4970### onRequestSelected 4971 4972onRequestSelected(callback: () => void) 4973 4974Called when the **Web** component obtains the focus. 4975 4976**Example** 4977 4978 ```ts 4979 // xxx.ets 4980 import { webview } from '@kit.ArkWeb'; 4981 4982 @Entry 4983 @Component 4984 struct WebComponent { 4985 controller: webview.WebviewController = new webview.WebviewController(); 4986 4987 build() { 4988 Column() { 4989 Web({ src: 'www.example.com', controller: this.controller }) 4990 .onRequestSelected(() => { 4991 console.log('onRequestSelected'); 4992 }) 4993 } 4994 } 4995 } 4996 ``` 4997### onScreenCaptureRequest<sup>10+</sup> 4998 4999onScreenCaptureRequest(callback: Callback\<OnScreenCaptureRequestEvent\>) 5000 5001Called when a screen capture request is received. 5002 5003**Parameters** 5004 5005| Name | Type | Description | 5006| ------- | ---------------------------------------- | -------------- | 5007| callback | Callback\<[OnScreenCaptureRequestEvent](#onscreencapturerequestevent12)\> | Called when a screen capture request is received.| 5008 5009**Example** 5010 5011 ```ts 5012 // xxx.ets 5013 import { webview } from '@kit.ArkWeb'; 5014 5015 @Entry 5016 @Component 5017 struct WebComponent { 5018 controller: webview.WebviewController = new webview.WebviewController(); 5019 5020 build() { 5021 Column() { 5022 Web({ src: 'www.example.com', controller: this.controller }) 5023 .onScreenCaptureRequest((event) => { 5024 if (event) { 5025 AlertDialog.show({ 5026 title: 'title: ' + event.handler.getOrigin(), 5027 message: 'text', 5028 primaryButton: { 5029 value: 'deny', 5030 action: () => { 5031 event.handler.deny(); 5032 } 5033 }, 5034 secondaryButton: { 5035 value: 'onConfirm', 5036 action: () => { 5037 event.handler.grant({ captureMode: WebCaptureMode.HOME_SCREEN }); 5038 } 5039 }, 5040 cancel: () => { 5041 event.handler.deny(); 5042 } 5043 }) 5044 } 5045 }) 5046 } 5047 } 5048 } 5049 ``` 5050 5051### onOverScroll<sup>10+</sup> 5052 5053onOverScroll(callback: Callback\<OnOverScrollEvent\>) 5054 5055Called when the web page is overscrolled. It is used to notify the user of the offset of the overscroll. 5056 5057**Parameters** 5058 5059| Name | Type | Description | 5060| ------- | ------ | ------------------- | 5061| callback | Callback\<[OnOverScrollEvent](#onoverscrollevent12)\> | Callback invoked when the web page is overscrolled.| 5062 5063**Example** 5064 5065 ```ts 5066 // xxx.ets 5067 import { webview } from '@kit.ArkWeb'; 5068 5069 @Entry 5070 @Component 5071 struct WebComponent { 5072 controller: webview.WebviewController = new webview.WebviewController(); 5073 5074 build() { 5075 Column() { 5076 Web({ src: 'www.example.com', controller: this.controller }) 5077 .onOverScroll((event) => { 5078 console.info("x = " + event.xOffset); 5079 console.info("y = " + event.yOffset); 5080 }) 5081 } 5082 } 5083 } 5084 ``` 5085 5086### onControllerAttached<sup>10+</sup> 5087 5088onControllerAttached(callback: () => void) 5089 5090Called when the controller is successfully bound to the **Web** component. The controller must be WebviewController. 5091As the web page is not yet loaded when this callback is called, APIs for operating the web page, for example, [zoomIn](js-apis-webview.md#zoomin) and [zoomOut](js-apis-webview.md#zoomout), cannot be used in the callback. Other APIs, such as [loadUrl](js-apis-webview.md#loadurl) and [getWebId](js-apis-webview.md#getwebid), which do not involve web page operations, can be used properly. 5092 5093For details about the component lifecycle, see [Lifecycle of Web Components](../../web/web-event-sequence.md). 5094 5095**Example** 5096 5097The following example uses **loadUrl** in the callback to load the web page. 5098 ```ts 5099 // xxx.ets 5100 import { webview } from '@kit.ArkWeb'; 5101 5102 @Entry 5103 @Component 5104 struct WebComponent { 5105 controller: webview.WebviewController = new webview.WebviewController(); 5106 5107 build() { 5108 Column() { 5109 Web({ src: '', controller: this.controller }) 5110 .onControllerAttached(() => { 5111 this.controller.loadUrl($rawfile("index.html")); 5112 }) 5113 } 5114 } 5115 } 5116 ``` 5117 5118The following example uses **getWebId** in the callback 5119 ```ts 5120 // xxx.ets 5121 import { webview } from '@kit.ArkWeb'; 5122 import { BusinessError } from '@kit.BasicServicesKit'; 5123 5124 @Entry 5125 @Component 5126 struct WebComponent { 5127 controller: webview.WebviewController = new webview.WebviewController(); 5128 5129 build() { 5130 Column() { 5131 Web({ src: $rawfile("index.html"), controller: this.controller }) 5132 .onControllerAttached(() => { 5133 try { 5134 let id = this.controller.getWebId(); 5135 console.log("id: " + id); 5136 } catch (error) { 5137 let code = (error as BusinessError).code; 5138 let message = (error as BusinessError).message; 5139 console.error(`ErrorCode: ${code}, Message: ${message}`); 5140 } 5141 }) 5142 } 5143 } 5144 } 5145 ``` 5146 HTML file to be loaded: 5147 ```html 5148 <!-- index.html --> 5149 <!DOCTYPE html> 5150 <html> 5151 <body> 5152 <p>Hello World</p> 5153 </body> 5154 </html> 5155 ``` 5156 5157### onNavigationEntryCommitted<sup>11+</sup> 5158 5159onNavigationEntryCommitted(callback: [OnNavigationEntryCommittedCallback](#onnavigationentrycommittedcallback11)) 5160 5161Called when a web page redirection request is submitted. 5162 5163**Parameters** 5164 5165| Name | Type | Description | 5166| -------------- | --------------------------------------------------------------------------- | ---------------------- | 5167| callback | [OnNavigationEntryCommittedCallback](#onnavigationentrycommittedcallback11) | Callback invoked when a web page redirection request is submitted.| 5168 5169**Example** 5170 5171 ```ts 5172 // xxx.ets 5173 import { webview } from '@kit.ArkWeb'; 5174 5175 @Entry 5176 @Component 5177 struct WebComponent { 5178 controller: webview.WebviewController = new webview.WebviewController(); 5179 5180 build() { 5181 Column() { 5182 Web({ src: 'www.example.com', controller: this.controller }) 5183 .onNavigationEntryCommitted((details) => { 5184 console.log("onNavigationEntryCommitted: [isMainFrame]= " + details.isMainFrame + 5185 ", [isSameDocument]=" + details.isSameDocument + 5186 ", [didReplaceEntry]=" + details.didReplaceEntry + 5187 ", [navigationType]=" + details.navigationType + 5188 ", [url]=" + details.url); 5189 }) 5190 } 5191 } 5192 } 5193 ``` 5194 5195### onSafeBrowsingCheckResult<sup>11+</sup> 5196 5197onSafeBrowsingCheckResult(callback: OnSafeBrowsingCheckResultCallback) 5198 5199Called when the safe browsing check result is received. 5200 5201**Parameters** 5202 5203| Name | Type | Description | 5204| ----------| --------------------------------------------------------------------------| ---------------------- | 5205| callback | [OnSafeBrowsingCheckResultCallback](#onsafebrowsingcheckresultcallback11) | Called when the safe browsing check result is received.| 5206 5207**Example** 5208 5209 ```ts 5210 // xxx.ets 5211 import { webview } from '@kit.ArkWeb'; 5212 5213 export enum ThreatType { 5214 UNKNOWN = -1, 5215 THREAT_ILLEGAL = 0, 5216 THREAT_FRAUD = 1, 5217 THREAT_RISK = 2, 5218 THREAT_WARNING = 3, 5219 } 5220 5221 export class OnSafeBrowsingCheckResultCallback { 5222 threatType: ThreatType = ThreatType.UNKNOWN; 5223 } 5224 5225 @Entry 5226 @Component 5227 struct WebComponent { 5228 controller: webview.WebviewController = new webview.WebviewController(); 5229 5230 build() { 5231 Column() { 5232 Web({ src: 'www.example.com', controller: this.controller }) 5233 .onSafeBrowsingCheckResult((callback) => { 5234 let jsonData = JSON.stringify(callback); 5235 let json: OnSafeBrowsingCheckResultCallback = JSON.parse(jsonData); 5236 console.log("onSafeBrowsingCheckResult: [threatType]= " + json.threatType); 5237 }) 5238 } 5239 } 5240 } 5241 ``` 5242 5243### onNativeEmbedLifecycleChange<sup>11+</sup> 5244 5245onNativeEmbedLifecycleChange(callback: NativeEmbedDataInfo) 5246 5247Called when the lifecycle of the Embed tag changes. 5248 5249**Parameters** 5250 5251| Name | Type | Description | 5252| -------------- | --------------------------------------------------------------------------- | ---------------------- | 5253| event | [NativeEmbedDataInfo](#nativeembeddatainfo11) | Callback invoked when the lifecycle of the Embed tag changes.| 5254 5255**Example** 5256 5257```ts 5258// EntryAbility.ets 5259 5260import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; 5261import { hilog } from '@kit.PerformanceAnalysisKit'; 5262import { window } from '@kit.ArkUI'; 5263import { webview } from '@kit.ArkWeb'; 5264 5265export default class EntryAbility extends UIAbility { 5266 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 5267 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); 5268 // Added in API version 12: feature to enable the back/forward cache for same-layer rendering. 5269 let features = new webview.BackForwardCacheSupportedFeatures(); 5270 features.nativeEmbed = true; 5271 features.mediaTakeOver = true; 5272 webview.WebviewController.enableBackForwardCache(features); 5273 webview.WebviewController.initializeWebEngine(); 5274 } 5275 5276 onDestroy(): void { 5277 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); 5278 } 5279 5280 onWindowStageCreate(windowStage: window.WindowStage): void { 5281 // Main window is created, set main page for this ability 5282 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); 5283 5284 windowStage.loadContent('pages/Index', (err) => { 5285 if (err.code) { 5286 hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); 5287 return; 5288 } 5289 hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); 5290 }); 5291 } 5292 5293 onWindowStageDestroy(): void { 5294 // Main window is destroyed, release UI related resources 5295 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); 5296 } 5297 5298 onForeground(): void { 5299 // Ability has brought to foreground 5300 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); 5301 } 5302 5303 onBackground(): void { 5304 // Ability has back to background 5305 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); 5306 } 5307} 5308``` 5309 5310 ```ts 5311 // xxx.ets 5312 import { webview } from '@kit.ArkWeb'; 5313 import { BusinessError } from '@kit.BasicServicesKit'; 5314 5315 @Entry 5316 @Component 5317 struct WebComponent { 5318 @State embedStatus: string = ''; 5319 controller: webview.WebviewController = new webview.WebviewController(); 5320 5321 build() { 5322 Column() { 5323 // Default behavior: Click the button to navigate to a new page, close the index page, and destroy the <Embed> tag. 5324 // Added in API version 12: When BFCache is enabled for the page that supports same-layer rendering, clicking the button navigates to a new page, closes the index page, and puts the <Embed> tag into BFCache. 5325 Button('Destroy') 5326 .onClick(() => { 5327 try { 5328 this.controller.loadUrl("www.example.com"); 5329 } catch (error) { 5330 console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); 5331 } 5332 }) 5333 5334 // Added in API version 12: When BFCache is enabled for the page that supports same-layer rendering, clicking the button to return to the page causes the <Embed> tag to exit BFCache. 5335 Button('backward') 5336 .onClick(() => { 5337 try { 5338 this.controller.backward(); 5339 } catch (error) { 5340 console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); 5341 } 5342 }) 5343 5344 // Added in API version 12: When BFCache is enabled for the page that supports same-layer rendering, clicking a button to advance to the next page causes the <Embed> tag to enter BFCache. 5345 Button('forward') 5346 .onClick(() => { 5347 try { 5348 this.controller.forward(); 5349 } catch (error) { 5350 console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); 5351 } 5352 }) 5353 5354 5355 // Added in API version 12: The Web kernel does not allow web pages loaded with non-HTTP and non-HTTPS protocols to enter BFCache. 5356 // Therefore, to test the ENTER_BFCACHE/LEAVE_BFCACHE states, you need to place the index.html on a web server and load it using the HTTP or HTTPS protocol. Example: 5357 // Web({ src: "http://xxxx/index.html", controller: this.controller }) 5358 Web({ src: $rawfile("index.html"), controller: this.controller }) 5359 .enableNativeEmbedMode(true) 5360 .onNativeEmbedLifecycleChange((event) => { 5361 // The Create event is triggered when the <Embed> tag is detected on the loaded page. 5362 if (event.status == NativeEmbedStatus.CREATE) { 5363 this.embedStatus = 'Create'; 5364 } 5365 // The Update event is triggered when the <Embed> tag on the page is moved or scaled. 5366 if (event.status == NativeEmbedStatus.UPDATE) { 5367 this.embedStatus = 'Update'; 5368 } 5369 // The Destroy event is triggered when you exit the page. 5370 if (event.status == NativeEmbedStatus.DESTROY) { 5371 this.embedStatus = 'Destroy'; 5372 } 5373 // The Enter BFCache event is triggered when the page with the same-layer tag enters BFCache. 5374 if (event.status == NativeEmbedStatus.ENTER_BFCACHE) { 5375 this.embedStatus = 'Enter BFCache'; 5376 } 5377 // The Leave BFCache event is triggered when the page with the same-layer tag leaves BFCache. 5378 if (event.status == NativeEmbedStatus.LEAVE_BFCACHE) { 5379 this.embedStatus = 'Leave BFCache'; 5380 } 5381 console.log("status = " + this.embedStatus); 5382 console.log("surfaceId = " + event.surfaceId); 5383 console.log("embedId = " + event.embedId); 5384 if (event.info) { 5385 console.log("id = " + event.info.id); 5386 console.log("type = " + event.info.type); 5387 console.log("src = " + event.info.src); 5388 console.log("width = " + event.info.width); 5389 console.log("height = " + event.info.height); 5390 console.log("url = " + event.info.url); 5391 } 5392 }) 5393 } 5394 } 5395 } 5396 ``` 5397 5398 HTML file to be loaded: 5399 ``` 5400 <!-- index.html --> 5401 <!Document> 5402 <html> 5403 <head> 5404 <title>Same-layer rendering test HTML</title> 5405 <meta name="viewport"> 5406 </head> 5407 <body> 5408 <div> 5409 <div id="bodyId"> 5410 <embed id="nativeButton" type = "native/button" width="800" height="800" src="test? params1=1?" style = "background-color:red"/> 5411 </div> 5412 </div> 5413 </body> 5414 </html> 5415 ``` 5416 5417### onNativeEmbedGestureEvent<sup>11+</sup> 5418 5419onNativeEmbedGestureEvent(callback: NativeEmbedTouchInfo) 5420 5421Called when a finger touches a same-layer rendering tag. 5422 5423**Parameters** 5424 5425| Name | Type | Description | 5426| -------------- | --------------------------------------------------------------------------- | ---------------------- | 5427| event | [NativeEmbedTouchInfo](#nativeembedtouchinfo11) | Callback invoked when a finger touches a same-layer rendering tag.| 5428 5429**Example** 5430 5431 ```ts 5432 // xxx.ets 5433 import { webview } from '@kit.ArkWeb'; 5434 import { NodeController, BuilderNode, NodeRenderType, FrameNode, UIContext } from "@kit.ArkUI"; 5435 5436 declare class Params { 5437 text: string; 5438 width: number; 5439 height: number; 5440 } 5441 5442 declare class nodeControllerParams { 5443 surfaceId: string; 5444 renderType: NodeRenderType; 5445 width: number; 5446 height: number; 5447 } 5448 5449 class MyNodeController extends NodeController { 5450 private rootNode: BuilderNode<[Params]> | undefined | null; 5451 private surfaceId_: string = ""; 5452 private renderType_: NodeRenderType = NodeRenderType.RENDER_TYPE_DISPLAY; 5453 private width_: number = 0; 5454 private height_: number = 0; 5455 5456 setRenderOption(params: nodeControllerParams) { 5457 this.surfaceId_ = params.surfaceId; 5458 this.renderType_ = params.renderType; 5459 this.width_ = params.width; 5460 this.height_ = params.height; 5461 } 5462 5463 makeNode(uiContext: UIContext): FrameNode | null { 5464 this.rootNode = new BuilderNode(uiContext, { surfaceId: this.surfaceId_, type: this.renderType_ }); 5465 this.rootNode.build(wrapBuilder(ButtonBuilder), { text: "myButton", width: this.width_, height: this.height_ }); 5466 return this.rootNode.getFrameNode(); 5467 } 5468 5469 postEvent(event: TouchEvent | undefined): boolean { 5470 return this.rootNode?.postTouchEvent(event) as boolean; 5471 } 5472 } 5473 5474 @Component 5475 struct ButtonComponent { 5476 @Prop params: Params; 5477 @State bkColor: Color = Color.Red; 5478 5479 build() { 5480 Column() { 5481 Button(this.params.text) 5482 .height(50) 5483 .width(200) 5484 .border({ width: 2, color: Color.Red }) 5485 .backgroundColor(this.bkColor) 5486 5487 } 5488 .width(this.params.width) 5489 .height(this.params.height) 5490 } 5491 } 5492 5493 @Builder 5494 function ButtonBuilder(params: Params) { 5495 ButtonComponent({ params: params }) 5496 .backgroundColor(Color.Green) 5497 } 5498 5499 @Entry 5500 @Component 5501 struct WebComponent { 5502 @State eventType: string = ''; 5503 controller: webview.WebviewController = new webview.WebviewController(); 5504 private nodeController: MyNodeController = new MyNodeController(); 5505 5506 build() { 5507 Column() { 5508 Stack() { 5509 NodeContainer(this.nodeController) 5510 Web({ src: $rawfile("index.html"), controller: this.controller }) 5511 .enableNativeEmbedMode(true) 5512 .onNativeEmbedLifecycleChange((embed) => { 5513 if (embed.status == NativeEmbedStatus.CREATE) { 5514 this.nodeController.setRenderOption({ 5515 surfaceId: embed.surfaceId as string, 5516 renderType: NodeRenderType.RENDER_TYPE_TEXTURE, 5517 width: px2vp(embed.info?.width), 5518 height: px2vp(embed.info?.height) 5519 }); 5520 this.nodeController.rebuild(); 5521 } 5522 }) 5523 .onNativeEmbedGestureEvent((event) => { 5524 if (event && event.touchEvent) { 5525 if (event.touchEvent.type == TouchType.Down) { 5526 this.eventType = 'Down' 5527 } 5528 if (event.touchEvent.type == TouchType.Up) { 5529 this.eventType = 'Up' 5530 } 5531 if (event.touchEvent.type == TouchType.Move) { 5532 this.eventType = 'Move' 5533 } 5534 if (event.touchEvent.type == TouchType.Cancel) { 5535 this.eventType = 'Cancel' 5536 } 5537 let ret = this.nodeController.postEvent(event.touchEvent) 5538 if (event.result) { 5539 event.result.setGestureEventResult(ret); 5540 } 5541 console.log("embedId = " + event.embedId); 5542 console.log("touchType = " + this.eventType); 5543 console.log("x = " + event.touchEvent.touches[0].x); 5544 console.log("y = " + event.touchEvent.touches[0].y); 5545 console.log("Component globalPos:(" + event.touchEvent.target.area.globalPosition.x + "," + event.touchEvent.target.area.globalPosition.y + ")"); 5546 console.log("width = " + event.touchEvent.target.area.width); 5547 console.log("height = " + event.touchEvent.target.area.height); 5548 } 5549 }) 5550 } 5551 } 5552 } 5553 } 5554 ``` 5555HTML file to be loaded: 5556 ``` 5557 <!-- index.html --> 5558 <!Document> 5559<html> 5560<head> 5561 <title>Same-layer rendering test HTML</title> 5562 <meta name="viewport"> 5563</head> 5564<body> 5565<div> 5566 <div id="bodyId"> 5567 <embed id="nativeButton" type = "native/button" width="800" height="800" src="test?params1=1?" style = "background-color:red"/> 5568 </div> 5569</div> 5570</body> 5571</html> 5572 ``` 5573 5574### onIntelligentTrackingPreventionResult<sup>12+</sup> 5575 5576onIntelligentTrackingPreventionResult(callback: OnIntelligentTrackingPreventionCallback) 5577 5578Called when the intelligent tracking prevention feature is enabled and the tracker cookie is blocked. 5579 5580**Parameters** 5581 5582| Name | Type | Description | 5583| ----------- | ------------------------------------------------------------------------------------------- | ---------------------------- | 5584| callback | [OnIntelligentTrackingPreventionCallback](#onintelligenttrackingpreventioncallback12) | Callback invoked when the intelligent tracking prevention feature is enabled and the tracker cookie is blocked.| 5585 5586**Example** 5587 5588 ```ts 5589 // xxx.ets 5590 import { webview } from '@kit.ArkWeb'; 5591 import { BusinessError } from '@kit.BasicServicesKit'; 5592 5593 @Entry 5594 @Component 5595 struct WebComponent { 5596 controller: webview.WebviewController = new webview.WebviewController(); 5597 5598 build() { 5599 Column() { 5600 // The onIntelligentTrackingPreventionResult callback is triggered only when the intelligent tracking prevention is enabled. 5601 Button('enableIntelligentTrackingPrevention') 5602 .onClick(() => { 5603 try { 5604 this.controller.enableIntelligentTrackingPrevention(true); 5605 } catch (error) { 5606 console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); 5607 } 5608 }) 5609 Web({ src: 'www.example.com', controller: this.controller }) 5610 .onIntelligentTrackingPreventionResult((details) => { 5611 console.log("onIntelligentTrackingPreventionResult: [websiteHost]= " + details.host + 5612 ", [trackerHost]=" + details.trackerHost); 5613 }) 5614 } 5615 } 5616 } 5617 ``` 5618 5619### onOverrideUrlLoading<sup>12+</sup> 5620 5621onOverrideUrlLoading(callback: OnOverrideUrlLoadingCallback) 5622 5623Called to enable the host application to obtain control when the URL is about to be loaded to this **Web** component. If the callback returns **true**, the **\<Web>** component stops loading the URL. If the callback returns **false**, the **Web** component continues to load the URL. 5624 5625POST requests do not trigger this callback. 5626 5627This callback is triggered when the **iframe** loads the redirection of a non-HTTP(s) protocol, but is not triggered when the **iframe** loads the HTTP(s) protocol or **about:blank** and when the redirection initiated by **loadUrl(String)** is called. 5628 5629Do not use the same URL to call the **loadUrl(String)** API and then return **true**. Doing so would unnecessarily cancel the current loading and start a new load with the same URL. The correct way to continue loading the given URL is to simply return **false**, rather than calling **loadUrl(String)**. 5630 5631**Parameters** 5632 5633| Name | Type | Description | 5634| -------------- | --------------------------------------------------------------------------- | ---------------------- | 5635| callback | [OnOverrideUrlLoadingCallback](#onoverrideurlloadingcallback12) | Callback for **onOverrideUrlLoading**.| 5636 5637**Example** 5638 5639 ```ts 5640 // xxx.ets 5641 import { webview } from '@kit.ArkWeb'; 5642 5643 @Entry 5644 @Component 5645 struct WebComponent { 5646 controller: webview.WebviewController = new webview.WebviewController(); 5647 5648 build() { 5649 Column() { 5650 Web({ src: $rawfile("index.html"), controller: this.controller }) 5651 .onOverrideUrlLoading((webResourceRequest: WebResourceRequest) => { 5652 if (webResourceRequest && webResourceRequest.getRequestUrl() == "about:blank") { 5653 return true; 5654 } 5655 return false; 5656 }) 5657 } 5658 } 5659 } 5660 ``` 5661 5662 HTML file to be loaded: 5663 ```html 5664 <!--index.html--> 5665 <!DOCTYPE html> 5666 <html> 5667 <head> 5668 <title>Test Web Page</title> 5669 </head> 5670 <body> 5671 <h1>onOverrideUrlLoading Demo</h1> 5672 <a href="about:blank">Click here</a> to visit about:blank. 5673 </body> 5674 </html> 5675 ``` 5676 5677### onViewportFitChanged<sup>12+</sup> 5678 5679onViewportFitChanged(callback: OnViewportFitChangedCallback) 5680 5681Called when the **viewport-fit** configuration in the web page's **\<meta>** tag changes. The application can adapt its layout to the viewport within this callback. 5682 5683**Parameters** 5684 5685| Name | Type | Description | 5686| -------- | ------------------------------------------------------------ | -------------------------------------- | 5687| callback | [OnViewportFitChangedCallback](#onviewportfitchangedcallback12) | Callback invoked when the **viewport-fit** configuration in the web page's **\<meta>** tag changes.| 5688 5689**Example** 5690 5691 ```ts 5692 // xxx.ets 5693 import { webview } from '@kit.ArkWeb'; 5694 5695 @Entry 5696 @Component 5697 struct WebComponent { 5698 controller: webview.WebviewController = new webview.WebviewController(); 5699 5700 build() { 5701 Column() { 5702 Web({ src: $rawfile('index.html'), controller: this.controller }) 5703 .onViewportFitChanged((data) => { 5704 let jsonData = JSON.stringify(data); 5705 let viewportFit: ViewportFit = JSON.parse(jsonData).viewportFit; 5706 if (viewportFit === ViewportFit.COVER) { 5707 // The index.html web page supports immersive layout. You can call expandSafeArea to adjust the Web component layout viewport to cover the safe area (status bar or navigation bar). 5708 } else if (viewportFit === ViewportFit.CONTAINS) { 5709 // The index.html web page does not support immersive layout. You can call expandSafeArea to adjust the Web component layout viewport as a safe area. 5710 } else { 5711 // Default value. No processing is required. 5712 } 5713 }) 5714 } 5715 } 5716 } 5717 ``` 5718 5719 HTML file to be loaded: 5720 ```html 5721 <!-- index.html --> 5722 <!DOCTYPE html> 5723 <html> 5724 <head> 5725 <meta name="viewport" content="width=device-width,viewport-fit=cover"> 5726 </head> 5727 <body> 5728 <div style="position: absolute; bottom: 0; margin-bottom: env(safe-area-inset-bottom)"></div> 5729 </body> 5730 </html> 5731 ``` 5732 5733### onInterceptKeyboardAttach<sup>12+</sup> 5734 5735onInterceptKeyboardAttach(callback: WebKeyboardCallback) 5736 5737Called before any editable element (such as the **\<input>** tag) on the web page invokes the soft keyboard. The application can use this API to intercept the display of the system's soft keyboard and configure a custom soft keyboard. (With this API, the application can determine whether to use the system's default soft keyboard, a system soft keyboard with a custom Enter key, or a completely application-defined soft keyboard). 5738 5739**Parameters** 5740 5741| Name | Type | Description | 5742| -------- | ------------------------------------------------------------ | -------------------------------------- | 5743| callback | [WebKeyboardCallback](#webkeyboardcallback12) | Callback invoked for intercepting the soft keyboard invoking in the web page.| 5744 5745**Example** 5746 5747 ```ts 5748 // xxx.ets 5749 import { webview } from '@kit.ArkWeb'; 5750 import { inputMethodEngine } from '@kit.IMEKit'; 5751 5752 @Entry 5753 @Component 5754 struct WebComponent { 5755 controller: webview.WebviewController = new webview.WebviewController(); 5756 webKeyboardController: WebKeyboardController = new WebKeyboardController() 5757 inputAttributeMap: Map<string, number> = new Map([ 5758 ['UNSPECIFIED', inputMethodEngine.ENTER_KEY_TYPE_UNSPECIFIED], 5759 ['GO', inputMethodEngine.ENTER_KEY_TYPE_GO], 5760 ['SEARCH', inputMethodEngine.ENTER_KEY_TYPE_SEARCH], 5761 ['SEND', inputMethodEngine.ENTER_KEY_TYPE_SEND], 5762 ['NEXT', inputMethodEngine.ENTER_KEY_TYPE_NEXT], 5763 ['DONE', inputMethodEngine.ENTER_KEY_TYPE_DONE], 5764 ['PREVIOUS', inputMethodEngine.ENTER_KEY_TYPE_PREVIOUS] 5765 ]) 5766 5767 /** 5768 * Builder for a custom keyboard component 5769 */ 5770 @Builder 5771 customKeyboardBuilder() { 5772 // Implement a custom keyboard component and connect to the WebKeyboardController to implement operations such as input, deletion, and close. 5773 Row() { 5774 Text("Finish") 5775 .fontSize(20) 5776 .fontColor(Color.Blue) 5777 .onClick(() => { 5778 this.webKeyboardController.close(); 5779 }) 5780 // Insert characters. 5781 Button("insertText").onClick(() => { 5782 this.webKeyboardController.insertText('insert '); 5783 }).margin({ 5784 bottom: 200, 5785 }) 5786 // Delete characters from the end to the beginning for the length specified by the length parameter. 5787 Button("deleteForward").onClick(() => { 5788 this.webKeyboardController.deleteForward(1); 5789 }).margin({ 5790 bottom: 200, 5791 }) 5792 // Delete characters from the beginning to the end for the length specified by the length parameter. 5793 Button("deleteBackward").onClick(() => { 5794 this.webKeyboardController.deleteBackward(1); 5795 }).margin({ 5796 left: -220, 5797 }) 5798 // Insert a function key. 5799 Button("sendFunctionKey").onClick(() => { 5800 this.webKeyboardController.sendFunctionKey(6); 5801 }) 5802 } 5803 } 5804 5805 build() { 5806 Column() { 5807 Web({ src: $rawfile('index.html'), controller: this.controller }) 5808 .onInterceptKeyboardAttach((KeyboardCallbackInfo) => { 5809 // Initialize option. By default, the default keyboard is used. 5810 let option: WebKeyboardOptions = { 5811 useSystemKeyboard: true, 5812 }; 5813 if (!KeyboardCallbackInfo) { 5814 return option; 5815 } 5816 5817 // Save the WebKeyboardController. When using a custom keyboard, this handler is required to control behaviors such as input, deletion, and closing of the soft keyboard. 5818 this.webKeyboardController = KeyboardCallbackInfo.controller 5819 let attributes: Record<string, string> = KeyboardCallbackInfo.attributes 5820 // Traverse attributes. 5821 let attributeKeys = Object.keys(attributes) 5822 for (let i = 0; i < attributeKeys.length; i++) { 5823 console.log('WebCustomKeyboard key = ' + attributeKeys[i] + ', value = ' + attributes[attributeKeys[i]]) 5824 } 5825 5826 if (attributes) { 5827 if (attributes['data-keyboard'] == 'customKeyboard') { 5828 // Determine the soft keyboard to use based on the attributes of editable HTML elements. For example, if the attribute includes data-keyboard and its value is customKeyboard, use a custom keyboard. 5829 console.log('WebCustomKeyboard use custom keyboard') 5830 option.useSystemKeyboard = false; 5831 // Sets the custom keyboard builder. 5832 option.customKeyboard = () => { 5833 this.customKeyboardBuilder() 5834 } 5835 return option; 5836 } 5837 5838 if (attributes['keyboard-return'] != undefined) { 5839 // Determine the soft keyboard to use based on the attributes of editable HTML elements. For example, if the attribute includes keyboard-return, use the system keyboard and specify the type of the system soft keyboard's Enter key. 5840 option.useSystemKeyboard = true; 5841 let enterKeyType: number | undefined = this.inputAttributeMap.get(attributes['keyboard-return']) 5842 if (enterKeyType != undefined) { 5843 option.enterKeyType = enterKeyType 5844 } 5845 return option; 5846 } 5847 } 5848 5849 return option; 5850 }) 5851 } 5852 } 5853 } 5854 ``` 5855 5856 HTML file to be loaded: 5857 ```html 5858 <!-- index.html --> 5859 <!DOCTYPE html> 5860 <html> 5861 5862 <head> 5863 <meta charset="utf-8"> 5864 <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0"> 5865 </head> 5866 5867 <body> 5868 5869 <p style="font-size:12px">input tag. Original default behavior: </p> 5870 <input type="text" style="width: 300px; height: 20px"><br> 5871 <hr style="height:2px;border-width:0;color:gray;background-color:gray"> 5872 5873 <p style="font-size:12px">input tag. System keyboard with enterKeyType as UNSPECIFIED: </p> 5874 <input type="text" keyboard-return="UNSPECIFIED" style="width: 300px; height: 20px"><br> 5875 <hr style="height:2px;border-width:0;color:gray;background-color:gray"> 5876 5877 <p style="font-size:12px">input tag. System keyboard with enterKeyType as GO: </p> 5878 <input type="text" keyboard-return="GO" style="width: 300px; height: 20px"><br> 5879 <hr style="height:2px;border-width:0;color:gray;background-color:gray"> 5880 5881 <p style="font-size:12px">input tag. System keyboard with enterKeyType as SEARCH: </p> 5882 <input type="text" keyboard-return="SEARCH" style="width: 300px; height: 20px"><br> 5883 <hr style="height:2px;border-width:0;color:gray;background-color:gray"> 5884 5885 <p style="font-size:12px">input tag. System keyboard with enterKeyType as SEND: </p> 5886 <input type="text" keyboard-return="SEND" style="width: 300px; height: 20px"><br> 5887 <hr style="height:2px;border-width:0;color:gray;background-color:gray"> 5888 5889 <p style="font-size:12px">input tag. System keyboard with enterKeyType as NEXT: </p> 5890 <input type="text" keyboard-return="NEXT" style="width: 300px; height: 20px"><br> 5891 <hr style="height:2px;border-width:0;color:gray;background-color:gray"> 5892 5893 <p style="font-size:12px">input tag. System keyboard with enterKeyType as DONE: </p> 5894 <input type="text" keyboard-return="DONE" style="width: 300px; height: 20px"><br> 5895 <hr style="height:2px;border-width:0;color:gray;background-color:gray"> 5896 5897 <p style="font-size:12px">input tag. System keyboard with enterKeyType as PREVIOUS: </p> 5898 <input type="text" keyboard-return="PREVIOUS" style="width: 300px; height: 20px"><br> 5899 <hr style="height:2px;border-width:0;color:gray;background-color:gray"> 5900 5901 <p style="font-size:12px">input tag. Custom keyboard: </p> 5902 <input type="text" data-keyboard="customKeyboard" style="width: 300px; height: 20px"><br> 5903 5904 </body> 5905 5906 </html> 5907 ``` 5908 5909### onNativeEmbedVisibilityChange<sup>12+</sup> 5910 5911onNativeEmbedVisibilityChange(callback: OnNativeEmbedVisibilityChangeCallback) 5912 5913Called when the visibility of a same-layer rendering tag (such as an **Embed** tag or an **Object** tag) on a web page changes in the viewport. By default, the same-layer rendering tag is invisible. If the rendering tag is visible when you access the page for the first time, the callback is triggered; otherwise, it is not triggered. That is, if the same-layer rendering tag changes from a non-zero value to **0 x 0**, the callback is triggered. If the rendering tag size changes from **0 x 0** to a non-zero value, the callback is not triggered. If all the same-layer rendering tags are invisible, they are reported as invisible. If all the same-layer rendering tags or part of them are visible, they are reported as invisible. 5914 5915**Parameters** 5916 5917| Name | Type | Description | 5918| -------------- | --------------------------------------------------------------------------- | ---------------------- | 5919| callback | [OnNativeEmbedVisibilityChangeCallback](#onnativeembedvisibilitychangecallback12) | Called when the visibility of a same-layer rendering tag changes.| 5920 5921**Example** 5922 ```ts 5923 // xxx.ets 5924 import { webview } from '@kit.ArkWeb'; 5925 5926 @Entry 5927 @Component 5928 struct WebComponent { 5929 @State embedVisibility: string = ''; 5930 controller: webview.WebviewController = new webview.WebviewController(); 5931 5932 build() { 5933 Column() { 5934 Stack() { 5935 Web({ src: $rawfile("index.html"), controller: this.controller }) 5936 .enableNativeEmbedMode(true) 5937 .onNativeEmbedVisibilityChange((embed) => { 5938 if (embed.visibility) { 5939 this.embedVisibility = 'Visible'; 5940 } else { 5941 this.embedVisibility = 'Hidden'; 5942 } 5943 console.log("embedId = " + embed.embedId); 5944 console.log("visibility = " + embed.visibility); 5945 }) 5946 } 5947 } 5948 } 5949 } 5950 ``` 5951 5952 HTML file to be loaded: 5953 ```html 5954 <!-- index.html --> 5955 <!DOCTYPE html> 5956 <html> 5957 <head> 5958 <title>Same-layer rendering test HTML</title> 5959 <meta name="viewport"> 5960 </head> 5961 <body> 5962 <div> 5963 <div id="bodyId"> 5964 <embed id="nativeVideo" type = "native/video" width="800" height="800" src="test? params1=1?" style = "background-color:red"/> 5965 </div> 5966 </div> 5967 </body> 5968 </html> 5969 ``` 5970 5971## WebKeyboardCallback<sup>12+</sup> 5972 5973type WebKeyboardCallback = (keyboardCallbackInfo: WebKeyboardCallbackInfo) => WebKeyboardOptions 5974 5975Called to intercept the soft keyboard from editable elements on a web page. This event is typically called when the **\<input>** tag on the web page is clicked. 5976 5977**System capability**: SystemCapability.Web.Webview.Core 5978 5979**Parameters** 5980 5981| Name | Type | Mandatory | Description | 5982| ------------- | ------ | ---- | ------------------ | 5983| keyboardCallbackInfo | [WebKeyboardCallbackInfo](#webkeyboardcallbackinfo12) | Yes | Input parameter of the callback for intercepting the soft keyboard from editable elements on a web page, including [WebKeyboardController](#webkeyboardcontroller12) and editable element attributes. | 5984 5985 5986**Return value** 5987 5988| Type | Description | 5989| ------------------ | ------------------------------------------------------------ | 5990| [WebKeyboardOptions](#webkeyboardoptions12) | [WebKeyboardOptions](#webkeyboardoptions12) instance, which is used to determine which type of soft keyboard to start by the ArkWeb rendering engine.| 5991 5992## WebKeyboardCallbackInfo<sup>12+</sup> 5993 5994Represents the input parameter of the callback for intercepting the soft keyboard from editable elements on a web page, including [WebKeyboardController](#webkeyboardcontroller12) and editable element attributes. 5995 5996| Name | Type | Readable | Writable | Mandatory | Description | 5997| -------------- | ------- | ---- | ---- | ---- | ---------------------------------------- | 5998| controller | [WebKeyboardController](#webkeyboardcontroller12) | Yes | No | Yes | Controller used to control the input, deletion, and closure of the custom keyboard.| 5999| attributes | Record<string, string> | Yes | No | Yes | Attributes of the web page element that triggered the soft keyboard to pop up. 6000 6001## WebKeyboardOptions<sup>12+</sup> 6002 6003Represents the return value of the callback that intercepts the soft keyboard from editable elements on the web page. You can specify the type of the keyboard to be used, and it is returned to the Web kernel to display a keyboard of the corresponding type. 6004 6005| Name | Type | Readable | Writable | Mandatory | Description | 6006| -------------- | ------- | ---- | ---- | ---- | ---------------------------------------- | 6007| useSystemKeyboard | boolean | Yes | Yes | Yes | Whether to use the system's default soft keyboard.| 6008| enterKeyType | number | Yes | Yes | No | Type of the Enter key of the system soft keyboard. For details about the value range, see [EnterKeyType](../apis-ime-kit/js-apis-inputmethod.md#enterkeytype10). This parameter has effect only when **useSystemKeyboard** is set to **true** and **enterKeyType** is set to a valid value.| 6009| customKeyboard | [CustomBuilder](../apis-arkui/arkui-ts/ts-types.md#custombuilder8) | Yes | Yes | No | Builder of a custom keyboard. This parameter is required when **useSystemKeyboard** is set to **false**. After it is set, the Web component starts the custom keyboard as configured. 6010 6011## WebKeyboardController<sup>12+</sup> 6012 6013Implements a controller to control the input, deletion, and closure of the custom keyboard. For details about the sample code, see [onInterceptKeyboardAttach](#oninterceptkeyboardattach12). 6014 6015### insertText<sup>12+</sup> 6016 6017insertText(text: string): void 6018 6019Inserts a character. 6020 6021**Parameters** 6022 6023| Name| Type| Mandatory| Default Value| Description | 6024| ------ | -------- | ---- | ------ | --------------------- | 6025| text | string | Yes | - | Character to insert into the **Web** component text box.| 6026 6027### deleteForward<sup>12+</sup> 6028 6029deleteForward(length: number): void 6030 6031Deletes characters from the end to the beginning for the length specified by the **length** parameter. 6032 6033**Parameters** 6034 6035| Name| Type| Mandatory| Default Value| Description | 6036| ------ | -------- | ---- | ------ | ------------------------ | 6037| length | number | Yes | - | Length of characters to be deleted from the end to the beginning.| 6038 6039### deleteBackward12+</sup> 6040 6041deleteBackward(length: number): void 6042 6043Deletes characters from the beginning to the end for the length specified by the **length** parameter. 6044 6045**Parameters** 6046 6047| Name| Type| Mandatory| Default Value| Description | 6048| ------ | -------- | ---- | ------ | ------------------------ | 6049| length | number | Yes | - | Length of characters to be deleted from the beginning to the end.| 6050 6051### sendFunctionKey<sup>12+</sup> 6052 6053sendFunctionKey(key: number): void 6054 6055Inserts a function key. Currently, only the Enter key type is supported. For details about the value, see [EnterKeyType](../apis-ime-kit/js-apis-inputmethod.md#enterkeytype10). 6056 6057**Parameters** 6058 6059| Name| Type| Mandatory| Default Value| Description | 6060| ------ | -------- | ---- | ------ | ------------------------------------------ | 6061| key | number | Yes | - | Function key to insert into the **Web** component text box. Currently, only the Enter key is supported.| 6062 6063### close<sup>12+</sup> 6064 6065close(): void 6066 6067Closes this custom keyboard. 6068 6069### onAdsBlocked<sup>12+</sup> 6070 6071onAdsBlocked(callback: OnAdsBlockedCallback) 6072 6073Called after an ad is blocked on the web page to notify the user of detailed information about the blocked ad. To reduce the frequency of notifications and minimize the impact on the page loading process, only the first notification is made when the page is fully loaded. Subsequent blocking events are reported at intervals of 1 second, and no notifications are sent if there is no ad blocked. 6074 6075**Parameters** 6076 6077| Name | Type | Description | 6078| -------------- | --------------------------------------------------------------------------- | ---------------------- | 6079| callback | [OnAdsBlockedCallback](#onadsblockedcallback12) | Callback for **onAdsBlocked**.| 6080 6081**Example** 6082 6083 ```ts 6084 // xxx.ets 6085 import { webview } from '@kit.ArkWeb'; 6086 6087 @Entry 6088 @Component 6089 struct WebComponent { 6090 @State totalAdsBlockCounts: number = 0; 6091 controller: webview.WebviewController = new webview.WebviewController(); 6092 6093 build() { 6094 Column() { 6095 Web({ src: 'https://www.example.com', controller: this.controller }) 6096 .onAdsBlocked((details: AdsBlockedDetails) => { 6097 if (details) { 6098 console.log(' Blocked ' + details.adsBlocked.length + ' in ' + details.url); 6099 let adList: Array<string> = Array.from(new Set(details.adsBlocked)); 6100 this.totalAdsBlockCounts += adList.length; 6101 console.log('Total blocked counts :' + this.totalAdsBlockCounts); 6102 } 6103 }) 6104 } 6105 } 6106 } 6107 ``` 6108 6109## ConsoleMessage 6110 6111Implements the **ConsoleMessage** object. For the sample code, see [onConsole](#onconsole). 6112 6113### getLineNumber 6114 6115getLineNumber(): number 6116 6117Obtains the number of rows in this console message. 6118 6119**Return value** 6120 6121| Type | Description | 6122| ------ | -------------------- | 6123| number | Number of rows in the console message.| 6124 6125### getMessage 6126 6127getMessage(): string 6128 6129Obtains the log information of this console message. 6130 6131**Return value** 6132 6133| Type | Description | 6134| ------ | ---------------------- | 6135| string | Log information of the console message.| 6136 6137### getMessageLevel 6138 6139getMessageLevel(): MessageLevel 6140 6141Obtains the level of this console message. 6142 6143**Return value** 6144 6145| Type | Description | 6146| --------------------------------- | ---------------------- | 6147| [MessageLevel](#messagelevel)| Level of the console message.| 6148 6149### getSourceId 6150 6151getSourceId(): string 6152 6153Obtains the path and name of the web page source file. 6154 6155**Return value** 6156 6157| Type | Description | 6158| ------ | ------------- | 6159| string | Path and name of the web page source file.| 6160 6161## JsResult 6162 6163Implements the **JsResult** object, which indicates the result returned to the **Web** component to indicate the user operation performed in the dialog box. For the sample code, see [onAlert Event](#onalert). 6164 6165### handleCancel 6166 6167handleCancel(): void 6168 6169Notifies the **Web** component of the user's cancel operation in the dialog box. 6170 6171### handleConfirm 6172 6173handleConfirm(): void 6174 6175Notifies the **Web** component of the user's confirm operation in the dialog box. 6176 6177### handlePromptConfirm<sup>9+</sup> 6178 6179handlePromptConfirm(result: string): void 6180 6181Notifies the **Web** component of the user's confirm operation in the dialog box as well as the dialog box content. 6182 6183**Parameters** 6184 6185| Name | Type | Mandatory | Default Value | Description | 6186| ------ | ------ | ---- | ---- | ----------- | 6187| result | string | Yes | - | User input in the dialog box.| 6188 6189## FullScreenExitHandler<sup>9+</sup> 6190 6191Implements a **FullScreenExitHandler** object for listening for exiting full screen mode. For the sample code, see [onFullScreenEnter](#onfullscreenenter9). 6192 6193### constructor<sup>9+</sup> 6194 6195constructor() 6196 6197### exitFullScreen<sup>9+</sup> 6198 6199exitFullScreen(): void 6200 6201Exits full screen mode. 6202 6203## ControllerHandler<sup>9+</sup> 6204 6205Implements a **WebviewController** object for new **Web** components. For the sample code, see [onWindowNew](#onwindownew9). 6206 6207### setWebController<sup>9+</sup> 6208 6209setWebController(controller: WebviewController): void 6210 6211Sets a **WebviewController** object. If opening a new window is not needed, set the parameter to **null**. 6212 6213**Parameters** 6214 6215| Name | Type | Mandatory | Default Value | Description | 6216| ---------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- | 6217| controller | [WebviewController](js-apis-webview.md#webviewcontroller) | Yes | - | **WebviewController** object of the **Web** component. If opening a new window is not needed, set it to **null**.| 6218 6219## WebResourceError 6220 6221Implements the **WebResourceError** object. For the sample code, see [onErrorReceive](#onerrorreceive). 6222 6223### getErrorCode 6224 6225getErrorCode(): number 6226 6227Obtains the error code for resource loading. 6228 6229**Return value** 6230 6231| Type | Description | 6232| ------ | ----------- | 6233| number | Error code for resource loading. For details about error codes, see [WebNetErrorList](js-apis-netErrorList.md).| 6234 6235### getErrorInfo 6236 6237getErrorInfo(): string 6238 6239Obtains error information about resource loading. 6240 6241**Return value** 6242 6243| Type | Description | 6244| ------ | ------------ | 6245| string | Error information about resource loading.| 6246 6247## WebResourceRequest 6248 6249Implements the **WebResourceRequest** object. For the sample code, see [onErrorReceive](#onerrorreceive). 6250 6251### getRequestHeader 6252 6253getRequestHeader(): Array\<Header\> 6254 6255Obtains the information about the resource request header. 6256 6257**Return value** 6258 6259| Type | Description | 6260| -------------------------- | ---------- | 6261| Array\<[Header](#header)\> | Information about the resource request header.| 6262 6263### getRequestUrl 6264 6265getRequestUrl(): string 6266 6267Obtains the URL of the resource request. 6268 6269**Return value** 6270 6271| Type | Description | 6272| ------ | ------------- | 6273| string | URL of the resource request.| 6274 6275### isMainFrame 6276 6277isMainFrame(): boolean 6278 6279Checks whether the resource request is in the main frame. 6280 6281**Return value** 6282 6283| Type | Description | 6284| ------- | ---------------- | 6285| boolean | Whether the resource request is in the main frame.| 6286 6287### isRedirect 6288 6289isRedirect(): boolean 6290 6291Checks whether the resource request is redirected by the server. 6292 6293**Return value** 6294 6295| Type | Description | 6296| ------- | ---------------- | 6297| boolean | Whether the resource request is redirected by the server.| 6298 6299### isRequestGesture 6300 6301isRequestGesture(): boolean 6302 6303Checks whether the resource request is associated with a gesture (for example, a tap). 6304 6305**Return value** 6306 6307| Type | Description | 6308| ------- | -------------------- | 6309| boolean | Whether the resource request is associated with a gesture (for example, a tap).| 6310 6311### getRequestMethod<sup>9+</sup> 6312 6313getRequestMethod(): string 6314 6315Obtains the request method. 6316 6317**Return value** 6318 6319| Type | Description | 6320| ------ | ------- | 6321| string | Request method.| 6322 6323## Header 6324 6325Describes the request/response header returned by the **Web** component. 6326 6327| Name | Type | Description | 6328| ----------- | ------ | ------------- | 6329| headerKey | string | Key of the request/response header. | 6330| headerValue | string | Value of the request/response header.| 6331 6332## WebResourceResponse 6333 6334Implements the **WebResourceResponse** object. For the sample code, see [onHttpErrorReceive](#onhttperrorreceive). 6335 6336### getReasonMessage 6337 6338getReasonMessage(): string 6339 6340Obtains the status code description of the resource response. 6341 6342**Return value** 6343 6344| Type | Description | 6345| ------ | ------------- | 6346| string | Status code description of the resource response.| 6347 6348### getResponseCode 6349 6350getResponseCode(): number 6351 6352Obtains the status code of the resource response. 6353 6354**Return value** 6355 6356| Type | Description | 6357| ------ | ----------- | 6358| number | Status code of the resource response.| 6359 6360### getResponseData 6361 6362getResponseData(): string 6363 6364Obtains the data in the resource response. 6365 6366**Return value** 6367 6368| Type | Description | 6369| ------ | --------- | 6370| string | Data in the resource response.| 6371 6372### getResponseEncoding 6373 6374getResponseEncoding(): string 6375 6376Obtains the encoding string of the resource response. 6377 6378**Return value** 6379 6380| Type | Description | 6381| ------ | ---------- | 6382| string | Encoding string of the resource response.| 6383 6384### getResponseHeader 6385 6386getResponseHeader() : Array\<Header\> 6387 6388Obtains the resource response header. 6389 6390**Return value** 6391 6392| Type | Description | 6393| -------------------------- | -------- | 6394| Array\<[Header](#header)\> | Resource response header.| 6395 6396### getResponseMimeType 6397 6398getResponseMimeType(): string 6399 6400Obtains the MIME type of the resource response. 6401 6402**Return value** 6403 6404| Type | Description | 6405| ------ | ------------------ | 6406| string | MIME type of the resource response.| 6407 6408### setResponseData<sup>9+</sup> 6409 6410setResponseData(data: string \| number \| Resource \| ArrayBuffer): void 6411 6412Sets the data in the resource response. 6413 6414**Parameters** 6415 6416| Name | Type | Mandatory | Default Value | Description | 6417| ---- | ---------------------------------------- | ---- | ---- | ---------------------------------------- | 6418| data | string \| number \| [Resource](../apis-arkui/arkui-ts/ts-types.md)<sup>10+</sup> \| ArrayBuffer<sup>11+</sup> | Yes | - | Resource response data to set. When set to a string, the value indicates a string in HTML format. When set to a number, the value indicates a file handle, which is closed by the system **Web** component. When set to a **Resource** object, the value indicates the file resources in the **rawfile** directory of the application. When set to a **ArrayBuffer** object, the value indicates the original binary data of a resource.| 6419 6420### setResponseEncoding<sup>9+</sup> 6421 6422setResponseEncoding(encoding: string): void 6423 6424Sets the encoding string of the resource response. 6425 6426**Parameters** 6427 6428| Name | Type | Mandatory | Default Value | Description | 6429| -------- | ------ | ---- | ---- | ------------ | 6430| encoding | string | Yes | - | Encoding string to set.| 6431 6432### setResponseMimeType<sup>9+</sup> 6433 6434setResponseMimeType(mimeType: string): void 6435 6436Sets the MIME type of the resource response. 6437 6438**Parameters** 6439 6440| Name | Type | Mandatory | Default Value | Description | 6441| -------- | ------ | ---- | ---- | -------------------- | 6442| mimeType | string | Yes | - | MIME type to set.| 6443 6444### setReasonMessage<sup>9+</sup> 6445 6446setReasonMessage(reason: string): void 6447 6448Sets the status code description of the resource response. 6449 6450**Parameters** 6451 6452| Name | Type | Mandatory | Default Value | Description | 6453| ------ | ------ | ---- | ---- | --------------- | 6454| reason | string | Yes | - | Status code description to set.| 6455 6456### setResponseHeader<sup>9+</sup> 6457 6458setResponseHeader(header: Array\<Header\>): void 6459 6460Sets the resource response header. 6461 6462**Parameters** 6463 6464| Name | Type | Mandatory | Default Value | Description | 6465| ------ | -------------------------- | ---- | ---- | ---------- | 6466| header | Array\<[Header](#header)\> | Yes | - | Resource response header to set.| 6467 6468### setResponseCode<sup>9+</sup> 6469 6470setResponseCode(code: number): void 6471 6472Sets the status code of the resource response. 6473 6474**Parameters** 6475 6476| Name | Type | Mandatory | Default Value | Description | 6477| ---- | ------ | ---- | ---- | ------------- | 6478| code | number | Yes | - | Status code to set.| 6479 6480### setResponseIsReady<sup>9+</sup> 6481 6482setResponseIsReady(IsReady: boolean): void 6483 6484Sets whether the resource response data is ready. 6485 6486**Parameters** 6487 6488| Name | Type | Mandatory | Default Value | Description | 6489| ------- | ------- | ---- | ---- | ------------- | 6490| IsReady | boolean | Yes | true | Whether the resource response data is ready.| 6491 6492## FileSelectorResult<sup>9+</sup> 6493 6494Notifies the **Web** component of the file selection result. For the sample code, see [onShowFileSelector](#onshowfileselector9). 6495 6496### handleFileList<sup>9+</sup> 6497 6498handleFileList(fileList: Array\<string\>): void 6499 6500Instructs the **Web** component to select a file. 6501 6502**Parameters** 6503 6504| Name | Type | Mandatory | Default Value | Description | 6505| -------- | --------------- | ---- | ---- | ------------ | 6506| fileList | Array\<string\> | Yes | - | List of files to operate.| 6507 6508## FileSelectorParam<sup>9+</sup> 6509 6510Implements the **FileSelectorParam** object. For the sample code, see [onShowFileSelector](#onshowfileselector9). 6511 6512### getTitle<sup>9+</sup> 6513 6514getTitle(): string 6515 6516Obtains the title of this file selector. 6517 6518**Return value** 6519 6520| Type | Description | 6521| ------ | ---------- | 6522| string | Title of the file selector.| 6523 6524### getMode<sup>9+</sup> 6525 6526getMode(): FileSelectorMode 6527 6528Obtains the mode of the file selector. 6529 6530**Return value** 6531 6532| Type | Description | 6533| ---------------------------------------- | ----------- | 6534| [FileSelectorMode](#fileselectormode9) | Mode of the file selector.| 6535 6536### getAcceptType<sup>9+</sup> 6537 6538getAcceptType(): Array\<string\> 6539 6540Obtains the file filtering type. 6541 6542**Return value** 6543 6544| Type | Description | 6545| --------------- | --------- | 6546| Array\<string\> | File filtering type.| 6547 6548### isCapture<sup>9+</sup> 6549 6550isCapture(): boolean 6551 6552Checks whether multimedia capabilities are invoked. 6553 6554**Return value** 6555 6556| Type | Description | 6557| ------- | ------------ | 6558| boolean | Whether multimedia capabilities are invoked.| 6559 6560## HttpAuthHandler<sup>9+</sup> 6561 6562Implements the **HttpAuthHandler** object. For the sample code, see [onHttpAuthRequest](#onhttpauthrequest9). 6563 6564### cancel<sup>9+</sup> 6565 6566cancel(): void 6567 6568Cancels HTTP authentication as requested by the user. 6569 6570### confirm<sup>9+</sup> 6571 6572confirm(userName: string, password: string): boolean 6573 6574Performs HTTP authentication with the user name and password provided by the user. 6575 6576**Parameters** 6577 6578| Name | Type | Mandatory | Default Value | Description | 6579| -------- | ------ | ---- | ---- | ---------- | 6580| userName | string | Yes | - | HTTP authentication user name.| 6581| password | string | Yes | - | HTTP authentication password. | 6582 6583**Return value** 6584 6585| Type | Description | 6586| ------- | --------------------- | 6587| boolean | Returns **true** if the authentication is successful; returns **false** otherwise.| 6588 6589### isHttpAuthInfoSaved<sup>9+</sup> 6590 6591isHttpAuthInfoSaved(): boolean 6592 6593Sets whether to use the account name and password cached on the server for authentication. 6594 6595**Return value** 6596 6597| Type | Description | 6598| ------- | ------------------------- | 6599| boolean | Returns **true** if the authentication is successful; returns **false** otherwise.| 6600 6601## SslErrorHandler<sup>9+</sup> 6602 6603Implements an **SslErrorHandler** object. For the sample code, see [onSslErrorEventReceive Event](#onsslerroreventreceive9). 6604 6605### handleCancel<sup>9+</sup> 6606 6607handleCancel(): void 6608 6609Cancels this request. 6610 6611### handleConfirm<sup>9+</sup> 6612 6613handleConfirm(): void 6614 6615Continues using the SSL certificate. 6616 6617## ClientAuthenticationHandler<sup>9+</sup> 6618 6619Implements a **ClientAuthenticationHandler** object returned by the **Web** component. For the sample code, see [onClientAuthenticationRequest](#onclientauthenticationrequest9). 6620 6621### confirm<sup>9+</sup> 6622 6623confirm(priKeyFile : string, certChainFile : string): void 6624 6625Uses the specified private key and client certificate chain. 6626 6627**Parameters** 6628 6629| Name | Type | Mandatory | Description | 6630| ------------- | ------ | ---- | ------------------ | 6631| priKeyFile | string | Yes | File that stores the private key, which is a directory including the file name. | 6632| certChainFile | string | Yes | File that stores the certificate chain, which is a directory including the file name.| 6633 6634### confirm<sup>10+</sup> 6635 6636confirm(authUri : string): void 6637 6638**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER 6639 6640Instructs the **Web** component to use the specified credentials (obtained from the certificate management module). 6641 6642**Parameters** 6643 6644| Name | Type | Mandatory | Description | 6645| ------- | ------ | ---- | ------- | 6646| authUri | string | Yes | Key value of the credentials.| 6647 6648### cancel<sup>9+</sup> 6649 6650cancel(): void 6651 6652Cancels the client certificate request sent by the same host and port server. No additional event will be reported for requests from the same host and port server. 6653 6654### ignore<sup>9+</sup> 6655 6656ignore(): void 6657 6658Ignores this request. 6659 6660## PermissionRequest<sup>9+</sup> 6661 6662Implements the **PermissionRequest** object. For the sample code, see [onPermissionRequest](#onpermissionrequest9). 6663 6664### deny<sup>9+</sup> 6665 6666deny(): void 6667 6668Denies the permission requested by the web page. 6669 6670### getOrigin<sup>9+</sup> 6671 6672getOrigin(): string 6673 6674Obtains the origin of this web page. 6675 6676**Return value** 6677 6678| Type | Description | 6679| ------ | ------------ | 6680| string | Origin of the web page that requests the permission.| 6681 6682### getAccessibleResource<sup>9+</sup> 6683 6684getAccessibleResource(): Array\<string\> 6685 6686Obtains the list of accessible resources requested for the web page. For details about the resource types, see [ProtectedResourceType](#protectedresourcetype9). 6687 6688**Return value** 6689 6690| Type | Description | 6691| --------------- | ------------- | 6692| Array\<string\> | List of accessible resources requested by the web page.| 6693 6694### grant<sup>9+</sup> 6695 6696grant(resources: Array\<string\>): void 6697 6698Grants the permission for resources requested by the web page. 6699 6700**Parameters** 6701 6702| Name | Type | Mandatory | Default Value | Description | 6703| --------- | --------------- | ---- | ---- | --------------- | 6704| resources | Array\<string\> | Yes | - | List of resources that can be requested by the web page with the permission to grant.| 6705 6706## ScreenCaptureHandler<sup>10+</sup> 6707 6708Implements the **ScreenCaptureHandler** object for accepting or rejecting a screen capture request. For the sample code, see [onScreenCaptureRequest Event](#onscreencapturerequest10). 6709 6710### deny<sup>10+</sup> 6711 6712deny(): void 6713 6714Rejects this screen capture request. 6715 6716### getOrigin<sup>10+</sup> 6717 6718getOrigin(): string 6719 6720Obtains the origin of this web page. 6721 6722**Return value** 6723 6724| Type | Description | 6725| ------ | ------------ | 6726| string | Origin of the web page that requests the permission.| 6727 6728### grant<sup>10+</sup> 6729 6730grant(config: ScreenCaptureConfig): void 6731 6732**Required permissions:** ohos.permission.MICROPHONE 6733 6734Grants the screen capture permission. 6735 6736**Parameters** 6737 6738| Name | Type | Mandatory | Default Value | Description | 6739| ------ | ---------------------------------------- | ---- | ---- | ------- | 6740| config | [ScreenCaptureConfig](#screencaptureconfig10) | Yes | - | Screen capture configuration.| 6741 6742## EventResult<sup>12+</sup> 6743 6744Represents the event consumption result sent to the **Web** component. For details about the supported events, see [TouchType](../apis-arkui/arkui-ts/ts-appendix-enums.md#touchtype). If the application does not consume the event, set this parameter to **false**, and the event will be consumed by the **Web** component. If the application has consumed the event, set this parameter to **true**, and the event will not be consumed by the **Web** component. For the sample code, see [onNativeEmbedGestureEvent](#onnativeembedgestureevent11). 6745 6746### setGestureEventResult<sup>12+</sup> 6747 6748setGestureEventResult(result: boolean): void 6749 6750**Parameters** 6751 6752| Name | Type | Mandatory | Description | 6753| ------- | ------ | ---- | ------- | 6754| result | boolean | Yes | Whether to consume the gesture event.| 6755 6756**Example** 6757 6758See [onNativeEmbedGestureEvent](#onnativeembedgestureevent11). 6759 6760## ContextMenuSourceType<sup>9+</sup> 6761 6762| Name | Value| Description | 6763| --------- | -- |------------ | 6764| None | 0 | Other event sources.| 6765| Mouse | 1 | Mouse event. | 6766| LongPress | 2 | Long press event. | 6767 6768## ContextMenuMediaType<sup>9+</sup> 6769 6770| Name | Value| Description | 6771| ----- | -- | ------------- | 6772| None | 0 | Non-special media or other media types.| 6773| Image | 1 | Image. | 6774 6775## ContextMenuInputFieldType<sup>9+</sup> 6776 6777| Name | Value| Description | 6778| --------- | -- | --------------------------- | 6779| None | 0 | Non-input field. | 6780| PlainText | 1 | Plain text field, such as the text, search, or email field.| 6781| Password | 2 | Password field. | 6782| Number | 3 | Numeric field. | 6783| Telephone | 4 | Phone number field. | 6784| Other | 5 | Field of any other type. | 6785 6786## ContextMenuEditStateFlags<sup>9+</sup> 6787 6788Supports using with a bitwise OR operator. For example, to support CAN_CUT, CAN_COPY, and CAN_SELECT_ALL at the same time, use CAN_CUT | CAN_COPY | CAN_SELECT_ALL or 11. 6789 6790| Name | Value| Description | 6791| -------------- | -- | -------- | 6792| NONE | 0 | Editing is not allowed.| 6793| CAN_CUT | 1 | The cut operation is allowed.| 6794| CAN_COPY | 2 | The copy operation is allowed.| 6795| CAN_PASTE | 4 | The paste operation is allowed.| 6796| CAN_SELECT_ALL | 8 | The select all operation is allowed.| 6797 6798## WebContextMenuParam<sup>9+</sup> 6799 6800Implements a context menu, which is displayed after the user clicks the right mouse button or long presses a specific element, such as an image or a link. For the sample code, see [onContextMenuShow](#oncontextmenushow9). 6801 6802### x<sup>9+</sup> 6803 6804x(): number 6805 6806Obtains the X coordinate of the context menu. 6807 6808**Return value** 6809 6810| Type | Description | 6811| ------ | ------------------ | 6812| number | If the display is normal, a non-negative integer is returned. Otherwise, **-1** is returned.| 6813 6814### y<sup>9+</sup> 6815 6816y(): number 6817 6818Obtains the Y coordinate of the context menu. 6819 6820**Return value** 6821 6822| Type | Description | 6823| ------ | ------------------ | 6824| number | If the display is normal, a non-negative integer is returned. Otherwise, **-1** is returned.| 6825 6826### getLinkUrl<sup>9+</sup> 6827 6828getLinkUrl(): string 6829 6830Obtains the URL of the destination link. 6831 6832**Return value** 6833 6834| Type | Description | 6835| ------ | ------------------------- | 6836| string | If it is a link that is being long pressed, the URL that has passed the security check is returned.| 6837 6838### getUnfilteredLinkUrl<sup>9+</sup> 6839 6840getUnfilteredLinkUrl(): string 6841 6842Obtains the URL of the destination link. 6843 6844**Return value** 6845 6846| Type | Description | 6847| ------ | --------------------- | 6848| string | If it is a link that is being long pressed, the original URL is returned.| 6849 6850### getSourceUrl<sup>9+</sup> 6851 6852getSourceUrl(): string 6853 6854Obtain the source URL. 6855 6856**Return value** 6857 6858| Type | Description | 6859| ------ | ------------------------ | 6860| string | If the selected element has the **src** attribute, the URL in the **src** is returned.| 6861 6862### existsImageContents<sup>9+</sup> 6863 6864existsImageContents(): boolean 6865 6866Checks whether image content exists. 6867 6868**Return value** 6869 6870| Type | Description | 6871| ------- | ------------------------- | 6872| boolean | The value **true** means that there is image content in the element being long pressed, and **false** means the opposite.| 6873 6874### getMediaType<sup>9+</sup> 6875 6876getMediaType(): ContextMenuMediaType 6877 6878Obtains the media type of this web page element. 6879 6880**Return value** 6881 6882| Type | Description | 6883| ---------------------------------------- | --------- | 6884| [ContextMenuMediaType](#contextmenumediatype9) | Media type of the web page element.| 6885 6886### getSelectionText<sup>9+</sup> 6887 6888getSelectionText(): string 6889 6890Obtains the selected text. 6891 6892**Return value** 6893 6894| Type | Description | 6895| ------ | -------------------- | 6896| string | Selected text for the context menu. If no text is selected, null is returned.| 6897 6898### getSourceType<sup>9+</sup> 6899 6900getSourceType(): ContextMenuSourceType 6901 6902Obtains the event source of the context menu. 6903 6904**Return value** 6905 6906| Type | Description | 6907| ---------------------------------------- | ------- | 6908| [ContextMenuSourceType](#contextmenusourcetype9) | Event source of the context menu.| 6909 6910### getInputFieldType<sup>9+</sup> 6911 6912getInputFieldType(): ContextMenuInputFieldType 6913 6914Obtains the input field type of this web page element. 6915 6916**Return value** 6917 6918| Type | Description | 6919| ---------------------------------------- | ------ | 6920| [ContextMenuInputFieldType](#contextmenuinputfieldtype9) | Input field type.| 6921 6922### isEditable<sup>9+</sup> 6923 6924isEditable(): boolean 6925 6926Checks whether this web page element is editable. 6927 6928**Return value** 6929 6930| Type | Description | 6931| ------- | -------------------------- | 6932| boolean | Returns **true** if the web page element is editable; returns **false** otherwise.| 6933 6934### getEditStateFlags<sup>9+</sup> 6935 6936getEditStateFlags(): number 6937 6938Obtains the edit state flag of this web page element. 6939 6940**Return value** 6941 6942| Type | Description | 6943| ------ | ---------------------------------------- | 6944| number | Edit state flag of the web page element. For details, see [ContextMenuEditStateFlags](#contextmenueditstateflags9).| 6945 6946## WebContextMenuResult<sup>9+</sup> 6947 6948Implements a **WebContextMenuResult** object. For the sample code, see [onContextMenuShow](#oncontextmenushow9). 6949 6950### closeContextMenu<sup>9+</sup> 6951 6952closeContextMenu(): void 6953 6954Closes this context menu. This API must be called when no operations in **WebContextMenuResult** are performed. 6955 6956### copyImage<sup>9+</sup> 6957 6958copyImage(): void 6959 6960Copies the image specified in **WebContextMenuParam**. 6961 6962### copy<sup>9+</sup> 6963 6964copy(): void 6965 6966Copies text related to this context menu. 6967 6968### paste<sup>9+</sup> 6969 6970paste(): void 6971 6972Performs the paste operation related to this context menu. 6973 6974### cut<sup>9+</sup> 6975 6976cut(): void 6977 6978Performs the cut operation related to this context menu. 6979 6980### selectAll<sup>9+</sup> 6981 6982selectAll(): void 6983 6984Performs the select all operation related to this context menu. 6985 6986## JsGeolocation 6987 6988Implements the **PermissionRequest** object. For the sample code, see [onGeolocationShow Event](#ongeolocationshow). 6989 6990### constructor 6991 6992constructor() 6993 6994### invoke 6995 6996invoke(origin: string, allow: boolean, retain: boolean): void 6997 6998Sets the geolocation permission status of a web page. 6999 7000**Parameters** 7001 7002| Name | Type | Mandatory | Default Value | Description | 7003| ------ | ------- | ---- | ---- | ---------------------------------------- | 7004| origin | string | Yes | - | Index of the origin. | 7005| allow | boolean | Yes | - | Geolocation permission status. | 7006| retain | boolean | Yes | - | Whether the geolocation permission status can be saved to the system. You can manage the geolocation permissions saved to the system through [GeolocationPermissions<sup>9+</sup>](js-apis-webview.md#geolocationpermissions).| 7007 7008## MessageLevel 7009 7010| Name | Value| Description | 7011| ----- | -- | ---- | 7012| Debug | 1 | Debug level.| 7013| Error | 4 | Error level.| 7014| Info | 2 | Information level.| 7015| Log | 5 | Log level.| 7016| Warn | 3 | Warning level.| 7017 7018## RenderExitReason<sup>9+</sup> 7019 7020Enumerates the reasons why the rendering process exits. 7021 7022| Name | Value| Description | 7023| -------------------------- | -- | ----------------- | 7024| ProcessAbnormalTermination | 0 | The rendering process exits abnormally. | 7025| ProcessWasKilled | 1 | The rendering process receives a SIGKILL message or is manually terminated.| 7026| ProcessCrashed | 2 | The rendering process crashes due to segmentation or other errors. | 7027| ProcessOom | 3 | The program memory is running low. | 7028| ProcessExitUnknown | 4 | Other reason. | 7029 7030## MixedMode 7031 7032| Name | Value| Description | 7033| ---------- | -- | ---------------------------------- | 7034| All | 0 | HTTP and HTTPS hybrid content can be loaded. This means that all insecure content can be loaded.| 7035| Compatible | 1 | HTTP and HTTPS hybrid content can be loaded in compatibility mode. This means that some insecure content may be loaded. | 7036| None | 2 | HTTP and HTTPS hybrid content cannot be loaded. | 7037 7038## CacheMode<sup>9+</sup> 7039 7040| Name | Value| Description | 7041| ------- | -- | ------------------------------------ | 7042| Default | 0 | The cache that has not expired is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet.| 7043| None | 1 | The cache is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet. | 7044| Online | 2 | The cache is not used to load the resources. All resources are obtained from the Internet. | 7045| Only | 3 | The cache alone is used to load the resources. | 7046 7047## FileSelectorMode<sup>9+</sup> 7048 7049| Name | Value| Description | 7050| -------------------- | -- | ---------- | 7051| FileOpenMode | 0 | Open and upload a file. | 7052| FileOpenMultipleMode | 1 | Open and upload multiple files. | 7053| FileOpenFolderMode | 2 | Open and upload a folder.| 7054| FileSaveMode | 3 | Save a file. | 7055 7056 ## HitTestType 7057 7058| Name | Value| Description | 7059| ------------- | -- | ------------------------ | 7060| EditText | 0 | Editable area. | 7061| Email | 1 | Email address. | 7062| HttpAnchor | 2 | Hyperlink whose **src** is **http**. | 7063| HttpAnchorImg | 3 | Image with a hyperlink, where **src** is **http**.| 7064| Img | 4 | HTML::img tag. | 7065| Map | 5 | Geographical address. | 7066| Phone | 6 | Phone number. | 7067| Unknown | 7 | Unknown content. | 7068 7069 ## OverScrollMode<sup>11+</sup> 7070 7071| Name | Value| Description | 7072| ------ | -- | ----------- | 7073| NEVER | 0 | The overscroll mode is disabled.| 7074| ALWAYS | 1 | The overscroll mode is enabled.| 7075 7076## OnContextMenuHideCallback<sup>11+</sup> 7077 7078Implements the callback context menu customizes the hidden callback. 7079 7080## SslError<sup>9+</sup> 7081 7082Enumerates the error codes returned by **onSslErrorEventReceive** API. 7083 7084| Name | Value| Description | 7085| ------------ | -- | ----------- | 7086| Invalid | 0 | Minor error. | 7087| HostMismatch | 1 | The host name does not match. | 7088| DateInvalid | 2 | The certificate has an invalid date. | 7089| Untrusted | 3 | The certificate issuer is not trusted.| 7090 7091## ProtectedResourceType<sup>9+</sup> 7092 7093| Name | Value| Description | Remarks | 7094| --------------------------- | --------------- | ------------- | -------------------------- | 7095| MidiSysex | TYPE_MIDI_SYSEX | MIDI SYSEX resource.| Currently, only permission events can be reported. MIDI devices are not yet supported.| 7096| VIDEO_CAPTURE<sup>10+</sup> | TYPE_VIDEO_CAPTURE | Video capture resource, such as a camera. | | 7097| AUDIO_CAPTURE<sup>10+</sup> | TYPE_AUDIO_CAPTURE | Audio capture resource, such as a microphone.| | 7098| SENSOR<sup>12+</sup> | TYPE_SENSOR | Sensor resource, such as an acceleration sensor.| | 7099 7100## WebDarkMode<sup>9+</sup> 7101 7102| Name | Value| Description | 7103| ---- | -- | ------------ | 7104| Off | 0 | The web dark mode is disabled. | 7105| On | 1 | The web dark mode is enabled. | 7106| Auto | 2 | The web dark mode setting follows the system settings.| 7107 7108## WebCaptureMode<sup>10+</sup> 7109 7110| Name | Value| Description | 7111| ----------- | -- | ------- | 7112| HOME_SCREEN | 0 | Capture of the home screen.| 7113 7114## WebMediaOptions<sup>10+</sup> 7115 7116Describes the web-based media playback policy. 7117 7118| Name | Type | Readable | Writable | Mandatory | Description | 7119| -------------- | ------- | ---- | ---- | ---- | ---------------------------------------- | 7120| resumeInterval | number | Yes | Yes | No | Validity period for automatically resuming a paused web audio, in seconds. The maximum validity period is 60 seconds. Due to the approximate value, the validity period may have a deviation of less than 1 second.| 7121| audioExclusive | boolean | Yes | Yes | No | Whether the audio of multiple **Web** instances in an application is exclusive. | 7122 7123## ScreenCaptureConfig<sup>10+</sup> 7124 7125Provides the web screen capture configuration. 7126 7127| Name | Type | Readable | Writable | Mandatory | Description | 7128| ----------- | --------------------------------------- | ---- | ---- | ---- | ---------- | 7129| captureMode | [WebCaptureMode](#webcapturemode10) | Yes | Yes | Yes | Web screen capture mode.| 7130 7131## WebLayoutMode<sup>11+</sup> 7132 7133| Name | Value| Description | 7134| ----------- | -- | ------------------ | 7135| NONE | 0 | The web layout follows the system. | 7136| FIT_CONTENT | 1 | The web layout adapts to the page size.| 7137 7138## NestedScrollOptions<sup>11+</sup> 7139 7140| Name | Type | Description | 7141| -------------- | ---------------- | -------------------- | 7142| scrollForward | [NestedScrollMode](#nestedscrollmode11) | Nested scrolling options when the component scrolls forward.| 7143| scrollBackward | [NestedScrollMode](#nestedscrollmode11) | Nested scrolling options when the component scrolls backward.| 7144 7145## NestedScrollMode<sup>11+</sup> 7146 7147| Name | Value| Description | 7148| ------------ | -- | ---------------------------------------- | 7149| SELF_ONLY | 0 | The scrolling is contained within the component, and no scroll chaining occurs, that is, the parent component does not scroll when the component scrolling reaches the boundary. | 7150| SELF_FIRST | 1 | The component scrolls first, and when it hits the boundary, the parent component scrolls. When the parent component hits the boundary, its edge effect is displayed. If no edge effect is specified for the parent component, the edge effect of the child component is displayed instead.| 7151| PARENT_FIRST | 2 | The parent component scrolls first, and when it hits the boundary, the component scrolls. When the component hits the boundary, its edge effect is displayed. If no edge effect is specified for the component, the edge effect of the parent component is displayed instead.| 7152| PARALLEL | 3 | The component and its parent component scroll at the same time. When both the component and its parent component hit the boundary, the edge effect of the component is displayed. If no edge effect is specified for the component, the edge effect of the parent component is displayed instead.| 7153 7154## DataResubmissionHandler<sup>9+</sup> 7155 7156Implements the **DataResubmissionHandler** object for resubmitting or canceling the web form data. 7157 7158### resend<sup>9+</sup> 7159 7160resend(): void 7161 7162Resends the web form data. 7163 7164**Example** 7165 7166 ```ts 7167 // xxx.ets 7168 import { webview } from '@kit.ArkWeb'; 7169 7170 @Entry 7171 @Component 7172 struct WebComponent { 7173 controller: webview.WebviewController = new webview.WebviewController(); 7174 7175 build() { 7176 Column() { 7177 Web({ src: 'www.example.com', controller: this.controller }) 7178 .onDataResubmitted((event) => { 7179 console.log('onDataResubmitted'); 7180 event.handler.resend(); 7181 }) 7182 } 7183 } 7184 } 7185 ``` 7186 7187### cancel<sup>9+</sup> 7188 7189cancel(): void 7190 7191Cancels the resending of web form data. 7192 7193**Example** 7194 7195 ```ts 7196 // xxx.ets 7197 import { webview } from '@kit.ArkWeb'; 7198 7199 @Entry 7200 @Component 7201 struct WebComponent { 7202 controller: webview.WebviewController = new webview.WebviewController(); 7203 7204 build() { 7205 Column() { 7206 Web({ src: 'www.example.com', controller: this.controller }) 7207 .onDataResubmitted((event) => { 7208 console.log('onDataResubmitted'); 7209 event.handler.cancel(); 7210 }) 7211 } 7212 } 7213 } 7214 ``` 7215 7216 ## WebController 7217 7218Implements a **WebController** to control the behavior of the **Web** component. A **WebController** can control only one **Web** component, and the APIs in the **WebController** can be invoked only after it has been bound to the target **Web** component. 7219 7220This API is deprecated since API version 9. You are advised to use [WebviewController<sup>9+</sup>](js-apis-webview.md#webviewcontroller) instead. 7221 7222### Creating an Object 7223 7224```ts 7225let webController: WebController = new WebController() 7226``` 7227 7228### getCookieManager<sup>(deprecated)</sup> 7229 7230getCookieManager(): WebCookie 7231 7232Obtains the cookie management object of the **Web** component. 7233 7234This API is deprecated since API version 9. You are advised to use [getCookie](js-apis-webview.md#getcookiedeprecated) instead. 7235 7236**Return value** 7237 7238| Type | Description | 7239| --------- | ---------------------------------------- | 7240| WebCookie | Cookie management object. For details, see [WebCookie](#webcookiedeprecated).| 7241 7242**Example** 7243 7244 ```ts 7245 // xxx.ets 7246 @Entry 7247 @Component 7248 struct WebComponent { 7249 controller: WebController = new WebController() 7250 7251 build() { 7252 Column() { 7253 Button('getCookieManager') 7254 .onClick(() => { 7255 let cookieManager = this.controller.getCookieManager() 7256 }) 7257 Web({ src: 'www.example.com', controller: this.controller }) 7258 } 7259 } 7260 } 7261 ``` 7262 7263### requestFocus<sup>(deprecated)</sup> 7264 7265requestFocus() 7266 7267Requests focus for this web page. 7268 7269This API is deprecated since API version 9. You are advised to use [requestFocus<sup>9+</sup>](js-apis-webview.md#requestfocus) instead. 7270 7271**Example** 7272 7273 ```ts 7274 // xxx.ets 7275 @Entry 7276 @Component 7277 struct WebComponent { 7278 controller: WebController = new WebController() 7279 7280 build() { 7281 Column() { 7282 Button('requestFocus') 7283 .onClick(() => { 7284 this.controller.requestFocus() 7285 }) 7286 Web({ src: 'www.example.com', controller: this.controller }) 7287 } 7288 } 7289 } 7290 ``` 7291 7292### accessBackward<sup>(deprecated)</sup> 7293 7294accessBackward(): boolean 7295 7296Checks whether going to the previous page can be performed on the current page. 7297 7298This API is deprecated since API version 9. You are advised to use [accessBackward<sup>9+</sup>](js-apis-webview.md#accessbackward) instead. 7299 7300**Return value** 7301 7302| Type | Description | 7303| ------- | --------------------- | 7304| boolean | Returns **true** if going to the previous page can be performed on the current page; returns **false** otherwise.| 7305 7306**Example** 7307 7308 ```ts 7309 // xxx.ets 7310 @Entry 7311 @Component 7312 struct WebComponent { 7313 controller: WebController = new WebController() 7314 7315 build() { 7316 Column() { 7317 Button('accessBackward') 7318 .onClick(() => { 7319 let result = this.controller.accessBackward() 7320 console.log('result:' + result) 7321 }) 7322 Web({ src: 'www.example.com', controller: this.controller }) 7323 } 7324 } 7325 } 7326 ``` 7327 7328### accessForward<sup>(deprecated)</sup> 7329 7330accessForward(): boolean 7331 7332Checks whether going to the next page can be performed on the current page. 7333 7334This API is deprecated since API version 9. You are advised to use [accessForward<sup>9+</sup>](js-apis-webview.md#accessforward) instead. 7335 7336**Return value** 7337 7338| Type | Description | 7339| ------- | --------------------- | 7340| boolean | Returns **true** if going to the next page can be performed on the current page; returns **false** otherwise.| 7341 7342**Example** 7343 7344 ```ts 7345 // xxx.ets 7346 @Entry 7347 @Component 7348 struct WebComponent { 7349 controller: WebController = new WebController() 7350 7351 build() { 7352 Column() { 7353 Button('accessForward') 7354 .onClick(() => { 7355 let result = this.controller.accessForward() 7356 console.log('result:' + result) 7357 }) 7358 Web({ src: 'www.example.com', controller: this.controller }) 7359 } 7360 } 7361 } 7362 ``` 7363 7364### accessStep<sup>(deprecated)</sup> 7365 7366accessStep(step: number): boolean 7367 7368Performs a specific number of steps forward or backward from the current page. 7369 7370This API is deprecated since API version 9. You are advised to use [accessStep<sup>9+</sup>](js-apis-webview.md#accessstep) instead. 7371 7372**Parameters** 7373 7374| Name | Type | Mandatory | Default Value | Description | 7375| ---- | ------ | ---- | ---- | --------------------- | 7376| step | number | Yes | - | Number of the steps to take. A positive number means to go forward, and a negative number means to go backward.| 7377 7378**Return value** 7379 7380| Type | Description | 7381| ------- | --------- | 7382| boolean | Whether going forward or backward from the current page is successful.| 7383 7384**Example** 7385 7386 ```ts 7387 // xxx.ets 7388 @Entry 7389 @Component 7390 struct WebComponent { 7391 controller: WebController = new WebController() 7392 @State steps: number = 2 7393 7394 build() { 7395 Column() { 7396 Button('accessStep') 7397 .onClick(() => { 7398 let result = this.controller.accessStep(this.steps) 7399 console.log('result:' + result) 7400 }) 7401 Web({ src: 'www.example.com', controller: this.controller }) 7402 } 7403 } 7404 } 7405 ``` 7406 7407### backward<sup>(deprecated)</sup> 7408 7409backward(): void 7410 7411Goes to the previous page based on the history stack. This API is generally used together with **accessBackward**. 7412 7413This API is deprecated since API version 9. You are advised to use [backward<sup>9+</sup>](js-apis-webview.md#backward) instead. 7414 7415**Example** 7416 7417 ```ts 7418 // xxx.ets 7419 @Entry 7420 @Component 7421 struct WebComponent { 7422 controller: WebController = new WebController() 7423 7424 build() { 7425 Column() { 7426 Button('backward') 7427 .onClick(() => { 7428 this.controller.backward() 7429 }) 7430 Web({ src: 'www.example.com', controller: this.controller }) 7431 } 7432 } 7433 } 7434 ``` 7435 7436### forward<sup>(deprecated)</sup> 7437 7438forward(): void 7439 7440Goes to the next page based on the history stack. This API is generally used together with **accessForward**. 7441 7442This API is deprecated since API version 9. You are advised to use [forward<sup>9+</sup>](js-apis-webview.md#forward) instead. 7443 7444**Example** 7445 7446 ```ts 7447 // xxx.ets 7448 @Entry 7449 @Component 7450 struct WebComponent { 7451 controller: WebController = new WebController() 7452 7453 build() { 7454 Column() { 7455 Button('forward') 7456 .onClick(() => { 7457 this.controller.forward() 7458 }) 7459 Web({ src: 'www.example.com', controller: this.controller }) 7460 } 7461 } 7462 } 7463 ``` 7464 7465### deleteJavaScriptRegister<sup>(deprecated)</sup> 7466 7467deleteJavaScriptRegister(name: string) 7468 7469Deletes a specific application JavaScript object that is registered with the window through **registerJavaScriptProxy**. The deletion takes effect immediately, with no need for invoking the [refresh](#refreshdeprecated) API. 7470 7471This API is deprecated since API version 9. You are advised to use [deleteJavaScriptRegister<sup>9+</sup>](js-apis-webview.md#deletejavascriptregister) instead. 7472 7473**Parameters** 7474 7475| Name | Type | Mandatory | Default Value | Description | 7476| ---- | ------ | ---- | ---- | ---------------------------------------- | 7477| name | string | Yes | - | Name of the registered JavaScript object, which can be used to invoke the corresponding object on the application side from the web side.| 7478 7479**Example** 7480 7481 ```ts 7482 // xxx.ets 7483 @Entry 7484 @Component 7485 struct WebComponent { 7486 controller: WebController = new WebController() 7487 @State name: string = 'Object' 7488 7489 build() { 7490 Column() { 7491 Button('deleteJavaScriptRegister') 7492 .onClick(() => { 7493 this.controller.deleteJavaScriptRegister(this.name) 7494 }) 7495 Web({ src: 'www.example.com', controller: this.controller }) 7496 } 7497 } 7498 } 7499 ``` 7500 7501### getHitTest<sup>(deprecated)</sup> 7502 7503getHitTest(): HitTestType 7504 7505Obtains the element type of the area being clicked. 7506 7507This API is deprecated since API version 9. You are advised to use [getHitTest<sup>9+</sup>](js-apis-webview.md#gethittest) instead. 7508 7509**Return value** 7510 7511| Type | Description | 7512| ------------------------------- | ----------- | 7513| [HitTestType](#hittesttype)| Element type of the area being clicked.| 7514 7515**Example** 7516 7517 ```ts 7518 // xxx.ets 7519 @Entry 7520 @Component 7521 struct WebComponent { 7522 controller: WebController = new WebController() 7523 7524 build() { 7525 Column() { 7526 Button('getHitTest') 7527 .onClick(() => { 7528 let hitType = this.controller.getHitTest() 7529 console.log("hitType: " + hitType) 7530 }) 7531 Web({ src: 'www.example.com', controller: this.controller }) 7532 } 7533 } 7534 } 7535 ``` 7536 7537### loadData<sup>(deprecated)</sup> 7538 7539loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string }) 7540 7541Loads data. If **baseUrl** is empty, the specified character string will be loaded using the data protocol. 7542 7543If **baseUrl** is set to a data URL, the encoded string will be loaded by the **Web** component using the data protocol. 7544 7545If **baseUrl** is set to an HTTP or HTTPS URL, the encoded string will be processed by the **Web** component as a non-encoded string in a manner similar to **loadUrl**. 7546 7547This API is deprecated since API version 9. You are advised to use [loadData<sup>9+</sup>](js-apis-webview.md#loaddata) instead. 7548 7549**Parameters** 7550 7551| Name | Type | Mandatory | Default Value | Description | 7552| ---------- | ------ | ---- | ---- | ---------------------------------------- | 7553| data | string | Yes | - | Character string obtained after being Base64 or URL encoded. | 7554| mimeType | string | Yes | - | Media type (MIME). | 7555| encoding | string | Yes | - | Encoding type, which can be Base64 or URL. | 7556| baseUrl | string | No | - | URL (HTTP/HTTPS/data compliant), which is assigned by the **Web** component to **window.origin**.| 7557| historyUrl | string | No | - | Historical record URL. If this parameter is not empty, it can be managed in historical records to implement page going backward and forward. This parameter is invalid when **baseUrl** is left empty.| 7558 7559**Example** 7560 7561 ```ts 7562 // xxx.ets 7563 @Entry 7564 @Component 7565 struct WebComponent { 7566 controller: WebController = new WebController() 7567 7568 build() { 7569 Column() { 7570 Button('loadData') 7571 .onClick(() => { 7572 this.controller.loadData({ 7573 data: "<html><body bgcolor=\"white\">Source:<pre>source</pre></body></html>", 7574 mimeType: "text/html", 7575 encoding: "UTF-8" 7576 }) 7577 }) 7578 Web({ src: 'www.example.com', controller: this.controller }) 7579 } 7580 } 7581 } 7582 ``` 7583 7584### loadUrl<sup>(deprecated)</sup> 7585 7586loadUrl(options: { url: string | Resource, headers?: Array\<Header\> }) 7587 7588Loads a URL using the specified HTTP header. 7589 7590The object injected through **loadUrl** is valid only in the current document. It will be invalid on a new page navigated to through **loadUrl**. 7591 7592The object injected through **registerJavaScriptProxy** is still valid on a new page redirected through **loadUrl**. 7593 7594This API is deprecated since API version 9. You are advised to use [loadUrl<sup>9+</sup>](js-apis-webview.md#loadurl) instead. 7595 7596**Parameters** 7597 7598| Name | Type | Mandatory | Default Value | Description | 7599| ------- | -------------------------- | ---- | ---- | -------------- | 7600| url | string \| Resource | Yes | - | URL to load. | 7601| headers | Array\<[Header](#header)\> | No | [] | Additional HTTP request header of the URL.| 7602 7603**Example** 7604 7605 ```ts 7606 // xxx.ets 7607 @Entry 7608 @Component 7609 struct WebComponent { 7610 controller: WebController = new WebController() 7611 7612 build() { 7613 Column() { 7614 Button('loadUrl') 7615 .onClick(() => { 7616 this.controller.loadUrl({ url: 'www.example.com' }) 7617 }) 7618 Web({ src: 'www.example.com', controller: this.controller }) 7619 } 7620 } 7621 } 7622 ``` 7623 7624### onActive<sup>(deprecated)</sup> 7625 7626onActive(): void 7627 7628Called when the **Web** component enters the active state. 7629 7630This API is deprecated since API version 9. You are advised to use [onActive<sup>9+</sup>](js-apis-webview.md#onactive) instead. 7631 7632**Example** 7633 7634 ```ts 7635 // xxx.ets 7636 @Entry 7637 @Component 7638 struct WebComponent { 7639 controller: WebController = new WebController() 7640 7641 build() { 7642 Column() { 7643 Button('onActive') 7644 .onClick(() => { 7645 this.controller.onActive() 7646 }) 7647 Web({ src: 'www.example.com', controller: this.controller }) 7648 } 7649 } 7650 } 7651 ``` 7652 7653### onInactive<sup>(deprecated)</sup> 7654 7655onInactive(): void 7656 7657Called when the **Web** component enters the inactive state. 7658 7659This API is deprecated since API version 9. You are advised to use [onInactive<sup>9+</sup>](js-apis-webview.md#oninactive) instead. 7660 7661**Example** 7662 7663 ```ts 7664 // xxx.ets 7665 @Entry 7666 @Component 7667 struct WebComponent { 7668 controller: WebController = new WebController() 7669 7670 build() { 7671 Column() { 7672 Button('onInactive') 7673 .onClick(() => { 7674 this.controller.onInactive() 7675 }) 7676 Web({ src: 'www.example.com', controller: this.controller }) 7677 } 7678 } 7679 } 7680 ``` 7681 7682### zoom<sup>(deprecated)</sup> 7683zoom(factor: number): void 7684 7685Sets a zoom factor for the current web page. 7686 7687This API is deprecated since API version 9. You are advised to use [zoom<sup>9+</sup>](js-apis-webview.md#zoom) instead. 7688 7689**Parameters** 7690 7691| Name | Type | Mandatory | Description | 7692| ------ | ------ | ---- | ------------------------------ | 7693| factor | number | Yes | Zoom factor to set. A positive value indicates zoom-in, and a negative value indicates zoom-out.| 7694 7695**Example** 7696 7697 ```ts 7698 // xxx.ets 7699 @Entry 7700 @Component 7701 struct WebComponent { 7702 controller: WebController = new WebController() 7703 @State factor: number = 1 7704 7705 build() { 7706 Column() { 7707 Button('zoom') 7708 .onClick(() => { 7709 this.controller.zoom(this.factor) 7710 }) 7711 Web({ src: 'www.example.com', controller: this.controller }) 7712 } 7713 } 7714 } 7715 ``` 7716 7717### refresh<sup>(deprecated)</sup> 7718 7719refresh() 7720 7721Called when the **Web** component refreshes the web page. 7722 7723This API is deprecated since API version 9. You are advised to use [refresh<sup>9+</sup>](js-apis-webview.md#refresh) instead. 7724 7725**Example** 7726 7727 ```ts 7728 // xxx.ets 7729 @Entry 7730 @Component 7731 struct WebComponent { 7732 controller: WebController = new WebController() 7733 7734 build() { 7735 Column() { 7736 Button('refresh') 7737 .onClick(() => { 7738 this.controller.refresh() 7739 }) 7740 Web({ src: 'www.example.com', controller: this.controller }) 7741 } 7742 } 7743 } 7744 ``` 7745 7746### registerJavaScriptProxy<sup>(deprecated)</sup> 7747 7748registerJavaScriptProxy(options: { object: object, name: string, methodList: Array\<string\> }) 7749 7750Registers a JavaScript object with the window. APIs of this object can then be invoked in the window. You must invoke the [refresh](#refreshdeprecated) API for the registration to take effect. 7751 7752This API is deprecated since API version 9. You are advised to use [registerJavaScriptProxy<sup>9+</sup>](js-apis-webview.md#registerjavascriptproxy) instead. 7753 7754**Parameters** 7755 7756| Name | Type | Mandatory | Default Value | Description | 7757| ---------- | --------------- | ---- | ---- | ---------------------------------------- | 7758| object | object | Yes | - | Application-side JavaScript object to be registered. Methods and attributes can be declared, but cannot be directly called on HTML5. The parameters and return value can only be of the string, number, or Boolean type.| 7759| name | string | Yes | - | Name of the object to be registered, which is the same as that invoked in the window. After registration, the window can use this name to access the JavaScript object at the application side.| 7760| methodList | Array\<string\> | Yes | - | Methods of the JavaScript object to be registered at the application side. | 7761 7762**Example** 7763 7764 ```ts 7765 // xxx.ets 7766 class TestObj { 7767 constructor() { 7768 } 7769 7770 test(): string { 7771 return "ArkUI Web Component" 7772 } 7773 7774 toString(): void { 7775 console.log('Web Component toString') 7776 } 7777 } 7778 7779 @Entry 7780 @Component 7781 struct Index { 7782 controller: WebController = new WebController() 7783 testObj = new TestObj(); 7784 build() { 7785 Column() { 7786 Row() { 7787 Button('Register JavaScript To Window').onClick(() => { 7788 this.controller.registerJavaScriptProxy({ 7789 object: this.testObj, 7790 name: "objName", 7791 methodList: ["test", "toString"], 7792 }) 7793 }) 7794 } 7795 Web({ src: $rawfile('index.html'), controller: this.controller }) 7796 .javaScriptAccess(true) 7797 } 7798 } 7799 } 7800 ``` 7801 7802 HTML file to be loaded: 7803 ```html 7804 <!-- index.html --> 7805 <!DOCTYPE html> 7806 <html> 7807 <meta charset="utf-8"> 7808 <body> 7809 Hello world! 7810 </body> 7811 <script type="text/javascript"> 7812 function htmlTest() { 7813 str = objName.test("test function") 7814 console.log('objName.test result:'+ str) 7815 } 7816 </script> 7817 </html> 7818 7819 ``` 7820 7821### runJavaScript<sup>(deprecated)</sup> 7822 7823runJavaScript(options: { script: string, callback?: (result: string) => void }) 7824 7825Executes a JavaScript script. This API uses an asynchronous callback to return the script execution result. **runJavaScript** can be invoked only after **loadUrl** is executed. For example, it can be invoked in **onPageEnd**. 7826 7827This API is deprecated since API version 9. You are advised to use [runJavaScript<sup>9+</sup>](js-apis-webview.md#runjavascript) instead. 7828 7829**Parameters** 7830 7831| Name | Type | Mandatory | Default Value | Description | 7832| -------- | ------------------------ | ---- | ---- | ---------------------------------------- | 7833| script | string | Yes | - | JavaScript script. | 7834| callback | (result: string) => void | No | - | Callback used to return the result. Returns **null** if the JavaScript script fails to be executed or no value is returned.| 7835 7836**Example** 7837 7838 ```ts 7839 // xxx.ets 7840 @Entry 7841 @Component 7842 struct WebComponent { 7843 controller: WebController = new WebController() 7844 @State webResult: string = '' 7845 build() { 7846 Column() { 7847 Text(this.webResult).fontSize(20) 7848 Web({ src: $rawfile('index.html'), controller: this.controller }) 7849 .javaScriptAccess(true) 7850 .onPageEnd((event) => { 7851 this.controller.runJavaScript({ 7852 script: 'test()', 7853 callback: (result: string)=> { 7854 this.webResult = result 7855 console.info(`The test() return value is: ${result}`) 7856 }}) 7857 if (event) { 7858 console.info('url: ', event.url) 7859 } 7860 }) 7861 } 7862 } 7863 } 7864 ``` 7865 HTML file to be loaded: 7866 ```html 7867 <!-- index.html --> 7868 <!DOCTYPE html> 7869 <html> 7870 <meta charset="utf-8"> 7871 <body> 7872 Hello world! 7873 </body> 7874 <script type="text/javascript"> 7875 function test() { 7876 console.log('Ark WebComponent') 7877 return "This value is from index.html" 7878 } 7879 </script> 7880 </html> 7881 ``` 7882 7883### stop<sup>(deprecated)</sup> 7884 7885stop() 7886 7887Stops page loading. 7888 7889This API is deprecated since API version 9. You are advised to use [stop<sup>9+</sup>](js-apis-webview.md#stop) instead. 7890 7891**Example** 7892 7893 ```ts 7894 // xxx.ets 7895 @Entry 7896 @Component 7897 struct WebComponent { 7898 controller: WebController = new WebController() 7899 7900 build() { 7901 Column() { 7902 Button('stop') 7903 .onClick(() => { 7904 this.controller.stop() 7905 }) 7906 Web({ src: 'www.example.com', controller: this.controller }) 7907 } 7908 } 7909 } 7910 ``` 7911 7912### clearHistory<sup>(deprecated)</sup> 7913 7914clearHistory(): void 7915 7916Clears the browsing history. 7917 7918This API is deprecated since API version 9. You are advised to use [clearHistory<sup>9+</sup>](js-apis-webview.md#clearhistory) instead. 7919 7920**Example** 7921 7922 ```ts 7923 // xxx.ets 7924 @Entry 7925 @Component 7926 struct WebComponent { 7927 controller: WebController = new WebController() 7928 7929 build() { 7930 Column() { 7931 Button('clearHistory') 7932 .onClick(() => { 7933 this.controller.clearHistory() 7934 }) 7935 Web({ src: 'www.example.com', controller: this.controller }) 7936 } 7937 } 7938 } 7939 ``` 7940 7941## WebCookie<sup>(deprecated)</sup> 7942 7943Manages behavior of cookies in **Web** components. All **Web** components in an application share a **WebCookie**. You can use the **getCookieManager** API in **controller** to obtain the **WebCookie** for subsequent cookie management. 7944 7945### setCookie<sup>(deprecated)</sup> 7946 7947setCookie() 7948 7949Sets the cookie. This API returns the result synchronously. Returns **true** if the operation is successful; returns **false** otherwise. 7950 7951This API is deprecated since API version 9. You are advised to use [setCookie<sup>9+</sup>](js-apis-webview.md#setcookie) instead. 7952 7953### saveCookie<sup>(deprecated)</sup> 7954 7955saveCookie() 7956 7957Saves the cookies in the memory to the drive. This API returns the result synchronously. 7958 7959This API is deprecated since API version 9. You are advised to use [saveCookieAsync<sup>9+</sup>](js-apis-webview.md#savecookieasync) instead. 7960 7961## ScriptItem<sup>11+</sup> 7962 7963Describes the **ScriptItem** object injected to the **Web** component through the [javaScriptOnDocumentStart](#javascriptondocumentstart11) attribute. 7964 7965| Name | Type | Mandatory | Description | 7966| ----------- | -------------- | ---- | --------------------- | 7967| script | string | Yes | JavaScript script to be injected and executed.| 7968| scriptRules | Array\<string> | Yes | Matching rules for allowed sources.<br>1. To allow URLs from all sources, use the wildcard (\*).<br>2. If exact match is required, specify the exact URL, for example, **https:\//www\\.example.com**.<br>3. For fuzzy match, you can use a wildcard (\*) in the website URL, for example, **https://\*.example.com**. Websites such as "x,*.y.com" and "* foobar.com" are not allowed. <br>4. If the source is an IP address, follow rule 2.<br>5. For protocols other than HTTP/HTTPS (user-defined protocols), exact match and fuzzy match are not supported, and the protocol must end with a slash (/), for example, **resource://**.<br>6. If one of the preceding rules is not met in the **scriptRules**, the **scriptRules** does not take effect.| 7969 7970## WebNavigationType<sup>11+</sup> 7971 7972Defines the navigation type. 7973 7974| Name | Value| Description | 7975| ----------------------------- | -- | ------------ | 7976| UNKNOWN | 0 | Unknown type. | 7977| MAIN_FRAME_NEW_ENTRY | 1 | Navigation to a new history entry from the main document. | 7978| MAIN_FRAME_EXISTING_ENTRY | 2 | Navigation to an existing history entry from the main document.| 7979| NAVIGATION_TYPE_NEW_SUBFRAME | 4 | User-triggered navigation from a subdocument.| 7980| NAVIGATION_TYPE_AUTO_SUBFRAME | 5 | Non-user-triggered navigation from a subdocument.| 7981 7982## LoadCommittedDetails<sup>11+</sup> 7983 7984Provides detailed information about the web page that has been submitted for redirection. 7985 7986| Name | Type | Mandatory | Description | 7987| ----------- | ------------------------------------ | ---- | --------------------- | 7988| isMainFrame | boolean | Yes | Whether the document is the main document.| 7989| isSameDocument | boolean | Yes | Whether to navigate without changing the document. Example of navigation in the same document: 1. navigation shown in the example; 2. navigation triggered by **pushState** or **replaceState**; 3. navigation to a history entry on the same page. | 7990| didReplaceEntry | boolean | Yes | Whether the submitted new entry replaces the existing entry. In certain scenarios for navigation to a subdocument, although the existing entry is not replaced, some attributes are changed. | 7991| navigationType | [WebNavigationType](#webnavigationtype11) | Yes | Navigation type. | 7992| url | string | Yes | URL of the current navigated-to web page. | 7993 7994## ThreatType<sup>11+</sup> 7995 7996Enumerates the website threat types. 7997 7998| Name | Value| Description | 7999| ---------------- | -- | ----------------------| 8000| THREAT_ILLEGAL | 0 | Illegal website. | 8001| THREAT_FRAUD | 1 | Fraudulent website. | 8002| THREAT_RISK | 2 | Website that poses security risks. | 8003| THREAT_WARNING | 3 | Website suspected to contain unsafe content.| 8004 8005## OnNavigationEntryCommittedCallback<sup>11+</sup> 8006 8007type OnNavigationEntryCommittedCallback = (loadCommittedDetails: [LoadCommittedDetails](#loadcommitteddetails11)) => void 8008 8009Called when a navigation item is submitted. 8010 8011| Name | Type | Description | 8012| -------------------- | ------------------------------------------------ | ------------------- | 8013| loadCommittedDetails | [LoadCommittedDetails](#loadcommitteddetails11) | Detailed information about the web page that has been submitted for redirection.| 8014 8015## OnSafeBrowsingCheckResultCallback<sup>11+</sup> 8016 8017type OnSafeBrowsingCheckResultCallback = (threatType: ThreatType) => void 8018 8019Called by a website safe browsing check. 8020 8021| Name | Type | Description | 8022| ---------- | ---------------------------- | ------------------- | 8023| threatType | [ThreatType](#threattype11) | Website threat type. | 8024 8025## FullScreenEnterEvent<sup>12+</sup> 8026 8027Provides details about the callback event for the **Web** component to enter the full-screen mode. 8028 8029| Name | Type | Mandatory | Description | 8030| ----------- | ------------------------------------ | ---- | --------------------- | 8031| handler | [FullScreenExitHandler](#fullscreenexithandler9) | Yes | Function handle for exiting full screen mode.| 8032| videoWidth | number | No | Video width, in px. If the element that enters fulls screen mode is a **\<video>** element, the value represents its width; if the element that enters fulls screen mode contains a **\<video>** element, the value represents the width of the first sub-video element; in other cases, the value is **0**.| 8033| videoHeight | number | No | Video height, in px. If the element that enters fulls screen mode is a **\<video>** element, the value represents its height; if the element that enters fulls screen mode contains a **\<video>** element, the value represents the height of the first sub-video element; in other cases, the value is **0**.| 8034 8035## OnFullScreenEnterCallback<sup>12+</sup> 8036 8037type OnFullScreenEnterCallback = (event: FullScreenEnterEvent) => void 8038 8039Called when the **Web** component enters full screen mode. 8040 8041| Name | Type | Description | 8042| ---------- | ---------------------------- | ------------------- | 8043| event | [FullScreenEnterEvent](#fullscreenenterevent12) | Callback event for the **Web** component to enter full screen mode.| 8044 8045## SslErrorEvent<sup>12+</sup> 8046 8047Provides details about the callback invoked when an SSL error occurs during resource loading. 8048 8049| Name | Type | Description | 8050| ------- | ------------------------------------ | -------------- | 8051| handler | [SslErrorHandler](#sslerrorhandler9) | User operation.| 8052| error | [SslError](#sslerror9) | Error code. | 8053| url | string | URL. | 8054| originalUrl | string | Original URL of the request. | 8055| referrer | string | Referrer URL. | 8056| isFatalError | boolean | Whether the error is a fatal error. | 8057| isMainFrame | boolean | Whether the request is made for the main frame. | 8058 8059 8060## OnSslErrorEventCallback<sup>12+</sup> 8061 8062type OnSslErrorEventCallback = (sslErrorEvent: SslErrorEvent) => void 8063 8064Provides details about the callback invoked when an SSL error occurs during resource loading. 8065 8066| Name | Type | Description | 8067| ---------- | ---------------------------- | ------------------- | 8068| sslErrorEvent | [SslErrorEvent](#sslerrorevent12) | Details about the callback invoked when an SSL error occurs during resource loading.| 8069 8070## NativeEmbedStatus<sup>11+</sup> 8071 8072Defines the lifecycle of the **embed** tag. When the same-layer rendering tag exists on the loaded page, **CREATE** is triggered. When the same-layer rendering tag is moved or is enlarged, **UPDATE **is triggered. When the page exits, **DESTROY** is triggered. 8073 8074| Name | Value| Description | 8075| ----------------------------- | -- | ------------ | 8076| CREATE | 0 | The tag is created. | 8077| UPDATE | 1 | The tag is updated. | 8078| DESTROY | 2 | The tag is destroyed.| 8079| ENTER_BFCACHE<sup>12+</sup> | 3 | The tag enters the BFCache. | 8080| LEAVE_BFCACHE<sup>12+</sup> | 4 | The tag leaves the BFCache.| 8081 8082## NativeEmbedInfo<sup>11+</sup> 8083 8084Provides detailed information about the **\<embed>** tag. 8085 8086| Name | Type | Mandatory | Description | 8087|-------------------| ------------------------------------ | ---- |---------------------------| 8088| id | string | No | ID of the tag. | 8089| type | string | No | Type of the tag. The value is in lowercase. | 8090| src | string | No | **src** information of the tag. | 8091| width | number | No | Width of the tag, in px. | 8092| height | number | No | Height of the tag, in px. | 8093| url | string | No | URL of the tag. | 8094| tag<sup>12+</sup> | string | No | Name of the tag, which consists of uppercase letters. | 8095| params<sup>12+</sup> | map<string, string> | No | List of key-value pairs contained in the **object** tag that form a map of the Object type. Use the methods provided by the Object type to operate the map object. | 8096| position<sup>12+</sup> | Position | No | Position of the same-layer tag relative to the **Web** component in the screen coordinate system, which is different from the standard **Position**. The unit is px.| 8097 8098## NativeEmbedDataInfo<sup>11+</sup> 8099 8100Provides detailed information about the lifecycle changes of the **\<embed>** tag. 8101 8102| Name | Type | Mandatory | Description | 8103| ----------- | ------------------------------------ | ---- | --------------------- | 8104| status | [NativeEmbedStatus](#nativeembedstatus11) | No | Lifecycle status of the tag.| 8105| surfaceId | string | No | Surface ID of the native image. | 8106| embedId | string | No | Unique ID of the tag. | 8107| info | [NativeEmbedInfo](#nativeembedinfo11) | No | Detailed information about the tag. | 8108## NativeEmbedTouchInfo<sup>11+</sup> 8109 8110Provides touch information of the **\<embed>** tag. 8111 8112| Name | Type | Mandatory | Description | 8113| ----------- | ------------------------------------ | ---- | --------------------- | 8114| embedId | string | No | Unique ID of the tag.| 8115| touchEvent | [TouchEvent](../apis-arkui/arkui-ts/ts-universal-events-touch.md#touchevent) | No | Touch action information.| 8116| result<sup>12+</sup> | [EventResult](#eventresult12) | No | Gesture event consumption result.| 8117 8118## FirstMeaningfulPaint<sup>12+</sup> 8119 8120Provides detailed information about the first meaningful paint. 8121 8122| Name | Type | Mandatory| Description | 8123| ------------------------ | ------ | ---- | -------------------------------------- | 8124| navigationStartTime | number | No | Navigation bar loading time, in microseconds. | 8125| firstMeaningfulPaintTime | number | No | Time taken for the first meaningful paint of the page, in milliseconds.| 8126 8127## OnFirstMeaningfulPaintCallback<sup>12+</sup> 8128 8129type OnFirstMeaningfulPaintCallback = (firstMeaningfulPaint: [FirstMeaningfulPaint](#firstmeaningfulpaint12)) => void 8130 8131Called when the first meaningful paint occurs on the web page. 8132 8133| Name | Type | Description | 8134| -------------------- | ----------------------------------------------- | -------------------------------- | 8135| firstMeaningfulPaint | [FirstMeaningfulPaint](#firstmeaningfulpaint12) | Information about the first meaningful paint.| 8136 8137## LargestContentfulPaint<sup>12+</sup> 8138 8139Provides detailed information about the largest content paint. 8140 8141| Name | Type | Mandatory| Description | 8142| ------------------------- | ------ | ---- | ---------------------------------------- | 8143| navigationStartTime | number | No | Navigation bar loading time, in microseconds. | 8144| largestImagePaintTime | number | No | Maximum image loading time, in milliseconds. | 8145| largestTextPaintTime | number | No | Maximum text loading time, in milliseconds. | 8146| largestImageLoadStartTime | number | No | Maximum time for an image to start loading, in milliseconds.| 8147| largestImageLoadEndTime | number | No | Maximum time for an image to finish loading, in milliseconds.| 8148| imageBPP | number | No | Maximum number of image pixels. | 8149 8150## OnLargestContentfulPaintCallback<sup>12+</sup> 8151 8152type OnLargestContentfulPaintCallback = (largestContentfulPaint: [LargestContentfulPaint](#largestcontentfulpaint12 8153)) => void 8154 8155Called when the largest content paint occurs on the web page. 8156 8157| Name | Type | Description | 8158| ---------------------- | --------------------------------------------------- | ------------------------------------ | 8159| largestContentfulPaint | [LargestContentfulPaint](#largestcontentfulpaint12) | Information about the largest content paint.| 8160 8161## IntelligentTrackingPreventionDetails<sup>12+</sup> 8162 8163Provides detailed information about intelligent tracking prevention. 8164 8165| Name | Type | Mandatory | Description | 8166| ------------- | ------------------------------------| ----- | ------------ | 8167| host | string | Yes | Domain name. | 8168| trackerHost | string | Yes | Domain name of the tracker. | 8169 8170## OnIntelligentTrackingPreventionCallback<sup>12+</sup> 8171 8172type OnIntelligentTrackingPreventionCallback = (details: IntelligentTrackingPreventionDetails) => void 8173 8174Represents the callback invoked when the tracker cookie is intercepted. 8175 8176| Name | Type | Description | 8177| ------- | -------------------------------------------------------------------------------- | ------------------------- | 8178| details | [IntelligentTrackingPreventionDetails](#intelligenttrackingpreventiondetails12) | Detailed information about intelligent tracking prevention.| 8179 8180## OnOverrideUrlLoadingCallback<sup>12+</sup> 8181 8182type OnOverrideUrlLoadingCallback = (webResourceRequest: WebResourceRequest) => boolean 8183 8184Represents a callback for **onOverrideUrlLoading**. 8185 8186**Parameters** 8187 8188| Name | Type | Description | 8189| -------------------- | ------------------------------------------------ | ------------------- | 8190| webResourceRequest | [WebResourceRequest](#webresourcerequest) | Information about the URL request.| 8191 8192**Return value** 8193 8194| Type | Description | 8195| ------- | ------------------------ | 8196| boolean | Returns **true** if the access is blocked; returns **false** otherwise.| 8197 8198## RenderMode<sup>12+</sup> 8199 8200Enumerates the rendering modes of the **Web** component. 8201 8202| Name | Value| Description | 8203| ----------------------------- | -- | ------------ | 8204| ASYNC_RENDER | 0 | The **Web** component is rendered asynchronously. | 8205| SYNC_RENDER | 1 | The **Web** component is rendered synchronously within the current execution context. | 8206 8207## NativeMediaPlayerConfig<sup>12+</sup> 8208 8209type NativeMediaPlayerConfig = { enable: boolean, shouldOverlay: boolean } 8210 8211Represents the configuration for [enabling the application to take over web page media playback](#enablenativemediaplayer12). 8212 8213**System capability**: SystemCapability.Web.Webview.Core 8214 8215| Name| Type| Read Only| Mandatory| Description| 8216|------|------|------|------|------| 8217| enable | boolean | No| Yes| Whether to enable the feature.<br> **true**: enabled<br> **false** (default): disabled| 8218| shouldOverlay | boolean | No| Yes| Whether the video player's display overlays the web page content when the application takes over the web page's video player.<br> **true**: The video player's display overlays the web page content. This means that the height of the video layer is adjusted to cover the web page content.<br> **false** (default): The video player's display does not overlay the web page content. This means that the video player maintains its original height and is embedded within the web page.| 8219 8220## RenderProcessNotRespondingReason<sup>12+</sup> 8221 8222Provides the reason why the rendering process does not respond. 8223 8224| Name | Value| Description | 8225| ----------------------------- | -- | ------------ | 8226| INPUT_TIMEOUT | 0 | The response to the input event sent to the rendering process times out. | 8227| NAVIGATION_COMMIT_TIMEOUT | 1 | The navigation for loading a new web page times out. | 8228 8229## RenderProcessNotRespondingData<sup>12+</sup> 8230 8231Provides detailed information about the unresponsive rendering process. 8232 8233| Name | Type | Mandatory| Description | 8234| ------------------------ | ------ | ---- | -------------------------------------- | 8235| jsStack | string | Yes | JavaScript call stack information of the web page. | 8236| pid | number | Yes | Process ID of the web page.| 8237| reason | [RenderProcessNotRespondingReason](#renderprocessnotrespondingreason12) | Yes | The reason why the rendering process does not respond.| 8238 8239## OnRenderProcessNotRespondingCallback<sup>12+</sup> 8240 8241type OnRenderProcessNotRespondingCallback = (data : RenderProcessNotRespondingData) => void 8242 8243Represents a callback invoked when the rendering process does not respond. 8244 8245| Name | Type | Description | 8246| -------------------- | ----------------------------------------------- | -------------------------------- | 8247| data | [RenderProcessNotRespondingData](#renderprocessnotrespondingdata12) | Detailed information about the unresponsive rendering process. | 8248 8249## OnRenderProcessRespondingCallback<sup>12+</sup> 8250 8251type OnRenderProcessRespondingCallback = () => void 8252 8253Represents a callback invoked when the rendering process transitions back to a normal operating state from an unresponsive state. 8254 8255## ViewportFit<sup>12+</sup> 8256 8257Enumerates the viewport types available for **viewport-fit** in the web page **\<meta>** tag. 8258 8259| Name | Value| Description | 8260| ----------------------------- | -- | ------------ | 8261| AUTO | 0 | The entire web page is visible. Default value. | 8262| CONTAINS | 1 | The initial layout viewport and the visual viewport fit within the largest rectangle that adapts to the device's display screen. | 8263| COVER | 2| The initial layout viewport and the visual viewport are confined within the bounding rectangle of the device's physical screen. | 8264 8265## OnViewportFitChangedCallback<sup>12+</sup> 8266 8267type OnViewportFitChangedCallback = (viewportFit: ViewportFit) => void 8268 8269Represents the callback invoked when the **viewport-fit** configuration in the web page's **\<meta>** tag changes. 8270 8271| Name | Type | Description | 8272| -------------------- | ----------------------------------------------- | -------------------------------- | 8273| viewportFit | [ViewportFit](#viewportfit12) | Viewport type for **viewport-fit** in the web page **\<meta>** tag.| 8274 8275## ExpandedMenuItemOptions<sup>12+</sup> 8276 8277Defines the custom expanded menu options. 8278 8279| Name | Type | Mandatory | Description | 8280| ---------- | -----------------------------------------------------| ------ | ---------------- | 8281| content | [ResourceStr](../apis-arkui/arkui-ts/ts-types.md#resourcestr) | Yes | Content to display. | 8282| startIcon | [ResourceStr](../apis-arkui/arkui-ts/ts-types.md#resourcestr) | No | Icon to display. | 8283| action | (selectedText: {plainText: string}) => void | Yes | Selected text.| 8284 8285## WebKeyboardAvoidMode<sup>12+</sup> 8286 8287Enumerates the soft keyboard avoidance modes. 8288 8289| Name | Value| Description | 8290| ------------------ | -- | ------------ | 8291| RESIZE_VISUAL | 0 | For soft keyboard avoidance, the visual viewport is resized, but not the layout viewport. | 8292| RESIZE_CONTENT | 1 | For soft keyboard avoidance, both the visual viewport and layout viewport are resized. Default value.| 8293| OVERLAYS_CONTENT | 2 | No viewport is resized, and soft keyboard avoidance is not triggered. | 8294 8295## OnPageEndEvent<sup>12+</sup> 8296 8297Represents the callback invoked when the web page loading ends. 8298 8299| Name | Type | Mandatory | Description | 8300| -------------- | ---- | ---- | ---------------------------------------- | 8301| url | string | Yes| URL of the page. | 8302 8303## OnPageBeginEvent<sup>12+</sup> 8304 8305Represents the callback invoked when the web page loading begins. 8306 8307| Name | Type | Mandatory | Description | 8308| -------------- | ---- | ---- | ---------------------------------------- | 8309| url | string | Yes| URL of the page. | 8310 8311## OnProgressChangeEvent<sup>12+</sup> 8312 8313Represents the callback invoked when the web page loading progress changes. 8314 8315| Name | Type | Mandatory | Description | 8316| -------------- | ---- | ---- | ---------------------------------------- | 8317| newProgress | number | Yes| New loading progress. The value is an integer ranging from 0 to 100. | 8318 8319## OnTitleReceiveEvent<sup>12+</sup> 8320 8321Represents the callback invoked when the document title of the web page is changed. 8322 8323| Name | Type | Mandatory | Description | 8324| -------------- | ---- | ---- | ---------------------------------------- | 8325| title | string | Yes| Document title. | 8326 8327## OnGeolocationShowEvent<sup>12+</sup> 8328 8329Represents the callback invoked when a request to obtain the geolocation information is received. 8330 8331| Name | Type | Mandatory | Description | 8332| -------------- | ---- | ---- | ---------------------------------------- | 8333| origin | string | Yes| Index of the origin. | 8334| geolocation | [JsGeolocation](#jsgeolocation) | Yes| User operation. | 8335 8336## OnAlertEvent<sup>12+</sup> 8337 8338Represents the callback invoked when **alert()** is invoked to display an alert dialog box on the web page. 8339 8340| Name | Type | Mandatory | Description | 8341| -------------- | ---- | ---- | ---------------------------------------- | 8342| url | string | Yes| URL of the web page where the dialog box is displayed. | 8343| message | string | Yes| Message displayed in the dialog box. | 8344| result | [JsResult](#jsresult) | Yes| User operation. | 8345 8346## OnBeforeUnloadEvent<sup>12+</sup> 8347 8348Represents the callback invoked when this page is about to exit after the user refreshes or closes the page. 8349 8350| Name | Type | Mandatory | Description | 8351| -------------- | ---- | ---- | ---------------------------------------- | 8352| url | string | Yes| URL of the web page where the dialog box is displayed. | 8353| message | string | Yes| Message displayed in the dialog box. | 8354| result | [JsResult](#jsresult) | Yes| User operation. | 8355 8356## OnConfirmEvent<sup>12+</sup> 8357 8358Represents the callback invoked when **confirm()** is invoked by the web page. 8359 8360| Name | Type | Mandatory | Description | 8361| -------------- | ---- | ---- | ---------------------------------------- | 8362| url | string | Yes| URL of the web page where the dialog box is displayed. | 8363| message | string | Yes| Message displayed in the dialog box. | 8364| result | [JsResult](#jsresult) | Yes| User operation. | 8365 8366## OnPromptEvent<sup>12+</sup> 8367 8368Represents the callback invoked when **prompt()** is invoked by the web page. 8369 8370| Name | Type | Mandatory | Description | 8371| -------------- | ---- | ---- | ---------------------------------------- | 8372| url | string | Yes| URL of the web page where the dialog box is displayed. | 8373| message | string | Yes| Message displayed in the dialog box. | 8374| result | [JsResult](#jsresult) | Yes| User operation. | 8375 8376## onConsoleEvent<sup>12+</sup> 8377 8378Represents the callback invoked to notify the host application of a JavaScript console message. 8379 8380| Name | Type | Mandatory | Description | 8381| -------------- | ---- | ---- | ---------------------------------------- | 8382| message | [ConsoleMessage](#consolemessage) | Yes| Console message. | 8383 8384## OnErrorReceiveEvent<sup>12+</sup> 8385 8386Represents the callback invoked when an error occurs during web page loading. 8387 8388| Name | Type | Mandatory | Description | 8389| -------------- | ---- | ---- | ---------------------------------------- | 8390| request | [WebResourceRequest](#webresourcerequest) | Yes| Encapsulation of a web page request. | 8391| error | [WebResourceError](#webresourceerror) | Yes| Encapsulation of a web page resource loading error.| 8392 8393## OnHttpErrorReceiveEvent<sup>12+</sup> 8394 8395Represents the callback invoked when an HTTP error occurs during web page resource loading. 8396 8397| Name | Type | Mandatory | Description | 8398| -------------- | ---- | ---- | ---------------------------------------- | 8399| request | [WebResourceRequest](#webresourcerequest) | Yes| Encapsulation of a web page request. | 8400| response | [WebResourceResponse](#webresourceresponse) | Yes| Encapsulation of a resource response.| 8401 8402## OnDownloadStartEvent<sup>12+</sup> 8403 8404Represents the callback invoked when the main application starts downloading a file. 8405 8406| Name | Type | Mandatory | Description | 8407| -------------- | ---- | ---- | ---------------------------------------- | 8408| url | string | Yes| URL for the download task. | 8409| userAgent | string | Yes| User agent used for download. | 8410| contentDisposition | string | Yes| Content-Disposition response header returned by the server, which may be empty.| 8411| mimetype | string | Yes| MIME type of the content returned by the server. | 8412| contentLength | number | Yes| Length of the content returned by the server. | 8413 8414## OnRefreshAccessedHistoryEvent<sup>12+</sup> 8415 8416Represents the callback invoked when the access history of the web page is refreshed. 8417 8418| Name | Type | Mandatory | Description | 8419| -------------- | ---- | ---- | ---------------------------------------- | 8420| url | string | Yes| URL to be accessed. | 8421| isRefreshed | boolean | Yes| Whether the page is reloaded. The value **true** means that the page is reloaded by invoking the [refresh<sup>9+</sup>](js-apis-webview.md#refresh) API, and **false** means the opposite.| 8422 8423## OnRenderExitedEvent<sup>12+</sup> 8424 8425Represents the callback invoked when the rendering process exits. 8426 8427| Name | Type | Mandatory | Description | 8428| -------------- | ---- | ---- | ---------------------------------------- | 8429| renderExitReason | [RenderExitReason](#renderexitreason9) | Yes| Cause for the abnormal exit of the rendering process.| 8430 8431## OnShowFileSelectorEvent<sup>12+</sup> 8432 8433Represents the callback invoked to notify the file selector result. 8434 8435| Name | Type | Mandatory | Description | 8436| -------------- | ---- | ---- | ---------------------------------------- | 8437| result | [FileSelectorResult](#fileselectorresult9) | Yes| File selection result to be sent to the **Web** component.| 8438| fileSelector | [FileSelectorParam](#fileselectorparam9) | Yes| Information about the file selector. | 8439 8440## onResourceLoadEvent<sup>12+</sup> 8441 8442Represents the callback invoked when the URL is loaded. 8443 8444| Name | Type | Mandatory | Description | 8445| -------------- | ---- | ---- | ---------------------------------------- | 8446| url | string | Yes| URL of the loaded resource file.| 8447 8448## onScaleChangeEvent<sup>12+</sup> 8449 8450Represents the callback invoked when the display scale of this page changes. 8451 8452| Name | Type | Mandatory | Description | 8453| -------------- | ---- | ---- | ---------------------------------------- | 8454| oldScale | number | Yes| Display ratio of the page before the change.| 8455| newScale | number | Yes| Display ratio of the page after the change.| 8456 8457## OnHttpAuthRequestEvent<sup>12+</sup> 8458 8459Represents the callback invoked when an HTTP authentication request is received. 8460 8461| Name | Type | Mandatory | Description | 8462| -------------- | ---- | ---- | ---------------------------------------- | 8463| handler | [HttpAuthHandler](#httpauthhandler9) | Yes| User operation. | 8464| host | string | Yes| Host to which HTTP authentication credentials apply.| 8465| realm | string | Yes| Realm to which HTTP authentication credentials apply. | 8466 8467## OnInterceptRequestEvent<sup>12+</sup> 8468 8469Represents the callback invoked when the **Web** component is about to load a URL. 8470 8471| Name | Type | Mandatory | Description | 8472| -------------- | ---- | ---- | ---------------------------------------- | 8473| request | [WebResourceRequest](#webresourcerequest) | Yes| Information about the URL request.| 8474 8475## onPermissionRequestEvent<sup>12+</sup> 8476 8477Represents the callback invoked when a permission request is received. 8478 8479| Name | Type | Mandatory | Description | 8480| -------------- | ---- | ---- | ---------------------------------------- | 8481| request | [PermissionRequest](#permissionrequest9) | Yes| User operation.| 8482 8483## onScreenCaptureRequestEvent<sup>12+</sup> 8484 8485Represents the callback invoked when a screen capture request is received. 8486 8487| Name | Type | Mandatory | Description | 8488| -------------- | ---- | ---- | ---------------------------------------- | 8489| handler | [ScreenCaptureHandler](#screencapturehandler10) | Yes| User operation.| 8490 8491## onContextMenuShowEvent<sup>12+</sup> 8492 8493Represents the callback invoked during a call to allow for the display of a custom context menu. 8494 8495| Name | Type | Mandatory | Description | 8496| -------------- | ---- | ---- | ---------------------------------------- | 8497| param | [WebContextMenuParam](#webcontextmenuparam9) | Yes| Parameters related to the context menu. | 8498| result | [WebContextMenuResult](#webcontextmenuresult9) | Yes| Result of the context menu.| 8499 8500## onSearchResultReceiveEvent<sup>12+</sup> 8501 8502Represents the callback invoked to notify the caller of the search result on the web page. 8503 8504| Name | Type | Mandatory | Description | 8505| -------------- | ---- | ---- | ---------------------------------------- | 8506| activeMatchOrdinal | number | Yes| Sequence number of the current match, which starts from 0. | 8507| numberOfMatches | number | Yes| Total number of matches. | 8508| isDoneCounting | boolean | Yes| Whether the search operation on the current page is complete. This API may be called multiple times until **isDoneCounting** is **true**.| 8509 8510## onScrollEvent<sup>12+</sup> 8511 8512Represents the callback invoked when the scrollbar scrolls to a specified position. 8513 8514| Name | Type | Mandatory | Description | 8515| -------------- | ---- | ---- | ---------------------------------------- | 8516| xOffset | number | Yes| Position of the scrollbar on the x-axis relative to the leftmost of the web page.| 8517| yOffset | number | Yes| Position of the scrollbar on the y-axis relative to the top of the web page.| 8518 8519## OnSslErrorEventReceiveEvent<sup>12+</sup> 8520 8521Represents the callback invoked when the web page receives an SSL error. 8522 8523| Name | Type | Mandatory | Description | 8524| -------------- | ---- | ---- | ---------------------------------------- | 8525| handler | [SslErrorHandler](#sslerrorhandler9) | Yes| User operation.| 8526| error | [SslError](#sslerror9) | Yes| Error code. | 8527 8528## onClientAuthenticationRequestEvent<sup>12+</sup> 8529 8530Represents the callback invoked when an SSL client certificate is required from the user. 8531 8532| Name | Type | Mandatory | Description | 8533| -------------- | ---- | ---- | ---------------------------------------- | 8534| handler | [ClientAuthenticationHandler](#clientauthenticationhandler9) | Yes| User operation. | 8535| host | string | Yes| Host name of the server that requests a certificate. | 8536| port | number | Yes| Port number of the server that requests a certificate. | 8537| keyTypes | Array<string\> | Yes| Acceptable asymmetric private key types. | 8538| issuers | Array<string\> | Yes| Issuer of the certificate that matches the private key.| 8539 8540## OnWindowNewEvent<sup>12+</sup> 8541 8542Represents the callback invoked when the web page requests the user to create a new window. 8543 8544| Name | Type | Mandatory | Description | 8545| -------------- | ---- | ---- | ---------------------------------------- | 8546| isAlert | boolean | Yes| Whether to open the target URL in a new window. The value **true** means to open the target URL in a new window, and **false** means to open the target URL in a new tab. | 8547| isUserTrigger | boolean | Yes| Whether the creation is triggered by the user. The value **true** means that the creation is triggered by the user, and **false** means the opposite. | 8548| targetUrl | string | Yes| Target URL. | 8549| handler | [ControllerHandler](#controllerhandler9) | Yes| **WebviewController** instance for setting the new window.| 8550 8551## onTouchIconUrlReceivedEvent<sup>12+</sup> 8552 8553Represents the callback invoked when an apple-touch-icon URL is received. 8554 8555| Name | Type | Mandatory | Description | 8556| -------------- | ---- | ---- | ---------------------------------------- | 8557| url | string | Yes| Received apple-touch-icon URL.| 8558| precomposed | boolean | Yes| Whether the apple-touch-icon is precomposed. | 8559 8560## onFaviconReceivedEvent<sup>12+</sup> 8561 8562Represents the callback invoked when this web page receives a new favicon. 8563 8564| Name | Type | Mandatory | Description | 8565| -------------- | ---- | ---- | ---------------------------------------- | 8566| favicon | [PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes| **PixelMap** object of the received favicon.| 8567 8568## onPageVisibleEvent<sup>12+</sup> 8569 8570Represents the callback invoked when the old page is not displayed and the new page is about to be visible. 8571 8572| Name | Type | Mandatory | Description | 8573| -------------- | ---- | ---- | ---------------------------------------- | 8574| url | string | Yes| URL of the new page that is able to be visible when the old page is not displayed.| 8575 8576## onDataResubmittedEvent<sup>12+</sup> 8577 8578Represents the callback invoked when the web form data can be resubmitted. 8579 8580| Name | Type | Mandatory | Description | 8581| -------------- | ---- | ---- | ---------------------------------------- | 8582| handler | [DataResubmissionHandler](#dataresubmissionhandler9) | Yes| Handler for resubmitting web form data.| 8583 8584## onAudioStateChangedEvent<sup>12+</sup> 8585 8586Represents the callback invoked when the audio playback status on the web page changes. 8587 8588| Name | Type | Mandatory | Description | 8589| -------------- | ---- | ---- | ---------------------------------------- | 8590| playing | boolean | Yes| Audio playback status on the current page. The value **true** means that audio is being played, and **false** means the opposite.| 8591 8592## onFirstContentfulPaintEvent<sup>12+</sup> 8593 8594Represents the callback invoked when the first content paint occurs on the web page. 8595 8596| Name | Type | Mandatory | Description | 8597| -------------- | ---- | ---- | ---------------------------------------- | 8598| navigationStartTick | number | Yes| Navigation start time, in microseconds. | 8599| firstContentfulPaintMs | number | Yes| Time between navigation and when the content is first rendered, in milliseconds.| 8600 8601## onLoadInterceptEvent<sup>12+</sup> 8602 8603Represents the callback invoked when the **Web** component is about to access a URL. 8604 8605| Name | Type | Mandatory | Description | 8606| -------------- | ---- | ---- | ---------------------------------------- | 8607| data | [WebResourceRequest](#webresourcerequest) | Yes| Information about the URL request.| 8608 8609## onOverScrollEvent<sup>12+</sup> 8610 8611Represents the callback invoked when the web page is overscrolled. 8612 8613| Name | Type | Mandatory | Description | 8614| -------------- | ---- | ---- | ---------------------------------------- | 8615| xOffset | number | Yes| Horizontal overscroll offset based on the leftmost edge of the web page.| 8616| yOffset | number | Yes| Vertical overscroll offset based on the top edge of the web page.| 8617 8618## JavaScriptProxy<sup>12+</sup> 8619 8620Defines the JavaScript object to be injected. 8621 8622| Name | Type | Mandatory | Description | 8623| -------------- | ---- | ---- | ---------------------------------------- | 8624| object | object | Yes | Object to be registered. Methods can be declared, but attributes cannot. | 8625| name | string | Yes | Name of the object to be registered, which is the same as that invoked in the window. | 8626| methodList | Array\<string\> | Yes | Synchronous methods of the JavaScript object to be registered at the application side. | 8627| controller | [WebviewController<sup>9+</sup>](js-apis-webview.md#webviewcontroller) \| [WebController](#webcontroller) | Yes | - | Controller. This API is deprecated since API version 9. You are advised to use **WebviewController** instead.| 8628| asyncMethodList<sup>12+</sup> | Array\<string\> | No | Asynchronous methods of the JavaScript object to be registered at the application side. Asynchronous methods do not provide return values. | 8629| permission<sup>12+</sup> | string | No | JSON string, which is empty by default. This string is used to configure JSBridge permission control and define the URL trustlist at the object and method levels.<br>For the example, see [Invoking Application Functions on the Frontend Page](../../web/web-in-page-app-function-invoking.md). | 8630 8631## AdsBlockedDetails<sup>12+</sup> 8632 8633Provides detailed information about the blocked ads when ads are blocked. 8634 8635| Name| Type | Description | 8636| ------- | -------------------------------------------------------------------------------- | ------------------------- | 8637| url | string | URL of the page where ads are blocked.| 8638| adsBlocked | Array\<string\> | URLs or DOMPath of the blocked ads. If ads have the same URLs, duplicate elements may exist.| 8639 8640## OnAdsBlockedCallback<sup>12+</sup> 8641 8642type OnAdsBlockedCallback = (details: AdsBlockedDetails) => void 8643 8644Represents the callback invoked when ads are blocked on the web page. 8645**Parameters** 8646 8647| Name | Type | Description | 8648| -------------------- | ----------------------------------------------- | -------------------------------- | 8649| details | [AdsBlockedDetails](#adsblockeddetails12) | Detailed information about the blocked ads when ads are blocked.| 8650 8651## NativeEmbedVisibilityInfo<sup>12+</sup> 8652 8653Provides visibility information of the **embed** tag. 8654 8655| Name | Type | Mandatory | Description | 8656| ------------- | ------------------------------------| ----- | ------------------ | 8657| visibility | boolean | No | Whether the **embed** tag is visible. | 8658| embedId | string | No | ID of the same-layer rendering tag. | 8659 8660## OnNativeEmbedVisibilityChangeCallback<sup>12+</sup> 8661 8662type OnNativeEmbedVisibilityChangeCallback = (nativeEmbedVisibilityInfo: NativeEmbedVisibilityInfo) => void 8663 8664Represents the callback invoked when the visibility of an **embed** tag changes. 8665 8666| Name | Type | Description | 8667| ------- | -------------------------------------------------------------------------------- | ------------------------- | 8668| nativeEmbedVisibilityInfo | [NativeEmbedVisibilityInfo](#nativeembedvisibilityinfo12) | The visibility information about the **embed** tag.| 8669