Skip to content

Preserve owned browser state across chat saves#3883

Merged
louis030195 merged 10 commits into
screenpipe:mainfrom
thisisharsh7:preserve-browser-state-across-chat-saves
Jun 8, 2026
Merged

Preserve owned browser state across chat saves#3883
louis030195 merged 10 commits into
screenpipe:mainfrom
thisisharsh7:preserve-browser-state-across-chat-saves

Conversation

@thisisharsh7

@thisisharsh7 thisisharsh7 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

This PR preserves owned browser state across chat saves.

Before this change, the browser sidebar state could be lost if the browser opened before the conversation file existed, or if a later foreground/background chat save rewrote the conversation without keeping browserState.

This change adds a small per-conversation browser-state cache and makes both chat save paths preserve the latest browser state, so reopening a chat restores the browser sidebar more reliably.

Before -

Screen.Recording.2026-06-06.at.9.35.39.PM.mov
Screen.Recording.2026-06-07.at.6.51.36.AM.mov

After -

Screen.Recording.2026-06-06.at.9.30.03.PM.mov
Screen.Recording.2026-06-07.at.6.46.11.AM.mov

@thisisharsh7 thisisharsh7 marked this pull request as ready for review June 6, 2026 17:02

@Anshgrover23 Anshgrover23 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thisisharsh7

  • Can you also show the repro starting from two completely fresh chats (before any conversation file exists)? That's the main scenario this PR is fixing.
  • Please add an E2E test covering this flow so we don't regress in the future.

@louis030195 louis030195 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thisisharsh7 lgtm, tests look clean too

generated by the screenpipe pr-review pipe (https://screenpi.pe), not written by a human — reply and tag @louis030195 if it got something wrong.

Comment on lines +95 to +101
export function markCachedBrowserStateCleared(
conversationId: string | null | undefined,
updatedAt = Date.now(),
): void {
if (!conversationId) return;
writeRaw(storageKey(conversationId), JSON.stringify({ cleared: true, updatedAt }));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thisisharsh7 Do we clear these localStorage entries when a conversation is permanently deleted?

@thisisharsh7 thisisharsh7 marked this pull request as draft June 7, 2026 04:36
@thisisharsh7

Copy link
Copy Markdown
Contributor Author

Updated -

  • clear cached browser state when a conversation is permanently deleted
  • add an E2E regression test for the fresh-chat browser-state flow

@louis030195

Copy link
Copy Markdown
Collaborator

how does this scale if user has 10k chats?

@thisisharsh7

Copy link
Copy Markdown
Contributor Author

how does this scale if user has 10k chats?

It should be fine. This only touches browser state for the chat you're currently opening or saving not all chats.
So even if someone has 10k chats we're still just:

  • reading that chat's file
  • reading that chat's cached browser state
  • picking the newer one
  • saving that chat back if needed

@louis030195 louis030195 merged commit 44f899f into screenpipe:main Jun 8, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants