> ## 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.

# downloadFile

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.

```typescript theme={null}
export declare function downloadFile(input: {
  page: Page;
  trigger: Trigger;
  timeoutInMs?: number;
}): Promise<Download>;
```

## Examples

```typescript Download from direct URL theme={null}
import { downloadFile } from "@intuned/browser";
import { BrowserContext, Page } from "playwright";

interface Params {}

export default async function handler(
  params: Params,
  page: Page,
  context: BrowserContext
) {
  // Download from a direct URL, this will open the url and automatically download the content in it.
  const download = await downloadFile({
    page,
    trigger:
      "https://intuned-docs-public-images.s3.amazonaws.com/32UP83A_ENG_US.pdf",
  });
  const file_name = download.suggestedFilename();
  return file_name;
}
```

```typescript Locator Trigger theme={null}
import { downloadFile } from "@intuned/browser";
import { BrowserContext, Page } from "playwright";

interface Params {}

export default async function handler(
  params: Params,
  page: Page,
  context: BrowserContext
) {
  await page.goto("https://sandbox.intuned.dev/pdfs");
  const download = await downloadFile({
    page,
    trigger: page.locator("xpath=//tbody/tr[1]//*[name()='svg']"),
  });
  const file_name = download.suggestedFilename();
  return file_name;
}
```

```typescript Callback Trigger theme={null}
import { downloadFile } from "@intuned/browser";
import { BrowserContext, Page } from "playwright";

interface Params {}

export default async function handler(
  params: Params,
  page: Page,
  context: BrowserContext
) {
  await page.goto("https://sandbox.intuned.dev/pdfs");
  const download = await downloadFile({
    page,
    trigger: async (page) => {
      await page.locator("xpath=//tbody/tr[1]//*[name()='svg']").click();
    },
  });
  const file_name = download.suggestedFilename();
  return file_name;
}
```

## Arguments

**input** `Object` *required*

Configuration object for the download operation

**properties**

**input.page** `Page` *required*

The Playwright Page object to use for the download

**input.trigger** `Trigger` *required*

The [Trigger](https://intunedhq.com/docs/automation-sdks/intuned-sdk/typescript/helpers/type-references/Trigger.md) method to initiate the download

**input.timeoutInMs** `number`

Maximum time in milliseconds to wait for the download to trigger. Defaults to
5000\.

## Returns: `Promise<Download>`

Promise that resolves to a [Playwright Download object](https://playwright.dev/docs/api/class-download)


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