Class Session

java.lang.Object
io.webfolder.cdp.session.Session
All Implemented Interfaces:
Constant, Dom, JavaScript, Keyboard, Mouse, Navigator, Selector, AutoCloseable

public class Session extends Object implements AutoCloseable, Selector, Keyboard, Mouse, Navigator, JavaScript, Dom
  • Field Details

    • frames

      public final List<io.webfolder.cdp.session.CdpFrame> frames
  • Method Details

    • getId

      public String getId()
      Gets the session identifier.
    • close

      public void close()
      Close the this browser window
      Specified by:
      close in interface AutoCloseable
    • remove

      public void remove()
      Removes a session from the management (without sending the close command)
    • isConnected

      public boolean isConnected()
      Returns:
      true if browser is connected.
    • isDisposed

      public boolean isDisposed()
      Returns:
      true if the session was disposed.
    • activate

      public void activate()
      Activate this browser window
    • addEventListener

      public void addEventListener(EventListener eventListener)
    • removeEventEventListener

      public void removeEventEventListener(EventListener eventListener)
    • addSyncEventListener

      public void addSyncEventListener(EventListener eventListener)
    • removeSyncEventEventListener

      public void removeSyncEventEventListener(EventListener eventListener)
    • waitDocumentReady

      public Session waitDocumentReady()
      waits until document is ready
      Returns:
      this
    • waitDocumentReady

      public Session waitDocumentReady(int timeout)
      waits until document is ready
      Parameters:
      timeout - the maximum time to wait in milliseconds
      Returns:
      this
    • waitUntil

      public boolean waitUntil(Predicate<Session> predicate)
    • waitUntil

      public boolean waitUntil(Predicate<Session> predicate, int timeout)
    • waitUntil

      public boolean waitUntil(Predicate<Session> predicate, int timeout, int period)
    • waitUntil

      public boolean waitUntil(Predicate<Session> predicate, int timeout, int period, boolean log)
    • waitUntil

      public Session waitUntil(WaitUntil condition)
      waits until the specified condition meets
      Parameters:
      condition -
      Returns:
      this
      Throws:
      CdpTimeoutException - if timeout value exceeds 10 seconds
    • waitUntil

      public Session waitUntil(WaitUntil condition, int timeout)
      waits until the specified condition meets
      Parameters:
      condition -
      timeout - Maximum navigation time in milliseconds, defaults to 10 seconds.
      Returns:
      this
      Throws:
      CdpTimeoutException - if timeout value exceeds the specified value
    • enableConsoleLog

      public Session enableConsoleLog()
      Redirects javascript console logs to cdp4j logger.
      Returns:
      this
    • enableDetailLog

      public Session enableDetailLog()
      Redirects runtime logs (network, security, storage etc..) to cdp4j logger
      Returns:
      this
    • enableNetworkLog

      public Session enableNetworkLog()
      Redirects network logs to cdp4j logger
      Returns:
      this
    • getThis

      public Session getThis()
      Specified by:
      getThis in interface Dom
      Specified by:
      getThis in interface JavaScript
      Specified by:
      getThis in interface Keyboard
      Specified by:
      getThis in interface Mouse
      Specified by:
      getThis in interface Navigator
      Specified by:
      getThis in interface Selector
    • getFrameId

      public String getFrameId()
    • captureScreenshot

      public byte[] captureScreenshot()
      Capture page screenshot.
    • captureScreenshot

      public byte[] captureScreenshot(ImageFormat format, Integer quality, Viewport clip, Boolean fromSurface)
      Takes a screenshot of the page.
      Parameters:
      format - Image compression format (defaults to png).
      quality - Compression quality from range [0..100] (jpeg only).
      clip - Capture the screenshot of a given region only.
      fromSurface - Capture the screenshot from the surface, rather than the view. Defaults to true.
    • printToPDF

      public byte[] printToPDF()
      Print page as PDF. Performance tip: Prefer to use printToPDF(Path) if pdf content is to big.
      Returns:
      pdf content as a byte array
    • printToPDF

      public void printToPDF(Path file)
      Print PDF content to a file
      Parameters:
      file - pdf file path
    • wait

      public Session wait(int timeout)
      Causes the current thread to wait until waiting time elapses.
      Parameters:
      timeout - the maximum time to wait in milliseconds
      Returns:
      this
      Throws:
      CdpException - if the session held by another thread at the time of invocation.
    • wait

      public Session wait(int timeout, boolean log)
      Causes the current thread to wait until waiting time elapses.
      Parameters:
      timeout - the maximum time to wait in milliseconds
      Returns:
      this
      Throws:
      CdpException - if the session held by another thread at the time of invocation.
    • getCommand

      public Command getCommand()
    • getAsyncCommand

      public AsyncCommand getAsyncCommand()
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • switchFrame

      public boolean switchFrame(Frame frame)
      Switch to child frame
    • switchFrame

      public boolean switchFrame(String frameId)
      Switch to child frame
    • getChildFrameId

      public String getChildFrameId()
      Return the child frame id for the context. Returns null if current context is root frame.
    • getChildFrameExecutionContextId

      public Integer getChildFrameExecutionContextId()
      Return the executionContextId of the child frame. Returns null if current context is root frame.
    • switchToRootFrame

      public void switchToRootFrame()
      Switch to root frame.
    • isRootFrame

      public boolean isRootFrame()
      Returns true if current context is root frame.
    • getFrames

      public List<Frame> getFrames()
      Returns flat list of child frames.
    • registerJsFunction

      public <T> T registerJsFunction(Class<T> klass)
    • getJsFunction

      public <T> T getJsFunction(Class<T> klass)
    • getTargetId

      public String getTargetId()
    • getBrowserContextId

      public String getBrowserContextId()
    • getExecutionContextId

      public Integer getExecutionContextId()
    • getSelectorEngine

      public SelectorEngine getSelectorEngine()
    • addCloseListener

      public boolean addCloseListener(CloseListener listener)
    • removeCloseListener

      public boolean removeCloseListener(CloseListener listener)
    • getJsonMapper

      public JsonMapper getJsonMapper()
    • isMultiFrameMode

      public Boolean isMultiFrameMode()
    • setRegisteredEventListeners

      public void setRegisteredEventListeners(EnumSet<Events> registeredEventListeners)
    • getRegisteredEventListeners

      public EnumSet<Events> getRegisteredEventListeners()
    • createVideoRecoder

      public VideoRecorder createVideoRecoder(VideoRecorderOptions options)
    • createRealtimeVideoRecoder

      public VideoRecorder createRealtimeVideoRecoder(VideoRecorderOptions options)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getEventParser

      public EventParser getEventParser()
    • setEventParser

      public void setEventParser(EventParser eventParser)
    • toString

      public String toString()
      Overrides:
      toString in class Object