Socket
Socket
Sign inDemoInstall

puppeteer-extra-plugin-repl

Package Overview
Dependencies
139
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    puppeteer-extra-plugin-repl

Start an interactive REPL in your puppeteer code.


Version published
Weekly downloads
864
decreased by-3.68%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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>)

Keywords

FAQs

Last updated on 01 Mar 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc