npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zorilla/puppeteer-extra-plugin-user-data-dir

v1.0.1

Published

Custom user data directory for puppeteer.

Readme

@zorilla/puppeteer-extra-plugin-user-data-dir

Manage Chrome user data directories (profiles) with automatic temporary directory creation, file injection, and cleanup.

A plugin for puppeteer-extra and playwright-extra that gives you full control over Chrome's user data directory. Perfect for managing browser profiles, injecting custom preferences, pre-loading cookies, or ensuring clean browser states between test runs.

Features

  • 🚀 Automatic temporary directories - Creates and cleans up temp profiles automatically
  • 📁 File injection - Write files into the profile before browser launch (preferences, cookies, extensions)
  • 🧹 Smart cleanup - Handles file locks with retry logic when deleting directories
  • 🔌 Plugin integration - Collects files from other plugins for coordinated profile setup
  • 🎯 Flexible control - Use temporary or persistent profiles with configurable cleanup

Install

npm install @zorilla/puppeteer-extra-plugin-user-data-dir

Usage

Basic Usage (Automatic Temporary Directory)

By default, the plugin creates a temporary directory that's automatically cleaned up when the browser disconnects:

import puppeteer from '@zorilla/puppeteer-extra'
import UserDataDirPlugin from '@zorilla/puppeteer-extra-plugin-user-data-dir'

puppeteer.use(UserDataDirPlugin())

const browser = await puppeteer.launch()
// Temporary directory created automatically at /tmp/puppeteer_dev_profile-xxxxx
// Directory is deleted when browser disconnects

Inject Files into Profile

Write custom files into the Chrome profile before launch. Useful for preferences, cookies, or other profile data:

import puppeteer from '@zorilla/puppeteer-extra'
import UserDataDirPlugin from '@zorilla/puppeteer-extra-plugin-user-data-dir'

puppeteer.use(
  UserDataDirPlugin({
    files: [
      {
        target: 'Profile',
        file: 'Preferences',
        contents: JSON.stringify({
          profile: {
            default_content_setting_values: {
              notifications: 2 // Block notifications
            }
          }
        })
      },
      {
        target: 'Profile',
        file: 'First Run',
        contents: '' // Skip first run wizard
      }
    ]
  })
)

const browser = await puppeteer.launch()
// Files are written to the Default profile before launch

Use a Persistent Profile Directory

Provide your own user data directory path to maintain state across browser sessions:

import puppeteer from '@zorilla/puppeteer-extra'
import UserDataDirPlugin from '@zorilla/puppeteer-extra-plugin-user-data-dir'

puppeteer.use(
  UserDataDirPlugin({
    deleteExisting: false // Don't delete the directory on disconnect
  })
)

const browser = await puppeteer.launch({
  userDataDir: '/path/to/my/profile'
})
// Your existing profile is used and preserved after disconnect

Custom Temporary Directory Location

Control where temporary directories are created:

import puppeteer from '@zorilla/puppeteer-extra'
import UserDataDirPlugin from '@zorilla/puppeteer-extra-plugin-user-data-dir'

puppeteer.use(
  UserDataDirPlugin({
    folderPath: '/custom/temp/location',
    folderPrefix: 'my-browser-profile-',
    deleteTemporary: true // Clean up when done
  })
)

const browser = await puppeteer.launch()
// Temporary directory created at /custom/temp/location/my-browser-profile-xxxxx

Playwright Usage

Works exactly the same with Playwright:

import { chromium } from '@zorilla/playwright-extra'
import UserDataDirPlugin from '@zorilla/puppeteer-extra-plugin-user-data-dir'

chromium.use(
  UserDataDirPlugin({
    files: [
      {
        target: 'Profile',
        file: 'Preferences',
        contents: JSON.stringify({ custom: 'settings' })
      }
    ]
  })
)

const browser = await chromium.launch()

API

Options

interface PluginOptions {
  /** Delete temporary directories on disconnect (default: true) */
  deleteTemporary?: boolean

  /** Delete non-temporary directories on disconnect (default: false) */
  deleteExisting?: boolean

  /** Files to write into the profile before launch */
  files?: Array<{
    target: 'Profile'  // Must be 'Profile'
    file: string       // Path relative to profile (e.g., 'Preferences', 'nested/file.txt')
    contents: string   // File contents
  }>

  /** Parent directory for temporary directories (default: os.tmpdir()) */
  folderPath?: string

  /** Prefix for temporary directory names (default: 'puppeteer_dev_profile-') */
  folderPrefix?: string
}

File Writing

Files are written to Chrome's Default profile directory within the user data directory. The plugin:

  • Creates nested directories automatically if needed
  • Writes files from both plugin options and other plugins
  • Validates that target is 'Profile' (logs warnings for invalid targets)
  • Handles write errors gracefully without crashing

Common files you might want to inject:

  • Preferences - Chrome preferences JSON (settings, permissions, etc.)
  • First Run - Empty file to skip first-run wizard
  • Local State - Browser-level state and settings
  • Custom extension data - Files in nested directories

Directory Cleanup

The plugin handles cleanup intelligently:

  • Temporary directories (deleteTemporary: true): Created by the plugin, deleted on disconnect
  • Existing directories (deleteExisting: false): Provided via userDataDir, preserved by default
  • Retry logic: Uses fs.rm with 4 retries and 100ms delays to handle file locks from Chrome processes

Use Cases

  • Clean test environments - Each test gets a fresh profile, no state leakage
  • Pre-configured browsers - Inject settings, permissions, or auth tokens before launch
  • Profile management - Easily switch between different browser configurations
  • Extension testing - Set up extension data before the browser starts
  • CI/CD pipelines - Ensure consistent, reproducible browser states

Further Reading

License

MIT