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

puppeteer-navigator

v3.1.2

Published

Library to enhance use of Puppeteer

Downloads

24

Readme

Puppeteer Navigator

A library to assist some common use cases of Puppeteer.

Features

  • Automate as much as possible waiting on elements and actions
    • Automatically wait for all selectors before performing action
    • Set timed wait defaults that will be applied between all actions
    • Attempt to automatically wait for all network activity to complete
  • Use simulated clicks for improved reliability in some use cases
    • Simulated clicks will work for elements that are in motion or covered up
  • Some simplified API's for convenience

API

/**
 * Options generally applied to all actions
 */
export interface NavigatorOptions {
    /** wait until element is visible on selection actions.  default true. */
    waitUntilVisible?: boolean;
    /** wait until the selector is found before performing actions. default true*/
    waitOnSelectors?: boolean;
    /** wait milliseconds after all actions. default 0 */
    waitAfterAction?: number;
    /** wait milliseconds after all network activity has stopped. default 0 */
    waitIdleTime?: number;
    /** wait milliseconds after any page load. default 0 */
    waitIdleLoadTime?: number;
    /** send click event directly to element vs using mouse cursor initiated click. default true */
    useSimulatedClicks?: boolean;
}
export interface ElementAny extends Element {
    [key: string]: any;
}

export interface Navigator {
    page(): Page
    updateOptions(customOptions:NavigatorOptions) : void
    /**
     * Navigate to URL
     * @param url 
     * @param waitCondition 
     */
    goto(url:string, waitCondition?:SelectorType) : Promise<Response>
    
    /**
     * Queries an element using css selector or xpath
     * Assumes xpath expression starts with '//'
     * @param selector css selector or xpath
     */
    queryElementHandle(selector: string | ElementHandle) : Promise<ElementHandle | null>

    /**
     * Uses the selector function to find a matching element
     * If a context is passed, then the matching element must be a descendant of the context element
     */
    queryElementHandleWithFn(selectorFn: ElementMatchFn, context: ElementHandle) : Promise<Node | null>

    /**
     * Query element using selector and uses the provided function to map a return value
     * @param selector css selector
     * @param valueMapFn function to map element to return value
     */
    queryElement(selector:string, valueMapFn:ElementMapFn) : Promise<any[]> 

    /**
     * Queries elements using selector and uses the provided function to map a list of return values
     * @param selector css selector
     * @param valueMapFn function to map elements to values to be returned
     */
    queryElements(selector:string, valueMapFn:ElementMapFn): Promise<any[]> 
    
    /**
     * Queries chlldren with all descendants for a match using the descendantFn.
     * Retuns all children who matched or had a descendant match.
     * 
     * This API is used to assist identifying rows in tables, lists, grids etc where we 
     * want to find a row containing some criteria we can test for with a function
     * 
     * @param selector css selector
     * @param valueMapFn function to map elements to values to be returned
     */
    queryChildrenAsHandles(parentSelector:string, descendantFn: (element:Element) => boolean ) : Promise<ElementHandle<Element>[]>


    /**
     * Sets the default chrome puppeteer download path
     * See - https://github.com/GoogleChrome/puppeteer/issues/299
     * @param {*} downloadPath 
     */
    setDownloadPath(downloadPath:string) : Promise<void>
    scrollElementToBottom(elementSelector:string, delay:number) : Promise<void>

    /**
     * Waits for element to be visible, function to be true or timeout if number
     * @param condition css selector, xpath or function
     */
    wait(condition:SelectorType) : Promise<JSHandle | void>

    /**
     * Waits for condition to be true
     * @param selector css selector, xpath or function
     * @param condition function that receives element of selector as input.
     * @param options 'waitAfter' additinoal wait time after condition is true
     */
    waitFn(selector:string, condition: (element:ElementAny) => boolean, options?: PageFnOptions & {waitAfter?:number}) : Promise<void>

    /**
     * Wait for any network activity to complete
     */
    waitActivity(idleTime:number|undefined, idleLoadTime:number|undefined) : Promise<unknown>

    /**
     * Performs a click on a HTML field.
     * @param selector css selector or xpath
     * @param clickOptions ClickOptions
     */
    click(selector:string | ElementHandle, clickOptions?:ClickOptions) : Promise<void>

    /**
     * Types text into a HTML field
     * @param selector css selector
     * @param text type text into field
     * @param typeOptions 'delay' sets delay between each key typed
     */
    type(selector:string, text:string, typeOptions?: { delay: number }) : Promise<void>

    /**
     * Selects an option within a HTML list.
     * Filters out any control characters that might be in the list label or value before attempting to match.
     * 
     * @param selector css selector
     * @param selectOption 'value' matches the option value attribute. 'label' matches the option label attribute
     */
    select(selector:string, selectOption: {value?:string, label?:string}) : Promise<void>


    /**
     * Find a frame and return a new navigator for the frame
     * @param selector frame selector
     */
    frameNavigator(selector:string) : Promise<Navigator>
 
}