Appearance
Browser API Reference
Related Tutorial
- Browser Automation Guide - Complete guide to browser automation
Overview
The Browser module provides comprehensive browser automation capabilities including navigation, element interaction, screenshot capture, and content extraction. It enables automated testing and web scraping workflows with support for proxy configuration, fingerprinting, and stealth mode.
Requirements
- Requires
agb-browser-use-1image for browser automation features
BrowserFingerprintContext
python
class BrowserFingerprintContext()Browser fingerprint context configuration.
BrowserProxy
python
class BrowserProxy()Browser proxy configuration. Supports two types of proxy: custom proxy, built-in proxy. built-in proxy support two strategies: restricted and polling.
BrowserViewport
python
class BrowserViewport()Browser viewport options.
BrowserScreen
python
class BrowserScreen()Browser screen options.
BrowserFingerprint
python
class BrowserFingerprint()Browser fingerprint options.
BrowserOption
python
class BrowserOption()browser initialization options.
Browser
python
class Browser(BaseService)Browser provides browser-related operations for the session.
initialize
python
def initialize(option: "BrowserOption") -> boolInitialize the browser instance with the given options. Returns True if successful, False otherwise.
initialize_async
python
async def initialize_async(option: "BrowserOption") -> boolInitialize the browser instance with the given options asynchronously. Returns True if successful, False otherwise.
destroy
python
def destroy()Destroy the browser instance.
screenshot
python
async def screenshot(page, full_page: bool = False, **options) -> bytesTakes a screenshot of the specified page with enhanced options and error handling. This is the async version of the screenshot method.
Arguments:
pagePage - The Playwright Page object to take a screenshot of. This is a required parameter.full_pagebool - Whether to capture the full scrollable page. Defaults to False. **options: Additional screenshot options that will override defaults. Common options include:- type (str): Image type, either 'png' or 'jpeg' (default: 'png')
- quality (int): Quality of the image, between 0-100 (jpeg only)
- timeout (int): Maximum time in milliseconds (default: 60000)
- animations (str): How to handle animations (default: 'disabled')
- caret (str): How to handle the caret (default: 'hide')
- scale (str): Scale setting (default: 'css')
Returns:
bytes: Screenshot data as bytes.
Raises:
BrowserError: If browser is not initialized.
RuntimeError: If screenshot capture fails.
ActOptions
python
class ActOptions()Options for configuring the behavior of the act method.
ActResult
python
class ActResult()Result of the act method.
ObserveOptions
python
class ObserveOptions()Options for configuring the behavior of the observe method.
ObserveResult
python
class ObserveResult()Result of the observe method.
ExtractOptions
python
class ExtractOptions(Generic[T])Options for configuring the behavior of the extract method.
BrowserAgent
python
class BrowserAgent(BaseService)BrowserAgent handles browser automation and agent logic.
navigate_async
python
async def navigate_async(url: str) -> strNavigates a specific page to the given URL.
Arguments:
urlstr - The URL to navigate to.
Returns:
str: A string indicating the result of the navigation.
screenshot
python
def screenshot(page=None,
full_page: bool = True,
quality: int = 80,
clip: Optional[Dict[str, float]] = None,
timeout: Optional[int] = None) -> strTakes a screenshot of the specified page.
Arguments:
pageOptional[Page] - The Playwright Page object to take a screenshot of. If None, the agent's currently focused page will be used.full_pagebool - Whether to capture the full scrollable page.qualityint - The quality of the image (0-100), for JPEG format.clipOptional[Dict[str, float]] - An object specifying the clipping region {x, y, width, height}.timeoutOptional[int] - Custom timeout for the operation in milliseconds.
Returns:
str: A base64 encoded data URL of the screenshot, or an error message.
screenshot_async
python
async def screenshot_async(page=None,
full_page: bool = True,
quality: int = 80,
clip: Optional[Dict[str, float]] = None,
timeout: Optional[int] = None) -> strAsynchronously takes a screenshot of the specified page.
Arguments:
pageOptional[Page] - The Playwright Page object to take a screenshot of. If None, the agent's currently focused page will be used.full_pagebool - Whether to capture the full scrollable page.qualityint - The quality of the image (0-100), for JPEG format.clipOptional[Dict[str, float]] - An object specifying the clipping region {x, y, width, height}.timeoutOptional[int] - Custom timeout for the operation in milliseconds.
Returns:
str: A base64 encoded data URL of the screenshot, or an error message.
close_async
python
async def close_async() -> boolAsynchronously closes the remote browser agent session. This will terminate the browser process managed by the agent.
Returns:
bool: True if the session was closed successfully, False otherwise.
act
python
def act(action_input: Union[ObserveResult, ActOptions],
page=None) -> "ActResult"Perform an action on a web page, using ActOptions to configure behavior.
Arguments:
action_inputUnion[ObserveResult, ActOptions] - The action to perform, either as a pre-defined ObserveResult or custom ActOptions.pageOptional[Page] - The Playwright Page object to act on. If None, the agent's currently focused page will be used automatically.
Returns:
ActResult: The result of the action.
act_async
python
async def act_async(action_input: Union[ObserveResult, ActOptions],
page=None) -> "ActResult"Asynchronously perform an action on a web page.
Arguments:
action_inputUnion[ObserveResult, ActOptions] - The action to perform.pageOptional[Page] - The Playwright Page object to act on. If None, the agent's currently focused page will be used automatically.
Returns:
ActResult: The result of the action.
observe
python
def observe(options: ObserveOptions,
page=None) -> Tuple[bool, List[ObserveResult]]Observe elements or state on a web page.
Arguments:
optionsObserveOptions - Options to configure the observation behavior.pageOptional[Page] - The Playwright Page object to observe. If None, the agent's currently focused page will be used.
Returns:
Tuple[bool, List[ObserveResult]]: A tuple containing a success boolean and a list of observation results.
observe_async
python
async def observe_async(options: ObserveOptions,
page=None) -> Tuple[bool, List[ObserveResult]]Asynchronously observe elements or state on a web page.
Arguments:
optionsObserveOptions - Options to configure the observation behavior.pageOptional[Page] - The Playwright Page object to observe. If None, the agent's currently focused page will be used.
Returns:
Tuple[bool, List[ObserveResult]]: A tuple containing a success boolean and a list of observation results.
extract
python
def extract(options: ExtractOptions, page=None) -> Tuple[bool, T]Extract information from a web page.
Arguments:
optionsExtractOptions - Options to configure the extraction, including schema.pageOptional[Page] - The Playwright Page object to extract from. If None, the agent's currently focused page will be used.
Returns:
Tuple[bool, T]: A tuple containing a success boolean and the extracted data as a Pydantic model instance, or None on failure.
extract_async
python
async def extract_async(options: ExtractOptions, page=None) -> Tuple[bool, T]Asynchronously extract information from a web page.
Arguments:
optionsExtractOptions - Options to configure the extraction, including schema.pageOptional[Page] - The Playwright Page object to extract from. If None, the agent's currently focused page will be used.
Returns:
Tuple[bool, T]: A tuple containing a success boolean and the extracted data as a Pydantic model instance, or None on failure.
ScreenFingerprint
python
@dataclass
class ScreenFingerprint()Screen fingerprint data structure.
availHeight: int
python
availHeight = NoneavailWidth: int
python
availWidth = NoneavailTop: int
python
availTop = NoneavailLeft: int
python
availLeft = NonecolorDepth: int
python
colorDepth = Noneheight: int
python
height = NonepixelDepth: int
python
pixelDepth = Nonewidth: int
python
width = NonedevicePixelRatio: float
python
devicePixelRatio = NonepageXOffset: int
python
pageXOffset = NonepageYOffset: int
python
pageYOffset = NoneinnerHeight: int
python
innerHeight = NoneouterHeight: int
python
outerHeight = NoneouterWidth: int
python
outerWidth = NoneinnerWidth: int
python
innerWidth = NonescreenX: int
python
screenX = NoneclientWidth: int
python
clientWidth = NoneclientHeight: int
python
clientHeight = NonehasHDR: bool
python
hasHDR = NoneBrand
python
@dataclass
class Brand()Brand information data structure.
brand: str
python
brand = Noneversion: str
python
version = NoneUserAgentData
python
@dataclass
class UserAgentData()User agent data structure.
brands: List[Brand]
python
brands = Nonemobile: bool
python
mobile = Noneplatform: str
python
platform = Nonearchitecture: str
python
architecture = Nonebitness: str
python
bitness = NonefullVersionList: List[Brand]
python
fullVersionList = Nonemodel: str
python
model = NoneplatformVersion: str
python
platformVersion = NoneuaFullVersion: str
python
uaFullVersion = NoneExtraProperties
python
@dataclass
class ExtraProperties()Navigator extra properties data structure.
vendorFlavors: List[str]
python
vendorFlavors = NoneisBluetoothSupported: bool
python
isBluetoothSupported = NoneglobalPrivacyControl: Optional[Any]
python
globalPrivacyControl = NonepdfViewerEnabled: bool
python
pdfViewerEnabled = NoneinstalledApps: List[Any]
python
installedApps = NoneNavigatorFingerprint
python
@dataclass
class NavigatorFingerprint()Navigator fingerprint data structure.
userAgent: str
python
userAgent = NoneuserAgentData: UserAgentData
python
userAgentData = NonedoNotTrack: str
python
doNotTrack = NoneappCodeName: str
python
appCodeName = NoneappName: str
python
appName = NoneappVersion: str
python
appVersion = Noneoscpu: str
python
oscpu = Nonewebdriver: str
python
webdriver = Nonelanguage: str
python
language = Nonelanguages: List[str]
python
languages = Noneplatform: str
python
platform = NonedeviceMemory: Optional[int]
python
deviceMemory = NonehardwareConcurrency: int
python
hardwareConcurrency = Noneproduct: str
python
product = NoneproductSub: str
python
productSub = Nonevendor: str
python
vendor = NonevendorSub: str
python
vendorSub = NonemaxTouchPoints: Optional[int]
python
maxTouchPoints = NoneextraProperties: ExtraProperties
python
extraProperties = NoneVideoCard
python
@dataclass
class VideoCard()Video card information data structure.
renderer: str
python
renderer = Nonevendor: str
python
vendor = NoneFingerprint
python
@dataclass
class Fingerprint()Main fingerprint data structure.
screen: ScreenFingerprint
python
screen = Nonenavigator: NavigatorFingerprint
python
navigator = NonevideoCodecs: Dict[str, str]
python
videoCodecs = NoneaudioCodecs: Dict[str, str]
python
audioCodecs = NonepluginsData: Dict[str, str]
python
pluginsData = Nonebattery: Optional[Dict[str, str]]
python
battery = NonevideoCard: VideoCard
python
videoCard = NonemultimediaDevices: List[str]
python
multimediaDevices = Nonefonts: List[str]
python
fonts = NonemockWebRTC: bool
python
mockWebRTC = Noneslim: Optional[bool]
python
slim = NoneFingerprintFormat
python
@dataclass
class FingerprintFormat()Complete fingerprint format including fingerprint data and headers.
fingerprint: Fingerprint
python
fingerprint = Noneheaders: Dict[str, str]
python
headers = Noneload
python
@classmethod
def load(cls, data: Union[dict, str]) -> 'FingerprintFormat'Load fingerprint from dictionary or JSON string.
This is the recommended public API for loading fingerprint data.
Arguments:
data: Either a dictionary or JSON string containing fingerprint data
Returns:
FingerprintFormat: Loaded fingerprint format object
Raises:
ValueError: If data is invalid or cannot be parsed
Example:
python
# From dictionary
fingerprint = FingerprintFormat.load({"fingerprint": {...}, "headers": {...}})
# From JSON string
fingerprint = FingerprintFormat.load('{"fingerprint": {...}, "headers": {...}}')create
python
@classmethod
def create(cls,
screen: ScreenFingerprint,
navigator: NavigatorFingerprint,
video_card: VideoCard,
headers: Dict[str, str],
video_codecs: Optional[Dict[str, str]] = None,
audio_codecs: Optional[Dict[str, str]] = None,
plugins_data: Optional[Dict[str, str]] = None,
battery: Optional[Dict[str, str]] = None,
multimedia_devices: Optional[List[str]] = None,
fonts: Optional[List[str]] = None,
mock_webrtc: bool = False,
slim: Optional[bool] = None) -> 'FingerprintFormat'Create FingerprintFormat directly using component classes.
Arguments:
screen: ScreenFingerprint object
navigator: NavigatorFingerprint object
video_card: VideoCard object
headers: Headers dictionary
video_codecs: Video codecs dictionary (optional)
audio_codecs: Audio codecs dictionary (optional)
plugins_data: Plugins data dictionary (optional)
battery: Battery information dictionary (optional)
multimedia_devices: List of multimedia devices (optional)
fonts: List of available fonts (optional)
mock_webrtc: Whether WebRTC is mocked (default: False)
slim: Slim mode flag (optional)
Returns:
FingerprintFormat: Complete fingerprint format object
BrowserFingerprintGenerator
python
class BrowserFingerprintGenerator()Browser fingerprint generator class for extracting comprehensive browser fingerprint data. This class uses Playwright to launch a local browser and collect fingerprint information including screen properties, navigator data, codecs, plugins, WebGL info, and HTTP headers.
generate_fingerprint
python
async def generate_fingerprint() -> Optional[FingerprintFormat]Extract comprehensive browser fingerprint using Playwright.
Returns:
Optional[FingerprintFormat]: FingerprintFormat object containing fingerprint and headers, or None if generation failed
generate_fingerprint_to_file
python
async def generate_fingerprint_to_file(
output_filename: str = "fingerprint_output.json") -> boolExtract comprehensive browser fingerprint and save to file.
Arguments:
output_filename: Name of the file to save fingerprint data
Returns:
bool: True if fingerprint generation and saving succeeded, False otherwise
Best Practices
- Initialize browser with appropriate options before use
- Wait for page load completion before interacting with elements
- Use appropriate selectors (CSS, XPath) for reliable element identification
- Handle navigation timeouts and errors gracefully
- Take screenshots for debugging and verification
- Clean up browser resources after automation tasks
- Configure proxy settings properly for network requirements
Related Resources
Documentation generated automatically from source code using pydoc-markdown.