Skip to content

fix: clear IndexedDB/localStorage before each query to prevent stale-cache bug#42

Open
koffuxu wants to merge 1 commit into
PleasePrompto:masterfrom
koffuxu:master
Open

fix: clear IndexedDB/localStorage before each query to prevent stale-cache bug#42
koffuxu wants to merge 1 commit into
PleasePrompto:masterfrom
koffuxu:master

Conversation

@koffuxu

@koffuxu koffuxu commented May 28, 2026

Copy link
Copy Markdown

Problem

NotebookLM persists the full conversation history in the browser's IndexedDB. Because ask_question.py uses a persistent Chrome profile (user_data_dir), every run reloaded the entire accumulated history from previous sessions. This caused two failure modes:

  1. Wrong answer returned – the answer-detection loop found an old message that appeared "stable" and returned it instead of waiting for the actual response.
  2. Timeout – after multiple runs, queued/pending answers from prior sessions filled the conversation. The loop waited for a new message that never arrived within the 2-minute window.

Fix

scripts/ask_question.py

  • Navigate to the root origin first (https://notebooklm.google.com/) and wipe localStorage, sessionStorage, and all IndexedDB databases via page.evaluate() before loading the target notebook. This ensures the page always starts with 0 messages.
  • Simplify response detection: set previous_count = 0 (no pre-snapshot needed) and accept any response where count > 0 or text changed, stable across 3 consecutive polls (~1.5 s).
  • JS focus() before typing to bypass any lingering Material Design overlay backdrops that can block click() after UI interactions.
  • Wait for textarea to clear after pressing Enter as a reliable confirmation that the question was accepted.

scripts/browser_utils.py

  • Use click(force=True) in StealthUtils.human_type() to bypass overlay backdrops.

Testing

Verified with headless Chromium on macOS. Query "方言识别支持哪几种方言?" returns a correct, on-topic answer in under 5 seconds (3 stable polls).

🤖 Generated with Claude Code

…cache bug

NotebookLM persists the full conversation in the browser's IndexedDB.
On every run the persistent Chrome profile reloaded the entire accumulated
history, causing the answer-detection loop to treat old messages as the
current response and either return stale content or spin until timeout.

Fix:
- Navigate to notebooklm.google.com root first and wipe IndexedDB,
  localStorage, and sessionStorage via page.evaluate() before loading
  the target notebook. This ensures the page always starts with 0 messages
  so the first response that appears is the answer to the current question.
- Replace click-based textarea focus with JS focus() to bypass any lingering
  Material Design overlay backdrops left after UI interactions.
- Replace click() with click(force=True) in StealthUtils.human_type() for
  the same reason.
- Simplify response-detection loop: set previous_count = 0 (no pre-snapshot
  needed) and accept any response where count > 0 or text changed, stable
  across 3 consecutive polls (~1.5 s).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant