From f6974d23e12ae095daae5217619c6de1c73fff74 Mon Sep 17 00:00:00 2001 From: Hunain Bin Sajid Date: Wed, 13 Nov 2024 11:40:13 +0500 Subject: [PATCH] fix: could not establish connection error --- src/components/main.tsx | 4 ++++ src/pages/popup/Popup.tsx | 24 ++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/components/main.tsx b/src/components/main.tsx index 452164d..772a063 100644 --- a/src/components/main.tsx +++ b/src/components/main.tsx @@ -26,6 +26,7 @@ export function Main(props: IMain): JSX.Element { const [currentTabState, setCurrentTabState] = useState(TAB_STATE.NONE); const fetchTabState = async () => { + try { const tab = await getCurrentTab(); const { data } = await sendMessageTab(tab.id!, { type: "tab", @@ -51,6 +52,9 @@ export function Main(props: IMain): JSX.Element { setActiveSidebar(SIDEBAR[2]); } } + } catch (error) { + console.log("Error fetching tab state", error); + } }; useEffect(() => { diff --git a/src/pages/popup/Popup.tsx b/src/pages/popup/Popup.tsx index ea6a3df..363546b 100644 --- a/src/pages/popup/Popup.tsx +++ b/src/pages/popup/Popup.tsx @@ -97,16 +97,20 @@ export default function Popup(): JSX.Element { }); setIsConnected(!!data.isConnected); if (data.isConnected) { - const tab = await getCurrentTab(); - const { data } = await sendMessageTab(tab.id!, { - type: "tab", - subtype: "get-tab-state", - }); - sendMessageTab(tab.id!, { - type: "tab", - subtype: "reload-state", - eventType: data?.tabState, - }); + try { + const tab = await getCurrentTab(); + const { data } = await sendMessageTab(tab.id!, { + type: "tab", + subtype: "get-tab-state", + }); + sendMessageTab(tab.id!, { + type: "tab", + subtype: "reload-state", + eventType: data?.tabState, + }); + } catch (error) { + console.log("Error in popup from sendMessageTab", error); + } } };