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 { |
| 7 | export interface EventSink<ListenerT extends(...args: any) => any> { |
| 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; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 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 | |
Philip Pfaffe | 1e2a371 | 2021-07-22 14:23:01 +0200 | [diff] [blame] | 137 | export type Enumerator = { |
| 138 | name: string, |
| 139 | value: unknown, |
| 140 | typeId: unknown, |
| 141 | }; |
| 142 | |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 143 | export interface FieldInfo { |
| 144 | name?: string; |
| 145 | offset: number; |
| 146 | typeId: unknown; |
| 147 | } |
| 148 | |
| 149 | export interface TypeInfo { |
| 150 | typeNames: string[]; |
| 151 | typeId: unknown; |
| 152 | members: FieldInfo[]; |
Philip Pfaffe | 1e2a371 | 2021-07-22 14:23:01 +0200 | [diff] [blame] | 153 | enumerators?: Enumerator[]; |
Philip Pfaffe | 5df6626 | 2021-07-19 16:55:50 +0200 | [diff] [blame] | 154 | alignment: number; |
| 155 | arraySize: number; |
| 156 | size: number; |
| 157 | canExpand: boolean; |
| 158 | hasValue: boolean; |
| 159 | } |
| 160 | |
| 161 | export interface EvalBase { |
| 162 | rootType: TypeInfo; |
| 163 | payload: unknown; |
| 164 | } |
| 165 | |
| 166 | export interface LanguageExtensionPlugin { |
| 167 | /** |
| 168 | * A new raw module has been loaded. If the raw wasm module references an external debug info module, its URL will be |
| 169 | * passed as symbolsURL. |
| 170 | */ |
| 171 | addRawModule(rawModuleId: string, symbolsURL: string|undefined, rawModule: RawModule): Promise<string[]>; |
| 172 | |
| 173 | /** |
| 174 | * Find locations in raw modules from a location in a source file. |
| 175 | */ |
| 176 | sourceLocationToRawLocation(sourceLocation: SourceLocation): Promise<RawLocationRange[]>; |
| 177 | |
| 178 | /** |
| 179 | * Find locations in source files from a location in a raw module. |
| 180 | */ |
| 181 | rawLocationToSourceLocation(rawLocation: RawLocation): Promise<SourceLocation[]>; |
| 182 | |
| 183 | /** |
| 184 | * Return detailed information about a scope. |
| 185 | */ |
| 186 | getScopeInfo(type: string): Promise<ScopeInfo>; |
| 187 | |
| 188 | /** |
| 189 | * List all variables in lexical scope at a given location in a raw module. |
| 190 | */ |
| 191 | listVariablesInScope(rawLocation: RawLocation): Promise<Variable[]>; |
| 192 | |
| 193 | /** |
| 194 | * Notifies the plugin that a script is removed. |
| 195 | */ |
| 196 | removeRawModule(rawModuleId: string): Promise<void>; |
| 197 | |
| 198 | /** |
| 199 | * Return type information for an expression. The result describes the type (and recursively its member types) of the |
| 200 | * result of the expression if it were evaluated in the given context. |
| 201 | */ |
| 202 | getTypeInfo(expression: string, context: RawLocation): Promise<{ |
| 203 | typeInfos: Array<TypeInfo>, |
| 204 | base: EvalBase, |
| 205 | }|null>; |
| 206 | |
| 207 | /** |
| 208 | * Returns a piece of JavaScript code that, if evaluated, produces a representation of the given expression or field. |
| 209 | */ |
| 210 | getFormatter( |
| 211 | expressionOrField: string|{ |
| 212 | base: EvalBase, |
| 213 | field: Array<FieldInfo>, |
| 214 | }, |
| 215 | context: RawLocation): Promise<{ |
| 216 | js: string, |
| 217 | }|null>; |
| 218 | |
| 219 | /** |
| 220 | * Returns a piece of JavaScript code that, if evaluated, produces the address of the given field in the wasm memory. |
| 221 | */ |
| 222 | getInspectableAddress(field: { |
| 223 | base: EvalBase, |
| 224 | field: Array<FieldInfo>, |
| 225 | }): Promise<{ |
| 226 | js: string, |
| 227 | }>; |
| 228 | |
| 229 | /** |
| 230 | * Find locations in source files from a location in a raw module |
| 231 | */ |
| 232 | getFunctionInfo(rawLocation: RawLocation): Promise<{ |
| 233 | frames: Array<FunctionInfo>, |
| 234 | }>; |
| 235 | |
| 236 | /** |
| 237 | * Find locations in raw modules corresponding to the inline function |
| 238 | * that rawLocation is in. Used for stepping out of an inline function. |
| 239 | */ |
| 240 | getInlinedFunctionRanges(rawLocation: RawLocation): Promise<RawLocationRange[]>; |
| 241 | |
| 242 | /** |
| 243 | * Find locations in raw modules corresponding to inline functions |
| 244 | * called by the function or inline frame that rawLocation is in. |
| 245 | * Used for stepping over inline functions. |
| 246 | */ |
| 247 | getInlinedCalleesRanges(rawLocation: RawLocation): Promise<RawLocationRange[]>; |
| 248 | |
| 249 | /** |
| 250 | * Retrieve a list of line numbers in a file for which line-to-raw-location mappings exist. |
| 251 | */ |
| 252 | getMappedLines(rawModuleId: string, sourceFileURL: string): Promise<number[]|undefined>; |
| 253 | } |
| 254 | |
| 255 | |
| 256 | export interface SupportedScriptTypes { |
| 257 | language: string; |
| 258 | symbol_types: string[]; |
| 259 | } |
| 260 | |
| 261 | export interface LanguageExtensions { |
| 262 | registerLanguageExtensionPlugin( |
| 263 | plugin: LanguageExtensionPlugin, pluginName: string, |
| 264 | supportedScriptTypes: SupportedScriptTypes): Promise<void>; |
| 265 | unregisterLanguageExtensionPlugin(plugin: LanguageExtensionPlugin): Promise<void>; |
| 266 | } |
| 267 | |
| 268 | export interface Chrome { |
| 269 | devtools: DevToolsAPI; |
| 270 | experimental: {devtools: ExperimentalDevToolsAPI}; |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | declare global { |
| 276 | interface Window { |
| 277 | chrome: Chrome.DevTools.Chrome; |
| 278 | } |
| 279 | } |