1# Class (WebMessageExt) 2 3Implements a **WebMessageExt** object that received and sent by the [WebMessagePort](./arkts-apis-webview-WebMessagePort.md) API. 4 5> **NOTE** 6> 7> - 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. 8> 9> - The initial APIs of this class are supported since API version 10. 10> 11> - You can preview how this component looks on a real device, but not in DevEco Studio Previewer. 12 13## getType<sup>10+</sup> 14 15getType(): WebMessageType 16 17Obtains the type of the data object. For details about the sample code, see [onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10). 18 19**System capability**: SystemCapability.Web.Webview.Core 20 21**Return value** 22 23| Type | Description | 24| --------------| --------------------------------------------------------- | 25| [WebMessageType](./arkts-apis-webview-e.md#webmessagetype10) | Data types supported by the [webMessagePort](./arkts-apis-webview-WebMessagePort.md) API.| 26 27## getString<sup>10+</sup> 28 29getString(): string 30 31Obtains string-type data of the data object. For details about the sample code, see [onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10). 32 33**System capability**: SystemCapability.Web.Webview.Core 34 35**Return value** 36 37| Type | Description | 38| --------------| ------------- | 39| string | Data of the string type.| 40 41**Error codes** 42 43For details about the error codes, see [Webview Error Codes](errorcode-webview.md). 44 45| ID| Error Message | 46| -------- | ------------------------------------- | 47| 17100014 | The type and value of the message do not match. | 48 49## getNumber<sup>10+</sup> 50 51getNumber(): number 52 53Obtains number-type data of the data object. For details about the sample code, see [onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10). 54 55**System capability**: SystemCapability.Web.Webview.Core 56 57**Return value** 58 59| Type | Description | 60| --------------| ------------- | 61| number | Data of the number type.| 62 63**Error codes** 64 65For details about the error codes, see [Webview Error Codes](errorcode-webview.md). 66 67| ID| Error Message | 68| -------- | ------------------------------------- | 69| 17100014 | The type and value of the message do not match. | 70 71## getBoolean<sup>10+</sup> 72 73getBoolean(): boolean 74 75Obtains Boolean-type data of the data object. For details about the sample code, see [onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10). 76 77**System capability**: SystemCapability.Web.Webview.Core 78 79**Return value** 80 81| Type | Description | 82| --------------| ------------- | 83| boolean | Data of the Boolean type.| 84 85**Error codes** 86 87For details about the error codes, see [Webview Error Codes](errorcode-webview.md). 88 89| ID| Error Message | 90| -------- | ------------------------------------- | 91| 17100014 | The type and value of the message do not match. | 92 93## getArrayBuffer<sup>10+</sup> 94 95getArrayBuffer(): ArrayBuffer 96 97Obtains raw binary data of the data object. For details about the sample code, see [onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10). 98 99**System capability**: SystemCapability.Web.Webview.Core 100 101**Return value** 102 103| Type | Description | 104| --------------| ------------- | 105| ArrayBuffer | Raw binary data.| 106 107**Error codes** 108 109For details about the error codes, see [Webview Error Codes](errorcode-webview.md). 110 111| ID| Error Message | 112| -------- | ------------------------------------- | 113| 17100014 | The type and value of the message do not match. | 114 115## getArray<sup>10+</sup> 116 117getArray(): Array\<string | number | boolean\> 118 119Obtains array-type data of the data object. For details about the sample code, see [onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10). 120 121**System capability**: SystemCapability.Web.Webview.Core 122 123**Return value** 124 125| Type | Description | 126| --------------| ------------- | 127| Array\<string \| number \| boolean\> | Data of the array type.| 128 129**Error codes** 130 131For details about the error codes, see [Webview Error Codes](errorcode-webview.md). 132 133| ID| Error Message | 134| -------- | ------------------------------------- | 135| 17100014 | The type and value of the message do not match. | 136 137## getError<sup>10+</sup> 138 139getError(): Error 140 141Obtains the error-object-type data of the data object. For details about the sample code, see [onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10). 142 143**System capability**: SystemCapability.Web.Webview.Core 144 145**Return value** 146 147| Type | Description | 148| --------------| ------------- | 149| Error | Data of the error object type.| 150 151**Error codes** 152 153For details about the error codes, see [Webview Error Codes](errorcode-webview.md). 154 155| ID| Error Message | 156| -------- | ------------------------------------- | 157| 17100014 | The type and value of the message do not match. | 158 159## setType<sup>10+</sup> 160 161setType(type: WebMessageType): void 162 163Sets the type for the data object. For details about the sample code, see [onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10). 164 165**System capability**: SystemCapability.Web.Webview.Core 166 167**Parameters** 168 169| Name| Type | Mandatory| Description | 170| ------ | ------ | ---- | ---------------------- | 171| type | [WebMessageType](./arkts-apis-webview-e.md#webmessagetype10) | Yes | Data types supported by the [webMessagePort](./arkts-apis-webview-WebMessagePort.md) API.| 172 173**Error codes** 174 175| ID| Error Message | 176| -------- | ------------------------------------- | 177| 17100014 | The type and value of the message do not match. | 178| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 179 180## setString<sup>10+</sup> 181 182setString(message: string): void 183 184Sets the string-type data of the data object. For details about the sample code, see [onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10). 185 186**System capability**: SystemCapability.Web.Webview.Core 187 188**Parameters** 189 190| Name| Type | Mandatory| Description | 191| ------ | ------ | ---- | -------------------- | 192| message | string | Yes | String type.| 193 194**Error codes** 195 196| ID| Error Message | 197| -------- | ------------------------------------- | 198| 17100014 | The type and value of the message do not match. | 199| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 200 201## setNumber<sup>10+</sup> 202 203setNumber(message: number): void 204 205Sets the number-type data of the data object. For details about the sample code, see [onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10). 206 207**System capability**: SystemCapability.Web.Webview.Core 208 209**Parameters** 210 211| Name| Type | Mandatory| Description | 212| ------ | ------ | ---- | -------------------- | 213| message | number | Yes | Data of the number type.| 214 215**Error codes** 216 217| ID| Error Message | 218| -------- | ------------------------------------- | 219| 17100014 | The type and value of the message do not match. | 220| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 221 222## setBoolean<sup>10+</sup> 223 224setBoolean(message: boolean): void 225 226Sets the Boolean-type data for the data object. For details about the sample code, see [onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10). 227 228**System capability**: SystemCapability.Web.Webview.Core 229 230**Parameters** 231 232| Name| Type | Mandatory| Description | 233| ------ | ------ | ---- | -------------------- | 234| message | boolean | Yes | Data of the Boolean type.| 235 236**Error codes** 237 238| ID| Error Message | 239| -------- | ------------------------------------- | 240| 17100014 | The type and value of the message do not match. | 241| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 242 243## setArrayBuffer<sup>10+</sup> 244 245setArrayBuffer(message: ArrayBuffer): void 246 247Sets the raw binary data for the data object. For details about the sample code, see [onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10). 248 249**System capability**: SystemCapability.Web.Webview.Core 250 251**Parameters** 252 253| Name| Type | Mandatory| Description | 254| ------ | ------ | ---- | -------------------- | 255| message | ArrayBuffer | Yes | Raw binary data.| 256 257**Error codes** 258 259For details about the error codes, see [Webview Error Codes](errorcode-webview.md). 260 261| ID| Error Message | 262| -------- | ------------------------------------- | 263| 17100014 | The type and value of the message do not match. | 264| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 265 266## setArray<sup>10+</sup> 267 268setArray(message: Array\<string | number | boolean\>): void 269 270Sets the array-type data for the data object. For details about the sample code, see [onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10). 271 272**System capability**: SystemCapability.Web.Webview.Core 273 274**Parameters** 275 276| Name| Type | Mandatory| Description | 277| ------ | ------ | ---- | -------------------- | 278| message | Array\<string \| number \| boolean\> | Yes | Data of the array type.| 279 280**Error codes** 281 282For details about the error codes, see [Webview Error Codes](errorcode-webview.md). 283 284| ID| Error Message | 285| -------- | ------------------------------------- | 286| 17100014 | The type and value of the message do not match. | 287| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 288 289## setError<sup>10+</sup> 290 291setError(message: Error): void 292 293Sets the error-object-type data for the data object. For details about the sample code, see [onMessageEventExt](./arkts-apis-webview-WebMessagePort.md#onmessageeventext10). 294 295**System capability**: SystemCapability.Web.Webview.Core 296 297**Parameters** 298 299| Name| Type | Mandatory| Description | 300| ------ | ------ | ---- | -------------------- | 301| message | Error | Yes | Data of the error object type.| 302 303**Error codes** 304 305For details about the error codes, see [Webview Error Codes](errorcode-webview.md). 306 307| ID| Error Message | 308| -------- | ------------------------------------- | 309| 17100014 | The type and value of the message do not match. | 310| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 311