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

# AD-002 Automate the source portal with Puppeteer Core

> AD-002 Automate the source portal with Puppeteer Core for ReportGeneratorTool.

**Status:** Accepted **Decision date:** 2025-08-01 **Implementation:** Confirmed in the repository at commit `27045ec`.

## Context and decision drivers

The report needs device readings and a chart from an external portal. The workflow signs in, selects a device and date range, downloads a CSV export, and captures the chart. The team wanted to run these interactions in the hosted report service.

## Options considered

| Option | Assessment at decision time |
| - | - |
| Puppeteer Core with Chromium | Supports the required portal interactions within the service. |
| Browserless API | Was considered too costly for the expected usage and would add an external service dependency. |
| Playwright | Was expected to require a larger cloud image and more hosting resources, based on experience with another company service. This was not measured for this repository. |

## Decision and rationale

Use Puppeteer Core with Chromium and portal-specific selectors. The implementation navigates the portal, downloads CSV data, and captures the chart as an image.

## Consequences

* The workflow can obtain data and imagery through the portal's existing interface.
* Portal markup, selectors, authentication, and timing changes can break report generation.
* Chromium and its system dependencies increase deployment and runtime requirements.
* Representative end-to-end checks are needed to detect portal changes.

## Implementation evidence

The [report service](https://github.com/TQKNG/automation/blob/27045ec413f88cd2227ab08e18ec76db3e8e3d34/src/functions/shared/utils/reportService.js) implements the browser interactions and chart capture. The [Dockerfile](https://github.com/TQKNG/automation/blob/27045ec413f88cd2227ab08e18ec76db3e8e3d34/Dockerfile) lists Chromium runtime dependencies, although the repository also contains a separate package deployment workflow and does not establish one authoritative deployment path.

## Revisit when

Reconsider browser automation if the portal offers a supported data interface, its UI changes frequently, or browser resource use becomes unacceptable.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.