in src/nova_act/impl/playwright.py [0:0]
def get_page(self, index: int) -> Page:
"""Get an open page by its index in the browser context"""
if self._context is None:
raise ClientNotStarted("Playwright not attached, run start() to start")
if index == -1:
return self._active_page
num_pages = len(self._context.pages)
if num_pages < 1:
raise InvalidPlaywrightState("No pages found in browser context.")
if index <= (-1 * num_pages) or index >= num_pages: # Allow backward indexing for convenience
pages = [f"{i}: {page}" for i, page in enumerate(self._context.pages)]
joined_output = "\n".join(pages)
raise PageNotFoundError(f"Page with index {index} not found. Choose from:\n{joined_output}")
return self._context.pages[index]