Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: guard all localStorage access for null WKWebView context (APP-4, 48 users)

Louis Beaumont216c3d9cb840
diff --git a/apps/screenpipe-app-tauri/app/layout.tsx b/apps/screenpipe-app-tauri/app/layout.tsx
index 30eebccec..b34e40073 100644
--- a/apps/screenpipe-app-tauri/app/layout.tsx
+++ b/apps/screenpipe-app-tauri/app/layout.tsx
@@ -55,11 +55,17 @@ export default function RootLayout({
// Debounced write to localStorage
debouncedWrite(() => {
try {
+ // localStorage can be null in Tauri WKWebView during navigation
+ if (!localStorage) return;
localStorage.setItem("console_logs", logs.join("\n"));
} catch (e) {
- // If localStorage is full, clear half the logs
- logs.splice(0, logs.length / 2);
- localStorage.setItem("console_logs", logs.join("\n"));
+ try {
+ // If localStorage is full, clear half the logs
+ logs.splice(0, logs.length / 2);
+ if (localStorage) localStorage.setItem("console_logs", logs.join("\n"));
+ } catch {
+ // localStorage unavailable, skip silently
+ }
}
});
};
diff --git a/apps/screenpipe-app-tauri/components/notification-handler.tsx b/apps/screenpipe-app-tauri/components/notification-handler.tsx
index 77a59b029..843484498 100644
--- a/apps/screenpipe-app-tauri/components/notification-handler.tsx
+++ b/apps/screenpipe-app-tauri/components/notification-handler.tsx
@@ -24,14 +24,18 @@ const NotificationHandler: React.FC = () => {
}
if (permission) {
- const welcomeShown = localStorage.getItem("welcomeNotificationShown");
-
- if (!welcomeShown) {
- sendNotification({
- title: "welcome to screenpipe",
- body: "thank you for using screenpipe! we're dedicated to help you get the most out of screenpipe.",
- });
- localStorage.setItem("welcomeNotificationShown", "true");
+ try {
+ const welcomeShown = localStorage?.getItem("welcomeNotificationShown");
+
+ if (!welcomeShown) {
+ sendNotification({
+ title: "welcome to screenpipe",
+ body: "thank you for using screenpipe! we're dedicated to help you get the most out of screenpipe.",
+ });
+ localStorage?.setItem("welcomeNotificationShown", "true");
+ }
+ } catch {
+ // localStorage unavailable in some WKWebView contexts
}
}
diff --git a/apps/screenpipe-app-tauri/components/onboarding/status.tsx b/apps/screenpipe-app-tauri/components/onboarding/status.tsx
index 14b559376..18da247fd 100644
--- a/apps/screenpipe-app-tauri/components/onboarding/status.tsx
+++ b/apps/screenpipe-app-tauri/components/onboarding/status.tsx
@@ -167,8 +167,8 @@ const OnboardingStatus: React.FC<OnboardingStatusProps> = ({
setIsSendingLogs(true);
try {
const BASE_URL = "https://screenpi.pe";
- const machineId = localStorage.getItem("machineId") || crypto.randomUUID();
- localStorage.setItem("machineId", machineId);
+ const machineId = localStorage?.getItem("machineId") || crypto.randomUUID();
+ try { localStorage?.setItem("machineId", machineId); } catch {}
const identifier = settings.user?.id || machineId;
const type = settings.user?.id ? "user" : "machine";
const logFilesResult = await commands.getLogFiles();
@@ -194,7 +194,7 @@ const OnboardingStatus: React.FC<OnboardingStatusProps> = ({
body: JSON.stringify({ identifier, type }),
});
const { data: { signedUrl, path } } = await signedRes.json();
- const consoleLog = (localStorage.getItem("console_logs") || "").slice(-50000);
+ const consoleLog = (localStorage?.getItem("console_logs") || "").slice(-50000);
const combinedLogs = logContents
.map((log) => `\n=== ${log.name} ===\n${log.content}`)
.join("\n\n") +
diff --git a/apps/screenpipe-app-tauri/components/onboarding/usecases-selection.tsx b/apps/screenpipe-app-tauri/components/onboarding/usecases-selection.tsx
index 627e14659..e411ba9d0 100644
--- a/apps/screenpipe-app-tauri/components/onboarding/usecases-selection.tsx
+++ b/apps/screenpipe-app-tauri/components/onboarding/usecases-selection.tsx
@@ -117,9 +117,12 @@ const OnboardingSelection: React.FC<OnboardingSelectionProps> = ({
// Load saved selection and submission status on mount
useEffect(() => {
- const savedOption = localStorage.getItem("onboarding_usecase");
- const savedOtherText = localStorage.getItem("onboarding_usecase_other");
- const submitted = localStorage.getItem("onboarding_usecase_submitted");
+ let savedOption: string | null = null, savedOtherText: string | null = null, submitted: string | null = null;
+ try {
+ savedOption = localStorage?.getItem("onboarding_usecase");
+ savedOtherText = localStorage?.getItem("onboarding_usecase_other");
+ submitted = localStorage?.getItem("onboarding_usecase_submitted");
+ } catch {}
if (savedOption && !selectedOption) {
handleOptionClick(savedOption);
@@ -135,14 +138,14 @@ const OnboardingSelection: React.FC<OnboardingSelectionProps> = ({
// Save selection when it changes
useEffect(() => {
if (selectedOption) {
- localStorage.setItem("onboarding_usecase", selectedOption);
+ try { localStorage?.setItem("onboarding_usecase", selectedOption); } catch {}
}
}, [selectedOption]);
// Save other text when it changes
useEffect(() => {
if (otherText) {
- localStorage.setItem("onboarding_usecase_other", otherText);
+ try { localStorage?.setItem("onboarding_usecase_other", otherText); } catch {}
}
}, [otherText]);
@@ -156,7 +159,7 @@ const OnboardingSelection: React.FC<OnboardingSelectionProps> = ({
selected_option: selectedOption,
other_text: isOtherSelected ? otherText.trim() : null,
});
- localStorage.setItem("onboarding_usecase_submitted", "true");
+ try { localStorage?.setItem("onboarding_usecase_submitted", "true"); } catch {}
setHasSubmitted(true);
}
diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-search.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-search.tsx
index 2fb680823..f2dfd7c68 100644
--- a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-search.tsx
+++ b/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-search.tsx
@@ -391,7 +391,7 @@ async function getCachedOrGenerateSuggestions(
appStats: AppStats,
): Promise<string[]> {
try {
- const cached = localStorage.getItem(CACHE_KEY);
+ const cached = localStorage?.getItem(CACHE_KEY);
if (cached) {
const parsedCache: CachedSuggestions = JSON.parse(cached);
const isExpired = Date.now() - parsedCache.timestamp > CACHE_DURATION_MS;
@@ -416,7 +416,7 @@ async function getCachedOrGenerateSuggestions(
timestamp: Date.now(),
appsHash: generateAppsHash(appStats),
};
- localStorage.setItem(CACHE_KEY, JSON.stringify(cacheData));
+ try { localStorage?.setItem(CACHE_KEY, JSON.stringify(cacheData)); } catch {}
return suggestions;
} catch (error) {
@@ -676,7 +676,7 @@ prioritize precision over recall - better to return no match than a wrong match.
try {
// Clear cache first
- localStorage.removeItem(CACHE_KEY);
+ try { localStorage?.removeItem(CACHE_KEY); } catch {}
const newSuggestions = await generateSuggestions(
openai,
@@ -692,7 +692,7 @@ prioritize precision over recall - better to return no match than a wrong match.
timestamp: Date.now(),
appsHash: generateAppsHash(appStats),
};
- localStorage.setItem(CACHE_KEY, JSON.stringify(cacheData));
+ try { localStorage?.setItem(CACHE_KEY, JSON.stringify(cacheData)); } catch {}
} catch (error) {
console.warn("failed to regenerate suggestions:", error);
} finally {
diff --git a/apps/screenpipe-app-tauri/components/settings/obsidian-sync-card.tsx b/apps/screenpipe-app-tauri/components/settings/obsidian-sync-card.tsx
index 9d2df50d3..5ad32b482 100644
--- a/apps/screenpipe-app-tauri/components/settings/obsidian-sync-card.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/obsidian-sync-card.tsx
@@ -170,7 +170,8 @@ export function ObsidianSyncCard() {
// Load settings from localStorage on mount
useEffect(() => {
- const saved = localStorage.getItem("obsidian-sync-settings");
+ let saved: string | null = null;
+ try { saved = localStorage?.getItem("obsidian-sync-settings"); } catch {}
if (saved) {
try {
const parsed = JSON.parse(saved);
@@ -182,7 +183,8 @@ export function ObsidianSyncCard() {
setSettingsLoaded(true);
// Load sync history
- const savedHistory = localStorage.getItem("obsidian-sync-history");
+ let savedHistory: string | null = null;
+ try { savedHistory = localStorage?.getItem("obsidian-sync-history"); } catch {}
if (savedHistory) {
try {
setSyncHistory(JSON.parse(savedHistory).slice(0, 10)); // Keep last 10
@@ -212,7 +214,7 @@ export function ObsidianSyncCard() {
// Save settings to localStorage immediately
useEffect(() => {
if (settingsLoaded) {
- localStorage.setItem("obsidian-sync-settings", JSON.stringify(settings));
+ try { localStorage?.setItem("obsidian-sync-settings", JSON.stringify(settings)); } catch {}
}
}, [settings, settingsLoaded]);
@@ -287,7 +289,7 @@ export function ObsidianSyncCard() {
const newEntry: SyncHistoryEntry = { timestamp: new Date().toISOString(), status: "success" };
setSyncHistory(prev => {
const updated = [newEntry, ...prev].slice(0, 10);
- localStorage.setItem("obsidian-sync-history", JSON.stringify(updated));
+ try { localStorage?.setItem("obsidian-sync-history", JSON.stringify(updated)); } catch {}
return updated;
});
toast({
@@ -306,7 +308,7 @@ export function ObsidianSyncCard() {
const newEntry: SyncHistoryEntry = { timestamp: new Date().toISOString(), status: "error", error: event.payload };
setSyncHistory(prev => {
const updated = [newEntry, ...prev].slice(0, 10);
- localStorage.setItem("obsidian-sync-history", JSON.stringify(updated));
+ try { localStorage?.setItem("obsidian-sync-history", JSON.stringify(updated)); } catch {}
return updated;
});
toast({
diff --git a/apps/screenpipe-app-tauri/components/share-logs-button.tsx b/apps/screenpipe-app-tauri/components/share-logs-button.tsx
index fb08d1dee..a4948202d 100644
--- a/apps/screenpipe-app-tauri/components/share-logs-button.tsx
+++ b/apps/screenpipe-app-tauri/components/share-logs-button.tsx
@@ -86,10 +86,11 @@ export const ShareLogsButton = ({
useEffect(() => {
const loadMachineId = async () => {
- let id = localStorage.getItem("machineId");
+ let id: string | null = null;
+ try { id = localStorage?.getItem("machineId"); } catch {}
if (!id) {
id = crypto.randomUUID();
- localStorage.setItem("machineId", id);
+ try { localStorage?.setItem("machineId", id); } catch {}
}
setMachineId(id);
};
@@ -209,7 +210,8 @@ export const ShareLogsButton = ({
})
);
- const consoleLog = (localStorage.getItem("console_logs") || "").slice(-50000); // Last 50KB of console logs
+ let consoleLog = "";
+ try { consoleLog = (localStorage?.getItem("console_logs") || "").slice(-50000); } catch {} // Last 50KB of console logs
const signedRes = await fetch(`${BASE_URL}/api/logs`, {
method: "POST",
diff --git a/apps/screenpipe-app-tauri/components/theme-provider.tsx b/apps/screenpipe-app-tauri/components/theme-provider.tsx
index cea2e4297..c8b4fc40b 100644
--- a/apps/screenpipe-app-tauri/components/theme-provider.tsx
+++ b/apps/screenpipe-app-tauri/components/theme-provider.tsx
@@ -33,10 +33,14 @@ export function ThemeProvider({
const [isLoaded, setIsLoaded] = useState(false);
useEffect(() => {
- const storedTheme = localStorage.getItem(storageKey) as ColorTheme;
- if (storedTheme) {
- setTheme(storedTheme);
- } else {
+ try {
+ const storedTheme = localStorage?.getItem(storageKey) as ColorTheme;
+ if (storedTheme) {
+ setTheme(storedTheme);
+ } else {
+ setTheme("system");
+ }
+ } catch {
setTheme("system");
}
setIsLoaded(true);
@@ -81,13 +85,13 @@ export function ThemeProvider({
const value = {
theme: theme || defaultTheme,
setTheme: (theme: ColorTheme) => {
- localStorage.setItem(storageKey, theme);
+ try { localStorage?.setItem(storageKey, theme); } catch {}
setTheme(theme);
},
toggleTheme: () => {
const currentTheme = theme || defaultTheme;
const newTheme = currentTheme === "light" ? "dark" : "light";
- localStorage.setItem(storageKey, newTheme);
+ try { localStorage?.setItem(storageKey, newTheme); } catch {}
setTheme(newTheme);
},
};
diff --git a/apps/screenpipe-app-tauri/components/update-notification.tsx b/apps/screenpipe-app-tauri/components/update-notification.tsx
index 27b0e5c6d..d216fbec4 100644
--- a/apps/screenpipe-app-tauri/components/update-notification.tsx
+++ b/apps/screenpipe-app-tauri/components/update-notification.tsx
@@ -7,7 +7,8 @@ const UpdateNotification: React.FC<{ checkIntervalHours: number }> = ({
}) => {
useEffect(() => {
const checkForUpdates = async () => {
- const lastCheckTime = localStorage.getItem("lastUpdateCheckTime");
+ let lastCheckTime: string | null = null;
+ try { lastCheckTime = localStorage?.getItem("lastUpdateCheckTime"); } catch {}
const currentTime = Date.now();
if (
@@ -52,7 +53,7 @@ const UpdateNotification: React.FC<{ checkIntervalHours: number }> = ({
console.error("Error checking for updates:", error);
}
- localStorage.setItem("lastUpdateCheckTime", currentTime.toString());
+ try { localStorage?.setItem("lastUpdateCheckTime", currentTime.toString()); } catch {}
}
};
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index c506c9579..be6792893 100755
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -9007,7 +9007,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "2.0.303"
+version = "2.0.304"
dependencies = [
"anyhow",
"async-stream",
@@ -9089,7 +9089,7 @@ dependencies = [
[[package]]
name = "screenpipe-audio"
-version = "0.3.97"
+version = "0.3.98"
dependencies = [
"anyhow",
"bytemuck",
@@ -9137,7 +9137,7 @@ dependencies = [
[[package]]
name = "screenpipe-core"
-version = "0.3.97"
+version = "0.3.98"
dependencies = [
"accessibility",
"accessibility-sys",
@@ -9188,7 +9188,7 @@ dependencies = [
[[package]]
name = "screenpipe-db"
-version = "0.3.97"
+version = "0.3.98"
dependencies = [
"anyhow",
"chrono",
@@ -9212,7 +9212,7 @@ dependencies = [
[[package]]
name = "screenpipe-events"
-version = "0.3.97"
+version = "0.3.98"
dependencies = [
"anyhow",
"chrono",
@@ -9228,7 +9228,7 @@ dependencies = [
[[package]]
name = "screenpipe-integrations"
-version = "0.3.97"
+version = "0.3.98"
dependencies = [
"anyhow",
"image 0.25.9",
@@ -9243,7 +9243,7 @@ dependencies = [
[[package]]
name = "screenpipe-server"
-version = "0.3.97"
+version = "0.3.98"
dependencies = [
"anyhow",
"async-trait",
@@ -9307,7 +9307,7 @@ dependencies = [
[[package]]
name = "screenpipe-vision"
-version = "0.3.97"
+version = "0.3.98"
dependencies = [
"accessibility-sys",
"anyhow",