Skip to main content
Downloads a file from a web page using various trigger methods. This function provides three flexible ways to initiate file downloads:
  • URL: Creates a new page, navigates to the URL, waits for download, then automatically closes the page. Ideal for direct download links.
  • Locator: Uses the current page to click the element and capture the resulting download. Perfect for download buttons or interactive elements.
  • Callback: Executes the provided function with the page object and captures the first triggered download. Offers maximum flexibility for complex download scenarios.
async def download_file(
    page: Page,
    trigger: Trigger,
    *,
    timeout_s: int,
) -> Download

Examples

from typing import TypedDict
from playwright.async_api import Page
from intuned_browser import download_file
class Params(TypedDict):
    pass
async def automation(page: Page, params: Params, **_kwargs):
    # Download from a direct URL, this will open the url and automatically download the content in it.
    download = await download_file(
        page,
        trigger="https://intuned-docs-public-images.s3.amazonaws.com/32UP83A_ENG_US.pdf"
    )
    file_name = download.suggested_filename
    return file_name

Arguments

page
Page
required
The Playwright Page object to use for the download.
trigger
Trigger
required
The Trigger method to initiate the download.
timeout_s
int
Maximum time in seconds to wait for download to start. Defaults to 5.

Returns: Download

The Playwright Download object representing the downloaded file.