mirror of
https://github.com/browser-use/browser-use
synced 2026-05-06 17:52:15 +02:00
35 lines
675 B
Python
35 lines
675 B
Python
from typing import Optional
|
|
|
|
from pydantic import BaseModel
|
|
|
|
from browser_use.dom.views import ProcessedDomContent
|
|
|
|
|
|
# Pydantic
|
|
class TabInfo(BaseModel):
|
|
"""Represents information about a browser tab"""
|
|
|
|
page_id: int
|
|
url: str
|
|
title: str
|
|
|
|
|
|
class BrowserState(ProcessedDomContent):
|
|
url: str
|
|
title: str
|
|
tabs: list[TabInfo]
|
|
screenshot: Optional[str] = None
|
|
|
|
def model_dump(self) -> dict:
|
|
dump = super().model_dump()
|
|
# Add a summary of available tabs
|
|
if self.tabs:
|
|
dump['available_tabs'] = [
|
|
f'Tab {i+1}: {tab.title} ({tab.url})' for i, tab in enumerate(self.tabs)
|
|
]
|
|
return dump
|
|
|
|
|
|
class BrowserError(Exception):
|
|
"""Base class for all browser errors"""
|