Package io.webfolder.cdp.command
Interface Target
public interface Target
Supports additional targets discovery and allows to attach to them.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
activateTarget
(String targetId) Activates (focuses) the target.Attaches to the browser target, only uses flat sessionId mode.attachToTarget
(String targetId) Attaches to the target with given id.attachToTarget
(String targetId, Boolean flatten) Attaches to the target with given id.void
autoAttachRelated
(String targetId, Boolean waitForDebuggerOnStart) 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.closeTarget
(String targetId) Closes the target.Creates a new empty BrowserContext.createBrowserContext
(Boolean disposeOnDetach, String proxyServer, String proxyBypassList, List<String> originsWithUniversalNetworkAccess) Creates a new empty BrowserContext.createTarget
(String url) Creates a new page.createTarget
(String url, Integer width, Integer height, String browserContextId, Boolean enableBeginFrameControl, Boolean newWindow, Boolean background) Creates a new page.void
Detaches session with given id.void
detachFromTarget
(String sessionId, String targetId) Detaches session with given id.void
disposeBrowserContext
(String browserContextId) Deletes a BrowserContext.void
exposeDevToolsProtocol
(String targetId) Inject object to the target's main frame that provides a communication channel with browser target.void
exposeDevToolsProtocol
(String targetId, String bindingName) Inject object to the target's main frame that provides a communication channel with browser target.Returns all browser contexts created with Target.createBrowserContext method.Returns information about a target.getTargetInfo
(String targetId) Returns information about a target.Retrieves a list of available targets.void
sendMessageToTarget
(String message) Deprecated.void
sendMessageToTarget
(String message, String sessionId, String targetId) Deprecated.void
setAutoAttach
(Boolean autoAttach, Boolean waitForDebuggerOnStart) Controls whether to automatically attach to new targets which are considered to be related to this one.void
setAutoAttach
(Boolean autoAttach, Boolean waitForDebuggerOnStart, Boolean flatten) Controls whether to automatically attach to new targets which are considered to be related to this one.void
setDiscoverTargets
(Boolean discover) Controls whether to discover available targets and notify via targetCreated/targetInfoChanged/targetDestroyed events.void
setRemoteLocations
(List<RemoteLocation> locations) Enables target discovery for the specified locations, when setDiscoverTargets was set to true.
-
Method Details
-
activateTarget
Activates (focuses) the target. -
attachToBrowserTarget
String attachToBrowserTarget()Attaches to the browser target, only uses flat sessionId mode.- Returns:
- Id assigned to the session.
-
attachToTarget
Attaches to the target with given id.- Returns:
- Id assigned to the session.
-
attachToTarget
Attaches to the target with given id.- Parameters:
flatten
- 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.- Returns:
- Id assigned to the session.
-
autoAttachRelated
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:
waitForDebuggerOnStart
- Whether to pause new targets when attaching to them. Use Runtime.runIfWaitingForDebugger to run paused targets.filter
- Only targets matching filter will be attached.
-
closeTarget
Closes the target. If the target is a page that gets closed too.- Returns:
- Always set to true. If an error occurs, the response indicates protocol error.
-
createBrowserContext
String createBrowserContext()Creates a new empty BrowserContext. Similar to an incognito profile but you can have more than one.- Returns:
- The id of the context created.
-
createBrowserContext
String createBrowserContext(Boolean disposeOnDetach, String proxyServer, String proxyBypassList, List<String> originsWithUniversalNetworkAccess) Creates a new empty BrowserContext. Similar to an incognito profile but you can have more than one.- Parameters:
disposeOnDetach
- If specified, disposes this context when debugging session disconnects.proxyServer
- Proxy server, similar to the one passed to --proxy-serverproxyBypassList
- Proxy bypass list, similar to the one passed to --proxy-bypass-listoriginsWithUniversalNetworkAccess
- An optional list of origins to grant unlimited cross-origin access to. Parts of the URL other than those constituting origin are ignored.- Returns:
- The id of the context created.
-
createTarget
Creates a new page.- Parameters:
url
- The initial URL the page will be navigated to. An empty string indicates about:blank.- Returns:
- The id of the page opened.
-
createTarget
String createTarget(String url, Integer width, Integer height, String browserContextId, Boolean enableBeginFrameControl, Boolean newWindow, Boolean background) Creates a new page.- Parameters:
url
- The initial URL the page will be navigated to. An empty string indicates about:blank.width
- Frame width in DIP (headless chrome only).height
- Frame height in DIP (headless chrome only).browserContextId
- The browser context to create the page in.enableBeginFrameControl
- Whether BeginFrames for this target will be controlled via DevTools (headless chrome only, not supported on MacOS yet, false by default).newWindow
- Whether to create a new Window or Tab (chrome-only, false by default).background
- Whether to create the target in background or foreground (chrome-only, false by default).- Returns:
- The id of the page opened.
-
detachFromTarget
void detachFromTarget()Detaches session with given id. -
detachFromTarget
Detaches session with given id.- Parameters:
sessionId
- Session to detach.targetId
- Deprecated.
-
disposeBrowserContext
Deletes a BrowserContext. All the belonging pages will be closed without calling their beforeunload hooks. -
exposeDevToolsProtocol
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 follwing 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. -
exposeDevToolsProtocol
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 follwing 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:
bindingName
- Binding name, 'cdp' if not specified.
-
getBrowserContexts
Returns all browser contexts created with Target.createBrowserContext method.- Returns:
- An array of browser context ids.
-
getTargetInfo
TargetInfo getTargetInfo()Returns information about a target. -
getTargetInfo
Returns information about a target. -
getTargets
List<TargetInfo> getTargets()Retrieves a list of available targets.- Parameters:
filter
- 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.- Returns:
- The list of targets.
-
sendMessageToTarget
Deprecated.Sends protocol message over session with given id. Consider using flat mode instead; see commands attachToTarget, setAutoAttach, and crbug.com/991325. -
sendMessageToTarget
Deprecated.Sends protocol message over session with given id. Consider using flat mode instead; see commands attachToTarget, setAutoAttach, and crbug.com/991325.- Parameters:
sessionId
- Identifier of the session.targetId
- Deprecated.
-
setAutoAttach
Controls whether to automatically attach to new targets which are considered to be related to this one. 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.- Parameters:
autoAttach
- Whether to auto-attach to related targets.waitForDebuggerOnStart
- Whether to pause new targets when attaching to them. Use Runtime.runIfWaitingForDebugger to run paused targets.
-
setAutoAttach
Controls whether to automatically attach to new targets which are considered to be related to this one. 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.- Parameters:
autoAttach
- Whether to auto-attach to related targets.waitForDebuggerOnStart
- Whether to pause new targets when attaching to them. Use Runtime.runIfWaitingForDebugger to run paused targets.flatten
- 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
- Only targets matching filter will be attached.
-
setDiscoverTargets
Controls whether to discover available targets and notify via targetCreated/targetInfoChanged/targetDestroyed events.- Parameters:
discover
- Whether to discover available targets.
-
setRemoteLocations
Enables target discovery for the specified locations, when setDiscoverTargets was set to true.- Parameters:
locations
- List of remote locations.
-