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

@touch4it/puppeteer

v2.0.0

Published

Wrapper around Puppeteer library to make it easier to use.

Downloads

21

Readme

Puppeteer wrapper

npm peer dependency version (scoped) MIT license npm version node version vulnerabilities

Wrapper around Puppeteer library to make it easier to use.

Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. Puppeteer runs headless by default, but can be configured to run full (non-headless) Chrome or Chromium.

Installing

Install puppeteer wrapper from npm

npm i puppeteer @touch4it/puppeteer

or

npm i puppeteer-core @touch4it/puppeteer

In order to use it you will need to require it first

const puppeteerT4IT = require('@touch4it/puppeteer');

Documentation

Get Puppeteer instance

Returns Puppeteer library.

const puppeteer = puppeteerT4IT.getPuppeteer();

Change default TIMEOUT and SCREENSHOT_DIRECTORY vars

If you want to use different timeout and screenshot directory, you can use init function to change these variables. You can pass following arguments into this function:

  • timeout Default request timeout which will be use in the module (defaults to 30000 ms)
  • screenshotDirectory Name of the directory where screenshots will be stored (defaults to screenshots/)
puppeteerT4IT.init(5000, 'some_other_dir/');

Launch new browser instance

You can pass option object as argument, which can contain all available option for launch() function

Returns new Browser instance.

let browser = await puppeteerT4IT.launch({ headless: false });

Get new page instance

You can pass following arguments into this function:

  • browser A Browser instance that you have created with puppeteer.launch()
  • authenticationData Object containing "username" and "password" authentication keys for basic auth when the page is launched

Returns new Page instance.

let page = await puppeteerT4IT.getPage(browser, { username: 'User', password: '123abc' });

Navigate to web page and test status code

You can pass following arguments into this function:

  • page Puppeteer page object
  • url URL to be redirected to
  • statusCode awaited HTTP response status code (defaults to 200)

Returns page

await puppeteerT4IT.goto(page, baseUrl);

Timeout execution for specified amount of milliseconds

You can pass following arguments into this function:

  • ms time in ms to wait

Returns empty Promise

await puppeteerT4IT.sleep(500);

Make screenshots from web page

You can pass following arguments into this function:

  • page Puppeteer page object
  • width Screen width
  • height Screen height
  • pageName Web page name under which a screenshot will be stored
  • deviceScaleFactor Specify device scale factor (Defaults to 1)
  • isMobile isMobile Whether the meta viewport tag is taken into account (defaults to false)
  • delay Time in ms to wait after reload (defaults to 0)
  • beforeAction Function to be called before screenshot is made (defaults to null)
  • beforeActionParameters beforeAction parameters (defaults to [])

Returns empty Promise

await puppeteerT4IT.screenshotPage(page, 360, 640, 'frontpage', 1, true, delay, clickOnButton, ['.navigation-element--class']);

Make screenshots in most popular screen resolutions

You can pass following arguments into this function:

  • page Puppeteer page object
  • name Web page name under which screenshots will be stored
  • delay Time in ms to wait after reload (defaults to 0)
  • beforeAction Function to be called before screenshot is made (defaults to null)
  • beforeActionParameters beforeAction parameters (defaults to [])

Returns empty Promise

await puppeteerT4IT.screenshotMultipleResolutions(page, 'projects', 4000);

Click on element

You can pass following arguments into this function:

  • page Puppeteer page object
  • querySelector Page element selector
  • delay Time in ms to wait after reload (defaults to 0)

Returns empty Promise

await puppeteerT4IT.click(page, '.class', 500);

Tap on element

You can pass following arguments into this function:

  • page Puppeteer page object
  • querySelector Page element selector
  • delay Time in ms to wait after reload (defaults to 0)

Returns empty Promise

await puppeteerT4IT.tapOnElement(page, '.class', 500);

Get href link from element

You can pass following arguments into this function:

  • page Puppeteer page object
  • querySelector Page element selector

Returns link href from element

await puppeteerT4IT.getLinkByQuerySelector(page, '.class');

Get href link hostname from element

You can pass following arguments into this function:

  • page Puppeteer page object
  • querySelector Page element selector

It returns link hostname from element.

await puppeteerT4IT.getHostnameByQuerySelector(page, '.class');

Get value from element

You can pass following arguments into this function:

  • page Puppeteer page object
  • querySelector Page element selector

Returns value of element

await puppeteerT4IT.getValueByQuerySelector(page, '.class');

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

Project updates are tracked in a CHANGELOG file