In Hyperbrowser, a Session is simply a dedicated, cloud-based browser instance that’s yours to direct. It’s like opening a fresh, private browser window—only this one lives in the cloud and is fully controllable through code. Each Session keeps its own cookies, storage, and browsing context, so you can run your tasks without mixing them up.
With our Sessions API, you can spin up these browser environments whenever you need them, configure them with optional parameters, and close them down when you’re done. Higher level endpoints like scrape and crawl also utilize sessions internally to handle their tasks.
Connect with your favorite browser automation libraries
Check out our API Reference to see the Sessions API in more detail
Usage
Starting a session is pretty simple, you can either startup a session directly by connecting to our websocket endpoint with your preferred automation tool like Playwright or Puppeteer, or you can create a session via the Sessions API.
Simple Connect
With this approach, you can startup a session with all default configurations set by just changing one line.
with sync_playwright() as p:
browser = p.chromium.connect_over_cdp(
f"wss://connect.hyperbrowser.ai?apiKey={os.getenv('HYPERBROWSER_API_KEY')}"
)
The simple connect approach doesn't support setting parameters. Use the Session API below for customizing session parameters, such as proxies, web recordings, or extensions.
Connect with Sessions API
With this approach, you have more control over your sessions with additional features or updated configurations.
import asyncio
from pyppeteer import connect
import os
from dotenv import load_dotenv
from hyperbrowser import AsyncHyperbrowser
from hyperbrowser.models.session import CreateSessionParams
# Load environment variables from .env file
load_dotenv()
client = AsyncHyperbrowser(api_key=os.getenv("HYPERBROWSER_API_KEY"))
async def main():
# Create a session and connect to it using Pyppeteer
session = await client.sessions.create(
params=CreateSessionParams(
solve_captchas=True, use_stealth=True, use_proxy=True
)
)
browser = await connect(browserWSEndpoint=session.ws_endpoint)
pages = await browser.pages()
page = pages[0]
# Navigate to a website
print("Navigating to Hacker News...")
await page.goto("https://news.ycombinator.com/")
page_title = await page.title()
print("Page title:", page_title)
await page.evaluate("() => { console.log('Page 1:', document.title); }")
# Clean up
await browser.close()
await client.sessions.stop(session.id)
# Run the async main function
if __name__ == "__main__":
asyncio.run(main())
import asyncio
from playwright.async_api import async_playwright
import os
from dotenv import load_dotenv
from hyperbrowser import AsyncHyperbrowser
# You can also use the sync `Hyperbrowser` to work with sync_playwright
from hyperbrowser.models.session import CreateSessionParams
# Load environment variables from .env file
load_dotenv()
client = AsyncHyperbrowser(api_key=os.getenv("HYPERBROWSER_API_KEY"))
async def main():
# Create a session and connect to it using Playwright
session = await client.sessions.create(
params=CreateSessionParams(
solve_captchas=True, use_stealth=True, use_proxy=True
)
)
# Initialize Playwright and connect to the browser
async with async_playwright() as p:
browser = await p.chromium.connect_over_cdp(session.ws_endpoint)
default_context = browser.contexts[0]
page = default_context.pages[0]
# Navigate to a website
print("Navigating to Hacker News...")
await page.goto("https://news.ycombinator.com/")
page_title = await page.title()
print("Page title:", page_title)
await page.evaluate("() => { console.log('Page 1:', document.title); }")
# Clean up
await browser.close()
await client.sessions.stop(session.id)
# Run the async main function
if __name__ == "__main__":
asyncio.run(main())
Hyperbrowser's CAPTCHA solving and Proxy features require being on a PAID plan.
Puppeteer
Connect with Puppeteer to automate browser actions via a websocket connection
Playwright
Connect with Playwright to automate browser actions via a websocket connection