Vercel2026-06-18

[Cloud Infrastructure] Utilizing Vercel Sandbox to Stably Scale Puppeteer in Serverless Environments


The Poor Compatibility Between Serverless Environments and "Browser Automation"

In B2B business automation (RPA), "Headless Browser Automation"—such as downloading CSV data from external SaaS dashboards or registering information by logging into specific commercial portals—is unavoidable.

When building these, TypeScript developers typically use Puppeteer or Playwright. However, attempting to run these in serverless (FaaS) environments like Vercel exposes severe constraints:

  1. Timeout Limits: Standard API routes (Serverless Functions) have maximum execution limits (e.g., 10 seconds for Hobby, 15 seconds to a maximum of 30 minutes for Pro), forcing heavy crawling processes that take minutes to terminate abruptly.
  2. Binary Size and Memory Exhaustion: Just launching Chromium (the browser itself) occupies hundreds of MB of memory, heavily straining the function's memory limit (usually 1024MB–3008MB) and triggering runtime errors (Out of Memory).
  3. Cold Starts: Because the browser instance loads from scratch every time, the delay upon first access is significant, making it unviable for real-time processing.

To solve these issues, the architecture of running the browser on Vercel Sandbox, an isolated and persistent execution environment provided by Vercel, is extremely effective.


2. Before & After: Resolving the Challenges

Item Standard Serverless Functions (Before) Vercel Sandbox (After)
Execution Time Timeouts occur within 10 seconds to a few minutes Long-running batch processes without timeouts can operate
Browser Memory Cannot open multiple tabs simultaneously due to memory limits Stably operates on allocated independent resources
Startup Overhead Booting is delayed every time due to cold starts Containers maintain a warmed-up state in the background
IP Rotation Static IP limitations from cloud providers Can be bypassed with Sandbox-specific IPs or proxy assignments

3. Concrete Implementation Example: Running Puppeteer in Vercel Sandbox

Below is an example of core TypeScript code for safely executing scraping or UI manipulation utilizing Vercel Sandbox (a persistent Node.js container).

import puppeteer from "puppeteer-core";

// Intended for execution within the Vercel Sandbox environment
export async function runBrowserAutomationTask(targetUrl: string) {
  let browser = null;
  try {
    // Specify a stable Chromium binary locally or on the Sandbox
    browser = await puppeteer.launch({
      args: [
        "--no-sandbox",
        "--disable-setuid-sandbox",
        "--disable-dev-shm-usage", // Avoid memory overflow
        "--disable-gpu",
      ],
      executablePath: process.env.CHROMIUM_PATH || "/usr/bin/chromium-browser",
      headless: true,
    });

    const page = await browser.newPage();
    
    // Explicitly set viewport size and timeout values
    await page.setViewport({ width: 1280, height: 800 });
    await page.setDefaultNavigationTimeout(60000); // 60-second grace period

    console.log(`Navigating to: ${targetUrl}`);
    await page.goto(targetUrl, { waitUntil: "networkidle2" });

    // Wait for a specific element to load
    await page.waitForSelector("#dashboard-report", { timeout: 15000 });

    // Retrieve data from within the portal
    const reportData = await page.evaluate(() => {
      const title = document.querySelector("h1")?.innerText;
      const count = document.querySelector(".report-count")?.textContent;
      return { title, count };
    });

    return { success: true, data: reportData };
  } catch (error) {
    console.error("Browser automation failed:", error);
    return { success: false, error: (error as Error).message };
  } finally {
    if (browser) {
      await browser.close();
    }
  }
}

4. HadayaLab's Browser Automation Development

HadayaLab supports the transition of "portal operations" and "data retrieval" currently done manually through logging in and transcribing into fully automated processes (Touchless) requiring zero human intervention.

  • Crawling SaaS Dashboards: Automatically fetch PDF invoices and CSV data from external ordering systems and billing portals every morning.
  • Google Drive / DB Integration: Automatically pipeline retrieved data to Google Drive or Upstash Redis, and send completion reports to Email (Resend) or Email (Resend).
  • Scaling Design using Vercel Sandbox: A secure serverless container architecture that automatically scales out its infrastructure even during traffic spikes.

If your company has browser operations currently performed as routine manual work, please consult us about HadayaLab's "Browser Automation Plans."

Get Your Free Workflow Audit