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