From 8de37e37c1e9bd23a91df0990d83a9f8882fafdb Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Thu, 21 Nov 2024 06:03:34 +0900 Subject: [PATCH] fix: disable redirect in embed --- lib/view/widget/player_embed.dart | 8 ++++++-- lib/view/widget/twitter_embed.dart | 4 +--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/view/widget/player_embed.dart b/lib/view/widget/player_embed.dart index b46cd206..023a6a3c 100644 --- a/lib/view/widget/player_embed.dart +++ b/lib/view/widget/player_embed.dart @@ -32,14 +32,18 @@ class PlayerEmbed extends ConsumerWidget { ), initialUrlRequest: URLRequest(url: WebUri.uri(replacedUrl)), shouldOverrideUrlLoading: (controller, navigationAction) async { + final url = navigationAction.request.url; if (navigationAction.hasGesture ?? false) { - final url = navigationAction.request.url; if (url != null) { await launchUrl(ref, url); return NavigationActionPolicy.CANCEL; } } - return NavigationActionPolicy.ALLOW; + if (url?.normalizePath() == replacedUrl.normalizePath()) { + return NavigationActionPolicy.ALLOW; + } else { + return NavigationActionPolicy.CANCEL; + } }, ); diff --git a/lib/view/widget/twitter_embed.dart b/lib/view/widget/twitter_embed.dart index cf9a1435..55746eb8 100644 --- a/lib/view/widget/twitter_embed.dart +++ b/lib/view/widget/twitter_embed.dart @@ -73,9 +73,7 @@ class TwitterEmbed extends HookConsumerWidget { height: height.value, child: InAppWebView( initialSettings: InAppWebViewSettings(transparentBackground: true), - initialUrlRequest: URLRequest( - url: WebUri.uri(Uri.dataFromString(content, mimeType: 'text/html')), - ), + initialData: InAppWebViewInitialData(data: content), onWebViewCreated: (controller) => controller.addJavaScriptHandler( handlerName: 'onReady', callback: (arguments) =>