Class TargetImpl

java.lang.Object
io.webfolder.cdp.command.TargetImpl
All Implemented Interfaces:
Target

public class TargetImpl
extends java.lang.Object
implements Target
  • Constructor Summary

    Constructors 
    Constructor Description
    TargetImpl​(SessionInvocationHandler handler)  
  • Method Summary

    Modifier and Type Method Description
    void activateTarget​(java.lang.String targetId)
    Activates (focuses) the target.
    java.lang.String attachToBrowserTarget()
    Attaches to the browser target, only uses flat sessionId mode.
    java.lang.String attachToTarget​(java.lang.String targetId)
    Attaches to the target with given id.
    java.lang.String attachToTarget​(java.lang.String targetId, java.lang.Boolean flatten)
    Attaches to the target with given id.
    java.lang.Boolean closeTarget​(java.lang.String targetId)
    Closes the target.
    java.lang.String createBrowserContext()
    Creates a new empty BrowserContext.
    java.lang.String createTarget​(java.lang.String url)
    Creates a new page.
    java.lang.String createTarget​(java.lang.String url, java.lang.Integer width, java.lang.Integer height, java.lang.String browserContextId, java.lang.Boolean enableBeginFrameControl, java.lang.Boolean newWindow, java.lang.Boolean background)
    Creates a new page.
    void detachFromTarget()
    Detaches session with given id.
    void detachFromTarget​(java.lang.String sessionId, java.lang.String targetId)
    Detaches session with given id.
    void disposeBrowserContext​(java.lang.String browserContextId)
    Deletes a BrowserContext.
    void exposeDevToolsProtocol​(java.lang.String targetId)
    Inject object to the target's main frame that provides a communication channel with browser target.
    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.
    java.util.List<java.lang.String> getBrowserContexts()
    Returns all browser contexts created with `Target.createBrowserContext` method.
    TargetInfo getTargetInfo()
    Returns information about a target.
    TargetInfo getTargetInfo​(java.lang.String targetId)
    Returns information about a target.
    java.util.List<TargetInfo> getTargets()
    Retrieves a list of available targets.
    void sendMessageToTarget​(java.lang.String message)
    Sends protocol message over session with given id.
    void sendMessageToTarget​(java.lang.String message, java.lang.String sessionId, java.lang.String targetId)
    Sends protocol message over session with given id.
    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.
    void setAutoAttach​(java.lang.Boolean autoAttach, java.lang.Boolean waitForDebuggerOnStart, java.lang.Boolean flatten, java.lang.Boolean windowOpen)
    Controls whether to automatically attach to new targets which are considered to be related to this one.
    void setDiscoverTargets​(java.lang.Boolean discover)
    Controls whether to discover available targets and notify via `targetCreated/targetInfoChanged/targetDestroyed` events.
    void setRemoteLocations​(java.util.List<RemoteLocation> locations)
    Enables target discovery for the specified locations, when `setDiscoverTargets` was set to `true`.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • activateTarget

      public void activateTarget​(java.lang.String targetId)
      Description copied from interface: Target
      Activates (focuses) the target.
      Specified by:
      activateTarget in interface Target
    • attachToTarget

      public java.lang.String attachToTarget​(java.lang.String targetId, java.lang.Boolean flatten)
      Description copied from interface: Target
      Attaches to the target with given id.
      Specified by:
      attachToTarget in interface Target
      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.
    • attachToBrowserTarget

      public java.lang.String attachToBrowserTarget()
      Description copied from interface: Target
      Attaches to the browser target, only uses flat sessionId mode.
      Specified by:
      attachToBrowserTarget in interface Target
      Returns:
      Id assigned to the session.
    • closeTarget

      public java.lang.Boolean closeTarget​(java.lang.String targetId)
      Description copied from interface: Target
      Closes the target. If the target is a page that gets closed too.
      Specified by:
      closeTarget in interface Target
    • exposeDevToolsProtocol

      public void exposeDevToolsProtocol​(java.lang.String targetId, java.lang.String bindingName)
      Description copied from interface: Target
      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.
      Specified by:
      exposeDevToolsProtocol in interface Target
      bindingName - Binding name, 'cdp' if not specified.
    • createBrowserContext

      public java.lang.String createBrowserContext()
      Description copied from interface: Target
      Creates a new empty BrowserContext. Similar to an incognito profile but you can have more than one.
      Specified by:
      createBrowserContext in interface Target
      Returns:
      The id of the context created.
    • getBrowserContexts

      public java.util.List<java.lang.String> getBrowserContexts()
      Description copied from interface: Target
      Returns all browser contexts created with `Target.createBrowserContext` method.
      Specified by:
      getBrowserContexts in interface Target
      Returns:
      An array of browser context ids.
    • createTarget

      public java.lang.String createTarget​(java.lang.String url, java.lang.Integer width, java.lang.Integer height, java.lang.String browserContextId, java.lang.Boolean enableBeginFrameControl, java.lang.Boolean newWindow, java.lang.Boolean background)
      Description copied from interface: Target
      Creates a new page.
      Specified by:
      createTarget in interface Target
      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).
      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

      public void detachFromTarget​(java.lang.String sessionId, java.lang.String targetId)
      Description copied from interface: Target
      Detaches session with given id.
      Specified by:
      detachFromTarget in interface Target
      Parameters:
      sessionId - Session to detach.
      targetId - Deprecated.
    • disposeBrowserContext

      public void disposeBrowserContext​(java.lang.String browserContextId)
      Description copied from interface: Target
      Deletes a BrowserContext. All the belonging pages will be closed without calling their beforeunload hooks.
      Specified by:
      disposeBrowserContext in interface Target
    • getTargetInfo

      public TargetInfo getTargetInfo​(java.lang.String targetId)
      Description copied from interface: Target
      Returns information about a target.
      Specified by:
      getTargetInfo in interface Target
    • getTargets

      public java.util.List<TargetInfo> getTargets()
      Description copied from interface: Target
      Retrieves a list of available targets.
      Specified by:
      getTargets in interface Target
      Returns:
      The list of targets.
    • sendMessageToTarget

      public void sendMessageToTarget​(java.lang.String message, java.lang.String sessionId, java.lang.String targetId)
      Description copied from interface: Target
      Sends protocol message over session with given id. Consider using flat mode instead; see commands attachToTarget, setAutoAttach, and crbug.com/991325.
      Specified by:
      sendMessageToTarget in interface Target
      sessionId - Identifier of the session.
      targetId - Deprecated.
    • setAutoAttach

      public void setAutoAttach​(java.lang.Boolean autoAttach, java.lang.Boolean waitForDebuggerOnStart, java.lang.Boolean flatten, java.lang.Boolean windowOpen)
      Description copied from interface: Target
      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.
      Specified by:
      setAutoAttach in interface Target
      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.
      windowOpen - Auto-attach to the targets created via window.open from current target.
    • setDiscoverTargets

      public void setDiscoverTargets​(java.lang.Boolean discover)
      Description copied from interface: Target
      Controls whether to discover available targets and notify via `targetCreated/targetInfoChanged/targetDestroyed` events.
      Specified by:
      setDiscoverTargets in interface Target
      Parameters:
      discover - Whether to discover available targets.
    • setRemoteLocations

      public void setRemoteLocations​(java.util.List<RemoteLocation> locations)
      Description copied from interface: Target
      Enables target discovery for the specified locations, when `setDiscoverTargets` was set to `true`.
      Specified by:
      setRemoteLocations in interface Target
      Parameters:
      locations - List of remote locations.
    • attachToTarget

      public java.lang.String attachToTarget​(java.lang.String targetId)
      Description copied from interface: Target
      Attaches to the target with given id.
      Specified by:
      attachToTarget in interface Target
      Returns:
      Id assigned to the session.
    • exposeDevToolsProtocol

      public void exposeDevToolsProtocol​(java.lang.String targetId)
      Description copied from interface: Target
      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.
      Specified by:
      exposeDevToolsProtocol in interface Target
    • createTarget

      public java.lang.String createTarget​(java.lang.String url)
      Description copied from interface: Target
      Creates a new page.
      Specified by:
      createTarget in interface Target
      Parameters:
      url - The initial URL the page will be navigated to.
      Returns:
      The id of the page opened.
    • detachFromTarget

      public void detachFromTarget()
      Description copied from interface: Target
      Detaches session with given id.
      Specified by:
      detachFromTarget in interface Target
    • getTargetInfo

      public TargetInfo getTargetInfo()
      Description copied from interface: Target
      Returns information about a target.
      Specified by:
      getTargetInfo in interface Target
    • sendMessageToTarget

      public void sendMessageToTarget​(java.lang.String message)
      Description copied from interface: Target
      Sends protocol message over session with given id. Consider using flat mode instead; see commands attachToTarget, setAutoAttach, and crbug.com/991325.
      Specified by:
      sendMessageToTarget in interface Target
    • setAutoAttach

      public void setAutoAttach​(java.lang.Boolean autoAttach, java.lang.Boolean waitForDebuggerOnStart)
      Description copied from interface: Target
      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.
      Specified by:
      setAutoAttach in interface Target
      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.