diff --git a/background.ts b/background.ts index 4e2e800..7529424 100644 --- a/background.ts +++ b/background.ts @@ -1,3 +1,18 @@ -import { init } from "./memory"; +import { init } from './memory'; -init(); +console.log('🔴 [DIAGNOSTYKA] Wczytywanie background.ts, TARGET =', process.env.TARGET); + +// Inicjalizacja pamięci storage +try { + init(); + console.log('✅ init() zakończone pomyślnie'); +} catch (error) { + console.error('❌ init() nie powiodło się:', error); +} + +// Log zakończenia inicjalizacji +if (process.env.TARGET === 'chrome') { + console.log('🔵 Service worker Chrome Rentgen zainicjalizowany (używa chrome.storage.session)'); +} else { + console.log('🦊 Strona tła Firefox Rentgen zainicjalizowana'); +} \ No newline at end of file diff --git a/components/report-window/report-window.tsx b/components/report-window/report-window.tsx index 5dc58e8..d870c76 100644 --- a/components/report-window/report-window.tsx +++ b/components/report-window/report-window.tsx @@ -24,6 +24,24 @@ function Report() { if (!origin) { return
Błąd: brak parametru "origin"
; } + + // Oczekiwanie na gotowość pamięci Chrome + const [memoryReady, setMemoryReady] = React.useState(process.env.TARGET !== 'chrome'); + + React.useEffect(() => { + if (process.env.TARGET === 'chrome') { + const memory = getMemory(); + if (typeof (memory as any).waitUntilReady === 'function') { + (memory as any).waitUntilReady().then(() => { + setMemoryReady(true); + console.log('✅ Memory gotowa dla okna raportu'); + }); + } else { + setMemoryReady(true); + } + } + }, []); + const [counter] = useEmitter(getMemory()); const rawAnswers = url.searchParams.get('answers'); const [answers, setAnswers] = React.useState( @@ -32,22 +50,32 @@ function Report() { const [mode, setMode] = React.useState(url.searchParams.get('mode') || 'survey'); const [scrRequestPath, setScrRequestPath] = React.useState(''); - const clusters = getMemory().getClustersForOrigin(origin || ''); + // Pobieranie klastrów tylko gdy pamięć jest gotowa + const clusters = memoryReady ? getMemory().getClustersForOrigin(origin || '') : {}; React.useEffect(() => { - if (!origin) return; + if (!origin || !memoryReady) return; const url = new URL(document.location.toString()); url.searchParams.set('origin', origin); url.searchParams.set('answers', JSON.stringify(answers)); url.searchParams.set('mode', mode); history.pushState({}, 'Rentgen', url.toString()); - }, [mode, answers, origin]); + }, [mode, answers, origin, memoryReady]); + + // Wyświetlanie wczytywania w trakcie oczekiwania na pamięć + if (!memoryReady) { + return
Wczytywanie danych z rozszerzenia...
; + } + const visited_url = Object.values(clusters) .sort((a, b) => (a.lastModified > b.lastModified ? -1 : 1)) .find((cluster) => !!cluster.lastFullUrl)?.lastFullUrl; - if (!visited_url) { - return
Wczytywanie...
; + // Jeśli nie znaleziono visited_url, próba skonstruowania z origin + const finalVisitedUrl = visited_url || origin; + + if (!finalVisitedUrl) { + return
Błąd: nie można znaleźć adresu strony
; } const result = ( @@ -55,7 +83,7 @@ function Report() { {mode === 'survey' ? ( cluster.getMarkedRequests().length > 0 + (cluster) => cluster.hasMarks() )} onComplete={(answers) => { setAnswers(parseAnswers(answers)); @@ -68,11 +96,11 @@ function Report() { {mode === 'screenshots' ? ( @@ -83,10 +111,10 @@ function Report() { @@ -95,28 +123,19 @@ function Report() { )} ); - return ( - -
- -
- {origin ? ( - <> - Generowanie raportu - {origin} - - ) : ( - Przejdź do wybranej strony internetowej - )} -
-
-
{result}
-
- ); + return result; } catch (e) { console.error(e); - return
ERROR! {JSON.stringify(e)}
; + return ( +
+

+ Wystąpił błąd +

+

Najprawdopodobniej Rentgen napotkał stronę, której nie jest w stanie obsłużyć.

+

{(e as Error).toString()}

+
+ ); } } -ReactDOM.render(, document.getElementById('app')); +ReactDOM.render(, document.getElementById('app')); \ No newline at end of file diff --git a/components/sidebar/sidebar.tsx b/components/sidebar/sidebar.tsx index 6fdd0de..d4709ff 100644 --- a/components/sidebar/sidebar.tsx +++ b/components/sidebar/sidebar.tsx @@ -12,6 +12,8 @@ const Sidebar = () => { const url = new URL(document.location.toString()); const origin = url.searchParams.get('origin'); + // Chrome: Oczekiwanie na gotowość pamięci + const [memoryReady, setMemoryReady] = React.useState(process.env.TARGET !== 'chrome'); const [minValueLength, setMinValueLength] = React.useState( localStorage.getItem('minValueLength') === null ? 7 @@ -44,8 +46,24 @@ const Sidebar = () => { : false ); + // Oczekiwanie na gotowość pamięci Chrome React.useEffect(() => { - if (!origin) return; + if (process.env.TARGET === 'chrome') { + const memory = getMemory(); + if (typeof (memory as any).waitUntilReady === 'function') { + (memory as any).waitUntilReady().then(() => { + setMemoryReady(true); + console.log('✅ Memory gotowa dla sidebara'); + }); + } else { + setMemoryReady(true); + } + } + }, []); + + React.useEffect(() => { + if (!origin || !memoryReady) return; + for (const cluster of Object.values(getMemory().getClustersForOrigin(origin))) { if (cluster.hasMarks()) { return setMarksOccurrence(true); @@ -53,9 +71,24 @@ const Sidebar = () => { } return setMarksOccurrence(false); - }, [eventCounts['*']]); + }, [eventCounts['*'], memoryReady]); if (!origin) return
Błąd: Brak parametru "origin"
; + + // Wyświetlanie stanu wczytywania dla Chrome + if (!memoryReady) { + return ( +
+
+ +
+ Ładowanie danych... +
+
+
+ ); + } + return (
@@ -121,12 +154,12 @@ const Sidebar = () => { {localStorage.getItem('blottingBrowser') === - 'nikttakniesplamitwojejprzeglądarkijakspidersweb' ? ( + 'nikttakniesplamitwojejprzeglądarki jakspidersweb' ? (