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.

38 lines (37 loc) 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Commands = void 0; /** * A class that provides a type-safe wrapper around Chrome's commands API. * This class allows you to retrieve registered commands and listen for command triggers. * Commands are keyboard shortcuts that can be used to trigger actions in your extension. */ class Commands { /** * Retrieves all registered commands for the extension. * @returns A promise that resolves to an array of Command objects * @throws {Error} If there's an error retrieving the commands */ static async getAll() { return new Promise((resolve, reject) => { chrome.commands.getAll((commands) => { if (chrome.runtime.lastError) { reject(chrome.runtime.lastError); } else { resolve(commands); } }); }); } /** * Adds a listener for command events. * @param callback - Function called when a command is triggered via keyboard shortcut * @returns A function that removes the listener when called */ static addCommandListener(callback) { chrome.commands.onCommand.addListener(callback); return () => chrome.commands.onCommand.removeListener(callback); } } exports.Commands = Commands;