From 5be36de2aeb11ea741d3058edfc52c15dfd6fcf1 Mon Sep 17 00:00:00 2001 From: Lin Jiacheng Date: Thu, 21 Nov 2024 18:29:49 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dscheme=E6=9C=AA?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=E5=AF=BC=E8=87=B4=E9=94=99=E8=AF=AF=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- harmony/rn_webview/src/main/ets/RNCWebView.ets | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/harmony/rn_webview/src/main/ets/RNCWebView.ets b/harmony/rn_webview/src/main/ets/RNCWebView.ets index 8a2f6bf01..db6a81f2d 100644 --- a/harmony/rn_webview/src/main/ets/RNCWebView.ets +++ b/harmony/rn_webview/src/main/ets/RNCWebView.ets @@ -24,7 +24,7 @@ import { RNComponentContext } from '@rnoh/react-native-openharmony'; import webview from '@ohos.web.webview'; -import { url as OSUrl } from '@kit.ArkTS'; +import { url as OSUrl, url } from '@kit.ArkTS'; import { RNC, TM } from '@rnoh/react-native-openharmony/generated'; import Logger from './Logger'; import { BaseOperate } from './WebViewBaseOperate'; @@ -47,6 +47,7 @@ import { } from './Magic'; import { WebViewTurboModule } from './WebViewTurboModule'; import { bundleManager } from '@kit.AbilityKit'; +import { LinkingManagerTurboModule } from '@rnoh/react-native-openharmony/src/main/ets/RNOHCorePackage/turboModules'; export const TAG = "WebView" @@ -360,6 +361,20 @@ export struct RNCWebView { onLoadIntercept(event: OnLoadInterceptEvent): boolean { Logger.debug(TAG, `onLoadIntercept request url:${event.data.getRequestUrl()} ,shouldInterceptLoad:${this.shouldInterceptLoad}`) if (!this.shouldInterceptLoad) { + try { + // 避免链接多一个/字符导致判断错误 + if (url.URL.parseURL(event.data.getRequestUrl()).toString() != url.URL.parseURL(this.url.toString()).toString()) { + this.webViewBaseOperate?.setLockIdentifier(BaseOperate.generateLockIdentifier()) + this.webViewBaseOperate?.emitShouldStartLoadWithRequest(event) + // 非网络链接拦截加载 + if ( !["https:","http:"].includes(new url.URL(event.data.getRequestUrl()).protocol)) { + return true + } + } + } catch (e) { + Logger.debug(TAG, "onLoadIntercept error:" + e) + } + return false } From 31cca356049542636e6d6115b1c0e73ea82ab61b Mon Sep 17 00:00:00 2001 From: Lin Jiacheng Date: Thu, 21 Nov 2024 18:32:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dscheme=E6=9C=AA?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=E5=AF=BC=E8=87=B4=E9=94=99=E8=AF=AF=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- harmony/rn_webview/src/main/ets/RNCWebView.ets | 1 - 1 file changed, 1 deletion(-) diff --git a/harmony/rn_webview/src/main/ets/RNCWebView.ets b/harmony/rn_webview/src/main/ets/RNCWebView.ets index db6a81f2d..537d67324 100644 --- a/harmony/rn_webview/src/main/ets/RNCWebView.ets +++ b/harmony/rn_webview/src/main/ets/RNCWebView.ets @@ -47,7 +47,6 @@ import { } from './Magic'; import { WebViewTurboModule } from './WebViewTurboModule'; import { bundleManager } from '@kit.AbilityKit'; -import { LinkingManagerTurboModule } from '@rnoh/react-native-openharmony/src/main/ets/RNOHCorePackage/turboModules'; export const TAG = "WebView"