You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* A flag indicating the state of a checkbox or radio item before it was clicked.
1914
-
*/
1915
-
wasChecked?: boolean | undefined;
1916
-
/**
1917
-
* @since Chrome 35
1918
-
* The URL of the page where the menu item was clicked. This property is not set if the click occurred in a context where there is no current page, such as in a launcher context menu.
1919
-
*/
1920
-
pageUrl: string;
1921
-
/**
1922
-
* Optional.
1923
-
* @since Chrome 35
1924
-
* If the element is a link, the URL it points to.
1925
-
*/
1926
-
linkUrl?: string | undefined;
1927
-
/**
1928
-
* Optional.
1929
-
* @since Chrome 35
1930
-
* The parent ID, if any, for the item clicked.
1931
-
*/
1932
-
parentMenuItemId?: number | string;
1933
-
/**
1934
-
* Optional.
1935
-
* @since Chrome 35
1936
-
* Will be present for elements with a 'src' URL.
1937
-
*/
1938
-
srcUrl?: string | undefined;
1868
+
/**
1869
+
* The different contexts a menu can appear in. Specifying 'all' is equivalent to the combination of all other contexts except for 'launcher'. The 'launcher' context is only supported by apps and is used to add menu items to the context menu that appears when clicking the app icon in the launcher/taskbar/dock/etc. Different platforms might put limitations on what is actually supported in a launcher context menu.
1870
+
* @since Chrome 44
1871
+
*/
1872
+
export enum ContextType {
1873
+
ALL = "all",
1874
+
PAGE = "page",
1875
+
FRAME = "frame",
1876
+
SELECTION = "selection",
1877
+
LINK = "link",
1878
+
EDITABLE = "editable",
1879
+
IMAGE = "image",
1880
+
VIDEO = "video",
1881
+
AUDIO = "audio",
1882
+
LAUNCHER = "launcher",
1883
+
BROWSER_ACTION = "browser_action",
1884
+
PAGE_ACTION = "page_action",
1885
+
ACTION = "action",
1939
1886
}
1940
1887
1941
-
type ContextType =
1942
-
| "all"
1943
-
| "page"
1944
-
| "frame"
1945
-
| "selection"
1946
-
| "link"
1947
-
| "editable"
1948
-
| "image"
1949
-
| "video"
1950
-
| "audio"
1951
-
| "launcher"
1952
-
| "browser_action"
1953
-
| "page_action"
1954
-
| "action";
1955
-
1956
-
type ContextItemType = "normal" | "checkbox" | "radio" | "separator";
1957
-
1888
+
/**
1889
+
* Properties of the new context menu item.
1890
+
* @since Chrome 123
1891
+
*/
1958
1892
export interface CreateProperties {
1959
-
/** Optional. Lets you restrict the item to apply only to documents whose URL matches one of the given patterns. (This applies to frames as well.) For details on the format of a pattern, see Match Patterns. */
1960
-
documentUrlPatterns?: string[] | undefined;
1961
-
/** Optional. The initial state of a checkbox or radio item: true for selected and false for unselected. Only one radio item can be selected at a time in a given group of radio items. */
1962
-
checked?: boolean | undefined;
1963
-
/** Optional. The text to be displayed in the item; this is required unless type is 'separator'. When the context is 'selection', you can use %s within the string to show the selected text. For example, if this parameter's value is "Translate '%s' to Pig Latin" and the user selects the word "cool", the context menu item for the selection is "Translate 'cool' to Pig Latin". */
1964
-
title?: string | undefined;
1965
-
/** Optional. List of contexts this menu item will appear in. Defaults to ['page'] if not specified. */
* Whether this context menu item is enabled or disabled. Defaults to true.
1971
-
*/
1972
-
enabled?: boolean | undefined;
1973
-
/** Optional. Similar to documentUrlPatterns, but lets you filter based on the src attribute of img/audio/video tags and the href of anchor tags. */
1974
-
targetUrlPatterns?: string[] | undefined;
1975
-
/**
1976
-
* Optional.
1977
-
* A function that will be called back when the menu item is clicked. Event pages cannot use this; instead, they should register a listener for chrome.contextMenus.onClicked.
1978
-
* @param info Information sent when a context menu item is clicked.
1979
-
* @param tab The details of the tab where the click took place. Note: this parameter only present for extensions.
/** Optional. The ID of a parent menu item; this makes the item a child of a previously added item. */
1983
-
parentId?: number | string | undefined;
1984
-
/** Optional. The type of menu item. Defaults to 'normal' if not specified. */
1985
-
type?: ContextItemType | undefined;
1986
-
/**
1987
-
* Optional.
1988
-
* @since Chrome 21
1989
-
* The unique ID to assign to this item. Mandatory for event pages. Cannot be the same as another ID for this extension.
1990
-
*/
1991
-
id?: string | undefined;
1893
+
/** The initial state of a checkbox or radio button: `true` for selected, `false` for unselected. Only one radio button can be selected at a time in a given group. */
1894
+
checked?: boolean;
1895
+
/** List of contexts this menu item will appear in. Defaults to `['page']`. */
/** Restricts the item to apply only to documents or frames whose URL matches one of the given patterns. For details on pattern formats, see Match Patterns. */
1898
+
documentUrlPatterns?: string[];
1899
+
/** Whether this context menu item is enabled or disabled. Defaults to `true`. */
1900
+
enabled?: boolean;
1901
+
/** The unique ID to assign to this item. Mandatory for event pages. Cannot be the same as another ID for this extension. */
1902
+
id?: string;
1903
+
/** The ID of a parent menu item; this makes the item a child of a previously added item. */
1904
+
parentId?: number | string;
1905
+
/** Similar to `documentUrlPatterns`, filters based on the `src` attribute of `img`, `audio`, and `video` tags and the `href` attribute of `a` tags. */
1906
+
targetUrlPatterns?: string[];
1907
+
/** The text to display in the item; this is _required_ unless `type` is `separator`. When the context is `selection`, use `%s` within the string to show the selected text. For example, if this parameter's value is "Translate '%s' to Pig Latin" and the user selects the word "cool", the context menu item for the selection is "Translate 'cool' to Pig Latin". */
1908
+
title?: string;
1909
+
/** The type of menu item. Defaults to `normal`. */
1910
+
type?: `${ItemType}`;
1911
+
/** Whether the item is visible in the menu. */
1912
+
visible?: boolean;
1992
1913
/**
1993
-
* Optional.
1994
-
* @since Chrome 62
1995
-
* Whether the item is visible in the menu.
1914
+
* A function that is called back when the menu item is clicked. This is not available inside of a service worker; instead, you should register a listener for {@link contextMenus.onClicked}.
1915
+
* @param info Information about the item clicked and the context where the click happened.
1916
+
* @param tab The details of the tab where the click took place. This parameter is not present for platform apps.
/** The URL of the page where the menu item was clicked. This property is not set if the click occurred in a context where there is no current page, such as in a launcher context menu. */
1955
+
pageUrl?: string;
1956
+
/** The parent ID, if any, for the item clicked.*/
1957
+
parentMenuItemId?: number | string;
1958
+
/** The text for the context selection, if any. */
1959
+
selectionText?: string | undefined;
1960
+
/** Will be present for elements with a 'src' URL. */
1961
+
srcUrl?: string | undefined;
1962
+
/** A flag indicating the state of a checkbox or radio item before it was clicked. */
1963
+
wasChecked?: boolean | undefined;
1964
+
}
1965
+
1966
+
/** The maximum number of top level extension items that can be added to an extension action context menu. Any items beyond this limit will be ignored. */
1967
+
export const ACTION_MENU_TOP_LEVEL_LIMIT: 6;
2011
1968
2012
1969
/**
2013
-
* Removes all context menu items added by this extension.
2014
-
* @since Chrome 123
2015
-
*/
2016
-
export function removeAll(): Promise<void>;
2017
-
/**
2018
-
* Removes all context menu items added by this extension.
2019
-
* @param callback Called when removal is complete.
2020
-
*/
2021
-
export function removeAll(callback: () => void): void;
2022
-
/**
2023
-
* Creates a new context menu item. Note that if an error occurs during creation, you may not find out until the creation callback fires (the details will be in chrome.runtime.lastError).
2024
-
* @param callback Called when the item has been created in the browser. If there were any problems creating the item, details will be available in chrome.runtime.lastError.
1970
+
* Creates a new context menu item. If an error occurs during creation, it may not be detected until the creation callback fires; details will be in {@link chrome.runtime.lastError}.
2025
1971
* @return The ID of the newly created item.
2026
1972
*/
2027
1973
export function create(createProperties: CreateProperties, callback?: () => void): number | string;
2028
-
/**
2029
-
* Updates a previously created context menu item.
2030
-
* @param id The ID of the item to update.
2031
-
* @param updateProperties The properties to update. Accepts the same values as the create function.
2032
-
* @since Chrome 123
2033
-
*/
2034
-
export function update(id: string | number, updateProperties: UpdateProperties): Promise<void>;
2035
-
/**
2036
-
* Updates a previously created context menu item.
2037
-
* @param id The ID of the item to update.
2038
-
* @param updateProperties The properties to update. Accepts the same values as the create function.
2039
-
* @param callback Called when the context menu has been updated.
0 commit comments