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

x-ray-chrome

v1.0.1

Published

x-ray chrome driver using puppeteer

Downloads

4

Readme

Usage

Basic

import xRay from 'x-ray';
import xRayChrome from 'x-ray-chrome';

const x = Xray().driver(xRayChrome())

Advanced

import xRay from 'x-ray';
import xRayChrome from 'x-ray-chrome';

const x = Xray().driver(xRayChrome({
    viewPort:{ width:360, height:640 },
    cl: async (page, ctx)=>{
            await page.click('button.toggleView');
            await page.waitForSelector('.more-items-list');
            await page.screenshot({path: './screenshot.jpg'});
    },
    navigationOptions:{
        timeout: 30000,
    }
}))

Complex example

import xRay from 'x-ray';
import xRayChrome from 'x-ray-chrome';

const x = Xray().driver(xRayChrome({
    cl: async (page, ctx) => {
            // login in github
            await page.type('#login_field', 'github_username');
            await page.type('#password', 'github_password');
            let waitForNavigation = page.waitForNavigation();
            await page.click('[name="commit"]');
            // wait to load the page
            await waitForNavigation;
            waitForNavigation = page.waitForNavigation();
            // wait to the repo page
            await page.goto('https://github.com/ssbeefeater/x-ray-chrome');
            await waitForNavigation;
            await page.waitForSelector('form.js-social-form');
            try {
            // if not already starred will give a star to this repo :P
            // else will throw an error because cant find the button
                await page.click('form.unstarred button[type="submit"]');
            } catch (err) {
                console.log('Repo already starred');
            }
            await page.screenshot({ path: 'star.png' });
            },
            navigationOptions: {
                timeout: 30000,
            }
}));

        const result = await x('https://github.com/login', 'form.js-social-form', {
            stars: 'a.social-count.js-social-count @text',
        });

        console.log(result) // { stars: number_of_stars }

<Const> xRayChrome

xRayChrome(options?: XRayChromeOptions): Driver

| Param | Type | Default value | | ------ | ------ | ------ | | options | XRayChromeOptions | {} |

Returns: Driver


Options

LaunchOptions

↳ XRayChromeOptions

Properties


Properties

<Optional> appMode

● appMode: boolean

Inherited from LaunchOptions.appMode

Whether to open chrome in appMode. Defaults to false.


<Optional> args

● args: string[]

Inherited from LaunchOptions.args

Additional arguments to pass to the Chromium instance. List of Chromium flags can be found here.


<Optional> cl

● cl: function

A function that will be called after the page load and before the page content will be return giving the power to interact with the current page using puppeteer methods like page.click([selector]).

Type declaration

▸(page: Page, ctx: Context): void

Parameters:

| Param | Type | | ------ | ------ | | page | Page | | ctx | Context |

Returns: void


<Optional> devtools

● devtools: boolean

Inherited from LaunchOptions.devtools

Whether to auto-open DevTools panel for each tab. If this option is true, the headless option will be set false.


<Optional> dumpio

● dumpio: boolean

Inherited from LaunchOptions.dumpio

Whether to pipe browser process stdout and stderr into process.stdout and process.stderr. Defaults to false.


<Optional> env

● env: any

Inherited from LaunchOptions.env

Specify environment variables that will be visible to Chromium. Defaults to process.env.


<Optional> executablePath

● executablePath: string

Inherited from LaunchOptions.executablePath

Path to a Chromium executable to run instead of bundled Chromium. If executablePath is a relative path, then it is resolved relative to current working directory.


<Optional> handleSIGHUP

● handleSIGHUP: boolean

Inherited from LaunchOptions.handleSIGHUP

Close chrome process on SIGHUP. Defaults to true.


<Optional> handleSIGINT

● handleSIGINT: boolean

Inherited from LaunchOptions.handleSIGINT

Close chrome process on Ctrl-C. Defaults to true.


<Optional> handleSIGTERM

● handleSIGTERM: boolean

Inherited from LaunchOptions.handleSIGTERM

Close chrome process on SIGTERM. Defaults to true.


<Optional> headless

● headless: boolean

Inherited from LaunchOptions.headless

Whether to run Chromium in headless mode. Defaults to true.


<Optional> ignoreDefaultArgs

● ignoreDefaultArgs: boolean

Inherited from LaunchOptions.ignoreDefaultArgs

Do not use puppeteer.defaultArgs() for launching Chromium. Defaults to false.


<Optional> ignoreHTTPSErrors

● ignoreHTTPSErrors: boolean

Inherited from LaunchOptions.ignoreHTTPSErrors

Whether to ignore HTTPS errors during navigation. Defaults to false.


<Optional> navigationOptions

● navigationOptions: NavigationOptions

The options to set to page.goTo method.


<Optional> pipe

● pipe: boolean

Inherited from LaunchOptions.pipe

Connects to the browser over a pipe instead of a WebSocket. Defaults to false.


<Optional> slowMo

● slowMo: number

Inherited from LaunchOptions.slowMo

Slows down Puppeteer operations by the specified amount of milliseconds. Useful so that you can see what is going on.


<Optional> timeout

● timeout: number

Inherited from LaunchOptions.timeout

Maximum time in milliseconds to wait for the Chrome instance to start. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.


<Optional> userDataDir

● userDataDir: string

Inherited from LaunchOptions.userDataDir

Path to a User Data Directory.


<Optional> viewPort

● viewPort: object

The view port of the page

Type declaration

height: number

default: 800

width: number

default: 1280