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.
Parameters
The Playwright
Page to operate on.CSS selector for the element that triggers the download when clicked.
DownloadResult
The raw file contents.
The filename suggested by the server via the
Content-Disposition header or
the URL.