Configuración de proxy en Playwright
Haz scraping de páginas renderizadas con JavaScript a través de proxies rotativos con Playwright.
Playwright automatiza los navegadores Chromium, Firefox y WebKit - esencial para hacer scraping de sitios que renderizan contenido con JavaScript. Configura SotaProxy a nivel del lanzamiento del navegador y cada página que abra el navegador se enrutará por el proxy.
Guía de configuración
Node.js - proxy a nivel de navegador
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({
proxy: {
server: 'http://proxy.sotaproxy.com:10000',
username: 'YOUR_USERNAME',
password: 'YOUR_PASSWORD',
},
});
const page = await browser.newPage();
await page.goto('https://httpbin.org/ip');
const content = await page.content();
console.log(content);
await browser.close();
})();Establece el proxy en chromium.launch(). Todas las páginas creadas por esta instancia del navegador se enrutan por SotaProxy.
Python - proxy a nivel de navegador
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(
proxy={
"server": "http://proxy.sotaproxy.com:10000",
"username": "YOUR_USERNAME",
"password": "YOUR_PASSWORD",
}
)
page = browser.new_page()
page.goto("https://httpbin.org/ip")
print(page.content())
browser.close()La misma configuración de proxy en Python. Funciona con sync_playwright y async_playwright.
Proxy por contexto (proxies distintos por pestaña)
const browser = await chromium.launch();
// Each context gets its own proxy
const context1 = await browser.newContext({
proxy: {
server: 'http://proxy.sotaproxy.com:10000',
username: 'YOUR_USERNAME_c_US',
password: 'YOUR_PASSWORD',
},
});
const context2 = await browser.newContext({
proxy: {
server: 'http://proxy.sotaproxy.com:10000',
username: 'YOUR_USERNAME_c_DE',
password: 'YOUR_PASSWORD',
},
});Lanza un navegador pero crea varios contextos con configuraciones de proxy distintas. Cada contexto está aislado - útil para pruebas multirregión.
Automatízalo con la API de SotaProxy
Todo lo anterior funciona sin abrir el panel. Con una clave API, Playwright puede obtener credenciales de proxy actualizadas, comprar nuevos proxies y renovar los que caducan - directamente desde el código.
const API = 'https://api.sotaproxy.com/api/v1'
const H = { Authorization: 'Bearer sk_live_your_key' }
// Every active proxy on your account - no copy-pasting credentials
const { proxies } = await (await fetch(`${API}/proxies`, { headers: H })).json()
const p = proxies[0]
const proxyUrl = `http://${p.login}:${p.password}@${p.ip}:${p.portHttp}`
// Buy more when you scale (price-check first with POST /quote)
await fetch(`${API}/orders`, {
method: 'POST',
headers: { ...H, 'Content-Type': 'application/json', 'Idempotency-Key': 'my-unique-order-id' },
body: JSON.stringify({ product: 'ipv4', countryId: 565, periodId: '1m', quantity: 5 }),
})Proxy at the browser or at the context
Playwright accepts credentials as separate fields rather than inside the URL. Context-level proxies are the feature that matters: every context can hold a different address in one browser process:
Pass server without credentials and put username and password in their own fields. Credentials inside the server URL are ignored by Chromium.
A different address per browser context
One browser, many contexts, each with its own address and its own cookie jar. That is the cheapest way to run parallel identities:
Python: one context per identity
from playwright.sync_api import sync_playwright
BASE = "http://proxy.sotaproxy.com:10000"
with sync_playwright() as p:
browser = p.chromium.launch()
for i in range(1, 6):
ctx = browser.new_context(
proxy={
"server": BASE,
"username": f"login_c_US_s_{i}_ttl_1h",
"password": "password",
},
locale="en-US",
timezone_id="America/New_York",
)
page = ctx.new_page()
page.goto("https://example.com", timeout=30000)- Match locale and timezone to the proxy country. A US address with a Warsaw timezone is a contradiction that fingerprinting scripts read instantly.
- Sticky sessions matter here. A rotation mid-page leaves half the assets loaded from another address.
- Block images and media through routing when you only need markup. It cuts residential traffic several times over.
- Set navigation timeouts to 30 seconds. The default 30000 milliseconds is right for us, shorter values throw away working routes.
Playwright specifics
Credentials inside server are ignored
Chromium strips them. If you see 407 in the network log, this is almost always why.
Localhost bypasses the proxy
Chromium never proxies loopback. Testing against a local mock server tells you nothing about the proxy path.
One context, many identities
Cookies and storage are per context. Reusing a context with a new address hands the site the previous identity on a new IP.
WebRTC still leaks the real address
The proxy does not cover it. Disable WebRTC in the context or the page reports your origin IP to any script that asks.
Notas y consejos
- •Usa headless: false durante el desarrollo para observar el navegador y depurar. Cambia a headless: true en producción.
- •Playwright maneja los proxies HTTPS automáticamente mediante túnel CONNECT - no se necesita configuración adicional.
- •Para sesiones persistentes, incluye un ID de sesión en el parámetro del nombre de usuario para mantener la misma IP entre navegaciones de página.
FAQ
¿Puedo usar Playwright con proxies SOCKS5?
Sí. Cambia la URL del servidor a socks5://proxy.sotaproxy.com:PORT. Consulta el endpoint SOCKS5 en el panel de SotaProxy.
¿Funciona Playwright para hacer scraping de sitios con protección Cloudflare?
Playwright con proxies residenciales maneja la mayoría de los sitios protegidos por Cloudflare. Combínalo con el plugin stealth (playwright-extra + puppeteer-extra-plugin-stealth) para objetivos Cloudflare exigentes.
Integraciones relacionadas
Obtén tus credenciales de proxy
Regístrate, recarga tu saldo y copia tu endpoint en Playwright. Tarda menos de 5 minutos.
Empezar