Package io.webfolder.cdp.session
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 Summary
FieldsFields inherited from interface io.webfolder.cdp.session.Constant
BACKSPACE, DOM_PROPERTIES, DOWN_ARROW, EMPTY_ARGS, EMPTY_NODE_ID, ENTER, ESC, LEFT_ARROW, RIGHT_ARROW, SPECIAL_KEYS, TAB, UP_ARROW, WAIT_PERIOD, WAIT_TIMEOUT
-
Method Summary
Modifier and TypeMethodDescriptionvoid
activate()
Activate this browser windowboolean
addCloseListener
(CloseListener listener) void
addEventListener
(EventListener eventListener) void
addSyncEventListener
(EventListener eventListener) byte[]
Capture page screenshot.byte[]
captureScreenshot
(ImageFormat format, Integer quality, Viewport clip, Boolean fromSurface) Takes a screenshot of the page.void
close()
Close the this browser windowcreateVideoRecoder
(VideoRecorderOptions options) Redirects javascript console logs to cdp4j logger.Redirects runtime logs (network, security, storage etc..) to cdp4j loggerRedirects network logs to cdp4j loggerboolean
Return the executionContextId of the child frame.Return the child frame id for the context.Returns flat list of child frames.getId()
Gets the session identifier.<T> T
getJsFunction
(Class<T> klass) getThis()
int
hashCode()
boolean
boolean
boolean
Returns true if current context is root frame.Navigates to an urlnavigateAndWait
(String url, WaitUntil condition) Navigates to an urlnavigateAndWait
(String url, WaitUntil condition, int timeout) Navigates to an urlbyte[]
Print page as PDF.void
printToPDF
(Path file) Print PDF content to a file<T> T
registerJsFunction
(Class<T> klass) void
remove()
Removes a session from the management (without sending the close command)boolean
removeCloseListener
(CloseListener listener) void
removeEventEventListener
(EventListener eventListener) void
removeSyncEventEventListener
(EventListener eventListener) void
setEventParser
(EventParser eventParser) void
setRegisteredEventListeners
(EnumSet<Events> registeredEventListeners) boolean
switchFrame
(Frame frame) Switch to child frameboolean
switchFrame
(String frameId) Switch to child framevoid
Switch to root frame.toString()
wait
(int timeout) Causes the current thread to wait until waiting time elapses.wait
(int timeout, boolean log) Causes the current thread to wait until waiting time elapses.waits until document is readywaitDocumentReady
(int timeout) waits until document is readywaits until the specified condition meetswaits until the specified condition meetsboolean
boolean
boolean
boolean
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.webfolder.cdp.session.Dom
clearOptions, clearOptions, focus, focus, focus, focus, getAttribute, getAttribute, getAttribute, getAttributes, getAttributes, getAttributes, getBoxModel, getBoxModel, getClickablePoint, getClickablePoint, getClickablePointWithObjectId, getDocumentSnapshot, getDOMSnapshot, getInnerHtml, getInnerHtml, getOptions, getOptions, getOuterHtml, getOuterHtml, getSelectedIndex, getSelectedIndex, getText, getText, getValue, getValue, isChecked, isChecked, isDisabled, isDisabled, scrollIntoViewIfNeeded, scrollIntoViewIfNeeded, scrollIntoViewIfNeededWithObjectId, selectInputText, selectInputText, setAttribute, setAttribute, setAttribute, setChecked, setChecked, setDisabled, setDisabled, setFiles, setFiles, setSelectedIndex, setSelectedIndex, setSelectedOptions, setSelectedOptions, setValue, setValue
Methods inherited from interface io.webfolder.cdp.session.JavaScript
callFunction, callFunction, callFunction, callPromise, evaluate, getVariable, setVariable
Methods inherited from interface io.webfolder.cdp.session.Keyboard
sendBackspace, sendDownArrow, sendEnter, sendEsc, sendKeyCode, sendKeys, sendLeftArrow, sendRightArrow, sendTab, sendUpArrow
Methods inherited from interface io.webfolder.cdp.session.Navigator
back, clearCache, clearCookies, forward, getContent, getLocation, getPathname, getQueryString, getTitle, isDomReady, reload, setUserAgent, stop
Methods inherited from interface io.webfolder.cdp.session.Selector
getNodeId, getNodeId, getObjectId, getObjectId, getObjectId, getObjectIds, getObjectIds, getObjectIdWithContext, getProperty, getProperty, getPropertyByObjectId, getPropertyDescriptor, matches, matches, matches, releaseObject, setProperty, setProperty
-
Field Details
-
frames
-
-
Method Details
-
getId
Gets the session identifier. -
close
public void close()Close the this browser window- Specified by:
close
in interfaceAutoCloseable
-
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
-
removeEventEventListener
-
addSyncEventListener
-
removeSyncEventEventListener
-
waitDocumentReady
waits until document is ready- Returns:
- this
-
waitDocumentReady
waits until document is ready- Parameters:
timeout
- the maximum time to wait in milliseconds- Returns:
- this
-
waitUntil
-
waitUntil
-
waitUntil
-
waitUntil
-
waitUntil
waits until the specified condition meets- Parameters:
condition
-- Returns:
- this
- Throws:
CdpTimeoutException
- if timeout value exceeds 10 seconds
-
waitUntil
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
Redirects javascript console logs to cdp4j logger.- Returns:
- this
-
enableDetailLog
Redirects runtime logs (network, security, storage etc..) to cdp4j logger- Returns:
- this
-
enableNetworkLog
Redirects network logs to cdp4j logger- Returns:
- this
-
getThis
-
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 useprintToPDF(Path)
if pdf content is to big.- Returns:
- pdf content as a byte array
-
printToPDF
Print PDF content to a file- Parameters:
file
- pdf file path
-
wait
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
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
-
getAsyncCommand
-
equals
-
switchFrame
Switch to child frame -
switchFrame
Switch to child frame -
getChildFrameId
Return the child frame id for the context. Returns null if current context is root frame. -
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
Returns flat list of child frames. -
registerJsFunction
-
getJsFunction
-
getTargetId
-
getBrowserContextId
-
getExecutionContextId
-
getSelectorEngine
-
addCloseListener
-
removeCloseListener
-
getJsonMapper
-
isMultiFrameMode
-
setRegisteredEventListeners
-
getRegisteredEventListeners
-
createVideoRecoder
-
createRealtimeVideoRecoder
-
hashCode
public int hashCode() -
getEventParser
-
setEventParser
-
toString
-