Skip to main content
Learn to extract data from any website using Zenrows’ Browser Sessions (formerly, Scraping Browser) with Playwright. This guide walks you through creating your first browser-based scraping request that can handle complex JavaScript-heavy sites with full browser automation. Zenrows’ Browser Sessions provides cloud-based Chrome instances you can control using Playwright. Whether dealing with dynamic content, complex user interactions, or sophisticated anti-bot protection, you can get started in minutes with Playwright’s powerful automation capabilities.

1. Set Up Your Project

Set Up Your Development Environment

Before diving in, ensure you have the proper development environment and Playwright installed. Browser Sessions works seamlessly with both Python and Node.js versions of Playwright.
While previous versions may work, we recommend using the latest stable versions for optimal performance and security.
Python 3+ installed (latest stable version recommended). Using an IDE like PyCharm or Visual Studio Code with the Python extension is recommended.
If you need help setting up your environment, check out our detailed Playwright web scraping guide

Get Your API Key and Connection URL

Sign Up for a free Zenrows account and get your API key from the Browser Sessions dashboard. You’ll need this key to authenticate your WebSocket connection.

2. Make Your First Request

Start with a simple request to understand how Browser Sessions works with Playwright. We’ll use the E-commerce Challenge page to demonstrate how to connect to the browser and extract the page title.
Replace YOUR_ZENROWS_API_KEY with your actual API key and run the script:

Expected Output

The script will print the page title:
Perfect! You’ve just made your first web scraping request with the Zenrows Browser Sessions using Playwright.

3. Build a Real-World Scraping Scenario

Let’s scale up to a practical scraping scenario by extracting product information from the e-commerce site. Using Playwright’s powerful selectors and data extraction methods, we’ll modify our code to extract product names, prices, and URLs from the page.

Run Your Application

Execute your script to test the scraping functionality:
Example Output The script will extract and display product information:
Congratulations! 🎉 You’ve successfully built a real-world scraping scenario with Playwright and the Zenrows Browser Sessions.

4. Alternative: Using the Zenrows Browser SDK

For a more streamlined development experience, you can use the Zenrows Browser SDK instead of managing WebSocket URLs manually. The SDK simplifies connection management and provides additional utilities.
The Zenrows Browser SDK is currently only available for JavaScript. For more details, see the GitHub Repository.

Install the SDK

Node.js

Quick Migration from WebSocket URL

If you have existing Playwright code using the WebSocket connection, migrating to the SDK requires minimal changes: Before (WebSocket URL):
Node.js
After (SDK):
Node.js

Complete Example with SDK

Node.js

SDK Benefits

  • Simplified configuration: No need to manually construct WebSocket URLs
  • Better error handling: Built-in error messages and debugging information
  • Future-proof: Automatic updates to connection protocols and endpoints
  • Additional utilities: Access to helper methods and advanced configuration options
The SDK is particularly useful for production environments where you want cleaner code organization and better error handling.

How Playwright with Browser Sessions Helps

Combining Playwright with Zenrows’ Browser Sessions provides powerful advantages for web scraping:

Key Benefits

  • Cloud-based browser instances: Run Playwright scripts on remote Chrome instances, freeing up local resources for other tasks.
  • Seamless integration: Connect your existing Playwright code to Zenrows with just a WebSocket URL change - no complex setup required.
  • Advanced automation: Use Playwright’s full feature set, which includes page interactions, form submissions, file uploads, and complex user workflows.
  • Built-in anti-detection: Benefit from residential proxy rotation and genuine browser fingerprints automatically.
  • Cross-browser support: While we use Chromium for optimal compatibility, Playwright’s API remains consistent across different browser engines.
  • High concurrency: Scale your Playwright scripts with up to 200 concurrent browser instances on Scale, more on Enterprise.
  • Reliable execution: Cloud infrastructure ensures consistent performance without local browser management overhead.

Troubleshooting

Below are common issues you might encounter when using Playwright with Browser Sessions:
1

Connection Refused

If you receive a Connection Refused error, it might be due to:
  • API Key Issues: Verify that you’re using the correct API key.
  • Network Issues: Check your internet connection and firewall settings.
  • WebSocket Endpoint: Ensure that the WebSocket URL (wss://browser.zenrows.com) is correct.
2

Empty Data or Timeout Errors

  • Use page.waitForSelector() to ensure elements load before extraction
  • Increase timeout values for slow-loading pages
    scraper.js
  • Verify CSS selectors are correct using browser developer tools
  • Add page.waitForLoadState('networkidle') for dynamic content
3

Browser Context Issues

  • Use existing context when available: browser.contexts[0] if browser.contexts else await browser.new_context()
  • Properly close pages and browsers to prevent resource leaks
  • Handle exceptions properly to ensure cleanup occurs
4

Geolocation Blocks

Although Zenrows rotates IPs, some websites may block them based on location. Try adjusting the region or country settings.
For more information, check our Browser Sessions Region Documentation and Country Documentation.
5

Get Help From Zenrows Experts

Our support team is available to assist you if issues persist despite following these solutions. Use the Browser Sessions dashboard or email us for personalized help from Zenrows experts.

Next Steps

You now have a solid foundation for Playwright-based web scraping with Zenrows. Here are some recommended next steps:

Frequently Asked Questions (FAQ)

Yes, Zenrows Browser Sessions is compatible with Puppeteer as well. The integration is similar, requiring only a change in the connection method to utilize our WebSocket endpoint.
For detailed instructions, refer to our Puppeteer Integration article.
No, Zenrows Browser Sessions handles proxy configuration and IP rotation automatically. You don’t need to set up proxies manually.
Currently, Zenrows Browser Sessions does not support CAPTCHA solving. For handling CAPTCHAs, you may need to use third-party services.
Consider using our Fetch for additional features like CAPTCHA solving, advanced anti-bot bypass, and more.
Yes! Browser Sessions supports the full Playwright API. You can use page interactions, screenshots, PDF generation, network interception, and all other Playwright features seamlessly.
You can create multiple pages within the same browser context using await browser.newPage() or await context.newPage(). Each page operates independently while sharing the same browser session.
Absolutely! Playwright’s expect() assertions, waitForSelector(), and other built-in retry mechanisms work perfectly with Browser Sessions. These features help handle dynamic content and improve scraping reliability.
Use Playwright’s standard screenshot methods:
The screenshot will be saved locally while the browser runs in the cloud.
Yes! You can intercept requests, modify responses, and monitor network traffic using Playwright’s page.route() and page.on('request') methods with Browser Sessions.
The main difference is that the browser runs in Zenrows’ cloud infrastructure instead of locally. This provides better IP rotation, fingerprint management, and resource efficiency while maintaining the exact same Playwright API.
File downloads work with Playwright’s standard download handling. Use page.waitForDownload() and the download will be transferred from the cloud browser to your local environment automatically.