ts-basic-components-web.md 143.5 KB
Newer Older
E
ester.zhou 已提交
1 2
# Web

E
ester.zhou 已提交
3 4
The **<Web\>** component can be used to display web pages.

5 6 7 8
> **NOTE**
>
> - This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
> - You can preview how this component looks on a real device. The preview is not yet available in the DevEco Studio Previewer.
E
ester.zhou 已提交
9

E
ester.zhou 已提交
10
## Required Permissions
E
ester.zhou 已提交
11
To 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-guidelines.md).
E
ester.zhou 已提交
12

E
ester.zhou 已提交
13 14
## Child Components

E
ester.zhou 已提交
15
Not supported
E
ester.zhou 已提交
16 17 18

## APIs

E
ester.zhou 已提交
19 20 21 22 23
Web(options: { src: ResourceStr, controller: WebController })

> **NOTE**
>
> Transition animation is not supported.
24 25

**Parameters**
E
ester.zhou 已提交
26 27 28 29 30

| Name       | Type                           | Mandatory  | Description   |
| ---------- | ------------------------------- | ---- | ------- |
| src        | [ResourceStr](ts-types.md)                           | Yes   | Address of a web page resource.|
| controller | [WebController](#webcontroller) | No   | Controller.   |
31 32

**Example**
E
ester.zhou 已提交
33 34

  Loading Online Web Pages
35 36 37 38 39
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
40
    controller: WebController = new WebController();
41 42
    build() {
      Column() {
E
ester.zhou 已提交
43
        Web({ src: 'www.example.com', controller: this.controller })
44 45 46 47
      }
    }
  }
  ```
E
ester.zhou 已提交
48

E
ester.zhou 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
  Loading Local Web Pages
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    build() {
      Column() {
        Web({ src: $rawfile("index.html"), controller: this.controller })
      }
    }
  }
  ```

  ```html
  <!-- index.html -->
  <!DOCTYPE html>
  <html>
      <body>
          <p>Hello World</p>
      </body>
  </html>
  ```
E
ester.zhou 已提交
73 74

## Attributes
75 76 77 78 79 80 81 82 83 84

The **\<Web>** component has network attributes.

### domStorageAccess

domStorageAccess(domStorageAccess: boolean)

Sets whether to enable the DOM Storage API. By default, this feature is disabled.

**Parameters**
E
ester.zhou 已提交
85

86 87 88 89 90
| Name             | Type   | Mandatory  | Default Value | Description                                |
| ---------------- | ------- | ---- | ---- | ------------------------------------ |
| domStorageAccess | boolean | Yes   | false | Whether to enable the DOM Storage API.|

**Example**
E
ester.zhou 已提交
91

92 93 94 95 96
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
97
    controller: WebController = new WebController();
98 99
    build() {
      Column() {
E
ester.zhou 已提交
100 101
        Web({ src: 'www.example.com', controller: this.controller })
          .domStorageAccess(true)
102 103 104 105 106 107 108 109 110 111 112 113
      }
    }
  }
  ```

### fileAccess

fileAccess(fileAccess: boolean)

Sets whether to enable the access to the file system in the application. By default, this feature is disabled. Access to the files specified through [$rawfile(filepath/filename)](../../ui/ts-resource-access.md) are not affected by this attribute.

**Parameters**
E
ester.zhou 已提交
114

115 116
| Name       | Type   | Mandatory  | Default Value | Description                                    |
| ---------- | ------- | ---- | ---- | ---------------------------------------- |
E
ester.zhou 已提交
117
| fileAccess | boolean | Yes   | true | Whether to enable the access to the file system in the application.|
118 119

**Example**
E
ester.zhou 已提交
120

121 122 123 124 125
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
126
    controller: WebController = new WebController();
127 128
    build() {
      Column() {
E
ester.zhou 已提交
129 130
        Web({ src: 'www.example.com', controller: this.controller })
          .fileAccess(true)
131 132 133 134 135 136 137 138 139 140 141 142
      }
    }
  }
  ```

### fileFromUrlAccess<sup>9+</sup>

fileFromUrlAccess(fileFromUrlAccess: boolean)

Sets whether to allow the use of JavaScript scripts on web pages for access to content in the application file system. By default, this feature is disabled. Access to the files specified through [$rawfile(filepath/filename)](../../ui/ts-resource-access.md) are not affected by this attribute.

**Parameters**
E
ester.zhou 已提交
143

144 145
| Name              | Type   | Mandatory  | Default Value  | Description                                    |
| ----------------- | ------- | ---- | ----- | ---------------------------------------- |
E
ester.zhou 已提交
146
| fileFromUrlAccess | boolean | Yes   | false | Whether to allow the use of JavaScript scripts on web pages for access to content in the application file system. By default, this feature is disabled.|
147 148

**Example**
E
ester.zhou 已提交
149

150 151 152 153 154
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
155
    controller: WebController = new WebController();
156 157
    build() {
      Column() {
E
ester.zhou 已提交
158 159
        Web({ src: 'www.example.com', controller: this.controller })
          .fileFromUrlAccess(true)
160 161 162 163 164 165 166 167 168 169 170 171
      }
    }
  }
  ```

### imageAccess

imageAccess(imageAccess: boolean)

Sets whether to enable automatic image loading. By default, this feature is enabled.

**Parameters**
E
ester.zhou 已提交
172

173 174
| Name        | Type   | Mandatory  | Default Value | Description           |
| ----------- | ------- | ---- | ---- | --------------- |
E
ester.zhou 已提交
175
| imageAccess | boolean | Yes   | true | Whether to enable automatic image loading. By default, this feature is enabled.|
176 177 178 179 180 181 182

**Example**
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
183
    controller: WebController = new WebController();
184 185
    build() {
      Column() {
E
ester.zhou 已提交
186 187
        Web({ src: 'www.example.com', controller: this.controller })
          .imageAccess(true)
188 189 190 191 192 193 194 195 196 197 198 199 200
      }
    }
  }
  ```

### javaScriptProxy

javaScriptProxy(javaScriptProxy: { object: object, name: string, methodList: Array\<string\>,
    controller: WebController })

Injects a JavaScript object into the window. Methods of this object can be invoked in the window. The parameters cannot be updated.

**Parameters**
E
ester.zhou 已提交
201

202 203 204 205 206
| Name       | Type           | Mandatory  | Default Value | Description                     |
| ---------- | --------------- | ---- | ---- | ------------------------- |
| object     | object          | Yes   | -    | Object to be registered. Methods can be declared, but not attributes.   |
| name       | string          | Yes   | -    | Name of the object to be registered, which is the same as that invoked in the window.|
| methodList | Array\<string\> | Yes   | -    | Methods of the JavaScript object to be registered at the application side. |
E
ester.zhou 已提交
207
| controller | [WebController](#webcontroller) | No   | -    | Controller.   |
208 209

**Example**
E
ester.zhou 已提交
210

211 212 213 214 215
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
216
    controller: WebController = new WebController();
217 218 219 220 221 222 223 224 225 226 227 228 229
    testObj = {
      test: (data1, data2, data3) => {
        console.log("data1:" + data1);
        console.log("data2:" + data2);
        console.log("data3:" + data3);
        return "AceString";
      },
      toString: () => {
        console.log('toString' + "interface instead.");
      }
    }
    build() {
      Column() {
E
ester.zhou 已提交
230 231 232 233 234 235 236
        Web({ src: 'www.example.com', controller: this.controller })
          .javaScriptAccess(true)
          .javaScriptProxy({
            object: this.testObj,
            name: "objName",
            methodList: ["test", "toString"],
            controller: this.controller,
237 238 239 240 241 242 243 244 245 246 247 248 249
        })
      }
    }
  }
  ```

### javaScriptAccess

javaScriptAccess(javaScriptAccess: boolean)

Sets whether JavaScript scripts can be executed. By default, JavaScript scripts can be executed.

**Parameters**
E
ester.zhou 已提交
250

251 252 253 254 255
| Name             | Type   | Mandatory  | Default Value | Description               |
| ---------------- | ------- | ---- | ---- | ------------------- |
| javaScriptAccess | boolean | Yes   | true | Whether JavaScript scripts can be executed.|

**Example**
E
ester.zhou 已提交
256

257 258 259 260 261
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
262
    controller: WebController = new WebController();
263 264
    build() {
      Column() {
E
ester.zhou 已提交
265 266
        Web({ src: 'www.example.com', controller: this.controller })
          .javaScriptAccess(true)
267 268 269 270 271 272 273 274 275 276 277 278
      }
    }
  }
  ```

### mixedMode

mixedMode(mixedMode: MixedMode)

Sets whether to enable loading of HTTP and HTTPS hybrid content can be loaded. By default, this feature is disabled.

**Parameters**
E
ester.zhou 已提交
279

280 281
| Name      | Type                       | Mandatory  | Default Value | Description     |
| --------- | --------------------------- | ---- | ---- | --------- |
E
ester.zhou 已提交
282
| mixedMode | [MixedMode](#mixedmode)| Yes   | MixedMode.None | Mixed content to load.|
283 284

**Example**
E
ester.zhou 已提交
285

286 287 288 289 290
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
291 292
    controller: WebController = new WebController();
    @State mode: MixedMode = MixedMode.All;
293 294
    build() {
      Column() {
E
ester.zhou 已提交
295 296
        Web({ src: 'www.example.com', controller: this.controller })
          .mixedMode(this.mode)
297 298 299 300 301 302 303 304 305 306 307 308
      }
    }
  }
  ```

### onlineImageAccess

onlineImageAccess(onlineImageAccess: boolean)

Sets whether to enable access to online images through HTTP and HTTPS. By default, this feature is enabled.

**Parameters**
E
ester.zhou 已提交
309

310 311 312 313 314
| Name              | Type   | Mandatory  | Default Value | Description            |
| ----------------- | ------- | ---- | ---- | ---------------- |
| onlineImageAccess | boolean | Yes   | true | Whether to enable access to online images through HTTP and HTTPS.|

**Example**
E
ester.zhou 已提交
315

316 317 318 319 320
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
321
    controller: WebController = new WebController();
322 323
    build() {
      Column() {
E
ester.zhou 已提交
324 325
        Web({ src: 'www.example.com', controller: this.controller })
          .onlineImageAccess(true)
326 327 328 329 330 331 332 333 334 335 336 337
      }
    }
  }
  ```

### zoomAccess

zoomAccess(zoomAccess: boolean)

Sets whether to enable zoom gestures. By default, this feature is enabled.

**Parameters**
E
ester.zhou 已提交
338

339 340 341 342 343
| Name       | Type   | Mandatory  | Default Value | Description         |
| ---------- | ------- | ---- | ---- | ------------- |
| zoomAccess | boolean | Yes   | true | Whether to enable zoom gestures.|

**Example**
E
ester.zhou 已提交
344

345 346 347 348 349
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
350
    controller: WebController = new WebController();
351 352
    build() {
      Column() {
E
ester.zhou 已提交
353 354
        Web({ src: 'www.example.com', controller: this.controller })
          .zoomAccess(true)
355 356 357 358 359 360 361 362 363 364 365 366
      }
    }
  }
  ```

### overviewModeAccess

overviewModeAccess(overviewModeAccess: boolean)

Sets whether to load web pages by using the overview mode. By default, this feature is enabled.

**Parameters**
E
ester.zhou 已提交
367

368 369
| Name               | Type   | Mandatory  | Default Value | Description           |
| ------------------ | ------- | ---- | ---- | --------------- |
E
ester.zhou 已提交
370
| overviewModeAccess | boolean | Yes   | true | Whether to load web pages by using the overview mode.|
371 372

**Example**
E
ester.zhou 已提交
373

374 375 376 377 378
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
379
    controller: WebController = new WebController();
380 381
    build() {
      Column() {
E
ester.zhou 已提交
382 383
        Web({ src: 'www.example.com', controller: this.controller })
          .overviewModeAccess(true)
384 385 386 387 388 389 390 391 392 393 394 395
      }
    }
  }
  ```

### databaseAccess

databaseAccess(databaseAccess: boolean)

Sets whether to enable database access. By default, this feature is disabled.

**Parameters**
E
ester.zhou 已提交
396

397 398
| Name           | Type   | Mandatory  | Default Value | Description             |
| -------------- | ------- | ---- | ---- | ----------------- |
E
ester.zhou 已提交
399
| databaseAccess | boolean | Yes   | false | Whether to enable database access.|
400 401

**Example**
E
ester.zhou 已提交
402

403 404 405 406 407
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
408
    controller: WebController = new WebController();
409 410
    build() {
      Column() {
E
ester.zhou 已提交
411 412
        Web({ src: 'www.example.com', controller: this.controller })
          .databaseAccess(true)
413 414 415 416 417 418 419 420 421 422 423 424
      }
    }
  }
  ```

### geolocationAccess

geolocationAccess(geolocationAccess: boolean)

Sets whether to enable geolocation access. By default, this feature is enabled.

**Parameters**
E
ester.zhou 已提交
425

426 427
| Name           | Type   | Mandatory  | Default Value | Description             |
| -------------- | ------- | ---- | ---- | ----------------- |
E
ester.zhou 已提交
428
| geolocationAccess | boolean | Yes   | true    | Whether to enable geolocation access.|
429 430

**Example**
E
ester.zhou 已提交
431

432 433 434 435 436
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
437
    controller: WebController = new WebController();
438 439
    build() {
      Column() {
E
ester.zhou 已提交
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
        Web({ src: 'www.example.com', controller: this.controller })
          .geolocationAccess(true)
      }
    }
  }
  ```

### mediaPlayGestureAccess

mediaPlayGestureAccess(access: boolean)

Sets whether a manual click is required for video playback.

**Parameters**

| Name      | Type  | Mandatory  | Default Value | Description     |
| --------- | ------ | ---- | ---- | --------- |
| access | boolean | Yes   | true    | Whether a manual click is required for video playback.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    @State access: boolean = true;
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .mediaPlayGestureAccess(this.access)
472 473 474 475 476 477 478 479 480 481 482 483
      }
    }
  }
  ```

### cacheMode

cacheMode(cacheMode: CacheMode)

Sets the cache mode.

**Parameters**
E
ester.zhou 已提交
484

485 486 487 488 489
| Name      | Type                       | Mandatory  | Default Value | Description     |
| --------- | --------------------------- | ---- | ---- | --------- |
| cacheMode | [CacheMode](#cachemode)| Yes   | CacheMode.Default | Cache mode to set.|

**Example**
E
ester.zhou 已提交
490

491 492 493 494 495
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
496 497
    controller: WebController = new WebController();
    @State mode: CacheMode = CacheMode.None;
498 499
    build() {
      Column() {
E
ester.zhou 已提交
500 501
        Web({ src: 'www.example.com', controller: this.controller })
          .cacheMode(this.mode)
502 503 504 505 506 507 508 509 510 511 512 513
      }
    }
  }
  ```

### textZoomRatio

textZoomRatio(textZoomRatio: number)

Sets the text zoom ratio of the page. The default value is **100**, which indicates 100%.

**Parameters**
E
ester.zhou 已提交
514

515 516 517 518 519
| Name         | Type  | Mandatory  | Default Value | Description           |
| ------------ | ------ | ---- | ---- | --------------- |
| textZoomRatio | number | Yes   | 100 | Text zoom ratio to set.|

**Example**
E
ester.zhou 已提交
520

521 522 523 524 525
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
526 527
    controller: WebController = new WebController();
    @State atio: number = 150;
