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 🙏

© 2026 – Pkg Stats / Ryan Hefner

webextension-contextmenu

v0.0.33

Published

Generate the webextension's right-click context menu with minimal typing

Readme

Webextension Context Menu

Generate the webextension's right-click context menu with minimal typing.

How to install and prepare

Install the library through

npm install webextension-contextmenu

then import with

import createContextMenu from 'webextension-contextmenu'

in your script file.

Usage

Library exports one function createContextMenu, which takes one object argument Menu that describes the entire menu structure.
The signature:

createContextMenu(Menu {
  optionTitle1: Menu {
    optionTitle2: optionProps2,
    optionTitle3: optionProps3,
    optionTitle4: optionProps4,
    ...
  }
}) => MenuIds {}

Where:
optionTitle - title of the option.
optionProps - description of the corresponding option. Depending on the type of the value, the resulting option appearance and behavior may differ.
|optionProps value| What represents | |---|---| |onClickHandler (Option, Tab) => void | function to run when clicking on the option, where: Option - the clicked option, Tab - the tab where it happened | |true|checkbox checked| |false|checkbox unchecked| |[true]| radio checked | |[]| radio unchecked | |null| options separator (it doesn't actually need to have any eligible optionTitle) | |Menu {}| another submenu | |[{ ...createProperties }] (single object inside an array)| any other createProperties that may be passed onto menus.create method |

Multiple values can be combined inside one optionProps with the use of an array, e.g. [() => {}, true] will create a checked option with a click handler.
Menus can be nested in other Menus as much as you would like, or the browser will allow.

MenuIds - returning value containing the ids of all created options. With the same object structure as the initial Menu argument, but with ids instead of optionProps.

Important: createContextMenu works asynchronously, so you should await or use Promise.then, if you want to continue working with its returned value

Updating

To update the context menu, run createContextMenu again with a new Menu argument.

Example:

createContextMenu({
  "My Greatest Extension": {
    "Option 1": (option, tab) => console.log("Do something", option, tab),
    "Option 2": {
      Radio1: [
        [], () => console.log("radio clicked"),
      ],
      Radio2: [
        [true], () => console.log("radio clicked"),
      ],
      Radio3: [
        [], () => console.log("radio clicked"),
      ],
    },
    "Separator optionTitle is irrelevant": null,
    // you can easily rewrite the optionTitle inside createProperties
    "Option 3": [{ title: "Rewritten title" }],
    "Option 4": [
      true,
      () => {
        console.log("Callback won't work because the option is disabled");
      },
      // if there are already multiple properties
      // the createProperties can just be passed as an object at the end of the array
      { enabled: false },
    ],
  },
})