Agent-readable docs index: /docs/llms.txt. Full docs in one file: /docs/llms-full.txt. Download /docs/docs.zip to grep all markdown files locally.

File downloads

Intercept file downloads triggered by clicking DOM elements.
When a click triggers a file download in the browser, Playwright can intercept it before the browser handles it natively. This is especially useful for files like PDFs that the browser would otherwise open in a new tab instead of downloading. downloadViaClick captures the file contents as a buffer so your workflow can process the file directly without relying on browser rendering behavior.

downloadViaClick()

Clicks a DOM element and intercepts the resulting download using Playwright's download event. The download listener is registered before the click so the event is never missed.
async function downloadViaClick( page: Page, selector: string, options?: DownloadViaClickOptions, ): Promise<DownloadResult>;

Parameters

path pagePagerequired
The Playwright Page to operate on.
path selectorstringrequired
CSS selector for the element that triggers the download when clicked.
path optionsDownloadViaClickOptions
properties
path loggerMinimalLogger
Optional logger. Logs download filename, size, and duration on completion.
path timeoutnumber
Milliseconds to wait for the download event. Defaults to 30000.

DownloadResult

bufferBuffer
The raw file contents.
filenamestring
The filename suggested by the server via the Content-Disposition header or the URL.

Example

import { downloadViaClick } from "libretto"; const { buffer, filename } = await downloadViaClick(page, "#export-btn", { logger, timeout: 60_000, }); console.log(`Downloaded ${filename} (${buffer.length} bytes)`);