Skip to main content
Playwright is a modern Node.js library for browser automation that supports Chromium, Firefox, and WebKit. Its robust feature set and simple API make it an excellent choice for scraping complex, interactive websites. Integrating 2extract.com proxies with Playwright is done by passing proxy settings directly to the browser.newContext() or browser.newPage() method.

Basic Setup

Here’s how to launch a Playwright browser instance that routes all traffic through our proxy gateway.
You’ll need playwright installed in your project: npm install playwright
basic_setup.js
In Playwright, proxy credentials are set at the browser or context level. All new pages within that context will automatically use the same proxy settings, which is simpler than Puppeteer’s per-page authentication.

Real-World Example: Checking Flight Prices on Google Flights

Flight prices are a classic example of geo-dependent data. Let’s build a script to check the price of a one-way flight from Berlin to London on a specific date, making the request appear as if it’s coming from Germany (DE).
flights_scraper.js
Google is a highly sophisticated target! The URL structure and CSS selectors on Google Flights are complex and change frequently. This script demonstrates the technical integration, but for reliable, large-scale scraping of Google, you will need to build very robust error handling and adapt your selectors regularly.

What This Example Demonstrates

  • Cross-Browser Automation: How to use Playwright’s powerful API to control a browser.
  • Simplified Proxy Setup in Playwright: Shows the modern approach of setting proxy credentials at the browser-launch level.
  • Scraping Dynamic Content: How to wait for specific elements (page.waitForSelector) to appear on a JavaScript-heavy page before trying to extract data.
  • Advanced Locators: Uses Playwright’s locator API for more resilient element selection.