From 1eecb8be384d8edc62f8a4253de9462c8b1a6a1f Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Wed, 18 Jun 2025 11:33:14 +0200 Subject: [PATCH] Clear persisted form values if time has expired (#935) --- .../entrypoints/popup/context/NavigationContext.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/browser-extension/src/entrypoints/popup/context/NavigationContext.tsx b/apps/browser-extension/src/entrypoints/popup/context/NavigationContext.tsx index 910c4a674..977464116 100644 --- a/apps/browser-extension/src/entrypoints/popup/context/NavigationContext.tsx +++ b/apps/browser-extension/src/entrypoints/popup/context/NavigationContext.tsx @@ -1,10 +1,11 @@ import React, { createContext, useContext, useEffect, useState, useMemo, useCallback } from 'react'; import { useLocation, useNavigate } from 'react-router-dom'; +import { sendMessage } from 'webext-bridge/popup'; import { storage } from '#imports'; -const LAST_VISITED_PAGE_KEY = 'local:lastVisitedPage'; -const LAST_VISITED_TIME_KEY = 'local:lastVisitedTime'; +const LAST_VISITED_PAGE_KEY = 'session:lastVisitedPage'; +const LAST_VISITED_TIME_KEY = 'session:lastVisitedTime'; const PAGE_MEMORY_DURATION = 120 * 1000; // 2 minutes in milliseconds type NavigationContextType = { @@ -41,6 +42,13 @@ export const NavigationProvider: React.FC<{ children: React.ReactNode }> = ({ ch const timeSinceLastVisit = Date.now() - lastVisitTime; if (timeSinceLastVisit <= PAGE_MEMORY_DURATION) { navigate(lastPage); + } else { + // Duration has expired, clear the last visited page and time. + await storage.removeItem(LAST_VISITED_PAGE_KEY); + await storage.removeItem(LAST_VISITED_TIME_KEY); + + // Clear persisted form values if they exist. + await sendMessage('CLEAR_PERSISTED_FORM_VALUES', null, 'background'); } } }, [navigate]);