Target Domain
Supports additional targets discovery and allows to attach to them.
Methods
- Target.activateTarget
- Target.attachToTarget
- Target.closeTarget
- Target.createBrowserContext
- Target.createTarget
- Target.detachFromTarget
- Target.disposeBrowserContext
- Target.getBrowserContexts
- Target.getTargets
- Target.setAutoAttach
- Target.setDiscoverTargets
- Target.sendMessageToTarget Deprecated
- Target.attachToBrowserTarget Experimental
- Target.autoAttachRelated Experimental
- Target.exposeDevToolsProtocol Experimental
- Target.getTargetInfo Experimental
- Target.openDevTools Experimental
- Target.setRemoteLocations Experimental
Events
- Target.receivedMessageFromTarget
- Target.targetCrashed
- Target.targetCreated
- Target.targetDestroyed
- Target.targetInfoChanged
- Target.attachedToTarget Experimental
- Target.detachedFromTarget Experimental
Types
- Target.SessionID
- Target.TargetID
- Target.TargetInfo
- Target.FilterEntry Experimental
- Target.RemoteLocation Experimental
- Target.TargetFilter Experimental
- Target.WindowState Experimental
Methods
Target.attachToTarget #
Attaches to the target with given id.
Parameters
targetId flattenOptional
booleanEnables "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
sessionId Id assigned to the session.
Target.closeTarget #
Closes the target. If the target is a page that gets closed too.
Parameters
targetId Return object
success booleanAlways set to true. If an error occurs, the response indicates protocol error.
Target.createBrowserContext #
Creates a new empty BrowserContext. Similar to an incognito profile but you can have more than one.
Parameters
disposeOnDetachOptional
booleanIf specified, disposes this context when debugging session disconnects.
proxyServerOptional
stringProxy server, similar to the one passed to --proxy-server
proxyBypassListOptional
stringProxy bypass list, similar to the one passed to --proxy-bypass-list
originsWithUniversalNetworkAccessOptional
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
browserContextId The id of the context created.
Target.createTarget #
Creates a new page.
Parameters
url stringThe initial URL the page will be navigated to. An empty string indicates about:blank.
leftOptional
integerFrame left origin in DIP (requires newWindow to be true or headless shell).
topOptional
integerFrame top origin in DIP (requires newWindow to be true or headless shell).
widthOptional
integerFrame width in DIP (requires newWindow to be true or headless shell).
heightOptional
integerFrame height in DIP (requires newWindow to be true or headless shell).
windowStateOptional
Frame window state (requires newWindow to be true or headless shell). Default is normal.
browserContextIdOptional
enableBeginFrameControlOptional
booleanWhether BeginFrames for this target will be controlled via DevTools (headless shell only, not supported on MacOS yet, false by default).
newWindowOptional
booleanWhether to create a new Window or Tab (false by default, not supported by headless shell).
backgroundOptional
booleanWhether to create the target in background or foreground (false by default, not supported by headless shell).
forTabOptional
booleanWhether to create the target of type "tab".
hiddenOptional
booleanWhether 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.
Return object
targetId The id of the page opened.
Target.detachFromTarget #
Detaches session with given id.
Parameters
sessionIdOptional
Session to detach.
targetIdOptional
Target.disposeBrowserContext #
Deletes a BrowserContext. All the belonging pages will be closed without calling their beforeunload hooks.
Parameters
browserContextId Target.getBrowserContexts #
Returns all browser contexts created with Target.createBrowserContext method.
Return object
browserContextIds array[ Browser.BrowserContextID ]An array of browser context ids.
Target.getTargets #
Retrieves a list of available targets.
Parameters
filterOptional
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
targetInfos array[ TargetInfo ]The list of targets.
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
autoAttach booleanWhether to auto-attach to related targets.
waitForDebuggerOnStart booleanWhether to pause new targets when attaching to them. Use Runtime.runIfWaitingForDebugger
to run paused targets.
flattenOptional
booleanEnables "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.
filterOptional
Target.setDiscoverTargets #
Controls whether to discover available targets and notify via
targetCreated/targetInfoChanged/targetDestroyed events.
Parameters
discover booleanWhether to discover available targets.
filterOptional
Only targets matching filter will be attached. If discover is false,
filter must be omitted or empty.
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
message stringsessionIdOptional
Identifier of the session.
targetIdOptional
Target.attachToBrowserTarget Experimental#
Attaches to the browser target, only uses flat sessionId mode.
Return object
sessionId Id assigned to the session.
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
targetId waitForDebuggerOnStart booleanWhether to pause new targets when attaching to them. Use Runtime.runIfWaitingForDebugger
to run paused targets.
filterOptional
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 protocolbinding.onmessage = json => handleMessage(json)- a callback that will be called for the protocol notifications and command responses.
Parameters
targetId bindingNameOptional
stringBinding name, 'cdp' if not specified.
inheritPermissionsOptional
booleanIf true, inherits the current root session's permissions (default: false).
Target.getTargetInfo Experimental#
Returns information about a target.
Parameters
targetIdOptional
Return object
targetInfo Target.openDevTools Experimental#
Opens a DevTools window for the target.
Parameters
targetId This can be the page or tab target ID.
Return object
targetId The targetId of DevTools page target.
Target.setRemoteLocations Experimental#
Enables target discovery for the specified locations, when setDiscoverTargets was set to
true.
Parameters
locations array[ RemoteLocation ]List of remote locations.
Events
Target.receivedMessageFromTarget #
Notifies about a new protocol message received from the session (as reported in
attachedToTarget event).
Parameters
sessionId Identifier of a session which sends a message.
message stringtargetIdOptional
Target.targetCrashed #
Issued when a target has crashed.
Parameters
targetId status stringTermination status type.
errorCode integerTermination error code.
Target.targetInfoChanged #
Issued when some information about a target has changed. This only happens between
targetCreated and targetDestroyed.
Parameters
targetInfo Target.attachedToTarget Experimental#
Issued when attached to target because of auto-attach or attachToTarget command.
Parameters
sessionId Identifier assigned to the session used to send/receive messages.
targetInfo waitingForDebugger booleanTypes
Target.TargetInfo #
Type: object
Properties
targetId type stringList 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 stringurl stringattached booleanWhether the target has an attached client.
openerIdOptional
Opener target Id
canAccessOpener booleanWhether the target has access to the originating window.
openerFrameIdOptional
parentFrameIdOptional
browserContextIdOptional
subtypeOptional
stringProvides additional details for specific target types. For example, for the type of "page", this may be set to "prerender".
Target.FilterEntry Experimental#
A filter used by target query/discovery/auto-attach operations.
Type: object
Properties
excludeOptional
booleanIf set, causes exclusion of matching targets from the list.
typeOptional
stringIf not present, matches any type.
Target.TargetFilter 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).
Type: array[ FilterEntry ]
Target.WindowState Experimental#
The state of the target window.
Type: string
Allowed values: normal, minimized, maximized, fullscreen