528 529
    build() {
      Column() {
E
ester.zhou 已提交
530 531
        Web({ src: 'www.example.com', controller: this.controller })
          .textZoomRatio(this.atio)
532 533 534 535 536 537 538 539 540 541 542 543
      }
    }
  }
  ```

### userAgent

userAgent(userAgent: string)

Sets the user agent.

**Parameters**
E
ester.zhou 已提交
544

545 546 547 548 549
| Name      | Type  | Mandatory  | Default Value | Description     |
| --------- | ------ | ---- | ---- | --------- |
| userAgent | string | Yes   | -    | User agent to set.|

**Example**
E
ester.zhou 已提交
550

551 552 553 554 555
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
556
    controller: WebController = new WebController();
557 558 559
    @State userAgent:string = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36';
    build() {
      Column() {
E
ester.zhou 已提交
560 561
        Web({ src: 'www.example.com', controller: this.controller })
          .userAgent(this.userAgent)
562 563 564 565
      }
    }
  }
  ```
E
ester.zhou 已提交
566

E
ester.zhou 已提交
567
>  **NOTE**
E
ester.zhou 已提交
568
>
E
ester.zhou 已提交
569
>  Only the following universal attributes are supported: [width](ts-universal-attributes-size.md#Attributes), [height](ts-universal-attributes-size.md#attributes), [padding](ts-universal-attributes-size.md#Attributes), [margin](ts-universal-attributes-size.md#attributes), and [border](ts-universal-attributes-border.md#attributes).
E
ester.zhou 已提交
570 571 572

## Events

E
ester.zhou 已提交
573
The universal events are not supported.
E
ester.zhou 已提交
574

575 576 577 578 579 580 581
### onAlert

onAlert(callback: (event?: { url: string; message: string; result: JsResult }) => boolean)

Triggered when **alert()** is invoked to display an alert dialog box on the web page.

**Parameters**
E
ester.zhou 已提交
582

583 584 585 586 587 588 589
| Name    | Type                 | Description           |
| ------- | --------------------- | --------------- |
| url     | string                | URL of the web page where the dialog box is displayed.|
| message | string                | Message displayed in the dialog box.      |
| result  | [JsResult](#jsresult) | The user's operation. |

**Return value**
E
ester.zhou 已提交
590

591 592 593 594 595
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.|

**Example**
E
ester.zhou 已提交
596

597 598 599 600 601
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
602
    controller: WebController = new WebController();
603 604
    build() {
      Column() {
E
ester.zhou 已提交
605
        Web({ src: 'www.example.com', controller: this.controller })
606 607
          .onAlert((event) => {
            AlertDialog.show({
E
ester.zhou 已提交
608
              title: 'onAlert',
609
              message: 'text',
E
ester.zhou 已提交
610 611 612 613 614 615 616 617
              primaryButton: {
                value: 'cancel',
                action: () => {
                  event.result.handleCancel()
                }
              },
              secondaryButton: {
                value: 'ok',
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
                action: () => {
                  event.result.handleConfirm()
                }
              },
              cancel: () => {
                event.result.handleCancel()
              }
            })
            return true;
          })
      }
    }
  }
  ```

### onBeforeUnload

onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResult }) => boolean)

E
ester.zhou 已提交
637
Triggered when the current page is about to exit after the user refreshes or closes the page. If the user refreshes the page, this callback is triggered only when the page has obtained focus.
638 639

**Parameters**
E
ester.zhou 已提交
640

641 642 643 644 645 646 647
| Name    | Type                 | Description           |
| ------- | --------------------- | --------------- |
| url     | string                | URL of the web page where the dialog box is displayed.|
| message | string                | Message displayed in the dialog box.      |
| result  | [JsResult](#jsresult) | The user's operation. |

**Return value**
E
ester.zhou 已提交
648

649 650 651 652 653
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.|

**Example**
E
ester.zhou 已提交
654

655 656 657 658 659 660 661 662 663 664 665 666 667
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onBeforeUnload((event) => {
            console.log("event.url:" + event.url);
            console.log("event.message:" + event.message);
E
ester.zhou 已提交
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
            AlertDialog.show({
              title: 'onBeforeUnload',
              message: 'text',
              primaryButton: {
                value: 'cancel',
                action: () => {
                  event.result.handleCancel()
                }
              },
              secondaryButton: {
                value: 'ok',
                action: () => {
                  event.result.handleConfirm()
                }
              },
              cancel: () => {
                event.result.handleCancel()
              }
            })
            return true;
688 689 690 691 692 693 694 695 696 697 698 699 700
          })
      }
    }
  }
  ```

### onConfirm

onConfirm(callback: (event?: { url: string; message: string; result: JsResult }) => boolean)

Triggered when **confirm()** is invoked by the web page.

**Parameters**
E
ester.zhou 已提交
701

702 703 704 705 706 707 708
| Name    | Type                 | Description           |
| ------- | --------------------- | --------------- |
| url     | string                | URL of the web page where the dialog box is displayed.|
| message | string                | Message displayed in the dialog box.      |
| result  | [JsResult](#jsresult) | The user's operation. |

**Return value**
E
ester.zhou 已提交
709

710 711 712 713 714
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.|

**Example**
E
ester.zhou 已提交
715

716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onConfirm((event) => {
            console.log("event.url:" + event.url);
            console.log("event.message:" + event.message);
            console.log("event.result:" + event.result);
            AlertDialog.show({
E
ester.zhou 已提交
731
              title: 'onConfirm',
732
              message: 'text',
E
ester.zhou 已提交
733 734 735 736 737 738 739 740
              primaryButton: {
                value: 'cancel',
                action: () => {
                  event.result.handleCancel()
                }
              },
              secondaryButton: {
                value: 'ok',
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
                action: () => {
                  event.result.handleConfirm()
                }
              },
              cancel: () => {
                event.result.handleCancel()
              }
            })
            return true;
          })
      }
    }
  }
  ```

### onPrompt<sup>9+</sup>

onPrompt(callback: (event?: { url: string; message: string; value: string; result: JsResult }) => boolean)

**Parameters**
E
ester.zhou 已提交
761

762 763 764 765 766 767 768
| Name    | Type                 | Description           |
| ------- | --------------------- | --------------- |
| url     | string                | URL of the web page where the dialog box is displayed.|
| message | string                | Message displayed in the dialog box.      |
| result  | [JsResult](#jsresult) | The user's operation. |

**Return value**
E
ester.zhou 已提交
769

770 771 772 773 774
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | If the callback returns **false**, the default dialog box is displayed. If the callback returns **true**, a system application can use the system dialog box (allows the confirm and cancel operations) and invoke the **JsResult** API to notify the **\<Web>** component of the user's operation.|

**Example**
E
ester.zhou 已提交
775

776 777 778 779 780
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
781 782
    controller: WebController = new WebController();
  
783 784
    build() {
      Column() {
E
ester.zhou 已提交
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
        Web({ src: 'www.example.com', controller: this.controller })
          .onPrompt((event) => {
            console.log("url:" + event.url);
            console.log("message:" + event.message);
            console.log("value:" + event.value);
            AlertDialog.show({
              title: 'onPrompt',
              message: 'text',
              primaryButton: {
                value: 'cancel',
                action: () => {
                  event.result.handleCancel()
                }
              },
              secondaryButton: {
                value: 'ok',
                action: () => {
                  event.result.handleConfirm()
                }
              },
              cancel: () => {
                event.result.handleCancel()
              }
            })
            return true;
          })
      }
812 813 814 815 816 817 818 819 820 821 822
    }
  }
  ```

### onConsole

onConsole(callback: (event?: { message: ConsoleMessage }) => boolean)

Triggered to notify the host application of a JavaScript console message.

**Parameters**
E
ester.zhou 已提交
823

824 825 826 827 828
| Name    | Type                             | Description     |
| ------- | --------------------------------- | --------- |
| message | [ConsoleMessage](#consolemessage) | Console message.|

**Return value**
E
ester.zhou 已提交
829

830 831 832 833 834
| Type     | Description                                 |
| ------- | ----------------------------------- |
| boolean | Returns **true** if the message will not be printed to the console; returns **false** otherwise.|

**Example**
E
ester.zhou 已提交
835

836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onConsole((event) => {
            console.log('getMessage:' + event.message.getMessage());
            console.log('getSourceId:' + event.message.getSourceId());
            console.log('getLineNumber:' + event.message.getLineNumber());
            console.log('getMessageLevel:' + event.message.getMessageLevel());
            return false;
          })
      }
    }
  }
  ```

### onDownloadStart

onDownloadStart(callback: (event?: { url: string, userAgent: string, contentDisposition: string, mimetype: string, contentLength: number }) => void)

**Parameters**
E
ester.zhou 已提交
863

864 865 866 867 868 869 870 871
| Name               | Type         | Description                               |
| ------------------ | ------------- | ----------------------------------- |
| url                | string        | URL for the download task.                          |
| contentDisposition | string        | Content-Disposition response header returned by the server, which may be empty.|
| mimetype           | string        | MIME type of the content returned by the server.               |
| contentLength      | contentLength | Length of the content returned by the server.                        |

**Example**
E
ester.zhou 已提交
872

873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onDownloadStart((event) => {
            console.log('url:' + event.url);
            console.log('userAgent:' + event.userAgent);
            console.log('contentDisposition:' + event.contentDisposition);
            console.log('contentLength:' + event.contentLength);
            console.log('mimetype:' + event.mimetype);
          })
      }
    }
  }
  ```

### onErrorReceive

onErrorReceive(callback: (event?: { request: WebResourceRequest, error: WebResourceError }) => void)

Triggered when an error occurs during web page loading. For better results, simplify the implementation logic in the callback.

**Parameters**
E
ester.zhou 已提交
902

903 904 905 906 907 908
| Name    | Type                                    | Description           |
| ------- | ---------------------------------------- | --------------- |
| request | [WebResourceRequest](#webresourcerequest) | Encapsulation of a web page request.     |
| error   | [WebResourceError](#webresourceerror)    | Encapsulation of a web page resource loading error.|

**Example**
E
ester.zhou 已提交
909

910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onErrorReceive((event) => {
            console.log('getErrorInfo:' + event.error.getErrorInfo());
            console.log('getErrorCode:' + event.error.getErrorCode());
            console.log('url:' + event.request.getRequestUrl());
            console.log('isMainFrame:' + event.request.isMainFrame());
            console.log('isRedirect:' + event.request.isRedirect());
            console.log('isRequestGesture:' + event.request.isRequestGesture());
            console.log('getRequestHeader_headerKey:' + event.request.getRequestHeader().toString());
            let result = event.request.getRequestHeader();
            console.log('The request header result size is ' + result.length);
            for (let i of result) {
              console.log('The request header key is : ' + i.headerKey + ', value is : ' + i.headerValue);
            }
          })
      }
    }
  }
  ```

### onHttpErrorReceive

onHttpErrorReceive(callback: (event?: { request: WebResourceRequest, response: WebResourceResponse }) => void)

Triggered when an HTTP error (the response code is greater than or equal to 400) occurs during web page resource loading.

**Parameters**
E
ester.zhou 已提交
946

947 948 949 950 951 952
| Name    | Type                                    | Description           |
| ------- | ---------------------------------------- | --------------- |
| request | [WebResourceRequest](#webresourcerequest) | Encapsulation of a web page request.     |
| error   | [WebResourceError](#webresourceerror)    | Encapsulation of a web page resource loading error.|

**Example**
E
ester.zhou 已提交
953

954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onHttpErrorReceive((event) => {
            console.log('url:' + event.request.getRequestUrl());
            console.log('isMainFrame:' + event.request.isMainFrame());
            console.log('isRedirect:' + event.request.isRedirect());
            console.log('isRequestGesture:' + event.request.isRequestGesture());
            console.log('getResponseData:' + event.response.getResponseData());
            console.log('getResponseEncoding:' + event.response.getResponseEncoding());
            console.log('getResponseMimeType:' + event.response.getResponseMimeType());
            console.log('getResponseCode:' + event.response.getResponseCode());
            console.log('getReasonMessage:' + event.response.getReasonMessage());
            let result = event.request.getRequestHeader();
            console.log('The request header result size is ' + result.length);
            for (let i of result) {
              console.log('The request header key is : ' + i.headerKey + ' , value is : ' + i.headerValue);
            }
            let resph = event.response.getResponseHeader();
            console.log('The response header result size is ' + resph.length);
            for (let i of resph) {
              console.log('The response header key is : ' + i.headerKey + ' , value is : ' + i.headerValue);
            }
          })
      }
    }
  }
  ```

### onPageBegin

onPageBegin(callback: (event?: { url: string }) => void)


Triggered when the web page starts to be loaded. This API is triggered only for the main frame content, and not for the iframe or frameset content.

**Parameters**
E
ester.zhou 已提交
998

999 1000 1001 1002 1003
| Name | Type  | Description     |
| ---- | ------ | --------- |
| url  | string | URL of the page.|

**Example**
E
ester.zhou 已提交
1004

1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onPageBegin((event) => {
            console.log('url:' + event.url);
          })
      }
    }
  }
  ```

### onPageEnd

onPageEnd(callback: (event?: { url: string }) => void)


Triggered when the web page loading is complete. This API is triggered only for the main frame content.

**Parameters**
E
ester.zhou 已提交
1031

1032 1033 1034 1035 1036
| Name | Type  | Description     |
| ---- | ------ | --------- |
| url  | string | URL of the page.|

**Example**
E
ester.zhou 已提交
1037

1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onPageEnd((event) => {
            console.log('url:' + event.url);
          })
      }
    }
  }
  ```

### onProgressChange

onProgressChange(callback: (event?: { newProgress: number }) => void)

Triggered when the web page loading progress changes.

**Parameters**
E
ester.zhou 已提交
1063

1064 1065 1066 1067
| Name        | Type  | Description                 |
| ----------- | ------ | --------------------- |
| newProgress | number | New loading progress. The value is an integer ranging from 0 to 100.|

E
ester.zhou 已提交
1068 1069
**Example**

1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onProgressChange((event) => {
            console.log('newProgress:' + event.newProgress)
          })
      }
    }
  }
  ```

### onTitleReceive

onTitleReceive(callback: (event?: { title: string }) => void)

Triggered when the document title of the web page is changed.

**Parameters**
E
ester.zhou 已提交
1095

1096 1097 1098 1099
| Name  | Type  | Description         |
| ----- | ------ | ------------- |
| title | string | Document title.|

E
ester.zhou 已提交
1100 1101
**Example**

1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onTitleReceive((event) => {
            console.log('title:' + event.title)
          })
      }
    }
  }
  ```

### onRefreshAccessedHistory

onRefreshAccessedHistory(callback: (event?: { url: string, isRefreshed: boolean }) => void)

Triggered when loading of the web page is complete. This API is used by an application to update the historical link it accessed.

**Parameters**
E
ester.zhou 已提交
1127

1128 1129 1130
| Name        | Type   | Description                             |
| ----------- | ------- | --------------------------------- |
| url         | string  | URL to be accessed.                          |
E
ester.zhou 已提交
1131 1132 1133
| isRefreshed | boolean | Whether the page is reloaded. The value **true** means that the page is reloaded by invoking the [refresh](#refresh) API, and **false** means the opposite.|

**Example**
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onRefreshAccessedHistory((event) => {
E
ester.zhou 已提交
1146
            console.log('url:' + event.url + ' isReload:' + event.isRefreshed);
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159
          })
      }
    }
  }
  ```

### onRenderExited

onRenderExited(callback: (event?: { renderExitReason: RenderExitReason }) => void)

Triggered when the rendering process exits abnormally.

**Parameters**
E
ester.zhou 已提交
1160

1161 1162 1163 1164
| Name             | Type                                    | Description            |
| ---------------- | ---------------------------------------- | ---------------- |
| renderExitReason | [RenderExitReason](#renderexitreason)| Cause for the abnormal exit of the rendering process.|

E
ester.zhou 已提交
1165 1166
**Example**

1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Web({ src: 'chrome://crash/', controller: this.controller })
          .onRenderExited((event) => {
            console.log('reason:' + event.renderExitReason);
          })
      }
    }
  }
  ```

### onShowFileSelector<sup>9+</sup>

E
ester.zhou 已提交
1187
onShowFileSelector(callback: (event?: { result: FileSelectorResult, fileSelector: FileSelectorParam }) => boolean)
1188 1189 1190 1191

