Why use proxies with Playwright?

Playwright is Microsoft's modern browser automation library with native proxy support. It provides a clean API for proxy configuration with authentication, making it ideal for web scraping and testing across multiple browsers.

Prerequisites

  • Node.js 16 or higher installed
  • npm or yarn package manager
  • DataSea account with proxy credentials
  • Basic JavaScript/TypeScript knowledge

Setup guide

  1. 01

    Get your DataSea credentials

    Sign in to your DataSea dashboard and copy your proxy credentials.

    text
    # DataSea Proxy Configuration
    Proxy Host: pr.datasea.io
    HTTP Port: 7011 (for http:// and https:// websites)
    HTTPS-to-proxy Port: 7010 (TLS between your client and the proxy)
    
    # Your credentials
    Username: your_proxy_username
    Password: your_16_char_password
    
    # Geo-targeting (add to username)
    username_country-UnitedStates
    username_session-abc123
    username_country-UnitedStates_session-abc123
  2. 02

    Install Playwright

    Install Playwright and browser binaries.

    bash
    # Install Playwright
    npm install playwright
    
    # Install browsers
    npx playwright install
    
    # Or install specific browser
    npx playwright install chromium
  3. 03

    Basic proxy configuration

    Playwright has built-in proxy support with authentication - no plugins needed.

    javascript
    const { chromium } = require('playwright');
    
    (async () => {
      const browser = await chromium.launch({
        proxy: {
          server: 'http://pr.datasea.io:7011',
          username: 'your_username',
          password: 'your_password'
        }
      });
    
      const page = await browser.newPage();
    
      await page.goto('https://httpbin.org/ip');
      const content = await page.textContent('body');
      console.log('Proxy IP:', content);
    
      await browser.close();
    })();
  4. 04

    Test your connection

    Verify the proxy is working correctly.

    javascript
    const { chromium } = require('playwright');
    
    async function testProxy() {
      const browser = await chromium.launch({
        proxy: {
          server: 'http://pr.datasea.io:7011',
          username: 'your_username',
          password: 'your_password'
        }
      });
    
      const page = await browser.newPage();
    
      await page.goto('https://api.ipify.org?format=json');
      const ipData = await page.evaluate(() => JSON.parse(document.body.innerText));
    
      console.log('Proxy IP:', ipData.ip);
      console.log('Proxy is working!');
    
      await browser.close();
    }
    
    testProxy();

Key features

Global coverage

Access 195+ countries with residential, datacenter, ISP, and mobile proxies.

Automatic rotation

Get new IPs per request or maintain sticky sessions across pages.

Cross-browser support

Same proxy config works with Chromium, Firefox, and WebKit.

Native proxy support

Built-in proxy configuration with authentication - no extra plugins.

Context isolation

Use different proxies per browser context for parallel scraping.

Geo-targeting

Target specific countries using username parameters.

Common use cases

Cross-browser scraping

Test your scraping across different browser engines.

javascript
const { chromium, firefox, webkit } = require('playwright');

const proxyConfig = {
  server: 'http://pr.datasea.io:7011',
  username: 'your_username',
  password: 'your_password'
};

async function scrapeWithBrowser(browserType, name) {
  const browser = await browserType.launch({ proxy: proxyConfig });
  const page = await browser.newPage();

  await page.goto('https://example.com');
  const title = await page.title();

  console.log(`${name}: ${title}`);
  await browser.close();
}

// Test across all browsers
Promise.all([
  scrapeWithBrowser(chromium, 'Chromium'),
  scrapeWithBrowser(firefox, 'Firefox'),
  scrapeWithBrowser(webkit, 'WebKit')
]);

Geo-targeted content access

Access region-specific content from different countries.

javascript
const { chromium } = require('playwright');

async function scrapeFromCountry(country) {
  const browser = await chromium.launch({
    proxy: {
      server: 'http://pr.datasea.io:7011',
      username: `your_username_country-${country}`,
      password: 'your_password'
    }
  });

  const page = await browser.newPage();
  await page.goto('https://example.com/localized');

  const content = await page.textContent('body');
  console.log(`Content from ${country}:`, content.slice(0, 200));

  await browser.close();
}

// Scrape from multiple countries
const countries = ['US', 'GB', 'DE', 'JP', 'AU'];
Promise.all(countries.map(scrapeFromCountry));

Parallel scraping with different contexts

Use browser contexts to scrape multiple sites with different proxies.

javascript
const { chromium } = require('playwright');

async function parallelScrape(urls) {
  const browser = await chromium.launch();

  const results = await Promise.all(urls.map(async (url, index) => {
    // Each context gets a different proxy/session
    const context = await browser.newContext({
      proxy: {
        server: 'http://pr.datasea.io:7011',
        username: `your_username_session-ctx${index}`,
        password: 'your_password'
      }
    });

    const page = await context.newPage();
    await page.goto(url);

    const title = await page.title();
    await context.close();

    return { url, title };
  }));

  await browser.close();
  return results;
}

const urls = [
  'https://example1.com',
  'https://example2.com',
  'https://example3.com'
];

parallelScrape(urls).then(console.log);

Authenticated session scraping

Login and scrape with sticky sessions to maintain the same IP.

javascript
const { chromium } = require('playwright');

async function authenticatedScrape() {
  const SESSION_ID = 'login' + Date.now(); // 1-32 letters or digits

  const browser = await chromium.launch({
    proxy: {
      server: 'http://pr.datasea.io:7011',
      username: `your_username_country-UnitedStates_session-${SESSION_ID}`,
      password: 'your_password'
    }
  });

  const context = await browser.newContext();
  const page = await context.newPage();

  // Login
  await page.goto('https://example.com/login');
  await page.fill('#email', 'user@example.com');
  await page.fill('#password', 'password123');
  await page.click('button[type="submit"]');

  // Wait for navigation
  await page.waitForURL('**/dashboard');

  // Scrape authenticated content
  const userData = await page.textContent('.user-info');
  console.log('User data:', userData);

  // Save session for later
  await context.storageState({ path: 'auth.json' });

  await browser.close();
}

authenticatedScrape();

Troubleshooting

Proxy Authentication Failed

Solution: Verify your credentials are correct and the username format is valid.

javascript
// Correct proxy configuration
const browser = await chromium.launch({
  proxy: {
    server: 'http://pr.datasea.io:7011',  // Use port 7011
    username: 'your_username',             // Or with targeting: username_country-UnitedStates
    password: 'your_password'              // 16-character password from dashboard
  }
});

Page Load Timeout

Solution: Increase timeout and use appropriate wait conditions.

javascript
// Increase navigation timeout
await page.goto('https://example.com', {
  timeout: 60000,  // 60 seconds
  waitUntil: 'domcontentloaded'
});

// Or set default timeout for all operations
page.setDefaultTimeout(60000);

// Wait for specific element instead of full load
await page.goto('https://example.com');
await page.waitForSelector('.content', { timeout: 30000 });

Different Proxy Per Request

Solution: Create new contexts for different proxies, or use rotating proxies.

javascript
// Option 1: New context per proxy
async function withDifferentProxy(country) {
  const context = await browser.newContext({
    proxy: {
      server: 'http://pr.datasea.io:7011',
      username: `your_username_country-${country}`,
      password: 'your_password'
    }
  });
  return context.newPage();
}

// Option 2: Rotating proxy (new IP each request)
// Just use base username - IPs rotate automatically
const context = await browser.newContext({
  proxy: {
    server: 'http://pr.datasea.io:7011',
    username: 'your_username',  // No session = new IP each request
    password: 'your_password'
  }
});

Frequent blocks

Solution: Use residential proxies and configure realistic browser settings.

javascript
const context = await browser.newContext({
  proxy: {
    server: 'http://pr.datasea.io:7011',
    username: 'your_username_country-UnitedStates',  // Use residential proxies
    password: 'your_password'
  },
  // Realistic browser fingerprint
  viewport: { width: 1920, height: 1080 },
  userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
  locale: 'en-US',
  timezoneId: 'America/New_York',
  // Disable automation flags
  javaScriptEnabled: true,
});

// Add random delays between actions
await page.waitForTimeout(Math.random() * 2000 + 1000);

Get started with industry‑leading proxy access

Connect to 150M+ real IPs in seconds. Built for scale, privacy, and performance. Free trial available.