Rayobyte Guides

Using Rayobyte Proxies With Playwright

How to use Rayobyte proxies in Playwright for Node.js and Python: browser and context-level proxies, a different sticky session per context, route blocking to save bandwidth, and scaling tips.

By Team of Monkeys Editorial Updated 3 min read Affiliate disclosure

This guide contains affiliate links to Geonode, Webshare and Rayobyte. If you buy through them we may earn a commission, at no extra cost to you.

Rayobyte with Playwright illustration showing Playwright connecting through Rayobyte to Browser, covering contexts, sessions 3jdej38j4

Why Playwright is convenient with proxies

Playwright accepts proxy credentials directly, and it can set a different proxy per browser context. That makes it easy to run several Rayobyte sessions, each with its own IP, inside one browser process. Our Playwright proxies guide covers the general setup.

Node.js

javascript
import { chromium } from "playwright";

const browser = await chromium.launch({
  proxy: {
    server: `http://${process.env.RAYOBYTE_HOST}:${process.env.RAYOBYTE_PORT}`,
    username: process.env.RAYOBYTE_USER,
    password: process.env.RAYOBYTE_PASS,
  },
});
const page = await browser.newPage();
await page.goto("https://httpbin.org/ip");
console.log(await page.textContent("body"));
await browser.close();

Python

python
import os
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(proxy={
        "server": f"http://{os.environ['RAYOBYTE_HOST']}:{os.environ['RAYOBYTE_PORT']}",
        "username": os.environ["RAYOBYTE_USER"],
        "password": os.environ["RAYOBYTE_PASS"],
    })
    page = browser.new_page()
    page.goto("https://httpbin.org/ip")
    print(page.text_content("body"))
    browser.close()

One session per context

Contexts are isolated browser sessions with their own cookies. Give each context its own sticky session by building the username from the dashboard's template with a unique session ID:

javascript
import { randomUUID } from "node:crypto";

async function newSessionContext(browser) {
  const sid = randomUUID().slice(0, 10);
  return browser.newContext({
    proxy: {
      server: `http://${process.env.RAYOBYTE_HOST}:${process.env.RAYOBYTE_PORT}`,
      username: process.env.RAYOBYTE_USER_TEMPLATE.replace("{session}", sid),
      password: process.env.RAYOBYTE_PASS,
    },
  });
}

On some Chromium versions, context-level proxies require a proxy at launch too; pass a placeholder such as { server: "http://per-context" } when launching. Premium Residential sessions last up to 120 minutes and can end early, so recreate the context on failure. See Rayobyte sticky sessions.

Residential tip: Before scaling, run a short pilot with Rayobyte on your real targets and record success rate, latency and GB per result. Our our complete Rayobyte guide explains which Rayobyte product fits which job.

Block heavy resources

javascript
await page.route("**/*", (route) => {
  const t = route.request().resourceType();
  return ["image", "media", "font"].includes(t) ? route.abort() : route.continue();
});

On per-GB products this is the single biggest saving.

Location and fingerprint

Match the context's locale, time zone and geolocation to the proxy's location:

javascript
browser.newContext({ locale: "de-DE", timezoneId: "Europe/Berlin", proxy: { /* ... */ } });

See Rayobyte geo-targeting.

Scaling

  • Run several contexts per browser rather than many browsers.
  • Close contexts when done to free memory.
  • Cap concurrent contexts to your server's capacity and your plan's concurrency. See concurrency and threads.
  • For heavy scale without managing browsers, consider rayobrowse.

HTTP/3

Rayobyte's residential network supports HTTP/3, and Chromium uses it on supporting sites if QUIC isn't disabled. Don't pass flags that disable QUIC unless you need to. See HTTP/3 proxies.

Proxy tip: If your residential usage goes up and down, compare Geonode: its per-GB residential bandwidth doesn't expire, so you only pay for what you use. See using Geonode with Playwright.

How it compares

See Rayobyte vs Geonode for Playwright, Rayobyte vs Webshare for Playwright and all three for Playwright.

If you're still shortlisting, compare these options with the wider market in our best proxies guide, and use our cheap proxies guide to estimate a sensible budget. For browser automation in depth, see our Puppeteer proxies guide.

Budget tip: If you want a cheap proxy to try this with, Webshare has a free plan with 10 datacenter proxies and 1 GB of bandwidth a month, no card required. Paid lists let you pick proxy count, bandwidth and location. See using Webshare with Playwright.

Key takeaways

  • Playwright accepts Rayobyte credentials directly in the proxy option.
  • Use one context per sticky session for many IPs in one browser.
  • Block images, fonts and media to cut bandwidth.
  • Match locale and time zone to the proxy location.

FAQ

Can Playwright use a different Rayobyte IP per context?

Yes. Set a proxy with a unique session ID on each context.

Does Playwright support SOCKS5 with authentication?

Chromium doesn't support SOCKS5 credentials. Use HTTP, or whitelist your IP.

Which Rayobyte product suits Playwright?

Premium Residential for protected sites; rotating ISP for speed where accepted; static ISP for logged-in profiles.

Affiliate disclosure: Team of Monkeys is an affiliate of Geonode, Webshare and Rayobyte. Links and banners marked as sponsored, and links to Geonode, Webshare and Rayobyte in the text, use our referral links, and we may earn a commission if you buy through them, at no extra cost to you. Our explanations and comparisons are written to be useful whichever provider you choose.

Editorial note: Proxy providers change their pools, features and prices often, so treat any figures here as typical ranges at the time of writing and confirm current terms with the provider before you buy.