From 84004e8d006a5f576f34ea989a922b07279a4d4c Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Tue, 5 Nov 2024 18:25:21 -0500 Subject: [PATCH 1/2] testing behavior of javascriptEnabled --- src/components/DappBrowser/BrowserTab.tsx | 42 +++++++++++++++-------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/components/DappBrowser/BrowserTab.tsx b/src/components/DappBrowser/BrowserTab.tsx index 02cca1a6425..27e46ec9802 100644 --- a/src/components/DappBrowser/BrowserTab.tsx +++ b/src/components/DappBrowser/BrowserTab.tsx @@ -52,7 +52,6 @@ import { useAnimatedTab } from './hooks/useAnimatedTab'; import { useTabScreenshotProvider } from './hooks/useTabScreenshotProvider'; import { freezeWebsite, getWebsiteMetadata, unfreezeWebsite } from './scripts'; import { BrowserTabProps, ScreenshotType } from './types'; -import { normalizeUrlForRecents } from './utils'; export const BrowserTab = React.memo(function BrowserTab({ addRecent, setLogo, setTitle, tabId }: BrowserTabProps) { const { isDarkMode } = useColorMode(); @@ -207,6 +206,7 @@ const FreezableWebViewComponent = ({ try { // validate message and parse data const parsedData = typeof data === 'string' ? JSON.parse(data) : data; + parsedData?.jsEnabled && console.log(parsedData); if (!parsedData || (!parsedData.topic && !parsedData.payload)) return; if (parsedData.topic === 'websiteMetadata') { @@ -257,6 +257,7 @@ const FreezableWebViewComponent = ({ (event: WebViewEvent) => { if (event.nativeEvent.loading) return; const { origin } = new URL(event.nativeEvent.url); + console.log('======> handleOnLoad', origin); if (typeof webViewRef !== 'function' && webViewRef?.current) { if (!webViewRef?.current) { @@ -346,20 +347,33 @@ const FreezableWebViewComponent = ({ } }, [isActiveTab, webViewRef]); + console.log( + '======> rendered tab ', + JSON.stringify( + { + tabId, + tabUrl, + isActiveTab, + javaScriptEnabled: isActiveTab, + }, + null, + 2 + ) + ); + return ( - - - + ); }; From 901d918a32834b05411e570f83d980d593064151 Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Mon, 25 Nov 2024 12:01:57 -0500 Subject: [PATCH 2/2] use setActive method on webview --- src/components/DappBrowser/BrowserTab.tsx | 43 ++++++++--------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/src/components/DappBrowser/BrowserTab.tsx b/src/components/DappBrowser/BrowserTab.tsx index dc644eeb370..0c3395dc243 100644 --- a/src/components/DappBrowser/BrowserTab.tsx +++ b/src/components/DappBrowser/BrowserTab.tsx @@ -207,7 +207,6 @@ const FreezableWebViewComponent = ({ try { // validate message and parse data const parsedData = typeof data === 'string' ? JSON.parse(data) : data; - parsedData?.jsEnabled && console.log(parsedData); if (!parsedData || (!parsedData.topic && !parsedData.payload)) return; if (parsedData.topic === 'websiteMetadata') { @@ -258,7 +257,6 @@ const FreezableWebViewComponent = ({ (event: WebViewEvent) => { if (event.nativeEvent.loading) return; const { origin } = new URL(event.nativeEvent.url); - console.log('======> handleOnLoad', origin); if (typeof webViewRef !== 'function' && webViewRef?.current) { if (!webViewRef?.current) { @@ -348,39 +346,28 @@ const FreezableWebViewComponent = ({ if (webViewRef?.current) { if (isActiveTab) { webViewRef.current.injectJavaScript(unfreezeWebsite); + webViewRef.current.setActive(true); } else { webViewRef.current.injectJavaScript(freezeWebsite); + webViewRef.current.setActive(false); } } }, [isActiveTab, webViewRef]); - console.log( - '======> rendered tab ', - JSON.stringify( - { - tabId, - tabUrl, - isActiveTab, - javaScriptEnabled: isActiveTab, - }, - null, - 2 - ) - ); - return ( - + + + ); };