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.
export declare function downloadFile(input: {
  page: Page;
  trigger: Trigger;
  timeoutInMs?: number;
}): Promise<Download>;

Examples

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",
  });
  file_name = download.suggestedFilename();
  return file_name;
}

Arguments

input
Object
required
Configuration object for the download operation

Returns: Promise<Download>

Promise that resolves to a Playwright Download object