Skip to content

Commit 8f957ab

Browse files
authored
🤖 Merge PR DefinitelyTyped#73504 [chrome] update devtools.panels namespace by @erwanjugand
1 parent 55272d0 commit 8f957ab

File tree

2 files changed

+77
-74
lines changed

2 files changed

+77
-74
lines changed

‎types/chrome/index.d.ts‎

Lines changed: 40 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,12 +2832,6 @@ declare namespace chrome {
28322832
* Manifest: "devtools_page"
28332833
*/
28342834
export namespace devtools.panels {
2835-
export interface PanelShownEvent extends chrome.events.Event<(window: Window) => void> {}
2836-
2837-
export interface PanelHiddenEvent extends chrome.events.Event<() => void> {}
2838-
2839-
export interface PanelSearchEvent extends chrome.events.Event<(action: string, queryString?: string) => void> {}
2840-
28412835
/** Represents a panel created by an extension. */
28422836
export interface ExtensionPanel {
28432837
/**
@@ -2848,15 +2842,13 @@ declare namespace chrome {
28482842
*/
28492843
createStatusBarButton(iconPath: string, tooltipText: string, disabled: boolean): Button;
28502844
/** Fired when the user switches to the panel. */
2851-
onShown: PanelShownEvent;
2845+
onShown: events.Event<(window: Window) => void>;
28522846
/** Fired when the user switches away from the panel. */
2853-
onHidden: PanelHiddenEvent;
2847+
onHidden: events.Event<() => void>;
28542848
/** Fired upon a search action (start of a new search, search result navigation, or search being canceled). */
2855-
onSearch: PanelSearchEvent;
2849+
onSearch: events.Event<(action: string, queryString?: string) => void>;
28562850
}
28572851

2858-
export interface ButtonClickedEvent extends chrome.events.Event<() => void> {}
2859-
28602852
/** A button created by the extension. */
28612853
export interface Button {
28622854
/**
@@ -2867,38 +2859,31 @@ declare namespace chrome {
28672859
*/
28682860
update(iconPath?: string | null, tooltipText?: string | null, disabled?: boolean | null): void;
28692861
/** Fired when the button is clicked. */
2870-
onClicked: ButtonClickedEvent;
2862+
onClicked: events.Event<() => void>;
28712863
}
28722864

2873-
export interface SelectionChangedEvent extends chrome.events.Event<() => void> {}
2874-
28752865
/** Represents the Elements panel. */
28762866
export interface ElementsPanel {
28772867
/**
28782868
* Creates a pane within panel's sidebar.
28792869
* @param title Text that is displayed in sidebar caption.
2880-
* @param callback A callback invoked when the sidebar is created.
28812870
*/
28822871
createSidebarPane(
28832872
title: string,
28842873
callback?: (
2885-
/** An ExtensionSidebarPane object for created sidebar pane */
2874+
/** An ExtensionSidebarPane object for created sidebar pane. */
28862875
result: ExtensionSidebarPane,
28872876
) => void,
28882877
): void;
28892878
/** Fired when an object is selected in the panel. */
2890-
onSelectionChanged: SelectionChangedEvent;
2879+
onSelectionChanged: events.Event<() => void>;
28912880
}
28922881

2893-
/**
2894-
* @since Chrome 41
2895-
* Represents the Sources panel.
2896-
*/
2882+
/** Represents the Sources panel. */
28972883
export interface SourcesPanel {
28982884
/**
28992885
* Creates a pane within panel's sidebar.
29002886
* @param title Text that is displayed in sidebar caption.
2901-
* @param callback A callback invoked when the sidebar is created.
29022887
*/
29032888
createSidebarPane(
29042889
title: string,
@@ -2908,115 +2893,96 @@ declare namespace chrome {
29082893
) => void,
29092894
): void;
29102895
/** Fired when an object is selected in the panel. */
2911-
onSelectionChanged: SelectionChangedEvent;
2896+
onSelectionChanged: events.Event<() => void>;
29122897
}
29132898

2914-
export interface ExtensionSidebarPaneShownEvent extends chrome.events.Event<(window: Window) => void> {}
2915-
2916-
export interface ExtensionSidebarPaneHiddenEvent extends chrome.events.Event<() => void> {}
2917-
29182899
/** A sidebar created by the extension. */
29192900
export interface ExtensionSidebarPane {
29202901
/**
29212902
* Sets the height of the sidebar.
2922-
* @param height A CSS-like size specification, such as '100px' or '12ex'.
2903+
* @param height A CSS-like size specification, such as `100px` or `12ex`.
29232904
*/
29242905
setHeight(height: string): void;
29252906
/**
29262907
* Sets an expression that is evaluated within the inspected page. The result is displayed in the sidebar pane.
29272908
* @param expression An expression to be evaluated in context of the inspected page. JavaScript objects and DOM nodes are displayed in an expandable tree similar to the console/watch.
29282909
* @param rootTitle An optional title for the root of the expression tree.
2929-
* @param callback A callback invoked after the sidebar pane is updated with the expression evaluation results.
2930-
*/
2931-
setExpression(expression: string, rootTitle?: string, callback?: () => void): void;
2932-
/**
2933-
* Sets an expression that is evaluated within the inspected page. The result is displayed in the sidebar pane.
2934-
* @param expression An expression to be evaluated in context of the inspected page. JavaScript objects and DOM nodes are displayed in an expandable tree similar to the console/watch.
2935-
* @param callback A callback invoked after the sidebar pane is updated with the expression evaluation results.
29362910
*/
29372911
setExpression(expression: string, callback?: () => void): void;
2912+
setExpression(expression: string, rootTitle: string | undefined, callback?: () => void): void;
29382913
/**
29392914
* Sets a JSON-compliant object to be displayed in the sidebar pane.
29402915
* @param jsonObject An object to be displayed in context of the inspected page. Evaluated in the context of the caller (API client).
29412916
* @param rootTitle An optional title for the root of the expression tree.
2942-
* @param callback A callback invoked after the sidebar is updated with the object.
2943-
*/
2944-
setObject(jsonObject: { [key: string]: unknown }, rootTitle?: string, callback?: () => void): void;
2945-
/**
2946-
* Sets a JSON-compliant object to be displayed in the sidebar pane.
2947-
* @param jsonObject An object to be displayed in context of the inspected page. Evaluated in the context of the caller (API client).
2948-
* @param callback A callback invoked after the sidebar is updated with the object.
29492917
*/
29502918
setObject(jsonObject: { [key: string]: unknown }, callback?: () => void): void;
2919+
setObject(
2920+
jsonObject: { [key: string]: unknown },
2921+
rootTitle: string | undefined,
2922+
callback?: () => void,
2923+
): void;
29512924
/**
29522925
* Sets an HTML page to be displayed in the sidebar pane.
29532926
* @param path Relative path of an extension page to display within the sidebar.
29542927
*/
29552928
setPage(path: string): void;
29562929
/** Fired when the sidebar pane becomes visible as a result of user switching to the panel that hosts it. */
2957-
onShown: ExtensionSidebarPaneShownEvent;
2930+
onShown: events.Event<(window: Window) => void>;
29582931
/** Fired when the sidebar pane becomes hidden as a result of the user switching away from the panel that hosts the sidebar pane. */
2959-
onHidden: ExtensionSidebarPaneHiddenEvent;
2932+
onHidden: events.Event<() => void>;
29602933
}
29612934

29622935
/** Elements panel. */
2963-
export var elements: ElementsPanel;
2964-
/**
2965-
* @since Chrome 38
2966-
* Sources panel.
2967-
*/
2968-
export var sources: SourcesPanel;
2936+
export const elements: ElementsPanel;
2937+
2938+
/** Sources panel. */
2939+
export const sources: SourcesPanel;
29692940

29702941
/**
29712942
* Creates an extension panel.
29722943
* @param title Title that is displayed next to the extension icon in the Developer Tools toolbar.
29732944
* @param iconPath Path of the panel's icon relative to the extension directory.
29742945
* @param pagePath Path of the panel's HTML page relative to the extension directory.
2975-
* @param callback A function that is called when the panel is created.
2976-
* Parameter panel: An ExtensionPanel object representing the created panel.
29772946
*/
29782947
export function create(
29792948
title: string,
29802949
iconPath: string,
29812950
pagePath: string,
2982-
callback?: (panel: ExtensionPanel) => void,
2951+
callback?: (
2952+
/** An ExtensionPanel object representing the created panel. */
2953+
panel: ExtensionPanel,
2954+
) => void,
29832955
): void;
2984-
/**
2985-
* Specifies the function to be called when the user clicks a resource link in the Developer Tools window. To unset the handler, either call the method with no parameters or pass null as the parameter.
2986-
* @param callback A function that is called when the user clicks on a valid resource link in Developer Tools window. Note that if the user clicks an invalid URL or an XHR, this function is not called.
2987-
* Parameter resource: A devtools.inspectedWindow.Resource object for the resource that was clicked.
2988-
* Parameter lineNumber: Specifies the line number within the resource that was clicked.
2989-
*/
2956+
2957+
/** Specifies the function to be called when the user clicks a resource link in the Developer Tools window. To unset the handler, either call the method with no parameters or pass null as the parameter. */
29902958
export function setOpenResourceHandler(
2991-
callback?: (resource: chrome.devtools.inspectedWindow.Resource, lineNumber: number) => void,
2959+
callback?: (
2960+
/** A {@link devtools.inspectedWindow.Resource} object for the resource that was clicked. */
2961+
resource: chrome.devtools.inspectedWindow.Resource,
2962+
/** Specifies the line number within the resource that was clicked. */
2963+
lineNumber: number,
2964+
) => void,
29922965
): void;
2966+
29932967
/**
2994-
* @since Chrome 38
2995-
* Requests DevTools to open a URL in a Developer Tools panel.
2996-
* @param url The URL of the resource to open.
2997-
* @param lineNumber Specifies the line number to scroll to when the resource is loaded.
2998-
* @param callback A function that is called when the resource has been successfully loaded.
2999-
*/
3000-
export function openResource(url: string, lineNumber: number, callback?: () => void): void;
3001-
/**
3002-
* @since Chrome 96
30032968
* Requests DevTools to open a URL in a Developer Tools panel.
30042969
* @param url The URL of the resource to open.
30052970
* @param lineNumber Specifies the line number to scroll to when the resource is loaded.
30062971
* @param columnNumber Specifies the column number to scroll to when the resource is loaded.
3007-
* @param callback A function that is called when the resource has been successfully loaded.
30082972
*/
2973+
export function openResource(url: string, lineNumber: number, callback?: () => void): void;
30092974
export function openResource(
30102975
url: string,
30112976
lineNumber: number,
3012-
columnNumber: number,
3013-
callback?: (response: unknown) => unknown,
2977+
columnNumber: number | undefined,
2978+
callback?: () => void,
30142979
): void;
2980+
30152981
/**
3016-
* @since Chrome 59
30172982
* The name of the color theme set in user's DevTools settings.
2983+
* @since Chrome 59
30182984
*/
3019-
export var themeName: "default" | "dark";
2985+
export const themeName: "default" | "dark";
30202986
}
30212987

30222988
////////////////////

‎types/chrome/test/index.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,44 @@ function testDevtools() {
13471347
};
13481348
chrome.devtools.recorder.registerRecorderExtensionPlugin({}, "MyPlugin", "application/json"); // $ExpectType void
13491349
chrome.devtools.recorder.registerRecorderExtensionPlugin(plugin, "MyPlugin", "application/json"); // $ExpectType void
1350+
}
1351+
1352+
function testDevtoolsPanels() {
1353+
const title = "title";
1354+
const iconPath = "iconPath";
1355+
const pagePath = "pagePath";
1356+
1357+
chrome.devtools.panels.elements; // $ExpectType ElementsPanel
1358+
chrome.devtools.panels.elements.createSidebarPane(title); // $ExpectType void
1359+
chrome.devtools.panels.elements.createSidebarPane(title, result => { // $ExpectType void
1360+
result; // $ExpectType ExtensionSidebarPane
1361+
});
1362+
checkChromeEvent(chrome.devtools.panels.elements.onSelectionChanged, () => void 0);
1363+
1364+
chrome.devtools.panels.sources; // $ExpectType SourcesPanel
1365+
chrome.devtools.panels.sources.createSidebarPane(title); // $ExpectType void
1366+
chrome.devtools.panels.sources.createSidebarPane(title, result => { // $ExpectType void
1367+
result; // $ExpectType ExtensionSidebarPane
1368+
});
1369+
checkChromeEvent(chrome.devtools.panels.sources.onSelectionChanged, () => void 0);
1370+
1371+
chrome.devtools.panels.themeName; // $ExpectType "default" | "dark"
1372+
1373+
chrome.devtools.panels.create(title, iconPath, pagePath); // $ExpectType void
1374+
chrome.devtools.panels.create(title, iconPath, pagePath, panel => { // $ExpectType void
1375+
panel; // $ExpectType ExtensionPanel
1376+
});
1377+
1378+
const url = "url";
1379+
const lineNumber = 10;
1380+
const columnNumber = 10;
1381+
1382+
chrome.devtools.panels.openResource(url, lineNumber); // $ExpectType void
1383+
chrome.devtools.panels.openResource(url, lineNumber, columnNumber); // $ExpectType void
1384+
chrome.devtools.panels.openResource(url, lineNumber, columnNumber, () => void 0); // $ExpectType void
1385+
chrome.devtools.panels.openResource(url, lineNumber, () => void 0); // $ExpectType void
13501386

1387+
chrome.devtools.panels.setOpenResourceHandler(); // $ExpectType void
13511388
chrome.devtools.panels.setOpenResourceHandler((resource, lineNumber) => { // $ExpectType void
13521389
resource; // $ExpectType Resource
13531390
lineNumber; // $ExpectType number

0 commit comments

Comments
 (0)