Camoufox with Residential Proxies: geoip, Sticky Sessions, Limits
Run Camoufox behind authenticated residential proxies: how geoip=True finds the exit IP, pinning locale, sticky sessions, persistent profiles and resource use.
Exitway team··8 min read
Camoufox is a patched Firefox driven through Playwright. It generates a coherent device fingerprint and, with geoip=True, derives timezone, geolocation and WebRTC IP from the proxy’s exit address. Behind a residential proxy, the working setup is:
- the HTTP endpoint (not SOCKS5)
- a sticky session per browser
- the country in the proxy username
- a pinned
locale - an explicit check for
InvalidIPat launch
Tested with camoufox 0.5.9 (browser 158.0.1-beta.41, Playwright 1.62.0) on Python 3.12 in a Debian container. Every snippet below ran against gw.exitway.net. Parameter names come from the installed package, not older docs.
Install in a container
Camoufox needs GTK and a few X libraries, even when headless:
apt-get install -y --no-install-recommends libgtk-3-0 libx11-xcb1 libasound2 \
libdbus-glib-1-2 libxtst6 libxt6 libpci3 xvfb
pip install "camoufox[geoip]"
python -m camoufox fetch # downloads the browser and the GeoIP database
python -m camoufox version # prints package, browser and storage info
On our image, camoufox version reported a 2.4 GB browsers directory and a 116.6 MB GeoIP database. Bake both into the image. Don’t fetch them at container start.
Minimal launch with an authenticated proxy
The proxy argument takes the Playwright dict. Exitway’s username carries the targeting: -country-de for the exit country, -session-<id> (1-32 letters and digits) for a sticky IP, and -lifetime-<minutes> (up to 1440) for how long it sticks.
import os
from camoufox.sync_api import Camoufox
USER = os.environ["EXITWAY_USER"]
PASS = os.environ["EXITWAY_PASS"]
proxy = {
"server": "http://gw.exitway.net:7777",
"username": f"{USER}-country-de-session-de01-lifetime-30",
"password": PASS,
}
with Camoufox(
proxy=proxy,
geoip=True, # exit IP -> timezone, geolocation, WebRTC IP
locale="de-DE", # pin it: geoip alone draws the language at random
os="windows",
headless="virtual", # Xvfb on Linux
humanize=True,
) as browser:
page = browser.new_page()
page.goto("https://example.com/", timeout=60_000)
print(page.evaluate("""() => ({
lang: navigator.language,
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
ua: navigator.userAgent,
})"""))
Port 7777 is Residential, 8888 is Datacenter. The residential vs datacenter article explains when the cheaper one is enough.
What geoip=True actually does
From the 0.5.9 source:
- Find the exit IP. Before the browser starts, Camoufox makes Python
requestscalls through your proxy to api.ipify.org, checkip.amazonaws.com, ipinfo.io/ip, icanhazip.com, ifconfig.co/ip and ipecho.net/plain, in that order, with a 15-second timeout each. The first valid IP wins. - Look it up locally. The IP goes through the bundled MaxMind-format database to get country, latitude/longitude and timezone. No browser traffic is involved.
- Apply it. The timezone, a
navigator.geolocationposition (with the permission reported as granted) and the WebRTC IP are set to match. The locale is set only if you didn’t pass one. - Cache it. The lookup is
lru_cached by proxy URL for the life of the Python process.
Step 3 hides a trap: the locale is drawn at random, weighted by CLDR language-population data for the country. We sampled the selector 200 times per country:
| Country | Most frequent draws (out of 200) |
|---|---|
| DE | en-DE 67, de-DE 60, fr-DE 20, bar-DE 18, ru-DE 8, nds-DE 6 |
| FR | fr-FR 126, en-FR 44, es-FR 17 |
| US | en-US 180, es-US 13 |
A German exit IP gets de-DE less than a third of the time. bar-DE (Bavarian) is a valid locale but an unusual Accept-Language. Pass locale= and the explicit value wins. With geoip on a German IP and locale="de-DE" we measured Accept-Language: de-DE,de;q=0.9, navigator.language de-DE, timezone Europe/Berlin (offset -60) and a Berlin geolocation.
Why the session must be sticky
The IP lookup is a separate connection from Python. The browser’s connections come later. In rotating mode every new connection gets a new IP, so the IP that was geolocated is not the IP the site sees. A single page load also opens several connections. Use one -session-<id> per browser (or per context, below) and set -lifetime- longer than the job. Rotating vs sticky sessions covers the trade-offs.
Two more consequences:
- Multi-timezone countries.
-country-uscan exit in any US timezone. Don’t hardcodeAmerica/New_York. Let geoip read the actual IP, which is what it’s for. - The cache outlives the IP. If a long-running process relaunches with the same proxy string after the session expired, it reuses the cached IP while the gateway may hand out a new one. Use a fresh session ID per launch.
When the proxy fails
Failures show up in different places depending on when they happen:
| Situation | What you get |
|---|---|
geoip=True, no bandwidth (402) |
camoufox.exceptions.InvalidIP: Failed to get IP address: ... Tunnel connection failed: 402 Payment Required, after 0.8 s, before the browser starts |
geoip=True, wrong password (407) |
Same InvalidIP, with 407 Proxy Authentication Required |
| No geoip, 402 on an HTTPS page | Page.goto: <unknown error>, page stays about:blank |
| No geoip, wrong password | Page.goto: NS_ERROR_PROXY_CONNECTION_REFUSED, Firefox “proxy server is refusing connections” page (localized to the locale you set) |
socks5:// server with credentials |
Browser does not support socks5 proxy authentication at launch |
Use the HTTP endpoint. Every Exitway port speaks both protocols, so changing the scheme is enough.
<unknown error> tells you nothing, so check the proxy before you start a 1 GB browser. A plain-HTTP request through the gateway returns its errors as ordinary responses with an X-Exitway-Error header. On success it returns the exit IP, which you can pass to geoip directly:
import os
import requests
from camoufox.sync_api import Camoufox
USER, PASS = os.environ["EXITWAY_USER"], os.environ["EXITWAY_PASS"]
SESSION = "de02"
username = f"{USER}-country-de-session-{SESSION}-lifetime-60"
proxy_url = f"http://{username}:{PASS}@gw.exitway.net:7777"
# 1. Preflight over plain HTTP: gateway errors come back as a normal
# response with X-Exitway-Error, success returns the exit IP.
r = requests.get("http://ipinfo.io/json", timeout=20,
proxies={"http": proxy_url, "https": proxy_url})
if "X-Exitway-Error" in r.headers:
raise SystemExit(f"proxy refused: {r.status_code} "
f"{r.headers['X-Exitway-Error']}")
exit_ip = r.json()["ip"]
# 2. Same session id -> same exit IP for the browser
proxy = {"server": "http://gw.exitway.net:7777",
"username": username, "password": PASS}
with Camoufox(proxy=proxy, geoip=exit_ip, locale="de-DE",
os="windows", headless="virtual", humanize=True) as browser:
page = browser.new_page()
page.goto("https://example.com/", timeout=60_000)
print(exit_ip, page.evaluate(
"Intl.DateTimeFormat().resolvedOptions().timeZone"))
On an account with no bandwidth this prints proxy refused: 402 insufficient_balance and exits without launching a browser. geoip accepts an IP string, so the lookup runs once, under your control.
Headless modes and humanize
headless= |
What runs | Observed |
|---|---|---|
False |
Headed Firefox, needs a display | Most faithful, unusable on a bare server |
True |
Firefox headless | WebGL was unavailable in our container |
"virtual" |
Headed Firefox inside Xvfb, managed by Camoufox | WebGL present; about 100 MB more memory than True |
humanize=True moves the cursor along a curved path before clicks. It adds latency: a click took 0.16 s without it, 1.43 s with True and 1.13 s with humanize=0.5 (the cap on movement time, in seconds).
On a Linux server, a fingerprint claiming Windows or macOS makes Camoufox turn on canvas noise and warn that the browser “reads as a privacy-hardened Firefox”. canvas_noise=False turns it off. Choose deliberately: a Linux fingerprint is consistent with the host, but Linux is a small slice of desktop traffic.
Persistent profiles
import os
from camoufox.sync_api import Camoufox
USER, PASS = os.environ["EXITWAY_USER"], os.environ["EXITWAY_PASS"]
SESSION = "de01"
proxy = {
"server": "http://gw.exitway.net:7777",
"username": f"{USER}-country-de-session-{SESSION}-lifetime-60",
"password": PASS,
}
with Camoufox(
persistent_context=True,
user_data_dir=f"profiles/{SESSION}", # cookies, storage, cache
proxy=proxy,
geoip=True,
locale="de-DE",
os="windows", # keep the OS stable across launches
headless="virtual",
) as context: # a BrowserContext, not a Browser
page = context.pages[0] if context.pages else context.new_page()
page.goto("https://example.com/", timeout=60_000)
What we observed over repeated launches on one profile:
- Cookies with an expiry and
localStoragepersisted. Session cookies did not, as in stock Firefox. - The fingerprint is not stored in the profile. Without
os=, one profile came back as macOS on the first launch and Windows on the second. Withos="windows"the OS stayed fixed, but screen size still changed (2560x1440, then 1536x864).
Name the profile after the session ID so the stored cookies, the exit IP and the country stay paired.
Many identities in one browser
Launching Firefox per identity is expensive. NewContext gives each context its own fingerprint and proxy:
import os
from camoufox.exceptions import InvalidIP
from camoufox.sync_api import Camoufox, NewContext
USER, PASS = os.environ["EXITWAY_USER"], os.environ["EXITWAY_PASS"]
IDENTITIES = [ # (country, locale, session id)
("de", "de-DE", "berlin01"),
("fr", "fr-FR", "paris01"),
("jp", "ja-JP", "tokyo01"),
]
with Camoufox(headless=True, os="windows") as browser:
for country, locale, sid in IDENTITIES:
proxy = {
"server": "http://gw.exitway.net:7777",
"username": f"{USER}-country-{country}-session-{sid}-lifetime-30",
"password": PASS,
}
try:
# Looks up exit IP + timezone through this proxy, then draws
# a fresh fingerprint for the context
context = NewContext(browser, proxy=proxy, locale=locale)
except InvalidIP as exc:
print(sid, "exit lookup failed:", exc)
continue
page = context.new_page()
page.goto("https://example.com/", timeout=60_000)
print(sid, page.evaluate("navigator.language"), page.title())
context.close()
NewContext runs its own lookup through the context’s proxy (http://ip-api.com/json), with a 15-second timeout. With no bandwidth, each context failed with 402 Client Error: Payment Required for url: http://ip-api.com/json?.... On a funded account the Paris context loaded with fr-FR and Europe/Paris, while the Berlin and Tokyo lookups timed out on a slow exit and were skipped by the except InvalidIP branch. That branch is not optional: retry a skipped identity with a new session ID. If you already know the exit IP and timezone, pass webrtc_ip= and timezone_id= to skip the lookup. Geo-targeted scraping covers choosing countries per job.
Resource usage and when not to use a full browser
Total memory (PSS) of every process in the container after loading example.com:
| Setup | Memory |
|---|---|
Camoufox, headless=True, 1 context |
907 MB (launch 2.2 s) |
Camoufox, headless=True, 5 contexts |
1,181 MB |
Camoufox, headless="virtual", 1 context |
1,015 MB |
| Chrome 158 via Patchright, headless, 1 context | 556 MB |
| curl_cffi Session after 10 requests | 34 MB |
Bandwidth grows the same way: a browser downloads scripts, fonts and images you don’t need. block_images=True saves traffic, but Camoufox’s own warning says blocking images “has been reported to cause detection issues on major WAFs”.
Use Camoufox when the content only exists after JavaScript runs, or when the page checks the browser environment. If the data is in the HTML or an XHR/JSON response you can call directly, curl_cffi gives you a browser-grade TLS fingerprint with a few percent of the memory. For a Chromium-based option, see Patchright, nodriver and SeleniumBase with authenticated proxies.
Responsible use
These tools exist so legitimate collection of public data doesn’t break on fragile clients. Camoufox doesn’t make a browser invisible, and nothing here is a way around a site’s access controls. Collect public pages only. Respect robots.txt and published rate limits, keep concurrency per site modest, and read the site’s terms before you automate it. Don’t use it for account creation, credential testing or purchase automation. Exitway’s Acceptable Use Policy applies to all traffic.
Run it on Exitway
Residential bandwidth starts at $0.70/GB with no subscription, and unused GB never expire, which suits bursty browser workloads. Create an account, copy your proxy credentials from the dashboard, and see /docs for every username parameter.