For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DiscordDashboard
DocumentationAPI ReferenceCookbook
DocumentationAPI ReferenceCookbook
  • Get Started
    • Introduction
    • Quickstart
    • Best Practices
  • Guides
    • Act SDK
    • Auth States
    • Conversations
    • Tools
  • Providers
    • OpenAI
    • Anthropic
  • Instances
    • Ubuntu
      • Browser
      • Code Execution
      • Environment Variables
    • Browser
    • Windows
  • Resources
    • Starter Templates
    • Cursor Rules
    • Cookbook
Logo
DiscordDashboard
InstancesUbuntu

Browser

Control a browser directly in your Scrapybara instance with Playwright
Was this page helpful?
Previous

Code Execution

Execute code in your Scrapybara instance
Next
Built with
Python
TypeScript
1

Start an instance

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

Start a browser session

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

Authenticate the session (optional)

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

1auth_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.

1instance.browser.authenticate(auth_state_id=auth_state_id)
4

Connect to the browser

1from playwright.sync_api import sync_playwright
2
3playwright = sync_playwright().start()
4browser = playwright.chromium.connect_over_cdp(cdp_url)
5

Interact with the browser

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

Stop the browser session

1instance.browser.stop()