Triggered to process an HTML form whose input type is **file**, in response to the tapping of the **Select File** button.

**Parameters**
E
ester.zhou 已提交
1192

1193 1194 1195 1196 1197
| Name         | Type                                    | Description             |
| ------------ | ---------------------------------------- | ----------------- |
| result       | [FileSelectorResult](#fileselectorresult9) | File selection result to be sent to the **\<Web>** component.|
| fileSelector | [FileSelectorParam](#fileselectorparam9) | Information about the file selector.      |

E
ester.zhou 已提交
1198 1199 1200 1201 1202 1203 1204 1205 1206
**Return value**

| Type     | Description                                 |
| ------- | ----------------------------------- |
| boolean | The value **true** means that the pop-up window provided by the system is displayed. The value **true** means that the default web pop-up window is displayed.|

**Example**

  ```ts
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();

    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onShowFileSelector((event) => {
            AlertDialog.show({
              title: event.fileSelector.getTitle(),
              message: 'isCapture:' + event.fileSelector.isCapture() + " mode:" + event.fileSelector.getMode() + 'acceptType:' + event.fileSelector.getAcceptType(),
              confirm: {
                value: 'upload',
                action: () => {
                  let fileList: Array<string> = [
                    '/data/storage/el2/base/test',
                  ]
                  event.result.handleFileList(fileList)
                }
              },
              cancel: () => {
                let fileList: Array<string> = []
                event.result.handleFileList(fileList)
              }
            })
            return true;
          })
      }
    }
  }
  ```

### onUrlLoadIntercept

onUrlLoadIntercept(callback: (event?: { data:string | WebResourceRequest }) => boolean)

Triggered when the **\<Web>** component is about to access a URL. This API is used to determine whether to block the access.

**Parameters**
E
ester.zhou 已提交
1248

1249 1250 1251 1252 1253
| Name | Type                                    | Description     |
| ---- | ---------------------------------------- | --------- |
| data | string / [WebResourceRequest](#webresourcerequest) | URL information.|

**Return value**
E
ester.zhou 已提交
1254

1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
| Type     | Description                      |
| ------- | ------------------------ |
| boolean | Returns **true** if the access is blocked; returns **false** otherwise.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onUrlLoadIntercept((event) => {
            console.log('onUrlLoadIntercept ' + event.data.toString())
            return true;
          })
      }
    }
  }
  ```

### onInterceptRequest<sup>9+</sup>

E
ester.zhou 已提交
1282
onInterceptRequest(callback: (event?: { request: WebResourceRequest}) => WebResourceResponse)
1283 1284 1285 1286

Triggered when the **\<Web>** component is about to access a URL. This API is used to block the URL and return the response data.

**Parameters**
E
ester.zhou 已提交
1287

1288 1289 1290 1291 1292
| Name    | Type                                    | Description       |
| ------- | ---------------------------------------- | ----------- |
| request | [WebResourceRequest](#webresourcerequest) | Information about the URL request.|

**Return value**
E
ester.zhou 已提交
1293

1294 1295
| Type                                      | Description                         |
| ---------------------------------------- | --------------------------- |
E
ester.zhou 已提交
1296 1297 1298
| [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.|

**Example**
1299 1300 1301 1302 1303 1304

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1305
    controller: WebController = new WebController();
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318
    responseweb: WebResourceResponse = new WebResourceResponse();
    heads:Header[] = new Array();
    @State webdata: string = "<!DOCTYPE html>\n" +
    "<html>\n"+
    "<head>\n"+
    "<title>intercept test</title>\n"+
    "</head>\n"+
    "<body>\n"+
    "<h1>intercept test</h1>\n"+
    "</body>\n"+
    "</html>"
    build() {
      Column() {
E
ester.zhou 已提交
1319
        Web({ src: 'www.example.com', controller: this.controller })
1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351
          .onInterceptRequest((event) => {
            console.log('url:' + event.request.getRequestUrl());
            var head1:Header = {
              headerKey:"Connection",
              headerValue:"keep-alive"
            }
            var head2:Header = {
              headerKey:"Cache-Control",
              headerValue:"no-cache"
            }
            var length = this.heads.push(head1);
            length = this.heads.push(head2);
            this.responseweb.setResponseHeader(this.heads);
            this.responseweb.setResponseData(this.webdata);
            this.responseweb.setResponseEncoding('utf-8');
            this.responseweb.setResponseMimeType('text/html');
            this.responseweb.setResponseCode(200);
            this.responseweb.setReasonMessage('OK');
            return this.responseweb;
          })
      }
    }
  }
  ```

### onHttpAuthRequest<sup>9+</sup>

onHttpAuthRequest(callback: (event?: { handler: HttpAuthHandler, host: string, realm: string}) => boolean)

Triggered when an HTTP authentication request is received.

**Parameters**
E
ester.zhou 已提交
1352

1353 1354 1355 1356 1357 1358 1359
| Name    | Type                                | Description            |
| ------- | ------------------------------------ | ---------------- |
| handler | [HttpAuthHandler](#httpauthhandler9) | The user's operation.  |
| host    | string                               | Host to which HTTP authentication credentials apply.|
| realm   | string                               | Realm to which HTTP authentication credentials apply. |

**Return value**
E
ester.zhou 已提交
1360

1361 1362
| Type     | Description                   |
| ------- | --------------------- |
E
ester.zhou 已提交
1363
| boolean | Returns **true** if the authentication is successful; returns **false** otherwise.|
1364 1365 1366 1367 1368

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
1369
  import web_webview from '@ohos.web.webview'
1370 1371 1372
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
1373 1374 1375
    controller: WebController = new WebController();
    httpAuth: boolean = false;
  
1376 1377
    build() {
      Column() {
E
ester.zhou 已提交
1378 1379 1380 1381 1382 1383 1384 1385
        Web({ src: 'www.example.com', controller: this.controller })
          .onHttpAuthRequest((event) => {
            AlertDialog.show({
              title: 'onHttpAuthRequest',
              message: 'text',
              primaryButton: {
                value: 'cancel',
                action: () => {
1386 1387
                  event.handler.cancel();
                }
E
ester.zhou 已提交
1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405
              },
              secondaryButton: {
                value: 'ok',
                action: () => {
                  this.httpAuth = event.handler.isHttpAuthInfoSaved();
                  if (this.httpAuth == false) {
                    web_webview.WebDataBase.saveHttpAuthCredentials(
                      event.host,
                      event.realm,
                      "2222",
                      "2222"
                    )
                    event.handler.cancel();
                  }
                }
              },
              cancel: () => {
                event.handler.cancel();
1406
              }
E
ester.zhou 已提交
1407 1408
            })
            return true;
1409
          })
E
ester.zhou 已提交
1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517
      }
    }
  }
  ```
### onSslErrorEventReceive<sup>9+</sup>

onSslErrorEventReceive(callback: (event: { handler: SslErrorHandler, error: SslError }) => void)

Invoked when an SSL error occurs during resource loading.

**Parameters**

| Name    | Type                          | Description            |
| ------- | ------------------------------------ | ----------------    |
| handler | [SslErrorHandler](#sslerrorhandler9) | The user's operation.|
| error   | [SslError](#sslerror9)       | Error code.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onSslErrorEventReceive((event) => {
            AlertDialog.show({
              title: 'onSslErrorEventReceive',
              message: 'text',
              primaryButton: {
                value: 'confirm',
                action: () => {
                  event.handler.handleConfirm();
                }
              },
              secondaryButton: {
                value: 'cancel',
                action: () => {
                  event.handler.handleCancel();
                }
              },
              cancel: () => {
                event.handler.handleCancel();
              }
            })
            return true;
          })
      }
    }
  }
  ```

### onClientAuthenticationRequest<sup>9+</sup>

onClientAuthenticationRequest(callback: (event: {handler : ClientAuthenticationHandler, host : string, port : number, keyTypes : Array<string>, issuers : Array<string>}) => void)

Invoked when an SSL client certificate request is received.

**Parameters**

| Name  | Type                            | Description            |
| ------- | ------------------------------------ | ----------------    |
| handler | [ClientAuthenticationHandler](#clientauthenticationhandler9) | The user's operation.|
| host    | string          | Host name of the server that requests a certificate.|
| port    | number          | Port number of the server that requests a certificate.|
| keyTypes| Array<string>   | Acceptable asymmetric private key types.|
| issuers | Array<string>   | Issuer of the certificate that matches the private key.|

  **Example**
  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();

    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onClientAuthenticationRequest((event) => {
            AlertDialog.show({
              title: 'onClientAuthenticationRequest',
              message: 'text',
              primaryButton: {
                value: 'confirm',
                action: () => {
                  event.handler.confirm("/system/etc/user.pk8", "/system/etc/chain-user.pem");
                }
              },
              secondaryButton: {
                value: 'cancel',
                action: () => {
                  event.handler.cancel();
                }
              },
              cancel: () => {
                event.handler.ignore();
              }
            })
            return true;
          })
      }
1518 1519 1520
    }
  }
  ```
E
ester.zhou 已提交
1521

1522 1523 1524 1525 1526 1527 1528
### onPermissionRequest<sup>9+</sup>

onPermissionRequest(callback: (event?: { request: PermissionRequest }) => void)

Invoked when a permission request is received.

**Parameters**
E
ester.zhou 已提交
1529

1530 1531 1532 1533
| Name    | Type                                | Description            |
| ------- | ------------------------------------ | ---------------- |
| request | [PermissionRequest](#permissionrequest9) | The user's operation.  |

E
ester.zhou 已提交
1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656
**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onPermissionRequest((event) => {
            AlertDialog.show({
              title: 'title',
              message: 'text',
              primaryButton: {
                value: 'deny',
                action: () => {
                  event.request.deny();
                }
              },
              secondaryButton: {
                value: 'onConfirm',
                action: () => {
                  event.request.grant(event.request.getAccessibleResource());
                }
              },
              cancel: () => {
                event.request.deny();
              }
            })
          })
      }
    }
  }
  ```

### onContextMenuShow<sup>9+</sup>

onContextMenuShow(callback: (event?: { param: WebContextMenuParam, result: WebContextMenuResult }) => boolean)

Invoked when a context menu is displayed upon a long press on a specific element (such as an image or link).

**Parameters**

| Name    | Type                                | Description            |
| ------- | ------------------------------------ | ---------------- |
| param   | [WebContextMenuParam](#webcontextmenuparam9)   | Parameters related to the context menu.|
| result  | [WebContextMenuResult](#webcontextmenuresult9) | Result of the context menu.|

**Return value**

| Type    | Description                  |
| ------ | -------------------- |
| boolean | The value **true** means a custom menu, and **false** means the default menu.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
          .onContextMenuShow((event) => {
            console.info("x coord = " + event.param.x());
            console.info("link url = " + event.param.getLinkUrl());
            return true;
        })
      }
    }
  }
  ```

### onScroll<sup>9+</sup>

onScroll(callback: (event: {xOffset: number, yOffset: number}) => void)

Invoked when the scrollbar of the page scrolls.

**Parameters**

| Name    | Type                                | Description            |
| ------- | ------------------------------------ | ---------------- |
| xOffset   | number   | Position of the scrollbar on the x-axis.|
| yOffset  | number | Position of the scrollbar on the y-axis.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
        .onScroll((event) => {
            console.info("x = " + event.xOffset);
            console.info("y = " + event.yOffset);
        })
      }
    }
  }
  ```

### onGeolocationShow

onGeolocationShow(callback: (event?: { origin: string, geolocation: JsGeolocation }) => void)

Invoked when a request to obtain the geolocation information is received.

**Parameters**

