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-extension-transport

v0.0.6

Published

Use puppeteer in your browser extension

Downloads

25

Readme

Puppeteer Extension Transport

lint build npm version

This package allows you to use puppeteer-core in your browser extension's background page/service worker. It internally uses chrome.debugger extension api.

IMPORTANT NOTE :- For this to work, extension should have debugger permission specified in it's manifest json. Check manifest.json in examples for reference.

Installation

To install this package run:

npm i puppeteer-extension-transport

or with yarn:

yarn add puppeteer-extension-transport

Usage

There are v2 extension example and v3 extension example in examples folder which you can load in your browser to test.

Here is an example of using this package:

import puppeteer from 'puppeteer-core/lib/cjs/puppeteer/web'
import { ExtensionDebuggerTransport } from 'puppeteer-extension-transport'

async function run(tabId) {
    const extensionTransport = await ExtensionDebuggerTransport.create(tabId)
    const browser = await puppeteer.connect({
        transport: extensionTransport,
        defaultViewport: null,
    })

      // use first page from pages instead of using browser.newPage()
    const [page] = await browser.pages()

    await page.goto('https://wikipedia.org')

    const screenshot = await page.screenshot({
        encoding: 'base64',
    });
    console.log(`data:image/png;base64,${screenshot}`)

    const englishButton = await page.waitForSelector('#js-link-box-en > strong')
    await englishButton.click()

    const searchBox = await page.waitForSelector('#searchInput');
    await searchBox.type('telephone')
    await page.keyboard.press('Enter')

    await page.close();
}

chrome.tabs.create(
    {
        active: true,
        url: 'https://www.google.co.in',
    },
    tab => (tab.id ? run(tab.id) : null)
)

Execution :

execution gif

Check puppeteer documentation here.

API

Check other available options/config for this package here.

FAQ

Q: With which browsers can this be used ? This can be used with chrome and chromium based edge browsers.

Q: Does this require browser to be started with some CLI flags ? No. This package internally uses chrome.debugger api to communicate with chrome devtools protocol.

Q: What do i need to specify in manifest.json of extension ? You will atleast need to specify below in manifest.json:

"permissions": ["debugger"]

Check example v2 manifest.json or v3 manifest.json

Q: Who could use this ? If you are planning to do any of the following in extension:

  1. do automation.
  2. profiling, debugging, monitoring and handling lifecycle events of web pages.
  3. any other thing you would like to use puppeteer for.