Description
The chrome.debugger API serves as an alternate transport for Chrome's remote debugging protocol. Use chrome.debugger to attach to one or more tabs to instrument network interaction, debug JavaScript, mutate the DOM and CSS, and more. Use the Debuggee property tabId to target tabs with sendCommand and route events by tabId from onEvent callbacks.
Permissions
debuggerSecurity Note
For security reasons, the chrome.debugger API does not provide access to all Chrome DevTools
Protocol Domains. The available domains are: Accessibility,
Audits, CacheStorage, Console,
CSS, Database, Debugger, DOM,
DOMDebugger, DOMSnapshot,
Emulation, Fetch, IO, Input,
Inspector, Log, Network, Overlay,
Page, Performance, Profiler,
Runtime, Storage, Target, Tracing,
WebAudio, and WebAuthn.
Manifest
You must declare the "debugger"` permission in your extension's manifest to use this API.
{
  "name": "My extension",
  ...
  "permissions": [
    "debugger",
  ],
  ...
}
Examples
To try this API, install the debugger API example from the chrome-extension-samples repository.
Types
Debuggee
Debuggee identifier. Either tabId, extensionId or targetId must be specified
Properties
- 
    extensionIdstring optional The id of the extension which you intend to debug. Attaching to an extension background page is only possible when the --silent-debugger-extension-apicommand-line switch is used.
- 
    tabIdnumber optional The id of the tab which you intend to debug. 
- 
    targetIdstring optional The opaque id of the debug target. 
DebuggerSession
Debugger session identifier. One of tabId, extensionId or targetId must be specified. Additionally, an optional sessionId can be provided. If sessionId is specified for arguments sent from onEvent, it means the event is coming from a child protocol session within the root debuggee session. If sessionId is specified when passed to sendCommand, it targets a child protocol session within the root debuggee session.
Properties
- 
    extensionIdstring optional The id of the extension which you intend to debug. Attaching to an extension background page is only possible when the --silent-debugger-extension-apicommand-line switch is used.
- 
    sessionIdstring optional The opaque id of the Chrome DevTools Protocol session. Identifies a child session within the root session identified by tabId, extensionId or targetId. 
- 
    tabIdnumber optional The id of the tab which you intend to debug. 
- 
    targetIdstring optional The opaque id of the debug target. 
DetachReason
Connection termination reason.
Enum
"target_closed"  "canceled_by_user" 
 
 
TargetInfo
Debug target information
Properties
- 
    attachedboolean True if debugger is already attached. 
- 
    extensionIdstring optional The extension id, defined if type = 'background_page'. 
- 
    faviconUrlstring optional Target favicon URL. 
- 
    idstring Target id. 
- 
    tabIdnumber optional The tab id, defined if type == 'page'. 
- 
    titlestring Target page title. 
- 
    typeTarget type. 
- 
    urlstring Target URL. 
TargetInfoType
Target type.
Enum
"page"  "background_page"  "worker"  "other" 
 
 
 
 
Methods
attach()
chrome.debugger.attach(
target: Debuggee,
requiredVersion: string,
callback?: function,
): Promise<void>
Attaches debugger to the given target.
Parameters
- 
    targetDebugging target to which you want to attach. 
- 
    requiredVersionstring Required debugging protocol version ("0.1"). One can only attach to the debuggee with matching major version and greater or equal minor version. List of the protocol versions can be obtained here. 
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
detach()
chrome.debugger.detach(
target: Debuggee,
callback?: function,
): Promise<void>
Detaches debugger from the given target.
Parameters
- 
    targetDebugging target from which you want to detach. 
- 
    callbackfunction optional The callbackparameter looks like:() => void 
Returns
- 
            Promise<void> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
getTargets()
chrome.debugger.getTargets(
callback?: function,
): Promise<TargetInfo[]>
Returns the list of available debug targets.
Parameters
- 
    callbackfunction optional The callbackparameter looks like:(result: TargetInfo[]) => void - 
    resultArray of TargetInfo objects corresponding to the available debug targets. 
 
- 
    
Returns
- 
            Promise<TargetInfo[]> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
sendCommand()
chrome.debugger.sendCommand(
target: DebuggerSession,
method: string,
commandParams?: object,
callback?: function,
): Promise<object | undefined>
Sends given command to the debugging target.
Parameters
- 
    targetDebugging target to which you want to send the command. 
- 
    methodstring Method name. Should be one of the methods defined by the remote debugging protocol. 
- 
    commandParamsobject optional JSON object with request parameters. This object must conform to the remote debugging params scheme for given method. 
- 
    callbackfunction optional The callbackparameter looks like:(result?: object) => void - 
    resultobject optional JSON object with the response. Structure of the response varies depending on the method name and is defined by the 'returns' attribute of the command description in the remote debugging protocol. 
 
- 
    
Returns
- 
            Promise<object | undefined> Chrome 96+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
Events
onDetach
chrome.debugger.onDetach.addListener(
callback: function,
)
Fired when browser terminates debugging session for the tab. This happens when either the tab is being closed or Chrome DevTools is being invoked for the attached tab.
Parameters
- 
    callbackfunction The callbackparameter looks like:(source: Debuggee, reason: DetachReason) => void - 
    source
- 
    reason
 
- 
    
onEvent
chrome.debugger.onEvent.addListener(
callback: function,
)
Fired whenever debugging target issues instrumentation event.
Parameters
- 
    callbackfunction The callbackparameter looks like:(source: DebuggerSession, method: string, params?: object) => void - 
    source
- 
    methodstring 
- 
    paramsobject optional 
 
-