Class Session

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

public class Session
extends java.lang.Object
implements java.lang.AutoCloseable, Selector, Keyboard, Mouse, Navigator, JavaScript, Dom
  • Method Details

    • getId

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

      public void close()
      Close the this browser window
      Specified by:
      close in interface java.lang.AutoCloseable
    • isConnected

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

      public void activate()
      Activate this browser window
    • addEventListener

      public void addEventListener​(EventListener eventListener)
    • removeEventEventListener

      public void removeEventEventListener​(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​(java.util.function.Predicate<Session> predicate)
    • waitUntil

      public boolean waitUntil​(java.util.function.Predicate<Session> predicate, int timeout)
    • waitUntil

      public boolean waitUntil​(java.util.function.Predicate<Session> predicate, int timeout, int period)
    • waitUntil

      public boolean waitUntil​(java.util.function.Predicate<Session> predicate, int timeout, int period, boolean log)
    • navigate

      public Session navigate​(java.lang.String url)
      Navigates to an url
      Parameters:
      url - URL to navigate page to. The url should include scheme, e.g. https://.
      Returns:
      this
    • navigateAndWait

      public Session navigateAndWait​(java.lang.String url, WaitUntil condition)
      Navigates to an url
      Parameters:
      url - URL to navigate page to. The url should include scheme, e.g. https://.
      condition - When to consider navigation succeeded.
      Returns:
      this
    • navigateAndWait

      public Session navigateAndWait​(java.lang.String url, WaitUntil condition, int timeout)
      Navigates to an url
      Parameters:
      url - URL to navigate page to. The url should include scheme, e.g. https://.
      condition - When to consider navigation succeeded.
      timeout - Maximum navigation time in milliseconds, defaults to 10 seconds.
      Returns:
      this
    • 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 java.lang.String getFrameId()
    • captureScreenshot

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

      public byte[] captureScreenshot​(boolean hideScrollbar)
      Takes a screenshot of the page.
      Parameters:
      hideScrollbar - hides the scollbar
    • captureScreenshot

      public byte[] captureScreenshot​(boolean hideScrollbar, ImageFormat format, java.lang.Integer quality, Viewport clip, java.lang.Boolean fromSurface)
      Takes a screenshot of the page.
      Parameters:
      hideScrollbar - hides the scollbar
      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​(java.nio.file.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()
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • equals

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object
    • getGson

      public com.google.gson.Gson getGson()
    • registerJsFunction

      public <T> T registerJsFunction​(java.lang.Class<T> klass)
    • getJsFunction

      public <T> T getJsFunction​(java.lang.Class<T> klass)
    • getTargetId

      public java.lang.String getTargetId()
    • getBrowserContextId

      public java.lang.String getBrowserContextId()
    • getExecutionContextId

      public java.lang.Integer getExecutionContextId()
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object