UNPKG

@mirawision/chrome-api

Version:

A comprehensive TypeScript library for Chrome Extension API, providing type-safe wrappers and utilities for bookmarks, commands, context menus, cookies, downloads, storage, notifications, runtime, scripting, and side panel functionalities.

30 lines (29 loc) 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContextMenu = void 0; /** * A class that provides a type-safe wrapper around Chrome's context menu API. * This class allows you to create context menu items and handle their click events. * Context menus appear when users right-click in your extension's allowed contexts. */ class ContextMenu { /** * Creates a new context menu item. * @param id - Unique identifier for the menu item * @param title - Text to be displayed in the menu * @param contexts - Array of contexts where the menu item will appear (defaults to ['page']) */ static create(id, title, contexts = ['page']) { chrome.contextMenus.create({ id, title, contexts }); } /** * Adds a listener for context menu item clicks. * @param callback - Function called when a menu item is clicked * @returns A function that removes the listener when called */ static addClickListener(callback) { chrome.contextMenus.onClicked.addListener(callback); return () => chrome.contextMenus.onClicked.removeListener(callback); } } exports.ContextMenu = ContextMenu;