Why My Scraping Script Never Steals Your Cursor
A scraping script can stay entirely out of sight while doing its job, which means desktop automation can run quietly alongside real work. More importantly, verifying the owning pid before reuse stops a script from acting on a browser that belongs to another process, a failure mode that can cause unwanted posts under someone else's session.
Chrome automation that never steals the cursor comes down to a few CDP calls plus strict discipline about when to touch window state. The standard `--start-minimized` flag is ignored by modern Chrome, so the working approach is to call `Browser.setWindowBounds` immediately after launching, first pinning the restore position inside the screen, then setting the state to minimized. With three flags that disable renderer backgrounding and timer throttling, a minimized window still renders pages fully, so scraping gets everything it needs from a hidden browser.
The bigger traps are on reuse. Every rerun of the script must not call `bringToFront` or any visibility method, or it will pop the user's manually minimized window back up. To safely reuse a browser, the script records its own pid in a state file and only reuses when that pid is still alive and still owns the port. Port 9222 is shared by every automation tool, so a bare port check can end up operating on someone else's browser. Login is the only reason to show a window, and even then it should appear centered and auto-minimize after five minutes.
CDP flatten mode is a separate trap: page commands need a sessionId, and the error `'Runtime.evaluate' wasn't found` means the command wasn't attached to a page. Finally, these scripts default to read-only; any write operation requires an explicit switch and manual confirmation.
Port 9222 is a shared default on most machines, so a pid check is the only real identity check before driving a browser; without it, an automation script can act on another process's session.
Hiding a Chrome window costs nothing in scraping capability as long as background throttling is disabled, which makes invisible automation a matter of window management discipline rather than a headless-mode trade-off.
The read-only default is a sensible safety posture for unattended scripts, because a script that can write has the same abuse potential as a logged-in user.
Sharing one browser between the script and a human is a genuinely smart move. You attach via CDP and each does its own thing, never stepping on the other's toes. The login state comes straight from the browser, so you skip the back-and-forth of logging in repeatedly.
Thanks. But once you actually try it, 'sharing' turns out to be the biggest pitfall: two scripts crammed into the same browser fight over not just the login state, but also tabs and windows. Today I hit a whole string of them: one script's --stop killed the entire process tree, and another platform's scraper got ECONNREFUSED; a cleanup script also proactively closed all editor tabs, destroying someone's half-filled content. The current approach is 'one browser per platform': CDP port, --user-data-dir, and pid state file each get their own set, and you scan the login state once per platform. Sharing only pays off under one condition: you run exactly one thing at a time. Reusing the login state is indeed nice, that part is correct.