Isolando sessões de navegador com Playwright em Python (a ideia por trás dos perfis antidetect)
Quem vende online acaba com várias contas abertas: loja, anúncios, marketplace. No mesmo Chrome, cookie e login se misturam. Navegador antidetect resolve isso com perfis isolados. Dá pra entender a ideia em 20 linhas de Python. O que vamos fazer Abrir dois "perfis" com Playwright, cada um com cookies, idioma, fuso, user agent e tela próprios, e confirmar que um não enxerga o outro. Instalação pip…
Local vendors often run multiple accounts on platforms like shops, ads, or marketplaces. When using a single browser like Chrome, cookies and login information get mixed together. An antidetect browser resolves this issue with isolated profiles. You can grasp the concept in just 20 lines of Python.
To begin, launch two profiles using Playwright, each with its own cookies, language, timezone, user agent, and screen resolution. Confirm that one profile cannot see the other.
Install Playwright by running `pip install playwright` and then install Chromium with `playwright install chromium`. The code is as follows:
```python
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
b = p.chromium.launch()
a = b.new_context(
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124 Safari/537.36",
locale="pt-BR",
timezone_id="America/Sao_Paulo",
viewport={"width": 1366, "height": 768}
)
c = b.new_context(
user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) Chrome/124 Safari/537.36",
locale="en-US",
timezone_id="America/New_York",
viewport={"width": 1440, "height": 900}
)
for name, ctx in (("A", a), ("B", c)):
pg = ctx.new_page()
ctx.add_cookies([
{
"name": "conta",
"value": name,
"url": "http://localhost:8765"
}
])
pg.goto("http://localhost:8765")
print(name, pg.evaluate("[navigator.language, Intl.DateTimeFormat().resolvedOptions().timeZone, screen.width]"), [x["value"] for x in ctx.cookies()])
b.close()
```
Before running the code, start a local server, such as `python3 -m http.server 8765`. The output should look like this:
```
A ['pt-BR', 'America/Sao_Paulo', 1366] ['A']
B ['en-US', 'America/New_York', 1440] ['B']
```
Each context has its own cookies and identity, with no one seeing the other's information. This solution provides basic isolation. A true antidetect browser handles dozens of signals, such as canvas, WebGL, and fonts, and allows you to open profiles through an interface without writing code. However, keep in mind that no tool authorizes violating platform rules.
Many shops prohibit duplicate accounts, so always read their terms. If you don't want to code, consider GoLogin, which offers a free plan with 3 profiles and 7 days of testing. Check their pricing page here: https://go.nowto.link/gologin. For more content in Portuguese, visit my newsletter: https://nuvemdev.substack.com. Some links are affiliate links: if you purchase, I may earn a commission with no extra cost to you.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.