Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 1 | // 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 | |
| 5 | export namespace Chrome { |
| 6 | export namespace DevTools { |
Tim van der Lippe | 269e9ae | 2021-12-14 14:33:28 +0100 | [diff] [blame] | 7 | export interface EventSink<ListenerT extends(...args: any) => void> { |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 8 | addListener(listener: ListenerT): void; |
| 9 | } |
| 10 | |
| 11 | export interface Resource { |
Philip Pfaffe | 11e4368 | 2021-07-29 13:14:42 +0200 | [diff] [blame] | 12 | readonly url: string; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 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; |
Philip Pfaffe | 140e543 | 2021-09-13 18:34:23 +0200 | [diff] [blame] | 71 | openResource(url: string, lineNumber: number, columnNumber?: number, callback?: () => unknown): void; |
Paul Lewis | ada689f | 2022-01-11 12:03:40 +0000 | [diff] [blame] | 72 | |
| 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 Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 79 | } |
| 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; |
Alex Rudenko | a385082 | 2022-05-24 09:34:22 +0200 | [diff] [blame] | 97 | recorder: RecorderExtensions; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | export interface ExperimentalDevToolsAPI { |
| 101 | inspectedWindow: InspectedWindow; |
| 102 | } |
| 103 | |
| 104 | export interface RawModule { |
| 105 | url: string; |
| 106 | code?: ArrayBuffer; |
| 107 | } |
| 108 | |
| 109 | export interface RawLocationRange { |
| 110 | rawModuleId: string; |
| 111 | startOffset: number; |
| 112 | endOffset: number; |
| 113 | } |
| 114 | |
| 115 | export interface RawLocation { |
| 116 | rawModuleId: string; |
| 117 | codeOffset: number; |
| 118 | inlineFrameIndex: number; |
| 119 | } |
| 120 | |
| 121 | export interface SourceLocation { |
| 122 | rawModuleId: string; |
| 123 | sourceFileURL: string; |
| 124 | lineNumber: number; |
| 125 | columnNumber: number; |
| 126 | } |
| 127 | |
| 128 | export interface Variable { |
| 129 | scope: string; |
| 130 | name: string; |
| 131 | type: string; |
| 132 | nestedName?: string[]; |
| 133 | } |
| 134 | |
| 135 | export interface ScopeInfo { |
| 136 | type: string; |
| 137 | typeName: string; |
| 138 | icon?: string; |
| 139 | } |
| 140 | |
| 141 | export interface FunctionInfo { |
| 142 | name: string; |
| 143 | } |
| 144 | |
Philip Pfaffe | 1e2a371 | 2021-07-22 14:23:01 +0200 | [diff] [blame] | 145 | export type Enumerator = { |
| 146 | name: string, |
| 147 | value: unknown, |
| 148 | typeId: unknown, |
| 149 | }; |
| 150 | |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 151 | export interface FieldInfo { |
| 152 | name?: string; |
| 153 | offset: number; |
| 154 | typeId: unknown; |
| 155 | } |
| 156 | |
| 157 | export interface TypeInfo { |
| 158 | typeNames: string[]; |
| 159 | typeId: unknown; |
| 160 | members: FieldInfo[]; |
Philip Pfaffe | 1e2a371 | 2021-07-22 14:23:01 +0200 | [diff] [blame] | 161 | enumerators?: Enumerator[]; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 162 | alignment: number; |
| 163 | arraySize: number; |
| 164 | size: number; |
| 165 | canExpand: boolean; |
| 166 | hasValue: boolean; |
| 167 | } |
| 168 | |
| 169 | export interface EvalBase { |
| 170 | rootType: TypeInfo; |
| 171 | payload: unknown; |
| 172 | } |
| 173 | |
Alex Rudenko | a385082 | 2022-05-24 09:34:22 +0200 | [diff] [blame] | 174 | export interface RecorderExtensionPlugin { |
Alex Rudenko | fba45c5 | 2022-06-01 09:32:05 +0200 | [diff] [blame] | 175 | stringify(recording: Record<string, any>): Promise<string>; |
| 176 | stringifyStep(step: Record<string, any>): Promise<string>; |
Alex Rudenko | a385082 | 2022-05-24 09:34:22 +0200 | [diff] [blame] | 177 | } |
| 178 | |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 179 | export type RemoteObjectId = string; |
| 180 | export type RemoteObjectType = 'object'|'undefined'|'string'|'number'|'boolean'|'bigint'|'array'|'null'; |
| 181 | |
| 182 | |
| 183 | export interface RemoteObject { |
| 184 | type: RemoteObjectType; |
| 185 | className?: string; |
| 186 | value?: any; |
| 187 | description?: string; |
| 188 | objectId?: RemoteObjectId; |
| 189 | linearMemoryAddress?: number; |
| 190 | hasChildren: boolean; |
| 191 | } |
| 192 | |
| 193 | export interface PropertyDescriptor { |
| 194 | name: string; |
| 195 | value: RemoteObject; |
| 196 | } |
| 197 | |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 198 | export interface LanguageExtensionPlugin { |
| 199 | /** |
| 200 | * A new raw module has been loaded. If the raw wasm module references an external debug info module, its URL will be |
| 201 | * passed as symbolsURL. |
| 202 | */ |
Philip Pfaffe | ae1192b | 2022-06-02 13:08:03 +0000 | [diff] [blame] | 203 | addRawModule(rawModuleId: string, symbolsURL: string|undefined, rawModule: RawModule): |
| 204 | Promise<string[]|{missingSymbolFiles: string[]}>; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 205 | |
| 206 | /** |
| 207 | * Find locations in raw modules from a location in a source file. |
| 208 | */ |
| 209 | sourceLocationToRawLocation(sourceLocation: SourceLocation): Promise<RawLocationRange[]>; |
| 210 | |
| 211 | /** |
| 212 | * Find locations in source files from a location in a raw module. |
| 213 | */ |
| 214 | rawLocationToSourceLocation(rawLocation: RawLocation): Promise<SourceLocation[]>; |
| 215 | |
| 216 | /** |
| 217 | * Return detailed information about a scope. |
| 218 | */ |
| 219 | getScopeInfo(type: string): Promise<ScopeInfo>; |
| 220 | |
| 221 | /** |
| 222 | * List all variables in lexical scope at a given location in a raw module. |
| 223 | */ |
| 224 | listVariablesInScope(rawLocation: RawLocation): Promise<Variable[]>; |
| 225 | |
| 226 | /** |
| 227 | * Notifies the plugin that a script is removed. |
| 228 | */ |
| 229 | removeRawModule(rawModuleId: string): Promise<void>; |
| 230 | |
| 231 | /** |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame^] | 232 | * DEPRECATED. Return type information for an expression. The result describes the type (and recursively its |
| 233 | * member types) of the result of the expression if it were evaluated in the given context. |
| 234 | * TODO(crbug.com/1342848) Remove. |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 235 | */ |
| 236 | getTypeInfo(expression: string, context: RawLocation): Promise<{ |
| 237 | typeInfos: Array<TypeInfo>, |
| 238 | base: EvalBase, |
| 239 | }|null>; |
| 240 | |
| 241 | /** |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame^] | 242 | * DEPRECATED. Returns a piece of JavaScript code that, if evaluated, produces a representation of the given |
| 243 | * expression or field. |
| 244 | * TODO(crbug.com/1342848) Remove. |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 245 | */ |
| 246 | getFormatter( |
| 247 | expressionOrField: string|{ |
| 248 | base: EvalBase, |
| 249 | field: Array<FieldInfo>, |
| 250 | }, |
| 251 | context: RawLocation): Promise<{ |
| 252 | js: string, |
| 253 | }|null>; |
| 254 | |
| 255 | /** |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame^] | 256 | * Evaluate a source language expression in the context of a given raw location and a given stopId. stopId is an |
| 257 | * opaque key that should be passed to the APIs accessing wasm state, e.g., getWasmLinearMemory. A stopId is |
| 258 | * invalidated once the debugger resumes. |
| 259 | * TODO(crbug.com/1342848) Make non-optional. |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 260 | */ |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame^] | 261 | evaluate?(expression: string, context: RawLocation, stopId: unknown): Promise<RemoteObject|null>; |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 262 | |
| 263 | /** |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame^] | 264 | * DEPRECATED. Returns a piece of JavaScript code that, if evaluated, produces the address of the given field in the wasm memory. |
| 265 | * TODO(crbug.com/1342848) Remove. |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 266 | */ |
| 267 | getInspectableAddress(field: { |
| 268 | base: EvalBase, |
| 269 | field: Array<FieldInfo>, |
| 270 | }): Promise<{ |
| 271 | js: string, |
| 272 | }>; |
| 273 | |
| 274 | /** |
| 275 | * Find locations in source files from a location in a raw module |
| 276 | */ |
Philip Pfaffe | ae1192b | 2022-06-02 13:08:03 +0000 | [diff] [blame] | 277 | getFunctionInfo(rawLocation: RawLocation): |
| 278 | Promise<{frames: Array<FunctionInfo>}|{missingSymbolFiles: Array<string>}>; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 279 | |
| 280 | /** |
| 281 | * Find locations in raw modules corresponding to the inline function |
| 282 | * that rawLocation is in. Used for stepping out of an inline function. |
| 283 | */ |
| 284 | getInlinedFunctionRanges(rawLocation: RawLocation): Promise<RawLocationRange[]>; |
| 285 | |
| 286 | /** |
| 287 | * Find locations in raw modules corresponding to inline functions |
| 288 | * called by the function or inline frame that rawLocation is in. |
| 289 | * Used for stepping over inline functions. |
| 290 | */ |
| 291 | getInlinedCalleesRanges(rawLocation: RawLocation): Promise<RawLocationRange[]>; |
| 292 | |
| 293 | /** |
| 294 | * Retrieve a list of line numbers in a file for which line-to-raw-location mappings exist. |
| 295 | */ |
| 296 | getMappedLines(rawModuleId: string, sourceFileURL: string): Promise<number[]|undefined>; |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 297 | |
| 298 | /** |
| 299 | * Retrieve properties of the remote object identified by the object id. |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame^] | 300 | * TODO(crbug.com/1342848) Make non-optional. |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 301 | */ |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame^] | 302 | getProperties?(objectId: RemoteObjectId): Promise<PropertyDescriptor[]>; |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 303 | /** |
| 304 | * Permanently release the remote object identified by the object id. |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame^] | 305 | * TODO(crbug.com/1342848) Make non-optional. |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 306 | */ |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame^] | 307 | releaseObject?(objectId: RemoteObjectId): Promise<void>; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | |
| 311 | export interface SupportedScriptTypes { |
| 312 | language: string; |
| 313 | symbol_types: string[]; |
| 314 | } |
| 315 | |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 316 | export type WasmValue = {type: 'i32'|'f32'|'f64', value: number}|{type: 'i64', value: bigint}| |
| 317 | {type: 'v128', value: string}; |
| 318 | |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 319 | export interface LanguageExtensions { |
| 320 | registerLanguageExtensionPlugin( |
| 321 | plugin: LanguageExtensionPlugin, pluginName: string, |
| 322 | supportedScriptTypes: SupportedScriptTypes): Promise<void>; |
| 323 | unregisterLanguageExtensionPlugin(plugin: LanguageExtensionPlugin): Promise<void>; |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 324 | |
| 325 | getWasmLinearMemory(offset: number, length: number, stopId: unknown): Promise<ArrayBuffer>; |
| 326 | getWasmLocal(local: number, stopId: unknown): Promise<WasmValue>; |
| 327 | getWasmGlobal(global: number, stopId: unknown): Promise<WasmValue>; |
| 328 | getWasmOp(op: number, stopId: unknown): Promise<WasmValue>; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 329 | } |
| 330 | |
Alex Rudenko | a385082 | 2022-05-24 09:34:22 +0200 | [diff] [blame] | 331 | export interface RecorderExtensions { |
Alex Rudenko | 53dbba4 | 2022-06-02 15:01:23 +0200 | [diff] [blame] | 332 | registerRecorderExtensionPlugin(plugin: RecorderExtensionPlugin, pluginName: string, mediaType: string): |
Alex Rudenko | fba45c5 | 2022-06-01 09:32:05 +0200 | [diff] [blame] | 333 | Promise<void>; |
Alex Rudenko | a385082 | 2022-05-24 09:34:22 +0200 | [diff] [blame] | 334 | unregisterRecorderExtensionPlugin(plugin: RecorderExtensionPlugin): Promise<void>; |
| 335 | } |
| 336 | |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 337 | export interface Chrome { |
| 338 | devtools: DevToolsAPI; |
| 339 | experimental: {devtools: ExperimentalDevToolsAPI}; |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | declare global { |
| 345 | interface Window { |
| 346 | chrome: Chrome.DevTools.Chrome; |
| 347 | } |
| 348 | } |