#!/usr/bin/env bash # # revive_notebooklm_auth.sh โ€” Revive Chrome headless and extract cookies. # # This script handles: # 1. Cleaning up stale Chrome processes on port 9223. # 2. Relaunching Chrome headless pointing to the default profile. # 3. Waiting for Chrome to initialize. # 4. Running the cookie extraction python script to sync auth.json/profile. # # Safe to run at any time when NotebookLM CLI reports authentication errors. # set -e CDP_PORT=9223 PROFILE_NAME="default" CHROME_PROFILE_DIR="$HOME/.notebooklm-mcp-cli/chrome-profiles/$PROFILE_NAME" echo "=== [NotebookLM Auth Revive] ===" # 1. Kill stale Chrome processes on port 9223 echo "๐Ÿงน Cleaning up any running Chrome processes on port $CDP_PORT..." # Find process using port 9223 and kill it PID=$(lsof -t -i:$CDP_PORT || true) if [ -n "$PID" ]; then echo "Found process $PID using port $CDP_PORT. Terminating..." kill -15 "$PID" 2>/dev/null || true sleep 2 # Force kill if still alive kill -9 "$PID" 2>/dev/null || true fi # Also kill general zombie chrome instances started by notebooklm pkill -f "remote-debugging-port=$CDP_PORT" || true sleep 1 # Delete SingletonLock if present (avoids Chrome crash/lock loop) LOCK_FILE="$CHROME_PROFILE_DIR/SingletonLock" if [ -f "$LOCK_FILE" ]; then echo "๐Ÿ”“ Removing SingletonLock file to unlock Chrome profile..." rm -f "$LOCK_FILE" fi # Ensure profile directory exists mkdir -p "$CHROME_PROFILE_DIR" # 2. Relaunch Chrome headless echo "๐Ÿš€ Launching Google Chrome headless on port $CDP_PORT..." google-chrome \ --headless=new \ --no-sandbox \ --disable-gpu \ --disable-dev-shm-usage \ --disable-extensions \ --no-first-run \ --no-default-browser-check \ --remote-debugging-port=$CDP_PORT \ --remote-debugging-address=127.0.0.1 \ --remote-allow-origins="*" \ --user-data-dir="$CHROME_PROFILE_DIR" > /dev/null 2>&1 & CHROME_PID=$! echo "Chrome process started with PID: $CHROME_PID" # 3. Wait for Chrome CDP to become ready echo "โณ Waiting for Chrome CDP interface to be ready..." for i in {1..15}; do if curl -s "http://127.0.0.1:$CDP_PORT/json/version" > /dev/null; then echo "โœ… Chrome CDP is ready!" break fi if [ "$i" -eq 15 ]; then echo "โŒ Chrome CDP failed to become ready after 15 seconds." echo "Check if Chrome is installed or logs for errors." exit 1 fi sleep 1 done # 4. Run cookie extraction & refresh script echo "๐Ÿ”‘ Extracting session cookies and auth tokens..." SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" python3 "$SCRIPT_DIR/notebooklm_refresh.py" --port "$CDP_PORT" --profile "$PROFILE_NAME" echo "=== [Revive Completed Successfully] ==="