viewpoint_cdp/protocol/runtime/
mod.rs

1//! Runtime domain types.
2//!
3//! The Runtime domain exposes JavaScript runtime by means of remote evaluation and mirror objects.
4
5use serde::{Deserialize, Serialize};
6
7/// Unique script identifier.
8pub type ScriptId = String;
9
10/// Unique execution context identifier.
11pub type ExecutionContextId = i64;
12
13/// Remote object value.
14#[derive(Debug, Clone, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct RemoteObject {
17    /// Object type.
18    #[serde(rename = "type")]
19    pub object_type: String,
20    /// Object subtype hint.
21    pub subtype: Option<String>,
22    /// Object class name.
23    pub class_name: Option<String>,
24    /// Remote object value.
25    pub value: Option<serde_json::Value>,
26    /// String representation of the object.
27    pub description: Option<String>,
28    /// Unique object identifier.
29    pub object_id: Option<String>,
30}
31
32/// Exception details.
33#[derive(Debug, Clone, Deserialize)]
34#[serde(rename_all = "camelCase")]
35pub struct ExceptionDetails {
36    /// Exception id.
37    pub exception_id: i64,
38    /// Exception text.
39    pub text: String,
40    /// Line number of the exception location.
41    pub line_number: i64,
42    /// Column number of the exception location.
43    pub column_number: i64,
44    /// Script ID of the exception location.
45    pub script_id: Option<ScriptId>,
46    /// URL of the exception location.
47    pub url: Option<String>,
48    /// Exception object if available.
49    pub exception: Option<RemoteObject>,
50    /// Execution context ID.
51    pub execution_context_id: Option<ExecutionContextId>,
52}
53
54/// Parameters for Runtime.evaluate.
55#[derive(Debug, Clone, Serialize)]
56#[serde(rename_all = "camelCase")]
57pub struct EvaluateParams {
58    /// Expression to evaluate.
59    pub expression: String,
60    /// Object group for the result.
61    #[serde(skip_serializing_if = "Option::is_none")]
62    pub object_group: Option<String>,
63    /// Whether to include command line API.
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub include_command_line_api: Option<bool>,
66    /// Whether to disable side effects.
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub silent: Option<bool>,
69    /// Execution context ID.
70    #[serde(skip_serializing_if = "Option::is_none")]
71    pub context_id: Option<ExecutionContextId>,
72    /// Whether to return by value.
73    #[serde(skip_serializing_if = "Option::is_none")]
74    pub return_by_value: Option<bool>,
75    /// Whether to await the promise.
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub await_promise: Option<bool>,
78}
79
80/// Result of Runtime.evaluate.
81#[derive(Debug, Clone, Deserialize)]
82#[serde(rename_all = "camelCase")]
83pub struct EvaluateResult {
84    /// Evaluation result.
85    pub result: RemoteObject,
86    /// Exception details if the evaluation threw.
87    pub exception_details: Option<ExceptionDetails>,
88}
89
90/// Event: Runtime.executionContextCreated
91#[derive(Debug, Clone, Deserialize)]
92pub struct ExecutionContextCreatedEvent {
93    /// Newly created execution context.
94    pub context: ExecutionContextDescription,
95}
96
97/// Execution context description.
98#[derive(Debug, Clone, Deserialize)]
99#[serde(rename_all = "camelCase")]
100pub struct ExecutionContextDescription {
101    /// Unique execution context id.
102    pub id: ExecutionContextId,
103    /// Execution context origin.
104    pub origin: String,
105    /// Human readable name describing given context.
106    pub name: String,
107    /// Auxiliary data about the context, including frame information.
108    pub aux_data: Option<ExecutionContextAuxData>,
109}
110
111/// Auxiliary data for execution context.
112#[derive(Debug, Clone, Deserialize)]
113#[serde(rename_all = "camelCase")]
114pub struct ExecutionContextAuxData {
115    /// Frame ID associated with this execution context.
116    pub frame_id: Option<String>,
117    /// Whether this is the default context for the frame.
118    pub is_default: Option<bool>,
119    /// Type of the context (e.g., "default", "isolated", "worker").
120    #[serde(rename = "type")]
121    pub context_type: Option<String>,
122}
123
124/// Event: Runtime.executionContextDestroyed
125#[derive(Debug, Clone, Deserialize)]
126#[serde(rename_all = "camelCase")]
127pub struct ExecutionContextDestroyedEvent {
128    /// ID of the destroyed context.
129    pub execution_context_id: ExecutionContextId,
130}
131
132// ============================================================================
133// Call Function On
134// ============================================================================
135
136/// Parameters for Runtime.callFunctionOn.
137#[derive(Debug, Clone, Serialize)]
138#[serde(rename_all = "camelCase")]
139pub struct CallFunctionOnParams {
140    /// Declaration of the function to call.
141    pub function_declaration: String,
142    /// Identifier of the object to call function on.
143    #[serde(skip_serializing_if = "Option::is_none")]
144    pub object_id: Option<String>,
145    /// Call arguments.
146    #[serde(skip_serializing_if = "Option::is_none")]
147    pub arguments: Option<Vec<CallArgument>>,
148    /// In silent mode exceptions thrown during evaluation are not reported.
149    #[serde(skip_serializing_if = "Option::is_none")]
150    pub silent: Option<bool>,
151    /// Whether the result is expected to be a JSON object.
152    #[serde(skip_serializing_if = "Option::is_none")]
153    pub return_by_value: Option<bool>,
154    /// Whether to generate preview for the result.
155    #[serde(skip_serializing_if = "Option::is_none")]
156    pub generate_preview: Option<bool>,
157    /// Whether execution should be treated as initiated by user in the UI.
158    #[serde(skip_serializing_if = "Option::is_none")]
159    pub user_gesture: Option<bool>,
160    /// Whether execution should await for resulting value.
161    #[serde(skip_serializing_if = "Option::is_none")]
162    pub await_promise: Option<bool>,
163    /// Specifies execution context which global object will be used.
164    #[serde(skip_serializing_if = "Option::is_none")]
165    pub execution_context_id: Option<ExecutionContextId>,
166    /// Symbolic group name that can be used to release multiple objects.
167    #[serde(skip_serializing_if = "Option::is_none")]
168    pub object_group: Option<String>,
169    /// Whether to throw an exception if side effect cannot be ruled out.
170    #[serde(skip_serializing_if = "Option::is_none")]
171    pub throw_on_side_effect: Option<bool>,
172    /// An alternative way to specify the execution context to call function on.
173    #[serde(skip_serializing_if = "Option::is_none")]
174    pub unique_context_id: Option<String>,
175    /// Specifies the result serialization.
176    #[serde(skip_serializing_if = "Option::is_none")]
177    pub serialization_options: Option<serde_json::Value>,
178}
179
180/// Call argument for callFunctionOn.
181#[derive(Debug, Clone, Serialize)]
182#[serde(rename_all = "camelCase")]
183pub struct CallArgument {
184    /// Primitive value or serializable javascript object.
185    #[serde(skip_serializing_if = "Option::is_none")]
186    pub value: Option<serde_json::Value>,
187    /// Primitive value which can not be JSON-stringified does not have value.
188    #[serde(skip_serializing_if = "Option::is_none")]
189    pub unserializable_value: Option<String>,
190    /// Remote object handle.
191    #[serde(skip_serializing_if = "Option::is_none")]
192    pub object_id: Option<String>,
193}
194
195/// Result of Runtime.callFunctionOn.
196#[derive(Debug, Clone, Deserialize)]
197#[serde(rename_all = "camelCase")]
198pub struct CallFunctionOnResult {
199    /// Call result.
200    pub result: RemoteObject,
201    /// Exception details if the call threw.
202    pub exception_details: Option<ExceptionDetails>,
203}
204
205// ============================================================================
206// Release Object
207// ============================================================================
208
209/// Parameters for Runtime.releaseObject.
210#[derive(Debug, Clone, Serialize)]
211#[serde(rename_all = "camelCase")]
212pub struct ReleaseObjectParams {
213    /// Identifier of the object to release.
214    pub object_id: String,
215}
216
217/// Parameters for Runtime.releaseObjectGroup.
218#[derive(Debug, Clone, Serialize)]
219#[serde(rename_all = "camelCase")]
220pub struct ReleaseObjectGroupParams {
221    /// Symbolic object group name.
222    pub object_group: String,
223}
224
225// ============================================================================
226// Get Properties
227// ============================================================================
228
229/// Parameters for Runtime.getProperties.
230#[derive(Debug, Clone, Serialize)]
231#[serde(rename_all = "camelCase")]
232pub struct GetPropertiesParams {
233    /// Identifier of the object to return properties for.
234    pub object_id: String,
235    /// If true, returns properties belonging only to the element itself.
236    #[serde(skip_serializing_if = "Option::is_none")]
237    pub own_properties: Option<bool>,
238    /// If true, returns accessor properties only.
239    #[serde(skip_serializing_if = "Option::is_none")]
240    pub accessor_properties_only: Option<bool>,
241    /// Whether preview should be generated for the results.
242    #[serde(skip_serializing_if = "Option::is_none")]
243    pub generate_preview: Option<bool>,
244    /// If true, returns non-indexed properties only.
245    #[serde(skip_serializing_if = "Option::is_none")]
246    pub non_indexed_properties_only: Option<bool>,
247}
248
249/// Property descriptor.
250#[derive(Debug, Clone, Deserialize)]
251#[serde(rename_all = "camelCase")]
252pub struct PropertyDescriptor {
253    /// Property name or symbol description.
254    pub name: String,
255    /// The value associated with the property.
256    pub value: Option<RemoteObject>,
257    /// True if the value associated with the property may be changed.
258    pub writable: Option<bool>,
259    /// A function which serves as a getter for the property.
260    pub get: Option<RemoteObject>,
261    /// A function which serves as a setter for the property.
262    pub set: Option<RemoteObject>,
263    /// True if the type of this property descriptor may be changed.
264    pub configurable: bool,
265    /// True if this property shows up during enumeration.
266    pub enumerable: bool,
267    /// True if the result was thrown during the evaluation.
268    pub was_thrown: Option<bool>,
269    /// True if the property is owned for the object.
270    pub is_own: Option<bool>,
271    /// Property symbol object.
272    pub symbol: Option<RemoteObject>,
273}
274
275/// Result of Runtime.getProperties.
276#[derive(Debug, Clone, Deserialize)]
277#[serde(rename_all = "camelCase")]
278pub struct GetPropertiesResult {
279    /// Object properties.
280    pub result: Vec<PropertyDescriptor>,
281    /// Internal object properties (only of the element itself).
282    pub internal_properties: Option<Vec<InternalPropertyDescriptor>>,
283    /// Object private properties.
284    pub private_properties: Option<Vec<PrivatePropertyDescriptor>>,
285    /// Exception details.
286    pub exception_details: Option<ExceptionDetails>,
287}
288
289/// Internal property descriptor.
290#[derive(Debug, Clone, Deserialize)]
291#[serde(rename_all = "camelCase")]
292pub struct InternalPropertyDescriptor {
293    /// Conventional property name.
294    pub name: String,
295    /// The value associated with the property.
296    pub value: Option<RemoteObject>,
297}
298
299/// Private property descriptor.
300#[derive(Debug, Clone, Deserialize)]
301#[serde(rename_all = "camelCase")]
302pub struct PrivatePropertyDescriptor {
303    /// Private property name.
304    pub name: String,
305    /// The value associated with the private property.
306    pub value: Option<RemoteObject>,
307    /// A function which serves as a getter for the private property.
308    pub get: Option<RemoteObject>,
309    /// A function which serves as a setter for the private property.
310    pub set: Option<RemoteObject>,
311}
312
313// ============================================================================
314// Binding
315// ============================================================================
316
317/// Parameters for Runtime.addBinding.
318#[derive(Debug, Clone, Serialize)]
319#[serde(rename_all = "camelCase")]
320pub struct AddBindingParams {
321    /// Binding name.
322    pub name: String,
323    /// If specified, the binding would only be exposed to the specified execution context.
324    #[serde(skip_serializing_if = "Option::is_none")]
325    pub execution_context_id: Option<ExecutionContextId>,
326    /// If specified, the binding is exposed to the given execution context name.
327    #[serde(skip_serializing_if = "Option::is_none")]
328    pub execution_context_name: Option<String>,
329}
330
331/// Parameters for Runtime.removeBinding.
332#[derive(Debug, Clone, Serialize)]
333pub struct RemoveBindingParams {
334    /// Binding name.
335    pub name: String,
336}
337
338/// Event: Runtime.bindingCalled
339#[derive(Debug, Clone, Deserialize)]
340#[serde(rename_all = "camelCase")]
341pub struct BindingCalledEvent {
342    /// Binding name.
343    pub name: String,
344    /// Binding payload.
345    pub payload: String,
346    /// Identifier of the context where the call was made.
347    pub execution_context_id: ExecutionContextId,
348}
349
350// ============================================================================
351// Console API Called Event
352// ============================================================================
353
354/// Console message type.
355#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
356#[serde(rename_all = "lowercase")]
357pub enum ConsoleApiType {
358    /// `console.log()`
359    Log,
360    /// `console.debug()`
361    Debug,
362    /// `console.info()`
363    Info,
364    /// `console.error()`
365    Error,
366    /// `console.warn()` / `console.warning()`
367    Warning,
368    /// `console.dir()`
369    Dir,
370    /// `console.dirxml()`
371    Dirxml,
372    /// `console.table()`
373    Table,
374    /// `console.trace()`
375    Trace,
376    /// `console.clear()`
377    Clear,
378    /// `console.count()`
379    Count,
380    /// `console.assert()`
381    Assert,
382    /// `console.profile()`
383    Profile,
384    /// `console.profileEnd()`
385    ProfileEnd,
386    /// `console.time()`
387    StartGroup,
388    /// `console.timeEnd()`
389    StartGroupCollapsed,
390    /// `console.groupEnd()`
391    EndGroup,
392    /// `console.timeLog()`
393    TimeEnd,
394}
395
396impl std::fmt::Display for ConsoleApiType {
397    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
398        let s = match self {
399            Self::Log => "log",
400            Self::Debug => "debug",
401            Self::Info => "info",
402            Self::Error => "error",
403            Self::Warning => "warning",
404            Self::Dir => "dir",
405            Self::Dirxml => "dirxml",
406            Self::Table => "table",
407            Self::Trace => "trace",
408            Self::Clear => "clear",
409            Self::Count => "count",
410            Self::Assert => "assert",
411            Self::Profile => "profile",
412            Self::ProfileEnd => "profileEnd",
413            Self::StartGroup => "startGroup",
414            Self::StartGroupCollapsed => "startGroupCollapsed",
415            Self::EndGroup => "endGroup",
416            Self::TimeEnd => "timeEnd",
417        };
418        write!(f, "{s}")
419    }
420}
421
422/// Stack trace entry.
423#[derive(Debug, Clone, Deserialize)]
424#[serde(rename_all = "camelCase")]
425pub struct CallFrame {
426    /// JavaScript function name.
427    pub function_name: String,
428    /// JavaScript script id.
429    pub script_id: ScriptId,
430    /// JavaScript script name or URL.
431    pub url: String,
432    /// JavaScript script line number (0-based).
433    pub line_number: i32,
434    /// JavaScript script column number (0-based).
435    pub column_number: i32,
436}
437
438/// Stack trace.
439#[derive(Debug, Clone, Deserialize)]
440#[serde(rename_all = "camelCase")]
441pub struct StackTrace {
442    /// String label of this stack trace.
443    pub description: Option<String>,
444    /// JavaScript function call frames.
445    pub call_frames: Vec<CallFrame>,
446    /// Asynchronous JavaScript stack trace that preceded this stack (if available).
447    pub parent: Option<Box<StackTrace>>,
448    /// Asynchronous JavaScript stack trace that preceded this stack (if available).
449    pub parent_id: Option<StackTraceId>,
450}
451
452/// Unique identifier of current debugger.
453#[derive(Debug, Clone, Deserialize)]
454#[serde(rename_all = "camelCase")]
455pub struct StackTraceId {
456    /// Unique id.
457    pub id: String,
458    /// Debugger id (only set when created by other debugger).
459    pub debugger_id: Option<String>,
460}
461
462/// Event: Runtime.consoleAPICalled
463///
464/// Issued when console API was called.
465#[derive(Debug, Clone, Deserialize)]
466#[serde(rename_all = "camelCase")]
467pub struct ConsoleApiCalledEvent {
468    /// Type of the call.
469    #[serde(rename = "type")]
470    pub call_type: ConsoleApiType,
471    /// Call arguments.
472    pub args: Vec<RemoteObject>,
473    /// Identifier of the context where the call was made.
474    pub execution_context_id: ExecutionContextId,
475    /// Call timestamp.
476    pub timestamp: f64,
477    /// Stack trace captured when the call was made.
478    pub stack_trace: Option<StackTrace>,
479    /// Console context descriptor for calls on non-default console context (not console.*):
480    /// 'anonymous#unique-logger-id' for call on unnamed context.
481    pub context: Option<String>,
482}
483
484// ============================================================================
485// Exception Thrown Event
486// ============================================================================
487
488/// Event: Runtime.exceptionThrown
489///
490/// Issued when exception was thrown and unhandled.
491#[derive(Debug, Clone, Deserialize)]
492#[serde(rename_all = "camelCase")]
493pub struct ExceptionThrownEvent {
494    /// Timestamp of the exception.
495    pub timestamp: f64,
496    /// Exception details.
497    pub exception_details: ExceptionDetails,
498}