|
| 1 | +// Copyright 2021 The Chromium Authors |
| 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[]) => void> { |
| 8 | + addListener(listener: ListenerT): void; |
| 9 | + removeListener(listener: ListenerT): void; |
| 10 | + } |
| 11 | + |
| 12 | + export interface Resource { |
| 13 | + readonly url: string; |
| 14 | + readonly type: string; |
| 15 | + |
| 16 | + /** |
| 17 | + * For WASM resources the content of the `build_id` custom section. For JavaScript resources the |
| 18 | + * `debugId` magic comment. |
| 19 | + */ |
| 20 | + readonly buildId?: string; |
| 21 | + |
| 22 | + getContent(callback: (content: string, encoding: string) => unknown): void; |
| 23 | + setContent(content: string, commit: boolean, callback?: (error?: Object) => unknown): void; |
| 24 | + /** |
| 25 | + * Augments this resource's scopes information based on the list of {@link NamedFunctionRange}s |
| 26 | + * for improved debuggability and function naming. |
| 27 | + * |
| 28 | + * @throws |
| 29 | + * If this resource was not produced by a sourcemap or if {@link ranges} are not nested properly. |
| 30 | + * Concretely: For each range, start position must be less than end position, and |
| 31 | + * there must be no "straddling" (i.e. partially overlapping ranges). |
| 32 | + */ |
| 33 | + setFunctionRangesForScript(ranges: NamedFunctionRange[]): Promise<void>; |
| 34 | + attachSourceMapURL(sourceMapURL: string): Promise<void>; |
| 35 | + } |
| 36 | + |
| 37 | + export interface InspectedWindow { |
| 38 | + tabId: number; |
| 39 | + |
| 40 | + onResourceAdded: EventSink<(resource: Resource) => unknown>; |
| 41 | + onResourceContentCommitted: EventSink<(resource: Resource, content: string) => unknown>; |
| 42 | + |
| 43 | + eval( |
| 44 | + expression: string, |
| 45 | + options?: {scriptExecutionContext?: string, frameURL?: string, useContentScriptContext?: boolean}, |
| 46 | + callback?: (result: unknown, exceptioninfo: { |
| 47 | + code: string, |
| 48 | + description: string, |
| 49 | + details: unknown[], |
| 50 | + isError: boolean, |
| 51 | + isException: boolean, |
| 52 | + value: string, |
| 53 | + }) => unknown): void; |
| 54 | + getResources(callback: (resources: Resource[]) => unknown): void; |
| 55 | + reload(reloadOptions?: {ignoreCache?: boolean, injectedScript?: string, userAgent?: string}): void; |
| 56 | + } |
| 57 | + |
| 58 | + export interface Button { |
| 59 | + onClicked: EventSink<() => unknown>; |
| 60 | + update(iconPath?: string, tooltipText?: string, disabled?: boolean): void; |
| 61 | + } |
| 62 | + |
| 63 | + export interface ExtensionView { |
| 64 | + onHidden: EventSink<() => unknown>; |
| 65 | + onShown: EventSink<(window?: Window) => unknown>; |
| 66 | + } |
| 67 | + |
| 68 | + export interface ExtensionPanel extends ExtensionView { |
| 69 | + show(): void; |
| 70 | + onSearch: EventSink<(action: string, queryString?: string) => unknown>; |
| 71 | + createStatusBarButton(iconPath: string, tooltipText: string, disabled: boolean): Button; |
| 72 | + } |
| 73 | + |
| 74 | + export interface RecorderView extends ExtensionView { |
| 75 | + show(): void; |
| 76 | + } |
| 77 | + |
| 78 | + export interface ExtensionSidebarPane extends ExtensionView { |
| 79 | + setHeight(height: string): void; |
| 80 | + setObject(jsonObject: string, rootTitle?: string, callback?: () => unknown): void; |
| 81 | + setPage(path: string): void; |
| 82 | + } |
| 83 | + |
| 84 | + export interface PanelWithSidebar { |
| 85 | + createSidebarPane(title: string, callback?: (result: ExtensionSidebarPane) => unknown): void; |
| 86 | + onSelectionChanged: EventSink<() => unknown>; |
| 87 | + } |
| 88 | + |
| 89 | + export interface Panels { |
| 90 | + elements: PanelWithSidebar; |
| 91 | + sources: PanelWithSidebar; |
| 92 | + network: NetworkPanel; |
| 93 | + themeName: string; |
| 94 | + |
| 95 | + create(title: string, iconPath: string, pagePath: string, callback?: (panel: ExtensionPanel) => unknown): void; |
| 96 | + openResource(url: string, lineNumber: number, columnNumber?: number, callback?: () => unknown): void; |
| 97 | + |
| 98 | + setOpenResourceHandler( |
| 99 | + callback?: (resource: Resource, lineNumber: number, columnNumber: number) => void, scheme?: string): void; |
| 100 | + |
| 101 | + /** |
| 102 | + * Fired when the theme changes in DevTools. |
| 103 | + * |
| 104 | + * @param callback The handler callback to register and be invoked on theme changes. |
| 105 | + */ |
| 106 | + setThemeChangeHandler(callback?: (themeName: string) => unknown): void; |
| 107 | + } |
| 108 | + |
| 109 | + export interface Request { |
| 110 | + getContent(callback: (content: string, encoding: string) => unknown): void; |
| 111 | + } |
| 112 | + |
| 113 | + export interface Network { |
| 114 | + onNavigated: EventSink<(url: string) => unknown>; |
| 115 | + onRequestFinished: EventSink<(request: Request) => unknown>; |
| 116 | + |
| 117 | + getHAR(callback: (harLog: object) => unknown): void; |
| 118 | + } |
| 119 | + |
| 120 | + export interface NetworkPanel { |
| 121 | + show(options?: {filter: string}): Promise<void>; |
| 122 | + } |
| 123 | + |
| 124 | + export interface DevToolsAPI { |
| 125 | + network: Network; |
| 126 | + panels: Panels; |
| 127 | + inspectedWindow: InspectedWindow; |
| 128 | + languageServices: LanguageExtensions; |
| 129 | + recorder: RecorderExtensions; |
| 130 | + performance: Performance; |
| 131 | + } |
| 132 | + |
| 133 | + export interface ExperimentalDevToolsAPI { |
| 134 | + inspectedWindow: InspectedWindow; |
| 135 | + } |
| 136 | + |
| 137 | + export interface RawModule { |
| 138 | + url: string; |
| 139 | + code?: ArrayBuffer; |
| 140 | + } |
| 141 | + |
| 142 | + export interface RawLocationRange { |
| 143 | + rawModuleId: string; |
| 144 | + startOffset: number; |
| 145 | + endOffset: number; |
| 146 | + } |
| 147 | + |
| 148 | + export interface RawLocation { |
| 149 | + rawModuleId: string; |
| 150 | + codeOffset: number; |
| 151 | + inlineFrameIndex: number; |
| 152 | + } |
| 153 | + |
| 154 | + export interface SourceLocation { |
| 155 | + rawModuleId: string; |
| 156 | + sourceFileURL: string; |
| 157 | + lineNumber: number; |
| 158 | + columnNumber: number; |
| 159 | + } |
| 160 | + |
| 161 | + export interface Variable { |
| 162 | + scope: string; |
| 163 | + name: string; |
| 164 | + type: string; |
| 165 | + nestedName?: string[]; |
| 166 | + } |
| 167 | + |
| 168 | + export interface ScopeInfo { |
| 169 | + type: string; |
| 170 | + typeName: string; |
| 171 | + icon?: string; |
| 172 | + } |
| 173 | + |
| 174 | + export interface FunctionInfo { |
| 175 | + name: string; |
| 176 | + } |
| 177 | + |
| 178 | + export type RecorderExtensionPlugin = RecorderExtensionExportPlugin|RecorderExtensionReplayPlugin; |
| 179 | + |
| 180 | + export interface RecorderExtensionExportPlugin { |
| 181 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 182 | + stringify(recording: Record<string, any>): Promise<string>; |
| 183 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 184 | + stringifyStep(step: Record<string, any>): Promise<string>; |
| 185 | + } |
| 186 | + export interface RecorderExtensionReplayPlugin { |
| 187 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 188 | + replay(recording: Record<string, any>): void; |
| 189 | + } |
| 190 | + |
| 191 | + export type RemoteObjectId = string; |
| 192 | + export type RemoteObjectType = 'object'|'undefined'|'string'|'number'|'boolean'|'bigint'|'array'|'null'; |
| 193 | + |
| 194 | + export interface RemoteObject { |
| 195 | + type: RemoteObjectType; |
| 196 | + className?: string; |
| 197 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 198 | + value?: any; |
| 199 | + description?: string; |
| 200 | + objectId?: RemoteObjectId; |
| 201 | + linearMemoryAddress?: number; |
| 202 | + linearMemorySize?: number; |
| 203 | + hasChildren: boolean; |
| 204 | + } |
| 205 | + |
| 206 | + /** |
| 207 | + * This refers to a Javascript or a Wasm value of reference type |
| 208 | + * in the V8 engine. We call it foreign object here to emphasize |
| 209 | + * the difference with the remote objects managed by a language |
| 210 | + * extension plugin. |
| 211 | + */ |
| 212 | + export interface ForeignObject { |
| 213 | + type: 'reftype'; |
| 214 | + valueClass: 'local'|'global'|'operand'; |
| 215 | + index: number; |
| 216 | + } |
| 217 | + |
| 218 | + export interface PropertyDescriptor { |
| 219 | + name: string; |
| 220 | + value: RemoteObject|ForeignObject; |
| 221 | + } |
| 222 | + |
| 223 | + export interface LanguageExtensionPlugin { |
| 224 | + /** |
| 225 | + * A new raw module has been loaded. If the raw wasm module references an external debug info module, its URL will be |
| 226 | + * passed as symbolsURL. |
| 227 | + */ |
| 228 | + addRawModule(rawModuleId: string, symbolsURL: string|undefined, rawModule: RawModule): |
| 229 | + Promise<string[]|{missingSymbolFiles: string[]}>; |
| 230 | + |
| 231 | + /** |
| 232 | + * Find locations in raw modules from a location in a source file. |
| 233 | + */ |
| 234 | + sourceLocationToRawLocation(sourceLocation: SourceLocation): Promise<RawLocationRange[]>; |
| 235 | + |
| 236 | + /** |
| 237 | + * Find locations in source files from a location in a raw module. |
| 238 | + */ |
| 239 | + rawLocationToSourceLocation(rawLocation: RawLocation): Promise<SourceLocation[]>; |
| 240 | + |
| 241 | + /** |
| 242 | + * Return detailed information about a scope. |
| 243 | + */ |
| 244 | + getScopeInfo(type: string): Promise<ScopeInfo>; |
| 245 | + |
| 246 | + /** |
| 247 | + * List all variables in lexical scope at a given location in a raw module. |
| 248 | + */ |
| 249 | + listVariablesInScope(rawLocation: RawLocation): Promise<Variable[]>; |
| 250 | + |
| 251 | + /** |
| 252 | + * Notifies the plugin that a script is removed. |
| 253 | + */ |
| 254 | + removeRawModule(rawModuleId: string): Promise<void>; |
| 255 | + |
| 256 | + /** |
| 257 | + * Retrieve function name(s) for the function(s) containing the rawLocation. This returns more than one entry if |
| 258 | + * the location is inside of an inlined function with the innermost function at index 0. |
| 259 | + */ |
| 260 | + getFunctionInfo(rawLocation: RawLocation): Promise<{frames: FunctionInfo[], missingSymbolFiles: string[]}| |
| 261 | + {missingSymbolFiles: string[]}|{frames: FunctionInfo[]}>; |
| 262 | + |
| 263 | + /** |
| 264 | + * Find locations in raw modules corresponding to the inline function |
| 265 | + * that rawLocation is in. Used for stepping out of an inline function. |
| 266 | + */ |
| 267 | + getInlinedFunctionRanges(rawLocation: RawLocation): Promise<RawLocationRange[]>; |
| 268 | + |
| 269 | + /** |
| 270 | + * Find locations in raw modules corresponding to inline functions |
| 271 | + * called by the function or inline frame that rawLocation is in. |
| 272 | + * Used for stepping over inline functions. |
| 273 | + */ |
| 274 | + getInlinedCalleesRanges(rawLocation: RawLocation): Promise<RawLocationRange[]>; |
| 275 | + |
| 276 | + /** |
| 277 | + * Retrieve a list of line numbers in a file for which line-to-raw-location mappings exist. |
| 278 | + */ |
| 279 | + getMappedLines(rawModuleId: string, sourceFileURL: string): Promise<number[]|undefined>; |
| 280 | + |
| 281 | + /** |
| 282 | + * Evaluate a source language expression in the context of a given raw location and a given stopId. stopId is an |
| 283 | + * opaque key that should be passed to the APIs accessing wasm state, e.g., getWasmLinearMemory. A stopId is |
| 284 | + * invalidated once the debugger resumes. |
| 285 | + */ |
| 286 | + evaluate(expression: string, context: RawLocation, stopId: unknown): Promise<RemoteObject|ForeignObject|null>; |
| 287 | + |
| 288 | + /** |
| 289 | + * Retrieve properties of the remote object identified by the object id. |
| 290 | + */ |
| 291 | + getProperties(objectId: RemoteObjectId): Promise<PropertyDescriptor[]>; |
| 292 | + |
| 293 | + /** |
| 294 | + * Permanently release the remote object identified by the object id. |
| 295 | + */ |
| 296 | + releaseObject(objectId: RemoteObjectId): Promise<void>; |
| 297 | + } |
| 298 | + |
| 299 | + export interface SupportedScriptTypes { |
| 300 | + language: string; |
| 301 | + // eslint-disable-next-line @typescript-eslint/naming-convention |
| 302 | + symbol_types: string[]; |
| 303 | + } |
| 304 | + |
| 305 | + export type WasmValue = {type: 'i32'|'f32'|'f64', value: number}|{type: 'i64', value: bigint}| |
| 306 | + {type: 'v128', value: string}|ForeignObject; |
| 307 | + |
| 308 | + export interface LanguageExtensions { |
| 309 | + registerLanguageExtensionPlugin( |
| 310 | + plugin: LanguageExtensionPlugin, pluginName: string, |
| 311 | + supportedScriptTypes: SupportedScriptTypes): Promise<void>; |
| 312 | + unregisterLanguageExtensionPlugin(plugin: LanguageExtensionPlugin): Promise<void>; |
| 313 | + |
| 314 | + getWasmLinearMemory(offset: number, length: number, stopId: unknown): Promise<ArrayBuffer>; |
| 315 | + getWasmLocal(local: number, stopId: unknown): Promise<WasmValue>; |
| 316 | + getWasmGlobal(global: number, stopId: unknown): Promise<WasmValue>; |
| 317 | + getWasmOp(op: number, stopId: unknown): Promise<WasmValue>; |
| 318 | + |
| 319 | + reportResourceLoad(resourceUrl: string, status: {success: boolean, errorMessage?: string, size?: number}): |
| 320 | + Promise<void>; |
| 321 | + } |
| 322 | + |
| 323 | + export interface Position { |
| 324 | + line: number; |
| 325 | + column: number; |
| 326 | + } |
| 327 | + |
| 328 | + export interface NamedFunctionRange { |
| 329 | + readonly name: string; |
| 330 | + readonly start: Position; |
| 331 | + readonly end: Position; |
| 332 | + } |
| 333 | + |
| 334 | + export interface RecorderExtensions { |
| 335 | + registerRecorderExtensionPlugin(plugin: RecorderExtensionPlugin, pluginName: string, mediaType?: string): |
| 336 | + Promise<void>; |
| 337 | + unregisterRecorderExtensionPlugin(plugin: RecorderExtensionPlugin): Promise<void>; |
| 338 | + createView(title: string, pagePath: string): Promise<RecorderView>; |
| 339 | + } |
| 340 | + |
| 341 | + export interface Performance { |
| 342 | + onProfilingStarted: EventSink<() => unknown>; |
| 343 | + onProfilingStopped: EventSink<() => unknown>; |
| 344 | + } |
| 345 | + |
| 346 | + export interface Chrome { |
| 347 | + devtools: DevToolsAPI; |
| 348 | + experimental: {devtools: ExperimentalDevToolsAPI}; |
| 349 | + } |
| 350 | + } |
| 351 | +} |
| 352 | + |
| 353 | +declare global { |
| 354 | + interface Window { |
| 355 | + chrome: Chrome.DevTools.Chrome; |
| 356 | + } |
| 357 | +} |
0 commit comments