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 { |
Alex Rudenko | 0b8b888 | 2023-01-17 13:21:49 +0100 | [diff] [blame] | 50 | show(): void; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 51 | onSearch: EventSink<(action: string, queryString?: string) => unknown>; |
| 52 | createStatusBarButton(iconPath: string, tooltipText: string, disabled: boolean): Button; |
| 53 | } |
| 54 | |
Alex Rudenko | 0b8b888 | 2023-01-17 13:21:49 +0100 | [diff] [blame] | 55 | export interface RecorderView extends ExtensionView { |
| 56 | show(): void; |
| 57 | } |
| 58 | |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 59 | export interface ExtensionSidebarPane extends ExtensionView { |
| 60 | setHeight(height: string): void; |
| 61 | setObject(jsonObject: string, rootTitle?: string, callback?: () => unknown): void; |
| 62 | setPage(path: string): void; |
| 63 | } |
| 64 | |
| 65 | export interface PanelWithSidebar { |
| 66 | createSidebarPane(title: string, callback?: (result: ExtensionSidebarPane) => unknown): void; |
| 67 | onSelectionChanged: EventSink<() => unknown>; |
| 68 | } |
| 69 | |
| 70 | export interface Panels { |
| 71 | elements: PanelWithSidebar; |
| 72 | sources: PanelWithSidebar; |
| 73 | themeName: string; |
| 74 | |
| 75 | create(title: string, iconPath: string, pagePath: string, callback?: (panel: ExtensionPanel) => unknown): void; |
Philip Pfaffe | 140e543 | 2021-09-13 18:34:23 +0200 | [diff] [blame] | 76 | openResource(url: string, lineNumber: number, columnNumber?: number, callback?: () => unknown): void; |
Paul Lewis | ada689f | 2022-01-11 12:03:40 +0000 | [diff] [blame] | 77 | |
| 78 | /** |
| 79 | * Fired when the theme changes in DevTools. |
| 80 | * |
| 81 | * @param callback The handler callback to register and be invoked on theme changes. |
| 82 | */ |
| 83 | setThemeChangeHandler(callback?: (themeName: string) => unknown): void; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | export interface Request { |
| 87 | getContent(callback: (content: string, encoding: string) => unknown): void; |
| 88 | } |
| 89 | |
| 90 | export interface Network { |
| 91 | onNavigated: EventSink<(url: string) => unknown>; |
| 92 | onRequestFinished: EventSink<(request: Request) => unknown>; |
| 93 | |
| 94 | getHAR(callback: (harLog: object) => unknown): void; |
| 95 | } |
| 96 | |
| 97 | export interface DevToolsAPI { |
| 98 | network: Network; |
| 99 | panels: Panels; |
| 100 | inspectedWindow: InspectedWindow; |
| 101 | languageServices: LanguageExtensions; |
Alex Rudenko | a385082 | 2022-05-24 09:34:22 +0200 | [diff] [blame] | 102 | recorder: RecorderExtensions; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | export interface ExperimentalDevToolsAPI { |
| 106 | inspectedWindow: InspectedWindow; |
| 107 | } |
| 108 | |
| 109 | export interface RawModule { |
| 110 | url: string; |
| 111 | code?: ArrayBuffer; |
| 112 | } |
| 113 | |
| 114 | export interface RawLocationRange { |
| 115 | rawModuleId: string; |
| 116 | startOffset: number; |
| 117 | endOffset: number; |
| 118 | } |
| 119 | |
| 120 | export interface RawLocation { |
| 121 | rawModuleId: string; |
| 122 | codeOffset: number; |
| 123 | inlineFrameIndex: number; |
| 124 | } |
| 125 | |
| 126 | export interface SourceLocation { |
| 127 | rawModuleId: string; |
| 128 | sourceFileURL: string; |
| 129 | lineNumber: number; |
| 130 | columnNumber: number; |
| 131 | } |
| 132 | |
| 133 | export interface Variable { |
| 134 | scope: string; |
| 135 | name: string; |
| 136 | type: string; |
| 137 | nestedName?: string[]; |
| 138 | } |
| 139 | |
| 140 | export interface ScopeInfo { |
| 141 | type: string; |
| 142 | typeName: string; |
| 143 | icon?: string; |
| 144 | } |
| 145 | |
| 146 | export interface FunctionInfo { |
| 147 | name: string; |
| 148 | } |
| 149 | |
Philip Pfaffe | 1e2a371 | 2021-07-22 14:23:01 +0200 | [diff] [blame] | 150 | export type Enumerator = { |
| 151 | name: string, |
| 152 | value: unknown, |
| 153 | typeId: unknown, |
| 154 | }; |
| 155 | |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 156 | export interface FieldInfo { |
| 157 | name?: string; |
| 158 | offset: number; |
| 159 | typeId: unknown; |
| 160 | } |
| 161 | |
| 162 | export interface TypeInfo { |
| 163 | typeNames: string[]; |
| 164 | typeId: unknown; |
| 165 | members: FieldInfo[]; |
Philip Pfaffe | 1e2a371 | 2021-07-22 14:23:01 +0200 | [diff] [blame] | 166 | enumerators?: Enumerator[]; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 167 | alignment: number; |
| 168 | arraySize: number; |
| 169 | size: number; |
| 170 | canExpand: boolean; |
| 171 | hasValue: boolean; |
| 172 | } |
| 173 | |
| 174 | export interface EvalBase { |
| 175 | rootType: TypeInfo; |
| 176 | payload: unknown; |
| 177 | } |
| 178 | |
Alex Rudenko | 0b8b888 | 2023-01-17 13:21:49 +0100 | [diff] [blame] | 179 | export type RecorderExtensionPlugin = RecorderExtensionExportPlugin|RecorderExtensionReplayPlugin; |
| 180 | |
| 181 | export interface RecorderExtensionExportPlugin { |
Alex Rudenko | fba45c5 | 2022-06-01 09:32:05 +0200 | [diff] [blame] | 182 | stringify(recording: Record<string, any>): Promise<string>; |
| 183 | stringifyStep(step: Record<string, any>): Promise<string>; |
Alex Rudenko | a385082 | 2022-05-24 09:34:22 +0200 | [diff] [blame] | 184 | } |
Alex Rudenko | 0b8b888 | 2023-01-17 13:21:49 +0100 | [diff] [blame] | 185 | export interface RecorderExtensionReplayPlugin { |
| 186 | replay(recording: Record<string, any>): void; |
| 187 | } |
Alex Rudenko | a385082 | 2022-05-24 09:34:22 +0200 | [diff] [blame] | 188 | |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 189 | export type RemoteObjectId = string; |
| 190 | export type RemoteObjectType = 'object'|'undefined'|'string'|'number'|'boolean'|'bigint'|'array'|'null'; |
| 191 | |
| 192 | |
| 193 | export interface RemoteObject { |
| 194 | type: RemoteObjectType; |
| 195 | className?: string; |
| 196 | value?: any; |
| 197 | description?: string; |
| 198 | objectId?: RemoteObjectId; |
| 199 | linearMemoryAddress?: number; |
Philip Pfaffe | 1ae5c9d | 2022-09-20 09:40:52 +0000 | [diff] [blame] | 200 | linearMemorySize?: number; |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 201 | hasChildren: boolean; |
| 202 | } |
| 203 | |
| 204 | export interface PropertyDescriptor { |
| 205 | name: string; |
| 206 | value: RemoteObject; |
| 207 | } |
| 208 | |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 209 | export interface LanguageExtensionPlugin { |
| 210 | /** |
| 211 | * A new raw module has been loaded. If the raw wasm module references an external debug info module, its URL will be |
| 212 | * passed as symbolsURL. |
| 213 | */ |
Philip Pfaffe | ae1192b | 2022-06-02 13:08:03 +0000 | [diff] [blame] | 214 | addRawModule(rawModuleId: string, symbolsURL: string|undefined, rawModule: RawModule): |
| 215 | Promise<string[]|{missingSymbolFiles: string[]}>; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 216 | |
| 217 | /** |
| 218 | * Find locations in raw modules from a location in a source file. |
| 219 | */ |
| 220 | sourceLocationToRawLocation(sourceLocation: SourceLocation): Promise<RawLocationRange[]>; |
| 221 | |
| 222 | /** |
| 223 | * Find locations in source files from a location in a raw module. |
| 224 | */ |
| 225 | rawLocationToSourceLocation(rawLocation: RawLocation): Promise<SourceLocation[]>; |
| 226 | |
| 227 | /** |
| 228 | * Return detailed information about a scope. |
| 229 | */ |
| 230 | getScopeInfo(type: string): Promise<ScopeInfo>; |
| 231 | |
| 232 | /** |
| 233 | * List all variables in lexical scope at a given location in a raw module. |
| 234 | */ |
| 235 | listVariablesInScope(rawLocation: RawLocation): Promise<Variable[]>; |
| 236 | |
| 237 | /** |
| 238 | * Notifies the plugin that a script is removed. |
| 239 | */ |
| 240 | removeRawModule(rawModuleId: string): Promise<void>; |
| 241 | |
| 242 | /** |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame] | 243 | * DEPRECATED. Return type information for an expression. The result describes the type (and recursively its |
| 244 | * member types) of the result of the expression if it were evaluated in the given context. |
| 245 | * TODO(crbug.com/1342848) Remove. |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 246 | */ |
| 247 | getTypeInfo(expression: string, context: RawLocation): Promise<{ |
| 248 | typeInfos: Array<TypeInfo>, |
| 249 | base: EvalBase, |
| 250 | }|null>; |
| 251 | |
| 252 | /** |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame] | 253 | * DEPRECATED. Returns a piece of JavaScript code that, if evaluated, produces a representation of the given |
| 254 | * expression or field. |
| 255 | * TODO(crbug.com/1342848) Remove. |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 256 | */ |
| 257 | getFormatter( |
| 258 | expressionOrField: string|{ |
| 259 | base: EvalBase, |
| 260 | field: Array<FieldInfo>, |
| 261 | }, |
| 262 | context: RawLocation): Promise<{ |
| 263 | js: string, |
| 264 | }|null>; |
| 265 | |
| 266 | /** |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame] | 267 | * Evaluate a source language expression in the context of a given raw location and a given stopId. stopId is an |
| 268 | * opaque key that should be passed to the APIs accessing wasm state, e.g., getWasmLinearMemory. A stopId is |
| 269 | * invalidated once the debugger resumes. |
| 270 | * TODO(crbug.com/1342848) Make non-optional. |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 271 | */ |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame] | 272 | evaluate?(expression: string, context: RawLocation, stopId: unknown): Promise<RemoteObject|null>; |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 273 | |
| 274 | /** |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame] | 275 | * DEPRECATED. Returns a piece of JavaScript code that, if evaluated, produces the address of the given field in the wasm memory. |
| 276 | * TODO(crbug.com/1342848) Remove. |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 277 | */ |
| 278 | getInspectableAddress(field: { |
| 279 | base: EvalBase, |
| 280 | field: Array<FieldInfo>, |
| 281 | }): Promise<{ |
| 282 | js: string, |
| 283 | }>; |
| 284 | |
| 285 | /** |
Philip Pfaffe | 913156f | 2022-12-16 09:21:58 +0000 | [diff] [blame] | 286 | * Retrieve function name(s) for the function(s) containing the rawLocation. This returns more than one entry if |
| 287 | * the location is inside of an inlined function with the innermost function at index 0. |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 288 | */ |
Philip Pfaffe | ae1192b | 2022-06-02 13:08:03 +0000 | [diff] [blame] | 289 | getFunctionInfo(rawLocation: RawLocation): |
| 290 | Promise<{frames: Array<FunctionInfo>}|{missingSymbolFiles: Array<string>}>; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 291 | |
| 292 | /** |
| 293 | * Find locations in raw modules corresponding to the inline function |
| 294 | * that rawLocation is in. Used for stepping out of an inline function. |
| 295 | */ |
| 296 | getInlinedFunctionRanges(rawLocation: RawLocation): Promise<RawLocationRange[]>; |
| 297 | |
| 298 | /** |
| 299 | * Find locations in raw modules corresponding to inline functions |
| 300 | * called by the function or inline frame that rawLocation is in. |
| 301 | * Used for stepping over inline functions. |
| 302 | */ |
| 303 | getInlinedCalleesRanges(rawLocation: RawLocation): Promise<RawLocationRange[]>; |
| 304 | |
| 305 | /** |
| 306 | * Retrieve a list of line numbers in a file for which line-to-raw-location mappings exist. |
| 307 | */ |
| 308 | getMappedLines(rawModuleId: string, sourceFileURL: string): Promise<number[]|undefined>; |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 309 | |
| 310 | /** |
| 311 | * Retrieve properties of the remote object identified by the object id. |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame] | 312 | * TODO(crbug.com/1342848) Make non-optional. |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 313 | */ |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame] | 314 | getProperties?(objectId: RemoteObjectId): Promise<PropertyDescriptor[]>; |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 315 | /** |
| 316 | * Permanently release the remote object identified by the object id. |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame] | 317 | * TODO(crbug.com/1342848) Make non-optional. |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 318 | */ |
Philip Pfaffe | 889342a | 2022-07-08 06:18:47 +0000 | [diff] [blame] | 319 | releaseObject?(objectId: RemoteObjectId): Promise<void>; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | |
| 323 | export interface SupportedScriptTypes { |
| 324 | language: string; |
| 325 | symbol_types: string[]; |
| 326 | } |
| 327 | |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 328 | export type WasmValue = {type: 'i32'|'f32'|'f64', value: number}|{type: 'i64', value: bigint}| |
| 329 | {type: 'v128', value: string}; |
| 330 | |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 331 | export interface LanguageExtensions { |
| 332 | registerLanguageExtensionPlugin( |
| 333 | plugin: LanguageExtensionPlugin, pluginName: string, |
| 334 | supportedScriptTypes: SupportedScriptTypes): Promise<void>; |
| 335 | unregisterLanguageExtensionPlugin(plugin: LanguageExtensionPlugin): Promise<void>; |
Philip Pfaffe | 6ed0126 | 2022-07-06 10:41:39 +0000 | [diff] [blame] | 336 | |
| 337 | getWasmLinearMemory(offset: number, length: number, stopId: unknown): Promise<ArrayBuffer>; |
| 338 | getWasmLocal(local: number, stopId: unknown): Promise<WasmValue>; |
| 339 | getWasmGlobal(global: number, stopId: unknown): Promise<WasmValue>; |
| 340 | getWasmOp(op: number, stopId: unknown): Promise<WasmValue>; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 341 | } |
| 342 | |
Alex Rudenko | 0b8b888 | 2023-01-17 13:21:49 +0100 | [diff] [blame] | 343 | |
Alex Rudenko | a385082 | 2022-05-24 09:34:22 +0200 | [diff] [blame] | 344 | export interface RecorderExtensions { |
Alex Rudenko | 0b8b888 | 2023-01-17 13:21:49 +0100 | [diff] [blame] | 345 | registerRecorderExtensionPlugin(plugin: RecorderExtensionPlugin, pluginName: string, mediaType?: string): |
Alex Rudenko | fba45c5 | 2022-06-01 09:32:05 +0200 | [diff] [blame] | 346 | Promise<void>; |
Alex Rudenko | a385082 | 2022-05-24 09:34:22 +0200 | [diff] [blame] | 347 | unregisterRecorderExtensionPlugin(plugin: RecorderExtensionPlugin): Promise<void>; |
Alex Rudenko | 0b8b888 | 2023-01-17 13:21:49 +0100 | [diff] [blame] | 348 | createView(title: string, pagePath: string): Promise<RecorderView>; |
Alex Rudenko | a385082 | 2022-05-24 09:34:22 +0200 | [diff] [blame] | 349 | } |
| 350 | |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 351 | export interface Chrome { |
| 352 | devtools: DevToolsAPI; |
| 353 | experimental: {devtools: ExperimentalDevToolsAPI}; |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | declare global { |
| 359 | interface Window { |
| 360 | chrome: Chrome.DevTools.Chrome; |
| 361 | } |
| 362 | } |