public final class V8Inspector extends java.lang.Object implements IJavetClosable
Each V8Inspector instance maps to a separate V8 inspector session
with its own CDP channel. Multiple sessions can be created on the same
V8Runtime, allowing multiple DevTools clients to connect simultaneously.
Use V8Runtime.createV8Inspector(String) to create sessions.
Multiple sessions can be created on the same runtime.
Sessions implement IJavetClosable so they can be explicitly disconnected
when no longer needed.
| Modifier and Type | Method and Description |
|---|---|
void |
addListeners(IV8InspectorListener... listeners)
Adds one or more inspector listeners to receive CDP notifications and responses.
|
void |
breakProgram(java.lang.String breakReason,
java.lang.String breakDetails)
Forces the V8 runtime to break (pause) immediately, as if a breakpoint
were hit.
|
void |
cancelPauseOnNextStatement()
Cancels a previously scheduled pause on the next statement.
|
void |
close()
Closes this inspector session, disconnecting it from the V8 runtime.
|
void |
consoleAPIMessage(int contextGroupId,
int level,
java.lang.String message,
java.lang.String url,
int lineNumber,
int columnNumber)
Called by V8 when a console API message is produced.
|
<T extends V8Value> |
evaluate(java.lang.String expression,
boolean includeCommandLineAPI)
Evaluates a JavaScript expression directly through the inspector session,
bypassing CDP JSON serialization.
|
void |
flushProtocolNotifications()
Called by V8 to flush any queued protocol notifications.
|
IJavetLogger |
getLogger()
Gets the logger used by this inspector session.
|
java.lang.String |
getName()
Gets the name of this inspector session.
|
int |
getSessionId()
Gets the native session ID for this inspector session.
|
void |
installAdditionalCommandLineAPI(IV8ValueObject commandLineAPI)
Called by V8 to install additional command-line API objects.
|
boolean |
isClosed()
Returns whether this session has been closed.
|
void |
receiveNotification(java.lang.String message)
Called by V8 when a CDP notification is received.
|
void |
receiveResponse(java.lang.String message)
Called by V8 when a CDP response is received.
|
void |
removeListeners(IV8InspectorListener... listeners)
Removes one or more previously added inspector listeners.
|
void |
runIfWaitingForDebugger(int contextGroupId)
Called by V8 when the runtime is waiting for a debugger connection.
|
void |
schedulePauseOnNextStatement(java.lang.String breakReason,
java.lang.String breakDetails)
Schedules a pause (breakpoint) on the next JavaScript statement that
executes.
|
void |
sendRequest(java.lang.String message)
Sends a CDP request message to the V8 inspector.
|
void |
setLogger(IJavetLogger logger)
Sets the logger used by this inspector session.
|
void |
setSkipAllPauses(boolean skip)
Tells V8 to skip all breakpoints (pauses) for this session.
|
void |
waitForDebugger()
Blocks the calling thread until all connected sessions have sent
Runtime.runIfWaitingForDebugger. |
public void addListeners(IV8InspectorListener... listeners)
listeners - the listeners to addpublic void breakProgram(java.lang.String breakReason,
java.lang.String breakDetails)
Debugger.paused notification with the
specified break reason.
Unlike schedulePauseOnNextStatement(String, String), this method
breaks immediately rather than waiting for the next JavaScript
statement to execute.
The caller must hold the V8 isolate lock (e.g., call from a thread that is currently executing JavaScript).
breakReason - a short reason string (e.g., "embedder-requested")breakDetails - additional JSON details (can be empty)public void close()
throws JavetException
sendRequest(String) are silently ignored.
Other sessions on the same runtime are not affected.close in interface IJavetClosableclose in interface java.lang.AutoCloseableJavetExceptionpublic void cancelPauseOnNextStatement()
schedulePauseOnNextStatement(String, String)public void consoleAPIMessage(int contextGroupId,
int level,
java.lang.String message,
java.lang.String url,
int lineNumber,
int columnNumber)
contextGroupId - the context group IDlevel - the message severity levelmessage - the console message texturl - the source URLlineNumber - the source line numbercolumnNumber - the source column numberpublic <T extends V8Value> T evaluate(java.lang.String expression, boolean includeCommandLineAPI)
Runtime.evaluate via sendRequest(String).
The caller must hold the V8 isolate lock. The returned value is a Javet V8 value that must be closed when no longer needed (if it is a reference type).
T - the expected V8 value typeexpression - the JavaScript expression to evaluateincludeCommandLineAPI - whether to include the command-line API scopenull if the session
is closed, the expression could not be run, or the result is emptypublic void flushProtocolNotifications()
public void installAdditionalCommandLineAPI(IV8ValueObject commandLineAPI)
commandLineAPI - the command-line API object provided by V8public IJavetLogger getLogger()
public java.lang.String getName()
public int getSessionId()
public boolean isClosed()
isClosed in interface IJavetClosablepublic void receiveNotification(java.lang.String message)
message - the CDP notification JSON messagepublic void receiveResponse(java.lang.String message)
message - the CDP response JSON messagepublic void removeListeners(IV8InspectorListener... listeners)
listeners - the listeners to removepublic void runIfWaitingForDebugger(int contextGroupId)
contextGroupId - the context group IDpublic void schedulePauseOnNextStatement(java.lang.String breakReason,
java.lang.String breakDetails)
Debugger.paused
notification with the specified reason.
This is useful for programmatic "break on next" functionality without needing to set a breakpoint at a specific source location.
Call cancelPauseOnNextStatement() to revoke a scheduled pause
before it fires.
breakReason - a short reason string (e.g., "ambiguous")breakDetails - additional JSON details (can be empty)public void sendRequest(java.lang.String message)
throws JavetException
message - the CDP request JSON messageJavetException - the javet exceptionpublic void setLogger(IJavetLogger logger)
logger - the loggerpublic void setSkipAllPauses(boolean skip)
setSkipAllPauses(false) to re-enable pausing.skip - true to skip all pauses, false to re-enablepublic void waitForDebugger()
Runtime.runIfWaitingForDebugger. This method must be called
from a thread that does not already hold the V8 isolate lock
(typically an execution thread, before running any JavaScript).
The inspector must have been created with waitForDebugger = true
(via V8Runtime.createV8Inspector(String, boolean)) for this to work.
When called, the method acquires the V8 lock and enters a message-pumping
loop, dispatching any incoming CDP messages while waiting. Once V8 invokes
the runIfWaitingForDebugger callback, the loop exits and this
method returns, allowing the thread to proceed with script execution.