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.

34 lines (33 loc) 1.55 kB
/// <reference types="chrome" /> /** * A class that provides a type-safe wrapper around Chrome's runtime API. * This class allows you to handle message passing between different parts of your extension, * manage extension lifecycle events, and access extension information. */ declare class Runtime { /** * Sends a message to the extension's runtime. * @param message - The message to send * @returns A promise that resolves to the response from the message handler * @template T - The type of the response */ static sendMessage<T>(message: any): Promise<T>; /** * Adds a listener for messages from the extension. * @param callback - Function called when a message is received * @returns A function that removes the listener when called */ static addMessageListener(callback: (message: any, sender: chrome.runtime.MessageSender, sendResponse: (response: any) => void) => void): () => void; /** * Adds a listener for messages from external extensions or apps. * @param callback - Function called when an external message is received * @returns A function that removes the listener when called */ static addExternalMessageListener(callback: (message: any, sender: chrome.runtime.MessageSender, sendResponse: (response: any) => void) => void): () => void; /** * Gets the manifest of the extension. * @returns A promise that resolves to the extension's manifest */ static getManifest(): Promise<chrome.runtime.Manifest>; } export { Runtime };