Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ssbeefeater/x-ray-chrome
x-ray chrome driver using puppeteer
https://github.com/ssbeefeater/x-ray-chrome
Last synced: 16 days ago
JSON representation
x-ray chrome driver using puppeteer
- Host: GitHub
- URL: https://github.com/ssbeefeater/x-ray-chrome
- Owner: ssbeefeater
- Created: 2018-07-29T17:27:29.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-29T23:08:15.000Z (over 6 years ago)
- Last Synced: 2024-09-22T06:42:39.385Z (about 2 months ago)
- Language: TypeScript
- Size: 47.9 KB
- Stars: 12
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Installation
```bash
npm install x-ray-chrome --save
#or
yarn add x-ray-chrome
```# Usage
### Basic
```javascript
import xRay from 'x-ray';
import xRayChrome from 'x-ray-chrome';const x = Xray().driver(xRayChrome())
```### Advanced
```javascript
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
```javascript
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 }
```
* [xRayChrome](#xraychrome)
---
### `` xRayChrome
▸ **xRayChrome**(options?: *[XRayChromeOptions](#options)*): `Driver`
| Param | Type | Default value |
| ------ | ------ | ------ |
| options | [XRayChromeOptions](#options) | {} |**Returns:** `Driver`
---
## Options
`LaunchOptions`
**↳ XRayChromeOptions**
### Properties
* [appMode](#appmode)
* [args](#args)
* [cl](#cl)
* [devtools](#devtools)
* [dumpio](#dumpio)
* [env](#env)
* [executablePath](#executablepath)
* [handleSIGHUP](#handlesighup)
* [handleSIGINT](#handlesigint)
* [handleSIGTERM](#handlesigterm)
* [headless](#headless)
* [ignoreDefaultArgs](#ignoredefaultargs)
* [ignoreHTTPSErrors](#ignorehttpserrors)
* [navigationOptions](#navigationoptions)
* [pipe](#pipe)
* [slowMo](#slowmo)
* [timeout](#timeout)
* [userDataDir](#userdatadir)
* [viewPort](#viewport)---
## Properties
### `` appMode
**● appMode**: *`boolean`*
*Inherited from LaunchOptions.appMode*
Whether to open chrome in appMode. Defaults to false.
### `` args
**● args**: *`string`[]*
*Inherited from LaunchOptions.args*
Additional arguments to pass to the Chromium instance. List of Chromium flags can be found here.
### `` 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`
### `` 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.
### `` dumpio
**● dumpio**: *`boolean`*
*Inherited from LaunchOptions.dumpio*
Whether to pipe browser process stdout and stderr into process.stdout and process.stderr. Defaults to false.
### `` env
**● env**: *`any`*
*Inherited from LaunchOptions.env*
Specify environment variables that will be visible to Chromium. Defaults to process.env.
### `` 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.
### `` handleSIGHUP
**● handleSIGHUP**: *`boolean`*
*Inherited from LaunchOptions.handleSIGHUP*
Close chrome process on SIGHUP. Defaults to true.
### `` handleSIGINT
**● handleSIGINT**: *`boolean`*
*Inherited from LaunchOptions.handleSIGINT*
Close chrome process on Ctrl-C. Defaults to true.
### `` handleSIGTERM
**● handleSIGTERM**: *`boolean`*
*Inherited from LaunchOptions.handleSIGTERM*
Close chrome process on SIGTERM. Defaults to true.
### `` headless
**● headless**: *`boolean`*
*Inherited from LaunchOptions.headless*
Whether to run Chromium in headless mode. Defaults to true.
### `` ignoreDefaultArgs
**● ignoreDefaultArgs**: *`boolean`*
*Inherited from LaunchOptions.ignoreDefaultArgs*
Do not use `puppeteer.defaultArgs()` for launching Chromium. Defaults to false.
### `` ignoreHTTPSErrors
**● ignoreHTTPSErrors**: *`boolean`*
*Inherited from LaunchOptions.ignoreHTTPSErrors*
Whether to ignore HTTPS errors during navigation. Defaults to false.
### `` navigationOptions
**● navigationOptions**: *`NavigationOptions`*
The options to set to page.goTo method.
### `` pipe
**● pipe**: *`boolean`*
*Inherited from LaunchOptions.pipe*
Connects to the browser over a pipe instead of a WebSocket. Defaults to false.
### `` 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.
### `` 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.
### `` userDataDir
**● userDataDir**: *`string`*
*Inherited from LaunchOptions.userDataDir*
Path to a User Data Directory.
### `` viewPort
**● viewPort**: *`object`*
The view port of the page
#### Type declaration
height: `number`
*__default__*: 800
width: `number`
*__default__*: 1280
___