Types
Useful Python types used in jsrun.
JavaScriptError
Bases: Exception
Raised when JavaScript code running in the runtime throws an exception.
The runtime surfaces JavaScript exceptions as JavaScriptError instances
that preserve structured metadata from V8, giving callers access to the
original error class, message, stack trace, and individual frames.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str | None
|
JavaScript error class name (e.g. |
message |
str | None
|
Error message string when available. |
stack |
str | None
|
V8 formatted stack trace string if provided. |
frames |
list[JsFrame]
|
Parsed stack frames populated with optional |
Example
RuntimeTerminated
Bases: RuntimeError
Raised when JavaScript execution is aborted by Runtime.terminate().
JsUndefined
Sentinel representing the JavaScript undefined value in Python.
JsFunction
Proxy for a JavaScript function returned from the runtime.
Instances execute on the underlying V8 isolate. Calling the proxy returns either a direct value (for synchronous JavaScript functions) or an awaitable object when the JavaScript side returns a pending Promise.
__call__
Invoke the JavaScript function with the provided arguments. If the JS function finishes synchronously, its return value is produced directly. Otherwise, the result is awaitable and must be awaited.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Arguments forwarded into JavaScript |
()
|
timeout
|
float | int | timedelta | None
|
Optional timeout (seconds as float/int, or datetime.timedelta) |
...
|
Returns:
| Type | Description |
|---|---|
Any | Awaitable[Any]
|
Either the JavaScript return value or an awaitable resolving to it. |
call_async
Always invoke the JavaScript function asynchronously, returning an awaitable regardless of whether the underlying JS completes synchronously.
RuntimeStats
Structured snapshot of runtime resource usage and execution counters.
Instances are returned from Runtime.get_stats() and provide
read-only insight into the V8 heap, total execution time, and active
resources currently managed by the runtime.
Attributes:
| Name | Type | Description |
|---|---|---|
heap_total_bytes |
int
|
Total heap size in bytes allocated by V8 |
heap_used_bytes |
int
|
Currently used heap memory in bytes |
external_memory_bytes |
int
|
External memory tracked by V8 (e.g., ArrayBuffers) |
physical_total_bytes |
int
|
Physical memory in bytes (RSS) |
total_execution_time_ms |
int
|
Cumulative execution time in milliseconds |
last_execution_time_ms |
int
|
Duration of the most recent execution in milliseconds |
last_execution_kind |
str | None
|
Type of last operation (e.g., "eval_async", "call_function_sync") |
eval_sync_count |
int
|
Number of synchronous eval operations |
eval_async_count |
int
|
Number of asynchronous eval operations |
eval_module_sync_count |
int
|
Number of synchronous module evaluations |
eval_module_async_count |
int
|
Number of asynchronous module evaluations |
call_function_async_count |
int
|
Number of asynchronous function calls |
call_function_sync_count |
int
|
Number of synchronous function calls |
active_async_ops |
int
|
Currently active async operations |
open_resources |
int
|
Number of open resources (timers, streams, etc.) |
active_timers |
int
|
Active setTimeout timers |
active_intervals |
int
|
Active setInterval timers |
active_js_streams |
int
|
Active JavaScript ReadableStreams exposed to Python |
active_py_streams |
int
|
Active Python async iterables exposed to JavaScript |
total_js_streams |
int
|
Total JavaScript streams created |
total_py_streams |
int
|
Total Python streams created |
bytes_streamed_js_to_py |
int
|
Total bytes transferred from JavaScript to Python |
bytes_streamed_py_to_js |
int
|
Total bytes transferred from Python to JavaScript |
external_memory_bytes
property
External memory tracked by V8 (e.g., ArrayBuffers).
total_execution_time_ms
property
Cumulative execution time in milliseconds.
last_execution_time_ms
property
Duration of the most recent execution in milliseconds.
last_execution_kind
property
Type of last operation (e.g., "eval_async", "call_function_sync").
eval_module_sync_count
property
Number of synchronous module evaluations.
eval_module_async_count
property
Number of asynchronous module evaluations.
call_function_async_count
property
Number of asynchronous function calls.
call_function_sync_count
property
Number of synchronous function calls.
active_js_streams
property
Active JavaScript ReadableStreams exposed to Python.
active_py_streams
property
Active Python async iterables exposed to JavaScript.
bytes_streamed_js_to_py
property
Total bytes transferred from JavaScript to Python.
InspectorConfig
Configuration for enabling the Chrome DevTools inspector.
__init__
__init__(host: str = '127.0.0.1', port: int = 9229, *, wait_for_connection: bool = False, break_on_next_statement: bool = False, target_url: str | None = None, display_name: str | None = None) -> None
Create a new inspector configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
Host interface to bind (defaults to |
'127.0.0.1'
|
port
|
int
|
TCP port for the DevTools server |
9229
|
wait_for_connection
|
bool
|
Block execution until a debugger connects |
False
|
break_on_next_statement
|
bool
|
Pause on the first statement after a debugger attaches |
False
|
target_url
|
str | None
|
Optional string reported to DevTools for the inspected target |
None
|
display_name
|
str | None
|
Optional display title surfaced in |
None
|
InspectorEndpoints
Runtime inspector metadata exposing DevTools URLs.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the inspector session |
websocket_url |
str
|
WebSocket URL for the Chrome DevTools Protocol |
devtools_frontend_url |
str
|
DevTools frontend URL to open in Chrome |
title |
str
|
Display title for the inspector target |
description |
str
|
Description of the inspector target |
target_url |
str
|
URL of the target being inspected |
favicon_url |
str
|
Favicon URL for the inspector target |
host |
str
|
Host address where the inspector is listening |
SnapshotBuilder
Build a V8 snapshot covering a custom bootstrap script.
Use execute_script() to run multiple scripts before calling
build() to produce the serialized bytes.
__init__
Create a snapshot builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bootstrap
|
str | None
|
Optional JavaScript source run before any scripts added via |
None
|
enable_console
|
bool | None
|
Whether |
False
|
execute_script
Run a JavaScript script inside the snapshot builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Identifier used in stack traces / debugging. |
required |
source
|
str
|
Source text to compile and execute. The code is executed as a
classic script (not an ES module), so |
required |