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

puppeteer-extra-plugin-repl

v2.3.3

Published

Start an interactive REPL in your puppeteer code.

Downloads

2,836

Readme

puppeteer-extra-plugin-repl

A plugin for puppeteer-extra.

Installation

yarn add puppeteer-extra-plugin-repl

Purpose

Make quick puppeteer debugging and exploration fun with an interactive REPL.

  • Can interrupt your code at anytime to start an interactive REPL in your console.
  • Adds convenience .repl() methods to Page and Browser instances.
  • Supports inspecting arbitrary objects and instances.
  • Features tab auto-completion for the available object properties and a colorized prompt.

Kudos

REPL

repl

Quickstart

const puppeteer = require('puppeteer-extra')
puppeteer.use(require('puppeteer-extra-plugin-repl')())

puppeteer.launch({ headless: true }).then(async browser => {
  const page = await browser.newPage()
  await page.goto('https://example.com')

  // Start an interactive REPL here with the `page` instance.
  await page.repl()
  // Afterwards start REPL with the `browser` instance.
  await browser.repl()

  await browser.close()
})

In the REPL session (hit tab two times to see all available properties):

> page.url()
// => https://example.com
> page.click('a')
> page.url()
// => https://www.iana.org/domains/reserved
> page.content()
// => <!DOCTYPE html><html><head> ...
> page.goto('https://google.com')
> page.type('input', 'what is the answer to life the universe and everything')
> page.click('input[type=submit]')
> page.url()
// => https://www.google.com/search?source=hp&ei=u9oXW5HpO8a ...
> page.evaluate(() => document.querySelector('h3 a').textContent)
// => Question 42 (The Impossible Quiz) - The Impossible Quiz Wiki - Fandom
  • Type inspect to return the current object.
  • Type exit (or hit ctrl+c) to leave the repl.

API

Table of Contents

Plugin

Extends: PuppeteerExtraPlugin

Interrupt your puppeteer code with an interactive REPL.

Features tab auto-completion for the given object properties and a colorized prompt.

Works with arbitrary objects ands class instances, though Page & Browser make the most sense. :-)

opts

Type: function (opts)

  • opts Object Options (optional, default {})
    • opts.addToPuppeteerClass boolean? If a .repl() method should be attached to Puppeteer Page and Browser instances (default: true).

Example:

// In this example we don't extend the native puppeteer classes

const puppeteer = require('puppeteer-extra')
const repl = require('puppeteer-extra-plugin-repl')({ addToPuppeteerClass: false })
puppeteer.use(repl)

puppeteer.launch({ headless: true }).then(async browser => {
  const page = await browser.newPage()
  await page.goto('https://example.com')

  // Start an interactive REPL here with the `page` instance.
  await repl.repl(page)
  // Afterwards start REPL with the `repl` instance itself. 🐴
  await repl.repl(repl)

  await browser.close()
})

repl

Create an interactive REPL for the provided object.

Uses an extended (colorized) readline interface under the hood. Will resolve the returned Promise when the readline interface is closed.

If opts.addToPuppeteerClass is true (default) then page.repl()/browser.repl() will point to this method, for convenience.

Can be used standalone as well, to inspect an arbitrary class instance or object.

Type: function (obj): Promise

  • obj Object An object or class instance to use in the repl (e.g. page, browser)

Example:

const repl = require('puppeteer-extra-plugin-repl')()
await repl.repl(<object or class instance to inspect>)