#!/usr/bin/env bash # Launch Brave with the debugging port socialmag talks to. # # socialmag never holds a password. It drives a browser that is already signed # in as you, which means there has to be a browser, listening, with your # sessions in it. This script is that browser. # # Sign in to your platforms once in the window this opens. The profile is # separate from your everyday Brave on purpose: socialmag navigates tabs and # clicks things, and it should not be doing that in the window you are reading # in. set -euo pipefail PORT="${SOCIALMAG_CDP_PORT:-9336}" PROFILE="${SOCIALMAG_BRAVE_PROFILE:-$HOME/.local/share/brave-socialmag}" BRAVE="" for candidate in brave brave-browser brave-browser-stable; do if command -v "$candidate" >/dev/null 2>&1; then BRAVE="$(command -v "$candidate")" break fi done if [[ -z "$BRAVE" ]]; then echo "error: no brave binary found on PATH" >&2 echo " looked for: brave, brave-browser, brave-browser-stable" >&2 echo " install Brave, or set BRAVE=/path/to/brave and re-run" >&2 exit 1 fi if curl -sf --max-time 2 "http://127.0.0.1:${PORT}/json/version" >/dev/null 2>&1; then echo "error: something is already listening on 127.0.0.1:${PORT}" >&2 echo " socialmag would drive that browser, not the one this script opens." >&2 echo " close it first, or set SOCIALMAG_CDP_PORT to a free port." >&2 exit 1 fi mkdir -p "$PROFILE" echo "brave : $BRAVE" echo "profile : $PROFILE" echo "cdp : http://127.0.0.1:${PORT}" echo # --disable-background-timer-throttling is load-bearing, not tidiness. socialmag # reads five of six platforms in a HIDDEN tab so it never steals your focus. A # throttled background tab stops running the timers those pages use to fetch # their own data, and the reads come back empty with no error. exec "$BRAVE" \ --remote-debugging-port="$PORT" \ --user-data-dir="$PROFILE" \ --disable-background-timer-throttling \ "$@"