Usa Shifter con Playwright
Ejecuta Chromium, Firefox y WebKit a través de los proxies residenciales y de ISP de Shifter — credenciales en línea, sin necesidad de extensiones adicionales. Soporte de primera clase para proxies en Node, Python, Java y .NET.
Inicio rápido
Instalar
npm install playwright Uso básico
import { chromium } from "playwright";
const browser = await chromium.launch({
proxy: {
server: "http://p.shifter.io:443",
username: "customer-USERNAME-country-us-sid-123ABC",
password: "PASSWORD",
},
});
const page = await browser.newPage();
await page.goto("https://ipinfo.io/json");
console.log(await page.textContent("body"));
// {"ip": "154.16.xxx.xxx", "city": "New York", "country": "US", ...}
await browser.close(); Características
Ejemplos
Geolocalización por contexto (un navegador, múltiples regiones)
Cada contexto de navegador puede tener su propio proxy. Crea un contexto para EE. UU., otro para Reino Unido y otro para Japón dentro de una misma instancia del navegador — la función más potente de Playwright para el scraping localizado en paralelo.
import { chromium } from "playwright";
const browser = await chromium.launch();
async function makeContext(country: string, sid: string) {
return browser.newContext({
proxy: {
server: "http://p.shifter.io:443",
username: `customer-USERNAME-country-${country}-sid-${sid}`,
password: "PASSWORD",
},
userAgent:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
});
}
const [us, uk, jp] = await Promise.all([
makeContext("us", "us-001"),
makeContext("uk", "uk-001"),
makeContext("jp", "jp-001"),
]);
const [usPage, ukPage, jpPage] = await Promise.all([
us.newPage(),
uk.newPage(),
jp.newPage(),
]);
await Promise.all([
usPage.goto("https://www.example.com"),
ukPage.goto("https://www.example.co.uk"),
jpPage.goto("https://www.example.jp"),
]);
console.log({
us: await usPage.title(),
uk: await ukPage.title(),
jp: await jpPage.title(),
});
await browser.close(); Multinavegador (Chromium / Firefox / WebKit)
La misma configuración de proxy en los tres motores. Útil para scraping entre navegadores o para elegir el motor con menor probabilidad de activar la detección de bots en un objetivo concreto.
import { chromium, firefox, webkit, type BrowserType } from "playwright";
const proxy = {
server: "http://p.shifter.io:443",
username: "customer-USERNAME-country-de-city-berlin-sid-456DEF",
password: "PASSWORD",
};
async function visit(engine: BrowserType, label: string) {
const browser = await engine.launch({ proxy });
const page = await browser.newPage();
await page.goto("https://example.de");
const title = await page.title();
await browser.close();
return { label, title };
}
const results = await Promise.all([
visit(chromium, "chromium"),
visit(firefox, "firefox"),
visit(webkit, "webkit"),
]);
console.log(results); Suite de pruebas Playwright Test
Configura Shifter una sola vez en playwright.config.ts para que todas las pruebas pasen por el proxy. Usa variables de entorno para las credenciales y evita incluirlas en el código fuente.
// playwright.config.ts
import { defineConfig } from "@playwright/test";
export default defineConfig({
testDir: "./tests",
workers: 4,
use: {
proxy: {
server: "http://p.shifter.io:443",
username: process.env.SHIFTER_USER!, // e.g. customer-USERNAME-country-us-sid-test
password: process.env.SHIFTER_PASS!,
},
userAgent:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
viewport: { width: 1920, height: 1080 },
ignoreHTTPSErrors: false,
},
});
// tests/products.spec.ts
import { test, expect } from "@playwright/test";
test("US homepage renders", async ({ page }) => {
await page.goto("https://example.com");
await expect(page.getByRole("heading", { level: 1 })).toBeVisible();
});
test("Product page parses", async ({ page }) => {
await page.goto("https://example.com/products/123");
const price = await page.locator(".price").textContent();
expect(price).toMatch(/^\$\d+/);
}); Python: chromium.launch con sesión persistente
Playwright es idéntico en todos los lenguajes. La misma configuración de proxy en forma de diccionario en Python — y el resto de la API refleja la versión de Node.
# pip install playwright
# playwright install chromium
import asyncio
import secrets
from playwright.async_api import async_playwright
async def main():
sid = secrets.token_hex(4)
async with async_playwright() as p:
browser = await p.chromium.launch(
proxy={
"server": "http://p.shifter.io:443",
"username": f"customer-USERNAME-country-fr-city-paris-sid-{sid}-ttl-300",
"password": "PASSWORD",
}
)
context = await browser.new_context(
user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36",
)
page = await context.new_page()
# Multi-step flow — same residential IP across every navigation.
await page.goto("https://example.fr/login", wait_until="networkidle")
await page.fill("#email", "user@example.com")
await page.fill("#password", "secret")
await page.click("button[type=submit]")
await page.wait_for_url("**/dashboard")
rows = await page.locator(".order-row").all_text_contents()
print(f"Found {len(rows)} orders")
await browser.close()
asyncio.run(main()) Preguntas frecuentes
Preguntas frecuentes sobre el uso de Shifter con Playwright.
Pasa un campo `proxy` en las opciones de lanzamiento del navegador con `server`, `username` y `password`. La misma estructura funciona en Chromium, Firefox y WebKit. Las credenciales se pasan en línea — no se necesita ninguna extensión y funciona en modo headless sin configuración adicional.
Empieza a usar Shifter con Playwright
Controla Chromium, Firefox y WebKit a través de los más de 205M de proxies residenciales y de ISP de Shifter, con credenciales en línea y sin necesidad de extensiones. Compatible con Node, Python, Java y .NET.