x-ray-chrome
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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


Package Sidebar

Install

npm i x-ray-chrome

Weekly Downloads

1

Version

1.0.1

License

none

Unpacked Size

174 kB

Total Files

11

Last publish

Collaborators

  • ssbeefeater