Playwright
We support Playwright's Chrome DevTools Protocol (CDP) connection method, which provides a reliable way to connect to BrowserCloud. This method is similar to how Puppeteer operates and is well-suited for most automation tasks. Playwright's Connect method is also supported, but more restrictive.
Once you have gotten your API key, you can connect Playwright to BrowserCloud.
Below are the examples of javascript and python scripts using BrowserCloud:
- Javascript
- Python
- Java
- C#
import { chromium } from "playwright-core";
// Connecting to Chrome locally
const browser = await chromium.launch();
// Connecting to Chrome via BrowserCloud
const browser = await chromium.connectOverCDP(
`wss://chrome-v2.browsercloud.io?token=${TOKEN}`
);
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
# Connecting to Chrome locally
browser = p.chromium.launch()
# Connecting to Chrome via BrowserCloud
browser = p.chromium.connect_over_cdp(
f"wss://chrome-v2.browsercloud.io?token={TOKEN}"
)
package org.example;
import com.microsoft.playwright.*;
public class Main {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
// Connecting to Chrome locally
Browser browserLocal = playwright.chromium().launch();
// Connecting to Chrome via BrowserCloud
Browser browser = playwright.chromium().connectOverCDP(
String.format("wss://chrome-v2.browsercloud.io?token=%s", TOKEN)
);
}
}
}
using Microsoft.Playwright;
namespace PlaywrightExample
{
class Program
{
public static async Task Main(string[] args)
{
using var playwright = await Playwright.CreateAsync();
// Connecting to Chrome locally
var browserLocal = await playwright.Chromium.LaunchAsync();
// Connecting to Chrome via BrowserCloud
var browser = await playwright.Chromium.ConnectOverCDPAsync(
$"wss://chrome-v2.browsercloud.io?token={TOKEN}"
);
}
}
}
Time to scale out your playwright apps as well as to use APIs and helper functions right through BrowserCloud!