Home Reference Source

chrome-remote-interface-extra

NPM chrome-remote-interface-extra package node requirement never semis sanic

The chrome-remote-interface-extra brings a GoogleChrome/puppeteer like api to the chrome-remote-interface-extra by cyrus-and :heart:, as well as, making many of the full CDP values puppeteer hides available.

Getting Started

Installation

To use chrome-remote-interface-extra in your project, run:

yarn add chrome-remote-interface-extra
# or "npm i chrome-remote-interface-extra"

Note: The chrome-remote-interface-extra differs from puppeteer in that you must BYOB (bring your own browser).

Documentation

Usage

Note: chrome-remote-interface-extra requires at least Node v8.6.0 (according to node.green) and is tested on the latest version of Node

Example - navigating to fairly complicated single page application (SPA) and saving a screenshot as wr.png:

const { CRIExtra, Browser } = require('chrome-remote-interface-extra')

const fairlyComplicatedPage =
  'https://webrecorder.io/jberlin/archival-acid-test-v2/list/bookmarks/b1/20170810014348/http://wsdl-docker.cs.odu.edu:8080/tests/reactSPA/'

async function webercorderIOScreenshot () {
  let client
  let browser
  try {
    client = await CRIExtra({ host: 'localhost', port: 9222 })
    browser = await Browser.create(client, {
      contextIds: [],
      ignoreHTTPSErrors: true
    })
    const page = await browser.newPage()
    await page.goto(fairlyComplicatedPage, { waitUntil: 'domcontentloaded' })
    await page.networkIdlePromise()
    await page.screenshot({ path: 'wr.png' })
    await browser.close()
  } catch (err) {
    console.error(err)
  } finally {
    if (browser) {
      await browser.close()
    } else if (client) {
      await client.close()
    }
  }
}

webercorderIOScreenshot().catch(error => {
  console.error('Screenshot failed', error)
})

Additional examples can be derived from looking over this project's test suite

FAQ

Q: Why

Simply put, puppeteer's abstractions around the Chrome DevTools Protocol (CDP) are fantastic except for one thing its Googley (not easily extendable beyond their own vision for the project).

The chrome-remote-interface by cyrus-and is a building block not an opinion, so why not build on top of it like jprichardson did for fs-extra.

Q: Who maintains chrome-remote-interface-extra?

N0tan3rd and the community! Lets build something together!

Q: What are chrome-remote-interface-extra’s goals and principles?

The goals of the project is to add extra utility to the chrome-remote-interface by

Q: Is chrome-remote-interface-extra replacing Selenium/WebDriver?

It should. Both Selenium/WebDriver can not provide you with access to the heart beat of the browser which is required for modern day web pages and use cases.

Q: Whats different from puppeteer / the extra utility you speak off

An non-exhaustive overview of the differences/additions is provided below. A full listing can be found by consulting our documentation

Added util.inspect.custom definitions to majority of classes so they play nicely with console.log and util.inspect

Added toJSON to CDP Type classes so that their values can easily be serialized to disk for latter computation

Animation Domain: Tweak and inspect your animations

Database Domain: You should see whats in your browsers database

Inspection and retrieval of per frame resources

ServiceWorkers!

Page

Page, Frame, DOMWorld

Page, NetworkManager

Frame

FrameManager, Page

Request, Response

Browser

Browser, BrowserContext, Target

Target