maxun icon indicating copy to clipboard operation
maxun copied to clipboard

Proxy: a {session} placeholder so each run gets its own sticky IP

Open alkaz-nodemaven opened this issue 1 month ago • 2 comments

Most residential proxy providers handle rotation and sticky sessions through the username: something like user-session-abc123 keeps one exit IP, and a new id gives you a new one.

Maxun takes one proxy URL and username/password per user and passes them as-is to every browser context. With a rotating gateway that leaves two options, and neither works well:

  • a rotating username: the IP changes mid-run, which breaks logins and multi-page robots
  • a fixed sticky username: every run of every robot comes from the same IP

Proposal: if the proxy username contains {session}, replace it with a fresh random id each time a browser context is created (a recording or a run). Without the placeholder nothing changes.

It would be a small change where the username is handed to Playwright (RemoteBrowser and the scheduler both build proxyOptions from getDecryptedProxyConfig), plus a short hint under the username field in the proxy settings. It would also cover part of #95 (a different IP per run) for anyone on a rotating gateway.

Happy to send a PR to develop if this sounds good.

alkaz-nodemaven avatar Oct 12 '26 13:10 alkaz-nodemaven

Scouted the call sites today — the proposal lands on a genuinely small patch, here's the map:

getDecryptedProxyConfig feeds exactly three construction points, all building proxyOptions the same way:

  • server/src/api/record.ts (~L565, run start)
  • server/src/workflow-management/scheduler/index.ts (~L59, scheduled runs)
  • server/src/browser-management/classes/RemoteBrowser.ts (~L583, per browser-context creation)

Because all three spread proxyConfig.proxy_username verbatim into Playwright's proxy.username, a shared helper at the single decryption boundary covers every path:

// proxy.ts
import crypto from "crypto";

export function expandSessionPlaceholder(username?: string): string | undefined {
  if (!username || !username.includes("{session}")) return username;
  return username.replace(/\{session\}/g, crypto.randomInt(0, 1e6).toString().padStart(6, "0"));
}

Semantics fall out for free from where the calls already sit:

  • RemoteBrowser: the config is read inside the context-creation block, so expansion there = one sticky IP per context, exactly as the issue wants for recordings.
  • record.ts / scheduler: expansion at run start = one IP per run, stable for the whole run (logins and multi-page flows keep one exit).

Two edge cases worth pinning in the PR:

  1. No placeholder → byte-identical behavior (the early return above guarantees this, so existing users are untouched).
  2. Retries/resume: if a run can re-create a context mid-run (RemoteBrowser relaunch), a naive expansion rotates the IP mid-run — the session id should probably be generated once per run and stashed on the run/browser object, not per launchContext call. That's the only place I'd expect review pushback.

Zero-placeholder users pay nothing, the diff is ~10 lines plus the hint in the proxy settings form. Happy to open a PR for this if nobody's claimed it.

heyuhe2003 avatar Oct 12 '26 14:10 heyuhe2003

@heyuhe2003 pls go ahead - assigned

amhsirak avatar Oct 12 '26 16:10 amhsirak