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 🙏

© 2024 – Pkg Stats / Ryan Hefner

puppet-browser-handler

v1.0.2

Published

A Node.js package that provides a convenient wrapper around Puppeteer for handling browser automation tasks. This package simplifies common browser operations like navigation, downloads management, screenshots, and page interactions.

Downloads

206

Readme

puppet-browser-handler 🎭

A Node.js package that provides a convenient wrapper around Puppeteer for handling browser automation tasks. This package simplifies common browser operations like navigation, downloads management, screenshots, and page interactions.

🚀 Installation

npm install puppet-browser-handler

⚡ Prerequisites

  • Node.js (v14 or higher recommended)
  • Google Chrome browser installed at /usr/bin/google-chrome
  • logger-standard package (will be installed as a dependency)
  • puppeteer package (will be installed as a dependency)

📚 Usage

import BrowserHandler from 'puppet-browser-handler';

// Initialize the browser handler with a download path
const browser = new BrowserHandler('./downloads');

// Example usage
async function example() {
  try {
    // Open browser (optional: provide cookies and headless configuration)
    await browser.openBrowser();
    
    // Navigate to a webpage
    await browser.goToPage('https://example.com');
    
    // Take a screenshot
    await browser.screenshot('example', 'png');
    
    // Close the browser
    await browser.closeBrowser();
  } catch (error) {
    console.error('Error:', error);
  }
}

✨ Features

🌐 Browser Management

  • Open and close browser sessions
  • Configure download behavior
  • Handle cookies
  • Manage multiple pages

🔍 Page Navigation and Interaction

  • Navigate to URLs
  • Click elements
  • Check element existence
  • Get href links from elements
  • Scroll pages
  • Take screenshots

🛠️ Utility Functions

  • Configurable sleep/delay function
  • Download path management
  • Viewport configuration

📖 API Reference

Constructor

const browser = new BrowserHandler(downloadPath);

Creates a new browser handler instance with optional download path.

Methods

🌐 Browser Control

  • openBrowser() - Launches a new browser instance
  • closeBrowser() - Closes the browser and all its pages
  • openNewPage() - Opens a new browser tab
  • closeCurrentPage() - Closes the current tab

🔍 Navigation & Interaction

  • goToPage(url) - Navigates to specified URL
  • click(selector) - Clicks an element on the page
  • elementExists(selector) - Checks if an element is present
  • getElementHrefLink(selector) - Gets href attribute from element
  • scrollDown() - Scrolls page to bottom

📸 Page Utilities

  • screenshot(fileName, fileExt) - Takes full page screenshot
  • sleep(limit, start) - Adds configurable delay between actions
  • configureDownloadsFolder() - Sets up download directory

🔒 Error Handling

The package includes built-in error handling and logging using the logger-standard package. All operations are logged with timestamps and service information.

📄 License

MIT

👥 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

🐛 Issues

If you find a bug or want to request a new feature, please open an issue.