autogen_ext.agents.web_surfer.playwright_controller#
- class PlaywrightController(downloads_folder: str | None = None, animate_actions: bool = False, viewport_width: int = 1440, viewport_height: int = 900, _download_handler: Callable[[Download], None] | None = None, to_resize_viewport: bool = True)[source]#
Bases:
object
A helper class to allow Playwright to interact with web pages to perform actions such as clicking, filling, and scrolling.
- Parameters:
downloads_folder (str | None) – The folder to save downloads to. If None, downloads are not saved.
animate_actions (bool) – Whether to animate the actions (create fake cursor to click).
viewport_width (int) – The width of the viewport.
viewport_height (int) – The height of the viewport.
_download_handler (Optional[Callable[[Download], None]]) – A function to handle downloads.
to_resize_viewport (bool) – Whether to resize the viewport
- async sleep(page: Page, duration: int | float) None [source]#
Pause the execution for a specified duration.
- async get_interactive_rects(page: Page) Dict[str, InteractiveRegion] [source]#
Retrieve interactive regions from the web page.
- Parameters:
page (Page) – The Playwright page object.
- Returns:
Dict[str, InteractiveRegion] – A dictionary of interactive regions.
- async get_visual_viewport(page: Page) VisualViewport [source]#
Retrieve the visual viewport of the web page.
- Parameters:
page (Page) – The Playwright page object.
- Returns:
VisualViewport – The visual viewport of the page.
- async get_focused_rect_id(page: Page) str | None [source]#
Retrieve the ID of the currently focused element.
- Parameters:
page (Page) – The Playwright page object.
- Returns:
str – The ID of the focused element or None if no control has focus.
- async get_page_metadata(page: Page) Dict[str, Any] [source]#
Retrieve metadata from the web page.
- Parameters:
page (Page) – The Playwright page object.
- Returns:
Dict[str, Any] – A dictionary of page metadata.
- async on_new_page(page: Page) None [source]#
Handle actions to perform on a new page.
- Parameters:
page (Page) – The Playwright page object.
- async back(page: Page) None [source]#
Navigate back to the previous page.
- Parameters:
page (Page) – The Playwright page object.
- async visit_page(page: Page, url: str) Tuple[bool, bool] [source]#
Visit a specified URL.
- Parameters:
page (Page) – The Playwright page object.
url (str) – The URL to visit.
- Returns:
Tuple[bool, bool] – A tuple indicating whether to reset prior metadata hash and last download.
- async page_down(page: Page) None [source]#
Scroll the page down by one viewport height minus 50 pixels.
- Parameters:
page (Page) – The Playwright page object.
- async page_up(page: Page) None [source]#
Scroll the page up by one viewport height minus 50 pixels.
- Parameters:
page (Page) – The Playwright page object.
- async gradual_cursor_animation(page: Page, start_x: float, start_y: float, end_x: float, end_y: float) None [source]#
Animate the cursor movement gradually from start to end coordinates.
- async add_cursor_box(page: Page, identifier: str) None [source]#
Add a red cursor box around the element with the given identifier.
- Parameters:
page (Page) – The Playwright page object.
identifier (str) – The element identifier.
- async remove_cursor_box(page: Page, identifier: str) None [source]#
Remove the red cursor box around the element with the given identifier.
- Parameters:
page (Page) – The Playwright page object.
identifier (str) – The element identifier.
- async click_id(page: Page, identifier: str) Page | None [source]#
Click the element with the given identifier.
- Parameters:
page (Page) – The Playwright page object.
identifier (str) – The element identifier.
- Returns:
Page | None – The new page if a new page is opened, otherwise None.
- async hover_id(page: Page, identifier: str) None [source]#
Hover the mouse over the element with the given identifier.
- Parameters:
page (Page) – The Playwright page object.
identifier (str) – The element identifier.
- async fill_id(page: Page, identifier: str, value: str, press_enter: bool = True) None [source]#
Fill the element with the given identifier with the specified value.
- async scroll_id(page: Page, identifier: str, direction: str) None [source]#
Scroll the element with the given identifier in the specified direction.
- async get_webpage_text(page: Page, n_lines: int = 50) str [source]#
Retrieve the text content of the web page.
- Parameters:
page (Page) – The Playwright page object.
n_lines (int) – The number of lines to return from the page inner text.
- Returns:
str – The text content of the page.