Stay organized with collections Save and categorize content based on your preferences.
DescriptionThe 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.
debugger
You must declare the "debugger"
permission in your extension's manifest to use this API.
{
"name": "My extension",
...
"permissions": [
"debugger",
],
...
}
Concepts and usage
Once attached, the chrome.debugger
API lets you send Chrome DevTools Protocol (CDP) commands to a given target. Explaining the CDP in depth is out of scope for this documentation—to learn more about CDP check out the official CDP documentation.
Targets represent something which is being debugged—this could include a tab, an iframe or a worker. Each target is identified by a UUID and has an associated type (such as iframe
, shared_worker
, and more).
Within a target, there may be multiple execution contexts—for example same process iframes don't get a unique target but are instead represented as different contexts that can be accessed from a single target.
Restricted domainsFor 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.
There is not a one to one mapping of frames to targets. Within a single tab, multiple same process frames may share the same target but use a different execution context. On the other hand, a new target may be created for an out-of-process iframe.
To attach to all frames, you need to handle each type of frame separately:
Listen for the Runtime.executionContextCreated
event to identify new execution contexts associated with same process frames.
Follow the steps to attach to related targets to identify out-of-process frames.
After connecting to a target, you may want to connect to further related targets including out-of-process child frames or associated workers.
Starting in Chrome 125, the chrome.debugger
API supports flat sessions. This lets you add additional targets as children to your main debugger session and message them without needing another call to chrome.debugger.attach
. Instead, you can add a sessionId
property when calling chrome.debugger.sendCommand
to identify the child target you would like to send a command to.
To automatically attach to out of process child frames, first add a listener for the Target.attachedToTarget
event:
chrome.debugger.onEvent.addListener((source, method, params) => {
if (method === "Target.attachedToTarget") {
// `source` identifies the parent session, but we need to construct a new
// identifier for the child session
const session = { ...source, sessionId: params.sessionId };
// Call any needed CDP commands for the child session
await chrome.debugger.sendCommand(session, "Runtime.enable");
}
});
Then, enable auto attach by sending the Target.setAutoAttach
command with the flatten
option set to true
:
await chrome.debugger.sendCommand({ tabId }, "Target.setAutoAttach", {
autoAttach: true,
waitForDebuggerOnStart: false,
flatten: true,
filter: [{ type: "iframe", exclude: false }]
});
Auto-attach only attaches to frames the target is aware of, which is limited to frames which are immediate children of a frame associated with it. For example, with the frame hierarchy A -> B -> C (where all are cross-origin), calling Target.setAutoAttach
for the target associated with A would result in the session also being attached to B. However, this is not recursive, so Target.setAutoAttach
also needs to be called for B to attach the session to C.
To try this API, install the debugger API example from the chrome-extension-samples repository.
Types DebuggeeDebuggee identifier. Either tabId, extensionId or targetId must be specified
PropertiesextensionId
string 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-api
command-line switch is used.
The id of the tab which you intend to debug.
The opaque id of the debug target.
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.
extensionId
string 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-api
command-line switch is used.
sessionId
string optional
The opaque id of the Chrome DevTools Protocol session. Identifies a child session within the root session identified by tabId, extensionId or targetId.
The id of the tab which you intend to debug.
The opaque id of the debug target.
Connection termination reason.
Enum"target_closed"
"canceled_by_user"
Debug target information
PropertiesTrue if debugger is already attached.
extensionId
string optional
The extension id, defined if type = 'background_page'.
faviconUrl
string optional
Target favicon URL.
Target id.
The tab id, defined if type == 'page'.
Target page title.
Target type.
Target URL.
Target type.
Enum"page"
"background_page"
"worker"
"other"
chrome.debugger.attach(
target: Debuggee,
requiredVersion: string,
): Promise<void>
Attaches debugger to the given target.
ParametersDebugging target to which you want to attach.
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.
chrome.debugger.detach(
target: Debuggee,
): Promise<void>
Detaches debugger from the given target.
ParametersDebugging target from which you want to detach.
chrome.debugger.getTargets(): Promise<TargetInfo[]>
Returns the list of available debug targets.
sendCommand()chrome.debugger.sendCommand(
target: DebuggerSession,
method: string,
commandParams?: object,
): Promise<object | undefined>
Sends given command to the debugging target.
ParametersDebugging target to which you want to send the command.
Method name. Should be one of the methods defined by the remote debugging protocol.
commandParams
object optional
JSON object with request parameters. This object must conform to the remote debugging params scheme for given method.
Promise<object | undefined>
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.
onEventchrome.debugger.onEvent.addListener(
callback: function,
)
Fired whenever debugging target issues instrumentation event.
ParametersThe callback
parameter looks like:
(source: DebuggerSession, method: string, params?: object) => void
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-11 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-11 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4