1# Class (WebMessageExt) 2<!--Kit: ArkWeb--> 3<!--Subsystem: Web--> 4<!--Owner: @aohui--> 5<!--Designer: @yaomingliu--> 6<!--Tester: @ghiker--> 7<!--Adviser: @HelloCrease--> 8 9[WebMessagePort](./arkts-apis-webview-WebMessagePort.md)接口接收、发送的数据对象。 10 11> **说明:** 12> 13> - 本模块首批接口从API version 9开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 14> 15> - 本Class首批接口从API version 10开始支持。 16> 17> - 示例效果请以真机运行为准,当前DevEco Studio预览器不支持。 18 19## getType<sup>10+</sup> 20 21getType(): WebMessageType 22 23获取数据对象的类型。完整示例代码参考[onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10)。 24 25**系统能力:** SystemCapability.Web.Webview.Core 26 27**返回值:** 28 29| 类型 | 说明 | 30| --------------| --------------------------------------------------------- | 31| [WebMessageType](./arkts-apis-webview-e.md#webmessagetype10) | [webMessagePort](./arkts-apis-webview-WebMessagePort.md)接口所支持的数据类型。 | 32 33## getString<sup>10+</sup> 34 35getString(): string 36 37获取数据对象的字符串类型数据。完整示例代码参考[onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10)。 38 39**系统能力:** SystemCapability.Web.Webview.Core 40 41**返回值:** 42 43| 类型 | 说明 | 44| --------------| ------------- | 45| string | 返回字符串类型的数据。 | 46 47**错误码:** 48 49以下错误码的详细介绍请参见[webview错误码](errorcode-webview.md)。 50 51| 错误码ID | 错误信息 | 52| -------- | ------------------------------------- | 53| 17100014 | The type and value of the message do not match. | 54 55## getNumber<sup>10+</sup> 56 57getNumber(): number 58 59获取数据对象的数值类型数据。完整示例代码参考[onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10)。 60 61**系统能力:** SystemCapability.Web.Webview.Core 62 63**返回值:** 64 65| 类型 | 说明 | 66| --------------| ------------- | 67| number | 返回数值类型的数据。 | 68 69**错误码:** 70 71以下错误码的详细介绍请参见[webview错误码](errorcode-webview.md)。 72 73| 错误码ID | 错误信息 | 74| -------- | ------------------------------------- | 75| 17100014 | The type and value of the message do not match. | 76 77## getBoolean<sup>10+</sup> 78 79getBoolean(): boolean 80 81获取数据对象的布尔类型数据。完整示例代码参考[onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10)。 82 83**系统能力:** SystemCapability.Web.Webview.Core 84 85**返回值:** 86 87| 类型 | 说明 | 88| --------------| ------------- | 89| boolean | 返回布尔类型的数据。 | 90 91**错误码:** 92 93以下错误码的详细介绍请参见[webview错误码](errorcode-webview.md)。 94 95| 错误码ID | 错误信息 | 96| -------- | ------------------------------------- | 97| 17100014 | The type and value of the message do not match. | 98 99## getArrayBuffer<sup>10+</sup> 100 101getArrayBuffer(): ArrayBuffer 102 103获取数据对象的原始二进制数据。完整示例代码参考[onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10)。 104 105**系统能力:** SystemCapability.Web.Webview.Core 106 107**返回值:** 108 109| 类型 | 说明 | 110| --------------| ------------- | 111| ArrayBuffer | 返回原始二进制数据。 | 112 113**错误码:** 114 115以下错误码的详细介绍请参见[webview错误码](errorcode-webview.md)。 116 117| 错误码ID | 错误信息 | 118| -------- | ------------------------------------- | 119| 17100014 | The type and value of the message do not match. | 120 121## getArray<sup>10+</sup> 122 123getArray(): Array\<string | number | boolean\> 124 125获取数据对象的数组类型数据。完整示例代码参考[onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10)。 126 127**系统能力:** SystemCapability.Web.Webview.Core 128 129**返回值:** 130 131| 类型 | 说明 | 132| --------------| ------------- | 133| Array\<string \| number \| boolean\> | 返回数组类型的数据。 | 134 135**错误码:** 136 137以下错误码的详细介绍请参见[webview错误码](errorcode-webview.md)。 138 139| 错误码ID | 错误信息 | 140| -------- | ------------------------------------- | 141| 17100014 | The type and value of the message do not match. | 142 143## getError<sup>10+</sup> 144 145getError(): Error 146 147获取数据对象的错误类型数据。完整示例代码参考[onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10)。 148 149**系统能力:** SystemCapability.Web.Webview.Core 150 151**返回值:** 152 153| 类型 | 说明 | 154| --------------| ------------- | 155| Error | 返回错误对象类型的数据。 | 156 157**错误码:** 158 159以下错误码的详细介绍请参见[webview错误码](errorcode-webview.md)。 160 161| 错误码ID | 错误信息 | 162| -------- | ------------------------------------- | 163| 17100014 | The type and value of the message do not match. | 164 165## setType<sup>10+</sup> 166 167setType(type: WebMessageType): void 168 169设置数据对象的类型。完整示例代码参考[onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10)。 170 171**系统能力:** SystemCapability.Web.Webview.Core 172 173**参数:** 174 175| 参数名 | 类型 | 必填 | 说明 | 176| ------ | ------ | ---- | ---------------------- | 177| type | [WebMessageType](./arkts-apis-webview-e.md#webmessagetype10) | 是 | [webMessagePort](./arkts-apis-webview-WebMessagePort.md)接口所支持的数据类型。 | 178 179**错误码:** 180 181| 错误码ID | 错误信息 | 182| -------- | ------------------------------------- | 183| 17100014 | The type and value of the message do not match. | 184| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 185 186## setString<sup>10+</sup> 187 188setString(message: string): void 189 190设置数据对象的字符串类型数据。完整示例代码参考[onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10)。 191 192**系统能力:** SystemCapability.Web.Webview.Core 193 194**参数:** 195 196| 参数名 | 类型 | 必填 | 说明 | 197| ------ | ------ | ---- | -------------------- | 198| message | string | 是 | 字符串类型数据。 | 199 200**错误码:** 201 202| 错误码ID | 错误信息 | 203| -------- | ------------------------------------- | 204| 17100014 | The type and value of the message do not match. | 205| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 206 207## setNumber<sup>10+</sup> 208 209setNumber(message: number): void 210 211设置数据对象的数值类型数据。完整示例代码参考[onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10)。 212 213**系统能力:** SystemCapability.Web.Webview.Core 214 215**参数:** 216 217| 参数名 | 类型 | 必填 | 说明 | 218| ------ | ------ | ---- | -------------------- | 219| message | number | 是 | 数值类型数据。 | 220 221**错误码:** 222 223| 错误码ID | 错误信息 | 224| -------- | ------------------------------------- | 225| 17100014 | The type and value of the message do not match. | 226| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 227 228## setBoolean<sup>10+</sup> 229 230setBoolean(message: boolean): void 231 232设置数据对象的布尔类型数据。完整示例代码参考[onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10)。 233 234**系统能力:** SystemCapability.Web.Webview.Core 235 236**参数:** 237 238| 参数名 | 类型 | 必填 | 说明 | 239| ------ | ------ | ---- | -------------------- | 240| message | boolean | 是 | 布尔类型数据。 | 241 242**错误码:** 243 244| 错误码ID | 错误信息 | 245| -------- | ------------------------------------- | 246| 17100014 | The type and value of the message do not match. | 247| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 248 249## setArrayBuffer<sup>10+</sup> 250 251setArrayBuffer(message: ArrayBuffer): void 252 253设置数据对象的原始二进制数据。完整示例代码参考[onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10)。 254 255**系统能力:** SystemCapability.Web.Webview.Core 256 257**参数:** 258 259| 参数名 | 类型 | 必填 | 说明 | 260| ------ | ------ | ---- | -------------------- | 261| message | ArrayBuffer | 是 | 原始二进制类型数据。 | 262 263**错误码:** 264 265以下错误码的详细介绍请参见[webview错误码](errorcode-webview.md)。 266 267| 错误码ID | 错误信息 | 268| -------- | ------------------------------------- | 269| 17100014 | The type and value of the message do not match. | 270| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 271 272## setArray<sup>10+</sup> 273 274setArray(message: Array\<string | number | boolean\>): void 275 276设置数据对象的数组类型数据。完整示例代码参考[onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10)。 277 278**系统能力:** SystemCapability.Web.Webview.Core 279 280**参数:** 281 282| 参数名 | 类型 | 必填 | 说明 | 283| ------ | ------ | ---- | -------------------- | 284| message | Array\<string \| number \| boolean\> | 是 | 数组类型数据。 | 285 286**错误码:** 287 288以下错误码的详细介绍请参见[webview错误码](errorcode-webview.md)。 289 290| 错误码ID | 错误信息 | 291| -------- | ------------------------------------- | 292| 17100014 | The type and value of the message do not match. | 293| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 294 295## setError<sup>10+</sup> 296 297setError(message: Error): void 298 299设置数据对象的错误对象类型数据。完整示例代码参考[onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10)。 300 301**系统能力:** SystemCapability.Web.Webview.Core 302 303**参数:** 304 305| 参数名 | 类型 | 必填 | 说明 | 306| ------ | ------ | ---- | -------------------- | 307| message | Error | 是 | 错误对象类型数据。 | 308 309**错误码:** 310 311以下错误码的详细介绍请参见[webview错误码](errorcode-webview.md)。 312 313| 错误码ID | 错误信息 | 314| -------- | ------------------------------------- | 315| 17100014 | The type and value of the message do not match. | 316| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. |