Skip to content

StepArtifacts

conatus.utils.browser.artifacts

Step artifacts for the browser.

To simplify: this module is here to save artifacts (HTML, screenshots, etc.) that could be potentially be saved during the browsing process.

In detail: this class is used in conjunction to the Step class. Each time a step is executed, the artifacts are saved in the StepArtifacts object.

As a reminder: Browser hierarchy

XXXXX SAVING STUFF

XXXXX WHAT ABOUT THE DOM?

StepArtifacts dataclass

StepArtifacts(
    step_n: int,
    screenshot: Image,
    screenshot_b64: str,
    last_html: str,
    new_download: Download | None,
    config: BrowserConfig,
)

Artifacts related to a page.

ATTRIBUTE DESCRIPTION
step_n

The step number.

TYPE: int

dom

The DOM of the page.

TYPE: int

screenshot

Screenshot of the page (Pillow).

TYPE: Image

screenshot_b64

Base64 encoded screenshot of the page.

TYPE: str

last_html

The last HTML of the page.

TYPE: str

new_download

A new download, if any.

TYPE: Download | None

config

The browser configuration.

TYPE: BrowserConfig

save

save() -> None

Save the artifacts.

Source code in conatus/utils/browser/artifacts.py
def save(self) -> None:
    """Save the artifacts."""
    if self.config.step.save_html:
        self.config.writer.write(
            self.last_html, f"page_{self.step_n}.html", OutputType.LOG
        )
    if self.config.step.save_screenshot:
        buffer = io.BytesIO()
        self.screenshot.save(buffer, format="PNG")
        _ = buffer.seek(0)
        self.config.writer.write(
            buffer, f"screenshot_{self.step_n}.png", OutputType.LOG
        )
    if self.config.step.save_screenshot_b64:
        self.config.writer.write(
            self.screenshot_b64,
            f"screenshot_{self.step_n}_b64.txt",
            OutputType.LOG,
        )