@types/chrome
Version:
TypeScript definitions for Chrome extension development
970 lines (889 loc) • 628 kB
TypeScript
// Type definitions for Chrome extension development
// Project: http://developer.chrome.com/extensions/
// Definitions by: Matthew Kimber <https://github.com/matthewkimber>
// otiai10 <https://github.com/otiai10>
// sreimer15 <https://github.com/sreimer15>
// MatCarlson <https://github.com/MatCarlson>
// ekinsol <https://github.com/ekinsol>
// Brian Wilson <https://github.com/echoabstract>
// Sebastiaan Pasma <https://github.com/spasma>
// bdbai <https://github.com/bdbai>
// pokutuna <https://github.com/pokutuna>
// Jason Xian <https://github.com/JasonXian>
// userTim <https://github.com/usertim>
// Idan Zeierman <https://github.com/idan315>
// Nicolas Rodriguez <https://github.com/nicolas377>
// Ido Salomon <https://github.com/idosal>
// Federico Brigante <https://github.com/fregante>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
/// <reference types="filesystem" />
/// <reference path="./har-format/index.d.ts" />
/// <reference path="./chrome-cast/index.d.ts" />
////////////////////
// Global object
////////////////////
interface Window {
chrome: typeof chrome;
}
////////////////////
// Accessibility Features
////////////////////
/**
* Use the chrome.accessibilityFeatures API to manage Chrome's accessibility features. This API relies on the ChromeSetting prototype of the type API for getting and setting individual accessibility features. In order to get feature states the extension must request accessibilityFeatures.read permission. For modifying feature state, the extension needs accessibilityFeatures.modify permission. Note that accessibilityFeatures.modify does not imply accessibilityFeatures.read permission.
* Availability: Since Chrome 37.
* Permissions: "accessibilityFeatures.read"
* Important: This API works only on Chrome OS.
*/
declare namespace chrome.accessibilityFeatures {
/** **ChromeOS only.** Spoken feedback (text-to-speech). */
export var spokenFeedback: chrome.types.ChromeSetting;
/** **ChromeOS only.** Enlarged cursor. */
export var largeCursor: chrome.types.ChromeSetting;
/** **ChromeOS only.** Sticky modifier keys (like shift or alt). */
export var stickyKeys: chrome.types.ChromeSetting;
/** **ChromeOS only.** High contrast rendering mode. */
export var highContrast: chrome.types.ChromeSetting;
/** **ChromeOS only.** Full screen magnification. */
export var screenMagnifier: chrome.types.ChromeSetting;
/** **ChromeOS only.** Auto mouse click after mouse stops moving. */
export var autoclick: chrome.types.ChromeSetting;
/** **ChromeOS only.** Virtual on-screen keyboard. */
export var virtualKeyboard: chrome.types.ChromeSetting;
/**
* **ChromeOS only.**
* Caret highlighting.
* @since Chrome 51.
*/
export var caretHighlight: chrome.types.ChromeSetting;
/**
* **ChromeOS only.**
* Cursor highlighting.
* @since Chrome 51.
*/
export var cursorHighlight: chrome.types.ChromeSetting;
/**
* **ChromeOS only.**
* Focus highlighting.
* @since Chrome 51.
*/
export var focusHighlight: chrome.types.ChromeSetting;
/**
* **ChromeOS only.**
* Select-to-speak.
* @since Chrome 51.
*/
export var selectToSpeak: chrome.types.ChromeSetting;
/**
* **ChromeOS only.**
* Switch Access.
* @since Chrome 51.
*/
export var switchAccess: chrome.types.ChromeSetting;
/**
* @since Chrome 42.
*/
export var animationPolicy: chrome.types.ChromeSetting;
}
////////////////////
// Action
////////////////////
/**
* Use the chrome.action API to control the extension's icon in the Google Chrome toolbar.
* Availability: Since Chrome 88. Manifest v3.
* Manifest: "action": {...}
*/
declare namespace chrome.action {
/** @deprecated Use BadgeColorDetails instead. */
export interface BadgeBackgroundColorDetails extends BadgeColorDetails {}
export interface BadgeColorDetails {
/** An array of four integers in the range [0,255] that make up the RGBA color of the badge. For example, opaque red is [255, 0, 0, 255]. Can also be a string with a CSS value, with opaque red being #FF0000 or #F00. */
color: string | ColorArray;
/** Optional. Limits the change to when a particular tab is selected. Automatically resets when the tab is closed. */
tabId?: number | undefined;
}
export interface BadgeTextDetails {
/** Any number of characters can be passed, but only about four can fit in the space. */
text: string;
/** Optional. Limits the change to when a particular tab is selected. Automatically resets when the tab is closed. */
tabId?: number | undefined;
}
export type ColorArray = [number, number, number, number];
export interface TitleDetails {
/** The string the action should display when moused over. */
title: string;
/** Optional. Limits the change to when a particular tab is selected. Automatically resets when the tab is closed. */
tabId?: number | undefined;
}
export interface PopupDetails {
/** Optional. Limits the change to when a particular tab is selected. Automatically resets when the tab is closed. */
tabId?: number | undefined;
/** The html file to show in a popup. If set to the empty string (''), no popup is shown. */
popup: string;
}
export interface BrowserClickedEvent extends chrome.events.Event<(tab: chrome.tabs.Tab) => void> { }
export interface TabIconDetails {
/** Optional. Either a relative image path or a dictionary {size -> relative image path} pointing to icon to be set. If the icon is specified as a dictionary, the actual image to be used is chosen depending on screen's pixel density. If the number of image pixels that fit into one screen space unit equals scale, then image with size scale * 19 will be selected. Initially only scales 1 and 2 will be supported. At least one image must be specified. Note that 'details.path = foo' is equivalent to 'details.imageData = {'19': foo}' */
path?: string | { [index: number]: string } | undefined;
/** Optional. Limits the change to when a particular tab is selected. Automatically resets when the tab is closed. */
tabId?: number | undefined;
/** Optional. Either an ImageData object or a dictionary {size -> ImageData} representing icon to be set. If the icon is specified as a dictionary, the actual image to be used is chosen depending on screen's pixel density. If the number of image pixels that fit into one screen space unit equals scale, then image with size scale * 19 will be selected. Initially only scales 1 and 2 will be supported. At least one image must be specified. Note that 'details.imageData = foo' is equivalent to 'details.imageData = {'19': foo}' */
imageData?: ImageData | { [index: number]: ImageData } | undefined;
}
export interface OpenPopupOptions {
/** Optional. The id of the window to open the action popup in. Defaults to the currently-active window if unspecified. */
windowId?: number | undefined;
}
export interface TabDetails {
/** Optional. The ID of the tab to query state for. If no tab is specified, the non-tab-specific state is returned. */
tabId?: number | undefined;
}
export interface UserSettings {
/** Whether the extension's action icon is visible on browser windows' top-level toolbar (i.e., whether the extension has been 'pinned' by the user). */
isOnToolbar: boolean;
}
/**
* Since Chrome 88.
* Disables the action for a tab.
* @param tabId The id of the tab for which you want to modify the action.
* @return The `disable` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
*/
export function disable(tabId?: number): Promise<void>;
/**
* Since Chrome 88.
* Disables the action for a tab.
* @param tabId The id of the tab for which you want to modify the action.
* @param callback
*/
export function disable(callback: () => void): void;
export function disable(tabId: number, callback: () => void): void;
/**
* Since Chrome 88.
* Enables the action for a tab. By default, actions are enabled.
* @param tabId The id of the tab for which you want to modify the action.
* @return The `enable` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
*/
export function enable(tabId?: number): Promise<void>;
/**
* Since Chrome 88.
* Enables the action for a tab. By default, actions are enabled.
* @param tabId The id of the tab for which you want to modify the action.
* @param callback
*/
export function enable(callback: () => void): void;
export function enable(tabId: number, callback: () => void): void;
/**
* Since Chrome 88.
* Gets the background color of the action.
*/
export function getBadgeBackgroundColor(details: TabDetails, callback: (result: ColorArray) => void): void;
/**
* Since Chrome 88.
* Gets the background color of the action.
* @return The `getBadgeBackgroundColor` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function getBadgeBackgroundColor(details: TabDetails): Promise<ColorArray>;
/**
* Since Chrome 88.
* Gets the badge text of the action. If no tab is specified, the non-tab-specific badge text is returned.
* If displayActionCountAsBadgeText is enabled, a placeholder text will be returned unless the
* declarativeNetRequestFeedback permission is present or tab-specific badge text was provided.
*/
export function getBadgeText(details: TabDetails, callback: (result: string) => void): void;
/**
* Since Chrome 88.
* Gets the badge text of the action. If no tab is specified, the non-tab-specific badge text is returned.
* If displayActionCountAsBadgeText is enabled, a placeholder text will be returned unless the
* declarativeNetRequestFeedback permission is present or tab-specific badge text was provided.
* @return The `getBadgeText` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function getBadgeText(details: TabDetails): Promise<string>;
/**
* Since Chrome 110.
* Gets the text color of the action.
*/
export function getBadgeTextColor(details: TabDetails, callback: (result: ColorArray) => void): void;
/**
* Since Chrome 110.
* Gets the text color of the action.
* @return The `getBadgeTextColor` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function getBadgeTextColor(details: TabDetails): Promise<ColorArray>;
/**
* Since Chrome 88.
* Gets the html document set as the popup for this action.
*/
export function getPopup(details: TabDetails, callback: (result: string) => void): void;
/**
* Since Chrome 88.
* Gets the html document set as the popup for this action.
* @return The `getPopup` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function getPopup(details: TabDetails): Promise<string>;
/**
* Since Chrome 88.
* Gets the title of the action.
*/
export function getTitle(details: TabDetails, callback: (result: string) => void): void;
/**
* Since Chrome 88.
* Gets the title of the action.
* @return The `getTitle` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function getTitle(details: TabDetails): Promise<string>;
/**
* Since Chrome 91.
* Returns the user-specified settings relating to an extension's action.
*/
export function getUserSettings(callback: (userSettings: UserSettings) => void): void;
/**
* Since Chrome 91.
* Returns the user-specified settings relating to an extension's action.
* @return The `getUserSettings` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function getUserSettings(): Promise<UserSettings>;
/**
* Since Chrome 110.
* Indicates whether the extension action is enabled for a tab (or globally if no tabId is provided). Actions enabled using only declarativeContent always return false.
*/
export function isEnabled(tabId: number | undefined, callback: (isEnabled: boolean) => void): void;
/**
* Since Chrome 110.
* Indicates whether the extension action is enabled for a tab (or globally if no tabId is provided). Actions enabled using only declarativeContent always return false.
* @return True if the extension action is enabled.
*/
export function isEnabled(tabId?: number): Promise<boolean>;
/**
* Since Chrome 99+.
* Opens the extension's popup.
* @param options Specifies options for opening the popup.
* () => {...}
* @return The `openPopup` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
*/
export function openPopup(options?: OpenPopupOptions): Promise<void>;
/**
* Since Chrome 99+.
* Opens the extension's popup.
* @param options Specifies options for opening the popup.
*/
export function openPopup(callback: () => void): void;
export function openPopup(options: OpenPopupOptions, callback: () => void): void;
/**
* Since Chrome 88.
* Sets the background color for the badge.
* @return The `setBadgeBackgroundColor` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
*/
export function setBadgeBackgroundColor(details: BadgeColorDetails): Promise<void>;
/**
* Since Chrome 88.
* Sets the background color for the badge.
*/
export function setBadgeBackgroundColor(details: BadgeColorDetails, callback: () => void): void;
/**
* Since Chrome 88.
* Sets the badge text for the action. The badge is displayed on top of the icon.
* @return The `setBadgeText` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
*/
export function setBadgeText(details: BadgeTextDetails): Promise<void>;
/**
* Since Chrome 88.
* Sets the badge text for the action. The badge is displayed on top of the icon.
*/
export function setBadgeText(details: BadgeTextDetails, callback: () => void): void;
/**
* Since Chrome 110.
* Sets the text color for the badge.
* @return The `setBadgeTextColor` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
*/
export function setBadgeTextColor(details: BadgeColorDetails): Promise<void>;
/**
* Since Chrome 100.
* Sets the text color for the badge.
*/
export function setBadgeTextColor(details: BadgeColorDetails, callback: () => void): void;
/**
* Since Chrome 88.
* Sets the icon for the action. The icon can be specified either as the path to an image file or as the pixel data from a canvas element,
* or as dictionary of either one of those. Either the path or the imageData property must be specified.
* @return The `setIcon` method provides its result via callback or returned as a `Promise` (MV3 only). Since Chrome 96.
*/
export function setIcon(details: TabIconDetails): Promise<void>
export function setIcon(details: TabIconDetails, callback: () => void): void;
/**
* Since Chrome 88.
* Sets the html document to be opened as a popup when the user clicks on the action's icon.
* @return The `setPopup` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
*/
export function setPopup(details: PopupDetails): Promise<void>;
/**
* Since Chrome 88.
* Sets the html document to be opened as a popup when the user clicks on the action's icon.
*/
export function setPopup(details: PopupDetails, callback: () => void): void;
/**
* Since Chrome 88.
* Sets the title of the action. This shows up in the tooltip.
* @return The `setTitle` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
*/
export function setTitle(details: TitleDetails): Promise<void>;
/**
* Since Chrome 88.
* Sets the title of the action. This shows up in the tooltip.
*/
export function setTitle(details: TitleDetails, callback: () => void): void;
/** Fired when an action icon is clicked. This event will not fire if the action has a popup. */
export var onClicked: BrowserClickedEvent;
}
////////////////////
// Alarms
////////////////////
/**
* Use the chrome.alarms API to schedule code to run periodically or at a specified time in the future.
* Availability: Since Chrome 22.
* Permissions: "alarms"
*/
declare namespace chrome.alarms {
export interface AlarmCreateInfo {
/** Optional. Length of time in minutes after which the onAlarm event should fire. */
delayInMinutes?: number | undefined;
/** Optional. If set, the onAlarm event should fire every periodInMinutes minutes after the initial event specified by when or delayInMinutes. If not set, the alarm will only fire once. */
periodInMinutes?: number | undefined;
/** Optional. Time at which the alarm should fire, in milliseconds past the epoch (e.g. Date.now() + n). */
when?: number | undefined;
}
export interface Alarm {
/** Optional. If not null, the alarm is a repeating alarm and will fire again in periodInMinutes minutes. */
periodInMinutes?: number | undefined;
/** Time at which this alarm was scheduled to fire, in milliseconds past the epoch (e.g. Date.now() + n). For performance reasons, the alarm may have been delayed an arbitrary amount beyond this. */
scheduledTime: number;
/** Name of this alarm. */
name: string;
}
export interface AlarmEvent extends chrome.events.Event<(alarm: Alarm) => void> { }
/**
* Creates an alarm. Near the time(s) specified by alarmInfo, the onAlarm event is fired. If there is another alarm with the same name (or no name if none is specified), it will be cancelled and replaced by this alarm.
* In order to reduce the load on the user's machine, Chrome limits alarms to at most once every 1 minute but may delay them an arbitrary amount more. That is, setting delayInMinutes or periodInMinutes to less than 1 will not be honored and will cause a warning. when can be set to less than 1 minute after "now" without warning but won't actually cause the alarm to fire for at least 1 minute.
* To help you debug your app or extension, when you've loaded it unpacked, there's no limit to how often the alarm can fire.
* @param alarmInfo Describes when the alarm should fire. The initial time must be specified by either when or delayInMinutes (but not both). If periodInMinutes is set, the alarm will repeat every periodInMinutes minutes after the initial event. If neither when or delayInMinutes is set for a repeating alarm, periodInMinutes is used as the default for delayInMinutes.
* @return The `create` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function create(alarmInfo: AlarmCreateInfo): Promise<void>;
/**
* Creates an alarm. Near the time(s) specified by alarmInfo, the onAlarm event is fired. If there is another alarm with the same name (or no name if none is specified), it will be cancelled and replaced by this alarm.
* In order to reduce the load on the user's machine, Chrome limits alarms to at most once every 1 minute but may delay them an arbitrary amount more. That is, setting delayInMinutes or periodInMinutes to less than 1 will not be honored and will cause a warning. when can be set to less than 1 minute after "now" without warning but won't actually cause the alarm to fire for at least 1 minute.
* To help you debug your app or extension, when you've loaded it unpacked, there's no limit to how often the alarm can fire.
* @param name Optional name to identify this alarm. Defaults to the empty string.
* @param alarmInfo Describes when the alarm should fire. The initial time must be specified by either when or delayInMinutes (but not both). If periodInMinutes is set, the alarm will repeat every periodInMinutes minutes after the initial event. If neither when or delayInMinutes is set for a repeating alarm, periodInMinutes is used as the default for delayInMinutes.
* @return The `create` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function create(name: string, alarmInfo: AlarmCreateInfo): Promise<void>;
/**
* Creates an alarm. Near the time(s) specified by alarmInfo, the onAlarm event is fired. If there is another alarm with the same name (or no name if none is specified), it will be cancelled and replaced by this alarm.
* In order to reduce the load on the user's machine, Chrome limits alarms to at most once every 1 minute but may delay them an arbitrary amount more. That is, setting delayInMinutes or periodInMinutes to less than 1 will not be honored and will cause a warning. when can be set to less than 1 minute after "now" without warning but won't actually cause the alarm to fire for at least 1 minute.
* To help you debug your app or extension, when you've loaded it unpacked, there's no limit to how often the alarm can fire.
* @param alarmInfo Describes when the alarm should fire. The initial time must be specified by either when or delayInMinutes (but not both). If periodInMinutes is set, the alarm will repeat every periodInMinutes minutes after the initial event. If neither when or delayInMinutes is set for a repeating alarm, periodInMinutes is used as the default for delayInMinutes.
*/
export function create(alarmInfo: AlarmCreateInfo, callback: () => void): void;
/**
* Creates an alarm. Near the time(s) specified by alarmInfo, the onAlarm event is fired. If there is another alarm with the same name (or no name if none is specified), it will be cancelled and replaced by this alarm.
* In order to reduce the load on the user's machine, Chrome limits alarms to at most once every 1 minute but may delay them an arbitrary amount more. That is, setting delayInMinutes or periodInMinutes to less than 1 will not be honored and will cause a warning. when can be set to less than 1 minute after "now" without warning but won't actually cause the alarm to fire for at least 1 minute.
* To help you debug your app or extension, when you've loaded it unpacked, there's no limit to how often the alarm can fire.
* @param name Optional name to identify this alarm. Defaults to the empty string.
* @param alarmInfo Describes when the alarm should fire. The initial time must be specified by either when or delayInMinutes (but not both). If periodInMinutes is set, the alarm will repeat every periodInMinutes minutes after the initial event. If neither when or delayInMinutes is set for a repeating alarm, periodInMinutes is used as the default for delayInMinutes.
*/
export function create(name: string, alarmInfo: AlarmCreateInfo, callback: () => void): void;
/**
* Gets an array of all the alarms.
*/
export function getAll(callback: (alarms: Alarm[]) => void): void;
/**
* Gets an array of all the alarms.
* @return The `getAll` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function getAll(): Promise<Alarm[]>;
/**
* Clears all alarms.
* function(boolean wasCleared) {...};
* @return The `clearAll` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function clearAll(): Promise<boolean>;
/**
* Clears all alarms.
*/
export function clearAll(callback: (wasCleared: boolean) => void): void;
/**
* Clears the alarm with the given name.
* @param name The name of the alarm to clear. Defaults to the empty string.
* @return The `clear` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function clear(name?: string): Promise<boolean>;
/**
* Clears the alarm with the given name.
* @param name The name of the alarm to clear. Defaults to the empty string.
*/
export function clear(callback: (wasCleared: boolean) => void): void;
export function clear(name: string, callback: (wasCleared: boolean) => void): void;
/**
* Clears the alarm without a name.
*/
export function clear(callback: (wasCleared: boolean) => void): void;
/**
* Clears the alarm without a name.
* @return The `clear` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function clear(): Promise<void>;
/**
* Retrieves details about the specified alarm.
*/
export function get(callback: (alarm: Alarm) => void): void;
/**
* Retrieves details about the specified alarm.
* @return The `get` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function get(): Promise<Alarm>;
/**
* Retrieves details about the specified alarm.
* @param name The name of the alarm to get. Defaults to the empty string.
*/
export function get(name: string, callback: (alarm: Alarm) => void): void;
/**
* Retrieves details about the specified alarm.
* @param name The name of the alarm to get. Defaults to the empty string.
* @return The `get` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function get(name: string): Promise<Alarm>;
/** Fired when an alarm has elapsed. Useful for event pages. */
export var onAlarm: AlarmEvent;
}
////////////////////
// Browser
////////////////////
/**
* Use the chrome.browser API to interact with the Chrome browser associated with
* the current application and Chrome profile.
*/
declare namespace chrome.browser {
export interface Options {
/** The URL to navigate to when the new tab is initially opened. */
url: string;
}
/**
* Opens a new tab in a browser window associated with the current application
* and Chrome profile. If no browser window for the Chrome profile is opened,
* a new one is opened prior to creating the new tab.
* @param options Configures how the tab should be opened.
* @param callback Called when the tab was successfully
* created, or failed to be created. If failed, runtime.lastError will be set.
*/
export function openTab(options: Options, callback: () => void): void;
/**
* Opens a new tab in a browser window associated with the current application
* and Chrome profile. If no browser window for the Chrome profile is opened,
* a new one is opened prior to creating the new tab. Since Chrome 42 only.
* @param options Configures how the tab should be opened.
*/
export function openTab(options: Options): void;
}
////////////////////
// Bookmarks
////////////////////
/**
* Use the chrome.bookmarks API to create, organize, and otherwise manipulate bookmarks. Also see Override Pages, which you can use to create a custom Bookmark Manager page.
* Availability: Since Chrome 5.
* Permissions: "bookmarks"
*/
declare namespace chrome.bookmarks {
/** A node (either a bookmark or a folder) in the bookmark tree. Child nodes are ordered within their parent folder. */
export interface BookmarkTreeNode {
/** Optional. The 0-based position of this node within its parent folder. */
index?: number | undefined;
/** Optional. When this node was created, in milliseconds since the epoch (new Date(dateAdded)). */
dateAdded?: number | undefined;
/** The text displayed for the node. */
title: string;
/** Optional. The URL navigated to when a user clicks the bookmark. Omitted for folders. */
url?: string | undefined;
/** Optional. When the contents of this folder last changed, in milliseconds since the epoch. */
dateGroupModified?: number | undefined;
/** The unique identifier for the node. IDs are unique within the current profile, and they remain valid even after the browser is restarted. */
id: string;
/** Optional. The id of the parent folder. Omitted for the root node. */
parentId?: string | undefined;
/** Optional. An ordered list of children of this node. */
children?: BookmarkTreeNode[] | undefined;
/**
* Optional.
* Since Chrome 37.
* Indicates the reason why this node is unmodifiable. The managed value indicates that this node was configured by the system administrator or by the custodian of a supervised user. Omitted if the node can be modified by the user and the extension (default).
*/
unmodifiable?: 'managed' | undefined;
}
export interface BookmarkRemoveInfo {
index: number;
parentId: string;
node: BookmarkTreeNode;
}
export interface BookmarkMoveInfo {
index: number;
oldIndex: number;
parentId: string;
oldParentId: string;
}
export interface BookmarkChangeInfo {
url?: string | undefined;
title: string;
}
export interface BookmarkReorderInfo {
childIds: string[];
}
export interface BookmarkRemovedEvent
extends chrome.events.Event<(id: string, removeInfo: BookmarkRemoveInfo) => void> { }
export interface BookmarkImportEndedEvent extends chrome.events.Event<() => void> { }
export interface BookmarkMovedEvent extends chrome.events.Event<(id: string, moveInfo: BookmarkMoveInfo) => void> { }
export interface BookmarkImportBeganEvent extends chrome.events.Event<() => void> { }
export interface BookmarkChangedEvent
extends chrome.events.Event<(id: string, changeInfo: BookmarkChangeInfo) => void> { }
export interface BookmarkCreatedEvent
extends chrome.events.Event<(id: string, bookmark: BookmarkTreeNode) => void> { }
export interface BookmarkChildrenReordered
extends chrome.events.Event<(id: string, reorderInfo: BookmarkReorderInfo) => void> { }
export interface BookmarkSearchQuery {
query?: string | undefined;
url?: string | undefined;
title?: string | undefined;
}
export interface BookmarkCreateArg {
/** Optional. Defaults to the Other Bookmarks folder. */
parentId?: string | undefined;
index?: number | undefined;
title?: string | undefined;
url?: string | undefined;
}
export interface BookmarkDestinationArg {
parentId?: string | undefined;
index?: number | undefined;
}
export interface BookmarkChangesArg {
title?: string | undefined;
url?: string | undefined;
}
/** @deprecated since Chrome 38. Bookmark write operations are no longer limited by Chrome. */
export var MAX_WRITE_OPERATIONS_PER_HOUR: number;
/** @deprecated since Chrome 38. Bookmark write operations are no longer limited by Chrome. */
export var MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE: number;
/**
* Searches for BookmarkTreeNodes matching the given query. Queries specified with an object produce BookmarkTreeNodes matching all specified properties.
* @param query A string of words and quoted phrases that are matched against bookmark URLs and titles.
*/
export function search(query: string, callback: (results: BookmarkTreeNode[]) => void): void;
/**
* Searches for BookmarkTreeNodes matching the given query. Queries specified with an object produce BookmarkTreeNodes matching all specified properties.
* @param query A string of words and quoted phrases that are matched against bookmark URLs and titles.
* @return The `search` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function search(query: string): Promise<BookmarkTreeNode[]>;
/**
* Searches for BookmarkTreeNodes matching the given query. Queries specified with an object produce BookmarkTreeNodes matching all specified properties.
* @param query An object with one or more of the properties query, url, and title specified. Bookmarks matching all specified properties will be produced.
*/
export function search(query: BookmarkSearchQuery, callback: (results: BookmarkTreeNode[]) => void): void;
/**
* Searches for BookmarkTreeNodes matching the given query. Queries specified with an object produce BookmarkTreeNodes matching all specified properties.
* @param query An object with one or more of the properties query, url, and title specified. Bookmarks matching all specified properties will be produced.
* @return The `search` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function search(query: BookmarkSearchQuery): Promise<BookmarkTreeNode[]>;
/**
* Retrieves the entire Bookmarks hierarchy.
*/
export function getTree(callback: (results: BookmarkTreeNode[]) => void): void;
/**
* Retrieves the entire Bookmarks hierarchy.
* @return The `getTree` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function getTree(): Promise<BookmarkTreeNode[]>;
/**
* Retrieves the recently added bookmarks.
* @param numberOfItems The maximum number of items to return.
*/
export function getRecent(numberOfItems: number, callback: (results: BookmarkTreeNode[]) => void): void;
/**
* Retrieves the recently added bookmarks.
* @param numberOfItems The maximum number of items to return.
* @return The `getRecent` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function getRecent(numberOfItems: number): Promise<BookmarkTreeNode[]>;
/**
* Retrieves the specified BookmarkTreeNode.
* @param id A single string-valued id
*/
export function get(id: string, callback: (results: BookmarkTreeNode[]) => void): void;
/**
* Retrieves the specified BookmarkTreeNode.
* @param id A single string-valued id
* @return The `get` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function get(id: string): Promise<BookmarkTreeNode[]>;
/**
* Retrieves the specified BookmarkTreeNode.
* @param idList An array of string-valued ids
*/
export function get(idList: string[], callback: (results: BookmarkTreeNode[]) => void): void;
/**
* Retrieves the specified BookmarkTreeNode.
* @param idList An array of string-valued ids
* @return The `get` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function get(idList: string[]): Promise<BookmarkTreeNode[]>;
/**
* Creates a bookmark or folder under the specified parentId. If url is NULL or missing, it will be a folder.
* @return The `create` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function create(bookmark: BookmarkCreateArg): Promise<BookmarkTreeNode>;
/**
* Creates a bookmark or folder under the specified parentId. If url is NULL or missing, it will be a folder.
*/
export function create(bookmark: BookmarkCreateArg, callback: (result: BookmarkTreeNode) => void): void;
/**
* Moves the specified BookmarkTreeNode to the provided location.
* @return The `move` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function move(
id: string,
destination: BookmarkDestinationArg,
): Promise<BookmarkTreeNode>;
/**
* Moves the specified BookmarkTreeNode to the provided location.
*/
export function move(
id: string,
destination: BookmarkDestinationArg,
callback: (result: BookmarkTreeNode) => void,
): void;
/**
* Updates the properties of a bookmark or folder. Specify only the properties that you want to change; unspecified properties will be left unchanged. Note: Currently, only 'title' and 'url' are supported.
* @return The `update` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function update(
id: string,
changes: BookmarkChangesArg,
): Promise<BookmarkTreeNode>;
/**
* Updates the properties of a bookmark or folder. Specify only the properties that you want to change; unspecified properties will be left unchanged. Note: Currently, only 'title' and 'url' are supported.
*/
export function update(
id: string,
changes: BookmarkChangesArg,
callback: (result: BookmarkTreeNode) => void,
): void;
/**
* Removes a bookmark or an empty bookmark folder.
* @return The `remove` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
*/
export function remove(id: string): Promise<void>;
/**
* Removes a bookmark or an empty bookmark folder.
*/
export function remove(id: string, callback: Function): void;
/**
* Retrieves the children of the specified BookmarkTreeNode id.
*/
export function getChildren(id: string, callback: (results: BookmarkTreeNode[]) => void): void;
/**
* Retrieves the children of the specified BookmarkTreeNode id.
* @return The `getChildren` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function getChildren(id: string): Promise<BookmarkTreeNode[]>;
/**
* Since Chrome 14.
* Retrieves part of the Bookmarks hierarchy, starting at the specified node.
* @param id The ID of the root of the subtree to retrieve.
*/
export function getSubTree(id: string, callback: (results: BookmarkTreeNode[]) => void): void;
/**
* Since Chrome 14.
* Retrieves part of the Bookmarks hierarchy, starting at the specified node.
* @param id The ID of the root of the subtree to retrieve.
* @return The `getSubTree` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function getSubTree(id: string): Promise<BookmarkTreeNode[]>;
/**
* Recursively removes a bookmark folder.
* @return The `removeTree` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
*/
export function removeTree(id: string): Promise<void>;
/**
* Recursively removes a bookmark folder.
*/
export function removeTree(id: string, callback: Function): void;
/** Fired when a bookmark or folder is removed. When a folder is removed recursively, a single notification is fired for the folder, and none for its contents. */
export var onRemoved: BookmarkRemovedEvent;
/** Fired when a bookmark import session is ended. */
export var onImportEnded: BookmarkImportEndedEvent;
/** Fired when a bookmark import session is begun. Expensive observers should ignore onCreated updates until onImportEnded is fired. Observers should still handle other notifications immediately. */
export var onImportBegan: BookmarkImportBeganEvent;
/** Fired when a bookmark or folder changes. Note: Currently, only title and url changes trigger this. */
export var onChanged: BookmarkChangedEvent;
/** Fired when a bookmark or folder is moved to a different parent folder. */
export var onMoved: BookmarkMovedEvent;
/** Fired when a bookmark or folder is created. */
export var onCreated: BookmarkCreatedEvent;
/** Fired when the children of a folder have changed their order due to the order being sorted in the UI. This is not called as a result of a move(). */
export var onChildrenReordered: BookmarkChildrenReordered;
}
////////////////////
// Browser Action
////////////////////
/**
* Use browser actions to put icons in the main Google Chrome toolbar, to the right of the address bar. In addition to its icon, a browser action can also have a tooltip, a badge, and a popup.
* Availability: Since Chrome 5.
* Manifest: "browser_action": {...}
*/
declare namespace chrome.browserAction {
export interface BadgeBackgroundColorDetails {
/** An array of four integers in the range [0,255] that make up the RGBA color of the badge. For example, opaque red is [255, 0, 0, 255]. Can also be a string with a CSS value, with opaque red being #FF0000 or #F00. */
color: string | ColorArray;
/** Optional. Limits the change to when a particular tab is selected. Automatically resets when the tab is closed. */
tabId?: number | undefined;
}
export interface BadgeTextDetails {
/** Any number of characters can be passed, but only about four can fit in the space. */
text?: string | null | undefined;
/** Optional. Limits the change to when a particular tab is selected. Automatically resets when the tab is closed. */
tabId?: number | undefined;
}
export type ColorArray = [number, number, number, number];
export interface TitleDetails {
/** The string the browser action should display when moused over. */
title: string;
/** Optional. Limits the change to when a particular tab is selected. Automatically resets when the tab is closed. */
tabId?: number | null;
}
export interface TabDetails {
/** Optional. Specify the tab to get the information. If no tab is specified, the non-tab-specific information is returned. */
tabId?: number | null;
}
export interface TabIconDetails {
/** Optional. Either a relative image path or a dictionary {size -> relative image path} pointing to icon to be set. If the icon is specified as a dictionary, the actual image to be used is chosen depending on screen's pixel density. If the number of image pixels that fit into one screen space unit equals scale, then image with size scale * 19 will be selected. Initially only scales 1 and 2 will be supported. At least one image must be specified. Note that 'details.path = foo' is equivalent to 'details.imageData = {'19': foo}' */
path?: string | { [index: string]: string } | undefined;
/** Optional. Limits the change to when a particular tab is selected. Automatically resets when the tab is closed. */
tabId?: number | undefined;
/** Optional. Either an ImageData object or a dictionary {size -> ImageData} representing icon to be set. If the icon is specified as a dictionary, the actual image to be used is chosen depending on screen's pixel density. If the number of image pixels that fit into one screen space unit equals scale, then image with size scale * 19 will be selected. Initially only scales 1 and 2 will be supported. At least one image must be specified. Note that 'details.imageData = foo' is equivalent to 'details.imageData = {'19': foo}' */
imageData?: ImageData | { [index: number]: ImageData } | undefined;
}
export interface PopupDetails {
/** Optional. Limits the change to when a particular tab is selected. Automatically resets when the tab is closed. */
tabId?: number | null;
/** The html file to show in a popup. If set to the empty string (''), no popup is shown. */
popup: string;
}
export interface BrowserClickedEvent extends chrome.events.Event<(tab: chrome.tabs.Tab) => void> { }
/**
* Since Chrome 22.
* Enables the browser action for a tab. By default, browser actions are enabled.
* @param tabId The id of the tab for which you want to modify the browser action.
* @return The `enable` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
*/
export function enable(tabId?: number | null): Promise<void>;
/**
* Since Chrome 22.
* Enables the browser action for a tab. By default, browser actions are enabled.
* @param tabId The id of the tab for which you want to modify the browser action.
* @param callback Supported since Chrome 67
*/
export function enable(callback?: () => void): void;
export function enable(tabId: number | null | undefined, callback?: () => void): void;
/**
* Sets the background color for the badge.
* @return The `setBadgeBackgroundColor` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
*/
export function setBadgeBackgroundColor(details: BadgeBackgroundColorDetails): Promise<void>;
/**
* Sets the background color for the badge.
* @param callback Supported since Chrome 67
*/
export function setBadgeBackgroundColor(details: BadgeBackgroundColorDetails, callback?: () => void): void;
/**
* Sets the badge text for the browser action. The badge is displayed on top of the icon.
* @return The `setBadgeText` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
*/
export function setBadgeText(details: BadgeTextDetails): Promise<void>;
/**
* Sets the badge text for the browser action. The badge is displayed on top of the icon.
* @param callback Supported since Chrome 67
*/
export function setBadgeText(details: BadgeTextDetails, callback: () => void): void;
/**
* Sets the title of the browser action. This shows up in the tooltip.
* @return The `setTitle` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
*/
export function setTitle(details: TitleDetails): Promise<void>;
/**
* Sets the title of the browser action. This shows up in the tooltip.
* @param callback Supported since Chrome 67
*/
export function setTitle(details: TitleDetails, callback: () => void): void;
/**
* Since Chrome 19.
* Gets the badge text of the browser action. If no tab is specified, the non-tab-specific badge text is returned.
* @param callback Supported since Chrome 67
*/
export function getBadgeText(details: TabDetails, callback: (result: string) => void): void;
/**
* Since Chrome 19.
* Gets the badge text of the browser action. If no tab is specified, the non-tab-specific badge text is returned.
* @return The `getBadgeText` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function getBadgeText(details: TabDetails): Promise<string>;
/**
* Sets the html document to be opened as a popup when the user clicks on the browser action's icon.
* @return The `setPopup` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
*/
export function setPopup(details: PopupDetails): Promise<void>;
/**
* Sets the html document to be opened as a popup when the user clicks on the browser action's icon.
* @param callback Supported since Chrome 67
*/
export function setPopup(details: PopupDetails, callback?: () => void): void;
/**
* Since Chrome 22.
* Disables the browser action for a tab.
* @param tabId The id of the tab for which you want to modify the browser action.
* @return The `disable` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
*/
export function disable(tabId?: number | null): Promise<void>;
/**
* Since Chrome 22.
* Disables the browser action for a tab.
* @param tabId The id of the tab for which you want to modify the browser action.
* @param callback Supported since Chrome 67
*/
export function disable(callback: () => void): void;
export function disable(tabId?: number | null, callback?: () => void): void;
/**
* Since Chrome 19.
* Gets the title of the browser action.
*/
export function getTitle(details: TabDetails, callback: (result: string) => void): void;
/**
* Since Chrome 19.
* Gets the title of the browser action.
* @return The `getTitle` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function getTitle(details: TabDetails): Promise<string>;
/**
* Since Chrome 19.
* Gets the background color of the browser action.
*/
export function getBadgeBackgroundColor(details: TabDetails, callback: (result: ColorArray) => void): void;
/**
* Since Chrome 19.
* Gets the background color of the browser action.
* @return The `getBadgeBackgroundColor` method provides its result via callback or returned as a `Promise` (MV3 only).
*/
export function getBadgeBackgroundColor(details: TabDetails): Promise<ColorArray>;
/**
* Since Chrome 19.
* Gets the html document set as the popup for this browser action.
*/
export functi