0.1.11 • Published 6 years ago

chrome-ditto v0.1.11

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Chrome Ditto

Common API for Nightmare, Puppeteer

Install

yarn add chrome-ditto

# or npm
npm i chrome-ditto

Usage

const Ditto = require('chrome-ditto')
const Nightmre = require('nightmare')
// const puppeteer = require('puppeteer')

(async () => {
    const browser = await Ditto(Nightmare)
    // const browser = Ditto(puppeteer)
    const page = await browser.newPage()
    await page.goto('http://www.example.com/')
    await page.wait('h1')
    let content = await page.evaluate(() => {
        return document.querySelector('p').textContent.trim()
    })
    console.log('content:', content)
    await page.screenshot('./example.png')
    await browser.close()
})()

API

Ditto

  • Ditto(model, options: DittoOptions): Browser

    model: Nightmare | Puppeteer, that you want to transform

  • DittoOptions

    • show: boolean

      show browser or not

    • showImages: boolean

    • ignoreHTTPSErrors: boolean
    • waitTimeout: number
    • sessionId: string

      persist states between pages

Browser

Init

  • init(options: DittoOptions): Promise

Properties

  • model
  • name: string

    name of Browser, 'nightmare', 'puppeteer' etc.

Page

Properties

  • ins

    instance of model

  • options: DittoOptions

Setters of Page

  • setUserAgent(ua: string): Promise
  • setViewport(width: number, height: number): Promise

Actions

  • click(selector: string): Promise
  • close(): Promise
  • goto(url: string): Promise
  • type(selector: string, text: string): Promise

Extract

  • evaluate(func: Function, arg1, arg2...): Promise
  • html(): Promise<string>
  • screenshot(relativePath: string): Promise

Waiting

  • wait(time: number): Promise
  • wait(selector: string, timeout: number): Promise
  • wait(func: Function, timeout: number, arg1, arg2...): Promise

    • func(arg1, arg2...): boolean
  • waitOne(waitings: Array<string|Function>, timeout: number): Promise<number>

    const isFooPage = () => !!window.location.href.match(/foo/)
    const flags = ['#succeessBox', '#failedBox', isfooPage]
    let indexOfFlag = await page.waitOne(flags)
    switch(indexOfFlag) {
      case 0:
        console.log('succeess')
        break
      case 1:
        console.log('failed')
        break
      case 2:
        throw 'foo?'
        break
    }
0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago