From caa489915d44c22298613938a80c9799c39a7777 Mon Sep 17 00:00:00 2001 From: SimpleLove520 <1960997571@qq.com> Date: Fri, 24 Jan 2025 14:23:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=A7=E8=A1=8C=E7=89=B9?= =?UTF-8?q?=E5=AE=9AJavaScript=20=E4=BB=A3=E7=A0=81=E5=90=8E=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E8=8E=B7=E5=8F=96=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SimpleLove520 <1960997571@qq.com> --- .../webview/in_app_webview/InAppWebView.ets | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/in_app_webview/InAppWebView.ets b/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/in_app_webview/InAppWebView.ets index c533bee1..5cc9c721 100644 --- a/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/in_app_webview/InAppWebView.ets +++ b/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/in_app_webview/InAppWebView.ets @@ -64,6 +64,7 @@ import common from '@ohos.app.ability.common'; import { FindInteractionController } from '../../find_interaction/FindInteractionController'; import PullToRefreshLayout from '../../pull_to_refresh/PullToRefreshLayout'; import EventConstant from '../../EventConstant' +import { BusinessError } from '@kit.BasicServicesKit'; const TAG = "InAppWebView" const METHOD_CHANNEL_NAME_PREFIX = "com.pichillilorenzo/flutter_inappwebview_"; @@ -494,11 +495,17 @@ export default class InAppWebView implements InAppWebViewInterface { } scriptToInject = this.userContentController.generateCodeForScriptEvaluation(scriptToInject, contentWorld); - this.controller.runJavaScriptExt(scriptToInject).then(res => { - if (resultUuid != null || resultCallback == null) - return; - resultCallback.onReceiveValue(res.getString()); - }) + try { + this.controller.runJavaScript(scriptToInject).then(res => { + if (resultUuid != null || resultCallback == null) + return; + resultCallback.onReceiveValue(res); + }); + } catch (error) { + let errorCode = (error as BusinessError).code; + let errorMsg = (error as BusinessError).message; + console.log(`run JavaScript error, ErrorCode:${errorCode}, errorMessage:${errorMsg}`); + } } public evaluateJavascript(source: string, contentWorld: ContentWorld | null, resultCallback: ValueCallback | null): void { -- Gitee