The BrowserActor class provides methods for browser automation, screenshot capture, and video recording.

Constructor

actor = BrowserActor(
    driver: Optional[Browser] = None,
    headless: Optional[bool] = True,
    record_video: Optional[bool] = False
)

Parameters

driver
Browser

Optional Playwright browser instance. If not provided, a new one will be created

headless
boolean
default: "true"

Whether to run the browser in headless mode

record_video
boolean
default: "false"

Enable video recording of browser interactions

Properties

page

@property
def page() -> Page

Returns the current page instance, creating a new one if none exists.

has_recording

@property
def has_recording() -> bool

Returns whether a video recording is available.

recording_data

@property
def recording_data() -> Optional[bytes]

Returns the cached video recording data if available.

has_screenshot

@property
def has_screenshot() -> bool

Returns whether a screenshot is available.

screenshot_data

@property
def screenshot_data() -> Optional[bytes]

Returns the cached screenshot data if available.

Methods

take_screenshot

def take_screenshot(full_page: bool = False) -> Optional[Image.Image]

Takes and returns a screenshot of the current page.

Parameters

full_page
boolean
default: "false"

If True, captures the full scrollable page. If False, captures only the current viewport.

Returns

PIL Image of the screenshot if page is open, None otherwise.

def navigate_to_url(url: str) -> None

Navigates the browser to the specified URL.

Parameters

url
string

The URL to navigate to

execute

def execute(interaction: BrowserInteraction) -> None

Executes a browser interaction (click, scroll, type, hover, or wait).

Parameters

interaction
BrowserInteraction

The browser interaction to execute

save_recording

def save_recording(output_path: str) -> bool

Saves the browser recording to the specified path if available.

Parameters

output_path
string

Path where the recording should be saved

Returns

True if recording was saved successfully, False otherwise.

close

def close() -> None

Cleans up all browser resources and saves recording if enabled. Should be called when finished using the browser.