Skip to main content
Version: v2

Playwright Configurations

This page covers advanced Playwright configurations for users already familiar with basic Playwright connections to Browserless. If you haven't set up your basic connection yet, start with our Connect Playwright guide.

Here are some advanced configurations you can explore:

Advanced Connection Methods

Understanding Connection Types

The basic guide covers connectOverCDP as the recommended method. For detailed comparison of connection methods and when to use each, see our Browser Versions documentation.

Multi-Browser Support

For Firefox and WebKit automation, you must use the connect method since CDP is Chrome-only. Complete examples and browser-specific configurations are available in our Browser Versions guide.

Performance Optimization

Package Optimization

Switch to playwright-core for production deployments to reduce bundle size:

npm install playwright-core

Error Handling and Retry Logic

Implement robust error handling for production environments:

async function withRetry(operation, maxRetries = 3) {  
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
return await operation();
} catch (error) {
if (attempt === maxRetries) throw error;

console.log(`Attempt ${attempt} failed, retrying...`);
await new Promise(resolve => setTimeout(resolve, 1000 * attempt));
}
}
}

Advanced Session Management

Timeout Configuration

For custom session timeouts and launch parameters, see our comprehensive Launch Options documentation.

Browser Context Configuration

Advanced context options for stealth, geolocation, and viewport settings:

const context = await browser.newContext({  
extraHTTPHeaders: {
'User-Agent': 'Custom User Agent String'
},
viewport: { width: 1920, height: 1080 },
deviceScaleFactor: 1,
geolocation: { longitude: -122.4194, latitude: 37.7749 },
permissions: ['geolocation']
});
note

Advanced browser context options (stealth, geolocation, viewport, etc.) are only available when using connectOverCDP. These options are not supported with the standard connect method.

Integration with Browserless Features

Stealth Mode Integration

For comprehensive bot detection bypass, see our Stealth documentation. Basic stealth integration:

const browser = await chromium.connectOverCDP(  
`wss://production-sfo.browserless.io/chromium/stealth?token=${TOKEN}`
);

Proxy Configuration

For built-in residential proxies and advanced proxy setups, see our Proxies documentation. Context-level proxy configuration for third-party providers:

const context = await browser.newContext({  
proxy: {
server: "http://proxy-provider.com:8080",
username: "username",
password: "password"
}
});

Version Compatibility

Ensure your Playwright version matches Browserless supported versions. Check the versions compatibility page for current supported versions.

Next Steps

Ready to take your Playwright automation to the next level? Explore these advanced features: