> ## Documentation Index
> Fetch the complete documentation index at: https://docs.camel-ai.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Camel.toolkits.browser toolkit commons

<a id="camel.toolkits.browser_toolkit_commons" />

<a id="camel.toolkits.browser_toolkit_commons._get_str" />

## \_get\_str

```python theme={"system"}
def _get_str(d: Any, k: str):
```

Safely retrieve a string value from a dictionary.

<a id="camel.toolkits.browser_toolkit_commons._get_number" />

## \_get\_number

```python theme={"system"}
def _get_number(d: Any, k: str):
```

Safely retrieve a number (int or float) from a dictionary

<a id="camel.toolkits.browser_toolkit_commons._get_bool" />

## \_get\_bool

```python theme={"system"}
def _get_bool(d: Any, k: str):
```

Safely retrieve a boolean value from a dictionary.

<a id="camel.toolkits.browser_toolkit_commons._parse_json_output" />

## \_parse\_json\_output

```python theme={"system"}
def _parse_json_output(text: str, logger: Any):
```

Extract JSON output from a string.

<a id="camel.toolkits.browser_toolkit_commons._reload_image" />

## \_reload\_image

```python theme={"system"}
def _reload_image(image: Image.Image):
```

<a id="camel.toolkits.browser_toolkit_commons.dom_rectangle_from_dict" />

## dom\_rectangle\_from\_dict

```python theme={"system"}
def dom_rectangle_from_dict(rect: Dict[str, Any]):
```

Create a DOMRectangle object from a dictionary.

<a id="camel.toolkits.browser_toolkit_commons.interactive_region_from_dict" />

## interactive\_region\_from\_dict

```python theme={"system"}
def interactive_region_from_dict(region: Dict[str, Any]):
```

Create an :class:`InteractiveRegion` object from a dictionary.

<a id="camel.toolkits.browser_toolkit_commons.visual_viewport_from_dict" />

## visual\_viewport\_from\_dict

```python theme={"system"}
def visual_viewport_from_dict(viewport: Dict[str, Any]):
```

Create a :class:`VisualViewport` object from a dictionary.

<a id="camel.toolkits.browser_toolkit_commons.add_set_of_mark" />

## add\_set\_of\_mark

```python theme={"system"}
def add_set_of_mark(
    screenshot: Union[bytes, Image.Image, io.BufferedIOBase],
    ROIs: Dict[str, InteractiveRegion]
):
```

<a id="camel.toolkits.browser_toolkit_commons._add_set_of_mark" />

## \_add\_set\_of\_mark

```python theme={"system"}
def _add_set_of_mark(screenshot: Image.Image, ROIs: Dict[str, InteractiveRegion]):
```

Add a set of marks to the screenshot.

**Parameters:**

* **screenshot** (Image.Image): The screenshot to add marks to.
* **ROIs** (Dict\[str, InteractiveRegion]): The regions to add marks to.

**Returns:**

Tuple\[Image.Image, List\[str], List\[str], List\[str]]: A tuple
containing the screenshot with marked ROIs, ROIs fully within the
images, ROIs located above the visible area, and ROIs located below
the visible area.

<a id="camel.toolkits.browser_toolkit_commons._draw_roi" />

## \_draw\_roi

```python theme={"system"}
def _draw_roi(
    draw: ImageDraw.ImageDraw,
    idx: int,
    font: Union[ImageFont.FreeTypeFont, ImageFont.ImageFont],
    rect: DOMRectangle
):
```

Draw a ROI on the image.

**Parameters:**

* **draw** (ImageDraw\.ImageDraw): The draw object.
* **idx** (int): The index of the ROI.
* **font** (ImageFont.FreeTypeFont | ImageFont.ImageFont): The font.
* **rect** (DOMRectangle): The DOM rectangle.

<a id="camel.toolkits.browser_toolkit_commons._get_text_color" />

## \_get\_text\_color

```python theme={"system"}
def _get_text_color(bg_color: Tuple[int, int, int, int]):
```

Determine the ideal text color (black or white) for contrast.

**Parameters:**

* **bg\_color**: The background color (R, G, B, A).

**Returns:**

A tuple representing black or white color for text.

<a id="camel.toolkits.browser_toolkit_commons._get_random_color" />

## \_get\_random\_color

```python theme={"system"}
def _get_random_color(identifier: int):
```

Generate a consistent random RGBA color based on the identifier.

**Parameters:**

* **identifier**: The ID used as a seed to ensure color consistency.

**Returns:**

A tuple representing (R, G, B, A) values.
