Target

Supports additional targets discovery and allows to attach to them.

Commands

Target.activateTarget

Activates (focuses) the target.

Parameters
Name Type Description
targetId TargetID

Target.attachToTarget

Attaches to the target with given id.

Parameters
Name Type Description
targetId TargetID
flatten (optional) boolean Enables "flat" access to the session via specifying sessionId attribute in the commands.
We plan to make this the default, deprecate non-flattened mode,
and eventually retire it. See crbug.com/991325.
Return Object
Name Type Description
sessionId SessionID Id assigned to the session.

Target.attachToBrowserTarget

Experimental

Attaches to the browser target, only uses flat sessionId mode.

Return Object
Name Type Description
sessionId SessionID Id assigned to the session.

Target.closeTarget

Closes the target. If the target is a page that gets closed too.

Parameters
Name Type Description
targetId TargetID
Return Object
Name Type Description
success Deprecated boolean Always set to true. If an error occurs, the response indicates protocol error.

Target.exposeDevToolsProtocol

Experimental

Inject object to the target's main frame that provides a communication
channel with browser target.

Injected object will be available as `window[bindingName]`.

The object has the following API:
- `binding.send(json)` - a method to send messages over the remote debugging protocol
- `binding.onmessage = json => handleMessage(json)` - a callback that will be called for the protocol notifications and command responses.

Parameters
Name Type Description
targetId TargetID
bindingName (optional) string Binding name, 'cdp' if not specified.
inheritPermissions (optional) boolean If true, inherits the current root session's permissions (default: false).

Target.createBrowserContext

Creates a new empty BrowserContext. Similar to an incognito profile but you can have more than
one.

Parameters
Name Type Description
disposeOnDetach (optional) Experimental boolean If specified, disposes this context when debugging session disconnects.
proxyServer (optional) Experimental string Proxy server, similar to the one passed to --proxy-server
proxyBypassList (optional) Experimental string Proxy bypass list, similar to the one passed to --proxy-bypass-list
originsWithUniversalNetworkAccess (optional) Experimental array<string> An optional list of origins to grant unlimited cross-origin access to.
Parts of the URL other than those constituting origin are ignored.
Return Object
Name Type Description
browserContextId Browser.BrowserContextID The id of the context created.

Target.getBrowserContexts

Returns all browser contexts created with `Target.createBrowserContext` method.

Return Object
Name Type Description
browserContextIds array<Browser.BrowserContextID> An array of browser context ids.
defaultBrowserContextId (optional) Experimental Browser.BrowserContextID The id of the default browser context if available.

Target.createTarget

Creates a new page.

Parameters
Name Type Description
url string The initial URL the page will be navigated to. An empty string indicates about:blank.
left (optional) Experimental integer Frame left origin in DIP (requires newWindow to be true or headless shell).
top (optional) Experimental integer Frame top origin in DIP (requires newWindow to be true or headless shell).
width (optional) integer Frame width in DIP (requires newWindow to be true or headless shell).
height (optional) integer Frame height in DIP (requires newWindow to be true or headless shell).
windowState (optional) WindowState Frame window state (requires newWindow to be true or headless shell).
Default is normal.
browserContextId (optional) Experimental Browser.BrowserContextID The browser context to create the page in.
enableBeginFrameControl (optional) Experimental boolean Whether BeginFrames for this target will be controlled via DevTools (headless shell only,
not supported on MacOS yet, false by default).
newWindow (optional) boolean Whether to create a new Window or Tab (false by default, not supported by headless shell).
background (optional) boolean Whether to create the target in background or foreground (false by default, not supported
by headless shell).
forTab (optional) Experimental boolean Whether to create the target of type "tab".
hidden (optional) Experimental boolean Whether to create a hidden target. The hidden target is observable via protocol, but not
present in the tab UI strip. Cannot be created with `forTab: true`, `newWindow: true` or
`background: false`. The life-time of the tab is limited to the life-time of the session.
focus (optional) Experimental boolean If specified, the option is used to determine if the new target should
be focused or not. By default, the focus behavior depends on the
value of the background field. For example, background=false and focus=false
will result in the target tab being opened but the browser window remain
unchanged (if it was in the background, it will remain in the background)
and background=false with focus=undefined will result in the window being focused.
Using background: true and focus: true is not supported and will result in an error.
Return Object
Name Type Description
targetId TargetID The id of the page opened.

Target.detachFromTarget

Detaches session with given id.

Parameters
Name Type Description
sessionId (optional) SessionID Session to detach.
targetId (optional) Deprecated TargetID Deprecated.

Target.disposeBrowserContext

Deletes a BrowserContext. All the belonging pages will be closed without calling their
beforeunload hooks.

Parameters
Name Type Description
browserContextId Browser.BrowserContextID

Target.getTargetInfo

Experimental

Returns information about a target.

Parameters
Name Type Description
targetId (optional) TargetID
Return Object
Name Type Description
targetInfo TargetInfo

Target.getTargets

Retrieves a list of available targets.

Parameters
Name Type Description
filter (optional) Experimental TargetFilter Only targets matching filter will be reported. If filter is not specified
and target discovery is currently enabled, a filter used for target discovery
is used for consistency.
Return Object
Name Type Description
targetInfos array<TargetInfo> The list of targets.

Target.sendMessageToTarget

Deprecated

Sends protocol message over session with given id.
Consider using flat mode instead; see commands attachToTarget, setAutoAttach,
and crbug.com/991325.

Parameters
Name Type Description
message string
sessionId (optional) SessionID Identifier of the session.
targetId (optional) Deprecated TargetID Deprecated.

Target.setAutoAttach

