• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Functions
2
3> **NOTE**
4>
5> - The initial APIs of this module are supported since API version 9. Updates will be marked with a superscript to indicate their earliest API version.
6>
7> - You can preview how this component looks on a real device, but not in DevEco Studio Previewer.
8
9## Module to Import
10
11```ts
12import { webview } from '@kit.ArkWeb';
13```
14
15## webview.once
16
17once(type: string, callback: Callback\<void\>): void
18
19Registers a one-time callback for web events of the specified type. Currently, only **webInited** is supported. This callback is triggered when the Web engine initialization is complete.
20
21When the first **Web** component is loaded in an application, the web engine is initialized. When other **Web** components are loaded in the same application, **once()** is not triggered. When the first **Web** component is loaded after the last **Web** component is destroyed in the application, the web engine will be initialized again.
22
23**System capability**: SystemCapability.Web.Webview.Core
24
25**Parameters**
26
27| Name | Type             | Mandatory| Description                 |
28| ------- | ---------------- | ---- | -------------------- |
29| type     | string          | Yes  | Web event type. The value can be **"webInited"**, indicating completion of web initialization.     |
30| callback | Callback\<void\> | Yes  | Callback to register.|
31
32**Error codes**
33
34For details about the error codes, see [Webview Error Codes](errorcode-webview.md).
35
36| Error Code| Error Message                 |
37| -------- | ----------------------- |
38| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.   |
39
40**Example**
41
42```ts
43// xxx.ets
44import { webview } from '@kit.ArkWeb';
45
46webview.once("webInited", () => {
47  console.log("configCookieSync");
48  webview.WebCookieManager.configCookieSync("https://www.example.com", "a=b");
49})
50
51@Entry
52@Component
53struct WebComponent {
54  controller: webview.WebviewController = new webview.WebviewController();
55
56  build() {
57    Column() {
58      Web({ src: 'www.example.com', controller: this.controller })
59    }
60  }
61}
62```
63