blob: 409d841c3cf7b4f73749c87ffa508ab1722b4309 [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 {
7 export interface EventSink<ListenerT extends(...args: any) => any> {
8 addListener(listener: ListenerT): void;
9 }
10
11 export interface Resource {
12 get url(): string;
13
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;
71 openResource(url: string, lineNumber: number, callback?: () => unknown): void;
72 }
73
74 export interface Request {
75 getContent(callback: (content: string, encoding: string) => unknown): void;
76 }
77
78 export interface Network {
79 onNavigated: EventSink<(url: string) => unknown>;
80 onRequestFinished: EventSink<(request: Request) => unknown>;
81
82 getHAR(callback: (harLog: object) => unknown): void;
83 }
84
85 export interface DevToolsAPI {
86 network: Network;
87 panels: Panels;
88 inspectedWindow: InspectedWindow;
89 languageServices: LanguageExtensions;
90 }
91
92 export interface ExperimentalDevToolsAPI {
93 inspectedWindow: InspectedWindow;
94 }
95
96 export interface RawModule {
97 url: string;
98 code?: ArrayBuffer;
99 }
100
101 export interface RawLocationRange {
102 rawModuleId: string;
103 startOffset: number;
104 endOffset: number;
105 }
106
107 export interface RawLocation {
108 rawModuleId: string;
109 codeOffset: number;
110 inlineFrameIndex: number;
111 }
112
113 export interface SourceLocation {
114 rawModuleId: string;
115 sourceFileURL: string;
116 lineNumber: number;
117 columnNumber: number;
118 }
119
120 export interface Variable {
121 scope: string;
122 name: string;
123 type: string;
124 nestedName?: string[];
125 }
126
127 export interface ScopeInfo {
128 type: string;
129 typeName: string;
130 icon?: string;
131 }
132
133 export interface FunctionInfo {
134 name: string;
135 }
136
137 export interface FieldInfo {
138 name?: string;
139 offset: number;
140 typeId: unknown;
141 }
142
143 export interface TypeInfo {
144 typeNames: string[];
145 typeId: unknown;
146 members: FieldInfo[];
147 alignment: number;
148 arraySize: number;
149 size: number;
150 canExpand: boolean;
151 hasValue: boolean;
152 }
153
154 export interface EvalBase {
155 rootType: TypeInfo;
156 payload: unknown;
157 }
158
159 export interface LanguageExtensionPlugin {
160 /**
161 * A new raw module has been loaded. If the raw wasm module references an external debug info module, its URL will be
162 * passed as symbolsURL.
163 */
164 addRawModule(rawModuleId: string, symbolsURL: string|undefined, rawModule: RawModule): Promise<string[]>;
165
166 /**
167 * Find locations in raw modules from a location in a source file.
168 */
169 sourceLocationToRawLocation(sourceLocation: SourceLocation): Promise<RawLocationRange[]>;
170
171 /**
172 * Find locations in source files from a location in a raw module.
173 */
174 rawLocationToSourceLocation(rawLocation: RawLocation): Promise<SourceLocation[]>;
175
176 /**
177 * Return detailed information about a scope.
178 */
179 getScopeInfo(type: string): Promise<ScopeInfo>;
180
181 /**
182 * List all variables in lexical scope at a given location in a raw module.
183 */
184 listVariablesInScope(rawLocation: RawLocation): Promise<Variable[]>;
185
186 /**
187 * Notifies the plugin that a script is removed.
188 */
189 removeRawModule(rawModuleId: string): Promise<void>;
190
191 /**
192 * Return type information for an expression. The result describes the type (and recursively its member types) of the
193 * result of the expression if it were evaluated in the given context.
194 */
195 getTypeInfo(expression: string, context: RawLocation): Promise<{
196 typeInfos: Array<TypeInfo>,
197 base: EvalBase,
198 }|null>;
199
200 /**
201 * Returns a piece of JavaScript code that, if evaluated, produces a representation of the given expression or field.
202 */
203 getFormatter(
204 expressionOrField: string|{
205 base: EvalBase,
206 field: Array<FieldInfo>,
207 },
208 context: RawLocation): Promise<{
209 js: string,
210 }|null>;
211
212 /**
213 * Returns a piece of JavaScript code that, if evaluated, produces the address of the given field in the wasm memory.
214 */
215 getInspectableAddress(field: {
216 base: EvalBase,
217 field: Array<FieldInfo>,
218 }): Promise<{
219 js: string,
220 }>;
221
222 /**
223 * Find locations in source files from a location in a raw module
224 */
225 getFunctionInfo(rawLocation: RawLocation): Promise<{
226 frames: Array<FunctionInfo>,
227 }>;
228
229 /**
230 * Find locations in raw modules corresponding to the inline function
231 * that rawLocation is in. Used for stepping out of an inline function.
232 */
233 getInlinedFunctionRanges(rawLocation: RawLocation): Promise<RawLocationRange[]>;
234
235 /**
236 * Find locations in raw modules corresponding to inline functions
237 * called by the function or inline frame that rawLocation is in.
238 * Used for stepping over inline functions.
239 */
240 getInlinedCalleesRanges(rawLocation: RawLocation): Promise<RawLocationRange[]>;
241
242 /**
243 * Retrieve a list of line numbers in a file for which line-to-raw-location mappings exist.
244 */
245 getMappedLines(rawModuleId: string, sourceFileURL: string): Promise<number[]|undefined>;
246 }
247
248
249 export interface SupportedScriptTypes {
250 language: string;
251 symbol_types: string[];
252 }
253
254 export interface LanguageExtensions {
255 registerLanguageExtensionPlugin(
256 plugin: LanguageExtensionPlugin, pluginName: string,
257 supportedScriptTypes: SupportedScriptTypes): Promise<void>;
258 unregisterLanguageExtensionPlugin(plugin: LanguageExtensionPlugin): Promise<void>;
259 }
260
261 export interface Chrome {
262 devtools: DevToolsAPI;
263 experimental: {devtools: ExperimentalDevToolsAPI};
264 }
265 }
266}
267
268declare global {
269 interface Window {
270 chrome: Chrome.DevTools.Chrome;
271 }
272}