Controls whether to automatically attach to new targets which are considered
to be directly related to this one (for example, iframes or workers).
When turned on, attaches to all existing related targets as well. When turned off,
automatically detaches from all currently attached targets.
This also clears all targets added by `autoAttachRelated` from the list of targets to watch
for creation of related targets.
You might want to call this recursively for auto-attached targets to attach
to all available targets.

Parameters
Name Type Description
autoAttach boolean Whether to auto-attach to related targets.
waitForDebuggerOnStart boolean Whether to pause new targets when attaching to them. Use `Runtime.runIfWaitingForDebugger`
to run paused targets.
flatten (optional) Experimental boolean Enables "flat" access to the session via specifying sessionId attribute in the commands.
We plan to make this the default, deprecate non-flattened mode,
and eventually retire it. See crbug.com/991325.
filter (optional) Experimental TargetFilter Only targets matching filter will be attached.

Target.autoAttachRelated

Experimental

Adds the specified target to the list of targets that will be monitored for any related target
creation (such as child frames, child workers and new versions of service worker) and reported
through `attachedToTarget`. The specified target is also auto-attached.
This cancels the effect of any previous `setAutoAttach` and is also cancelled by subsequent
`setAutoAttach`. Only available at the Browser target.

Parameters
Name Type Description
targetId TargetID
waitForDebuggerOnStart boolean Whether to pause new targets when attaching to them. Use `Runtime.runIfWaitingForDebugger`
to run paused targets.
filter (optional) Experimental TargetFilter Only targets matching filter will be attached.

Target.setDiscoverTargets

Controls whether to discover available targets and notify via
`targetCreated/targetInfoChanged/targetDestroyed` events.

Parameters
Name Type Description
discover boolean Whether to discover available targets.
filter (optional) Experimental TargetFilter Only targets matching filter will be attached. If `discover` is false,
`filter` must be omitted or empty.

Target.setRemoteLocations

Experimental

Enables target discovery for the specified locations, when `setDiscoverTargets` was set to
`true`.

Parameters
Name Type Description
locations array<RemoteLocation> List of remote locations.

Target.getDevToolsTarget

Experimental

Gets the targetId of the DevTools page target opened for the given target
(if any).

Parameters
Name Type Description
targetId TargetID Page or tab target ID.
Return Object
Name Type Description
targetId (optional) TargetID The targetId of DevTools page target if exists.

Target.openDevTools

Experimental

Opens a DevTools window for the target.

Parameters
Name Type Description
targetId TargetID This can be the page or tab target ID.
panelId (optional) string The id of the panel we want DevTools to open initially. Currently
supported panels are elements, console, network, sources, resources
and performance.
Return Object
Name Type Description
targetId TargetID The targetId of DevTools page target.

Events

Target.attachedToTarget

Experimental

Issued when attached to target because of auto-attach or `attachToTarget` command.

Parameters
Name Type Description
sessionId SessionID Identifier assigned to the session used to send/receive messages.
targetInfo TargetInfo
waitingForDebugger boolean

Target.detachedFromTarget

Experimental

Issued when detached from target for any reason (including `detachFromTarget` command). Can be
issued multiple times per target if multiple sessions have been attached to it.

Parameters
Name Type Description
sessionId SessionID Detached session identifier.
targetId (optional) Deprecated TargetID Deprecated.

Target.receivedMessageFromTarget

Notifies about a new protocol message received from the session (as reported in
`attachedToTarget` event).

Parameters
Name Type Description
sessionId SessionID Identifier of a session which sends a message.
message string
targetId (optional) Deprecated TargetID Deprecated.

Target.targetCreated

Issued when a possible inspection target is created.

Parameters
Name Type Description
targetInfo TargetInfo

Target.targetDestroyed

Issued when a target is destroyed.

Parameters
Name Type Description
targetId TargetID

Target.targetCrashed

Issued when a target has crashed.

Parameters
Name Type Description
targetId TargetID
status string Termination status type.
errorCode integer Termination error code.

Target.targetInfoChanged

Issued when some information about a target has changed. This only happens between
`targetCreated` and `targetDestroyed`.

Parameters
Name Type Description
targetInfo TargetInfo

Types

TargetID

(string)

SessionID

(string)

Unique identifier of attached debugging session.

TargetInfo

(object)
Properties
Name Type Description
targetId TargetID
type string List of types: https://source.chromium.org/chromium/chromium/src/+/main:content/browser/devtools/devtools_agent_host_impl.cc?ss=chromium&q=f:devtools%20-f:out%20%22::kTypeTab%5B%5D%22
title string
url string
attached boolean Whether the target has an attached client.
openerId (optional) TargetID Opener target Id
canAccessOpener Experimental boolean Whether the target has access to the originating window.
openerFrameId (optional) Experimental Page.FrameId Frame id of originating window (is only set if target has an opener).
parentFrameId (optional) Experimental Page.FrameId Id of the parent frame, only present for the "iframe" targets.
browserContextId (optional) Experimental Browser.BrowserContextID
subtype (optional) Experimental string Provides additional details for specific target types. For example, for
the type of "page", this may be set to "prerender".

FilterEntry

(object) Experimental

A filter used by target query/discovery/auto-attach operations.

Properties
Name Type Description
exclude (optional) boolean If set, causes exclusion of matching targets from the list.
type (optional) string If not present, matches any type.

TargetFilter

(array) Experimental

The entries in TargetFilter are matched sequentially against targets and
the first entry that matches determines if the target is included or not,
depending on the value of `exclude` field in the entry.
If filter is not specified, the one assumed is
[{type: "browser", exclude: true}, {type: "tab", exclude: true}, {}]
(i.e. include everything but `browser` and `tab`).

RemoteLocation

(object) Experimental
Properties
Name Type Description
host string
port integer

WindowState

(string) Experimental

The state of the target window.

Allowed Values
  • normal
  • minimized
  • maximized
  • fullscreen

Summary