Package io.webfolder.cdp.command
Interface Target
public interface Target
Supports additional targets discovery and allows to attach to them
-
Method Summary
Modifier and Type Method Description voidactivateTarget(java.lang.String targetId)Activates (focuses) the target.java.lang.StringattachToBrowserTarget()Attaches to the browser target, only uses flat sessionId mode.java.lang.StringattachToTarget(java.lang.String targetId)Attaches to the target with given id.java.lang.StringattachToTarget(java.lang.String targetId, java.lang.Boolean flatten)Attaches to the target with given id.java.lang.BooleancloseTarget(java.lang.String targetId)Closes the target.java.lang.StringcreateBrowserContext()Creates a new empty BrowserContext.java.lang.StringcreateTarget(java.lang.String url)Creates a new page.java.lang.StringcreateTarget(java.lang.String url, java.lang.Integer width, java.lang.Integer height, java.lang.String browserContextId, java.lang.Boolean enableBeginFrameControl)Creates a new page.voiddetachFromTarget()Detaches session with given id.voiddetachFromTarget(java.lang.String sessionId, java.lang.String targetId)Detaches session with given id.voiddisposeBrowserContext(java.lang.String browserContextId)Deletes a BrowserContext.voidexposeDevToolsProtocol(java.lang.String targetId)Inject object to the target's main frame that provides a communication channel with browser target.voidexposeDevToolsProtocol(java.lang.String targetId, java.lang.String bindingName)Inject object to the target's main frame that provides a communication channel with browser target.java.util.List<java.lang.String>getBrowserContexts()Returns all browser contexts created withTarget.createBrowserContextmethod.TargetInfogetTargetInfo()Returns information about a target.TargetInfogetTargetInfo(java.lang.String targetId)Returns information about a target.java.util.List<TargetInfo>getTargets()Retrieves a list of available targets.voidsendMessageToTarget(java.lang.String message)Sends protocol message over session with given id.voidsendMessageToTarget(java.lang.String message, java.lang.String sessionId, java.lang.String targetId)Sends protocol message over session with given id.voidsetAutoAttach(java.lang.Boolean autoAttach, java.lang.Boolean waitForDebuggerOnStart)Controls whether to automatically attach to new targets which are considered to be related to this one.voidsetAutoAttach(java.lang.Boolean autoAttach, java.lang.Boolean waitForDebuggerOnStart, java.lang.Boolean flatten)Controls whether to automatically attach to new targets which are considered to be related to this one.voidsetDiscoverTargets(java.lang.Boolean discover)Controls whether to discover available targets and notify viatargetCreated/targetInfoChanged/targetDestroyedevents.voidsetRemoteLocations(java.util.List<RemoteLocation> locations)Enables target discovery for the specified locations, whensetDiscoverTargetswas set totrue.
-
Method Details
-
activateTarget
void activateTarget(java.lang.String targetId)Activates (focuses) the target. -
attachToTarget
java.lang.String attachToTarget(java.lang.String targetId, java.lang.Boolean flatten)Attaches to the target with given id.- Parameters:
flatten- Enables "flat" access to the session via specifying sessionId attribute in the commands.- Returns:
- Id assigned to the session.
-
attachToBrowserTarget
java.lang.String attachToBrowserTarget()Attaches to the browser target, only uses flat sessionId mode.- Returns:
- Id assigned to the session.
-
closeTarget
java.lang.Boolean closeTarget(java.lang.String targetId)Closes the target. If the target is a page that gets closed too. -
exposeDevToolsProtocol
void exposeDevToolsProtocol(java.lang.String targetId, java.lang.String bindingName)Inject object to the target's main frame that provides a communication channel with browser target. Injected object will be available aswindow[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.
-
createBrowserContext
java.lang.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.
-
getBrowserContexts
java.util.List<java.lang.String> getBrowserContexts()Returns all browser contexts created withTarget.createBrowserContextmethod.- Returns:
- An array of browser context ids.
-
createTarget
java.lang.String createTarget(java.lang.String url, java.lang.Integer width, java.lang.Integer height, java.lang.String browserContextId, java.lang.Boolean enableBeginFrameControl)Creates a new page.- Parameters:
url- The initial URL the page will be navigated to.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).- Returns:
- The id of the page opened.
-
detachFromTarget
void detachFromTarget(java.lang.String sessionId, java.lang.String targetId)Detaches session with given id.- Parameters:
sessionId- Session to detach.targetId- Deprecated.
-
disposeBrowserContext
void disposeBrowserContext(java.lang.String browserContextId)Deletes a BrowserContext. All the belonging pages will be closed without calling their beforeunload hooks. -
getTargetInfo
Returns information about a target. -
getTargets
java.util.List<TargetInfo> getTargets()Retrieves a list of available targets.- Returns:
- The list of targets.
-
sendMessageToTarget
void sendMessageToTarget(java.lang.String message, java.lang.String sessionId, java.lang.String targetId)Sends protocol message over session with given id.- Parameters:
sessionId- Identifier of the session.targetId- Deprecated.
-
setAutoAttach
void setAutoAttach(java.lang.Boolean autoAttach, java.lang.Boolean waitForDebuggerOnStart, java.lang.Boolean flatten)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.- Parameters:
autoAttach- Whether to auto-attach to related targets.waitForDebuggerOnStart- Whether to pause new targets when attaching to them. UseRuntime.runIfWaitingForDebuggerto run paused targets.flatten- Enables "flat" access to the session via specifying sessionId attribute in the commands.
-
setDiscoverTargets
void setDiscoverTargets(java.lang.Boolean discover)Controls whether to discover available targets and notify viatargetCreated/targetInfoChanged/targetDestroyedevents.- Parameters:
discover- Whether to discover available targets.
-
setRemoteLocations
Enables target discovery for the specified locations, whensetDiscoverTargetswas set totrue.- Parameters:
locations- List of remote locations.
-
attachToTarget
java.lang.String attachToTarget(java.lang.String targetId)Attaches to the target with given id.- Returns:
- Id assigned to the session.
-
exposeDevToolsProtocol
void exposeDevToolsProtocol(java.lang.String targetId)Inject object to the target's main frame that provides a communication channel with browser target. Injected object will be available aswindow[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. -
createTarget
java.lang.String createTarget(java.lang.String url)Creates a new page.- Parameters:
url- The initial URL the page will be navigated to.- Returns:
- The id of the page opened.
-
detachFromTarget
void detachFromTarget()Detaches session with given id. -
getTargetInfo
TargetInfo getTargetInfo()Returns information about a target. -
sendMessageToTarget
void sendMessageToTarget(java.lang.String message)Sends protocol message over session with given id. -
setAutoAttach
void setAutoAttach(java.lang.Boolean autoAttach, java.lang.Boolean waitForDebuggerOnStart)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.- Parameters:
autoAttach- Whether to auto-attach to related targets.waitForDebuggerOnStart- Whether to pause new targets when attaching to them. UseRuntime.runIfWaitingForDebuggerto run paused targets.
-