blob: 1c4b50b8ce7a2e43dc8c074c31b06bac3faf9c8e [file] [log] [blame]
Philip Pfaffe5df66262021-07-19 16:55:50 +02001// Copyright 2021 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5export namespace Chrome {
6 export namespace DevTools {
Tim van der Lippe269e9ae2021-12-14 14:33:28 +01007 export interface EventSink<ListenerT extends(...args: any) => void> {
Philip Pfaffe5df66262021-07-19 16:55:50 +02008 addListener(listener: ListenerT): void;
9 }
10
11 export interface Resource {
Philip Pfaffe11e43682021-07-29 13:14:42 +020012 readonly url: string;
Philip Pfaffe5df66262021-07-19 16:55:50 +020013
14 getContent(callback: (content: string, encoding: string) => unknown): void;
15 setContent(content: string, commit: boolean, callback?: (error?: Object) => unknown): void;
16 }
17
18 export interface InspectedWindow {
19 tabId: number;
20
21 onResourceAdded: EventSink<(resource: Resource) => unknown>;
22 onResourceContentCommitted: EventSink<(resource: Resource, content: string) => unknown>;
23
24 eval(
25 expression: string,
26 options?: {contextSecurityOrigin?: string, frameURL?: string, useContentScriptContext?: boolean},
27 callback?: (result: unknown, exceptioninfo: {
28 code: string,
29 description: string,
30 details: unknown[],
31 isError: boolean,
32 isException: boolean,
33 value: string
34 }) => unknown): void;
35 getResources(callback: (resources: Resource[]) => unknown): void;
36 reload(reloadOptions?: {ignoreCache?: boolean, injectedScript?: string, userAgent?: string}): void;
37 }
38
39 export interface Button {
40 onClicked: EventSink<() => unknown>;
41 update(iconPath?: string, tooltipText?: string, disabled?: boolean): void;
42 }
43
44 export interface ExtensionView {
45 onHidden: EventSink<() => unknown>;
46 onShown: EventSink<(window?: Window) => unknown>;
47 }
48
49 export interface ExtensionPanel extends ExtensionView {
50 onSearch: EventSink<(action: string, queryString?: string) => unknown>;
51 createStatusBarButton(iconPath: string, tooltipText: string, disabled: boolean): Button;
52 }
53
54 export interface ExtensionSidebarPane extends ExtensionView {
55 setHeight(height: string): void;
56 setObject(jsonObject: string, rootTitle?: string, callback?: () => unknown): void;
57 setPage(path: string): void;
58 }
59
60 export interface PanelWithSidebar {
61 createSidebarPane(title: string, callback?: (result: ExtensionSidebarPane) => unknown): void;
62 onSelectionChanged: EventSink<() => unknown>;
63 }
64
65 export interface Panels {
66 elements: PanelWithSidebar;
67 sources: PanelWithSidebar;
68 themeName: string;
69
70 create(title: string, iconPath: string, pagePath: string, callback?: (panel: ExtensionPanel) => unknown): void;
Philip Pfaffe140e5432021-09-13 18:34:23 +020071 openResource(url: string, lineNumber: number, columnNumber?: number, callback?: () => unknown): void;
Paul Lewisada689f2022-01-11 12:03:40 +000072
73 /**
74 * Fired when the theme changes in DevTools.
75 *
76 * @param callback The handler callback to register and be invoked on theme changes.
77 */
78 setThemeChangeHandler(callback?: (themeName: string) => unknown): void;
Philip Pfaffe5df66262021-07-19 16:55:50 +020079 }
80
81 export interface Request {
82 getContent(callback: (content: string, encoding: string) => unknown): void;
83 }
84
85 export interface Network {
86 onNavigated: EventSink<(url: string) => unknown>;
87 onRequestFinished: EventSink<(request: Request) => unknown>;
88
89 getHAR(callback: (harLog: object) => unknown): void;
90 }
91
92 export interface DevToolsAPI {
93 network: Network;
94 panels: Panels;
95 inspectedWindow: InspectedWindow;
96 languageServices: LanguageExtensions;
97 }
98
99 export interface ExperimentalDevToolsAPI {
100 inspectedWindow: InspectedWindow;
101 }
102
103 export interface RawModule {
104 url: string;
105 code?: ArrayBuffer;
106 }
107
108 export interface RawLocationRange {
109 rawModuleId: string;
110 startOffset: number;
111 endOffset: number;
112 }
113
114 export interface RawLocation {
115 rawModuleId: string;
116 codeOffset: number;
117 inlineFrameIndex: number;
118 }
119
120 export interface SourceLocation {
121 rawModuleId: string;
122 sourceFileURL: string;
123 lineNumber: number;
124 columnNumber: number;
125 }
126
127 export interface Variable {
128 scope: string;
129 name: string;
130 type: string;
131 nestedName?: string[];
132 }
133
134 export interface ScopeInfo {
135 type: string;
136 typeName: string;
137 icon?: string;
138 }
139
140 export interface FunctionInfo {
141 name: string;
142 }
143
Philip Pfaffe1e2a3712021-07-22 14:23:01 +0200144 export type Enumerator = {
145 name: string,
146 value: unknown,
147 typeId: unknown,
148 };
149
Philip Pfaffe5df66262021-07-19 16:55:50 +0200150 export interface FieldInfo {
151 name?: string;
152 offset: number;
153 typeId: unknown;
154 }
155
156 export interface TypeInfo {
157 typeNames: string[];
158 typeId: unknown;
159 members: FieldInfo[];
Philip Pfaffe1e2a3712021-07-22 14:23:01 +0200160 enumerators?: Enumerator[];
Philip Pfaffe5df66262021-07-19 16:55:50 +0200161 alignment: number;
162 arraySize: number;
163 size: number;
164 canExpand: boolean;
165 hasValue: boolean;
166 }
167
168 export interface EvalBase {
169 rootType: TypeInfo;
170 payload: unknown;
171 }
172
173 export interface LanguageExtensionPlugin {
174 /**
175 * A new raw module has been loaded. If the raw wasm module references an external debug info module, its URL will be
176 * passed as symbolsURL.
177 */
178 addRawModule(rawModuleId: string, symbolsURL: string|undefined, rawModule: RawModule): Promise<string[]>;
179
180 /**
181 * Find locations in raw modules from a location in a source file.
182 */
183 sourceLocationToRawLocation(sourceLocation: SourceLocation): Promise<RawLocationRange[]>;
184
185 /**
186 * Find locations in source files from a location in a raw module.
187 */
188 rawLocationToSourceLocation(rawLocation: RawLocation): Promise<SourceLocation[]>;
189
190 /**
191 * Return detailed information about a scope.
192 */
193 getScopeInfo(type: string): Promise<ScopeInfo>;
194
195 /**
196 * List all variables in lexical scope at a given location in a raw module.
197 */
198 listVariablesInScope(rawLocation: RawLocation): Promise<Variable[]>;
199
200 /**
201 * Notifies the plugin that a script is removed.
202 */
203 removeRawModule(rawModuleId: string): Promise<void>;
204
205 /**
206 * Return type information for an expression. The result describes the type (and recursively its member types) of the
207 * result of the expression if it were evaluated in the given context.
208 */
209 getTypeInfo(expression: string, context: RawLocation): Promise<{
210 typeInfos: Array<TypeInfo>,
211 base: EvalBase,
212 }|null>;
213
214 /**
215 * Returns a piece of JavaScript code that, if evaluated, produces a representation of the given expression or field.
216 */
217 getFormatter(
218 expressionOrField: string|{
219 base: EvalBase,
220 field: Array<FieldInfo>,
221 },
222 context: RawLocation): Promise<{
223 js: string,
224 }|null>;
225
226 /**
227 * Returns a piece of JavaScript code that, if evaluated, produces the address of the given field in the wasm memory.
228 */
229 getInspectableAddress(field: {
230 base: EvalBase,
231 field: Array<FieldInfo>,
232 }): Promise<{
233 js: string,
234 }>;
235
236 /**
237 * Find locations in source files from a location in a raw module
238 */
239 getFunctionInfo(rawLocation: RawLocation): Promise<{
240 frames: Array<FunctionInfo>,
241 }>;
242
243 /**
244 * Find locations in raw modules corresponding to the inline function
245 * that rawLocation is in. Used for stepping out of an inline function.
246 */
247 getInlinedFunctionRanges(rawLocation: RawLocation): Promise<RawLocationRange[]>;
248
249 /**
250 * Find locations in raw modules corresponding to inline functions
251 * called by the function or inline frame that rawLocation is in.
252 * Used for stepping over inline functions.
253 */
254 getInlinedCalleesRanges(rawLocation: RawLocation): Promise<RawLocationRange[]>;
255
256 /**
257 * Retrieve a list of line numbers in a file for which line-to-raw-location mappings exist.
258 */
259 getMappedLines(rawModuleId: string, sourceFileURL: string): Promise<number[]|undefined>;
260 }
261
262
263 export interface SupportedScriptTypes {
264 language: string;
265 symbol_types: string[];
266 }
267
268 export interface LanguageExtensions {
269 registerLanguageExtensionPlugin(
270 plugin: LanguageExtensionPlugin, pluginName: string,
271 supportedScriptTypes: SupportedScriptTypes): Promise<void>;
272 unregisterLanguageExtensionPlugin(plugin: LanguageExtensionPlugin): Promise<void>;
273 }
274
275 export interface Chrome {
276 devtools: DevToolsAPI;
277 experimental: {devtools: ExperimentalDevToolsAPI};
278 }
279 }
280}
281
282declare global {
283 interface Window {
284 chrome: Chrome.DevTools.Chrome;
285 }
286}