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

v2.4.6

Published

Make puppeteer browser debugging possible from anywhere (devtools with screencasting on the internet).

Downloads

5,599

Readme

puppeteer-extra-plugin-devtools

A plugin for puppeteer-extra.

Installation

yarn add puppeteer-extra-plugin-devtools

Purpose

Make puppeteer browser debugging possible from anywhere.

  • Creates a secure tunnel to make the devtools frontend (incl. screencasting) accessible from the public internet
  • Works for both headless and headful puppeteer instances, as well as within docker containers
  • Uses the already existing DevTools Protocol websocket connection from puppeteer
  • Features some convenience functions for using the devtools frontend locally

Magic

screenshot

Quickstart

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

puppeteer
  .launch({ headless: true, defaultViewport: null })
  .then(async browser => {
    console.log('Start')
    const tunnel = await devtools.createTunnel(browser)
    console.log(tunnel.url)

    const page = await browser.newPage()
    await page.goto('https://example.com')
    console.log('All setup.')
  })

API

Table of Contents

Plugin

Extends: PuppeteerExtraPlugin

As the tunnel page is public the plugin will require basic auth.

You can set your own credentials using opts or setAuthCredentials().

If you don't specify basic auth credentials the plugin will generate a password and print it to STDOUT.

opts

Type: function (opts)

  • opts Object Options (optional, default {})
    • opts.auth Object? Basic auth credentials for the public page
      • opts.auth.user string? Username (default: 'user')
      • opts.auth.pass string? Password (will be generated if not provided)
    • opts.prefix Object? The prefix to use for the localtunnel.me subdomain (default: 'devtools-tunnel')
    • opts.localtunnel Object? Advanced options to pass to localtunnel

Example:

const puppeteer = require('puppeteer-extra')
const devtools = require('puppeteer-extra-plugin-devtools')({
  auth: { user: 'francis', pass: 'president' }
})
puppeteer.use(devtools)

puppeteer.launch().then(async browser => {
  console.log('tunnel url:', (await devtools.createTunnel(browser)).url)
  // => tunnel url: https://devtools-tunnel-n9aogqwx3d.localtunnel.me
})

createTunnel

Create a new public tunnel.

Supports multiple browser instances (will create a new tunnel for each).

Type: function (browser): Tunnel

  • browser Puppeteer.Browser The browser to create the tunnel for (there can be multiple)

Example:

const puppeteer = require('puppeteer-extra')
const devtools = require('puppeteer-extra-plugin-devtools')()
devtools.setAuthCredentials('bob', 'swordfish')
puppeteer.use(devtools)
;(async () => {
  const browserFleet = await Promise.all(
    [...Array(3)].map(slot => puppeteer.launch())
  )
  for (const [index, browser] of browserFleet.entries()) {
    const { url } = await devtools.createTunnel(browser)
    console.info(`Browser ${index}'s devtools frontend can be found at: ${url}`)
  }
})()
// =>
// Browser 0's devtools frontend can be found at: https://devtools-tunnel-fzenb4zuav.localtunnel.me
// Browser 1's devtools frontend can be found at: https://devtools-tunnel-qe2t5rghme.localtunnel.me
// Browser 2's devtools frontend can be found at: https://devtools-tunnel-pp83sdi4jo.localtunnel.me

setAuthCredentials

Set the basic auth credentials for the public tunnel page.

Alternatively the credentials can be defined when instantiating the plugin.

Type: function (user, pass)

Example:

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

puppeteer.launch().then(async browser => {
  devtools.setAuthCredentials('bob', 'swordfish')
  const tunnel = await devtools.createTunnel(browser)
})

getLocalDevToolsUrl

Convenience function to get the local devtools frontend URL.

Type: function (browser): string

  • browser Puppeteer.Browser

Example:

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

puppeteer.launch().then(async browser => {
  console.log(devtools.getLocalDevToolsUrl(browser))
  // => http://localhost:55952
})

Tunnel

Extends: RemoteDevTools.DevToolsTunnel

The devtools tunnel for a browser instance.

Type: function (wsEndpoint, opts)

  • wsEndpoint
  • opts (optional, default {})

url

Get the public devtools frontend url.

Type: function (): string

Example:

const tunnel = await devtools.createTunnel(browser)
console.log(tunnel.url)
// => https://devtools-tunnel-sdoqqj95vg.localtunnel.me

getUrlForPage

Get the devtools frontend deep link for a specific page.

Type: function (page): string

  • page Puppeteer.Page

Example:

const page = await browser.newPage()
const tunnel = await devtools.createTunnel(browser)
console.log(tunnel.getUrlForPage(page))
// => https://devtools-tunnel-bmkjg26zmr.localtunnel.me/devtools/inspector.html?ws(...)

close

Close the tunnel.

The tunnel will automatically stop when your script exits.

Type: function ()

Example:

const tunnel = await devtools.createTunnel(browser)
tunnel.close()