| Name     | Type                        | Description         |
| ----------- | ------------------------------- | ---------------- |
| origin      | string                          | Index of the origin.    |
| geolocation | [JsGeolocation](#jsgeolocation) | The user's operation.|

1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667
**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller:WebController = new WebController();
    build() {
      Column() {
        Web({ src:'www.example.com', controller:this.controller })
E
ester.zhou 已提交
1668 1669
        .geolocationAccess(true)
        .onGeolocationShow((event) => {
1670 1671 1672 1673 1674 1675
          AlertDialog.show({
            title: 'title',
            message: 'text',
            confirm: {
              value: 'onConfirm',
              action: () => {
E
ester.zhou 已提交
1676
                event.geolocation.invoke(event.origin, true, true);
1677 1678 1679
              }
            },
            cancel: () => {
E
ester.zhou 已提交
1680
              event.geolocation.invoke(event.origin, false, true);
1681 1682 1683
            }
          })
        })
E
ester.zhou 已提交
1684
      }
1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699
    }
  }
  ```

## ConsoleMessage

Implements the **ConsoleMessage** object. For details about the sample code, see [onConsole](#onconsole).

### getLineNumber

getLineNumber(): number

Obtains the number of rows in this console message.

**Return value**
E
ester.zhou 已提交
1700

1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
| Type    | Description                  |
| ------ | -------------------- |
| number | Number of rows in the console message.|

### getMessage

getMessage(): string

Obtains the log information of this console message.

**Return value**
E
ester.zhou 已提交
1712

1713 1714
| Type    | Description                    |
| ------ | ---------------------- |
E
ester.zhou 已提交
1715
| string | Log information of this console message.|
1716 1717 1718 1719 1720 1721 1722 1723

### getMessageLevel

getMessageLevel(): MessageLevel

Obtains the level of this console message.

**Return value**
E
ester.zhou 已提交
1724

1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735
| Type                               | Description                    |
| --------------------------------- | ---------------------- |
| [MessageLevel](#messagelevel)| Level of the console message.|

### getSourceId

getSourceId(): string

Obtains the path and name of the web page source file.

**Return value**
E
ester.zhou 已提交
1736

1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763
| Type    | Description           |
| ------ | ------------- |
| string | Path and name of the web page source file.|

## JsResult

Implements the **JsResult** object, which indicates the result returned to the **\<Web>** component to indicate the user operation performed in the dialog box. For details about the sample code, see [onAlert Event](#onalert).

### handleCancel

handleCancel(): void

Notifies the **\<Web>** component of the user's cancel operation in the dialog box.

### handleConfirm

handleConfirm(): void

Notifies the **\<Web>** component of the user's confirm operation in the dialog box.

### handlePromptConfirm<sup>9+</sup>

handlePromptConfirm(result: string): void

Notifies the **\<Web>** component of the user's confirm operation in the dialog box as well as the dialog box content.

**Parameters**
E
ester.zhou 已提交
1764

1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779
| Name   | Type  | Mandatory  | Default Value | Description       |
| ------ | ------ | ---- | ---- | ----------- |
| result | string | Yes   | -    | User input in the dialog box.|

## WebResourceError

Implements the **WebResourceError** object. For details about the sample code, see [onErrorReceive](#onerrorreceive).

### getErrorCode

getErrorCode(): number

Obtains the error code for resource loading.

**Return value**
E
ester.zhou 已提交
1780

1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791
| Type    | Description         |
| ------ | ----------- |
| number | Error code for resource loading.|

### getErrorInfo

getErrorInfo(): string

Obtains error information about resource loading.

**Return value**
E
ester.zhou 已提交
1792

1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807
| Type    | Description          |
| ------ | ------------ |
| string | Error information about resource loading.|

## WebResourceRequest

Implements the **WebResourceRequest** object. For details about the sample code, see [onErrorReceive](#onerrorreceive).

### getRequestHeader

getResponseHeader() : Array\<Header\>

Obtains the information about the resource request header.

**Return value**
E
ester.zhou 已提交
1808

1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819
| Type                        | Description        |
| -------------------------- | ---------- |
| Array\<[Header](#header)\> | Information about the resource request header.|

### getRequestUrl

getRequestUrl(): string

Obtains the URL of the resource request.

**Return value**
E
ester.zhou 已提交
1820

1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831
| Type    | Description           |
| ------ | ------------- |
| string | URL of the resource request.|

### isMainFrame

isMainFrame(): boolean

Checks whether the resource request is in the main frame.

**Return value**
E
ester.zhou 已提交
1832

1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843
| Type     | Description              |
| ------- | ---------------- |
| boolean | Whether the resource request is in the main frame.|

### isRedirect

isRedirect(): boolean

Checks whether the resource request is redirected by the server.

**Return value**
E
ester.zhou 已提交
1844

1845 1846
| Type     | Description              |
| ------- | ---------------- |
E
ester.zhou 已提交
1847
| boolean | Whether the resource request is redirected by the server.|
1848 1849 1850 1851 1852 1853 1854 1855

### isRequestGesture

isRequestGesture(): boolean

Checks whether the resource request is associated with a gesture (for example, a tap).

**Return value**
E
ester.zhou 已提交
1856

1857 1858
| Type     | Description                  |
| ------- | -------------------- |
E
ester.zhou 已提交
1859
| boolean | Whether the resource request is associated with a gesture (for example, a tap).|
1860 1861

## Header
E
ester.zhou 已提交
1862

E
ester.zhou 已提交
1863
Describes the request/response header returned by the **\<Web>** component.
E
ester.zhou 已提交
1864

1865 1866 1867 1868
| Name         | Type    | Description           |
| ----------- | ------ | ------------- |
| headerKey   | string | Key of the request/response header.  |
| headerValue | string | Value of the request/response header.|
E
ester.zhou 已提交
1869 1870


1871
## WebResourceResponse
E
ester.zhou 已提交
1872

1873
Implements the **WebResourceResponse** object. For details about the sample code, see [onHttpErrorReceive](#onhttperrorreceive).
E
ester.zhou 已提交
1874

1875
### getReasonMessage
E
ester.zhou 已提交
1876

1877
getReasonMessage(): string
E
ester.zhou 已提交
1878

1879
Obtains the status code description of the resource response.
E
ester.zhou 已提交
1880

1881
**Return value**
E
ester.zhou 已提交
1882

1883 1884 1885
| Type    | Description           |
| ------ | ------------- |
| string | Status code description of the resource response.|
E
ester.zhou 已提交
1886

1887
### getResponseCode
E
ester.zhou 已提交
1888

1889
getResponseCode(): number
E
ester.zhou 已提交
1890

1891
Obtains the status code of the resource response.
E
ester.zhou 已提交
1892

1893
**Return value**
E
ester.zhou 已提交
1894

1895 1896 1897
| Type    | Description         |
| ------ | ----------- |
| number | Status code of the resource response.|
E
ester.zhou 已提交
1898

1899
### getResponseData
E
ester.zhou 已提交
1900

1901
getResponseData(): string
E
ester.zhou 已提交
1902

1903
Obtains the data in the resource response.
E
ester.zhou 已提交
1904

1905
**Return value**
E
ester.zhou 已提交
1906

1907 1908 1909
| Type    | Description       |
| ------ | --------- |
| string | Data in the resource response.|
E
ester.zhou 已提交
1910

1911
### getResponseEncoding
E
ester.zhou 已提交
1912

1913 1914 1915 1916 1917
getResponseEncoding(): string

Obtains the encoding string of the resource response.

**Return value**
E
ester.zhou 已提交
1918

1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929
| Type    | Description        |
| ------ | ---------- |
| string | Encoding string of the resource response.|

### getResponseHeader

getResponseHeader() : Array\<Header\>

Obtains the resource response header.

**Return value**
E
ester.zhou 已提交
1930

1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941
| Type                        | Description      |
| -------------------------- | -------- |
| Array\<[Header](#header)\> | Resource response header.|

### getResponseMimeType

getResponseMimeType(): string

Obtains the MIME type of the resource response.

**Return value**
E
ester.zhou 已提交
1942

1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953
| Type    | Description                |
| ------ | ------------------ |
| string | MIME type of the resource response.|

### setResponseData<sup>9+</sup>

setResponseData(data: string)

Sets the data in the resource response.

**Parameters**
E
ester.zhou 已提交
1954

1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965
| Name | Type  | Mandatory  | Default Value | Description       |
| ---- | ------ | ---- | ---- | ----------- |
| data | string | Yes   | -    | Resource response data to set.|

### setResponseEncoding<sup>9+</sup>

setResponseEncoding(encoding: string)

Sets the encoding string of the resource response.

**Parameters**
E
ester.zhou 已提交
1966

1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977
| Name     | Type  | Mandatory  | Default Value | Description        |
| -------- | ------ | ---- | ---- | ------------ |
| encoding | string | Yes   | -    | Encoding string to set.|

### setResponseMimeType<sup>9+</sup>

setResponseMimeType(mimeType: string)

Sets the MIME type of the resource response.

**Parameters**
E
ester.zhou 已提交
1978

1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989
| Name     | Type  | Mandatory  | Default Value | Description                |
| -------- | ------ | ---- | ---- | -------------------- |
| mimeType | string | Yes   | -    | MIME type to set.|

### setReasonMessage<sup>9+</sup>

setReasonMessage(reason: string)

Sets the status code description of the resource response.

**Parameters**
E
ester.zhou 已提交
1990

1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001
| Name   | Type  | Mandatory  | Default Value | Description           |
| ------ | ------ | ---- | ---- | --------------- |
| reason | string | Yes   | -    | Status code description to set.|

### setResponseHeader<sup>9+</sup>

setResponseHeader(header: Array\<Header\>)

Sets the resource response header.

**Parameters**
E
ester.zhou 已提交
2002

2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013
| Name   | Type                      | Mandatory  | Default Value | Description      |
| ------ | -------------------------- | ---- | ---- | ---------- |
| header | Array\<[Header](#header)\> | Yes   | -    | Resource response header to set.|

### setResponseCode<sup>9+</sup>

setResponseCode(code: number)

Sets the status code of the resource response.

**Parameters**
E
ester.zhou 已提交
2014

2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029
| Name | Type  | Mandatory  | Default Value | Description         |
| ---- | ------ | ---- | ---- | ------------- |
| code | number | Yes   | -    | Status code to set.|

## FileSelectorResult<sup>9+</sup>

Notifies the **\<Web>** component of the file selection result. For details about the sample code, see [onShowFileSelector](#onshowfileselector9).

### handleFileList<sup>9+</sup>

handleFileList(fileList: Array\<string\>): void

Instructs the **\<Web>** component to select a file.

**Parameters**
E
ester.zhou 已提交
2030

2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045
| Name     | Type           | Mandatory  | Default Value | Description        |
| -------- | --------------- | ---- | ---- | ------------ |
| fileList | Array\<string\> | Yes   | -    | List of files to operate.|

## FileSelectorParam<sup>9+</sup>

Implements the **FileSelectorParam** object. For details about the sample code, see [onShowFileSelector](#onshowfileselector9).

### getTitle<sup>9+</sup>

getTitle(): string

Obtains the title of the file selector.

**Return value**
E
ester.zhou 已提交
2046

2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057
| Type    | Description        |
| ------ | ---------- |
| string | Title of the file selector.|

### getMode<sup>9+</sup>

getMode(): FileSelectorMode

Obtains the mode of the file selector.

**Return value**
E
ester.zhou 已提交
2058

2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069
| Type                                      | Description         |
| ---------------------------------------- | ----------- |
| [FileSelectorMode](#fileselectormode)| Mode of the file selector.|

### getAcceptType<sup>9+</sup>

getAcceptType(): Array\<string\>

Obtains the file filtering type.

**Return value**
E
ester.zhou 已提交
2070

2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081
| Type             | Description       |
| --------------- | --------- |
| Array\<string\> | File filtering type.|

### isCapture<sup>9+</sup>

isCapture(): boolean

Checks whether multimedia capabilities are invoked.

**Return value**
E
ester.zhou 已提交
2082

2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110
| Type     | Description          |
| ------- | ------------ |
| boolean | Whether multimedia capabilities are invoked.|

## HttpAuthHandler<sup>9+</sup>

Implements the **HttpAuthHandler** object. For details about the sample code, see [onHttpAuthRequest](#onhttpauthrequest9).

### cancel<sup>9+</sup>

cancel(): void

Cancels HTTP authentication as requested by the user.

### confirm<sup>9+</sup>

confirm(userName: string, pwd: string): boolean

Performs HTTP authentication with the user name and password provided by the user.

**Parameters**

| Name     | Type  | Mandatory  | Default Value | Description      |
| -------- | ------ | ---- | ---- | ---------- |
| userName | string | Yes   | -    | HTTP authentication user name.|
| pwd      | string | Yes   | -    | HTTP authentication password. |

**Return value**
E
ester.zhou 已提交
2111

2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122
| Type     | Description                   |
| ------- | --------------------- |
| boolean | Returns **true** if the authentication is successful; returns **false** otherwise.|

### isHttpAuthInfoSaved<sup>9+</sup>

isHttpAuthInfoSaved(): boolean

Uses the password cached on the server for authentication.

**Return value**
E
ester.zhou 已提交
2123

2124 2125 2126 2127
| Type     | Description                       |
| ------- | ------------------------- |
| boolean | Returns **true** if the authentication is successful; returns **false** otherwise.|

E
ester.zhou 已提交
2128
## SslErrorHandler<sup>9+</sup>
2129

E
ester.zhou 已提交
2130
Implements an **SslErrorHandler** object. For details about the sample code, see [onSslErrorEventReceive Event](#onsslerroreventreceive9).
2131

E
ester.zhou 已提交
2132
### handleCancel<sup>9+</sup>
2133

E
ester.zhou 已提交
2134
handleCancel(): void
2135

E
ester.zhou 已提交
2136
Instructs the web component to cancel the request.
2137

E
ester.zhou 已提交
2138
### handleConfirm<sup>9+</sup>
2139

E
ester.zhou 已提交
2140
handleConfirm(): void
2141

E
ester.zhou 已提交
2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187
Instructs the web component to continue using the SSL certificate.

## ClientAuthenticationHandler<sup>9+</sup>

Defines a **ClientAuthenticationHandler** object returned by the web component. For details about the sample code, see [onClientAuthenticationRequest](#onclientauthenticationrequest9).

### confirm<sup>9+</sup>

confirm(priKeyFile : string, certChainFile : string): void

Instructs the web component to use the specified private key and client certificate chain.

**Parameters**

| Name        | Type| Mandatory  | Description       |
| --------      | ------   | ----  | ----------     |
| priKeyFile    | string   | Yes   | File that stores the private key, including the directory and file name.|
| certChainFile | string   | Yes   | File that stores the certificate chain, including the directory and file name.|

### cancel<sup>9+</sup>

cancel(): void

Instructs the web component to cancel 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.

### ignore<sup>9+</sup>

ignore(): void

Instructs the web component to ignore this request.

## PermissionRequest<sup>9+</sup>

Implements the **PermissionRequest** object. For details about the sample code, see [onPermissionRequest](#onpermissionrequest9).

### deny<sup>9+</sup>

deny(): void

Denies the permission requested by the web page.

### getOrigin<sup>9+</sup>

getOrigin(): string

Obtains the origin of this web page.
2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217

**Return value**

| Type     | Description                   |
| ------- | --------------------- |
| string  | Origin of the web page that requests the permission.|

### getAccessibleResource<sup>9+</sup>

getAccessibleResource(): Array\<string\>

Obtains the list of accessible resources requested for the web page. For details about the resource types, see [ProtectedResourceType](#protectedresourcetype9).

**Return value**

| Type           | Description                    |
| --------------- | ----------------------- |
| Array\<string\> | List of accessible resources requested by the web page.|

### grant<sup>9+</sup>

grant(resources: Array\<string\>): void

Grants the permission for resources requested by the web page.

**Parameters**

| Name    | Type       | Mandatory| Default Value| Description               |
| --------- | --------------- | ---- | ----- | ---------------------- |
| resources | Array\<string\> | Yes  | -     | List of accessible resources requested by the web page.|
E
ester.zhou 已提交
2218

E
ester.zhou 已提交
2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328
## WebContextMenuParam<sup>9+</sup>

Provides the information about the context menu that is displayed when a page element is long pressed. For details about the sample code, see [onContextMenuShow](#oncontextmenushow9).

### x<sup>9+</sup>

x(): number

X coordinate of the context menu.

**Return value**

| Type           | Description                    |
| --------------- | ----------------------- |
| number | If the display is normal, a non-negative integer is returned. Otherwise, **-1** is returned.|

### y<sup>9+</sup>

y(): number

Y coordinate of the context menu.

**Return value**

| Type           | Description                    |
| --------------- | ----------------------- |
| number | If the display is normal, a non-negative integer is returned. Otherwise, **-1** is returned.|

### getLinkUrl<sup>9+</sup>

getLinkUrl(): string

Obtains the URL of the destination link.

**Return value**

| Type           | Description                    |
| --------------- | ----------------------- |
| string | If it is the link that is being long pressed, the URL that has passed the security check is returned.|

### getUnfilterendLinkUrl<sup>9+</sup>

getUnfilterendLinkUrl(): string

Obtains the URL of the destination link.

**Return value**

| Type           | Description                    |
| --------------- | ----------------------- |
| string | If it is the link that is being long pressed, the original URL is returned.|

### getSourceUrl<sup>9+</sup>

getSourceUrl(): string

Obtain the source URL.

**Return value**

| Type           | Description                    |
| --------------- | ----------------------- |
| string | If the selected element has the **src** attribute, the URL in the **src** is returned.|

### existsImageContents<sup>9+</sup>

existsImageContents(): boolean

Checks whether image content exists.

**Return value**

| Type           | Description                    |
| --------------- | ----------------------- |
| boolean | The value **true** means that there is image content in the element being long pressed, and **false** means the opposite.|

## WebContextMenuResult<sup>9+</sup>

Defines the response event executed when a context menu is displayed. For details about the sample code, see [onContextMenuShow](#oncontextmenushow9).

### closeContextMenu<sup>9+</sup>

closeContextMenu(): void

Closes this context menu. This API must be called when no operations in **WebContextMenuResult** are performed.

### copyImage<sup>9+</sup>

copyImage(): void

Copies the image specified in **WebContextMenuParam**.

## JsGeolocation

Implements the **PermissionRequest** object. For details about the sample code, see [onGeolocationShow Event](#ongeolocationshow).

### invoke

invoke(origin: string, allow: boolean, retain: boolean): void

Sets the geolocation permission status of a web page.

**Parameters**

| Name    | Type| Mandatory| Default Value| Description              |
| --------- | ------- | ---- | ----- | ---------------------- |
| origin    | string  | Yes  | -     | Index of the source.    |
| allow     | boolean | Yes  | -     | Geolocation permission status.|
| retain    | boolean | Yes  | -     | Whether the geolocation permission status can be saved to the system. The **[GeolocationPermissions](#geolocationpermissions9)** API can be used to manage the geolocation permission status saved to the system.|

E
ester.zhou 已提交
2329 2330
## WebController

E
ester.zhou 已提交
2331
Defines 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.
E
ester.zhou 已提交
2332 2333 2334 2335 2336 2337 2338

### Creating an Object

```
webController: WebController = new WebController()
```

2339 2340 2341 2342 2343 2344 2345
### requestFocus

requestFocus()

Requests focus for this web page.

**Example**
E
ester.zhou 已提交
2346

2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('requestFocus')
          .onClick(() => {
            this.controller.requestFocus();
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
2366 2367 2368 2369 2370 2371
### accessBackward

accessBackward(): boolean

Checks whether going to the previous page can be performed on the current page.

2372
**Return value**
E
ester.zhou 已提交
2373

2374 2375 2376 2377 2378
| Type     | Description                   |
| ------- | --------------------- |
| boolean | Returns **true** if going to the previous page can be performed on the current page; returns **false** otherwise.|

**Example**
E
ester.zhou 已提交
2379

2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('accessBackward')
          .onClick(() => {
            let result = this.controller.accessBackward();
            console.log('result:' + result);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
2400 2401 2402 2403 2404 2405
### accessForward

accessForward(): boolean

Checks whether going to the next page can be performed on the current page.

2406
**Return value**
E
ester.zhou 已提交
2407

2408 2409 2410 2411 2412
| Type     | Description                   |
| ------- | --------------------- |
| boolean | Returns **true** if going to the next page can be performed on the current page; returns **false** otherwise.|

**Example**
E
ester.zhou 已提交
2413

2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('accessForward')
          .onClick(() => {
            let result = this.controller.accessForward();
            console.log('result:' + result);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
2434 2435 2436 2437 2438 2439
### accessStep

accessStep(step: number): boolean

Indicates whether a specific number of steps forward or backward can be performed on the current page.

2440 2441 2442 2443 2444 2445 2446
**Parameters**

| Name | Type  | Mandatory  | Default Value | Description                 |
| ---- | ------ | ---- | ---- | --------------------- |
| step | number | Yes   | -    | Number of the steps to take. A positive number means to going forward, and a negative number means to going backward.|

**Return value**
E
ester.zhou 已提交
2447

2448 2449 2450 2451 2452
| Type     | Description       |
| ------- | --------- |
| boolean | Whether to go forward or backward from the current page.|

**Example**
E
ester.zhou 已提交
2453

2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    @State steps: number = 2;
  
    build() {
      Column() {
        Button('accessStep')
          .onClick(() => {
            let result = this.controller.accessStep(this.steps);
            console.log('result:' + result);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
2474 2475 2476 2477 2478 2479 2480

### backward

backward(): void

Goes to the previous page based on the history stack. This API is generally used together with **accessBackward**.

2481
**Example**
E
ester.zhou 已提交
2482

2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('backward')
          .onClick(() => {
            this.controller.backward();
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
2501 2502 2503 2504 2505 2506 2507

### forward

forward(): void

Goes to the next page based on the history stack. This API is generally used together with **accessForward**.

2508
**Example**
E
ester.zhou 已提交
2509

2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('forward')
          .onClick(() => {
            this.controller.forward();
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### backOrForward<sup>9+</sup>

backOrForward(step: number): void

Performs a specific number of steps forward or backward on the current page based on the history stack. No redirection will be performed if the corresponding page does not exist in the history stack.

**Parameters**
E
ester.zhou 已提交
2536

2537 2538 2539 2540 2541
| Name | Type  | Mandatory  | Default Value | Description       |
| ---- | ------ | ---- | ---- | ----------- |
| step | number | Yes   | -    | Number of the steps to take.|

**Example**
E
ester.zhou 已提交
2542

2543 2544 2545 2546 2547
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
E
ester.zhou 已提交
2548 2549 2550
    controller: WebController = new WebController();
    @State step: number = -2;
  
2551 2552 2553
    build() {
      Column() {
        Button('backOrForward')
E
ester.zhou 已提交
2554 2555 2556 2557 2558
          .onClick(() => {
            this.controller.backOrForward(this.step);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569
    }
  }
  ```

### deleteJavaScriptRegister

deleteJavaScriptRegister(name: string)

Deletes 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](#refresh) API.

**Parameters**
E
ester.zhou 已提交
2570

2571 2572 2573 2574 2575
| Name | Type  | Mandatory  | Default Value | Description                                    |
| ---- | ------ | ---- | ---- | ---------------------------------------- |
| 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.|

**Example**
E
ester.zhou 已提交
2576

2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    @State name: string = 'Object';
  
    build() {
      Column() {
        Button('deleteJavaScriptRegister')
          .onClick(() => {
            this.controller.deleteJavaScriptRegister(this.name);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
2597 2598 2599 2600 2601 2602
### getHitTest

getHitTest(): HitTestType

Obtains the element type of the area being clicked.	

2603
**Return value**
E
ester.zhou 已提交
2604

2605 2606 2607 2608 2609
| Type                             | Description         |
| ------------------------------- | ----------- |
| [HitTestType](#hittesttype)| Element type of the area being clicked.|

**Example**
E
ester.zhou 已提交
2610

2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('getHitTest')
          .onClick(() => {
            let hitType = this.controller.getHitTest();
            console.log("hitType: " + hitType);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### getHitTestValue<sup>9+</sup>
getHitTestValue(): HitTestValue

Obtains the element information of the area being clicked.

**Return value**
E
ester.zhou 已提交
2637

2638 2639 2640 2641 2642
| Type                            | Description        |
| ------------------------------ | ---------- |
| [HitTestValue](#hittestvalue9) | Element information of the area being clicked.|

**Example**
E
ester.zhou 已提交
2643

2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('getHitTestValue')
          .onClick(() => {
            let hitValue = this.controller.getHitTestValue();
            console.log("hitType: " + hitValue.getType());
            console.log("extra: " + hitValue.getExtra());
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### getWebId<sup>9+</sup>
getWebId(): number

Obtains the index value of this **\<Web>** component, which can be used for **\<Web>** component management.

**Return value**
E
ester.zhou 已提交
2671

2672 2673 2674 2675 2676
| Type    | Description          |
| ------ | ------------ |
| number | Index value of the current **\<Web>** component.|

**Example**
E
ester.zhou 已提交
2677

2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('getWebId')
          .onClick(() => {
            let id = this.controller.getWebId();
            console.log("id: " + id);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### getTitle<sup>9+</sup>
getTitle(): string

Obtains the title of the current web page.

**Return value**
E
ester.zhou 已提交
2704

2705 2706 2707 2708 2709
| Type    | Description      |
| ------ | -------- |
| string | Title of the current web page.|

**Example**
E
ester.zhou 已提交
2710

2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('getTitle')
          .onClick(() => {
            let title = this.controller.getTitle();
            console.log("title: " + title);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### getPageHeight<sup>9+</sup>
getPageHeight(): number

Obtains the height of the current web page.

**Return value**
E
ester.zhou 已提交
2737

2738 2739 2740 2741 2742
| Type    | Description        |
| ------ | ---------- |
| number | Height of the current web page.|

**Example**
E
ester.zhou 已提交
2743

2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('getPageHeight')
          .onClick(() => {
            let pageHeight = this.controller.getPageHeight();
            console.log("pageHeight: " + pageHeight);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### getDefaultUserAgent<sup>9+</sup>
getDefaultUserAgent(): string

Obtains the default user agent of the current web page.

**Return value**
E
ester.zhou 已提交
2770

2771 2772 2773 2774 2775
| Type    | Description     |
| ------ | ------- |
| string | Default user agent.|

**Example**
E
ester.zhou 已提交
2776

2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('getDefaultUserAgent')
          .onClick(() => {
            let userAgent = this.controller.getDefaultUserAgent();
            console.log("userAgent: " + userAgent);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
2796 2797 2798

### loadData

2799
loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string })
E
ester.zhou 已提交
2800 2801 2802

Loads data. If **baseUrl** is empty, the specified character string will be loaded using the data protocol.

E
ester.zhou 已提交
2803
If **baseUrl** is set to a data URL, the encoded string will be loaded by the **\<Web>** component using the data protocol.
E
ester.zhou 已提交
2804

E
ester.zhou 已提交
2805
If **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**.
E
ester.zhou 已提交
2806

2807
**Parameters**
E
ester.zhou 已提交
2808

2809 2810 2811 2812 2813 2814 2815 2816 2817
| Name       | Type  | Mandatory  | Default Value | Description                                    |
| ---------- | ------ | ---- | ---- | ---------------------------------------- |
| data       | string | Yes   | -    | Character string obtained after being Base64 or URL encoded.             |
| mimeType   | string | Yes   | -    | Media type (MIME).                             |
| encoding   | string | Yes   | -    | Encoding type, which can be Base64 or URL.               |
| baseUrl    | string | No   | -    | URL (HTTP/HTTPS/data compliant), which is assigned by the **\<Web>** component to **window.origin**.|
| 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.|

**Example**
E
ester.zhou 已提交
2818

2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('loadData')
          .onClick(() => {
            this.controller.loadData({
              data: "<html><body bgcolor=\"white\">Source:<pre>source</pre></body></html>",
              mimeType: "text/html",
              encoding: "UTF-8"
            });
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
2841 2842 2843

### loadUrl

2844
loadUrl(options: { url: string | Resource, headers?: Array\<Header\> })
E
ester.zhou 已提交
2845 2846 2847 2848 2849

Loads a URL using the specified HTTP header.

The object injected through **loadUrl** is valid only in the current document. It will be invalid on a new page navigated to through **loadUrl**.

2850 2851 2852
The object injected through **registerJavaScriptProxy** is still valid on a new page redirected through **loadUrl**.

**Parameters**
E
ester.zhou 已提交
2853

2854 2855 2856 2857 2858 2859
| Name    | Type                      | Mandatory  | Default Value | Description          |
| ------- | -------------------------- | ---- | ---- | -------------- |
| url     | string                     | Yes   | -    | URL to load.    |
| headers | Array\<[Header](#header)\> | No   | []   | Additional HTTP request header of the URL.|

**Example**
E
ester.zhou 已提交
2860

2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('loadUrl')
          .onClick(() => {
            this.controller.loadUrl({ url: 'www.example.com' });
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
2879 2880 2881 2882 2883

### onActive

onActive(): void

E
ester.zhou 已提交
2884
Invoked to instruct the **\<Web>** component to enter the foreground, active state.
E
ester.zhou 已提交
2885

2886
**Example**
E
ester.zhou 已提交
2887

2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('onActive')
          .onClick(() => {
            this.controller.onActive();
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
2907 2908 2909 2910 2911 2912
### onInactive

onInactive(): void

Invoked to instruct the **\<Web>** component to enter the inactive state.

2913
**Example**
E
ester.zhou 已提交
2914

2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('onInactive')
          .onClick(() => {
            this.controller.onInactive();
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### zoom
zoom(factor: number): void

Sets a zoom factor for the current web page.

**Parameters**
E
ester.zhou 已提交
2940

2941 2942 2943 2944 2945
| Name   | Type  | Mandatory  | Description                          |
| ------ | ------ | ---- | ------------------------------ |
| factor | number | Yes   | Zoom factor to set. A positive value indicates zoom-in, and a negative value indicates zoom-out.|

**Example**
E
ester.zhou 已提交
2946

2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    @State factor: number = 1;
  
    build() {
      Column() {
        Button('zoom')
          .onClick(() => {
            this.controller.zoom(this.factor);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### zoomIn<sup>9+</sup>
zoomIn(): boolean

Zooms in on the current web page by 20%.

**Return value**
E
ester.zhou 已提交
2973

2974 2975 2976 2977 2978
| Type     | Description         |
| ------- | ----------- |
| boolean | Operation result.|

**Example**
E
ester.zhou 已提交
2979

2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('zoomIn')
          .onClick(() => {
            let result = this.controller.zoomIn();
            console.log("result: " + result);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### zoomOut<sup>9+</sup>
zoomOut(): boolean

Zooms out the current web page by 20%.

**Return value**
E
ester.zhou 已提交
3006

3007 3008 3009 3010 3011
| Type     | Description         |
| ------- | ----------- |
| boolean | Operation result.|

**Example**
E
ester.zhou 已提交
3012

3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('zoomOut')
          .onClick(() => {
            let result = this.controller.zoomOut();
            console.log("result: " + result);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
3033 3034
### refresh

3035
refresh()
E
ester.zhou 已提交
3036 3037 3038

Invoked to instruct the **\<Web>** component to refresh the web page.

3039
**Example**
E
ester.zhou 已提交
3040

3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('refresh')
          .onClick(() => {
            this.controller.refresh();
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
3059

3060
### registerJavaScriptProxy
E
ester.zhou 已提交
3061

3062 3063 3064 3065 3066
registerJavaScriptProxy(options: { object: object, name: string, methodList: Array\<string\> })

Registers a JavaScript object and invokes the methods of the object in the window. You must invoke the [refresh](#refresh) API for the registration to take effect.

**Parameters**
E
ester.zhou 已提交
3067

3068 3069 3070 3071 3072 3073 3074
| Name       | Type           | Mandatory  | Default Value | Description                                    |
| ---------- | --------------- | ---- | ---- | ---------------------------------------- |
| object     | object          | Yes   | -    | Application-side JavaScript object to be registered. Methods can be declared, but not attributes. The parameters and return value can only be of the string, number, or Boolean type.|
| 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.|
| methodList | Array\<string\> | Yes   | -    | Methods of the JavaScript object to be registered at the application side.                |

**Example**
E
ester.zhou 已提交
3075

3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct Index {
    controller: WebController = new WebController()
    testObj = {
      test: (data) => {
        return "ArkUI Web Component";
      },
      toString: () => {
        console.log('Web Component toString');
      }
    }
    build() {
      Column() {
        Row() {
          Button('Register JavaScript To Window').onClick(() => {
            this.controller.registerJavaScriptProxy({
              object: this.testObj,
              name: "objName",
              methodList: ["test", "toString"],
            });
          })
        }
        Web({ src: $rawfile('index.html'), controller: this.controller })
          .javaScriptAccess(true)
      }
    }
  }
  ```

  ```html
  <!-- index.html -->
  <!DOCTYPE html>
  <html>
      <meta charset="utf-8">
      <body>
          Hello world!
      </body>
      <script type="text/javascript">
      function htmlTest() {
          str = objName.test("test function");
          console.log('objName.test result:'+ str);
      }
  </script>
  </html>
  
  ```
E
ester.zhou 已提交
3125 3126 3127

### runJavaScript

3128
runJavaScript(options: { script: string, callback?: (result: string) => void })
E
ester.zhou 已提交
3129

E
ester.zhou 已提交
3130
Asynchronously executes a JavaScript script. This API uses a callback to return the script execution result. **runJavaScript** can be invoked only after **loadUrl** is executed. For example, it can be executed in **onPageEnd**.
E
ester.zhou 已提交
3131

3132
**Parameters**
E
ester.zhou 已提交
3133

3134 3135 3136 3137 3138 3139
| Name     | Type                    | Mandatory  | Default Value | Description                                    |
| -------- | ------------------------ | ---- | ---- | ---------------------------------------- |
| script   | string                   | Yes   | -    | JavaScript script.                           |
| 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.|

**Example**
E
ester.zhou 已提交
3140

3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    @State webResult: string = ''
    build() {
      Column() {
        Text(this.webResult).fontSize(20)
        Web({ src: $rawfile('index.html'), controller: this.controller })
        .javaScriptAccess(true)
        .onPageEnd(e => {
          this.controller.runJavaScript({
            script: 'test()',
            callback: (result: string)=> {
              this.webResult = result
              console.info(`The test() return value is: ${result}`)
            }});
          console.info('url: ', e.url);
        })
      }
    }
  }
  ```

  ```html
  <!-- index.html -->
  <!DOCTYPE html>
  <html>
    <meta charset="utf-8">
    <body>
        Hello world!
    </body>
    <script type="text/javascript">
    function test() {
        console.log('Ark WebComponent');
        return "This value is from index.html"
    }
    </script>
  </html>
E
ester.zhou 已提交
3182

3183
  ```
E
ester.zhou 已提交
3184 3185 3186

### stop

3187
stop()
E
ester.zhou 已提交
3188 3189 3190

Stops page loading.

3191
**Example**
E
ester.zhou 已提交
3192

3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('stop')
          .onClick(() => {
            this.controller.stop();
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
3212 3213 3214 3215 3216 3217
### clearHistory

clearHistory(): void

Clears the browsing history.

3218
**Example**
E
ester.zhou 已提交
3219

3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('clearHistory')
          .onClick(() => {
            this.controller.clearHistory();
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292
### clearSslCache

clearSslCache(): void

Clears user operation corresponding to the SSL certificate error event recorded by the web component.

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();

    build() {
      Column() {
        Button('clearSslCache')
          .onClick(() => {
            this.controller.clearSslCache();
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### clearClientAuthenticationCache

clearClientAuthenticationCache(): void

Clears the user operation corresponding to the client certificate request event recorded by the web component.

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();

    build() {
      Column() {
        Button('clearClientAuthenticationCache')
          .onClick(() => {
            this.controller.clearClientAuthenticationCache();
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

3293
### getCookieManager<sup>9+</sup>
E
ester.zhou 已提交
3294 3295 3296 3297

getCookieManager(): WebCookie

Obtains the cookie management object of the **\<Web>** component.
3298 3299

**Return value**
E
ester.zhou 已提交
3300

3301 3302 3303 3304 3305
| Type       | Description                                      |
| --------- | ---------------------------------------- |
| WebCookie | Cookie management object. For details, see [WebCookie](#webcookie).|

**Example**
E
ester.zhou 已提交
3306

3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('getCookieManager')
          .onClick(() => {
            let cookieManager = this.controller.getCookieManager();
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
3326
### createWebMessagePorts<sup>9+</sup>
3327

E
ester.zhou 已提交
3328
createWebMessagePorts(): Array\<WebMessagePort\>
3329

E
ester.zhou 已提交
3330
Creates web message ports.
3331 3332 3333 3334

**Return value**


E
ester.zhou 已提交
3335 3336 3337
| Type                             | Description           |
| ------------------------------- | ------------- |
| Array\<[WebMessagePort](#webmessageport9)\> | Array of web message ports.|
3338

E
ester.zhou 已提交
3339
**Example**
3340

E
ester.zhou 已提交
3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    ports: WebMessagePort[] = null;
    build() {
      Column() {
        Button('createWebMessagePorts')
          .onClick(() => {
            this.ports = this.controller.createWebMessagePorts();
            console.log("createWebMessagePorts size:" + this.ports.length)
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
3360

E
ester.zhou 已提交
3361
### postMessage<sup>9+</sup>
3362

E
ester.zhou 已提交
3363
postMessage(options: { message: WebMessageEvent, uri: string}): void
E
ester.zhou 已提交
3364

E
ester.zhou 已提交
3365
Sends a web message to an HTML5 page.
3366 3367 3368

**Parameters**

E
ester.zhou 已提交
3369 3370 3371 3372
| Name       | Type           | Mandatory  | Default Value | Description                     |
| ---------- | --------------- | ---- | ---- | ------------------------- |
| message     | [WebMessageEvent](#webmessageevent9)          | Yes   | -    |Message to send, including data and the message port.|
| uri       | string          | Yes   | -    | URI to receive the message.|
3373 3374

**Example**
E
ester.zhou 已提交
3375

3376 3377 3378 3379 3380 3381
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
E
ester.zhou 已提交
3382
    ports: WebMessagePort[] = null;
3383 3384
    build() {
      Column() {
E
ester.zhou 已提交
3385
        Button('postMessage')
3386
          .onClick(() => {
E
ester.zhou 已提交
3387 3388 3389 3390 3391
            var sendPortArray = new Array(this.ports[1]);
            var msgEvent = new WebMessageEvent();
            msgEvent.setData("__init_ports__");
            msgEvent.setPorts(sendPortArray);
            this.controller.postMessage({message: msgEvent, uri: "*"});
3392 3393 3394 3395 3396
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
E
ester.zhou 已提交
3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408
  // xxx.js
  var h5Port;
  window.addEventListener('message', function(event){
    if (event.data == '__init_ports__') {
      if(event.ports[0] != null) {
        h5Port = event.ports[0];
        h5Port.onmessage = function(event) {
          console.log('receive message from ets, on message:' + event.data);
        }
      }
    }
  })
3409
  ```
E
ester.zhou 已提交
3410

E
ester.zhou 已提交
3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514
### getUrl<sup>9+</sup>

getUrl(): string

Obtains the URL of the current page.

**Return value**

| Type                             | Description           |
| ------------------------------- | ------------- |
| string | URL of the current page.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    build() {
      Column() {
        Button('getUrl')
          .onClick(() => {
            console.log("url: " + this.controller.getUrl());
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

## HitTestValue<sup>9+</sup>
Implements the **HitTestValue** object. For details about the sample code, see [getHitTestValue](#gethittestvalue9).

### getType<sup>9+</sup>
getType(): HitTestType

Obtains the element type of the area being clicked.

**Return value**

| Type                             | Description           |
| ------------------------------- | ------------- |
| [HitTestType](#hittesttype)| Element type of the area being clicked.|

### getExtra<sup>9+</sup>
getExtra(): string

Obtains the extra information of the area being clicked. If the area being clicked is an image or a link, the extra information is the URL of the image or link.

**Return value**

| Type    | Description          |
| ------ | ------------ |
| string | Extra information of the area being clicked.|


## WebCookie

Manages 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.

### setCookie<sup>9+</sup>
setCookie(url: string, value: string): boolean

Sets the cookie. This API returns the result synchronously. Returns **true** if the operation is successful; returns **false** otherwise.

**Parameters**

| Name  | Type  | Mandatory  | Default Value | Description             |
| ----- | ------ | ---- | ---- | ----------------- |
| url   | string | Yes   | -    | URL of the cookie to set.|
| value | string | Yes   | -    | Value of the cookie to set.        |

**Return value**

| Type     | Description           |
| ------- | ------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('setCookie')
          .onClick(() => {
            let result = this.controller.getCookieManager().setCookie("www.example.com", "a=b");
            console.log("result: " + result);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### saveCookieSync<sup>9+</sup>
saveCookieSync(): boolean
E
ester.zhou 已提交
3515

3516 3517 3518
Saves this cookie in the memory to the drive. This API returns the result synchronously.

**Return value**
E
ester.zhou 已提交
3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633

| Type     | Description                  |
| ------- | -------------------- |
| boolean | Operation result.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('saveCookieSync')
          .onClick(() => {
            let result = this.controller.getCookieManager().saveCookieSync();
            console.log("result: " + result);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### getCookie<sup>9+</sup>
getCookie(url: string): string

Obtains the cookie value corresponding to the specified URL.

**Parameters**

| Name  | Type  | Mandatory  | Default Value | Description             |
| ----- | ------ | ---- | ---- | ----------------- |
| url   | string | Yes   | -    | URL of the cookie value to obtain.|

**Return value**

| Type     | Description                  |
| ------- | -------------------- |
| string | Cookie value corresponding to the specified URL.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('getCookie')
          .onClick(() => {
            let value = webview.WebCookieManager.getCookie('www.example.com');
            console.log("value: " + value);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### setCookie<sup>9+</sup>
setCookie(url: string, value: string): boolean

Sets a cookie value for the specified URL.

**Parameters**

| Name  | Type  | Mandatory  | Default Value | Description             |
| ----- | ------ | ---- | ---- | ----------------- |
| url   | string | Yes   | -    | URL of the cookie to set.|
| value   | string | Yes   | -    | Cookie value to set.|

**Return value**

| Type     | Description                  |
| ------- | -------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('setCookie')
          .onClick(() => {
            let result = web_webview.WebCookieManager.setCookie('www.example.com', 'a=b');
            console.log("result: " + result);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### saveCookieSync<sup>9+</sup>
saveCookieSync(): boolean

Saves cookies in the memory to the drive. This API is synchronous.

**Return value**

3634 3635 3636 3637 3638
| Type     | Description                  |
| ------- | -------------------- |
| boolean | Operation result.|

**Example**
E
ester.zhou 已提交
3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('saveCookieSync')
          .onClick(() => {
            let result = web_webview.WebCookieManager.saveCookieSync();
            console.log("result: " + result);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### saveCookieAsync<sup>9+</sup>
saveCookieAsync(): Promise\<boolean>

Saves cookies in the memory to the drive. This API uses a promise to return the value.

**Return value**

| Type     | Description                  |
| ------- | -------------------- |
| Promise\<boolean> | Promise used to return the result.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('saveCookieAsync')
          .onClick(() => {
            web_webview.WebCookieManager.saveCookieAsync()
              .then (function(result) {
                console.log("result: " + result);
              })
              .catch(function(error) {
                console.error("error: " + error);
              });
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### saveCookieAsync<sup>9+</sup>
saveCookieAsync(callback: AsyncCallback\<boolean>): void

Saves cookies in the memory to the drive. This API uses an asynchronous callback to return the value.

**Parameters**

| Name  | Type  | Mandatory  | Default Value | Description             |
| ----- | ------ | ---- | ---- | ----------------- |
| callback   | AsyncCallback\<boolean> | Yes   | -    | Callback used to return the operation result.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('saveCookieAsync')
          .onClick(() => {
            web_webview.WebCookieManager.saveCookieAsync(function(result) {
              console.log("result: " + result);
            });
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### isCookieAllowed<sup>9+</sup>
isCookieAllowed(): boolean

Checks whether the **WebCookieManager** instance has the permission to send and receive cookies.

**Return value**

| Type     | Description                  |
| ------- | -------------------- |
| boolean | Whether the **WebCookieManager** instance has the permission to send and receive cookies.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('isCookieAllowed')
          .onClick(() => {
            let result = web_webview.WebCookieManager.isCookieAllowed();
            console.log("result: " + result);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### putAcceptCookieEnabled<sup>9+</sup>
putAcceptCookieEnabled(accept: boolean): void

Sets whether the **WebCookieManager** instance has the permission to send and receive cookies.

**Parameters**

| Name  | Type  | Mandatory  | Default Value | Description             |
| ----- | ------ | ---- | ---- | ----------------- |
| accept   | boolean | Yes   | -    | Whether the **WebCookieManager** instance has the permission to send and receive cookies.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('putAcceptCookieEnabled')
          .onClick(() => {
            web_webview.WebCookieManager.putAcceptCookieEnabled(false);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### isThirdPartyCookieAllowed<sup>9+</sup>
isThirdCookieAllowed(): boolean

Checks whether the **WebCookieManager** instance has the permission to send and receive third-party cookies.

**Return value**

| Type     | Description                  |
| ------- | -------------------- |
| boolean | Whether the **WebCookieManager** instance has the permission to send and receive third-party cookies.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('isThirdPartyCookieAllowed')
          .onClick(() => {
            let result = web_webview.WebCookieManager.isThirdPartyCookieAllowed();
            console.log("result: " + result);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### putAcceptThirdPartyCookieEnabled<sup>9+</sup>
putAcceptThirdPartyCookieEnabled(accept: boolean): void

Sets whether the **WebCookieManager** instance has the permission to send and receive third-party cookies.

**Parameters**

| Name  | Type  | Mandatory  | Default Value | Description             |
| ----- | ------ | ---- | ---- | ----------------- |
| accept   | boolean | Yes   | -    | Whether the **WebCookieManager** instance has the permission to send and receive third-party cookies.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('putAcceptThirdPartyCookieEnabled')
          .onClick(() => {
            web_webview.WebCookieManager.putAcceptThirdPartyCookieEnabled(false);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### existCookie<sup>9+</sup>
existCookie(): boolean

Checks whether cookies exist.

**Return value**

| Type     | Description                  |
| ------- | -------------------- |
| boolean | Whether cookies exist.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('existCookie')
          .onClick(() => {
            let result = web_webview.WebCookieManager.existCookie();
            console.log("result: " + result);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### deleteEntireCookie<sup>9+</sup>
deleteEntireCookie(): void

Deletes all cookies.

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('deleteEntireCookie')
          .onClick(() => {
            web_webview.WebCookieManager.deleteEntireCookie();
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### deleteSessionCookie<sup>9+</sup>
deleteSessionCookie(): void

Deletes all session cookies.

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('deleteSessionCookie')
          .onClick(() => {
            webview.WebCookieManager.deleteSessionCookie();
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

## WebDataBase<sup>9+</sup>
Implements the **WebDataBase** object.

### existHttpAuthCredentials<sup>9+</sup>

static existHttpAuthCredentials(): boolean

Checks whether any saved HTTP authentication credentials exist. This API is synchronous.

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Whether any saved HTTP authentication credentials exist. Returns **true** if any saved HTTP authentication credentials exist exists; returns **false** otherwise.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('existHttpAuthCredentials')
          .onClick(() => {
            let result = web_webview.WebDataBase.existHttpAuthCredentials();
            console.log('result: ' + result);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### deleteHttpAuthCredentials<sup>9+</sup>

static deleteHttpAuthCredentials(): void

Deletes all HTTP authentication credentials saved in the cache. This API returns the result synchronously.

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
  
    build() {
      Column() {
        Button('deleteHttpAuthCredentials')
          .onClick(() => {
            web_webview.WebDataBase.deleteHttpAuthCredentials();
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### getHttpAuthCredentials<sup>9+</sup>

static getHttpAuthCredentials(host: string, realm: string): Array\<string\>

Retrieves HTTP authentication credentials for a given host and domain. This API is synchronous.

**Parameters**

| Name  | Type  | Mandatory  | Default Value | Description            |
| ----- | ------ | ---- | ---- | ---------------- |
| host  | string | Yes   | -    | Host for which you want to obtain the HTTP authentication credentials.|
| realm | string | Yes   | -    | Realm for which you want to obtain the HTTP authentication credentials. |

**Return value**

| Type             | Description                    |
| --------------- | ---------------------- |
| Array\<string\> | Returns the array of the matching user names and passwords if the operation is successful; returns an empty array otherwise.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    host: string = "www.spincast.org";
    realm: string = "protected example";
    username_password: string[];
    build() {
      Column() {
        Button('getHttpAuthCredentials')
          .onClick(() => {
            this.username_password = web_webview.WebDataBase.getHttpAuthCredentials(this.host, this.realm);
            console.log('num: ' + this.username_password.length);
            ForEach(this.username_password, (item) => {
              console.log('username_password: ' + item);
            }, item => item)
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### saveHttpAuthCredentials<sup>9+</sup>

static saveHttpAuthCredentials(host: string, realm: string, username: string, password: string): void

Saves HTTP authentication credentials for a given host and realm. This API returns the result synchronously.

**Parameters**

| Name     | Type  | Mandatory  | Default Value | Description            |
| -------- | ------ | ---- | ---- | ---------------- |
| host     | string | Yes   | -    | Host for which you want to obtain the HTTP authentication credentials.|
| realm    | string | Yes   | -    | Realm to which HTTP authentication credentials apply. |
| username | string | Yes   | -    | User name.            |
| password | string | Yes   | -    | Password.             |

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview'
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    host: string = "www.spincast.org";
    realm: string = "protected example";
    build() {
      Column() {
        Button('saveHttpAuthCredentials')
          .onClick(() => {
            web_webview.WebDataBase.saveHttpAuthCredentials(this.host, this.realm, "Stromgol", "Laroche");
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

## GeolocationPermissions<sup>9+</sup>

Defines a **GeolocationPermissions** object.

### allowGeolocation<sup>9+</sup>

static allowGeolocation(origin: string): void

Allows the specified source to use the geolocation information.

**Parameters**

| Name   | Type| Mandatory| Default Value| Description      |
| -------- | -------- | ---- | ----- | ------------- |
| origin   | string   | Yes  | -     | Index of the source.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview';
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    origin: string = "file:///";
    build() {
      Column() {
        Button('allowGeolocation')
          .onClick(() => {
            web_webview.GeolocationPermissions.allowGeolocation(this.origin);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### deleteGeolocation<sup>9+</sup>

static deleteGeolocation(origin: string): void

Clears the geolocation permission status of a specified source.

**Parameters**

| Name   | Type| Mandatory| Default Value| Description      |
| -------- | -------- | ---- | ----- | ------------- |
| origin   | string   | Yes  | -     | Index of the source.|

**Example**

  ```ts
  // xxx.ets
  import web_webview from '@ohos.web.webview';
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    origin: string = "file:///";
    build() {
      Column() {
        Button('deleteGeolocation')
          .onClick(() => {
            web_webview.GeolocationPermissions.deleteGeolocation(this.origin);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### deleteAllGeolocation<sup>9+</sup>

static deleteAllGeolocation(): void

Clears the geolocation permission status of all sources.

**Example**

4188 4189
  ```ts
  // xxx.ets
E
ester.zhou 已提交
4190
  import web_webview from '@ohos.web.webview';
4191 4192 4193 4194 4195 4196
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    build() {
      Column() {
E
ester.zhou 已提交
4197
        Button('deleteAllGeolocation')
4198
          .onClick(() => {
E
ester.zhou 已提交
4199
            web_webview.GeolocationPermissions.deleteAllGeolocation();
4200 4201 4202 4203 4204 4205 4206
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4207
### getAccessibleGeolocation<sup>9+</sup>
4208

E
ester.zhou 已提交
4209
static getAccessibleGeolocation(origin: string, callback: AsyncCallback\<boolean\>): void
4210

E
ester.zhou 已提交
4211
Obtains the geolocation permission status of the specified source. This API uses an asynchronous callback to return the result.
4212

E
ester.zhou 已提交
4213
**Parameters**
4214

E
ester.zhou 已提交
4215 4216 4217 4218
| Name   | Type| Mandatory| Default Value| Description      |
| -------- | -------- | ---- | ----- | ------------- |
| origin   | string   | Yes  | -     | Index of the origin.|
| callback | AsyncCallback\<boolean\> | Yes| - | Callback used to return the geolocation permission status of the specified source. If the operation is successful, the value **true** means that the geolocation permission is granted, and **false** means the opposite. If the operation fails, the geolocation permission status of the specified source is not found.|
4219 4220

**Example**
E
ester.zhou 已提交
4221

4222 4223
  ```ts
  // xxx.ets
E
ester.zhou 已提交
4224
  import web_webview from '@ohos.web.webview';
4225 4226 4227 4228
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
E
ester.zhou 已提交
4229
    origin: string = "file:///";
4230 4231
    build() {
      Column() {
E
ester.zhou 已提交
4232
        Button('getAccessibleGeolocationAsync')
4233
          .onClick(() => {
E
ester.zhou 已提交
4234 4235 4236 4237 4238 4239 4240
            web_webview.GeolocationPermissions.getAccessibleGeolocation(this.origin, (error, result) => {
              if (error) {
                console.log('getAccessibleGeolocationAsync error: ' + JSON.stringify(error));
                return;
              }
              console.log('getAccessibleGeolocationAsync result: ' + result);
            });
4241 4242 4243 4244 4245 4246 4247
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4248
### getAccessibleGeolocation<sup>9+</sup>
4249

E
ester.zhou 已提交
4250
static getAccessibleGeolocation(origin: string): Promise\<boolean\>
4251

E
ester.zhou 已提交
4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264
Obtains the geolocation permission status of the specified source. This API uses a promise to return the result.

**Parameters**

| Name   | Type| Mandatory| Default Value| Description      |
| -------- | -------- | ---- | ----- | ------------- |
| origin   | string   | Yes  | -     | Index of the origin.|

**Return value**

| Type              | Description                                 |
| ------------------ | ------------------------------------ |
| Promise\<boolean\> | Promise used to return the geolocation permission status of the specified source. If the operation is successful, the value **true** means that the geolocation permission is granted, and **false** means the opposite. If the operation fails, the geolocation permission status of the specified source is not found.|
4265 4266

**Example**
E
ester.zhou 已提交
4267

4268 4269
  ```ts
  // xxx.ets
E
ester.zhou 已提交
4270
  import web_webview from '@ohos.web.webview';
4271 4272 4273 4274
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
E
ester.zhou 已提交
4275
    origin: string = "file:///";
4276 4277
    build() {
      Column() {
E
ester.zhou 已提交
4278
        Button('getAccessibleGeolocationPromise')
4279
          .onClick(() => {
E
ester.zhou 已提交
4280 4281 4282 4283 4284
            web_webview.GeolocationPermissions.getAccessibleGeolocation(this.origin).then(result => {
              console.log('getAccessibleGeolocationPromise result: ' + result);
            }).catch(error => {
              console.log('getAccessibleGeolocationPromise error: ' + JSON.stringify(error));
            });
4285 4286 4287 4288 4289 4290 4291
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4292
### getStoredGeolocation<sup>9+</sup>
4293

E
ester.zhou 已提交
4294
static getStoredGeolocation(callback: AsyncCallback\<Array\<string\>\>): void
4295

E
ester.zhou 已提交
4296
Obtains the geolocation permission status of all sources. This API uses an asynchronous callback to return the result.
4297 4298 4299

**Parameters**

E
ester.zhou 已提交
4300 4301 4302
| Name   | Type| Mandatory| Default Value| Description      |
| -------- | -------- | ---- | ----- | ------------- |
| callback | AsyncCallback\<Array\<string\>\> | Yes| - | Callback used to return the geolocation permission status of all sources.|
4303 4304

**Example**
E
ester.zhou 已提交
4305

4306 4307
  ```ts
  // xxx.ets
E
ester.zhou 已提交
4308
  import web_webview from '@ohos.web.webview';
4309 4310 4311 4312 4313 4314
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    build() {
      Column() {
E
ester.zhou 已提交
4315
        Button('getStoredGeolocationAsync')
4316
          .onClick(() => {
E
ester.zhou 已提交
4317 4318 4319 4320 4321 4322 4323 4324
            web_webview.GeolocationPermissions.getStoredGeolocation((error, origins) => {
              if (error) {
                console.log('getStoredGeolocationAsync error: ' + JSON.stringify(error));
                return;
              }
              let origins_str: string = origins.join();
              console.log('getStoredGeolocationAsync origins: ' + origins_str);
            });
4325 4326 4327 4328 4329 4330 4331
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

E
ester.zhou 已提交
4332
### getStoredGeolocation<sup>9+</sup>
4333

E
ester.zhou 已提交
4334
static getStoredGeolocation(): Promise\<Array\<string\>\>
4335

E
ester.zhou 已提交
4336
Obtains the geolocation permission status of all sources. This API uses a promise to return the result.
4337 4338

**Parameters**
E
ester.zhou 已提交
4339 4340 4341 4342 4343 4344 4345 4346 4347 4348

| Name   | Type| Mandatory| Default Value| Description      |
| -------- | -------- | ---- | ----- | ------------- |
| callback | AsyncCallback\<Array\<string\>\> | Yes| - | Callback used to return the geolocation permission status of all sources.|

**Return value**

| Type                      | Description                                 |
| -------------------------- | ------------------------------------ |
| Promise\<Array\<string\>\> | Promise used to return the geolocation permission status of all sources.|
4349 4350

**Example**
E
ester.zhou 已提交
4351

4352 4353
  ```ts
  // xxx.ets
E
ester.zhou 已提交
4354
  import web_webview from '@ohos.web.webview';
4355 4356 4357 4358 4359 4360
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    build() {
      Column() {
E
ester.zhou 已提交
4361
        Button('getStoredGeolocationPromise')
4362
          .onClick(() => {
E
ester.zhou 已提交
4363 4364 4365 4366 4367 4368
            web_webview.GeolocationPermissions.getStoredGeolocation().then(origins => {
              let origins_str: string = origins.join();
              console.log('getStoredGeolocationPromise origins: ' + origins_str);
            }).catch(error => {
                console.log('getStoredGeolocationPromise error: ' + JSON.stringify(error));
            });
4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

## WebStorage<sup>9+</sup>
Implements the **WebStorage** object, which can be used to manage the Web SQL and the HTML5 Web Storage API. All **\<Web>** components in an application share one **WebStorage**.
### deleteAllData<sup>9+</sup>
static deleteAllData(): void

Deletes all data in the Web SQL database.

**Example**
E
ester.zhou 已提交
4384

4385 4386
  ```ts
  // xxx.ets
E
ester.zhou 已提交
4387
  import web_webview from '@ohos.web.webview'
4388 4389 4390 4391 4392 4393 4394 4395
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    build() {
      Column() {
        Button('deleteAllData')
          .onClick(() => {
E
ester.zhou 已提交
4396
            web_webview.WebStorage.deleteAllData();
4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410
          })
        Web({ src: 'www.example.com', controller: this.controller })
        .databaseAccess(true)
      }
    }
  }
  ```

### deleteOrigin<sup>9+</sup>
static deleteOrigin(origin : string): void

Deletes all data in the specified origin.

**Parameters**
E
ester.zhou 已提交
4411

4412 4413 4414 4415 4416
| Name   | Type  | Mandatory  | Description        |
| ------ | ------ | ---- | ---------- |
| origin | string | Yes   | Index of the origin.|

**Example**
E
ester.zhou 已提交
4417

4418 4419
  ```ts
  // xxx.ets
E
ester.zhou 已提交
4420
  import web_webview from '@ohos.web.webview'
4421 4422 4423 4424 4425 4426 4427 4428 4429
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    origin: string = "origin";
    build() {
      Column() {
        Button('getHttpAuthCredentials')
          .onClick(() => {
E
ester.zhou 已提交
4430
            web_webview.WebStorage.deleteOrigin(this.origin);
4431 4432 4433 4434 4435 4436 4437 4438 4439
          })
        Web({ src: 'www.example.com', controller: this.controller })
        .databaseAccess(true)
      }
    }
  }
  ```

### getOrigins<sup>9+</sup>
E
ester.zhou 已提交
4440
static getOrigins(callback: AsyncCallback<Array<WebStorageOrigin>>) : void
4441 4442 4443 4444

Obtains information about all origins that are currently using the Web SQL database. This API uses an asynchronous callback to return the result.

**Parameters**
E
ester.zhou 已提交
4445

4446 4447 4448 4449 4450
| Name     | Type                                    | Mandatory  | Description                                 |
| -------- | ---------------------------------------- | ---- | ----------------------------------- |
| callback | AsyncCallback<Array<[WebStorageOrigin](#webstorageorigin9)>> | Yes   | Callback used to return the information about the origins. For details, see **WebStorageOrigin**.|

**Example**
E
ester.zhou 已提交
4451

4452 4453
  ```ts
  // xxx.ets
E
ester.zhou 已提交
4454
  import web_webview from '@ohos.web.webview'
4455 4456 4457 4458 4459 4460 4461 4462 4463
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    origin: string = "origin";
    build() {
      Column() {
        Button('getOrigins')
          .onClick(() => {
E
ester.zhou 已提交
4464
            web_webview.WebStorage.getOrigins((error, origins) => {
4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481
              if (error) {
                console.log('error: ' + error);
                return;
              }
              for (let i = 0; i < origins.length; i++) {
                console.log('origin: ' + origins[i].origin);
                console.log('usage: ' + origins[i].usage);
                console.log('quota: ' + origins[i].quota);
              }
            })
          })
        Web({ src: 'www.example.com', controller: this.controller })
        .databaseAccess(true)
      }
    }
  }
  ```
E
ester.zhou 已提交
4482

4483
### getOrigins<sup>9+</sup>
E
ester.zhou 已提交
4484
static getOrigins() : Promise<Array<WebStorageOrigin>>
4485 4486 4487 4488 4489 4490 4491 4492 4493 4494

Obtains information about all origins that are currently using the Web SQL database. This API uses a promise to return the result.

**Return value**

| Type                                      | Description                                      |
| ---------------------------------------- | ---------------------------------------- |
| Promise<Array<[WebStorageOrigin](#webstorageorigin9)>> | Promise used to return the information about the origins. For details, see **WebStorageOrigin**.|

**Example**
E
ester.zhou 已提交
4495

4496 4497
  ```ts
  // xxx.ets
E
ester.zhou 已提交
4498
  import web_webview from '@ohos.web.webview'
4499 4500 4501 4502 4503 4504 4505 4506 4507
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    origin: string = "origin";
    build() {
      Column() {
        Button('getOrigins')
          .onClick(() => {
E
ester.zhou 已提交
4508
            web_webview.WebStorage.getOrigins()
4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532
              .then(origins => {
                for (let i = 0; i < origins.length; i++) {
                  console.log('origin: ' + origins[i].origin);
                  console.log('usage: ' + origins[i].usage);
                  console.log('quota: ' + origins[i].quota);
                }
              })
              .catch(error => {
                console.log('error: ' + error);
              })
          })
        Web({ src: 'www.example.com', controller: this.controller })
          .databaseAccess(true)
      }
    }
  }
  ```

### getOriginQuota<sup>9+</sup>
static getOriginQuota(origin : string, callback : AsyncCallback\<number>) : void

Obtains the storage quota of an origin in the Web SQL database, in bytes. This API uses an asynchronous callback to return the result.

**Parameters**
E
ester.zhou 已提交
4533

4534 4535 4536 4537 4538 4539
| Name     | Type                  | Mandatory  | Description       |
| -------- | ---------------------- | ---- | --------- |
| origin   | string                 | Yes   | Index of the origin.|
| callback | AsyncCallback\<number> | Yes   | Callback used to return the storage quota of the origin.|

**Example**
E
ester.zhou 已提交
4540

4541 4542
  ```ts
  // xxx.ets
E
ester.zhou 已提交
4543
  import web_webview from '@ohos.web.webview'
4544 4545 4546 4547 4548 4549 4550 4551 4552
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    origin: string = "origin";
    build() {
      Column() {
        Button('getOriginQuota')
          .onClick(() => {
E
ester.zhou 已提交
4553
            web_webview.WebStorage.getOriginQuota(this.origin, (error, quota) => {
4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573
              if (error) {
                console.log('error: ' + error);
                return;
              }
              console.log('quota: ' + quota);
            })
          })
        Web({ src: 'www.example.com', controller: this.controller })
          .databaseAccess(true)
      }
    }
  }
  ```

### getOriginQuota<sup>9+</sup>
static getOriginQuota(origin : string) : Promise\<number>

Obtains the storage quota of an origin in the Web SQL database, in bytes. This API uses a promise to return the result.

**Parameters**
E
ester.zhou 已提交
4574

4575 4576 4577 4578 4579
| Name   | Type  | Mandatory  | Description        |
| ------ | ------ | ---- | ---------- |
| origin | string | Yes   | Index of the origin.|

**Return value**
E
ester.zhou 已提交
4580

4581 4582 4583 4584 4585
| Type              | Description                     |
| ---------------- | ----------------------- |
| Promise\<number> | Promise used to return the storage quota of the origin.|

**Example**
E
ester.zhou 已提交
4586

4587 4588
  ```ts
  // xxx.ets
E
ester.zhou 已提交
4589
  import web_webview from '@ohos.web.webview'
4590 4591 4592 4593 4594 4595 4596 4597 4598
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    origin: string = "origin";
    build() {
      Column() {
        Button('getOriginQuota')
          .onClick(() => {
E
ester.zhou 已提交
4599
            web_webview.WebStorage.getOriginQuota(this.origin)
4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619
              .then(quota => {
                console.log('quota: ' + quota);
              })
              .catch(error => {
                console.log('error: ' + error);
              })
          })
        Web({ src: 'www.example.com', controller: this.controller })
          .databaseAccess(true)
      }
    }
  }
  ```

### getOriginUsage<sup>9+</sup>
static getOriginUsage(origin : string, callback : AsyncCallback\<number>) : void

Obtains the storage usage of an origin in the Web SQL database, in bytes. This API uses an asynchronous callback to return the result.

**Parameters**
E
ester.zhou 已提交
4620

4621 4622 4623 4624 4625 4626
| Name     | Type                  | Mandatory  | Description        |
| -------- | ---------------------- | ---- | ---------- |
| origin   | string                 | Yes   | Index of the origin.|
| callback | AsyncCallback\<number> | Yes   | Callback used to return the storage usage of the origin.  |

**Example**
E
ester.zhou 已提交
4627

4628 4629
  ```ts
  // xxx.ets
E
ester.zhou 已提交
4630
  import web_webview from '@ohos.web.webview'
4631 4632 4633 4634 4635 4636 4637 4638 4639
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    origin: string = "origin";
    build() {
      Column() {
        Button('getOriginUsage')
          .onClick(() => {
E
ester.zhou 已提交
4640
            web_webview.WebStorage.getOriginUsage(this.origin, (error, usage) => {
4641 4642 4643 4644
              if (error) {
                console.log('error: ' + error);
                return;
              }
E
ester.zhou 已提交
4645
              console.log('usage: ' + usage);
4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660
            })
          })
        Web({ src: 'www.example.com', controller: this.controller })
          .databaseAccess(true)
      }
    }
  }
  ```

### getOriginUsage<sup>9+</sup>
static getOriginUsage(origin : string) : Promise\<number>

Obtains the storage usage of an origin in the Web SQL database, in bytes. This API uses a promise to return the result.

**Parameters**
E
ester.zhou 已提交
4661

4662 4663 4664 4665 4666
| Name   | Type  | Mandatory  | Description        |
| ------ | ------ | ---- | ---------- |
| origin | string | Yes   | Index of the origin.|

**Return value**
E
ester.zhou 已提交
4667

4668 4669 4670 4671 4672
| Type              | Description                    |
| ---------------- | ---------------------- |
| Promise\<number> | Promise used to return the storage usage of the origin.|

**Example**
E
ester.zhou 已提交
4673

4674 4675
  ```ts
  // xxx.ets
E
ester.zhou 已提交
4676
  import web_webview from '@ohos.web.webview'
4677 4678 4679 4680 4681 4682 4683 4684 4685
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    origin: string = "origin";
    build() {
      Column() {
        Button('getOriginQuota')
          .onClick(() => {
E
ester.zhou 已提交
4686
            web_webview.WebStorage.getOriginUsage(this.origin)
4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712
              .then(usage => {
                console.log('usage: ' + usage);
              })
              .catch(error => {
                console.log('error: ' + error);
              })
          })
        Web({ src: 'www.example.com', controller: this.controller })
          .databaseAccess(true)
      }
    }
  }
  ```
### searchAllAsync<sup>9+</sup>

searchAllAsync(searchString: string): void

Searches the web page for content that matches the keyword specified by **'searchString'** and highlights the matches on the page. This API returns the result asynchronously through [onSearchResultReceive](#onsearchresultreceive9).

**Parameters**

| Name | Type  | Mandatory  | Default Value | Description                 |
| ---- | ------ | ---- | ---- | --------------------- |
| searchString | string | Yes   | -    | Search keyword.|

**Example**
E
ester.zhou 已提交
4713

4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    @State searchString: string = "xxx";

    build() {
      Column() {
        Button('searchString')
          .onClick(() => {
            this.controller.searchAllAsync(this.searchString);
          })
        Button('clearMatches')
          .onClick(() => {
            this.controller.clearMatches();
          })
        Button('searchNext')
          .onClick(() => {
            this.controller.searchNext(true);
          })
        Web({ src: 'www.example.com', controller: this.controller })
     	  .onSearchResultReceive(ret => {
            console.log("on search result receive:" + "[cur]" + ret.activeMatchOrdinal +
              "[total]" + ret.numberOfMatches + "[isDone]"+ ret.isDoneCounting);
          })
      }
    }
  }
  ```

### clearMatches<sup>9+</sup>

clearMatches(): void

Clears the matches found through [searchAllAsync](#searchallasync9).

**Example**
E
ester.zhou 已提交
4753

4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();

    build() {
      Column() {
        Button('clearMatches')
          .onClick(() => {
            this.controller.clearMatches();
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### searchNext<sup>9+</sup>

searchNext(forward: boolean): void

Searches for and highlights the next match.

**Parameters**

| Name | Type  | Mandatory  | Default Value | Description                 |
| ---- | ------ | ---- | ---- | --------------------- |
| forward | boolean | Yes   | -    | Whether to search forward.|


**Example**
E
ester.zhou 已提交
4787

4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();

    build() {
      Column() {
        Button('searchNext')
          .onClick(() => {
            this.controller.searchNext(true);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### onSearchResultReceive<sup>9+</sup>

onSearchResultReceive(callback: (event?: {activeMatchOrdinal: number, numberOfMatches: number, isDoneCounting: boolean}) => void): WebAttribute

Invoked to notify the caller of the search result on the web page.

**Parameters**

| Name               | Type         | Description                               |
| ------------------ | ------------- | ----------------------------------- |
| activeMatchOrdinal | number        | Sequence number of the current match, which starts from 0.|
| numberOfMatches    | number        | Total number of matches.|
| isDoneCounting     | boolean       | Whether the search operation on the current page is complete. This API may be called multiple times until **isDoneCounting** is **true**.|

**Example**
E
ester.zhou 已提交
4822

4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846
  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();

    build() {
      Column() {
        Web({ src: 'www.example.com', controller: this.controller })
     	  .onSearchResultReceive(ret => {
            console.log("on search result receive:" + "[cur]" + ret.activeMatchOrdinal +
              "[total]" + ret.numberOfMatches + "[isDone]"+ ret.isDoneCounting);
          })
      }
    }
  }
  ```

## WebStorageOrigin<sup>9+</sup>

Provides usage information about the Web SQL database.

**Parameters**
E
ester.zhou 已提交
4847

4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911
| Name   | Type  | Mandatory  | Description        |
| ------ | ------ | ---- | ---------- |
| origin | string | Yes   | Index of the origin.|
| usage  | number | Yes   | Storage usage of the origin.  |
| quota  | number | Yes   | Storage quota of the origin. |

## MessageLevel enums

| Name   | Description   |
| ----- | :---- |
| Debug | Debug level.|
| Error | Error level.|
| Info  | Information level.|
| Log   | Log level.|
| Warn  | Warning level. |

## RenderExitReason

Explains why the rendering process exits.

| Name                        | Description               |
| -------------------------- | ----------------- |
| ProcessAbnormalTermination | The rendering process exits abnormally.        |
| ProcessWasKilled           | The rendering process receives a SIGKILL message or is manually terminated.|
| ProcessCrashed             | The rendering process crashes due to segmentation or other errors.   |
| ProcessOom                 | The program memory is running low.          |
| ProcessExitUnknown         | Other reason.            |

## MixedMode

| Name        | Description                                |
| ---------- | ---------------------------------- |
| All        | HTTP and HTTPS hybrid content can be loaded. This means that all insecure content can be loaded.|
| Compatible | HTTP and HTTPS hybrid content can be loaded in compatibility mode. This means that some insecure content may be loaded.          |
| None       | HTTP and HTTPS hybrid content cannot be loaded.              |

## CacheMode
| Name     | Description                                  |
| ------- | ------------------------------------ |
| Default | The cache that has not expired is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet.|
| None    | The cache is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet.    |
| Online  | The cache is not used to load the resources. All resources are obtained from the Internet.              |
| Only    | The cache alone is used to load the resources.                       |

## FileSelectorMode
| Name                  | Description        |
| -------------------- | ---------- |
| FileOpenMode         | Open and upload a file. |
| FileOpenMultipleMode | Open and upload multiple files. |
| FileOpenFolderMode   | Open and upload a folder.|
| FileSaveMode         | Save a file.   |

 ## HitTestType

| Name           | Description                      |
| ------------- | ------------------------ |
| EditText      | Editable area.                 |
| Email         | Email address.                 |
| HttpAnchor    | Hyperlink whose **src** is **http**.          |
| HttpAnchorImg | Image with a hyperlink, where **src** is **http**.|
| Img           | HTML::img tag.            |
| Map           | Geographical address.                   |
| Unknown       | Unknown content.                   |

E
ester.zhou 已提交
4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922
## SslError<sup>9+</sup>

Enumerates the error codes returned by **onSslErrorEventReceive** API.

| Name          | Description                 |
| -------------- | -----------------    |
| Invalid        | Minor error.           |
| HostMismatch   | The host name does not match.       |
| DateInvalid    | The certificate has an invalid date.       |
| Untrusted      | The certificate issuer is not trusted.|

4923 4924 4925 4926
## ProtectedResourceType<sup>9+</sup>

| Name     | Description           | Remarks          |
| --------- | -------------- | -------------- |
E
ester.zhou 已提交
4927
| MidiSysex | MIDI SYSEX resource.| Currently, only permission events can be reported. MIDI devices are not yet supported.|
4928 4929 4930 4931 4932 4933

## WebAsyncController

Implements the **WebAsyncController** object, which can be used to control the behavior of a **\<Web>** component with asynchronous callbacks. A **WebAsyncController **object controls one **\<Web>** component.

### Creating an Object
E
ester.zhou 已提交
4934

E
ester.zhou 已提交
4935
```
4936 4937
webController: WebController = new WebController();
webAsyncController: WebAsyncController = new WebAsyncController(webController);
E
ester.zhou 已提交
4938 4939
```

4940 4941
### storeWebArchive<sup>9+</sup>

E
ester.zhou 已提交
4942
storeWebArchive(baseName: string, autoName: boolean, callback: AsyncCallback<string>): void
4943 4944 4945 4946 4947 4948 4949

Saves the current web page. This API uses an asynchronous callback to return the result.

**Parameters**

| Name     | Type                                    | Mandatory  | Description                                 |
| -------- | ---------------------------------------- | ---- | ----------------------------------- |
E
ester.zhou 已提交
4950 4951 4952
| baseName | string | Yes| Save path. The value cannot be null.
| autoName | boolean | Yes| Whether to automatically generate a file name.<br>The value **false** means not to automatically generate a file name.<br>The value **true** means to automatically generate a file name based on the URL of current page and the **baseName** value. In this case, **baseName** is regarded as a directory.
| callback | AsyncCallback<string> | Yes   | Callback used to return the save path if the operation is successful and null otherwise.|
4953 4954 4955 4956 4957

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
4958
  import web_webview from '@ohos.web.webview'
4959 4960 4961 4962 4963 4964 4965 4966
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    build() {
      Column() {
        Button('saveWebArchive')
          .onClick(() => {
E
ester.zhou 已提交
4967
            let webAsyncController = new web_webview.WebAsyncController(this.controller);
4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981
            webAsyncController.storeWebArchive("/data/storage/el2/base/", true, (filename) => {
              if (filename != null) {
                console.info(`save web archive success: ${filename}`)
              }
            });
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### storeWebArchive<sup>9+</sup>

E
ester.zhou 已提交
4982
storeWebArchive(baseName: string, autoName: boolean): Promise<string>
4983 4984 4985 4986 4987 4988 4989

Stores the current web page. This API uses an asynchronous callback to return the result.

**Parameters**

| Name     | Type                                    | Mandatory  | Description                                 |
| -------- | ---------------------------------------- | ---- | ----------------------------------- |
E
ester.zhou 已提交
4990 4991
| baseName | string | Yes| Save path. The value cannot be null.
| autoName | boolean | Yes| Whether to automatically generate a file name.<br>The value **false** means not to automatically generate a file name.<br>The value **true** means to automatically generate a file name based on the URL of current page and the **baseName** value. In this case, **baseName** is regarded as a directory.
4992 4993 4994

**Return value**

E
ester.zhou 已提交
4995 4996 4997
| Type                                      | Description                                      |
| ---------------------------------------- | ---------------------------------------- |
| Promise<string> | Promise used to return the save path if the operation is successful and null otherwise.|
4998 4999 5000 5001 5002

**Example**

  ```ts
  // xxx.ets
E
ester.zhou 已提交
5003
  import web_webview from '@ohos.web.webview'
5004 5005 5006 5007 5008 5009 5010 5011
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    build() {
      Column() {
        Button('saveWebArchive')
          .onClick(() => {
E
ester.zhou 已提交
5012
            let webAsyncController = new web_webview.WebAsyncController(this.controller);
5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024
            webAsyncController.storeWebArchive("/data/storage/el2/base/", true)
              .then(filename => {
                if (filename != null) {
                  console.info(`save web archive success: ${filename}`)
                }
              })
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
E
ester.zhou 已提交
5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245

## WebMessagePort<sup>9+</sup>

Defines a **WebMessagePort** instance, which can can be used to send and receive messages.

### close<sup>9+</sup>
close(): void

Disables this message port.

### postMessageEvent<sup>9+</sup>
postMessageEvent(message: WebMessageEvent): void

Sends messages.

**Parameters**

| Name  | Type  | Mandatory  | Default Value | Description             |
| ----- | ------ | ---- | ---- | ----------------- |
| message   | [WebMessageEvent](#webmessageevent9) | Yes   | -    | Message to send.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    ports: WebMessagePort[] = null;

    build() {
      Column() {
        Button('postMessageEvent')
          .onClick(() => {
            var msg = new WebMessageEvent();
            msg.setData("post message from ets to html5");
            this.ports[0].postMessageEvent(msg);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```

### onMessageEvent<sup>9+</sup>
onMessageEvent(callback: (result: string) => void): void

Registers a callback to receive messages from an HTML5 page.

**Parameters**

| Name  | Type  | Mandatory  | Default Value | Description             |
| ----- | ------ | ---- | ---- | ----------------- |
| callback   | function | Yes   | -    | Callback for receiving messages.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    ports: WebMessagePort[] = null;

    build() {
      Column() {
        Button('onMessageEvent')
          .onClick(() => {
            this.ports[0].onMessageEvent((result: string) => {
              console.log("received message from html5, on message:" + result);
            })
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```


## WebMessageEvent<sup>9+</sup>

Implements the **WebMessageEvent** object to encapsulate the message and port.

### getData<sup>9+</sup>
getData(): string

Obtains the messages stored in this object.

**Return value**

| Type                             | Description           |
| ------------------------------- | ------------- |
| string | Message stored in the object of this type.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    build() {
      Column() {
        Button('getPorts')
          .onClick(() => {
            var msgEvent = new WebMessageEvent();
            msgEvent.setData("message event data");
            var messageData = msgEvent.getData();
            console.log("message is:" + messageData);
          })
      }
    }
  }
  ```

### setData<sup>9+</sup>
setData(data: string): void

Sets the message in this object.

**Parameters**

| Name  | Type  | Mandatory  | Default Value | Description             |
| ----- | ------ | ---- | ---- | ----------------- |
| data   | string | Yes   | -    | Message to send.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    ports: WebMessagePort[] = null;

    build() {
      Column() {
        Button('setData')
          .onClick(() => {
            var msg = new WebMessageEvent();
            msg.setData("post message from ets to HTML5");
            this.ports[0].postMessageEvent(msg);
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```
### getPorts<sup>9+</sup>
getPorts(): Array\<WebMessagePort\>

Obtains the message port stored in this object.

**Return value**

| Type                             | Description           |
| ------------------------------- | ------------- |
| Array\<[WebMessagePort](#webmessageport9)\> | Message port stored in the object of this type.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    ports: WebMessagePort[] = null;
    build() {
      Column() {
        Button('getPorts')
          .onClick(() => {
            var sendPortArray = new Array(this.ports[0]);
            var msgEvent = new WebMessageEvent();
            msgEvent.setPorts(sendPortArray);
            var getPorts = msgEvent.getPorts();
            console.log("Ports is:" + getPorts);
          })
      }
    }
  }
  ```

### setPorts<sup>9+</sup>
setPorts(ports: Array\<WebMessagePort\>): void

Sets the message port in this object.

**Parameters**

| Name  | Type  | Mandatory  | Default Value | Description             |
| ----- | ------ | ---- | ---- | ----------------- |
| ports   | Array\<[WebMessagePort](#webmessageport9)\> | Yes   | -    | Message port.|

**Example**

  ```ts
  // xxx.ets
  @Entry
  @Component
  struct WebComponent {
    controller: WebController = new WebController();
    ports: WebMessagePort[] = null;
  
    build() {
      Column() {
        Button('setPorts')
          .onClick(() => {
            var sendPortArray = new Array(this.ports[1]);
            var msgEvent = new WebMessageEvent();
            msgEvent.setData("__init_ports__");
            msgEvent.setPorts(sendPortArray);
            this.controller.postMessage({message: msgEvent, uri: "*"});
          })
        Web({ src: 'www.example.com', controller: this.controller })
      }
    }
  }
  ```