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

# download_file

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.

```python theme={null}
async def download_file(
    page: Page,
    trigger: Trigger,
    *,
    timeout_s: int,
) -> Download
```

## Examples

<CodeGroup>
  ```python Download from direct URL theme={null}
  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
  ```

  ```python Locator Trigger theme={null}
  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):
      await page.goto("https://sandbox.intuned.dev/pdfs")
      download = await download_file(
          page,
          trigger=page.locator("xpath=//tbody/tr[1]//*[name()='svg']")
      )
      file_name = download.suggested_filename
      return file_name
  ```

  ```python Callback Trigger theme={null}
  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):
      await page.goto("https://sandbox.intuned.dev/pdfs")
      download = await download_file(
          page,
          trigger=lambda page: page.locator("xpath=//tbody/tr[1]//*[name()='svg']").click()
      )
      file_name = download.suggested_filename
      return file_name
  ```
</CodeGroup>

## Arguments

<ResponseField name="page" type="Page" required>
  The Playwright Page object to use for the download.
</ResponseField>

<ResponseField name="trigger" type="Trigger" required>
  The [Trigger](../type-references/Trigger) method to initiate the download.
</ResponseField>

<ResponseField name="timeout_s" type="int">
  Maximum time in seconds to wait for download to start. Defaults to 5.
</ResponseField>

## Returns: `Download`

The [Playwright Download object](https://playwright.dev/python/docs/api/class-download) representing the downloaded file.
