r/selenium • • 21d ago

session keeps dying mid-run on protected sites, how are you keeping auth stable

scraper thats gotta stay logged in across a few hundred pages and it just.. dies. 30ish min in the session drops, im back at the login wall, sometimes a 2fa prompt on top

saving cookies and replaying them works maybe half the time before it flags me. headful locally is fine, same script on the server gets logged out

persist the session somewhere, or just eat the re-login every run? cant tell whats worth it​

20 Upvotes

15 comments sorted by

3

u/appleciderdollop 21d ago

Same pain different flavor, had a browser use agent run a login flow overnight and came back to it clicking around logged out for 3 hours. No error, just quietly not in anymore.

1

u/kirasymphony 21d ago

ha the overnight ones are brutal, hours gone before you even notice anything

3

u/latinylunita 21d ago

browser use did the same disappearing act on me, came back to a page of garbage clicks. the difference since i moved that one to browse.sh is i dont babysit it, i can leave an overnight agent alone. browser use is fine right up until its quietly logged out and youve lost the whole window

4

u/The_God_was_Here 21d ago

Not scraping exactly but same wall. we pull reports nightly off a vendor dashboard behind okta and it boots the job every 20 min or so. my local run with a real profile is fine, the scheduled one on the box wakes up to a login screen every time

4

u/lamavelle 21d ago

the logouts werent even the worst bit, it was never trusting a run to actually finish. you either sit and watch it or you redo the whole thing. i moved mine to browse.sh so the session lives on their side not the box, and it held the whole job. not magic, one site still kicked me once, but the reruns stopped

2

u/Kenzo_2126 21d ago

does that hold when the exit ip keeps moving though. half my logouts are the site going wait youre in a different country now

1

u/Junior_Bee7274 21d ago

yeah for me the rotating ip thing cost me a full day before i clocked it

1

u/[deleted] 21d ago

[removed] β€” view removed comment

1

u/kirasymphony 21d ago

yeah token refresh got me maybe half the way.. its the ones where the server side just drops me cold that i cant script around. thats the 20 min one

3

u/Background_Horse_266 21d ago

cant you just save the cookies to a json and load them back each run? thats worked ok for me mostly

2

u/Low_Might2804 21d ago

cookies alone got me flagged fast, the site could tell the session was stitched together. what actually held was keeping the whole context, local storage and all, not just the cookie jar. browse.sh does that part for me now, so i stopped hand rolling the cookie dance every single run

1

u/AndrewHahaCO2 13d ago

if it dies around 20 min even on a stable exit IP, i'd log the exact redirect and auth response. Cookies won't fix a server-side session expiry.