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

async-chainable-nightmare

v1.3.1

Published

Plugin for async-chainable that wraps Nightmare

Downloads

14

Readme

async-chainable-nightmare

Plugin for async-chainable that wraps Nightmare

This plugin patches many of the somewhat odd behaviours of the Nightmare module including:

  • All async calls that need to be wrapped in Promises (e.g. resolve, type etc.) are done so automatically
  • Some inconsiquential error messages that would otherwise abort the sequence chain are ignoerd (e.g. typing into an input box that doesn't raise the blur event)
var asyncChainable = require('async-chainable');
var asyncChainableNightmare = require('async-chainable-nightmare');

asyncChainable()
	.use(asyncChainableNightmare)
	.nightmare({show: true})

	.nightmareOn('console', function() {
		var args = Array.prototype.slice.call(arguments, 0);
		console.log('Page Console>', args);
	})

	.nightmareGoto('http://google.com')
	.then(function(cb) { console.log('Navigated'); cb() })

	.then(function(cb) { console.log('Typing into `input[name="q"]`'); cb() })
	.nightmareType('input[name="q"]', 'github async-chainable-nightmare')
	.then(function(cb) { console.log('Typed'); cb() })

	.then(function(cb) { console.log('Clicking `input[name="btnK"]'); cb() })
	.nightmareClick('input[name="btnK"]')
	.then(function(cb) { console.log('Clicked'); cb() })

	.then(function(cb) { console.log('Waiting for `.content`'); cb() })
	.nightmareWait('.content')
	.then(function(cb) { console.log('Main content area found'); cb() })

	.then(function(cb) { console.log('Evaluating `#resultStats`'); cb() })
	.nightmareEvaluate('result', function () {
		return document.querySelector('#resultStats').innerHTML;
	})
	.then(function(cb) { console.log('Evaluated'); cb() })

	.then(function(cb) { console.log('All done'); cb() })
	.end();

API

The async-chainable-nightmare API follows the specification of the main Nightmare. The Nightmare instance must be first initialized by a call to nightmare([options]) followed by subsequent calls to any nightmare prefixed function.

async-chainable-nightmare provides the following functions:

| Function | Description | |--------------------------------------|---------------------------------------------------------------------------------------------------------------------------------| | nightmare([options]) | Initialize a Nightmare instance and store it as nightmare in the async-chainable context | | nightmareClick(selector) | Simulate a mouse click event on a given selector | | nightmareEvaluate([key], function) | Execute the given function within the context of the page and, optionally, store the result in the named key within the context | | nightmareGoto(url) | Navigate the Nightmare instance to the given URL | | nightmareOn(event, function) | Bind to a Nightmare event | | nightmarePdf(path, [options]) | Take a PDF screenshot and save it to the given file. PDF options are specified here. | | nightmarePDF(path, [options]) | Alias of nightmarePdf. | | nightmareScreenshot([path]) | Take a screenshot. if path is provided that file will be written (must end in .png), if no path is provided a buffer is returned into the screenshot key within the context | | nightmareType(selector, text) | Enter the given text into the input box specified by the selector | | nightmareWait(selector | timeout) | Wait for a given selector to appear or a given number of milliseconds |

Debugging

This module uses debug for internal debugging so setting the DEBUG=async-chainable-nightmare environment variable will show additional messages:

DEBUG=async-chainable-nightmare node myScript.js

Timeouts

You can set the default Nightmare timeouts by passing waitTimeout (default: 30s), gotoTimeout (default: 30s), loadTimeout (default: infinite) into the initial nightmare(options) call.

Should any subsequent event timeout the NIGHTMARE-TIMEOUT error response will be passed to end().

For example in the following code the module is asked to load a page and wait for an element which will never load. Since the timeout is set for 1 second Nightmare will give up after that time and immediately throw an error, skipping to the end() call.

	asyncChainable()
		.use(require('async-chainable-nightmare'))
		.nightmare({waitTimeout: 1000}) // Give up waiting after 1 second
		.nightmareGoto('http://somewhere.com')
		.nightmareWait('#someImpossibleElement')
		... Do other things ...
		.end(function(err) {
			// Err will be 'NIGHTMARE-TIMEOUT' here
		});