| 17100006 | Can not register message event using this port. |
**Example**
```ts
// xxx.ets
importweb_webviewfrom'@ohos.web.webview'
// Example of sending messages between an application and a web page: Use the init_web_messageport channel to receive messages from the web page on the application side through port 0 and receive messages from the application on the web page side through port 1.
console.log("In html got message, not any instance of support type");
document.getElementById("msg").innerHTML="not any instance of support type";
}
}else{
console.log("In html got message, not support type");
document.getElementById("msg").innerHTML="not support type";
}
}
h5Port.onmessageerror=(event)=>{
console.error(`hwd In html Error receiving message: ${event}`);
};
}
}
})
// Use h5Port to send a message of the string type to the ArkTS side.
functionpostStringToApp(){
if(h5Port){
console.log("In html send string message");
h5Port.postMessage("hello");
console.log("In html send string message end");
}else{
console.error("In html h5port is null, please init first");
}
}
```
## WebviewController
Implements a **WebviewController** to control the behavior of the **\<Web>** component. A **WebviewController** can control only one **\<Web>** component, and the APIs (except static APIs) in the **WebviewController** can be invoked only after it has been bound to the target **\<Web>** component.
...
...
@@ -422,7 +656,8 @@ struct WebComponent {
}
```
Example of loading local web pages:
There are three methods for loading local resource files:
1. Using $rawfile
```ts
// xxx.ets
importweb_webviewfrom'@ohos.web.webview'
...
...
@@ -448,7 +683,7 @@ struct WebComponent {
}
}
```
2. Using the resources protocol
```ts
// xxx.ets
importweb_webviewfrom'@ohos.web.webview'
...
...
@@ -475,6 +710,8 @@ struct WebComponent {
}
```
3. Using a sandbox path. For details, see the example of loading local resource files in the sandbox in [Web](../arkui-ts/ts-basic-components-web.md#web).
Executes a JavaScript script. This API uses an asynchronous callback to return the script execution result. **runJavaScriptExt** can be invoked only after **loadUrl** is executed. For example, it can be invoked in **onPageEnd**.
Executes a JavaScript script. This API uses a promise to return the script execution result. **runJavaScriptExt** can be invoked only after **loadUrl** is executed. For example, it can be invoked in **onPageEnd**.
| isExtentionType<sup>10+</sup> | boolean | No | Whether to use the extended interface. The default value is **false**, indicating that the extended interface is not used.|
**Return value**
| Type | Description |
...
...
@@ -1626,8 +2095,8 @@ Sends a web message to an HTML5 window.
| [JsMessageType](#jsmessagetype10) | Type of the data object that is returned after script execution using the [runJavaScirptExt](#runjavascriptext10) API.|
### getString<sup>10+</sup>
getString(): string
Obtains string-type data of the data object. For the complete sample code, see [runJavaScriptExt](#runjavascriptext10).
> This topic describes only module-specific error codes. For details about universal error codes, see [Universal Error Codes](errorcode-universal.md).
## 17100001 WebviewController Not Associated with a Web Component
**Error Message**
...
...
@@ -229,3 +228,41 @@ The related JS database API is not used.
1. Check whether the JS database API is used.
2. If the JS database API is used, find out the failure cause, for example, check whether **databaseAccess** is enabled.
## 17100013 Memory Allocation Failure
**Error Message**
New failed, out of memeory.
**Description**
Memory allocation failed due to insufficient memory.
**Possible Causes**
The data to send is too large.
**Solution**
Check the length of the data to be sent.
## 17100014 Type and Value Mismatch
**Error Message**
The type does not match with the value of the message.
**Description**
The type and value of the message do not match.
**Possible Causes**
The value of the obtained message does not match the type of the message.
**Solution**
Call the API based on the message type to obtain the message value. For example, if the type is **BOOLEAN**, call the **GetBoolean** API to obtain the Boolean value.