Browser

Control a browser directly in your Scrapybara instance with Playwright
1

Start an instance

from scrapybara import Scrapybara
client = Scrapybara(api_key="your_api_key")
instance = client.start_ubuntu()
2

Start a browser session

cdp_url = instance.browser.start().cdp_url
3

Authenticate the session (optional)

To save the authenticated state of a browser session, use the saveAuth method.

auth_state_id = instance.browser.save_auth(name="default").auth_state_id

Now, you can reuse the saved auth state on other instances by passing the auth_state_id to the authenticate method. The browser needs to be started first.

instance.browser.authenticate(auth_state_id=auth_state_id)
4

Connect to the browser

from playwright.sync_api import sync_playwright
playwright = sync_playwright().start()
browser = playwright.chromium.connect_over_cdp(cdp_url)
5

Interact with the browser

page = browser.new_page()
page.goto("https://scrapybara.com")
screenshot = page.screenshot()
6

Stop the browser session

instance.browser.stop()