From 4836ba418572c90f56df0e3c100d4d81ca156dd7 Mon Sep 17 00:00:00 2001 From: aengu Date: Sat, 13 Jul 2024 07:01:59 +0800 Subject: [PATCH] =?UTF-8?q?postMessageEventExt=E5=AD=98=E5=9C=A8=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E2=80=9CError:=20BusinessError=20401:=20Parameter=20e?= =?UTF-8?q?rror.=20The=20type=20of=20'message'=20is=20invalid.=E2=80=9D?= =?UTF-8?q?=EF=BC=8C=E5=BD=93=E5=89=8D=E6=9C=AA=E7=9F=A5=E5=8E=9F=E5=9B=A0?= =?UTF-8?q?=EF=BC=8C=E7=A1=AE=E8=AE=A4=E6=95=B0=E6=8D=AE=E6=98=AF=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: aengu --- .../webview/web_message/WebMessageChannel.ets | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/web_message/WebMessageChannel.ets b/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/web_message/WebMessageChannel.ets index c4bd1cc9..1dde56c7 100644 --- a/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/web_message/WebMessageChannel.ets +++ b/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/web_message/WebMessageChannel.ets @@ -107,15 +107,23 @@ export class WebMessageChannel implements Disposable { try { /// 安卓端还会传入WebMessagePortCompat[]类型,目前ohos没有 if (data != null && message.getType() == web_webview.WebMessageType.ARRAY_BUFFER) { - let webMessageExt: web_webview.WebMessageExt = new web_webview.WebMessageExt() - webMessageExt.setArrayBuffer(data as ArrayBuffer) - webMessageExt.setType(web_webview.WebMessageType.ARRAY_BUFFER) - port.postMessageEventExt(webMessageExt); + try{ + let webMessageExt: web_webview.WebMessageExt = new web_webview.WebMessageExt() + webMessageExt.setArrayBuffer(data as ArrayBuffer) + webMessageExt.setType(web_webview.WebMessageType.ARRAY_BUFFER) + port.postMessageEventExt(webMessageExt); + } catch( ex ) { // NOTE:存在“Error: BusinessError 401: Parameter error. The type of 'message' is invalid.”,未知原因,数据是正常数据 + port.postMessageEvent(data as ArrayBuffer); + } } else { - let webMessageExt: web_webview.WebMessageExt = new web_webview.WebMessageExt() - webMessageExt.setString(data != null ? data.toString() : null) - webMessageExt.setType(web_webview.WebMessageType.STRING) - port.postMessageEventExt(webMessageExt); + try{ + let webMessageExt: web_webview.WebMessageExt = new web_webview.WebMessageExt() + webMessageExt.setString(data != null ? data.toString() : null) + webMessageExt.setType(web_webview.WebMessageType.STRING) + port.postMessageEventExt(webMessageExt); + } catch( ex ) { // NOTE:存在“Error: BusinessError 401: Parameter error. The type of 'message' is invalid.”,未知原因,数据是正常数据 + port.postMessageEvent(data != null ? data.toString() : null); + } } result.success(true); } catch (e) { -- Gitee